Testing potential performance improvements from ideas from the post below found 3 potential bugs in webGPU, non-compatibility mode. BabylonJS 9.37.2. sand box and descriptions below.Tested in Chrome. Firefox gives different errors. We’ve worked around it locally for now, but it would be nice for it to just work right.
found while testing this: WebGPU: CPU cost per draw call in 9.29/9.30, and which small PRs would you welcome?
**
**1. Instance buffers that grow aren’t picked up**
Adding instances to a mesh after it was first drawn regrows its instance buffers (Mesh._processInstancedBuffers for custom instanced buffers, and the world-matrix buffer in _renderWithInstances / _updateInstancedBuffers). The old buffers are disposed but the draw context isn’t marked dirty, so the replayed bundle uses the destroyed buffer: [Buffer "..._Vertex_Storage_size512"] used in submit while destroyed, every frame. (332 errors in the repro above with non-compatibility mode, 0 with compatibility mode.) The selection outline code already calls resetDrawCache() after it changes instancedBuffers in this mode, so these two paths may just need the same.
**2. Replacing the vertex data of a mesh that was already drawn**
setVerticesData (and so bakeTransformIntoVertices) on a drawn mesh disposes the old vertex buffer, and the bundle keeps using it: [Buffer "...Geometry_..._position_..."] used in submit while destroyed (143 errors in the repro, 0 in compatibility mode). If users are expected to call mesh.resetDrawCache() after changing vertex data in this mode, note that bakeTransformIntoVertices splices the sub-meshes off while it calls setVerticesData and puts them back after, so a hook on the geometry finds no sub-meshes to reset: it has to be done after the bake.
**3. Depth pre-pass draws nothing (node material, two-sided, alpha blended)**
With needDepthPrePass = true the sub-mesh is drawn twice in one pass, color writes off then on. The color write doesn’t seem to be part of what makes a recorded bundle dirty, so the color draw replays the depth-only recording: no error, the mesh is just invisible. In our tests it needs a NodeMaterial, two-sided (backFaceCulling = false) and alpha blended; a StandardMaterial with the same settings draws fine. Our workaround: before each draw, compare engine.getColorWrite() with the colour write the current draw context was recorded with and mark it dirty when they differ.