diff --git a/src/webgpu/shader/execution/expression/case_cache.ts b/src/webgpu/shader/execution/expression/case_cache.ts index daee31993161..a74223593bca 100644 --- a/src/webgpu/shader/execution/expression/case_cache.ts +++ b/src/webgpu/shader/execution/expression/case_cache.ts @@ -166,13 +166,13 @@ export class CaseCache implements Cacheable> { */ serialize(data: Record): Uint8Array { const maxSize = 32 << 20; // 32MB - max size for a file - const s = new BinaryStream(new Uint8Array(maxSize).buffer); - s.writeU32(Object.keys(data).length); + const stream = new BinaryStream(new ArrayBuffer(maxSize)); + stream.writeU32(Object.keys(data).length); for (const name in data) { - s.writeString(name); - s.writeArray(data[name], serializeCase); + stream.writeString(name); + stream.writeArray(data[name], serializeCase); } - return new Uint8Array(s.buffer()); + return new Uint8Array(stream.buffer()); } /** diff --git a/src/webgpu/util/binary_stream.ts b/src/webgpu/util/binary_stream.ts index 2b32db9b3e06..27b2a2788ccb 100644 --- a/src/webgpu/util/binary_stream.ts +++ b/src/webgpu/util/binary_stream.ts @@ -20,7 +20,7 @@ export default class BinaryStream { /** buffer() returns the stream's buffer sliced to the 8-byte rounded read or write offset */ buffer(): ArrayBufferLike { - return new Uint8Array(this.view.buffer, align(this.offset, 8)).buffer; + return new Uint8Array(this.view.buffer, 0, align(this.offset, 8)).buffer; } /** writeBool() writes a boolean as 255 or 0 to the buffer at the next byte offset */