Ejemplo n.º 1
0
        public void TestMipDimensions()
        {
            // Define variables and constants
            const uint ORIGINAL_WIDTH_TX = 1 << 10;
            Texture1DArray <TexelFormat.RGBA32UInt> textureArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                                   .WithWidth(ORIGINAL_WIDTH_TX)
                                                                   .WithMipAllocation(true)
                                                                   .WithUsage(ResourceUsage.Write)
                                                                   .CreateArray(10);

            // Set up context


            // Execute
            for (int i = 0; ORIGINAL_WIDTH_TX >> i > 0; ++i)
            {
                Assert.AreEqual(ORIGINAL_WIDTH_TX >> i, textureArray.MipWidth((uint)i));
            }

#if !DEVELOPMENT && !RELEASE
            try {
                textureArray.MipWidth(10000U);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            // Assert outcome
            textureArray.Dispose();
        }
Ejemplo n.º 2
0
        public void TestReadAndReadAll()
        {
            // Define variables and constants
            const uint WIDTH_TX = 512U;

            Texture1D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32Int>()
                                                       .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_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);

            TexelFormat.RGBA32Int[] readAllData = srcTex.ReadAll();
            for (int i = 0, curMipIndex = 0; i < readAllData.Length; ++curMipIndex)
            {
                var readData = srcTex.Read((uint)curMipIndex);
                for (int j = 0; j < readData.Width; ++j, ++i)
                {
                    Assert.AreEqual(readData[j], readAllData[i]);
                }
            }

            srcTex.Dispose();
        }
Ejemplo n.º 3
0
        public void TestSubresIndex()
        {
            // Define variables and constants
            Texture1D <TexelFormat.RGBA32UInt> texture = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                         .WithWidth(1 << 5)
                                                         .WithMipAllocation(true)
                                                         .WithUsage(ResourceUsage.Write);

            // Set up context


            // Execute
            Assert.AreEqual(texture.GetSubresourceIndex(0U), 0U);
            Assert.AreEqual(texture.GetSubresourceIndex(1U), 1U);
            Assert.AreEqual(texture.GetSubresourceIndex(2U), 2U);

#if !DEVELOPMENT && !RELEASE
            try {
                texture.GetSubresourceIndex(10000U);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            // Assert outcome
            texture.Dispose();
        }
Ejemplo n.º 4
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX = 512U;

                const uint NUM_TEXELS_TO_COPY  = 25U;
                const uint FIRST_TEXEL_TO_COPY = 25U;
                const uint SRC_MIP_INDEX       = 1U;
                const uint DST_MIP_INDEX       = 3U;
                const uint DST_WRITE_OFFSET    = 15U;
                const uint DATA_VALUE_START_R  = 512U + FIRST_TEXEL_TO_COPY;

                Texture1D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32Int>()
                                                           .WithDynamicDetail(false)
                                                           .WithInitialData(
                    Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX))
                    .Select(i => new TexelFormat.RGBA32Int {
                    R = i, G = i * 2, B = i * 3, A = i * 4
                })
                    .ToArray()
                    )
                                                           .WithMipAllocation(true)
                                                           .WithMipGenerationTarget(false)
                                                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                           .WithUsage(ResourceUsage.Immutable)
                                                           .WithWidth(WIDTH_TX);

                // Set up context


                // Execute
                Texture1D <TexelFormat.RGBA32Int> dstTex = srcTex.Clone()
                                                           .WithUsage(ResourceUsage.StagingRead)
                                                           .WithPermittedBindings(GPUBindings.None);
                srcTex.CopyTo(
                    dstTex,
                    new SubresourceBox(FIRST_TEXEL_TO_COPY, FIRST_TEXEL_TO_COPY + NUM_TEXELS_TO_COPY),
                    SRC_MIP_INDEX,
                    DST_MIP_INDEX,
                    DST_WRITE_OFFSET
                    );

                // Assert outcome
                TexelArray1D <TexelFormat.RGBA32Int> copiedData = dstTex.Read(DST_MIP_INDEX);
                for (int i = 0; i < NUM_TEXELS_TO_COPY; ++i)
                {
                    Assert.AreEqual(DATA_VALUE_START_R + i, copiedData[i + (int)DST_WRITE_OFFSET].R);
                    Assert.AreEqual((DATA_VALUE_START_R + i) * 2, copiedData[i + (int)DST_WRITE_OFFSET].G);
                    Assert.AreEqual((DATA_VALUE_START_R + i) * 3, copiedData[i + (int)DST_WRITE_OFFSET].B);
                    Assert.AreEqual((DATA_VALUE_START_R + i) * 4, copiedData[i + (int)DST_WRITE_OFFSET].A);
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Ejemplo n.º 5
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint MIP0_WIDTH   = 512U;
                const uint ARRAY_LENGTH = 10U;
                Texture1DArray <TexelFormat.RGBA32UInt> srcArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                                   .WithDynamicDetail(false)
                                                                   .WithInitialData(
                    Enumerable.Repeat(
                        Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, MIP0_WIDTH))
                        .Select(i => (uint)i)
                        .Select(i => new TexelFormat.RGBA32UInt {
                    R = i, G = i * 2, B = i * 3, A = i * 4
                }),
                        (int)ARRAY_LENGTH
                        )
                    .Flatten()
                    .ToArray()
                    )
                                                                   .WithMipAllocation(true)
                                                                   .WithMipGenerationTarget(false)
                                                                   .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                                   .WithUsage(ResourceUsage.Immutable)
                                                                   .WithMipAllocation(true)
                                                                   .WithUsage(ResourceUsage.Write)
                                                                   .WithWidth(MIP0_WIDTH)
                                                                   .CreateArray(ARRAY_LENGTH);

                // Set up context
                Texture1DArray <TexelFormat.RGBA32UInt> dstArray = srcArray.Clone()
                                                                   .WithUsage(ResourceUsage.StagingRead)
                                                                   .WithPermittedBindings(GPUBindings.None)
                                                                   .CreateArray(srcArray.ArrayLength);

                srcArray.CopyTo(dstArray);

                var data = dstArray[4].ReadAll();

                // Execute
                for (int i = 0, curMipIndex = 0; i < data.Length; ++curMipIndex)
                {
                    for (int j = 0; j < dstArray.MipWidth((uint)curMipIndex); ++j, ++i)
                    {
                        Assert.AreEqual((uint)i, data[i].R);
                        Assert.AreEqual((uint)i * 2, data[i].G);
                        Assert.AreEqual((uint)i * 3, data[i].B);
                        Assert.AreEqual((uint)i * 4, data[i].A);
                    }
                }

                // Assert outcome
                srcArray.Dispose();
                dstArray.Dispose();
            });
        }
Ejemplo n.º 6
0
        public void TestWrite()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX = 512U;

                const uint TARGET_MIP_INDEX = 1U;
                const uint WRITE_OFFSET     = 30U;
                const int NUM_TX_TO_WRITE   = 198;

                Texture1D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32Int>()
                                                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                           .WithMipAllocation(true)
                                                           .WithDynamicDetail(true)
                                                           .WithUsage(ResourceUsage.Write)
                                                           .WithWidth(WIDTH_TX);

                // Set up context


                // Execute
                srcTex.Write(
                    Enumerable.Range(0, NUM_TX_TO_WRITE)
                    .Select(i => new TexelFormat.RGBA32Int {
                    R = i, G = i * 2, B = i * 3, A = i * 4
                })
                    .ToArray(),
                    TARGET_MIP_INDEX,
                    WRITE_OFFSET
                    );

                Texture1D <TexelFormat.RGBA32Int> dstTex = srcTex.Clone()
                                                           .WithDynamicDetail(false)
                                                           .WithUsage(ResourceUsage.StagingRead)
                                                           .WithPermittedBindings(GPUBindings.None);

                srcTex.CopyTo(dstTex);

                // Assert outcome
                TexelArray1D <TexelFormat.RGBA32Int> copiedData = dstTex.Read(TARGET_MIP_INDEX);
                for (int i = 0; i < NUM_TX_TO_WRITE; ++i)
                {
                    Assert.AreEqual(i, copiedData[i + (int)WRITE_OFFSET].R);
                    Assert.AreEqual(i * 2, copiedData[i + (int)WRITE_OFFSET].G);
                    Assert.AreEqual(i * 3, copiedData[i + (int)WRITE_OFFSET].B);
                    Assert.AreEqual(i * 4, copiedData[i + (int)WRITE_OFFSET].A);
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Ejemplo n.º 7
0
        public void TestArrayElementsAreIdentical()
        {
            // Define variables and constants
            const uint MIP0_WIDTH   = 512U;
            const uint ARRAY_LENGTH = 10U;
            Texture1DArray <TexelFormat.RGBA32UInt> srcArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                               .WithDynamicDetail(true)
                                                               .WithInitialData(
                Enumerable.Repeat(
                    Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, MIP0_WIDTH))
                    .Select(i => (uint)i)
                    .Select(i => new TexelFormat.RGBA32UInt {
                R = i, G = i * 2, B = i * 3, A = i * 4
            }),
                    (int)ARRAY_LENGTH
                    )
                .Flatten()
                .ToArray()
                )
                                                               .WithMipAllocation(true)
                                                               .WithMipGenerationTarget(false)
                                                               .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                               .WithUsage(ResourceUsage.Immutable)
                                                               .WithMipAllocation(true)
                                                               .WithUsage(ResourceUsage.Write)
                                                               .WithWidth(MIP0_WIDTH)
                                                               .CreateArray(ARRAY_LENGTH);

            // Set up context


            // Execute


            // Assert outcome
            foreach (Texture1D <TexelFormat.RGBA32UInt> arrayElement in srcArray)
            {
                Assert.AreEqual(srcArray.IsGlobalDetailTarget, arrayElement.IsGlobalDetailTarget);
                Assert.AreEqual(srcArray.IsMipGenTarget, arrayElement.IsMipGenTarget);
                Assert.AreEqual(srcArray.IsMipmapped, arrayElement.IsMipmapped);
                Assert.AreEqual(srcArray.NumMips, arrayElement.NumMips);
                Assert.AreEqual(srcArray.PermittedBindings, arrayElement.PermittedBindings);
                Assert.AreEqual(srcArray.Size / srcArray.ArrayLength, arrayElement.Size);
                Assert.AreEqual(srcArray.TexelFormat, arrayElement.TexelFormat);
                Assert.AreEqual(srcArray.TexelSizeBytes, arrayElement.TexelSizeBytes);
                Assert.AreEqual(srcArray.Usage, arrayElement.Usage);
                Assert.AreEqual(srcArray.Width, arrayElement.Width);
            }

            srcArray.Dispose();
        }
Ejemplo n.º 8
0
        public void TestClone()
        {
            // Define variables and constants
            const uint WIDTH_TX = 512U;
            Texture1D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32Int>()
                                                       .WithDynamicDetail(false)
                                                       .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX))
                .Select(i => new TexelFormat.RGBA32Int {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                       .WithMipAllocation(true)
                                                       .WithMipGenerationTarget(false)
                                                       .WithPermittedBindings(GPUBindings.None)
                                                       .WithUsage(ResourceUsage.StagingRead)
                                                       .WithWidth(WIDTH_TX);

            // Set up context


            // Execute
            Texture1D <TexelFormat.RGBA32Int> destNoCopy = srcTex.Clone(false);
            Texture1D <TexelFormat.RGBA32Int> 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);

            TexelFormat.RGBA32Int[] copiedData = destCopy.ReadAll();
            for (int i = 0; i < copiedData.Length; ++i)
            {
                Assert.AreEqual(i, copiedData[i].R);
                Assert.AreEqual(i * 2, copiedData[i].G);
                Assert.AreEqual(i * 3, copiedData[i].B);
                Assert.AreEqual(i * 4, copiedData[i].A);
            }

            srcTex.Dispose();
            destCopy.Dispose();
            destNoCopy.Dispose();
        }
Ejemplo n.º 9
0
        public void TestCloneWithInitData()
        {
            // Define variables and constants
            const uint MIP0_WIDTH   = 512U;
            const uint ARRAY_LENGTH = 10U;
            Texture1DArray <TexelFormat.RGBA32UInt> srcArray = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                               .WithDynamicDetail(false)
                                                               .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, MIP0_WIDTH) * (int)ARRAY_LENGTH)
                .Select(i => (uint)i)
                .Select(i => new TexelFormat.RGBA32UInt {
                R = i, G = i * 2, B = i * 3, A = i * 4
            })
                .ToArray()
                )
                                                               .WithMipAllocation(true)
                                                               .WithMipGenerationTarget(false)
                                                               .WithPermittedBindings(GPUBindings.None)
                                                               .WithUsage(ResourceUsage.StagingRead)
                                                               .WithWidth(MIP0_WIDTH)
                                                               .CreateArray(ARRAY_LENGTH);

            // Set up context


            // Execute
            var cloneArray = srcArray.Clone(true).CreateArray(ARRAY_LENGTH);

            // Assert outcome
            uint curVal = 0U;

            foreach (Texture1D <TexelFormat.RGBA32UInt> texture1D in cloneArray)
            {
                TexelFormat.RGBA32UInt[] texData = texture1D.ReadAll();
                for (int i = 0; i < texData.Length; i++)
                {
                    Assert.AreEqual(curVal, texData[i].R);
                    Assert.AreEqual(curVal * 2, texData[i].G);
                    Assert.AreEqual(curVal * 3, texData[i].B);
                    Assert.AreEqual(curVal * 4, texData[i].A);

                    ++curVal;
                }
            }

            cloneArray.Dispose();
            srcArray.Dispose();
        }
Ejemplo n.º 10
0
        public void TestReadWrite()
        {
            // Define variables and constants
            const uint WIDTH_TX          = 512U;
            const uint TARGET_MIP_INDEX  = 4U;
            const uint DATA_WRITE_OFFSET = 10U;
            const uint DATA_WRITE_COUNT  = 10U;

            Texture1D <TexelFormat.RGBA32UInt> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                        .WithInitialData(
                Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_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);

            srcTex.ReadWrite(data => {
                for (uint i = DATA_WRITE_OFFSET; i < DATA_WRITE_OFFSET + DATA_WRITE_COUNT; ++i)
                {
                    data[(int)i] = new TexelFormat.RGBA32UInt {
                        R = i, G = i * 3, B = i * 6, A = i * 9
                    };
                }
            },
                             TARGET_MIP_INDEX);

            var readData = srcTex.Read(TARGET_MIP_INDEX);

            for (uint i = DATA_WRITE_OFFSET; i < DATA_WRITE_OFFSET + DATA_WRITE_COUNT; ++i)
            {
                Assert.AreEqual(i, readData[(int)i].R);
                Assert.AreEqual(i * 3, readData[(int)i].G);
                Assert.AreEqual(i * 6, readData[(int)i].B);
                Assert.AreEqual(i * 9, readData[(int)i].A);
            }

            srcTex.Dispose();
        }
Ejemplo n.º 11
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX = 512U;
                Texture1D <TexelFormat.RGBA32Int> srcTex = TextureFactory.NewTexture1D <TexelFormat.RGBA32Int>()
                                                           .WithDynamicDetail(false)
                                                           .WithInitialData(
                    Enumerable.Range(0, (int)TextureUtils.GetSizeTexels(true, WIDTH_TX))
                    .Select(i => new TexelFormat.RGBA32Int {
                    R = i, G = i * 2, B = i * 3, A = i * 4
                })
                    .ToArray()
                    )
                                                           .WithMipAllocation(true)
                                                           .WithMipGenerationTarget(false)
                                                           .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                                                           .WithUsage(ResourceUsage.Immutable)
                                                           .WithWidth(WIDTH_TX);

                // Set up context


                // Execute
                Texture1D <TexelFormat.RGBA32Int> dstTex = srcTex.Clone()
                                                           .WithUsage(ResourceUsage.StagingRead)
                                                           .WithPermittedBindings(GPUBindings.None);
                srcTex.CopyTo(dstTex);

                // Assert outcome
                TexelFormat.RGBA32Int[] copiedData = dstTex.ReadAll();
                for (int i = 0; i < copiedData.Length; ++i)
                {
                    Assert.AreEqual(i, copiedData[i].R);
                    Assert.AreEqual(i * 2, copiedData[i].G);
                    Assert.AreEqual(i * 3, copiedData[i].B);
                    Assert.AreEqual(i * 4, copiedData[i].A);
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Ejemplo n.º 12
0
        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);
        }
        public void TestCreationWithInitialData()
        {
            // Define variables and constants
            const uint TEXTURE_WIDTH = 1 << 6;
            Texture1DBuilder <TexelFormat.RGBA8UInt> texBuilder = TextureFactory.NewTexture1D <TexelFormat.RGBA8UInt>()
                                                                  .WithUsage(ResourceUsage.StagingRead)
                                                                  .WithPermittedBindings(GPUBindings.None)
                                                                  .WithWidth(TEXTURE_WIDTH);

            TexelFormat.RGBA8UInt[]           initialDataA = new TexelFormat.RGBA8UInt[TEXTURE_WIDTH];
            TexelFormat.RGBA8UInt[]           initialDataB = new TexelFormat.RGBA8UInt[(TEXTURE_WIDTH << 1) - 1];
            Texture1D <TexelFormat.RGBA8UInt> testTextureA, testTextureB;

            TexelArray1D <TexelFormat.RGBA8UInt> texAData;

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

            // 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 texelIndex = 0U;

            while (mipWidth > 0)
            {
                for (uint i = 0; i < mipWidth; ++i, ++texelIndex)
                {
                    initialDataB[texelIndex].R = (byte)(i + mipWidth);
                    initialDataB[texelIndex].G = (byte)(i * 2 + mipWidth);
                    initialDataB[texelIndex].B = (byte)(i * 3 + mipWidth);
                    initialDataB[texelIndex].A = (byte)(i * 4 + mipWidth);
                }
                mipWidth >>= 1;
            }
            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);
            }

            mipWidth   = TEXTURE_WIDTH;
            texelIndex = 0U;
            while (mipWidth > 0)
            {
                for (uint i = 0; i < mipWidth; ++i, ++texelIndex)
                {
                    Assert.AreEqual((byte)(i + mipWidth), initialDataB[texelIndex].R);
                    Assert.AreEqual((byte)(i * 2 + mipWidth), initialDataB[texelIndex].G);
                    Assert.AreEqual((byte)(i * 3 + mipWidth), initialDataB[texelIndex].B);
                    Assert.AreEqual((byte)(i * 4 + mipWidth), initialDataB[texelIndex].A);
                }
                mipWidth >>= 1;
            }

            testTextureA.Dispose();
            testTextureB.Dispose();
        }
        public void TestCreationParameters()
        {
            // Define variables and constants
            var defaultBuilder        = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>().WithUsage(ResourceUsage.DiscardWrite).WithWidth(100);
            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>();

            // Set up context

            // Execute

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

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

            ITexture1DArray 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), 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 = defaultBuilder.WithUsage(ResourceUsage.Immutable).WithInitialData(new TexelFormat.RGBA32UInt[1000]).CreateArray(10);
            Assert.AreEqual(10U, ta.ArrayLength);
            ta.Dispose();

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