Skip to content

Commit 733d29c

Browse files
authored
Improve the behavior of $addFlags
1 parent 414fe5f commit 733d29c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/typegpu/src/core/buffer/buffer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,23 @@ class TgpuBufferImpl<TData extends AnyData> implements TgpuBuffer<TData> {
187187
return this as this & UnionToIntersection<LiteralToUsageType<T[number]>>;
188188
}
189189

190-
// Temporary solution
191190
$addFlags(flags: GPUBufferUsageFlags) {
191+
if (!this._ownBuffer) {
192+
throw new Error(
193+
'Cannot add flags to a buffer that is not managed by TypeGPU.',
194+
);
195+
}
196+
197+
if (flags & GPUBufferUsage.MAP_READ) {
198+
this.flags = GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ;
199+
return this;
200+
}
201+
202+
if (flags & GPUBufferUsage.MAP_WRITE) {
203+
this.flags = GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_WRITE;
204+
return this;
205+
}
206+
192207
this.flags |= flags;
193208
return this;
194209
}

0 commit comments

Comments
 (0)