You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(webgpu): pack multi-batch sprite flush into a single vertex upload
When a flush contained more than one batch (e.g. blend-mode change,
texture-slot overflow, or pipeline switch), every batch called
device.queue.writeBuffer(vertexBuffer, offset: 0, ...) before
queue.submit(commandBuffer). Per the WebGPU queue model, all
writeBuffer ops serialize before the submit — so only the LAST
batch's vertex data was actually in the buffer when the command
buffer ran. Every drawIndexed in the pass then read the same
(final) vertex range, and earlier batches rendered with the wrong
sprites' positions/UVs/colors.
Symptom on the blendmodes example: "Normal" renders correctly
(single batch), but any non-Normal blend mode produced a distorted
background (actually a bunny rendered at the background's draw slot)
and misplaced / missing bunnies.
Fix: walk the batches once before beginRenderPass, pack every
batch's vertices into the CPU-side vertex buffer at its own sprite
offset, and grow GPU buffers for the total sprite count. Then do a
single queue.writeBuffer for the whole packed region, and each
drawIndexed uses firstIndex = firstSprite * 6 to target its own
range. Pre-built quad indices (0,1,2,0,2,3 per sprite) already
match a linear sprite layout, so no per-batch index rewriting is
needed.
Also corrects _ensureBatchCapacity to size for total sprites in a
flush (was max-per-batch after the previous fix, which was correct
for avoiding in-loop growth but too small for the packed layout).
0 commit comments