Example #1
0
        public void TestGenerateMips()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 256U;
                const uint HEIGHT_TX = 128U;
                const uint ARR_LEN   = 4U;
                Texture2DArray <TexelFormat.RGBA8UNorm> sourceTex = TextureFactory.NewTexture2D <TexelFormat.RGBA8UNorm>()
                                                                    .WithWidth(WIDTH_TX)
                                                                    .WithHeight(HEIGHT_TX)
                                                                    .WithMipAllocation(true)
                                                                    .WithMipGenerationTarget(true)
                                                                    .WithPermittedBindings(GPUBindings.ReadableShaderResource | GPUBindings.RenderTarget)
                                                                    .WithUsage(ResourceUsage.Write)
                                                                    .CreateArray(ARR_LEN);

                Texture2DArray <TexelFormat.RGBA8UNorm> copyDestTex = sourceTex.Clone()
                                                                      .WithUsage(ResourceUsage.StagingRead)
                                                                      .WithPermittedBindings(GPUBindings.None)
                                                                      .WithMipGenerationTarget(false)
                                                                      .CreateArray(ARR_LEN);

                // Set up context
                for (uint u = 0U; u < ARR_LEN; u++)
                {
                    sourceTex[u].Write(
                        // ReSharper disable PossibleLossOfFraction No one cares
                        Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(false, WIDTH_TX, HEIGHT_TX))
                        .Select(i => new TexelFormat.RGBA8UNorm {
                        R = 0f, G = 0.33f, B = 0.67f, A = 1f
                    }).ToArray(),
                        // ReSharper restore PossibleLossOfFraction
                        new SubresourceBox(0U, WIDTH_TX, 0U, HEIGHT_TX),
                        0U
                        );
                }

                // Execute
                sourceTex.GenerateMips();
                sourceTex.CopyTo(copyDestTex);

                // Assert outcome
                for (uint u = 0U; u < ARR_LEN; u++)
                {
                    for (uint i = 1U; i < TextureUtils.GetNumMips(WIDTH_TX, HEIGHT_TX); ++i)
                    {
                        IEnumerable <TexelFormat.RGBA8UNorm> outData = copyDestTex[u].Read(i);
                        // ReSharper disable CompareOfFloatsByEqualityOperator Exact equality is fine here
                        Assert.IsTrue(outData.Any(texel => texel.R != 0f || texel.G != 0f || texel.B != 0f || texel.A != 0f));
                        // ReSharper restore CompareOfFloatsByEqualityOperator
                    }
                }

                sourceTex.Dispose();
                copyDestTex.Dispose();
            });
        }
Example #2
0
        public void TestWrite()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 100U;
                const uint HEIGHT_TX = 100U;

                const uint WRITE_OFFSET_U = 30U;
                const uint WRITE_OFFSET_V = 30U;

                SubresourceBox writeTarget = new SubresourceBox(
                    WRITE_OFFSET_U, WIDTH_TX,
                    WRITE_OFFSET_V, HEIGHT_TX
                    );

                Texture2D <TexelFormat.RGBA8Int> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA8Int>()
                                                          .WithUsage(ResourceUsage.Write)
                                                          .WithMultisampling(true)
                                                          .WithWidth(WIDTH_TX)
                                                          .WithHeight(HEIGHT_TX);

                // Set up context


                // Execute
                srcTex.Write(
                    Enumerable.Range(0, (int)writeTarget.Volume)
                    .Select(i => new TexelFormat.RGBA8Int {
                    R = (sbyte)i, G = (sbyte)(i * 2), B = (sbyte)(i * 3), A = (sbyte)(i * 4)
                })
                    .ToArray(),
                    writeTarget
                    );

                Texture2D <TexelFormat.RGBA8Int> dstTex = srcTex.Clone()
                                                          .WithUsage(ResourceUsage.StagingRead)
                                                          .WithPermittedBindings(GPUBindings.None);

                srcTex.CopyTo(dstTex);

                // Assert outcome
                TexelArray2D <TexelFormat.RGBA8Int> copiedData = dstTex.Read(0U);
                for (uint v = WRITE_OFFSET_V, value = 0U; v < HEIGHT_TX; ++v)
                {
                    for (uint u = WRITE_OFFSET_U; u < WIDTH_TX; ++u, ++value)
                    {
                        Assert.AreEqual((sbyte)value, copiedData[(int)u, (int)v].R);
                        Assert.AreEqual((sbyte)(value * 2U), copiedData[(int)u, (int)v].G);
                        Assert.AreEqual((sbyte)(value * 3U), copiedData[(int)u, (int)v].B);
                        Assert.AreEqual((sbyte)(value * 4U), copiedData[(int)u, (int)v].A);
                    }
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Example #3
0
        public void TestReadWrite()
        {
            // Define variables and constants
            const uint WIDTH_TX               = 512U;
            const uint HEIGHT_TX              = 512U;
            const uint TARGET_MIP_INDEX       = 2U;
            const uint DATA_WRITE_OFFSET_U    = 10U;
            const uint DATA_WRITE_OFFSET_V    = 10U;
            const uint DATA_WRITE_SQUARE_SIZE = 80U;

            Texture2D <TexelFormat.RGBA32UInt> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA32UInt>()
                                                        .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                .Select(i => (uint)i)
                .Select(i => new TexelFormat.RGBA32UInt {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                        .WithMipAllocation(true)
                                                        .WithPermittedBindings(GPUBindings.None)
                                                        .WithUsage(ResourceUsage.StagingReadWrite)
                                                        .WithWidth(WIDTH_TX)
                                                        .WithHeight(HEIGHT_TX);

            srcTex.ReadWrite(data => {
                for (uint u = DATA_WRITE_OFFSET_U; u < DATA_WRITE_OFFSET_U + DATA_WRITE_SQUARE_SIZE; ++u)
                {
                    for (uint v = DATA_WRITE_OFFSET_V; v < DATA_WRITE_OFFSET_V + DATA_WRITE_SQUARE_SIZE; ++v)
                    {
                        data[(int)u, (int)v] = new TexelFormat.RGBA32UInt {
                            R = u, G = v, B = u + v, A = u - v
                        };
                    }
                }
            },
                             TARGET_MIP_INDEX);

            var readData = srcTex.Read(TARGET_MIP_INDEX);

            for (uint u = DATA_WRITE_OFFSET_U; u < DATA_WRITE_OFFSET_U + DATA_WRITE_SQUARE_SIZE; ++u)
            {
                for (uint v = DATA_WRITE_OFFSET_V; v < DATA_WRITE_OFFSET_V + DATA_WRITE_SQUARE_SIZE; ++v)
                {
                    Assert.AreEqual(u, readData[(int)u, (int)v].R);
                    Assert.AreEqual(v, readData[(int)u, (int)v].G);
                    Assert.AreEqual(u + v, readData[(int)u, (int)v].B);
                    Assert.AreEqual(u - v, readData[(int)u, (int)v].A);
                }
            }

            srcTex.Dispose();
        }
Example #4
0
        public void TestDiscardWrite()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 400U;
                const uint HEIGHT_TX = 200U;

                const uint WRITE_OFFSET_U = 190U;
                const uint WRITE_OFFSET_V = 10U;
                const int NUM_TX_TO_WRITE = 13555;

                Texture2D <TexelFormat.RGB32UInt> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGB32UInt>()
                                                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                           .WithUsage(ResourceUsage.DiscardWrite)
                                                           .WithWidth(WIDTH_TX)
                                                           .WithHeight(HEIGHT_TX);

                // Set up context


                // Execute
                srcTex.DiscardWrite(
                    Enumerable.Range(0, NUM_TX_TO_WRITE)
                    .Select(i => new TexelFormat.RGB32UInt {
                    R = (uint)i, G = (uint)i * 2, B = (uint)i * 3
                })
                    .ToArray(),
                    0U,
                    WRITE_OFFSET_U,
                    WRITE_OFFSET_V
                    );

                Texture2D <TexelFormat.RGB32UInt> dstTex = srcTex.Clone()
                                                           .WithUsage(ResourceUsage.StagingRead)
                                                           .WithPermittedBindings(GPUBindings.None);


                srcTex.CopyTo(dstTex);

                // Assert outcome
                TexelFormat.RGB32UInt[] copiedData = dstTex.Read(0U).Data;
                int offset = (int)(WRITE_OFFSET_V * WIDTH_TX + WRITE_OFFSET_U);
                for (int i = 0; i < NUM_TX_TO_WRITE; ++i)
                {
                    Assert.AreEqual((uint)i, copiedData[i + offset].R);
                    Assert.AreEqual((uint)i * 2U, copiedData[i + offset].G);
                    Assert.AreEqual((uint)i * 3U, copiedData[i + offset].B);
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Example #5
0
        public void TestClone()
        {
            // Define variables and constants
            const uint WIDTH_TX  = 512U;
            const uint HEIGHT_TX = 1024U;
            Texture2D <TexelFormat.Int8> srcTex = TextureFactory.NewTexture2D <TexelFormat.Int8>()
                                                  .WithDynamicDetail(false)
                                                  .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                .Select(i => new TexelFormat.Int8 {
                Value = (sbyte)i
            })
                .ToArray()
                )
                                                  .WithMipAllocation(true)
                                                  .WithMipGenerationTarget(false)
                                                  .WithPermittedBindings(GPUBindings.None)
                                                  .WithUsage(ResourceUsage.StagingRead)
                                                  .WithMultisampling(false)
                                                  .WithWidth(WIDTH_TX)
                                                  .WithHeight(HEIGHT_TX);

            // Set up context


            // Execute
            Texture2D <TexelFormat.Int8> destNoCopy = srcTex.Clone(false);
            Texture2D <TexelFormat.Int8> destCopy   = srcTex.Clone(true);

            // Assert outcome
            Assert.AreEqual(srcTex.IsGlobalDetailTarget, destNoCopy.IsGlobalDetailTarget);
            Assert.AreEqual(srcTex.IsMipGenTarget, destNoCopy.IsMipGenTarget);
            Assert.AreEqual(srcTex.IsMipmapped, destNoCopy.IsMipmapped);
            Assert.AreEqual(srcTex.NumMips, destNoCopy.NumMips);
            Assert.AreEqual(srcTex.PermittedBindings, destNoCopy.PermittedBindings);
            Assert.AreEqual(srcTex.Size, destNoCopy.Size);
            Assert.AreEqual(srcTex.TexelFormat, destNoCopy.TexelFormat);
            Assert.AreEqual(srcTex.TexelSizeBytes, destNoCopy.TexelSizeBytes);
            Assert.AreEqual(srcTex.Usage, destNoCopy.Usage);
            Assert.AreEqual(srcTex.Width, destNoCopy.Width);
            Assert.AreEqual(srcTex.IsMultisampled, destNoCopy.IsMultisampled);

            TexelFormat.Int8[] copiedData = destCopy.ReadAll();
            for (int i = 0; i < copiedData.Length; ++i)
            {
                Assert.AreEqual((sbyte)i, copiedData[i].Value);
            }

            srcTex.Dispose();
            destCopy.Dispose();
            destNoCopy.Dispose();
        }
        public void TestRTVCreation()
        {
            Texture2D <TexelFormat.RenderTarget> testResource = TextureFactory.NewTexture2D <TexelFormat.RenderTarget>()
                                                                .WithDynamicDetail(false)
                                                                .WithMipAllocation(false)
                                                                .WithMipGenerationTarget(false)
                                                                .WithPermittedBindings(GPUBindings.RenderTarget)
                                                                .WithUsage(ResourceUsage.Write)
                                                                .WithWidth(800U)
                                                                .WithHeight(600U)
                                                                .WithMultisampling(true);
            RenderTargetView testRTV = testResource.CreateRenderTargetView(0U);

            Assert.IsFalse(testRTV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testRTV.Resource);
            Assert.AreEqual(0U, testRTV.MipIndex);
            testResource.Dispose();
            Assert.IsTrue(testRTV.ResourceOrViewDisposed);
            testRTV.Dispose();
            Assert.IsTrue(testRTV.IsDisposed);

            Texture2DArray <TexelFormat.RenderTarget> testResourceArr = TextureFactory.NewTexture2D <TexelFormat.RenderTarget>()
                                                                        .WithDynamicDetail(false)
                                                                        .WithMipAllocation(false)
                                                                        .WithMipGenerationTarget(false)
                                                                        .WithPermittedBindings(GPUBindings.RenderTarget)
                                                                        .WithUsage(ResourceUsage.Write)
                                                                        .WithWidth(800U)
                                                                        .WithHeight(600U)
                                                                        .WithMultisampling(true)
                                                                        .CreateArray(10U);

            testRTV = testResourceArr[3].CreateRenderTargetView(0U);
            Assert.IsFalse(testRTV.ResourceOrViewDisposed);
            Assert.AreEqual(testResourceArr[3], testRTV.Resource);
            Assert.AreEqual(0U, testRTV.MipIndex);
            testResourceArr.Dispose();
            Assert.IsTrue(testRTV.ResourceOrViewDisposed);
            testRTV.Dispose();
            Assert.IsTrue(testRTV.IsDisposed);
        }
        public void TestDSVCreation()
        {
            Texture2D <TexelFormat.DepthStencil> testResource = TextureFactory.NewTexture2D <TexelFormat.DepthStencil>()
                                                                .WithDynamicDetail(false)
                                                                .WithMipAllocation(true)
                                                                .WithMipGenerationTarget(false)
                                                                .WithPermittedBindings(GPUBindings.DepthStencilTarget)
                                                                .WithUsage(ResourceUsage.Write)
                                                                .WithWidth(512U)
                                                                .WithHeight(128U)
                                                                .WithMultisampling(false);
            DepthStencilView testDSV = testResource.CreateDepthStencilView(1U);

            Assert.IsFalse(testDSV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testDSV.Resource);
            Assert.AreEqual(1U, testDSV.MipIndex);
            testResource.Dispose();
            Assert.IsTrue(testDSV.ResourceOrViewDisposed);
            testDSV.Dispose();
            Assert.IsTrue(testDSV.IsDisposed);

            Texture2DArray <TexelFormat.DepthStencil> testResourceArr = TextureFactory.NewTexture2D <TexelFormat.DepthStencil>()
                                                                        .WithDynamicDetail(false)
                                                                        .WithMipAllocation(true)
                                                                        .WithMipGenerationTarget(false)
                                                                        .WithPermittedBindings(GPUBindings.DepthStencilTarget)
                                                                        .WithUsage(ResourceUsage.Write)
                                                                        .WithWidth(512U)
                                                                        .WithHeight(128U)
                                                                        .WithMultisampling(false)
                                                                        .CreateArray(10U);

            testDSV = testResourceArr[3].CreateDepthStencilView(1U);
            Assert.IsFalse(testDSV.ResourceOrViewDisposed);
            Assert.AreEqual(testResourceArr[3], testDSV.Resource);
            Assert.AreEqual(1U, testDSV.MipIndex);
            testResourceArr.Dispose();
            Assert.IsTrue(testDSV.ResourceOrViewDisposed);
            testDSV.Dispose();
            Assert.IsTrue(testDSV.IsDisposed);
        }
Example #8
0
        public void TestReadAndReadAll()
        {
            // Define variables and constants
            const uint WIDTH_TX  = 512U;
            const uint HEIGHT_TX = 64U;

            Texture2D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA32Int>()
                                                       .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                .Select(i => new TexelFormat.RGBA32Int {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                       .WithMipAllocation(true)
                                                       .WithPermittedBindings(GPUBindings.None)
                                                       .WithUsage(ResourceUsage.StagingRead)
                                                       .WithWidth(WIDTH_TX)
                                                       .WithHeight(HEIGHT_TX);

            TexelFormat.RGBA32Int[] readAllData = srcTex.ReadAll();
            for (int i = 0, curMipIndex = 0; i < readAllData.Length; ++curMipIndex)
            {
                var readData = srcTex.Read((uint)curMipIndex);
                for (int v = 0; v < readData.Height; ++v)
                {
                    for (int u = 0; u < readData.Width; ++u, ++i)
                    {
                        Assert.AreEqual(readData[u, v].R, readAllData[i].R);
                        Assert.AreEqual(readData[u, v].G, readAllData[i].G);
                        Assert.AreEqual(readData[u, v].B, readAllData[i].B);
                        Assert.AreEqual(readData[u, v].A, readAllData[i].A);
                    }
                }
            }

            srcTex.Dispose();
        }
        public void TestClearDepthStencil()
        {
            Texture2D <TexelFormat.DepthStencil> depthStencilBuffer = TextureFactory.NewTexture2D <TexelFormat.DepthStencil>()
                                                                      .WithWidth(800U)
                                                                      .WithHeight(600U)
                                                                      .WithDynamicDetail(false)
                                                                      .WithMipAllocation(false)
                                                                      .WithMipGenerationTarget(false)
                                                                      .WithMultisampling(false)
                                                                      .WithPermittedBindings(GPUBindings.DepthStencilTarget)
                                                                      .WithUsage(ResourceUsage.Write);

            DepthStencilView dsv = depthStencilBuffer.CreateDepthStencilView(0U);

            RenderCommand testCommand = RenderCommand.ClearDepthStencil(dsv);

            Assert.AreEqual(RenderCommandInstruction.ClearDepthStencil, testCommand.Instruction);
            Assert.AreEqual((RenderCommandArgument)(IntPtr)(ResourceViewHandle)dsv.ResourceViewHandle, testCommand.Arg1);

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.ClearDepthStencil(null as DepthStencilView);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            dsv.Dispose();
            depthStencilBuffer.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.ClearDepthStencil(dsv);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }
        public void TestClearRenderTarget()
        {
            Texture2D <TexelFormat.RenderTarget> renderTarget = TextureFactory.NewTexture2D <TexelFormat.RenderTarget>()
                                                                .WithWidth(800U)
                                                                .WithHeight(600U)
                                                                .WithDynamicDetail(false)
                                                                .WithMipAllocation(false)
                                                                .WithMipGenerationTarget(false)
                                                                .WithMultisampling(false)
                                                                .WithPermittedBindings(GPUBindings.RenderTarget)
                                                                .WithUsage(ResourceUsage.Write);

            RenderTargetView rtv = renderTarget.CreateRenderTargetView(0U);

            RenderCommand testCommand = RenderCommand.ClearRenderTarget(rtv);

            Assert.AreEqual(RenderCommandInstruction.ClearRenderTarget, testCommand.Instruction);
            Assert.AreEqual((RenderCommandArgument)(IntPtr)(ResourceViewHandle)rtv.ResourceViewHandle, testCommand.Arg1);

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.ClearRenderTarget(null as RenderTargetView);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            rtv.Dispose();
            renderTarget.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.ClearRenderTarget(rtv);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }
Example #11
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 512U;
                const uint HEIGHT_TX = 32U;

                const uint NUM_TEXELS_TO_COPY_PER_ROW = 25U;
                const uint FIRST_TEXEL_TO_COPY_IN_ROW = 25U;
                const uint NUM_ROWS_TO_COPY           = 5U;
                const uint FIRST_ROW_TO_COPY          = 1U;
                const uint SRC_MIP_INDEX      = 0U;
                const uint DST_MIP_INDEX      = 2U;
                const uint DST_WRITE_OFFSET_X = 15U;
                const uint DST_WRITE_OFFSET_Y = 2U;

                const float DATA_VALUE_START_R_ROW_ADDITION = (float)WIDTH_TX;
                const float DATA_VALUE_START_R = FIRST_TEXEL_TO_COPY_IN_ROW + DATA_VALUE_START_R_ROW_ADDITION * FIRST_ROW_TO_COPY;

                TexelFormat.RGBA32Float[] initialData = Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX, HEIGHT_TX))
                                                        .Select(i => new TexelFormat.RGBA32Float {
                    R = (float)i, G = (float)i * 2f, B = (float)i * 4f, A = (float)i * 8f
                })
                                                        .ToArray();

                Texture2D <TexelFormat.RGBA32Float> srcTex = TextureFactory.NewTexture2D <TexelFormat.RGBA32Float>()
                                                             .WithDynamicDetail(false)
                                                             .WithMultisampling(false)
                                                             .WithInitialData(initialData)
                                                             .WithMipAllocation(true)
                                                             .WithMipGenerationTarget(false)
                                                             .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                             .WithUsage(ResourceUsage.Immutable)
                                                             .WithWidth(WIDTH_TX)
                                                             .WithHeight(HEIGHT_TX);

                // Set up context

                // Execute
                Texture2D <TexelFormat.RGBA32Float> dstTex = srcTex.Clone()
                                                             .WithUsage(ResourceUsage.StagingRead)
                                                             .WithPermittedBindings(GPUBindings.None);
                SubresourceBox targetBox = new SubresourceBox(
                    FIRST_TEXEL_TO_COPY_IN_ROW, FIRST_TEXEL_TO_COPY_IN_ROW + NUM_TEXELS_TO_COPY_PER_ROW,
                    FIRST_ROW_TO_COPY, FIRST_ROW_TO_COPY + NUM_ROWS_TO_COPY
                    );
                srcTex.CopyTo(
                    dstTex,
                    targetBox,
                    SRC_MIP_INDEX,
                    DST_MIP_INDEX,
                    DST_WRITE_OFFSET_X,
                    DST_WRITE_OFFSET_Y
                    );

                // Assert outcome
                TexelArray2D <TexelFormat.RGBA32Float> copiedData = dstTex.Read(DST_MIP_INDEX);
                for (int v = 0; v < NUM_ROWS_TO_COPY; ++v)
                {
                    for (int u = 0; u < NUM_TEXELS_TO_COPY_PER_ROW; ++u)
                    {
                        var thisTexel = copiedData[u + (int)DST_WRITE_OFFSET_X, v + (int)DST_WRITE_OFFSET_Y];
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u), thisTexel.R);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 2f, thisTexel.G);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 4f, thisTexel.B);
                        Assert.AreEqual((float)(DATA_VALUE_START_R + DATA_VALUE_START_R_ROW_ADDITION * v + u) * 8f, thisTexel.A);
                    }
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
        public unsafe void TestSetShaderResourceViews()
        {
            Texture2DBuilder <TexelFormat.RGBA32UInt> texBuilder = TextureFactory.NewTexture2D <TexelFormat.RGBA32UInt>()
                                                                   .WithWidth(100U)
                                                                   .WithHeight(100U)
                                                                   .WithUsage(ResourceUsage.DiscardWrite);
            Texture2D <TexelFormat.RGBA32UInt> tex0 = texBuilder.Create();
            Texture2D <TexelFormat.RGBA32UInt> tex2 = texBuilder.Create();

            BaseResourceView rv0 = tex0.CreateView();
            BaseResourceView rv2 = tex2.CreateView();

            Shader shader = new FragmentShader(
                @"Tests\SimpleFS.cso",
                new ResourceViewBinding(0U, "RV0"),
                new ResourceViewBinding(1U, "RV1"),
                new ResourceViewBinding(2U, "RV2")
                );

            Dictionary <ResourceViewBinding, BaseResourceView> rvDict = new Dictionary <ResourceViewBinding, BaseResourceView>();

            rvDict[shader.ResourceViewBindings[0]] = rv0;
            rvDict[shader.ResourceViewBindings[2]] = rv2;

            RenderCommand testCommand = RenderCommand.SetShaderResourceViews(shader, rvDict);

            Assert.AreEqual(RenderCommandInstruction.FSSetResources, testCommand.Instruction);
            ResourceViewHandle *resHandleArray = (ResourceViewHandle *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg1, sizeof(long)));

            Assert.AreEqual(rv0.ResourceViewHandle, resHandleArray[0]);
            Assert.AreEqual(ResourceViewHandle.NULL, resHandleArray[1]);
            Assert.AreEqual(rv2.ResourceViewHandle, resHandleArray[2]);
            Assert.AreEqual((RenderCommandArgument)3U, testCommand.Arg2);

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderResourceViews(null, rvDict);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }

            try {
                RenderCommand.SetShaderResourceViews(shader, null);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            tex0.Dispose();
            tex2.Dispose();
            rv0.Dispose();
            rv2.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderResourceViews(shader, rvDict);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            shader.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderResourceViews(shader, new Dictionary <ResourceViewBinding, BaseResourceView>());
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }
        public unsafe void TestSetRenderTargets()
        {
            Texture2DArray <TexelFormat.RenderTarget> backBufferArray = TextureFactory.NewTexture2D <TexelFormat.RenderTarget>()
                                                                        .WithWidth(800U)
                                                                        .WithHeight(600U)
                                                                        .WithDynamicDetail(false)
                                                                        .WithMipAllocation(false)
                                                                        .WithMipGenerationTarget(false)
                                                                        .WithMultisampling(false)
                                                                        .WithPermittedBindings(GPUBindings.RenderTarget)
                                                                        .WithUsage(ResourceUsage.Write)
                                                                        .CreateArray(RenderCommand.MAX_RENDER_TARGETS + 1U);

            Texture2D <TexelFormat.DepthStencil> depthStencil = backBufferArray.Clone()
                                                                .WithTexelFormat <TexelFormat.DepthStencil>()
                                                                .WithPermittedBindings(GPUBindings.DepthStencilTarget);

            RenderTargetView[] rtvArr = backBufferArray.Select(tex => tex.CreateRenderTargetView(0U)).ToArray();
            DepthStencilView   dsv    = depthStencil.CreateDepthStencilView(0U);

            RenderCommand testCommand = RenderCommand.SetRenderTargets(dsv, rtvArr.Take((int)RenderCommand.MAX_RENDER_TARGETS).ToArray());

            Assert.AreEqual(RenderCommandInstruction.SetRenderTargets, testCommand.Instruction);
            RenderTargetViewHandle *rtvArrPtr
                = (RenderTargetViewHandle *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg1, sizeof(long)));

            for (int i = 0; i < RenderCommand.MAX_RENDER_TARGETS; ++i)
            {
                Assert.AreEqual(rtvArr[i].ResourceViewHandle, rtvArrPtr[i]);
            }
            Assert.AreEqual(
                dsv.ResourceViewHandle,
                UnsafeUtils.Reinterpret <IntPtr, DepthStencilViewHandle>(new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg2, sizeof(long))), sizeof(DepthStencilViewHandle))
                );
            Assert.AreEqual((RenderCommandArgument)RenderCommand.MAX_RENDER_TARGETS, testCommand.Arg3);

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetRenderTargets(null as DepthStencilView, rtvArr.Take((int)RenderCommand.MAX_RENDER_TARGETS).ToArray());
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }

            try {
                RenderCommand.SetRenderTargets(dsv, null);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }

            try {
                RenderCommand.SetRenderTargets(dsv, rtvArr[0], rtvArr[1], null, rtvArr[2]);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }

            try {
                RenderCommand.SetRenderTargets(dsv, rtvArr);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            rtvArr.ForEach(rtv => rtv.Dispose());
            dsv.Dispose();
            backBufferArray.Dispose();
            depthStencil.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetRenderTargets(dsv, rtvArr.Take((int)RenderCommand.MAX_RENDER_TARGETS).ToArray());
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }
        public void TestCreateDefaultViewForTextures()
        {
            const uint         TEST_TEXTURE_WIDTH  = 128U;
            const uint         TEST_TEXTURE_HEIGHT = 64U;
            const uint         TEST_TEXTURE_DEPTH  = 32U;
            const uint         TEST_ARRAY_LEN      = 10U;
            IResource          testResource;
            ShaderResourceView testSRV;

            testResource = TextureFactory.NewTexture1D <TexelFormat.RGB32Float>()
                           .WithDynamicDetail(false)
                           .WithMipAllocation(true)
                           .WithMipGenerationTarget(false)
                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                           .WithUsage(ResourceUsage.Write)
                           .WithWidth(TEST_TEXTURE_WIDTH)
                           .Create();
            testSRV = ((ITexture)testResource).CreateView();
            Assert.IsFalse(testSRV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testSRV.Resource);
            Assert.AreEqual(0U, ((ShaderTextureResourceView)testSRV).FirstMipIndex);
            Assert.AreEqual(TextureUtils.GetNumMips(TEST_TEXTURE_WIDTH), ((ShaderTextureResourceView)testSRV).NumMips);
            testResource.Dispose();
            Assert.IsTrue(testSRV.ResourceOrViewDisposed);
            testSRV.Dispose();
            Assert.IsTrue(testSRV.IsDisposed);

            testResource = TextureFactory.NewTexture2D <TexelFormat.RGB32Float>()
                           .WithDynamicDetail(false)
                           .WithMipAllocation(true)
                           .WithMipGenerationTarget(false)
                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                           .WithUsage(ResourceUsage.Write)
                           .WithWidth(TEST_TEXTURE_WIDTH)
                           .WithHeight(TEST_TEXTURE_HEIGHT)
                           .Create();
            testSRV = ((ITexture)testResource).CreateView();
            Assert.IsFalse(testSRV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testSRV.Resource);
            Assert.AreEqual(0U, ((ShaderTextureResourceView)testSRV).FirstMipIndex);
            Assert.AreEqual(TextureUtils.GetNumMips(TEST_TEXTURE_WIDTH, TEST_TEXTURE_HEIGHT), ((ShaderTextureResourceView)testSRV).NumMips);
            testResource.Dispose();
            Assert.IsTrue(testSRV.ResourceOrViewDisposed);
            testSRV.Dispose();
            Assert.IsTrue(testSRV.IsDisposed);

            testResource = TextureFactory.NewTexture3D <TexelFormat.RGB32Float>()
                           .WithDynamicDetail(false)
                           .WithMipAllocation(true)
                           .WithMipGenerationTarget(false)
                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                           .WithUsage(ResourceUsage.Write)
                           .WithWidth(TEST_TEXTURE_WIDTH)
                           .WithHeight(TEST_TEXTURE_HEIGHT)
                           .WithDepth(TEST_TEXTURE_DEPTH)
                           .Create();
            testSRV = ((ITexture)testResource).CreateView();
            Assert.IsFalse(testSRV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testSRV.Resource);
            Assert.AreEqual(0U, ((ShaderTextureResourceView)testSRV).FirstMipIndex);
            Assert.AreEqual(TextureUtils.GetNumMips(TEST_TEXTURE_WIDTH, TEST_TEXTURE_HEIGHT, TEST_TEXTURE_DEPTH), ((ShaderTextureResourceView)testSRV).NumMips);
            testResource.Dispose();
            Assert.IsTrue(testSRV.ResourceOrViewDisposed);
            testSRV.Dispose();
            Assert.IsTrue(testSRV.IsDisposed);

            testResource = TextureFactory.NewTexture1D <TexelFormat.RGB32Float>()
                           .WithDynamicDetail(false)
                           .WithMipAllocation(true)
                           .WithMipGenerationTarget(false)
                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                           .WithUsage(ResourceUsage.Write)
                           .WithWidth(TEST_TEXTURE_WIDTH)
                           .CreateArray(TEST_ARRAY_LEN);
            testSRV = ((ITextureArray)testResource).CreateView();
            Assert.IsFalse(testSRV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testSRV.Resource);
            Assert.AreEqual(0U, ((ShaderTextureArrayResourceView)testSRV).FirstMipIndex);
            Assert.AreEqual(TextureUtils.GetNumMips(TEST_TEXTURE_WIDTH), ((ShaderTextureArrayResourceView)testSRV).NumMips);
            Assert.AreEqual(0U, ((ShaderTextureArrayResourceView)testSRV).FirstArrayElementIndex);
            Assert.AreEqual(TEST_ARRAY_LEN, ((ShaderTextureArrayResourceView)testSRV).NumArrayElements);
            testResource.Dispose();
            Assert.IsTrue(testSRV.ResourceOrViewDisposed);
            testSRV.Dispose();
            Assert.IsTrue(testSRV.IsDisposed);

            testResource = TextureFactory.NewTexture2D <TexelFormat.RGB32Float>()
                           .WithDynamicDetail(false)
                           .WithMipAllocation(true)
                           .WithMipGenerationTarget(false)
                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                           .WithUsage(ResourceUsage.Write)
                           .WithWidth(TEST_TEXTURE_WIDTH)
                           .WithHeight(TEST_TEXTURE_HEIGHT)
                           .CreateArray(TEST_ARRAY_LEN);
            testSRV = ((ITextureArray)testResource).CreateView();
            Assert.IsFalse(testSRV.ResourceOrViewDisposed);
            Assert.AreEqual(testResource, testSRV.Resource);
            Assert.AreEqual(0U, ((ShaderTextureArrayResourceView)testSRV).FirstMipIndex);
            Assert.AreEqual(TextureUtils.GetNumMips(TEST_TEXTURE_WIDTH, TEST_TEXTURE_HEIGHT), ((ShaderTextureArrayResourceView)testSRV).NumMips);
            Assert.AreEqual(0U, ((ShaderTextureArrayResourceView)testSRV).FirstArrayElementIndex);
            Assert.AreEqual(TEST_ARRAY_LEN, ((ShaderTextureArrayResourceView)testSRV).NumArrayElements);
            testResource.Dispose();
            Assert.IsTrue(testSRV.ResourceOrViewDisposed);
            testSRV.Dispose();
            Assert.IsTrue(testSRV.IsDisposed);
        }
Example #15
0
        public void TestCreationWithInitialData()
        {
            // Define variables and constants
            const uint TEXTURE_WIDTH  = 1 << 6;
            const uint TEXTURE_HEIGHT = 1 << 4;
            Texture2DBuilder <TexelFormat.RGBA8UInt> texBuilder = TextureFactory.NewTexture2D <TexelFormat.RGBA8UInt>()
                                                                  .WithUsage(ResourceUsage.StagingRead)
                                                                  .WithPermittedBindings(GPUBindings.None)
                                                                  .WithWidth(TEXTURE_WIDTH)
                                                                  .WithHeight(TEXTURE_HEIGHT);

            TexelFormat.RGBA8UInt[]           initialDataA = new TexelFormat.RGBA8UInt[TEXTURE_WIDTH * TEXTURE_HEIGHT];
            TexelFormat.RGBA8UInt[]           initialDataB = new TexelFormat.RGBA8UInt[TextureUtils.GetSizeTexels(true, TEXTURE_WIDTH, TEXTURE_HEIGHT)];
            Texture2D <TexelFormat.RGBA8UInt> testTextureA, testTextureB;

            TexelArray2D <TexelFormat.RGBA8UInt> texAData;

            TexelArray2D <TexelFormat.RGBA8UInt>[] texBData = new TexelArray2D <TexelFormat.RGBA8UInt> [TextureUtils.GetNumMips(TEXTURE_WIDTH, TEXTURE_HEIGHT)];

            // Set up context
            for (uint i = 0; i < initialDataA.Length; ++i)
            {
                initialDataA[i].R = (byte)i;
                initialDataA[i].G = (byte)(i * 2);
                initialDataA[i].B = (byte)(i * 3);
                initialDataA[i].A = (byte)(i * 4);
            }
            testTextureA = texBuilder.WithInitialData(initialDataA).Create();

            uint mipWidth   = TEXTURE_WIDTH;
            uint mipHeight  = TEXTURE_HEIGHT;
            uint texelIndex = 0U;

            while (mipWidth > 1U || mipHeight > 1U)
            {
                for (uint v = 0; v < mipHeight; ++v)
                {
                    for (uint u = 0; u < mipWidth; ++u, ++texelIndex)
                    {
                        initialDataB[texelIndex].R = (byte)(u + mipWidth + v + mipHeight);
                        initialDataB[texelIndex].G = (byte)(u + mipWidth + v + mipHeight * 2);
                        initialDataB[texelIndex].B = (byte)(u + mipWidth + v + mipHeight * 3);
                        initialDataB[texelIndex].A = (byte)(u + mipWidth + v + mipHeight * 4);
                    }
                }
                mipWidth  = Math.Max(1U, mipWidth >> 1);
                mipHeight = Math.Max(1U, mipHeight >> 1);
            }
            initialDataB[initialDataB.Length - 1] = new TexelFormat.RGBA8UInt {
                R = 2, G = 3, B = 4, A = 5
            };
            testTextureB = texBuilder.WithMipAllocation(true).WithInitialData(initialDataB).Create();

            // Execute
            texAData = testTextureA.Read(0U);
            for (uint i = 0; i < texBData.Length; ++i)
            {
                texBData[i] = testTextureB.Read(i);
            }

            // Assert outcome
            for (uint i = 0; i < texAData.Width; ++i)
            {
                Assert.AreEqual((byte)i, initialDataA[i].R);
                Assert.AreEqual((byte)(i * 2), initialDataA[i].G);
                Assert.AreEqual((byte)(i * 3), initialDataA[i].B);
                Assert.AreEqual((byte)(i * 4), initialDataA[i].A);
            }

            for (uint mipIndex = 0U; mipIndex < testTextureB.NumMips; ++mipIndex)
            {
                for (uint v = 0; v < testTextureB.MipHeight(mipIndex); ++v)
                {
                    for (uint u = 0; u < testTextureB.MipWidth(mipIndex); ++u)
                    {
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex)), texBData[mipIndex][u, v].R);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 2), texBData[mipIndex][u, v].G);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 3), texBData[mipIndex][u, v].B);
                        Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) * 4), texBData[mipIndex][u, v].A);
                    }
                }
            }

            testTextureA.Dispose();
            testTextureB.Dispose();
        }
Example #16
0
        public void TestCreationParameters()
        {
            // Define variables and constants
            var defaultBuilder        = TextureFactory.NewTexture2D <TexelFormat.RGBA32UInt>().WithUsage(ResourceUsage.DiscardWrite).WithWidth(100).WithHeight(256);
            var withStagingUsage      = defaultBuilder.WithUsage(ResourceUsage.StagingReadWrite).WithPermittedBindings(GPUBindings.None);
            var withReadWriteBindings = defaultBuilder.WithUsage(ResourceUsage.Write).WithPermittedBindings(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource);
            var withDifferentFormat   = defaultBuilder.WithTexelFormat <TexelFormat.Int8>();
            var withWidth300          = defaultBuilder.WithWidth(300);
            var withMipAllocation     = defaultBuilder.WithUsage(ResourceUsage.Write).WithWidth(1 << 9).WithMipAllocation(true);
            var withDynDetail         = withMipAllocation.WithDynamicDetail(true);
            var withMipGen            = withMipAllocation
                                        .WithUsage(ResourceUsage.Write)
                                        .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                                        .WithMipGenerationTarget(true)
                                        .WithTexelFormat <TexelFormat.RGBA8UNorm>();
            var withMS = defaultBuilder.WithMultisampling(true);

            // Set up context

            // Execute

            // Assert outcome
            ITexture2D tex = withStagingUsage.Create();

            Assert.AreEqual(ResourceUsage.StagingReadWrite, tex.Usage);
            tex.Dispose();
            tex = withReadWriteBindings.Create();
            tex.Dispose();
            Assert.AreEqual(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource, tex.PermittedBindings);
            tex = withDifferentFormat.Create();
            tex.Dispose();
            Assert.AreEqual(typeof(TexelFormat.Int8), tex.TexelFormat);
            tex = withWidth300.Create();
            tex.Dispose();
            Assert.AreEqual(300U, tex.Width);
            tex = withMipAllocation.Create();
            tex.Dispose();
            Assert.AreEqual(TextureUtils.GetNumMips(1 << 9, 256), tex.NumMips);
            tex = withDynDetail.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsGlobalDetailTarget);
            tex = withMipGen.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsMipGenTarget);
            tex = withMS.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsMultisampled);
            tex.Dispose();

            ITexture2DArray ta = withStagingUsage.CreateArray(10);

            Assert.AreEqual(ResourceUsage.StagingReadWrite, ta.Usage);
            ta.Dispose();
            ta = withReadWriteBindings.CreateArray(10);
            Assert.AreEqual(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource, ta.PermittedBindings);
            ta.Dispose();
            ta = withDifferentFormat.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(typeof(TexelFormat.Int8), ta.TexelFormat);
            ta.Dispose();
            ta = withWidth300.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(300U, ta.Width);
            ta.Dispose();
            ta = withMipAllocation.CreateArray(10);
            Assert.AreEqual(TextureUtils.GetNumMips(1 << 9, 256), ta.NumMips);
            ta.Dispose();
            ta = withDynDetail.CreateArray(10);
            Assert.AreEqual(true, ta.IsGlobalDetailTarget);
            ta.Dispose();
            ta = withMipGen.CreateArray(10);
            Assert.AreEqual(true, ta.IsMipGenTarget);
            ta.Dispose();
            ta = withMS.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(true, ta.IsMultisampled);
            ta.Dispose();

            ta = defaultBuilder.WithUsage(ResourceUsage.Immutable).WithInitialData(new TexelFormat.RGBA32UInt[10U * 100U * 256U]).CreateArray(10);
            Assert.AreEqual(10U, ta.ArrayLength);
            ta.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.Immutable)
                .WithInitialData(null)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.DiscardWrite)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.StagingRead)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithWidth(0U)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(140)
                .WithHeight(1U)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[1 << 4])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(32U)
                .WithHeight(32U)
                .WithMultisampling(true)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithWidth(2U)
                .WithHeight(2U)
                .WithMultisampling(true)
                .WithInitialData(new TexelFormat.Float32[4])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }