Example #1
0
        public static ResourceFlags Convert(TextureUsage usage, PixelFormat format)
        {
            var flags = ResourceFlags.None;

            if ((usage & TextureUsage.ShaderRead) == 0)
            {
                flags |= ResourceFlags.DenyShaderResource;
            }

            if ((usage & TextureUsage.ShaderWrite) != 0)
            {
                flags |= ResourceFlags.AllowUnorderedAccess;
            }

            if ((usage & TextureUsage.RenderTarget) != 0)
            {
                if (!PixelFormatUtil.IsDepthStencilFormat(format))
                {
                    flags |= ResourceFlags.AllowRenderTarget;
                }
                else
                {
                    flags |= ResourceFlags.AllowDepthStencil;
                }
            }

            return(flags);
        }
Example #2
0
        public static BindFlags ToDirectX(this TextureUsage usage, PixelFormat format)
        {
            var bindFlags = BindFlags.None;

            if ((usage & TextureUsage.ShaderRead) != 0)
            {
                bindFlags |= BindFlags.ShaderResource;
            }

            if ((usage & TextureUsage.ShaderWrite) != 0)
            {
                bindFlags |= BindFlags.UnorderedAccess;
            }

            if ((usage & TextureUsage.RenderTarget) != 0)
            {
                if (!PixelFormatUtil.IsDepthStencilFormat(format))
                {
                    bindFlags |= BindFlags.RenderTarget;
                }
                else
                {
                    bindFlags |= BindFlags.DepthStencil;
                }
            }

            return(bindFlags);
        }
Example #3
0
        public TextureViewD3D11(DeviceD3D11 device, TextureD3D11 texture, TextureViewDescriptor descriptor)
            : base(texture, descriptor)
        {
            Device = device;

            if ((texture.Usage & TextureUsage.RenderTarget) != TextureUsage.None)
            {
                // TODO: Use TextureViewDescriptor
                if (!PixelFormatUtil.IsDepthStencilFormat(descriptor.Format))
                {
                    RenderTargetView = device.D3D11Device.CreateRenderTargetView(texture);
                }
                else
                {
                    DepthStencilView = device.D3D11Device.CreateDepthStencilView(texture);
                }
            }
        }
Example #4
0
        public TextureD3D12(
            D3D12GraphicsDevice device,
            ref TextureDescriptor descriptor,
            ID3D12Resource nativeTexture)
            : base(device, ref descriptor)
        {
            DXGIFormat = descriptor.Format.ToDirectX();
            if (nativeTexture == null)
            {
                ResourceFlags resourceFlags = ResourceFlags.None;
                if ((descriptor.Usage & TextureUsage.ShaderWrite) != 0)
                {
                    resourceFlags |= ResourceFlags.AllowUnorderedAccess;
                }

                // A multisampled resource must have either D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET or
                // D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL set in D3D12_RESOURCE_DESC::Flags.
                if ((descriptor.Usage & TextureUsage.RenderTarget) != 0 ||
                    descriptor.Samples > 0 ||
                    !PixelFormatUtil.IsCompressed(descriptor.Format))
                {
                    if (PixelFormatUtil.IsDepthStencilFormat(descriptor.Format))
                    {
                        if ((descriptor.Usage & TextureUsage.ShaderRead) == 0)
                        {
                            resourceFlags |= ResourceFlags.DenyShaderResource;
                        }

                        resourceFlags |= ResourceFlags.AllowDepthStencil;
                    }
                    else
                    {
                        resourceFlags |= ResourceFlags.AllowRenderTarget;
                    }
                }
            }
            else
            {
                Resource = nativeTexture;
            }
        }