Skip to content

Commit b7945d0

Browse files
committed
fix(Glyph3DMapper): avoid zero-sized glyph SSBO bindings
WebGPU Glyph3DMapper could create a zero-byte glyphSSBO when the glyph mapper had no instances. Dawn rejects bind groups that bind zero-sized storage buffers, which caused runtime validation failures during CreateBindGroup. This change keeps the draw count at zero but allocates a single dummy SSBO instance when numInstances === 0, initializing identity matrix/normal data and default color when needed. That preserves behavior while ensuring the storage buffer binding remains valid.
1 parent cc8a76e commit b7945d0

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

  • Sources/Rendering/WebGPU/Glyph3DMapper

Sources/Rendering/WebGPU/Glyph3DMapper/index.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,38 @@ function vtkWebGPUGlyph3DMapper(publicAPI, model) {
182182
);
183183
const device = model.WebGPURenderWindow.getDevice();
184184

185+
const ssboInstances = Math.max(model.numInstances, 1);
185186
model.SSBO.clearData();
186-
model.SSBO.setNumberOfInstances(model.numInstances);
187+
model.SSBO.setNumberOfInstances(ssboInstances);
187188
model.SSBO.addEntry('matrix', 'mat4x4<f32>');
188189
model.SSBO.addEntry('normal', 'mat4x4<f32>');
189190
if (model.carray) {
190191
model.SSBO.addEntry('color', 'vec4<f32>');
191192
}
192193

193-
model.SSBO.setAllInstancesFromArray('matrix', garray);
194-
model.SSBO.setAllInstancesFromArray3x3To4x4('normal', narray);
195-
if (model.carray) {
196-
model.SSBO.setAllInstancesFromArrayColorToFloat(
197-
'color',
198-
model.carray.getData()
194+
if (model.numInstances > 0) {
195+
model.SSBO.setAllInstancesFromArray('matrix', garray);
196+
model.SSBO.setAllInstancesFromArray3x3To4x4('normal', narray);
197+
if (model.carray) {
198+
model.SSBO.setAllInstancesFromArrayColorToFloat(
199+
'color',
200+
model.carray.getData()
201+
);
202+
}
203+
} else {
204+
model.SSBO.setArray(
205+
'matrix',
206+
0,
207+
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
208+
);
209+
model.SSBO.setArray(
210+
'normal',
211+
0,
212+
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
199213
);
214+
if (model.carray) {
215+
model.SSBO.setArray('color', 0, [1, 1, 1, 1]);
216+
}
200217
}
201218

202219
model.SSBO.send(device);

0 commit comments

Comments
 (0)