@@ -129,38 +129,34 @@ class UniformsGroup extends UniformBuffer {
129129 */
130130 get byteLength ( ) {
131131
132+ const bytesPerElement = this . bytesPerElement ;
133+
132134 let offset = 0 ; // global buffer offset in bytes
133135
134136 for ( let i = 0 , l = this . uniforms . length ; i < l ; i ++ ) {
135137
136138 const uniform = this . uniforms [ i ] ;
137139
138- const { boundary, itemSize } = uniform ;
139-
140- // offset within a single chunk in bytes
141-
142- const chunkOffset = offset % GPU_CHUNK_BYTES ;
143- const remainingSizeInChunk = GPU_CHUNK_BYTES - chunkOffset ;
144-
145- // conformance tests
146-
147- if ( chunkOffset !== 0 && ( remainingSizeInChunk - boundary ) < 0 ) {
148-
149- // check for chunk overflow
140+ const boundary = uniform . boundary ;
141+ const itemSize = uniform . itemSize * bytesPerElement ; // size of the uniform in bytes
150142
151- offset += ( GPU_CHUNK_BYTES - chunkOffset ) ;
143+ const chunkOffset = offset % GPU_CHUNK_BYTES ; // offset in the current chunk
144+ const chunkPadding = chunkOffset % boundary ; // required padding to match boundary
145+ const chunkStart = chunkOffset + chunkPadding ; // start position in the current chunk for the data
152146
153- } else if ( chunkOffset % boundary !== 0 ) {
147+ offset += chunkPadding ;
154148
155- // check for correct alignment
149+ // Check for chunk overflow
150+ if ( chunkStart !== 0 && ( GPU_CHUNK_BYTES - chunkStart ) < itemSize ) {
156151
157- offset += ( chunkOffset % boundary ) ;
152+ // Add padding to the end of the chunk
153+ offset += ( GPU_CHUNK_BYTES - chunkStart ) ;
158154
159155 }
160156
161- uniform . offset = ( offset / this . bytesPerElement ) ;
157+ uniform . offset = offset / bytesPerElement ;
162158
163- offset += ( itemSize * this . bytesPerElement ) ;
159+ offset += itemSize ;
164160
165161 }
166162
0 commit comments