diff --git a/src/common/runtime/standalone.ts b/src/common/runtime/standalone.ts index 5e91b211384..786d7eae01e 100644 --- a/src/common/runtime/standalone.ts +++ b/src/common/runtime/standalone.ts @@ -9,6 +9,7 @@ import { parseQuery } from '../internal/query/parseQuery.js'; import { TestQueryLevel } from '../internal/query/query.js'; import { TestTreeNode, TestSubtree, TestTreeLeaf, TestTree } from '../internal/tree.js'; import { assert, ErrorWithExtra } from '../util/util.js'; +import { setDefaultRequestAdapterOptions } from '../util/navigator_gpu.js'; import { optionEnabled } from './helper/options.js'; import { TestWorker } from './helper/test_worker.js'; @@ -33,6 +34,11 @@ const worker = optionEnabled('worker') ? new TestWorker(debug) : undefined; const autoCloseOnPass = document.getElementById('autoCloseOnPass') as HTMLInputElement; const resultsVis = document.getElementById('resultsVis')!; +const powerPreference = new URLSearchParams(window.location.search).get('powerPreference'); +if (powerPreference) { + setDefaultRequestAdapterOptions({ powerPreference: powerPreference as GPUPowerPreference }); +} + dataCache.setStore({ load: async (path: string) => { const response = await fetch(`data/${path}`); diff --git a/src/common/util/navigator_gpu.ts b/src/common/util/navigator_gpu.ts index 8f219f80952..47cb1a4701c 100644 --- a/src/common/util/navigator_gpu.ts +++ b/src/common/util/navigator_gpu.ts @@ -32,6 +32,15 @@ export function setGPUProvider(provider: GPUProvider) { let impl: GPU | undefined = undefined; +let defaultRequestAdapterOptions: GPURequestAdapterOptions | undefined; + +export function setDefaultRequestAdapterOptions(options: GPURequestAdapterOptions) { + if (impl) { + throw new Error('must call setDefaultRequestAdapterOptions before getGPU'); + } + defaultRequestAdapterOptions = { ...options }; +} + /** * Finds and returns the `navigator.gpu` object (or equivalent, for non-browser implementations). * Throws an exception if not found. @@ -43,5 +52,23 @@ export function getGPU(): GPU { impl = gpuProvider(); + if (defaultRequestAdapterOptions) { + // eslint-disable-next-line @typescript-eslint/unbound-method + const oldFn = impl.requestAdapter; + impl.requestAdapter = function ( + options?: GPURequestAdapterOptions + ): Promise { + const promise = oldFn.call(this, { ...defaultRequestAdapterOptions, ...(options || {}) }); + void promise.then(async adapter => { + if (adapter) { + const info = await adapter.requestAdapterInfo(); + // eslint-disable-next-line no-console + console.log(info); + } + }); + return promise; + }; + } + return impl; }