Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void TestCopyTo()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 256U;
                const uint HEIGHT_TX = 32U;
                const uint DEPTH_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_PER_SLICE = 5U;
                const uint FIRST_ROW_TO_COPY_IN_SLICE = 1U;
                const uint NUM_SLICES_TO_COPY         = 10U;
                const uint FIRST_SLICE_TO_COPY        = 4U;
                const uint SRC_MIP_INDEX      = 1U;
                const uint DST_MIP_INDEX      = 1U;
                const uint DST_WRITE_OFFSET_X = 15U;
                const uint DST_WRITE_OFFSET_Y = 2U;
                const uint DST_WRITE_OFFSET_Z = 0U;

                const float DATA_VALUE_ADDITION_W = (float)(HEIGHT_TX >> 1) * (float)(WIDTH_TX >> 1);
                const float DATA_VALUE_ADDITION_V = (float)(WIDTH_TX >> 1);
                const float DATA_VALUE_START_R    =
                    WIDTH_TX * HEIGHT_TX * DEPTH_TX
                    + FIRST_TEXEL_TO_COPY_IN_ROW
                    + DATA_VALUE_ADDITION_V * FIRST_ROW_TO_COPY_IN_SLICE
                    + DATA_VALUE_ADDITION_W * FIRST_SLICE_TO_COPY;

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

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

                // Set up context

                // Execute
                Texture3D <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_IN_SLICE, FIRST_ROW_TO_COPY_IN_SLICE + NUM_ROWS_TO_COPY_PER_SLICE,
                    FIRST_SLICE_TO_COPY, FIRST_SLICE_TO_COPY + NUM_SLICES_TO_COPY
                    );
                srcTex.CopyTo(
                    dstTex,
                    targetBox,
                    SRC_MIP_INDEX,
                    DST_MIP_INDEX,
                    DST_WRITE_OFFSET_X,
                    DST_WRITE_OFFSET_Y,
                    DST_WRITE_OFFSET_Z
                    );

                // Assert outcome
                TexelArray3D <TexelFormat.RGBA32Float> copiedData = dstTex.Read(DST_MIP_INDEX);
                for (int w = 0; w < NUM_SLICES_TO_COPY; ++w)
                {
                    for (int v = 0; v < NUM_ROWS_TO_COPY_PER_SLICE; ++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, w + (int)DST_WRITE_OFFSET_Z];
                            Assert.AreEqual((float)(DATA_VALUE_START_R + u + v * DATA_VALUE_ADDITION_V + w * DATA_VALUE_ADDITION_W), thisTexel.R);
                            Assert.AreEqual((float)(DATA_VALUE_START_R + u + v * DATA_VALUE_ADDITION_V + w * DATA_VALUE_ADDITION_W) * 2f, thisTexel.G);
                            Assert.AreEqual((float)(DATA_VALUE_START_R + u + v * DATA_VALUE_ADDITION_V + w * DATA_VALUE_ADDITION_W) * 4f, thisTexel.B);
                            Assert.AreEqual((float)(DATA_VALUE_START_R + u + v * DATA_VALUE_ADDITION_V + w * DATA_VALUE_ADDITION_W) * 8f, thisTexel.A);
                        }
                    }
                }

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
Exemplo n.º 3
0
        public void TestWrite()
        {
            LosgapSystem.InvokeOnMaster(() => {
                // Define variables and constants
                const uint WIDTH_TX  = 100U;
                const uint HEIGHT_TX = 100U;
                const uint DEPTH_TX  = 100U;

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

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

                Texture3D <TexelFormat.RGBA8Int> srcTex = TextureFactory.NewTexture3D <TexelFormat.RGBA8Int>()
                                                          .WithUsage(ResourceUsage.Write)
                                                          .WithWidth(WIDTH_TX)
                                                          .WithHeight(HEIGHT_TX)
                                                          .WithDepth(DEPTH_TX);

                // Set up context


                // Execute
                var initData = 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();
                srcTex.Write(
                    initData,
                    writeTarget
                    );

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

                srcTex.CopyTo(dstTex);

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

                srcTex.Dispose();
                dstTex.Dispose();
            });
        }
        public void TestCreationWithInitialData()
        {
            // Define variables and constants
            const uint TEXTURE_WIDTH  = 1 << 6;
            const uint TEXTURE_HEIGHT = 1 << 4;
            const uint TEXTURE_DEPTH  = 1 << 3;
            Texture3DBuilder <TexelFormat.RGBA8UInt> texBuilder = TextureFactory.NewTexture3D <TexelFormat.RGBA8UInt>()
                                                                  .WithUsage(ResourceUsage.StagingRead)
                                                                  .WithPermittedBindings(GPUBindings.None)
                                                                  .WithWidth(TEXTURE_WIDTH)
                                                                  .WithHeight(TEXTURE_HEIGHT)
                                                                  .WithDepth(TEXTURE_DEPTH);

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

            TexelArray3D <TexelFormat.RGBA8UInt> texAData;

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

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

            while (mipWidth > 1U || mipHeight > 1U || mipDepth > 1U)
            {
                for (uint w = 0; w < mipDepth; ++w)
                {
                    for (uint v = 0; v < mipHeight; ++v)
                    {
                        for (uint u = 0; u < mipWidth; ++u, ++texelIndex)
                        {
                            initialDataB[texelIndex].R = (byte)(u + mipWidth + v + mipHeight + w + mipDepth);
                            initialDataB[texelIndex].G = (byte)(u + mipWidth + v + mipHeight + w + mipDepth * 2);
                            initialDataB[texelIndex].B = (byte)(u + mipWidth + v + mipHeight + w + mipDepth * 3);
                            initialDataB[texelIndex].A = (byte)(u + mipWidth + v + mipHeight + w + mipDepth * 4);
                        }
                    }
                }
                mipWidth  = Math.Max(1U, mipWidth >> 1);
                mipHeight = Math.Max(1U, mipHeight >> 1);
                mipDepth  = Math.Max(1U, mipDepth >> 1);
            }
            initialDataB[initialDataB.Length - 1] = new TexelFormat.RGBA8UInt {
                R = 3, G = 4, B = 5, A = 6
            };
            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 w = 0; w < testTextureB.MipDepth(mipIndex); ++w)
                {
                    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) + w + testTextureB.MipDepth(mipIndex)), texBData[mipIndex][u, v, w].R);
                            Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) + w + testTextureB.MipDepth(mipIndex) * 2), texBData[mipIndex][u, v, w].G);
                            Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) + w + testTextureB.MipDepth(mipIndex) * 3), texBData[mipIndex][u, v, w].B);
                            Assert.AreEqual((byte)(u + testTextureB.MipWidth(mipIndex) + v + testTextureB.MipHeight(mipIndex) + w + testTextureB.MipDepth(mipIndex) * 4), texBData[mipIndex][u, v, w].A);
                        }
                    }
                }
            }

            testTextureA.Dispose();
            testTextureB.Dispose();
        }
Exemplo n.º 5
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(TexelArray3D <TTexel> other)
 {
     return(Equals(Data, other.Data) && Width == other.Width && Height == other.Height && Depth == other.Depth);
 }