Skip to content

Commit 3e09926

Browse files
committed
fix(renderer): derive SECTION_2D_UNIFORM_SLOT_COUNT from the slot index
SECTION_2D_UNIFORM_SLOT_COUNT sized the shared section-2D-overlay uniform buffer with a hand-written 6, while SECTION_2D_UNIFORM_SLOT_INDEX maps each draw site to its slot. Nothing tied the two together: a new key added to the index type-checks fine (a property access needs the key to compile) but the count doesn't grow with it, so the buffer stays one slot short and the new draw site's bind-group offset lands one record past the end. Derive the count from the index instead, and pin the two equal with a test so a future divergence fails a test rather than only surfacing as a WebGPU validation error on the new site. Refs #3342
1 parent 5a431e5 commit 3e09926

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ifc-lite/renderer': patch
3+
---
4+
5+
Derive `SECTION_2D_UNIFORM_SLOT_COUNT` from `Object.keys(SECTION_2D_UNIFORM_SLOT_INDEX).length` instead of a hand-written `6`, so adding a draw site to the index can no longer leave the shared uniform buffer one slot short of what the index addresses. A test pins the two values equal so a future divergence fails loudly instead of only showing up as a WebGPU bind-group validation error on the new draw site.

packages/renderer/src/section-2d-overlay-lifecycle.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ describe('Section2DOverlayRenderer: dispose releases EVERY family (#1277 leak)',
334334
});
335335
});
336336

337+
describe('SECTION_2D_UNIFORM_SLOT_COUNT (#3342)', () => {
338+
it('equals the number of entries in SECTION_2D_UNIFORM_SLOT_INDEX', () => {
339+
assert.strictEqual(
340+
SECTION_2D_UNIFORM_SLOT_COUNT,
341+
Object.keys(SECTION_2D_UNIFORM_SLOT_INDEX).length,
342+
);
343+
});
344+
});
345+
337346
describe('Section2DOverlayRenderer: shared uniform buffer', () => {
338347
function lastWrite(writes: Array<{ data: Float32Array }>): Float32Array {
339348
assert.ok(writes.length > 0, 'expected a uniform write');

packages/renderer/src/shaders/section-2d-overlay.wgsl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export const SECTION_2D_UNIFORM_SLOT_INDEX = {
8080
clashBox: 5,
8181
} as const;
8282

83-
/** How many uniform records the shared buffer holds. */
84-
export const SECTION_2D_UNIFORM_SLOT_COUNT = 6;
83+
/** How many uniform records the shared buffer holds — one per entry above. */
84+
export const SECTION_2D_UNIFORM_SLOT_COUNT = Object.keys(SECTION_2D_UNIFORM_SLOT_INDEX).length;
8585

8686
/**
8787
* Byte stride between uniform slots for `device`.

0 commit comments

Comments
 (0)