diff --git a/cli/tests/unit/webgpu_test.ts b/cli/tests/unit/webgpu_test.ts index bcdc6b1ff1b6bf..75ae34981759e7 100644 --- a/cli/tests/unit/webgpu_test.ts +++ b/cli/tests/unit/webgpu_test.ts @@ -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(); diff --git a/cli/tsc/dts/lib.deno_webgpu.d.ts b/cli/tsc/dts/lib.deno_webgpu.d.ts index 50d9ecfb641e49..74fa7c90741518 100644 --- a/cli/tsc/dts/lib.deno_webgpu.d.ts +++ b/cli/tsc/dts/lib.deno_webgpu.d.ts @@ -78,6 +78,7 @@ declare class GPU { requestAdapter( options?: GPURequestAdapterOptions, ): Promise; + getPreferredCanvasFormat(): GPUTextureFormat; } /** @category WebGPU */ diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index db0dc926483e65..55ca9c3822203b 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -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)}`; }