public ResourcePoolEntry <DX11DepthStencil> Lock(int w, int h, eDepthFormat format, SampleDescription sd) { lock (lockObject) { foreach (ResourcePoolEntry <DX11DepthStencil> entry in this.pool) { DX11DepthStencil tr = entry.Element; if (!entry.IsLocked && tr.Width == w && tr.DepthFormat == format && tr.Height == h && tr.Texture.Description.SampleDescription.Count == sd.Count && tr.Texture.Description.SampleDescription.Quality == sd.Quality) { entry.Lock(); return(entry); } } DX11DepthStencil res = new DX11DepthStencil(this.device, w, h, sd, format); ResourcePoolEntry <DX11DepthStencil> newentry = new ResourcePoolEntry <DX11DepthStencil>(res); this.pool.Add(newentry); return(newentry); } }
public static Format GetStencilSRVFormat(this eDepthFormat depthformat) { switch (depthformat) { case eDepthFormat.d32: return(Format.Unknown); case eDepthFormat.d24s8: return(Format.X24_Typeless_G8_UInt); case eDepthFormat.d16: return(Format.Unknown); case eDepthFormat.d32s8: return(Format.X32_Typeless_G8X24_UInt); default: return(Format.Unknown); } }
public static Format GetSRVFormat(this eDepthFormat depthformat) { switch (depthformat) { case eDepthFormat.d32: return(Format.R32_Float); case eDepthFormat.d24s8: return(Format.R24_UNorm_X8_Typeless); case eDepthFormat.d16: return(Format.R16_UNorm); case eDepthFormat.d32s8: return(Format.R32_Float_X8X24_Typeless); default: return(Format.R32_Float); } }
public static Format GetDepthFormat(this eDepthFormat depthformat) { switch (depthformat) { case eDepthFormat.d32: return(Format.D32_Float); case eDepthFormat.d24s8: return(Format.D24_UNorm_S8_UInt); case eDepthFormat.d16: return(Format.D16_UNorm); case eDepthFormat.d32s8: return(Format.D32_Float_S8X24_UInt); default: return(Format.D32_Float); //Defaults as R32 } }
public static Format GetTypeLessFormat(this eDepthFormat depthformat) { switch (depthformat) { case eDepthFormat.d32: return(Format.R32_Typeless); case eDepthFormat.d24s8: return(Format.R24G8_Typeless); case eDepthFormat.d16: return(Format.R16_Typeless); case eDepthFormat.d32s8: return(Format.R32G8X24_Typeless); default: return(Format.R32_Typeless); } }
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 DX11SliceDepthStencil(DxDevice device, IDxTexture2D texture, int sliceindex, eDepthFormat depthformat) { this.device = device; this.parent = texture; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { Format = depthformat.GetDepthFormat(), Dimension = DepthStencilViewDimension.Texture2DArray, Texture2DArray = new DepthStencilViewDescription.Texture2DArrayResource() { ArraySize = 1, FirstArraySlice = sliceindex, MipSlice = 0 } }; this.DepthView = new DepthStencilView(device, this.parent.Texture, dsvd); }
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 DX11DepthStencil(DxDevice device, int w, int h, eDepthFormat depthformat = eDepthFormat.d24s8) : this(device, w, h, new SampleDescription(1, 0), 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); } }
public static bool HasStencil(this eDepthFormat depthformat) { return(depthformat == eDepthFormat.d24s8 || depthformat == eDepthFormat.d32s8); }
public ResourcePoolEntry <DX11DepthStencil> LockDepth(int w, int h, SampleDescription sd, eDepthFormat format) { return(this.depthpool.Lock(w, h, format, sd)); }