From c0e9512b39a4ed3713d1fd9b28469d0edf68f578 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 6 Aug 2024 03:00:32 -0700 Subject: [PATCH] BREAKING(webgpu/unstable): Replace async .requestAdapterInfo() with sync .info (#24783) Closes https://github.com/denoland/deno/issues/24779 Ref https://github.com/gpuweb/gpuweb/pull/4662 --- cli/tsc/dts/lib.deno_webgpu.d.ts | 2 +- ext/webgpu/01_webgpu.js | 13 ++++++++++--- ext/webgpu/webgpu.idl | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/tsc/dts/lib.deno_webgpu.d.ts b/cli/tsc/dts/lib.deno_webgpu.d.ts index 12ef5e6c50..944af0e4c5 100644 --- a/cli/tsc/dts/lib.deno_webgpu.d.ts +++ b/cli/tsc/dts/lib.deno_webgpu.d.ts @@ -123,10 +123,10 @@ declare type GPUPowerPreference = "low-power" | "high-performance"; declare class GPUAdapter { readonly features: GPUSupportedFeatures; readonly limits: GPUSupportedLimits; + readonly info: GPUAdapterInfo; readonly isFallbackAdapter: boolean; requestDevice(descriptor?: GPUDeviceDescriptor): Promise; - requestAdapterInfo(): Promise; } /** diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index 15b82a8e3b..2c30e47f02 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -423,6 +423,8 @@ class GPUAdapter { [_adapter]; /** @type {bool} */ [_invalid]; + /** @type {GPUAdapterInfo | undefined} */ + #adapterInfo; /** @returns {GPUSupportedFeatures} */ get features() { @@ -502,9 +504,9 @@ class GPUAdapter { } /** - * @returns {Promise} + * @returns {GPUAdapterInfo} */ - requestAdapterInfo() { + get info() { webidl.assertBranded(this, GPUAdapterPrototype); if (this[_invalid]) { @@ -513,6 +515,10 @@ class GPUAdapter { ); } + if (this.#adapterInfo !== undefined) { + return this.#adapterInfo; + } + const { vendor, architecture, @@ -525,7 +531,8 @@ class GPUAdapter { adapterInfo[_architecture] = architecture; adapterInfo[_device] = device; adapterInfo[_description] = description; - return PromiseResolve(adapterInfo); + this.#adapterInfo = adapterInfo; + return adapterInfo; } [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { diff --git a/ext/webgpu/webgpu.idl b/ext/webgpu/webgpu.idl index 07d9d60ec7..d673ce77ba 100644 --- a/ext/webgpu/webgpu.idl +++ b/ext/webgpu/webgpu.idl @@ -78,11 +78,11 @@ enum GPUPowerPreference { [Exposed=(Window, Worker), SecureContext] interface GPUAdapter { [SameObject] readonly attribute GPUSupportedFeatures features; + [SameObject] readonly attribute GPUAdapterInfo info; [SameObject] readonly attribute GPUSupportedLimits limits; readonly attribute boolean isFallbackAdapter; Promise requestDevice(optional GPUDeviceDescriptor descriptor = {}); - Promise requestAdapterInfo(); }; dictionary GPUDeviceDescriptor