Skip to content

Commit 8e332b6

Browse files
committed
fix(WebGPU): update to account for changes in webgpu
Deal with deprecation of [[block]] and handle firefox validation of UBO sizes to be a multiple of alignment Also fix a bug with mixing geometry and volumes under webgpu
1 parent bec9cb3 commit 8e332b6

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Sources/Rendering/WebGPU/StorageBuffer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function vtkWebGPUStorageBuffer(publicAPI, model) {
172172
}
173173
lines.push(`
174174
};
175-
[[block]] struct ${model.name}Struct
175+
struct ${model.name}Struct
176176
{
177177
values: array<${model.name}StructEntry>;
178178
};

Sources/Rendering/WebGPU/UniformBuffer/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
4646
let currOffset = 0;
4747
const newEntries = [];
4848

49+
// compute the max alignment, this is required as WebGPU defines a UBO to have
50+
// a size that is a multiple of the maxAlignment
51+
let maxAlignment = 4;
52+
for (let i = 0; i < model.bufferEntries.length; i++) {
53+
const entry = model.bufferEntries[i];
54+
if (entry.sizeInBytes % 16 === 0) {
55+
maxAlignment = Math.max(16, maxAlignment);
56+
}
57+
if (entry.sizeInBytes % 8 === 0) {
58+
maxAlignment = Math.max(8, maxAlignment);
59+
}
60+
}
61+
4962
// pack anything whose size is a multiple of 16 bytes first
5063
// this includes a couple types that don't require 16 byte alignment
5164
// such as mat2x2<f32> but that is OK
@@ -169,6 +182,8 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
169182
model._bufferEntryNames.set(model.bufferEntries[i].name, i);
170183
}
171184
model.sizeInBytes = currOffset;
185+
model.sizeInBytes =
186+
maxAlignment * Math.ceil(model.sizeInBytes / maxAlignment);
172187
model.sortDirty = false;
173188
};
174189

@@ -266,7 +281,7 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
266281
// sort the entries
267282
publicAPI.sortBufferEntries();
268283

269-
const lines = [`[[block]] struct ${model.name}Struct\n{`];
284+
const lines = [`struct ${model.name}Struct\n{`];
270285
for (let i = 0; i < model.bufferEntries.length; i++) {
271286
const entry = model.bufferEntries[i];
272287
lines.push(` ${entry.name}: ${entry.type};`);

Sources/Rendering/WebGPU/VolumePass/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ function vtkWebGPUVolumePass(publicAPI, model) {
275275
code,
276276
'//VTK::RenderEncoder::Impl',
277277
[
278-
'output.outColor1 = vec4<f32>(stopval, 0.0, 0.0, 0.0);',
279-
'output.outColor2 = vec4<f32>(input.fragPos.z, 0.0, 0.0, 0.0);',
278+
'output.outColor1 = vec4<f32>(input.fragPos.z, 0.0, 0.0, 0.0);',
279+
'output.outColor2 = vec4<f32>(stopval, 0.0, 0.0, 0.0);',
280280
]
281281
).result;
282282
fDesc.setCode(code);

0 commit comments

Comments
 (0)