|
|
@@ -129,38 +129,34 @@ class UniformsGroup extends UniformBuffer {
|
|
|
*/
|
|
|
get byteLength() {
|
|
|
|
|
|
+ const bytesPerElement = this.bytesPerElement;
|
|
|
+
|
|
|
let offset = 0; // global buffer offset in bytes
|
|
|
|
|
|
for ( let i = 0, l = this.uniforms.length; i < l; i ++ ) {
|
|
|
|
|
|
const uniform = this.uniforms[ i ];
|
|
|
|
|
|
- const { boundary, itemSize } = uniform;
|
|
|
-
|
|
|
- // offset within a single chunk in bytes
|
|
|
-
|
|
|
- const chunkOffset = offset % GPU_CHUNK_BYTES;
|
|
|
- const remainingSizeInChunk = GPU_CHUNK_BYTES - chunkOffset;
|
|
|
-
|
|
|
- // conformance tests
|
|
|
-
|
|
|
- if ( chunkOffset !== 0 && ( remainingSizeInChunk - boundary ) < 0 ) {
|
|
|
-
|
|
|
- // check for chunk overflow
|
|
|
+ const boundary = uniform.boundary;
|
|
|
+ const itemSize = uniform.itemSize * bytesPerElement; // size of the uniform in bytes
|
|
|
|
|
|
- offset += ( GPU_CHUNK_BYTES - chunkOffset );
|
|
|
+ const chunkOffset = offset % GPU_CHUNK_BYTES; // offset in the current chunk
|
|
|
+ const chunkPadding = chunkOffset % boundary; // required padding to match boundary
|
|
|
+ const chunkStart = chunkOffset + chunkPadding; // start position in the current chunk for the data
|
|
|
|
|
|
- } else if ( chunkOffset % boundary !== 0 ) {
|
|
|
+ offset += chunkPadding;
|
|
|
|
|
|
- // check for correct alignment
|
|
|
+ // Check for chunk overflow
|
|
|
+ if ( chunkStart !== 0 && ( GPU_CHUNK_BYTES - chunkStart ) < itemSize ) {
|
|
|
|
|
|
- offset += ( chunkOffset % boundary );
|
|
|
+ // Add padding to the end of the chunk
|
|
|
+ offset += ( GPU_CHUNK_BYTES - chunkStart );
|
|
|
|
|
|
}
|
|
|
|
|
|
- uniform.offset = ( offset / this.bytesPerElement );
|
|
|
+ uniform.offset = offset / bytesPerElement;
|
|
|
|
|
|
- offset += ( itemSize * this.bytesPerElement );
|
|
|
+ offset += itemSize;
|
|
|
|
|
|
}
|
|
|
|