Пример #1
0
        public unsafe void TestIndexAccessors()
        {
            // Define variables and constants
            const int WIDTH  = 4;
            const int HEIGHT = 8;
            const int DEPTH  = 2;

            TexelFormat.Int8[] data = new TexelFormat.Int8[WIDTH * HEIGHT * DEPTH];

            TexelArray1D <TexelFormat.Int8> array1D = new TexelArray1D <TexelFormat.Int8>(data);
            TexelArray2D <TexelFormat.Int8> array2D = new TexelArray2D <TexelFormat.Int8>(data, WIDTH);
            TexelArray3D <TexelFormat.Int8> array3D = new TexelArray3D <TexelFormat.Int8>(data, WIDTH, HEIGHT);

            // Set up context
            for (int i = 0; i < WIDTH * HEIGHT * DEPTH; ++i)
            {
                data[i].Value = (sbyte)i;
            }

            // Execute


            // Assert outcome
            Assert.AreEqual((sbyte)3, array1D[3].Value);
            Assert.AreEqual((sbyte)22, array2D[2, 5].Value);
            Assert.AreEqual((sbyte)54, array3D[2, 5, 1].Value);
        }
Пример #2
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();
            });
        }
Пример #3
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();
            });
        }
Пример #4
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(TexelArray1D <TTexel> other)
 {
     return(Equals(Data, other.Data) && Width == other.Width);
 }
        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();
        }