Metal/WebGPU: clearQuad — don't enable stencil ops when FB has no stencil. Closes #3310. (#3733)

This commit is contained in:
Branimir Karadžić
2026-06-06 22:59:27 -07:00
committed by GitHub
parent 9dc9749b53
commit ac6aa47b41
2 changed files with 34 additions and 0 deletions

View File

@@ -2301,6 +2301,30 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
return isValid(fb.m_depthHandle);
}
bool hasStencil(FrameBufferHandle _fbh)
{
if (!isValid(_fbh) )
{
return NULL != m_mainFrameBuffer.m_swapChain
&& NULL != m_mainFrameBuffer.m_swapChain->m_backBufferStencil
;
}
const FrameBufferMtl& fb = m_frameBuffers[_fbh.idx];
if (NULL != fb.m_swapChain)
{
return NULL != fb.m_swapChain->m_backBufferStencil;
}
if (!isValid(fb.m_depthHandle) )
{
return false;
}
const TextureMtl& depthTexture = m_textures[fb.m_depthHandle.idx];
return 0 < bimg::getBlockInfo(bimg::TextureFormat::Enum(depthTexture.m_textureFormat) ).stencilBits;
}
void setDepthStencilState(uint64_t _state, uint64_t _stencil = 0)
{
_state &= BGFX_STATE_WRITE_Z|BGFX_STATE_DEPTH_TEST_MASK;
@@ -2310,6 +2334,11 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
_state &= ~(BGFX_STATE_WRITE_Z|BGFX_STATE_DEPTH_TEST_MASK);
}
if (!hasStencil(m_fbh) )
{
_stencil = 0;
}
uint32_t fstencil = unpackStencil(0, _stencil);
uint32_t ref = (fstencil&BGFX_STENCIL_FUNC_REF_MASK)>>BGFX_STENCIL_FUNC_REF_SHIFT;

View File

@@ -3235,6 +3235,11 @@ WGPU_IMPORT
void setDepthStencilState(WGPUDepthStencilState& _outDepthStencilState, TextureFormat::Enum _format, uint64_t _state, uint64_t _stencil)
{
if (!hasStencil(_format) )
{
_stencil = 0;
}
_stencil = 0 == _stencil ? kStencilDisabled : _stencil;
const uint32_t fstencil = unpackStencil(0, _stencil);