From 0167b113b5301f95777277e606f5ee4a246786a1 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Mon, 9 Sep 2024 12:30:47 +0200 Subject: [PATCH] [browser][MT] fix feature detection on webworker (#107452) --- .../browser/runtime/jiterpreter-jit-call.ts | 15 +-------------- .../runtime/jiterpreter-trace-generator.ts | 17 ++--------------- src/mono/browser/runtime/startup.ts | 3 +++ 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/mono/browser/runtime/jiterpreter-jit-call.ts b/src/mono/browser/runtime/jiterpreter-jit-call.ts index f9ee806540c60f..48e9797cb29e8f 100644 --- a/src/mono/browser/runtime/jiterpreter-jit-call.ts +++ b/src/mono/browser/runtime/jiterpreter-jit-call.ts @@ -61,7 +61,6 @@ const maxJitQueueLength = 6, let trampBuilder: WasmBuilder; let fnTable: WebAssembly.Table; -let wasmEhSupported: boolean | undefined = undefined; let nextDisambiguateIndex = 0; const fnCache: Array = []; const targetCache: { [target: number]: TrampolineInfo } = {}; @@ -276,18 +275,6 @@ export function mono_interp_jit_wasm_jit_call_trampoline ( mono_interp_flush_jitcall_queue(); } -function getIsWasmEhSupported (): boolean { - if (wasmEhSupported !== undefined) - return wasmEhSupported; - - // Probe whether the current environment can handle wasm exceptions - wasmEhSupported = runtimeHelpers.featureWasmEh === true; - if (!wasmEhSupported) - mono_log_info("Disabling Jiterpreter Exception Handling"); - - return wasmEhSupported; -} - export function mono_interp_flush_jitcall_queue (): void { const jitQueue: TrampolineInfo[] = []; let methodPtr = 0; @@ -336,7 +323,7 @@ export function mono_interp_flush_jitcall_queue (): void { } if (builder.options.enableWasmEh) { - if (!getIsWasmEhSupported()) { + if (!runtimeHelpers.featureWasmEh) { // The user requested to enable wasm EH but it's not supported, so turn the option back off applyOptions({ enableWasmEh: false }); builder.options.enableWasmEh = false; diff --git a/src/mono/browser/runtime/jiterpreter-trace-generator.ts b/src/mono/browser/runtime/jiterpreter-trace-generator.ts index b994927d308d88..c50647835c2c40 100644 --- a/src/mono/browser/runtime/jiterpreter-trace-generator.ts +++ b/src/mono/browser/runtime/jiterpreter-trace-generator.ts @@ -3526,19 +3526,6 @@ function emit_arrayop (builder: WasmBuilder, frame: NativePointer, ip: MintOpcod return true; } -let wasmSimdSupported: boolean | undefined; - -function getIsWasmSimdSupported (): boolean { - if (wasmSimdSupported !== undefined) - return wasmSimdSupported; - - wasmSimdSupported = runtimeHelpers.featureWasmSimd === true; - if (!wasmSimdSupported) - mono_log_info("Disabling Jiterpreter SIMD"); - - return wasmSimdSupported; -} - function get_import_name ( builder: WasmBuilder, typeName: string, functionPtr: number @@ -3557,7 +3544,7 @@ function emit_simd ( ): boolean { // First, if compiling an intrinsic attempt to emit the special vectorized implementation // We only do this if SIMD is enabled since we'll be using the v128 opcodes. - if (builder.options.enableSimd && getIsWasmSimdSupported()) { + if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) { switch (argCount) { case 2: if (emit_simd_2(builder, ip, index)) @@ -3577,7 +3564,7 @@ function emit_simd ( // Fall back to a mix of non-vectorized wasm and the interpreter's implementation of the opcodes switch (opcode) { case MintOpcode.MINT_SIMD_V128_LDC: { - if (builder.options.enableSimd && getIsWasmSimdSupported()) { + if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) { builder.local("pLocals"); const view = localHeapViewU8().slice(ip + 4, ip + 4 + sizeOfV128); builder.v128_const(view); diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 4d07e712358b08..834ceb81f2f7bb 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -128,6 +128,9 @@ async function instantiateWasmWorker ( successCallback: InstantiateWasmSuccessCallback ): Promise { if (!WasmEnableThreads) return; + + await ensureUsedWasmFeatures(); + // wait for the config to arrive by message from the main thread await loaderHelpers.afterConfigLoaded.promise;