summaryrefslogtreecommitdiff
path: root/ext/webgpu/01_webgpu.js
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-05-10 04:10:22 -0700
committerGitHub <noreply@github.com>2024-05-10 04:10:22 -0700
commit6066e069d141d7c0c19e088011fdf3c06782d12c (patch)
tree5e00678b77a887f604d71629c5876c5b58b19d5f /ext/webgpu/01_webgpu.js
parent19c0633a947f2ee28cc07b59c32322151779101d (diff)
fix(ext/webgpu): invalidate GPUAdapter when a device is created (#23752)
This removes the need for using `Deno.resources` to close the gpuadapter resource, while being more spec compliant.
Diffstat (limited to 'ext/webgpu/01_webgpu.js')
-rw-r--r--ext/webgpu/01_webgpu.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js
index be0b87cdf..502de2124 100644
--- a/ext/webgpu/01_webgpu.js
+++ b/ext/webgpu/01_webgpu.js
@@ -417,9 +417,12 @@ function createGPUAdapter(inner) {
return adapter;
}
+const _invalid = Symbol("[[invalid]]");
class GPUAdapter {
/** @type {InnerGPUAdapter} */
[_adapter];
+ /** @type {bool} */
+ [_invalid];
/** @returns {GPUSupportedFeatures} */
get features() {
@@ -466,6 +469,12 @@ class GPUAdapter {
}
}
+ if (this[_invalid]) {
+ throw new TypeError(
+ "The adapter cannot be reused, as it has been invalidated by a device creation",
+ );
+ }
+
const { rid, queueRid, features, limits } = op_webgpu_request_device(
this[_adapter].rid,
descriptor.label,
@@ -473,6 +482,8 @@ class GPUAdapter {
descriptor.requiredLimits,
);
+ this[_invalid] = true;
+
const inner = new InnerGPUDevice({
rid,
adapter: this,
@@ -496,6 +507,12 @@ class GPUAdapter {
requestAdapterInfo() {
webidl.assertBranded(this, GPUAdapterPrototype);
+ if (this[_invalid]) {
+ throw new TypeError(
+ "The adapter cannot be reused, as it has been invalidated by a device creation",
+ );
+ }
+
const {
vendor,
architecture,