Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(render): a uniform changed after its first upload reaches WebGPU draws

esengine1bc41058a092
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
index f88ddae1f..a6b2a8fda 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
@@ -692,8 +692,13 @@ void WebGPUDevice::resizeBuffer(BufferHandle buffer, u32 sizeBytes, const void*
if (it == buffers_.end()) return;
// The RHI contract: the handle stays stable across growth. WebGPU buffers are
- // fixed-size, so re-create the WGPUBuffer behind the same id.
- if (it->second.buffer) wgpuBufferRelease(it->second.buffer);
+ // fixed-size, so re-create the WGPUBuffer behind the same id. A cached bind
+ // group names the old WGPUBuffer, not the id, and would keep drawing its bytes.
+ if (it->second.buffer) {
+ evictBindGroups(static_cast<u64>(reinterpret_cast<uintptr_t>(it->second.buffer)));
+ wgpuBufferRelease(it->second.buffer);
+ }
+ bind_group_dirty_ = true;
WGPUBufferDescriptor bd{};
bd.usage = toWGPUBufferUsage(it->second.usage);
diff --git a/tools/render-host/run.mjs b/tools/render-host/run.mjs
index 6e204a05c..f828c8907 100644
--- a/tools/render-host/run.mjs
+++ b/tools/render-host/run.mjs
@@ -19,6 +19,7 @@
* ESTELLA_VERIFY_STEPS fixed-dt frames to advance before capture (default 30)
* ESTELLA_VERIFY_GRID editor-grid on/off pixel-diff assertion (value = spacing)
* ESTELLA_VERIFY_GRID_EXPECT what that diff must be: "frame" (default) or "nothing"
+ * ESTELLA_VERIFY_GRID_RESPACE respace the drawn grid; the frame must change with it
* ESTELLA_VERIFY_DEPTH_LAYERS bitmask of layers resolved by depth (2.5D)
* ESTELLA_VERIFY_RENDER_RESOLUTION render at the scene's own resolution and
* scale the finished image (1 = design, 2 = integer)
@@ -816,6 +817,22 @@ app.whenReady().then(async () => {
await writeFile(process.env.ESTELLA_VERIFY_GRID_OUT, Buffer.from(dataUrl.split(',')[1], 'base64'));
}
await readFrame('window.__estellaGridOn = px.slice(); return true;');
+ // ESTELLA_VERIFY_GRID_RESPACE: the spacing rides a material uniform the frames
+ // above already uploaded, so a backend that keeps binding the first upload
+ // draws the old grid again. The view does not move, so only the grid can differ.
+ let respaced = null;
+ if (process.env.ESTELLA_VERIFY_GRID_RESPACE) {
+ await exec(`window.__estellaHeadless.api.setGrid(true, ${Number(process.env.ESTELLA_VERIFY_GRID_RESPACE)})`);
+ await exec('window.__estellaHeadless.api.step(2, 1 / 60)');
+ respaced = await readFrame(`
+ const on = window.__estellaGridOn;
+ let differing = 0;
+ for (let i = 0; i < px.length; i += 4) {
+ if (Math.abs(on[i] - px[i]) + Math.abs(on[i + 1] - px[i + 1]) + Math.abs(on[i + 2] - px[i + 2]) > 12) differing++;
+ }
+ return differing;
+ `);
+ }
await exec('window.__estellaHeadless.api.setGrid(false)');
await exec('window.__estellaHeadless.api.step(2, 1 / 60)');
grid = await readFrame(`
@@ -846,6 +863,7 @@ app.whenReady().then(async () => {
ok: want === 'nothing' ? differing === 0 : want === 'grazing' ? lopsided : covers,
};
`);
+ if (respaced != null) grid = { ...grid, respacedPixels: respaced, ok: grid.ok && respaced > 300 };
}
finish({ ok: true, entityCount, missingAssets, drawCalls, draws, counters, profile, capture, expect, count, seam, resize, preview, meshPreview, grid, deviceLoss, meshResident, meshAsset, meshMaterial, meshPrefab, setField, animator, pick, cameraTarget }, server);
} catch (e) {
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index f90a25e87..fa34a5b85 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -63,6 +63,8 @@ export const SCENES = [
{ id: "sprite-batch", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/sprite-rendering.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/sprite-rendering.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_COUNTERS: "{\"render.sprites\":19,\"batch.draws\":3,\"batch.merged\":16,\"batch.break.runStart\":1,\"batch.break.indexGap\":2}" } },
// Editor grid on/off pixel diff — guards the custom-draw reflected material path (drawMeshWithMaterial + MaterialConstants UBO).
{ id: "editor-grid", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_STEPS: "3" } },
+ // The same grid respaced after it has drawn: a uniform changed after its first upload has to reach the frame, which on WebGPU it once did not (the grid stayed where the view first looked).
+ { id: "editor-grid-respace", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_GRID_RESPACE: "160", ESTELLA_VERIFY_STEPS: "3" } },
// The same grid from straight above a 3D view. It stands on the ground there, so it fills the frame; the 2D plane would be edge-on and light one band.
{ id: "editor-grid-3d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-instanced.esscene", ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_PERSPECTIVE: "1", ESTELLA_VERIFY_ORBIT: "0,90", ESTELLA_VERIFY_STEPS: "3" } },
// The same 3D view head-on, where this fixture's eye lies IN the ground: every