Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/typegpu-docs/src/content/docs/fundamentals/roots.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ To unwrap a `TgpuVertexLayout` make sure to explicitly mark each of its attribut

## Destroying resources

Calling `root.destroy()` will destroy all resources created with it.
It will also destroy the underlying WebGPU device, if it wasn't originally passed in via the `initFromDevice` function.
Calling `root.destroy()` will destroy all resources created with it. However, if an existing device is passed in via `tgpu.initFromDevice()`, this method
is a no-op.

```ts
root.destroy(); // <- frees up all the resources
Expand Down
18 changes: 1 addition & 17 deletions packages/typegpu/src/core/root/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ class WithFragmentImpl implements WithFragment {
}
}

interface Disposable {
destroy(): void;
}

/**
* Holds all data that is necessary to facilitate CPU and GPU communication.
* Programs that share a root can interact via GPU buffers.
Expand All @@ -261,8 +257,6 @@ class TgpuRootImpl extends WithBindingImpl
implements TgpuRoot, ExperimentalTgpuRoot {
'~unstable': Omit<ExperimentalTgpuRoot, keyof TgpuRoot>;

private _disposables: Disposable[] = [];

private _unwrappedBindGroupLayouts = new WeakMemo(
(key: TgpuBindGroupLayout) => key.unwrap(this),
);
Expand Down Expand Up @@ -307,9 +301,7 @@ class TgpuRootImpl extends WithBindingImpl
typeSchema: TData,
initialOrBuffer?: Infer<TData> | GPUBuffer,
): TgpuBuffer<TData> {
const buffer = INTERNAL_createBuffer(this, typeSchema, initialOrBuffer);
this._disposables.push(buffer);
return buffer;
return INTERNAL_createBuffer(this, typeSchema, initialOrBuffer);
}

createUniform<TData extends AnyWgslData>(
Expand All @@ -319,7 +311,6 @@ class TgpuRootImpl extends WithBindingImpl
const buffer = INTERNAL_createBuffer(this, typeSchema, initialOrBuffer)
// biome-ignore lint/suspicious/noExplicitAny: i'm sure it's fine
.$usage('uniform' as any);
this._disposables.push(buffer);

return new TgpuBufferShorthandImpl('uniform', buffer);
}
Expand All @@ -331,7 +322,6 @@ class TgpuRootImpl extends WithBindingImpl
const buffer = INTERNAL_createBuffer(this, typeSchema, initialOrBuffer)
// biome-ignore lint/suspicious/noExplicitAny: i'm sure it's fine
.$usage('storage' as any);
this._disposables.push(buffer);

return new TgpuBufferShorthandImpl('mutable', buffer);
}
Expand All @@ -343,7 +333,6 @@ class TgpuRootImpl extends WithBindingImpl
const buffer = INTERNAL_createBuffer(this, typeSchema, initialOrBuffer)
// biome-ignore lint/suspicious/noExplicitAny: i'm sure it's fine
.$usage('storage' as any);
this._disposables.push(buffer);

return new TgpuBufferShorthandImpl('readonly', buffer);
}
Expand All @@ -369,10 +358,6 @@ class TgpuRootImpl extends WithBindingImpl
}

destroy() {
for (const disposable of this._disposables) {
disposable.destroy();
}

clearTextureUtilsCache(this.device);

if (this._ownDevice) {
Expand Down Expand Up @@ -413,7 +398,6 @@ class TgpuRootImpl extends WithBindingImpl
>
> {
const texture = INTERNAL_createTexture(props, this);
this._disposables.push(texture);
// biome-ignore lint/suspicious/noExplicitAny: <too much type wrangling>
return texture as any;
}
Expand Down
Loading