Skip to content

Commit

Permalink
BREAKING(webgpu/unstable): Replace async .requestAdapterInfo() with s…
Browse files Browse the repository at this point in the history
…ync .info (#24783)

Closes #24779

Ref gpuweb/gpuweb#4662
  • Loading branch information
littledivy authored Aug 6, 2024
1 parent 7f6b484 commit c0e9512
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/tsc/dts/lib.deno_webgpu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GPUDevice>;
requestAdapterInfo(): Promise<GPUAdapterInfo>;
}

/**
Expand Down
13 changes: 10 additions & 3 deletions ext/webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ class GPUAdapter {
[_adapter];
/** @type {bool} */
[_invalid];
/** @type {GPUAdapterInfo | undefined} */
#adapterInfo;

/** @returns {GPUSupportedFeatures} */
get features() {
Expand Down Expand Up @@ -502,9 +504,9 @@ class GPUAdapter {
}

/**
* @returns {Promise<GPUAdapterInfo>}
* @returns {GPUAdapterInfo}
*/
requestAdapterInfo() {
get info() {
webidl.assertBranded(this, GPUAdapterPrototype);

if (this[_invalid]) {
Expand All @@ -513,6 +515,10 @@ class GPUAdapter {
);
}

if (this.#adapterInfo !== undefined) {
return this.#adapterInfo;
}

const {
vendor,
architecture,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/webgpu/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
Promise<GPUAdapterInfo> requestAdapterInfo();
};

dictionary GPUDeviceDescriptor
Expand Down

0 comments on commit c0e9512

Please sign in to comment.