@@ -46,6 +46,19 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
46
46
let currOffset = 0 ;
47
47
const newEntries = [ ] ;
48
48
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
+
49
62
// pack anything whose size is a multiple of 16 bytes first
50
63
// this includes a couple types that don't require 16 byte alignment
51
64
// such as mat2x2<f32> but that is OK
@@ -169,6 +182,8 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
169
182
model . _bufferEntryNames . set ( model . bufferEntries [ i ] . name , i ) ;
170
183
}
171
184
model . sizeInBytes = currOffset ;
185
+ model . sizeInBytes =
186
+ maxAlignment * Math . ceil ( model . sizeInBytes / maxAlignment ) ;
172
187
model . sortDirty = false ;
173
188
} ;
174
189
@@ -266,7 +281,7 @@ function vtkWebGPUUniformBuffer(publicAPI, model) {
266
281
// sort the entries
267
282
publicAPI . sortBufferEntries ( ) ;
268
283
269
- const lines = [ `[[block]] struct ${ model . name } Struct\n{` ] ;
284
+ const lines = [ `struct ${ model . name } Struct\n{` ] ;
270
285
for ( let i = 0 ; i < model . bufferEntries . length ; i ++ ) {
271
286
const entry = model . bufferEntries [ i ] ;
272
287
lines . push ( ` ${ entry . name } : ${ entry . type } ;` ) ;
0 commit comments