Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(unstable): implement navigator.gpu.getPreferredCanvasFormat() #22149

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/tests/unit/webgpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ Deno.test({
Deno.close(Number(resources[resources.length - 1]));
});

Deno.test(function getPreferredCanvasFormat() {
const preferredFormat = navigator.gpu.getPreferredCanvasFormat();
assert(preferredFormat === "bgra8unorm" || preferredFormat === "rgba8unorm");
});

async function checkIsWsl() {
return Deno.build.os === "linux" && await hasMicrosoftProcVersion();

Expand Down
1 change: 1 addition & 0 deletions cli/tsc/dts/lib.deno_webgpu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ declare class GPU {
requestAdapter(
options?: GPURequestAdapterOptions,
): Promise<GPUAdapter | null>;
getPreferredCanvasFormat(): GPUTextureFormat;
}

/** @category WebGPU */
Expand Down
10 changes: 10 additions & 0 deletions ext/webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ class GPU {
}
}

getPreferredCanvasFormat() {
// Same as Gecko.
//
// https://github.com/mozilla/gecko-dev/blob/b75080bb8b11844d18cb5f9ac6e68a866ef8e243/dom/webgpu/Instance.h#L42-L47
if (core.build.os == "android") {
return "rgba8unorm";
}
return "bgra8unorm";
}

[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
}
Expand Down