public DX11DepthStencil(DxDevice device, int w, int h, SampleDescription sd, eDepthFormat depthformat = eDepthFormat.d24s8) { this.device = device; var depthBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = depthformat.GetTypeLessFormat(), Height = h, Width = w, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = sd, Usage = ResourceUsage.Default }; this.Texture = new Texture2D(device.Device, depthBufferDesc); this.resourceDesc = this.Texture.Description; this.DepthFormat = depthformat; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = depthformat.GetSRVFormat(), Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, }; if (sd.Count == 1) { srvd.Texture2D.MipLevels = 1; srvd.Texture2D.MostDetailedMip = 0; } this.ShaderView = new ShaderResourceView(device.Device, this.Texture, srvd); if (depthformat.HasStencil()) { ShaderResourceViewDescription stencild = new ShaderResourceViewDescription() { Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled, Format = depthformat.GetStencilSRVFormat(), }; if (sd.Count == 1) { stencild.Texture2D.MipLevels = 1; stencild.Texture2D.MostDetailedMip = 0; } ShaderResourceView stencilview = new ShaderResourceView(this.device.Device, this.Texture, stencild); this.Stencil = DX11Texture2D.FromReference(this.device, this.Texture, stencilview); } else { //Just pass depth instead this.Stencil = null; } DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = sd.Count == 1 ? DepthStencilViewDimension.Texture2D : DepthStencilViewDimension.Texture2DMultisampled, }; this.DepthView = new DepthStencilView(device.Device, this.Texture, dsvd); //Read only dsv only supported in dx11 minimum if (device.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (depthformat.HasStencil()) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyView = new DepthStencilView(device.Device, this.Texture, dsvd); } }
public DX11DepthTextureArray(DxDevice device, int w, int h, int elemcnt, eDepthFormat depthformat, bool buildslices = true) { this.device = device; this.DepthFormat = depthformat; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = depthformat.GetTypeLessFormat(), Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, }; this.Texture = new Texture2D(device, texBufferDesc); this.resourceDesc = this.Texture.Description; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Format = depthformat.GetSRVFormat(), Dimension = ShaderResourceViewDimension.Texture2DArray, Texture2DArray = new ShaderResourceViewDescription.Texture2DArrayResource() { ArraySize = elemcnt, FirstArraySlice = 0, MipLevels = 1, MostDetailedMip = 0 } }; this.ShaderView = new ShaderResourceView(device.Device, this.Texture, srvd); DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = DepthStencilViewDimension.Texture2DArray, Texture2DArray = new DepthStencilViewDescription.Texture2DArrayResource() { ArraySize = elemcnt, FirstArraySlice = 0, MipSlice = 0 } }; this.DepthView = new DepthStencilView(device, this.Texture, dsvd); dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (depthformat.HasStencil()) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyView = new DepthStencilView(device.Device, this.Texture, dsvd); this.SliceDepthView = new DX11SliceDepthStencil[this.ElementCount]; if (buildslices) { for (int i = 0; i < this.ElementCount; i++) { this.SliceDepthView[i] = new DX11SliceDepthStencil(this.device, this, i, depthformat); } } }
public DX11CubeDepthStencil(DxDevice device, int size, SampleDescription sd, eDepthFormat depthformat) { this.device = device; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = depthformat.GetTypeLessFormat(), Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, MipLevels = 1 }; this.Texture = new Texture2D(device, texBufferDesc); this.resourceDesc = this.Texture.Description; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = depthformat.GetSRVFormat(), TextureCube = new ShaderResourceViewDescription.TextureCubeResource() { MipLevels = 1, MostDetailedMip = 0 } }; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = DepthStencilViewDimension.Texture2DArray, Texture2DArray = new DepthStencilViewDescription.Texture2DArrayResource() { ArraySize = 6, FirstArraySlice = 0, MipSlice = 0 } }; this.DepthView = new DepthStencilView(device, this.Texture, dsvd); if (device.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (depthformat.HasStencil()) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyView = new DepthStencilView(device, this.Texture, dsvd); } this.ShaderView = new ShaderResourceView(device, this.Texture, svd); this.SliceDepthViews = new DX11SliceDepthStencil[6]; for (int i = 0; i < 6; i++) { this.SliceDepthViews[i] = new DX11SliceDepthStencil(device, this, i, depthformat); } }