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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(render): the probe block stays a constant buffer under ANGLE on D3D11
esengine82d9642f9025
diff --git a/src/esengine/renderer/frame/RenderContext.cpp b/src/esengine/renderer/frame/RenderContext.cppindex 95c4924d2..0548b37bd 100644--- a/src/esengine/renderer/frame/RenderContext.cpp+++ b/src/esengine/renderer/frame/RenderContext.cpp@@ -154,8 +154,7 @@ void RenderContext::initFrameUbo() {morphBlocks_.init(device_, static_cast<u32>(sizeof(MorphConstants)));// A run per instance, not one for the draw: the block is what a merged draw// says about every object in it, and GL wants the whole declared block bound.- probeBlocks_.init(device_,- static_cast<u32>(sizeof(ProbeConstants)) * PROBE_MAX_INSTANCES);+ probeBlocks_.init(device_, PROBE_BLOCK_BYTES);instanceBlocks_.init(device_, static_cast<u32>(sizeof(InstanceConstants)));// What a draw with no shapes and no volume reads. A pose has no zero: geometry// without one is drawn by a shader that does not declare the block.diff --git a/src/esengine/renderer/store/ProbeConstants.hpp b/src/esengine/renderer/store/ProbeConstants.hppindex 3474694bd..dc91fd9d3 100644--- a/src/esengine/renderer/store/ProbeConstants.hpp+++ b/src/esengine/renderer/store/ProbeConstants.hpp@@ -56,4 +56,15 @@ struct ProbeConstants {static_assert(sizeof(ProbeConstants) == 16 * PROBE_TEXELS,"ProbeConstants must be a tight array of vec4 to match std140");+/**+ * @brief Bytes the block is declared with: every run, then one vec4 that is not data.+ *+ * @details ANGLE on D3D11 turns a block whose only member is a large array into a+ * StructuredBuffer placed after the stage's texture registers. A lit material+ * under a reflection samples sixteen, so it lands out of range and Chrome's+ * GPU process aborts. A second member keeps the block a constant buffer.+ */+inline constexpr u32 PROBE_BLOCK_BYTES =+ static_cast<u32>(sizeof(ProbeConstants)) * PROBE_MAX_INSTANCES + 16;+} // namespace esenginediff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex 86f601808..1e38a0ed4 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -1029,7 +1029,7 @@ struct LightConstants {u_reflBox : array<vec4f, 30>,};@group(0) @binding(2) var<uniform> lc : LightConstants;-struct ProbeConstants { u_probeIrradiance : array<vec4f, 1000> };+struct ProbeConstants { u_probeIrradiance : array<vec4f, 1000>, u_probeTail : vec4f };@group(0) @binding(7) var<uniform> pc : ProbeConstants;// Which run of that block this fragment's instance reads. WGSL has no module// varying, so the entry point hands it over — the GLSL twin reads the varying@@ -1834,6 +1834,7 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p// volume" from "a probe in the dark"."layout(std140) uniform ProbeConstants {\n"" highp vec4 u_probeIrradiance[10 * 100];\n"+ " highp vec4 u_probeTail;\n" // see PROBE_BLOCK_BYTES"};\n""flat in highp float v_probeSlot;\n"// The shadow map rides the draw's third texture slot, behind the feature thediff --git a/tools/check-shader-blocks.mjs b/tools/check-shader-blocks.mjsindex cc1720158..7ebea5033 100644--- a/tools/check-shader-blocks.mjs+++ b/tools/check-shader-blocks.mjs@@ -231,6 +231,23 @@ for (const name of wgslFns.keys()) {if (!glslFns.has(name)) problems.push(`the helper ${name}() is WGSL-only — the GLSL twin has none`);}+/**+ * ANGLE on D3D11 compiles a block whose only member is an array of fifty or more into a+ * StructuredBuffer, placed after the stage's texture registers. These headers are the+ * fragment stage's, where a lit material already uses all sixteen: the register is out+ * of range and Chrome's GPU process aborts on the first draw.+ */+const ANGLE_STRUCTURED_BUFFER_MIN = 50;+for (const [, name, body] of glslText.matchAll(/layout\(std140\)\s+uniform\s+(\w+)\s*\{([^}]*)\}/g)) {+ const fields = body.split(';').map((f) => f.trim()).filter(Boolean);+ const array = fields.length === 1 ? /\[([^\]]+)\]$/.exec(fields[0]) : null;+ const length = array ? Number(resolve(`[${array[1]}]`).slice(1, -1)) : 0;+ if (length >= ANGLE_STRUCTURED_BUFFER_MIN) {+ problems.push(`${name}: its only member is an array of ${length}, which ANGLE turns into a`+ + ' StructuredBuffer on D3D11 — give the block a second member (see PROBE_BLOCK_BYTES)');+ }+}+if (problems.length > 0) {console.error('check-shader-blocks: the injected shader headers disagree:');for (const p of problems) console.error(` ${p}`);