Implemented BGFX_SAMPLER_SAMPLE_STENCIL in all backends. (#3884)

This commit is contained in:
Branimir Karadžić
2026-08-13 15:38:58 -07:00
committed by GitHub
parent 3d3b08778e
commit 56ef37bcf8
12 changed files with 465 additions and 82 deletions
+36 -16
View File
@@ -3390,8 +3390,11 @@ namespace bgfx { namespace d3d11
case TextureD3D11::TextureCube:
desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
desc.Texture2DArray.ArraySize = 6;
desc.Texture2DArray.FirstArraySlice = 0;
desc.Texture2DArray.ArraySize = arrayed
? bx::max<uint16_t>(_numLayers, 1)
: uint16_t(bx::max<uint16_t>(texture.m_numLayers, 1) * 6)
;
desc.Texture2DArray.FirstArraySlice = _firstLayer;
desc.Texture2DArray.MipSlice = _mip;
break;
@@ -3443,9 +3446,11 @@ namespace bgfx { namespace d3d11
const bool msaaSample = 1 < msaa.Count && 0 != (texture.m_flags&BGFX_TEXTURE_MSAA_SAMPLE);
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
desc.Format = _stencil
? DXGI_FORMAT_X24_TYPELESS_G8_UINT
: texture.getSrvFormat()
desc.Format = !_stencil
? texture.getSrvFormat()
: (DXGI_FORMAT_R32G8X24_TYPELESS == s_textureFormat[texture.m_textureFormat].m_fmt
? DXGI_FORMAT_X32_TYPELESS_G8X24_UINT
: DXGI_FORMAT_X24_TYPELESS_G8_UINT)
;
switch (texture.m_type)
@@ -3689,7 +3694,13 @@ namespace bgfx { namespace d3d11
const Rect fbRect(0, 0, bx::narrowCast<uint16_t>(width), bx::narrowCast<uint16_t>(height) );
if (_rect.isEqual(fbRect) )
const bool discreteClear = true
&& isValid(m_fbh)
&& !m_frameBuffers[m_fbh.idx].m_needsQuadClear
;
if (_rect.isEqual(fbRect)
&& discreteClear)
{
clear(_clear, _palette);
}
@@ -5335,14 +5346,19 @@ namespace bgfx { namespace d3d11
&& numLayers == m_numLayers
;
if (0 != (_flags & BGFX_SAMPLER_SAMPLE_STENCIL) )
const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
? _flags
: uint32_t(m_flags)
;
if (0 != (flags & BGFX_SAMPLER_SAMPLE_STENCIL) )
{
ts.m_srv[_stage] = s_renderD3D11->getCachedSrv(
TextureHandle{ uint16_t(this - s_renderD3D11->m_textures) }
, 0
, 1
, 0
, UINT16_MAX
, _firstMip
, numMips
, _firstLayer
, numLayers
, false
, true
);
@@ -5362,10 +5378,6 @@ namespace bgfx { namespace d3d11
ts.m_srv[_stage] = m_srv;
}
const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
? _flags
: uint32_t(m_flags)
;
uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT;
ts.m_sampler[_stage] = s_renderD3D11->getSamplerState(flags, _palette[index]);
}
@@ -5377,10 +5389,15 @@ namespace bgfx { namespace d3d11
const bool needResolve = NULL != m_rt;
if (needResolve)
{
const DXGI_FORMAT resolveFormat = bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) )
? s_textureFormat[m_textureFormat].m_fmt
: getSrvFormat()
;
for (uint32_t ii = _layer, end = _layer + _numLayers; ii < end; ++ii)
{
const UINT resource = _mip + (ii * m_numMips);
deviceCtx->ResolveSubresource(m_texture2d, resource, m_rt, resource, s_textureFormat[m_textureFormat].m_fmt);
deviceCtx->ResolveSubresource(m_texture2d, resource, m_rt, resource, resolveFormat);
}
}
@@ -5544,6 +5561,7 @@ namespace bgfx { namespace d3d11
{
m_width = 0;
m_height = 0;
m_needsQuadClear = false;
if (0 < m_numTh)
{
@@ -5723,6 +5741,8 @@ namespace bgfx { namespace d3d11
desc.Texture3D.FirstWSlice = at.layer;
desc.Texture3D.WSize = at.numLayers;
m_needsQuadClear = true;
DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) );
break;
}