예제 #1
0
        protected override Resource GetStagingTexture(LayerMipmapSlice lm)
        {
            Debug.Assert(IO.SupportedFormats.Contains(Format) || Format == Format.R8_UInt);

            Debug.Assert(lm.Layer == 0);
            Debug.Assert(lm.IsIn(LayerMipmap));

            var mipDim = Size.GetMip(lm.Mipmap);
            var desc   = new Texture3DDescription
            {
                Width          = mipDim.Width,
                Height         = mipDim.Height,
                Depth          = mipDim.Depth,
                Format         = Format,
                MipLevels      = 1,
                BindFlags      = BindFlags.None,
                CpuAccessFlags = CpuAccessFlags.Read,
                OptionFlags    = ResourceOptionFlags.None,
                Usage          = ResourceUsage.Staging
            };

            // create staging texture
            var staging = new SharpDX.Direct3D11.Texture3D(Device.Get().Handle, desc);

            // copy data to staging texture
            Device.Get().CopySubresource(handle, staging, GetSubresourceIndex(lm), 0, mipDim);

            return(staging);
        }
예제 #2
0
        protected int GetSubresourceIndex(LayerMipmapSlice lm)
        {
            Debug.Assert(lm.IsIn(LayerMipmap));

            return(lm.Layer * LayerMipmap.Mipmaps + lm.Mipmap);
        }
예제 #3
0
        public void Run(ITexture src, ITexture dst, LayerMipmapSlice lm, UploadBuffer buffer, ITextureCache cache)
        {
            Debug.Assert(src.HasSameDimensions(dst));
            Debug.Assert(cache.IsCompatibleWith(src));
            Debug.Assert(lm.IsIn(src.LayerMipmap));

            var srcSize = src.Size.GetMip(lm.Mipmap);

            var dev = Device.Get();

            dev.Compute.Set(src.Is3D ? Shader3D.Compute : Shader.Compute);
            var builder = src.Is3D ? ShaderBuilder.Builder3D : ShaderBuilder.Builder2D;

            // execute x
            buffer.SetData(new BufferData
            {
                Size      = srcSize,
                Direction = new Size3(1, 0, 0),
                Layer     = lm.Layer
            });
            dev.Compute.SetConstantBuffer(0, buffer.Handle);
            dev.Compute.SetShaderResource(0, src.GetSrView(lm));
            var      tmp1 = cache.GetTexture();
            ITexture tmp2 = null;

            dev.Compute.SetUnorderedAccessView(0, tmp1.GetUaView(lm.Mipmap));

            dev.Dispatch(
                Utility.Utility.DivideRoundUp(srcSize.Width, builder.LocalSizeX),
                Utility.Utility.DivideRoundUp(srcSize.Height, builder.LocalSizeY),
                Utility.Utility.DivideRoundUp(srcSize.Depth, builder.LocalSizeZ)
                );

            UnbindResources(dev);

            // execute y
            buffer.SetData(new BufferData
            {
                Size      = srcSize,
                Direction = new Size3(0, 1, 0),
                Layer     = lm.Layer
            });
            dev.Compute.SetConstantBuffer(0, buffer.Handle);
            dev.Compute.SetShaderResource(0, tmp1.GetSrView(lm));
            if (src.Is3D)
            {
                tmp2 = cache.GetTexture();
                dev.Compute.SetUnorderedAccessView(0, tmp2.GetUaView(lm.Mipmap));

                dev.Dispatch(
                    Utility.Utility.DivideRoundUp(srcSize.Width, builder.LocalSizeX),
                    Utility.Utility.DivideRoundUp(srcSize.Height, builder.LocalSizeY),
                    Utility.Utility.DivideRoundUp(srcSize.Depth, builder.LocalSizeZ)
                    );

                UnbindResources(dev);

                // execute z
                buffer.SetData(new BufferData
                {
                    Size      = srcSize,
                    Direction = new Size3(0, 0, 1),
                    Layer     = lm.Layer
                });
                dev.Compute.SetConstantBuffer(0, buffer.Handle);
                dev.Compute.SetShaderResource(0, tmp2.GetSrView(lm));
            }

            // bind final target
            dev.Compute.SetUnorderedAccessView(0, dst.GetUaView(lm.Mipmap));

            dev.Dispatch(
                Utility.Utility.DivideRoundUp(srcSize.Width, builder.LocalSizeX),
                Utility.Utility.DivideRoundUp(srcSize.Height, builder.LocalSizeY),
                Utility.Utility.DivideRoundUp(srcSize.Depth, builder.LocalSizeZ)
                );

            UnbindResources(dev);
            cache.StoreTexture(tmp1);
            if (tmp2 != null)
            {
                cache.StoreTexture(tmp2);
            }
        }