diff --git a/src/common/framework/test_config.ts b/src/common/framework/test_config.ts index 072aaf736027..48d090c45185 100644 --- a/src/common/framework/test_config.ts +++ b/src/common/framework/test_config.ts @@ -44,6 +44,11 @@ export type TestConfig = { */ forceFallbackAdapter: boolean; + /** + * Enforce the default limits on the adapter + */ + enforceDefaultLimits: boolean; + /** * Whether to enable the `logToWebSocket` function used for out-of-band test logging. */ @@ -59,5 +64,6 @@ export const globalTestConfig: TestConfig = { unrollConstEvalLoops: false, compatibility: false, forceFallbackAdapter: false, + enforceDefaultLimits: false, logToWebSocket: false, }; diff --git a/src/common/runtime/cmdline.ts b/src/common/runtime/cmdline.ts index b2d220ec8ef9..635c30eb1410 100644 --- a/src/common/runtime/cmdline.ts +++ b/src/common/runtime/cmdline.ts @@ -107,6 +107,8 @@ for (let i = 0; i < sys.args.length; ++i) { globalTestConfig.compatibility = true; } else if (a === '--force-fallback-adapter') { globalTestConfig.forceFallbackAdapter = true; + } else if (a === '--enforce-default-limits') { + globalTestConfig.enforceDefaultLimits = true; } else if (a === '--log-to-websocket') { globalTestConfig.logToWebSocket = true; } else { diff --git a/src/common/runtime/helper/options.ts b/src/common/runtime/helper/options.ts index 4a82c7d2928e..5ec7140d3ae4 100644 --- a/src/common/runtime/helper/options.ts +++ b/src/common/runtime/helper/options.ts @@ -53,6 +53,7 @@ export interface CTSOptions { debug: boolean; compatibility: boolean; forceFallbackAdapter: boolean; + enforceDefaultLimits: boolean; unrollConstEvalLoops: boolean; powerPreference: GPUPowerPreference | null; logToWebSocket: boolean; @@ -63,6 +64,7 @@ export const kDefaultCTSOptions: CTSOptions = { debug: true, compatibility: false, forceFallbackAdapter: false, + enforceDefaultLimits: false, unrollConstEvalLoops: false, powerPreference: null, logToWebSocket: false, @@ -100,6 +102,7 @@ export const kCTSOptionsInfo: OptionsInfos = { debug: { description: 'show more info' }, compatibility: { description: 'run in compatibility mode' }, forceFallbackAdapter: { description: 'pass forceFallbackAdapter: true to requestAdapter' }, + enforceDefaultLimits: { description: 'force the adapter limits to the default limits' }, unrollConstEvalLoops: { description: 'unroll const eval loops in WGSL' }, powerPreference: { description: 'set default powerPreference for some tests', diff --git a/src/common/runtime/helper/utils_worker.ts b/src/common/runtime/helper/utils_worker.ts index 5886839f6c33..7054be317c13 100644 --- a/src/common/runtime/helper/utils_worker.ts +++ b/src/common/runtime/helper/utils_worker.ts @@ -19,6 +19,7 @@ export function setupWorkerEnvironment(ctsOptions: CTSOptions): Logger { globalTestConfig.enableDebugLogs = ctsOptions.debug; globalTestConfig.unrollConstEvalLoops = ctsOptions.unrollConstEvalLoops; globalTestConfig.compatibility = compatibility; + globalTestConfig.enforceDefaultLimits = ctsOptions.enforceDefaultLimits; globalTestConfig.logToWebSocket = ctsOptions.logToWebSocket; const log = new Logger(); diff --git a/src/common/runtime/server.ts b/src/common/runtime/server.ts index d908ce89ba7a..bb68b0413353 100644 --- a/src/common/runtime/server.ts +++ b/src/common/runtime/server.ts @@ -96,6 +96,8 @@ for (let i = 0; i < sys.args.length; ++i) { emitCoverage = true; } else if (a === '--force-fallback-adapter') { globalTestConfig.forceFallbackAdapter = true; + } else if (a === '--enforce-default-limits') { + globalTestConfig.enforceDefaultLimits = true; } else if (a === '--log-to-websocket') { globalTestConfig.logToWebSocket = true; } else if (a === '--gpu-provider') { diff --git a/src/common/runtime/standalone.ts b/src/common/runtime/standalone.ts index a079ac28dd98..d5b51b11c6f5 100644 --- a/src/common/runtime/standalone.ts +++ b/src/common/runtime/standalone.ts @@ -52,6 +52,7 @@ const { runnow, powerPreference, compatibility, forceFallbackAdapter } = options globalTestConfig.enableDebugLogs = options.debug; globalTestConfig.unrollConstEvalLoops = options.unrollConstEvalLoops; globalTestConfig.compatibility = compatibility; +globalTestConfig.enforceDefaultLimits = options.enforceDefaultLimits; globalTestConfig.logToWebSocket = options.logToWebSocket; const logger = new Logger(); diff --git a/src/common/util/navigator_gpu.ts b/src/common/util/navigator_gpu.ts index 4e58797097ed..c787eaa79cf7 100644 --- a/src/common/util/navigator_gpu.ts +++ b/src/common/util/navigator_gpu.ts @@ -1,4 +1,7 @@ +// eslint-disable-next-line import/no-restricted-paths +import { getDefaultLimitsForAdapter } from '../../webgpu/capability_info.js'; import { TestCaseRecorder } from '../framework/fixture.js'; +import { globalTestConfig } from '../framework/test_config.js'; import { ErrorWithExtra, assert, objectEquals } from './util.js'; @@ -49,6 +52,8 @@ 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. @@ -60,6 +65,64 @@ export function getGPU(recorder: TestCaseRecorder | null): GPU { impl = gpuProvider(); + if (globalTestConfig.enforceDefaultLimits) { + // eslint-disable-next-line @typescript-eslint/unbound-method + const oldFn = impl.requestAdapter; + impl.requestAdapter = async function (options?: GPURequestAdapterOptions) { + const adapter = await oldFn.call(this, { ...defaultRequestAdapterOptions, ...options }); + if (adapter) { + const limits = Object.fromEntries( + Object.entries(getDefaultLimitsForAdapter(adapter)).map(([key, { default: v }]) => [ + key, + v, + ]) + ); + + Object.defineProperty(adapter, 'limits', { + get() { + return limits; + }, + }); + } + 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' + ); + } + } + } + } + }; + + // 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) { // eslint-disable-next-line @typescript-eslint/unbound-method const oldFn = impl.requestAdapter; diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 16ed2d6f855f..abf50ddcf2c9 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,112 +1,112 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "e5d3d0ec", - "webgpu/shader/execution/binary/af_logical.bin": "4cadb0c4", - "webgpu/shader/execution/binary/af_division.bin": "24d5c047", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "27b5045f", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "e51ed65c", - "webgpu/shader/execution/binary/af_multiplication.bin": "ccdd9db3", - "webgpu/shader/execution/binary/af_remainder.bin": "7ba7561", - "webgpu/shader/execution/binary/af_subtraction.bin": "77ae32fd", - "webgpu/shader/execution/binary/f16_addition.bin": "7cf4d65a", - "webgpu/shader/execution/binary/f16_logical.bin": "b9e93570", - "webgpu/shader/execution/binary/f16_division.bin": "9ec5ad6a", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "e89ed3cb", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "375d5af3", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "9bd3af4e", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "43350bb3", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "1edb6630", - "webgpu/shader/execution/binary/f16_multiplication.bin": "7485e77b", - "webgpu/shader/execution/binary/f16_remainder.bin": "ec817ba", - "webgpu/shader/execution/binary/f16_subtraction.bin": "aae1c57a", - "webgpu/shader/execution/binary/f32_addition.bin": "7134e85", - "webgpu/shader/execution/binary/f32_logical.bin": "24ba1a54", - "webgpu/shader/execution/binary/f32_division.bin": "f51e95fe", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "97f4a153", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "70677010", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "355c0954", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "85135fad", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a3fa2750", - "webgpu/shader/execution/binary/f32_multiplication.bin": "ba41fc13", - "webgpu/shader/execution/binary/f32_remainder.bin": "142765dd", - "webgpu/shader/execution/binary/f32_subtraction.bin": "c1523f1c", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "bcff0350", - "webgpu/shader/execution/binary/i32_comparison.bin": "396f7bad", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "7357b8e9", - "webgpu/shader/execution/binary/u32_comparison.bin": "374b246a", - "webgpu/shader/execution/abs.bin": "1ab55590", - "webgpu/shader/execution/acos.bin": "d85ca70", - "webgpu/shader/execution/acosh.bin": "e28fd395", - "webgpu/shader/execution/asin.bin": "eced623b", - "webgpu/shader/execution/asinh.bin": "223989ea", - "webgpu/shader/execution/atan.bin": "d896ec78", - "webgpu/shader/execution/atan2.bin": "b394e737", - "webgpu/shader/execution/atanh.bin": "9e4a5a", - "webgpu/shader/execution/bitcast.bin": "51bb8e9f", - "webgpu/shader/execution/ceil.bin": "11d3b9aa", - "webgpu/shader/execution/clamp.bin": "b2860448", - "webgpu/shader/execution/cos.bin": "c965712f", - "webgpu/shader/execution/cosh.bin": "89f1ce32", - "webgpu/shader/execution/cross.bin": "8b3df30b", - "webgpu/shader/execution/degrees.bin": "182a521e", - "webgpu/shader/execution/determinant.bin": "d5b3ed92", - "webgpu/shader/execution/distance.bin": "d21d853b", - "webgpu/shader/execution/dot.bin": "c91e716", - "webgpu/shader/execution/exp.bin": "4240da7", - "webgpu/shader/execution/exp2.bin": "11938883", - "webgpu/shader/execution/faceForward.bin": "a2e27acc", - "webgpu/shader/execution/floor.bin": "c06553ca", - "webgpu/shader/execution/fma.bin": "7dea01cf", - "webgpu/shader/execution/fract.bin": "677b1105", - "webgpu/shader/execution/frexp.bin": "3dbf112c", - "webgpu/shader/execution/inverseSqrt.bin": "8f6bb04e", - "webgpu/shader/execution/ldexp.bin": "287a7307", - "webgpu/shader/execution/length.bin": "908ff679", - "webgpu/shader/execution/log.bin": "8585f4ac", - "webgpu/shader/execution/log2.bin": "6847e7ca", - "webgpu/shader/execution/max.bin": "777cfa16", - "webgpu/shader/execution/min.bin": "51ae81f5", - "webgpu/shader/execution/mix.bin": "56c2fa65", - "webgpu/shader/execution/modf.bin": "4e106c58", - "webgpu/shader/execution/normalize.bin": "32c44235", - "webgpu/shader/execution/pack2x16float.bin": "133f1db3", - "webgpu/shader/execution/pow.bin": "370df2fa", - "webgpu/shader/execution/quantizeToF16.bin": "8a4fa4a8", - "webgpu/shader/execution/radians.bin": "c4684d86", - "webgpu/shader/execution/reflect.bin": "3620e893", - "webgpu/shader/execution/refract.bin": "f6bd722f", - "webgpu/shader/execution/round.bin": "765d4e71", - "webgpu/shader/execution/saturate.bin": "772a5d55", - "webgpu/shader/execution/sign.bin": "b99ea52d", - "webgpu/shader/execution/sin.bin": "69c8cce9", - "webgpu/shader/execution/sinh.bin": "3bc5f870", - "webgpu/shader/execution/smoothstep.bin": "bc6be719", - "webgpu/shader/execution/sqrt.bin": "c3960a52", - "webgpu/shader/execution/step.bin": "8a715292", - "webgpu/shader/execution/tan.bin": "5c531104", - "webgpu/shader/execution/tanh.bin": "ff9cadf1", - "webgpu/shader/execution/transpose.bin": "f9cebed4", - "webgpu/shader/execution/trunc.bin": "1c0edd1b", - "webgpu/shader/execution/unpack2x16float.bin": "1d4051b9", - "webgpu/shader/execution/unpack2x16snorm.bin": "f9a16118", - "webgpu/shader/execution/unpack2x16unorm.bin": "cad45023", - "webgpu/shader/execution/unpack4x8snorm.bin": "26f9cbc4", - "webgpu/shader/execution/unpack4x8unorm.bin": "76de2d56", - "webgpu/shader/execution/unary/af_arithmetic.bin": "7044a2b4", - "webgpu/shader/execution/unary/af_assignment.bin": "fca7094b", - "webgpu/shader/execution/unary/bool_conversion.bin": "ac26e6b8", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "913af76", - "webgpu/shader/execution/unary/f16_conversion.bin": "1fb4a7a4", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "7c274ba7", - "webgpu/shader/execution/unary/f32_conversion.bin": "1175ae48", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "7bf685a3", - "webgpu/shader/execution/unary/i32_conversion.bin": "60437023", - "webgpu/shader/execution/unary/u32_conversion.bin": "3bc30fc0", - "webgpu/shader/execution/unary/ai_assignment.bin": "66d85afa", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "3c6c91e3", - "webgpu/shader/execution/unary/ai_arithmetic.bin": "37cc249a", - "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "c22028c6", - "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "8fa6602", - "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "f1bc0050", - "webgpu/shader/execution/derivatives.bin": "d96a3465", - "webgpu/shader/execution/fwidth.bin": "c63db6a9" + "webgpu/shader/execution/binary/af_addition.bin": "5408a94a", + "webgpu/shader/execution/binary/af_logical.bin": "1d33464b", + "webgpu/shader/execution/binary/af_division.bin": "65b73bb6", + "webgpu/shader/execution/binary/af_matrix_addition.bin": "35487ff5", + "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "3289a7a2", + "webgpu/shader/execution/binary/af_multiplication.bin": "30ecda2d", + "webgpu/shader/execution/binary/af_remainder.bin": "ee1b68bd", + "webgpu/shader/execution/binary/af_subtraction.bin": "66966082", + "webgpu/shader/execution/binary/f16_addition.bin": "f6c2622f", + "webgpu/shader/execution/binary/f16_logical.bin": "93930f71", + "webgpu/shader/execution/binary/f16_division.bin": "271933e8", + "webgpu/shader/execution/binary/f16_matrix_addition.bin": "f7a9b40a", + "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "db7072c9", + "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "b0303b76", + "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "edd3ccf", + "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "6b6aab4f", + "webgpu/shader/execution/binary/f16_multiplication.bin": "df977744", + "webgpu/shader/execution/binary/f16_remainder.bin": "54eaaa18", + "webgpu/shader/execution/binary/f16_subtraction.bin": "ccb413fc", + "webgpu/shader/execution/binary/f32_addition.bin": "77eded0d", + "webgpu/shader/execution/binary/f32_logical.bin": "8fe5762b", + "webgpu/shader/execution/binary/f32_division.bin": "3bd88eb1", + "webgpu/shader/execution/binary/f32_matrix_addition.bin": "6978f1b0", + "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "3884d7de", + "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "7696009e", + "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "ddc14abb", + "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "73de6c8e", + "webgpu/shader/execution/binary/f32_multiplication.bin": "2e8c2ac9", + "webgpu/shader/execution/binary/f32_remainder.bin": "e3177f52", + "webgpu/shader/execution/binary/f32_subtraction.bin": "caaadf56", + "webgpu/shader/execution/binary/i32_arithmetic.bin": "bd8e9f33", + "webgpu/shader/execution/binary/i32_comparison.bin": "76a32f73", + "webgpu/shader/execution/binary/u32_arithmetic.bin": "7f23f1ed", + "webgpu/shader/execution/binary/u32_comparison.bin": "af2a5678", + "webgpu/shader/execution/abs.bin": "e8e1ea83", + "webgpu/shader/execution/acos.bin": "31f1ed7c", + "webgpu/shader/execution/acosh.bin": "a7cb33a1", + "webgpu/shader/execution/asin.bin": "8ba86fc4", + "webgpu/shader/execution/asinh.bin": "2e2bf668", + "webgpu/shader/execution/atan.bin": "430514c3", + "webgpu/shader/execution/atan2.bin": "ae6817b5", + "webgpu/shader/execution/atanh.bin": "1a0b7d8f", + "webgpu/shader/execution/bitcast.bin": "4ae03bc0", + "webgpu/shader/execution/ceil.bin": "56fe5677", + "webgpu/shader/execution/clamp.bin": "5d094bf4", + "webgpu/shader/execution/cos.bin": "b7ad204e", + "webgpu/shader/execution/cosh.bin": "fa2f83cb", + "webgpu/shader/execution/cross.bin": "3e1af337", + "webgpu/shader/execution/degrees.bin": "2f19b33b", + "webgpu/shader/execution/determinant.bin": "f76c17f4", + "webgpu/shader/execution/distance.bin": "6969e44a", + "webgpu/shader/execution/dot.bin": "30da82e", + "webgpu/shader/execution/exp.bin": "a4732d12", + "webgpu/shader/execution/exp2.bin": "84801f38", + "webgpu/shader/execution/faceForward.bin": "83a06f41", + "webgpu/shader/execution/floor.bin": "2128b59f", + "webgpu/shader/execution/fma.bin": "c89a9b44", + "webgpu/shader/execution/fract.bin": "e9abda08", + "webgpu/shader/execution/frexp.bin": "77a177df", + "webgpu/shader/execution/inverseSqrt.bin": "3436ce23", + "webgpu/shader/execution/ldexp.bin": "990e3515", + "webgpu/shader/execution/length.bin": "bdd3557d", + "webgpu/shader/execution/log.bin": "3f875472", + "webgpu/shader/execution/log2.bin": "2a5deabe", + "webgpu/shader/execution/max.bin": "4d651b8c", + "webgpu/shader/execution/min.bin": "d04ec399", + "webgpu/shader/execution/mix.bin": "21317ca4", + "webgpu/shader/execution/modf.bin": "2ccbf20b", + "webgpu/shader/execution/normalize.bin": "b40908b4", + "webgpu/shader/execution/pack2x16float.bin": "6081f086", + "webgpu/shader/execution/pow.bin": "3b43ebfd", + "webgpu/shader/execution/quantizeToF16.bin": "7b730228", + "webgpu/shader/execution/radians.bin": "53b98108", + "webgpu/shader/execution/reflect.bin": "48554589", + "webgpu/shader/execution/refract.bin": "7b87b0bf", + "webgpu/shader/execution/round.bin": "f1902f69", + "webgpu/shader/execution/saturate.bin": "d1b03abc", + "webgpu/shader/execution/sign.bin": "11274a63", + "webgpu/shader/execution/sin.bin": "29a57158", + "webgpu/shader/execution/sinh.bin": "c9a446b4", + "webgpu/shader/execution/smoothstep.bin": "e169b991", + "webgpu/shader/execution/sqrt.bin": "d52c7e6c", + "webgpu/shader/execution/step.bin": "5e7ec97a", + "webgpu/shader/execution/tan.bin": "d4d2c708", + "webgpu/shader/execution/tanh.bin": "c4885953", + "webgpu/shader/execution/transpose.bin": "b46b7447", + "webgpu/shader/execution/trunc.bin": "6b54eb50", + "webgpu/shader/execution/unpack2x16float.bin": "60acf1b0", + "webgpu/shader/execution/unpack2x16snorm.bin": "3953f12b", + "webgpu/shader/execution/unpack2x16unorm.bin": "b31090b1", + "webgpu/shader/execution/unpack4x8snorm.bin": "de8990eb", + "webgpu/shader/execution/unpack4x8unorm.bin": "d6ee5b49", + "webgpu/shader/execution/unary/af_arithmetic.bin": "7f09aa85", + "webgpu/shader/execution/unary/af_assignment.bin": "6a7f0f82", + "webgpu/shader/execution/unary/bool_conversion.bin": "8fcb14ff", + "webgpu/shader/execution/unary/f16_arithmetic.bin": "84b2e3e", + "webgpu/shader/execution/unary/f16_conversion.bin": "f30cb12c", + "webgpu/shader/execution/unary/f32_arithmetic.bin": "d7d69b4f", + "webgpu/shader/execution/unary/f32_conversion.bin": "7081e848", + "webgpu/shader/execution/unary/i32_arithmetic.bin": "af3f3824", + "webgpu/shader/execution/unary/i32_conversion.bin": "2753cd5f", + "webgpu/shader/execution/unary/u32_conversion.bin": "37d1d643", + "webgpu/shader/execution/unary/ai_assignment.bin": "25777c", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "88cad0b3", + "webgpu/shader/execution/unary/ai_arithmetic.bin": "27145100", + "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "ef8c71c4", + "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "b193fd0d", + "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "e69afbcf", + "webgpu/shader/execution/derivatives.bin": "ae627673", + "webgpu/shader/execution/fwidth.bin": "ecd0c359" } \ No newline at end of file