public DX11DepthStencil(DX11RenderContext context, int w, int h, SampleDescription sd, Format format) { this.context = context; var depthBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = h, Width = w, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default }; this.Resource = new Texture2D(context.Device, depthBufferDesc); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = 1, Format = DepthFormatsHelper.GetSRVFormat(format), Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); if (format == Format.D24_UNorm_S8_UInt || format == Format.D32_Float_S8X24_UInt) { ShaderResourceViewDescription stencild = new ShaderResourceViewDescription() { ArraySize = 1, Format = format == Format.D24_UNorm_S8_UInt ? SlimDX.DXGI.Format.X24_Typeless_G8_UInt : Format.X32_Typeless_G8X24_UInt, Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, MipLevels = 1, MostDetailedMip = 0 }; this.stencilview = new ShaderResourceView(this.context.Device, this.Resource, stencild); this.Stencil = DX11Texture2D.FromTextureAndSRV(this.context, this.Resource, this.stencilview); } else { //Just pass depth instead this.Stencil = DX11Texture2D.FromTextureAndSRV(this.context, this.Resource, this.SRV); } DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = DepthFormatsHelper.GetDepthFormat(format), Dimension = sd.Count == 1 ? DepthStencilViewDimension.Texture2D : DepthStencilViewDimension.Texture2DMultisampled, MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); //Read only dsv only supported in dx11 minimum if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt || format == Format.D32_Float_S8X24_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.desc = depthBufferDesc; this.isowner = true; }
public DX11DepthTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format, bool buildslices = true) { this.context = context; this.original = format; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, }; this.Resource = new Texture2D(context.Device, texBufferDesc); ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format), Dimension = DepthStencilViewDimension.Texture2DArray, MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); this.desc = texBufferDesc; this.SliceDSV = new DX11SliceDepthStencil[this.ElemCnt]; if (buildslices) { for (int i = 0; i < this.ElemCnt; i++) { this.SliceDSV[i] = new DX11SliceDepthStencil(this.context, this, i, DepthFormatsHelper.GetDepthFormat(format)); } } }
public DX11CubeDepthStencil(DX11RenderContext context, int size, SampleDescription sd, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, MipLevels = 1 }; this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.SliceDSV = new DX11SliceDepthStencil[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize = 6, Dimension = DepthStencilViewDimension.Texture2DArray, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format), MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); for (int i = 0; i < 6; i++) { this.SliceDSV[i] = new DX11SliceDepthStencil(context, this, i, DepthFormatsHelper.GetDepthFormat(format)); } }