diff --git a/src/webgpu/shader/execution/expression/case_cache.ts b/src/webgpu/shader/execution/expression/case_cache.ts index daee31993161..ff82792d647d 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 stream.buffer(); } /** diff --git a/src/webgpu/util/binary_stream.ts b/src/webgpu/util/binary_stream.ts index 2b32db9b3e06..a6512020e631 100644 --- a/src/webgpu/util/binary_stream.ts +++ b/src/webgpu/util/binary_stream.ts @@ -19,8 +19,8 @@ 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; + buffer(): Uint8Array { + return new Uint8Array(this.view.buffer, 0, align(this.offset, 8)); } /** writeBool() writes a boolean as 255 or 0 to the buffer at the next byte offset */