Beispiel #1
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();
        }
Beispiel #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();
        }
Beispiel #3
0
        public void TestMipDimensions()
        {
            // Define variables and constants
            const uint ORIGINAL_WIDTH_TX = 1 << 10;
            Texture1D <TexelFormat.RGBA32UInt> texture = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>()
                                                         .WithWidth(ORIGINAL_WIDTH_TX)
                                                         .WithMipAllocation(true)
                                                         .WithUsage(ResourceUsage.Write);

            // Set up context


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

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

            // Assert outcome
            texture.Dispose();
        }
Beispiel #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();
            });
        }
Beispiel #5
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();
            });
        }
Beispiel #6
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();
        }
Beispiel #7
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();
        }
Beispiel #8
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();
            });
        }
        /// <summary>
        /// Creates a new <see cref="Texture1D{TTexel}"/> with the supplied builder parameters.
        /// </summary>
        /// <remarks>
        /// In debug mode, this method will check a large number of <see cref="Assure">assurances</see>
        /// on the builder parameters before creating the resource.
        /// </remarks>
        /// <returns>A new <see cref="Texture1D{TTexel}"/>.</returns>
        public override Texture1D <TTexel> Create()
        {
            Texture1D <TTexel> result = new Texture1D <TTexel>(
                CreateTexture1D(1U, InitialData),
                Usage,
                TextureUtils.GetSize(texelSizeBytes, mipAllocation, width),
                permittedBindings,
                false,
                mipGenerationTarget,
                dynamicDetail,
                width,
                texelSizeBytes,
                mipAllocation,
                numMips,
                0U
                );

            if (dynamicDetail)
            {
                RenderingModule.DynamicDetailTextures.Value.Add(new WeakReference <IResource>(result));
            }
            return(result);
        }
Beispiel #10
0
        public void CopyTo(Texture1D <TTexel> dest, SubresourceBox srcRegion, uint srcMipIndex = 0U, uint dstMipIndex = 0U, uint destWriteOffsetX = 0U)
        {
            Assure.LessThan(
                srcMipIndex, NumMips,
                "Can not copy from mip level " + srcMipIndex + ": Only " + NumMips + " present in source texture."
                );
            Assure.LessThan(
                dstMipIndex, dest.NumMips,
                "Can not copy to mip level " + dstMipIndex + ": Only " + dest.NumMips + " present in destination texture."
                );
            Assure.LessThan(
                srcRegion.Left,
                MipWidth(srcMipIndex),
                "Buffer overflow: Please ensure you are not attempting to copy from past the end of the source texture."
                );
            Assure.LessThanOrEqualTo(
                srcRegion.Right,
                MipWidth(srcMipIndex),
                "Buffer overflow: Please ensure you are not attempting to copy from past the end of the source texture."
                );
            Assure.LessThanOrEqualTo(
                srcRegion.Width + destWriteOffsetX,
                dest.MipWidth(dstMipIndex),
                "Buffer overflow: Please ensure you are not attempting to copy to past the end of the destination texture."
                );

            base.CopyTo(
                dest,
                srcRegion,
                GetSubresourceIndex(srcMipIndex),
                dest.GetSubresourceIndex(dstMipIndex),
                destWriteOffsetX,
                0U,
                0U
                );
        }