Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser][MT] fix feature detection on webworker #107452

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/mono/browser/runtime/jiterpreter-jit-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function | undefined> = [];
const targetCache: { [target: number]: TrampolineInfo } = {};
Expand Down Expand Up @@ -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 = <MonoMethod><any>0;
Expand Down Expand Up @@ -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(<any>{ enableWasmEh: false });
builder.options.enableWasmEh = false;
Expand Down
17 changes: 2 additions & 15 deletions src/mono/browser/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, <SimdIntrinsic2>index))
Expand All @@ -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(<any>ip + 4, <any>ip + 4 + sizeOfV128);
builder.v128_const(view);
Expand Down
3 changes: 3 additions & 0 deletions src/mono/browser/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ async function instantiateWasmWorker (
successCallback: InstantiateWasmSuccessCallback
): Promise<void> {
if (!WasmEnableThreads) return;

await ensureUsedWasmFeatures();

// wait for the config to arrive by message from the main thread
await loaderHelpers.afterConfigLoaded.promise;

Expand Down
Loading