From 2d441f8e563a692a02a21ba790e976039ef10274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Mon, 19 Feb 2024 14:41:03 +0100 Subject: [PATCH] Add service worker support --- docs/intro/developing.md | 1 + src/common/runtime/helper/options.ts | 3 +- .../runtime/helper/test_worker-worker.ts | 2 +- src/common/runtime/helper/test_worker.ts | 49 ++++ src/common/runtime/standalone.ts | 5 +- src/common/runtime/wpt.ts | 3 + src/common/tools/dev_server.ts | 8 +- .../tools/gen_listings_and_webworkers.ts | 2 +- src/resources/cache/hashes.json | 214 +++++++++--------- src/webgpu/web_platform/worker/worker.spec.ts | 18 ++ src/webgpu/web_platform/worker/worker.ts | 2 +- .../web_platform/worker/worker_launcher.ts | 25 ++ 12 files changed, 218 insertions(+), 114 deletions(-) diff --git a/docs/intro/developing.md b/docs/intro/developing.md index d8869f985b31..23da946b1e0c 100644 --- a/docs/intro/developing.md +++ b/docs/intro/developing.md @@ -58,6 +58,7 @@ The following url parameters change how the harness runs: - `debug=1` enables verbose debug logging from tests. - `worker=dedicated` runs the tests on a dedicated worker instead of the main thread. - `worker=shared` runs the tests on a shared worker instead of the main thread. +- `worker=service` runs the tests on a service worker instead of the main thread. - `power_preference=low-power` runs most tests passing `powerPreference: low-power` to `requestAdapter` - `power_preference=high-performance` runs most tests passing `powerPreference: high-performance` to `requestAdapter` diff --git a/src/common/runtime/helper/options.ts b/src/common/runtime/helper/options.ts index 60c2d1069181..67fd00372d39 100644 --- a/src/common/runtime/helper/options.ts +++ b/src/common/runtime/helper/options.ts @@ -25,7 +25,7 @@ export function optionString( * The possible options for the tests. */ export interface CTSOptions { - worker?: 'dedicated' | 'shared' | ''; + worker?: 'dedicated' | 'shared' | 'service' | ''; debug: boolean; compatibility: boolean; forceFallbackAdapter: boolean; @@ -68,6 +68,7 @@ export const kCTSOptionsInfo: OptionsInfos = { { value: '', description: 'no worker' }, { value: 'dedicated', description: 'dedicated worker' }, { value: 'shared', description: 'shared worker' }, + { value: 'service', description: 'service worker' }, ], }, debug: { description: 'show more info' }, diff --git a/src/common/runtime/helper/test_worker-worker.ts b/src/common/runtime/helper/test_worker-worker.ts index caf6e7a1bc17..25d9a3d33647 100644 --- a/src/common/runtime/helper/test_worker-worker.ts +++ b/src/common/runtime/helper/test_worker-worker.ts @@ -48,7 +48,7 @@ async function reportTestResults(this: MessagePort | Worker, ev: MessageEvent) { } self.onmessage = (ev: MessageEvent) => { - void reportTestResults.call(self, ev); + void reportTestResults.call(ev.source || self, ev); }; self.onconnect = (event: MessageEvent) => { diff --git a/src/common/runtime/helper/test_worker.ts b/src/common/runtime/helper/test_worker.ts index a9ca4e2338c7..ccbd374b232d 100644 --- a/src/common/runtime/helper/test_worker.ts +++ b/src/common/runtime/helper/test_worker.ts @@ -92,3 +92,52 @@ export class TestSharedWorker { rec.injectResult(workerResult); } } + +export class TestServiceWorker { + private readonly ctsOptions: CTSOptions; + private readonly resolvers = new Map void>(); + + constructor(ctsOptions?: CTSOptions) { + this.ctsOptions = { ...(ctsOptions || kDefaultCTSOptions), ...{ worker: 'service' } }; + } + + async run( + rec: TestCaseRecorder, + query: string, + expectations: TestQueryWithExpectation[] = [] + ): Promise { + const [suite, name] = query.split(":", 2); + const fileName = name.split(',').join('/'); + const serviceWorkerPath = `/out/${suite}/webworker/${fileName}.worker.js`; + + const registration = await navigator.serviceWorker.register(serviceWorkerPath, { + type: 'module', + scope: '/', + }); + await navigator.serviceWorker.ready; + + navigator.serviceWorker.onmessage = ev => { + const query: string = ev.data.query; + const result: TransferredTestCaseResult = ev.data.result; + if (result.logs) { + for (const l of result.logs) { + Object.setPrototypeOf(l, LogMessageWithStack.prototype); + } + } + this.resolvers.get(query)!(result as LiveTestCaseResult); + + // MAINTENANCE_TODO(kainino0x): update the Logger with this result (or don't have a logger and + // update the entire results JSON somehow at some point). + }; + + registration.active.postMessage({ + query, + expectations, + ctsOptions: this.ctsOptions, + }); + const serviceWorkerResult = await new Promise(resolve => { + this.resolvers.set(query, resolve); + }); + rec.injectResult(serviceWorkerResult); + } +} diff --git a/src/common/runtime/standalone.ts b/src/common/runtime/standalone.ts index fa938c55a276..62090ee5dc92 100644 --- a/src/common/runtime/standalone.ts +++ b/src/common/runtime/standalone.ts @@ -21,7 +21,7 @@ import { OptionsInfos, camelCaseToSnakeCase, } from './helper/options.js'; -import { TestDedicatedWorker, TestSharedWorker } from './helper/test_worker.js'; +import { TestDedicatedWorker, TestSharedWorker, TestServiceWorker } from './helper/test_worker.js'; const rootQuerySpec = 'webgpu:*'; let promptBeforeReload = false; @@ -66,6 +66,7 @@ setBaseResourcePath('../out/resources'); const dedicatedWorker = options.worker === 'dedicated' ? new TestDedicatedWorker(options) : undefined; const sharedWorker = options.worker === 'shared' ? new TestSharedWorker(options) : undefined; +const serviceWorker = options.worker === 'service' ? new TestServiceWorker(options) : undefined; const autoCloseOnPass = document.getElementById('autoCloseOnPass') as HTMLInputElement; const resultsVis = document.getElementById('resultsVis')!; @@ -182,6 +183,8 @@ function makeCaseHTML(t: TestTreeLeaf): VisualizedSubtree { await dedicatedWorker.run(rec, name); } else if (sharedWorker) { await sharedWorker.run(rec, name); + } else if (serviceWorker) { + await serviceWorker.run(rec, name); } else { await t.run(rec); } diff --git a/src/common/runtime/wpt.ts b/src/common/runtime/wpt.ts index aacd34b13e51..bba86fd1ba3d 100644 --- a/src/common/runtime/wpt.ts +++ b/src/common/runtime/wpt.ts @@ -34,6 +34,7 @@ void (async () => { const workerString = optionString('worker'); const dedicatedWorker = workerString === 'dedicated' ? new TestDedicatedWorker() : undefined; const sharedWorker = workerString === 'shared' ? new TestSharedWorker() : undefined; + const serviceWorker = workerString === 'service' ? new TestServiceWorker() : undefined; globalTestConfig.unrollConstEvalLoops = optionEnabled('unroll_const_eval_loops'); @@ -68,6 +69,8 @@ void (async () => { await dedicatedWorker.run(rec, name, expectations); } else if (sharedWorker) { await sharedWorker.run(rec, name, expectations); + } else if (serviceWorker) { + await serviceWorker.run(rec, name, expectations); } else { await testcase.run(rec, expectations); } diff --git a/src/common/tools/dev_server.ts b/src/common/tools/dev_server.ts index 57cb6a7ea4f6..535b99d9346e 100644 --- a/src/common/tools/dev_server.ts +++ b/src/common/tools/dev_server.ts @@ -150,14 +150,17 @@ app.get('/out/**/*.js', async (req, res, next) => { const tsUrl = jsUrl.replace(/\.js$/, '.ts'); if (compileCache.has(tsUrl)) { res.setHeader('Content-Type', 'application/javascript'); + res.setHeader('Service-Worker-Allowed', '/'); res.send(compileCache.get(tsUrl)); return; } - let absPath = path.join(srcDir, tsUrl); + // FIXME: I'm not sure if this is the way I should handle it... + const dir = jsUrl.endsWith('worker.js') ? path.resolve(srcDir, '../out') : srcDir; + let absPath = path.join(dir, tsUrl); if (!fs.existsSync(absPath)) { // The .ts file doesn't exist. Try .js file in case this is a .js/.d.ts pair. - absPath = path.join(srcDir, jsUrl); + absPath = path.join(dir, jsUrl); } try { @@ -166,6 +169,7 @@ app.get('/out/**/*.js', async (req, res, next) => { compileCache.set(tsUrl, result.code); res.setHeader('Content-Type', 'application/javascript'); + res.setHeader('Service-Worker-Allowed', '/'); res.send(result.code); } else { throw new Error(`Failed compile ${tsUrl}.`); diff --git a/src/common/tools/gen_listings_and_webworkers.ts b/src/common/tools/gen_listings_and_webworkers.ts index ca1f9ff99049..a816917ff21e 100644 --- a/src/common/tools/gen_listings_and_webworkers.ts +++ b/src/common/tools/gen_listings_and_webworkers.ts @@ -37,7 +37,7 @@ if (argv.length < 4) { usage(0); } -const myself = 'src/common/tools/gen_listings.ts'; +const myself = 'src/common/tools/gen_listings_and_webworkers.ts'; const outDir = argv[2]; diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 73df50c4d73f..62f344b32cac 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,109 +1,109 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "f9c25825", - "webgpu/shader/execution/binary/af_logical.bin": "c3c5c046", - "webgpu/shader/execution/binary/af_division.bin": "8eec7360", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "92f5acd", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "cf1920bc", - "webgpu/shader/execution/binary/af_multiplication.bin": "c3ca2d36", - "webgpu/shader/execution/binary/af_remainder.bin": "ef236c3e", - "webgpu/shader/execution/binary/af_subtraction.bin": "823c3d19", - "webgpu/shader/execution/binary/f16_addition.bin": "72625726", - "webgpu/shader/execution/binary/f16_logical.bin": "d20f2684", - "webgpu/shader/execution/binary/f16_division.bin": "865fb316", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "2908c1e6", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "dbc6dd4a", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "fff001f3", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "f6557db8", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "7d0beef1", - "webgpu/shader/execution/binary/f16_multiplication.bin": "fe1eeb2f", - "webgpu/shader/execution/binary/f16_remainder.bin": "44c68db0", - "webgpu/shader/execution/binary/f16_subtraction.bin": "4d349e03", - "webgpu/shader/execution/binary/f32_addition.bin": "3d909f18", - "webgpu/shader/execution/binary/f32_logical.bin": "300cb917", - "webgpu/shader/execution/binary/f32_division.bin": "26126d0b", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "8e3b7347", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "eba8334f", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "5f633cc4", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "ee699077", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "6e8e9044", - "webgpu/shader/execution/binary/f32_multiplication.bin": "9e8aa842", - "webgpu/shader/execution/binary/f32_remainder.bin": "44997694", - "webgpu/shader/execution/binary/f32_subtraction.bin": "7da0351c", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "78991d8", - "webgpu/shader/execution/binary/i32_comparison.bin": "eeb5a624", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "e317f38", - "webgpu/shader/execution/binary/u32_comparison.bin": "3bd52719", - "webgpu/shader/execution/abs.bin": "58d33fc0", - "webgpu/shader/execution/acos.bin": "8ab770e1", - "webgpu/shader/execution/acosh.bin": "1b797a55", - "webgpu/shader/execution/asin.bin": "49c3e54", - "webgpu/shader/execution/asinh.bin": "ec965820", - "webgpu/shader/execution/atan.bin": "13292f0c", - "webgpu/shader/execution/atan2.bin": "943937cf", - "webgpu/shader/execution/atanh.bin": "113723aa", - "webgpu/shader/execution/bitcast.bin": "49055551", - "webgpu/shader/execution/ceil.bin": "fc4d440", - "webgpu/shader/execution/clamp.bin": "f0590b61", - "webgpu/shader/execution/cos.bin": "dc6a6d3c", - "webgpu/shader/execution/cosh.bin": "682a8b93", - "webgpu/shader/execution/cross.bin": "c2cf537f", - "webgpu/shader/execution/degrees.bin": "b9044d85", - "webgpu/shader/execution/determinant.bin": "c872e66b", - "webgpu/shader/execution/distance.bin": "8df8d8a7", - "webgpu/shader/execution/dot.bin": "84aacdd9", - "webgpu/shader/execution/exp.bin": "1e815ae0", - "webgpu/shader/execution/exp2.bin": "ee9fd571", - "webgpu/shader/execution/faceForward.bin": "e2b2e81c", - "webgpu/shader/execution/floor.bin": "9d437a66", - "webgpu/shader/execution/fma.bin": "352b140", - "webgpu/shader/execution/fract.bin": "95a1650d", - "webgpu/shader/execution/frexp.bin": "c9ed5769", - "webgpu/shader/execution/inverseSqrt.bin": "8a275a8d", - "webgpu/shader/execution/ldexp.bin": "cb51dbe1", - "webgpu/shader/execution/length.bin": "53468ea4", - "webgpu/shader/execution/log.bin": "33bef86d", - "webgpu/shader/execution/log2.bin": "42fc6f07", - "webgpu/shader/execution/max.bin": "33b63886", - "webgpu/shader/execution/min.bin": "f4e85c7", - "webgpu/shader/execution/mix.bin": "b7346332", - "webgpu/shader/execution/modf.bin": "b291939c", - "webgpu/shader/execution/normalize.bin": "8d42f4e4", - "webgpu/shader/execution/pack2x16float.bin": "32836353", - "webgpu/shader/execution/pow.bin": "5fd2851d", - "webgpu/shader/execution/quantizeToF16.bin": "7a1878ee", - "webgpu/shader/execution/radians.bin": "dbb58186", - "webgpu/shader/execution/reflect.bin": "9f1132c5", - "webgpu/shader/execution/refract.bin": "508a9b82", - "webgpu/shader/execution/round.bin": "47ccb377", - "webgpu/shader/execution/saturate.bin": "771426ff", - "webgpu/shader/execution/sign.bin": "6b04f125", - "webgpu/shader/execution/sin.bin": "8e2495ec", - "webgpu/shader/execution/sinh.bin": "77ab8cf1", - "webgpu/shader/execution/smoothstep.bin": "bdd40525", - "webgpu/shader/execution/sqrt.bin": "d6b16a43", - "webgpu/shader/execution/step.bin": "34fd45ba", - "webgpu/shader/execution/tan.bin": "7df2e6b4", - "webgpu/shader/execution/tanh.bin": "e303ee3c", - "webgpu/shader/execution/transpose.bin": "985b9dd0", - "webgpu/shader/execution/trunc.bin": "b244b3d9", - "webgpu/shader/execution/unpack2x16float.bin": "c1ebb8d5", - "webgpu/shader/execution/unpack2x16snorm.bin": "f7fd89e", - "webgpu/shader/execution/unpack2x16unorm.bin": "35e0330e", - "webgpu/shader/execution/unpack4x8snorm.bin": "3d4ca4cd", - "webgpu/shader/execution/unpack4x8unorm.bin": "985e1f9a", - "webgpu/shader/execution/unary/af_arithmetic.bin": "fab31dec", - "webgpu/shader/execution/unary/af_assignment.bin": "af1899", - "webgpu/shader/execution/unary/bool_conversion.bin": "c4e6e40c", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "db964478", - "webgpu/shader/execution/unary/f16_conversion.bin": "df65cc9a", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "bd022e24", - "webgpu/shader/execution/unary/f32_conversion.bin": "ff00ace3", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "239e3b46", - "webgpu/shader/execution/unary/i32_complement.bin": "81fe7e5b", - "webgpu/shader/execution/unary/i32_conversion.bin": "24deb50a", - "webgpu/shader/execution/unary/u32_complement.bin": "37ba2547", - "webgpu/shader/execution/unary/u32_conversion.bin": "f26f8c3a", - "webgpu/shader/execution/unary/ai_assignment.bin": "46ee1c6f", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "aa09a4bc", - "webgpu/shader/execution/unary/ai_arithmetic.bin": "6e2d927f" + "webgpu/shader/execution/binary/af_addition.bin": "a68bee8", + "webgpu/shader/execution/binary/af_logical.bin": "d918e30f", + "webgpu/shader/execution/binary/af_division.bin": "96820a8b", + "webgpu/shader/execution/binary/af_matrix_addition.bin": "4a2ba436", + "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "37b9fedf", + "webgpu/shader/execution/binary/af_multiplication.bin": "dc20148e", + "webgpu/shader/execution/binary/af_remainder.bin": "1ab411eb", + "webgpu/shader/execution/binary/af_subtraction.bin": "bf8d4630", + "webgpu/shader/execution/binary/f16_addition.bin": "b5109d4b", + "webgpu/shader/execution/binary/f16_logical.bin": "92496ae9", + "webgpu/shader/execution/binary/f16_division.bin": "5629279b", + "webgpu/shader/execution/binary/f16_matrix_addition.bin": "794c648c", + "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "d41a4181", + "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "518de262", + "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "a63f0d8d", + "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "35956816", + "webgpu/shader/execution/binary/f16_multiplication.bin": "ecd1c32", + "webgpu/shader/execution/binary/f16_remainder.bin": "37f5fe21", + "webgpu/shader/execution/binary/f16_subtraction.bin": "9c1872b4", + "webgpu/shader/execution/binary/f32_addition.bin": "4323d8d8", + "webgpu/shader/execution/binary/f32_logical.bin": "dcc4de", + "webgpu/shader/execution/binary/f32_division.bin": "623c8255", + "webgpu/shader/execution/binary/f32_matrix_addition.bin": "f9c5c1d9", + "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "9899b0ac", + "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "1cb7da66", + "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "5a058633", + "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a237a6da", + "webgpu/shader/execution/binary/f32_multiplication.bin": "cf585b2a", + "webgpu/shader/execution/binary/f32_remainder.bin": "2f77b197", + "webgpu/shader/execution/binary/f32_subtraction.bin": "af5fe1a1", + "webgpu/shader/execution/binary/i32_arithmetic.bin": "f27c0e44", + "webgpu/shader/execution/binary/i32_comparison.bin": "45e085c3", + "webgpu/shader/execution/binary/u32_arithmetic.bin": "3999a23c", + "webgpu/shader/execution/binary/u32_comparison.bin": "8eb1e985", + "webgpu/shader/execution/abs.bin": "260ef05", + "webgpu/shader/execution/acos.bin": "84a62150", + "webgpu/shader/execution/acosh.bin": "672f6ae9", + "webgpu/shader/execution/asin.bin": "41895e51", + "webgpu/shader/execution/asinh.bin": "929dbdba", + "webgpu/shader/execution/atan.bin": "6eaf3edb", + "webgpu/shader/execution/atan2.bin": "b6a67a0", + "webgpu/shader/execution/atanh.bin": "9c3a89c3", + "webgpu/shader/execution/bitcast.bin": "c3f828d5", + "webgpu/shader/execution/ceil.bin": "3f9492f0", + "webgpu/shader/execution/clamp.bin": "e06eb0a2", + "webgpu/shader/execution/cos.bin": "434a43b0", + "webgpu/shader/execution/cosh.bin": "191be956", + "webgpu/shader/execution/cross.bin": "8a86fc0a", + "webgpu/shader/execution/degrees.bin": "69535ca4", + "webgpu/shader/execution/determinant.bin": "965baaf4", + "webgpu/shader/execution/distance.bin": "62b166b7", + "webgpu/shader/execution/dot.bin": "3d00bec2", + "webgpu/shader/execution/exp.bin": "c01fd77b", + "webgpu/shader/execution/exp2.bin": "7e5c74fb", + "webgpu/shader/execution/faceForward.bin": "625543a3", + "webgpu/shader/execution/floor.bin": "a285aa9d", + "webgpu/shader/execution/fma.bin": "b775f80f", + "webgpu/shader/execution/fract.bin": "f4ebd38", + "webgpu/shader/execution/frexp.bin": "fb7ba097", + "webgpu/shader/execution/inverseSqrt.bin": "8518a775", + "webgpu/shader/execution/ldexp.bin": "6003926c", + "webgpu/shader/execution/length.bin": "4f13ad76", + "webgpu/shader/execution/log.bin": "fa312745", + "webgpu/shader/execution/log2.bin": "fbed9711", + "webgpu/shader/execution/max.bin": "df03adbe", + "webgpu/shader/execution/min.bin": "ff1d84e2", + "webgpu/shader/execution/mix.bin": "e0c143b9", + "webgpu/shader/execution/modf.bin": "db4210ed", + "webgpu/shader/execution/normalize.bin": "d6296dfb", + "webgpu/shader/execution/pack2x16float.bin": "b6cce15", + "webgpu/shader/execution/pow.bin": "aa9dc70e", + "webgpu/shader/execution/quantizeToF16.bin": "1c9a930b", + "webgpu/shader/execution/radians.bin": "ae212178", + "webgpu/shader/execution/reflect.bin": "eb51657c", + "webgpu/shader/execution/refract.bin": "84c404d0", + "webgpu/shader/execution/round.bin": "d111c3c2", + "webgpu/shader/execution/saturate.bin": "6b709a46", + "webgpu/shader/execution/sign.bin": "3a2d4dd4", + "webgpu/shader/execution/sin.bin": "d46868f3", + "webgpu/shader/execution/sinh.bin": "76d7aa3a", + "webgpu/shader/execution/smoothstep.bin": "6c73de07", + "webgpu/shader/execution/sqrt.bin": "506a2093", + "webgpu/shader/execution/step.bin": "d26a70cc", + "webgpu/shader/execution/tan.bin": "f514bc1b", + "webgpu/shader/execution/tanh.bin": "60e1f252", + "webgpu/shader/execution/transpose.bin": "1b1108df", + "webgpu/shader/execution/trunc.bin": "11e27602", + "webgpu/shader/execution/unpack2x16float.bin": "3067a7f5", + "webgpu/shader/execution/unpack2x16snorm.bin": "61529420", + "webgpu/shader/execution/unpack2x16unorm.bin": "46d97621", + "webgpu/shader/execution/unpack4x8snorm.bin": "1ae2ce6f", + "webgpu/shader/execution/unpack4x8unorm.bin": "2a432aee", + "webgpu/shader/execution/unary/af_arithmetic.bin": "be9a86c6", + "webgpu/shader/execution/unary/af_assignment.bin": "63972495", + "webgpu/shader/execution/unary/bool_conversion.bin": "6c043c34", + "webgpu/shader/execution/unary/f16_arithmetic.bin": "bd55368e", + "webgpu/shader/execution/unary/f16_conversion.bin": "b8215ee0", + "webgpu/shader/execution/unary/f32_arithmetic.bin": "2a6165d4", + "webgpu/shader/execution/unary/f32_conversion.bin": "2201f531", + "webgpu/shader/execution/unary/i32_arithmetic.bin": "eef7d8ac", + "webgpu/shader/execution/unary/i32_complement.bin": "b869f894", + "webgpu/shader/execution/unary/i32_conversion.bin": "58467190", + "webgpu/shader/execution/unary/u32_complement.bin": "186152ce", + "webgpu/shader/execution/unary/u32_conversion.bin": "54053cfd", + "webgpu/shader/execution/unary/ai_assignment.bin": "576dd458", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "f33f5692", + "webgpu/shader/execution/unary/ai_arithmetic.bin": "44bdb6ae" } \ No newline at end of file diff --git a/src/webgpu/web_platform/worker/worker.spec.ts b/src/webgpu/web_platform/worker/worker.spec.ts index 0f34a58ddaa5..9b93a5d5339e 100644 --- a/src/webgpu/web_platform/worker/worker.spec.ts +++ b/src/webgpu/web_platform/worker/worker.spec.ts @@ -51,3 +51,21 @@ g.test('shared_worker') const result = await launchSharedWorker(); assert(result.error === undefined, `should be no error from worker but was: ${result.error}`); }); + +g.test('service_worker') + .desc(`test WebGPU is available in service workers and check for basic functionality`) + .fn(async t => { + if (isNode()) { + t.skip('node does not support 100% compatible workers'); + return; + } + // Note: we load worker_launcher dynamically because ts-node support + // is using commonjs which doesn't support import.meta. Further, + // we need to put the url in a string add pass the string to import + // otherwise typescript tries to parse the file which again, fails. + // worker_launcher.js is excluded in node.tsconfig.json. + const url = './worker_launcher.js'; + const { launchServiceWorker } = await import(url); + const result = await launchServiceWorker(); + assert(result.error === undefined, `should be no error from worker but was: ${result.error}`); + }); diff --git a/src/webgpu/web_platform/worker/worker.ts b/src/webgpu/web_platform/worker/worker.ts index f3c907a4118a..033473d63a97 100644 --- a/src/webgpu/web_platform/worker/worker.ts +++ b/src/webgpu/web_platform/worker/worker.ts @@ -87,7 +87,7 @@ async function reportTestResults(this: MessagePort | Worker, ev: MessageEvent) { } self.onmessage = (ev: MessageEvent) => { - void reportTestResults.call(self, ev); + void reportTestResults.call(ev.source || self, ev); }; self.onconnect = (event: MessageEvent) => { diff --git a/src/webgpu/web_platform/worker/worker_launcher.ts b/src/webgpu/web_platform/worker/worker_launcher.ts index 0487e4ad38b4..8ea652ac0efe 100644 --- a/src/webgpu/web_platform/worker/worker_launcher.ts +++ b/src/webgpu/web_platform/worker/worker_launcher.ts @@ -33,3 +33,28 @@ export async function launchSharedWorker() { }); return await promise; } + +export async function launchServiceWorker() { + const selfPath = import.meta.url; + const selfPathDir = selfPath.substring(0, selfPath.lastIndexOf('/')); + const serviceWorkerPath = selfPathDir + '/worker.js'; + const registration = await navigator.serviceWorker.register(serviceWorkerPath, { + type: 'module', + scope: '/', + }); + await navigator.serviceWorker.ready; + + const promise = new Promise(resolve => { + navigator.serviceWorker.addEventListener( + 'message', + ev => { + resolve(ev.data as TestResult); + }, + { once: true } + ); + }); + registration.active.postMessage({ + defaultRequestAdapterOptions: getDefaultRequestAdapterOptions(), + }); + return await promise; +}