From b7299d53fe57d2eae28554a917633f218f72665b Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Fri, 3 Jan 2025 22:08:28 -0800 Subject: [PATCH] Remove check for wrapping. The code already exits if a provider exists. --- src/common/util/navigator_gpu.ts | 60 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/common/util/navigator_gpu.ts b/src/common/util/navigator_gpu.ts index c787eaa79cf..9f137dd933c 100644 --- a/src/common/util/navigator_gpu.ts +++ b/src/common/util/navigator_gpu.ts @@ -52,8 +52,6 @@ export function getDefaultRequestAdapterOptions() { return defaultRequestAdapterOptions; } -let s_wrappedForEnforceDefaultLimits = false; - /** * Finds and returns the `navigator.gpu` object (or equivalent, for non-browser implementations). * Throws an exception if not found. @@ -87,40 +85,36 @@ export function getGPU(recorder: TestCaseRecorder | null): GPU { return adapter; }; - if (!s_wrappedForEnforceDefaultLimits) { - s_wrappedForEnforceDefaultLimits = true; - - const enforceDefaultLimits = (adapter: GPUAdapter, desc: GPUDeviceDescriptor | undefined) => { - if (desc?.requiredLimits) { - const limits = getDefaultLimitsForAdapter(adapter); - for (const [key, value] of Object.entries(desc.requiredLimits)) { - const info = limits[key as keyof ReturnType]; - if (info && value !== undefined) { - const [beyondLimit, condition] = - info.class === 'maximum' - ? [value > info.default, 'greater'] - : [value < info.default, 'less']; - if (beyondLimit) { - throw new DOMException( - `requestedLimit ${value} for ${key} is ${condition} than adapter limit ${info.default}`, - 'OperationError' - ); - } + const enforceDefaultLimits = (adapter: GPUAdapter, desc: GPUDeviceDescriptor | undefined) => { + if (desc?.requiredLimits) { + const limits = getDefaultLimitsForAdapter(adapter); + for (const [key, value] of Object.entries(desc.requiredLimits)) { + const info = limits[key as keyof ReturnType]; + if (info && value !== undefined) { + const [beyondLimit, condition] = + info.class === 'maximum' + ? [value > info.default, 'greater'] + : [value < info.default, 'less']; + if (beyondLimit) { + throw new DOMException( + `requestedLimit ${value} for ${key} is ${condition} than adapter limit ${info.default}`, + 'OperationError' + ); } } } - }; - - // eslint-disable-next-line @typescript-eslint/unbound-method - const origFn = GPUAdapter.prototype.requestDevice; - GPUAdapter.prototype.requestDevice = async function ( - this: GPUAdapter, - desc?: GPUDeviceDescriptor | undefined - ) { - enforceDefaultLimits(this, desc); - return await origFn.call(this, desc); - }; - } + } + }; + + // eslint-disable-next-line @typescript-eslint/unbound-method + const origFn = GPUAdapter.prototype.requestDevice; + GPUAdapter.prototype.requestDevice = async function ( + this: GPUAdapter, + desc?: GPUDeviceDescriptor | undefined + ) { + enforceDefaultLimits(this, desc); + return await origFn.call(this, desc); + }; } if (defaultRequestAdapterOptions) {