File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,16 @@ class Bindings extends DataMap {
224224
225225 }
226226
227+ if ( binding . isStorageBuffer ) {
228+
229+ const attribute = binding . attribute ;
230+ const attributeType = attribute . isIndirectStorageBufferAttribute ? AttributeType . INDIRECT : AttributeType . STORAGE ;
231+
232+ this . attributes . update ( attribute , attributeType ) ;
233+
234+
235+ }
236+
227237 if ( binding . isUniformBuffer ) {
228238
229239 const updated = binding . update ( ) ;
Original file line number Diff line number Diff line change @@ -109,6 +109,8 @@ class WebGPUAttributeUtils {
109109 bufferAttribute . itemSize = 4 ;
110110 bufferAttribute . array = array ;
111111
112+ bufferData . _force3to4BytesAlignment = true ;
113+
112114 }
113115
114116 const size = array . byteLength + ( ( 4 - ( array . byteLength % 4 ) ) % 4 ) ; // ensure 4 byte alignment, see #20441
@@ -142,9 +144,27 @@ class WebGPUAttributeUtils {
142144 const backend = this . backend ;
143145 const device = backend . device ;
144146
147+ const bufferData = backend . get ( bufferAttribute ) ;
145148 const buffer = backend . get ( bufferAttribute ) . buffer ;
146149
147- const array = bufferAttribute . array ;
150+ let array = bufferAttribute . array ;
151+
152+ // if storage buffer ensure 4 byte alignment
153+ if ( bufferData . _force3to4BytesAlignment === true ) {
154+
155+ array = new array . constructor ( bufferAttribute . count * 4 ) ;
156+
157+ for ( let i = 0 ; i < bufferAttribute . count ; i ++ ) {
158+
159+ array . set ( bufferAttribute . array . subarray ( i * 3 , i * 3 + 3 ) , i * 4 ) ;
160+
161+ }
162+
163+ bufferAttribute . array = array ;
164+
165+ }
166+
167+
148168 const isTypedArray = this . _isTypedArray ( array ) ;
149169 const updateRanges = bufferAttribute . updateRanges ;
150170
You can’t perform that action at this time.
0 commit comments