From ffcbac4ac0221f1b5146d3a69570635d01239efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 21 Jun 2026 20:02:03 -0700 Subject: [PATCH] D3D11/WebGPU: Fixed vertex pulling draw count. Guard WebGPU getPipeline stream loop. (#3775) --- src/renderer_d3d11.cpp | 5 +++++ src/renderer_webgpu.cpp | 37 +++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index dcb2695b5..3eee5f96e 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -6456,6 +6456,11 @@ namespace bgfx { namespace d3d11 } } + if (UINT32_MAX == draw.m_streamMask) + { + currentNumVertices = draw.m_numVertices; + } + if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx || currentState.isIndex16() != draw.isIndex16() ) { diff --git a/src/renderer_webgpu.cpp b/src/renderer_webgpu.cpp index 4e0f319f6..5fc832412 100644 --- a/src/renderer_webgpu.cpp +++ b/src/renderer_webgpu.cpp @@ -2742,17 +2742,20 @@ WGPU_IMPORT murmur.add(program.m_fsh->m_hash); } - for (BitMaskToIndexIteratorT it(_streamMask); !it.isDone(); it.next() ) + if (UINT32_MAX != _streamMask) { - const uint8_t idx = it.idx; + for (BitMaskToIndexIteratorT it(_streamMask); !it.isDone(); it.next() ) + { + const uint8_t idx = it.idx; - uint16_t handle = _stream[idx].m_handle.idx; - const VertexBufferWGPU& vb = m_vertexBuffers[handle]; - const uint16_t layoutIdx = isValid(_stream[idx].m_layoutHandle) - ? _stream[idx].m_layoutHandle.idx - : vb.m_layoutHandle.idx; + uint16_t handle = _stream[idx].m_handle.idx; + const VertexBufferWGPU& vb = m_vertexBuffers[handle]; + const uint16_t layoutIdx = isValid(_stream[idx].m_layoutHandle) + ? _stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; - murmur.add(m_vertexLayouts[layoutIdx].m_hash); + murmur.add(m_vertexLayouts[layoutIdx].m_hash); + } } murmur.add(layout.m_attributes, sizeof(layout.m_attributes) ); @@ -3036,7 +3039,8 @@ WGPU_IMPORT const Binding& bind = _renderBind.m_bind[stage]; const ShaderBinding& shaderBind = _program.m_shaderBinding[stage]; - if (isValid(shaderBind.uniformHandle) ) + if (isValid(shaderBind.uniformHandle) + && kInvalidHandle != bind.m_idx) { switch (bind.m_type) { @@ -5536,8 +5540,6 @@ m_resolution.formatColor = TextureFormat::BGRA8; currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); - uint32_t currentNumVertices = 0; - static ViewState viewState; viewState.reset(_render); @@ -5976,8 +5978,6 @@ m_resolution.formatColor = TextureFormat::BGRA8; bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - currentNumVertices = draw.m_numVertices; - const uint64_t state = draw.m_stateFlags; const RenderPipeline& renderPipeline = *getPipeline( @@ -6217,7 +6217,16 @@ m_resolution.formatColor = TextureFormat::BGRA8; if (0 != currentState.m_streamMask) { - uint32_t numVertices = currentNumVertices; + uint32_t numVertices = draw.m_numVertices; + + if (UINT32_MAX == numVertices) + { + const VertexBufferWGPU& vb = m_vertexBuffers[currentState.m_stream[0].m_handle.idx]; + const uint16_t decl = isValid(draw.m_stream[0].m_layoutHandle) ? draw.m_stream[0].m_layoutHandle.idx : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[decl]; + numVertices = vb.m_size/layout.m_stride; + } + uint32_t numIndices = 0; uint32_t numPrimsSubmitted = 0; uint32_t numInstances = 0;