Remove SIMD for now (#1025)

This is by no means a proper fix, but Chrome 91 (stable tomorrow) brings some breaking changes to SIMD, and I'd rather disable SIMD for now to avoid breaking Squoosh altogether once it hits stable, and work on a proper fix in a separate branch.
This commit is contained in:
Ingvar Stepanyan
2021-05-24 12:50:48 +01:00
committed by GitHub
parent af80643809
commit f779e13bc8
4 changed files with 7 additions and 69 deletions

View File

@@ -14,28 +14,17 @@ import type { JXLModule } from 'codecs/jxl/enc/jxl_enc';
import type { EncodeOptions } from '../shared/meta'; import type { EncodeOptions } from '../shared/meta';
import { initEmscriptenModule } from 'features/worker-utils'; import { initEmscriptenModule } from 'features/worker-utils';
import { threads, simd } from 'wasm-feature-detect'; import { threads } from 'wasm-feature-detect';
import wasmUrl from 'url:codecs/jxl/enc/jxl_enc.wasm'; import wasmUrl from 'url:codecs/jxl/enc/jxl_enc.wasm';
import wasmUrlWithMT from 'url:codecs/jxl/enc/jxl_enc_mt.wasm'; import wasmUrlWithMT from 'url:codecs/jxl/enc/jxl_enc_mt.wasm';
import workerUrl from 'omt:codecs/jxl/enc/jxl_enc_mt.worker.js'; import workerUrl from 'omt:codecs/jxl/enc/jxl_enc_mt.worker.js';
import wasmUrlWithMTAndSIMD from 'url:codecs/jxl/enc/jxl_enc_mt_simd.wasm';
import workerUrlWithSIMD from 'omt:codecs/jxl/enc/jxl_enc_mt_simd.worker.js';
let emscriptenModule: Promise<JXLModule>; let emscriptenModule: Promise<JXLModule>;
async function init() { async function init() {
if (await threads()) { if (await threads()) {
if (await simd()) {
const jxlEncoder = await import('codecs/jxl/enc/jxl_enc_mt_simd');
return initEmscriptenModule(
jxlEncoder.default,
wasmUrlWithMTAndSIMD,
workerUrlWithSIMD,
);
}
const jxlEncoder = await import('codecs/jxl/enc/jxl_enc_mt'); const jxlEncoder = await import('codecs/jxl/enc/jxl_enc_mt');
return initEmscriptenModule(jxlEncoder.default, wasmUrlWithMT, workerUrl); return initEmscriptenModule(jxlEncoder.default, wasmUrlWithMT, workerUrl);
} }

View File

@@ -14,18 +14,12 @@ import type { WebPModule } from 'codecs/webp/enc/webp_enc';
import type { EncodeOptions } from '../shared/meta'; import type { EncodeOptions } from '../shared/meta';
import { initEmscriptenModule } from 'features/worker-utils'; import { initEmscriptenModule } from 'features/worker-utils';
import { simd } from 'wasm-feature-detect';
import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm'; import wasmUrl from 'url:codecs/webp/enc/webp_enc.wasm';
import wasmUrlWithSIMD from 'url:codecs/webp/enc/webp_enc_simd.wasm';
let emscriptenModule: Promise<WebPModule>; let emscriptenModule: Promise<WebPModule>;
async function init() { async function init() {
if (await simd()) {
const webpEncoder = await import('codecs/webp/enc/webp_enc_simd');
return initEmscriptenModule(webpEncoder.default, wasmUrlWithSIMD);
}
const webpEncoder = await import('codecs/webp/enc/webp_enc'); const webpEncoder = await import('codecs/webp/enc/webp_enc');
return initEmscriptenModule(webpEncoder.default, wasmUrl); return initEmscriptenModule(webpEncoder.default, wasmUrl);
} }

View File

@@ -14,28 +14,17 @@ import type { WP2Module } from 'codecs/wp2/enc/wp2_enc';
import type { EncodeOptions } from '../shared/meta'; import type { EncodeOptions } from '../shared/meta';
import { initEmscriptenModule } from 'features/worker-utils'; import { initEmscriptenModule } from 'features/worker-utils';
import { threads, simd } from 'wasm-feature-detect'; import { threads } from 'wasm-feature-detect';
import wasmUrl from 'url:codecs/wp2/enc/wp2_enc.wasm'; import wasmUrl from 'url:codecs/wp2/enc/wp2_enc.wasm';
import wasmUrlWithMT from 'url:codecs/wp2/enc/wp2_enc_mt.wasm'; import wasmUrlWithMT from 'url:codecs/wp2/enc/wp2_enc_mt.wasm';
import workerUrl from 'omt:codecs/wp2/enc/wp2_enc_mt.worker.js'; import workerUrl from 'omt:codecs/wp2/enc/wp2_enc_mt.worker.js';
import wasmUrlWithMTAndSIMD from 'url:codecs/wp2/enc/wp2_enc_mt_simd.wasm';
import workerUrlWithSIMD from 'omt:codecs/wp2/enc/wp2_enc_mt_simd.worker.js';
let emscriptenModule: Promise<WP2Module>; let emscriptenModule: Promise<WP2Module>;
async function init() { async function init() {
if (await threads()) { if (await threads()) {
if (await simd()) {
const wp2Encoder = await import('codecs/wp2/enc/wp2_enc_mt_simd');
return initEmscriptenModule(
wp2Encoder.default,
wasmUrlWithMTAndSIMD,
workerUrlWithSIMD,
);
}
const wp2Encoder = await import('codecs/wp2/enc/wp2_enc_mt'); const wp2Encoder = await import('codecs/wp2/enc/wp2_enc_mt');
return initEmscriptenModule(wp2Encoder.default, wasmUrlWithMT, workerUrl); return initEmscriptenModule(wp2Encoder.default, wasmUrlWithMT, workerUrl);
} }

View File

@@ -1,4 +1,4 @@
import { threads, simd } from 'wasm-feature-detect'; import { threads } from 'wasm-feature-detect';
import webpDataUrl from 'data-url:./tiny.webp'; import webpDataUrl from 'data-url:./tiny.webp';
import avifDataUrl from 'data-url:./tiny.avif'; import avifDataUrl from 'data-url:./tiny.avif';
@@ -75,9 +75,6 @@ import avifEncWasm from 'url:codecs/avif/enc/avif_enc.wasm';
import * as avifEnc from 'entry-data:codecs/avif/enc/avif_enc.js'; import * as avifEnc from 'entry-data:codecs/avif/enc/avif_enc.js';
// JXL // JXL
import * as jxlEncMtSimdWorker from 'entry-data:codecs/jxl/enc/jxl_enc_mt_simd.worker.js';
import * as jxlEncMtSimd from 'entry-data:codecs/jxl/enc/jxl_enc_mt_simd';
import jxlEncMtSimdWasm from 'url:codecs/jxl/enc/jxl_enc_mt_simd.wasm';
import * as jxlEncMtWorker from 'entry-data:codecs/jxl/enc/jxl_enc_mt.worker.js'; import * as jxlEncMtWorker from 'entry-data:codecs/jxl/enc/jxl_enc_mt.worker.js';
import * as jxlEncMt from 'entry-data:codecs/jxl/enc/jxl_enc_mt'; import * as jxlEncMt from 'entry-data:codecs/jxl/enc/jxl_enc_mt';
import jxlEncMtWasm from 'url:codecs/jxl/enc/jxl_enc_mt.wasm'; import jxlEncMtWasm from 'url:codecs/jxl/enc/jxl_enc_mt.wasm';
@@ -89,15 +86,10 @@ import oxiMtWasm from 'url:codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm';
import oxiWasm from 'url:codecs/oxipng/pkg/squoosh_oxipng_bg.wasm'; import oxiWasm from 'url:codecs/oxipng/pkg/squoosh_oxipng_bg.wasm';
// WebP // WebP
import * as webpEncSimd from 'entry-data:codecs/webp/enc/webp_enc_simd';
import webpEncSimdWasm from 'url:codecs/webp/enc/webp_enc_simd.wasm';
import * as webpEnc from 'entry-data:codecs/webp/enc/webp_enc'; import * as webpEnc from 'entry-data:codecs/webp/enc/webp_enc';
import webpEncWasm from 'url:codecs/webp/enc/webp_enc.wasm'; import webpEncWasm from 'url:codecs/webp/enc/webp_enc.wasm';
// WP2 // WP2
import * as wp2EncMtSimdWorker from 'entry-data:codecs/wp2/enc/wp2_enc_mt_simd.worker.js';
import * as wp2EncMtSimd from 'entry-data:codecs/wp2/enc/wp2_enc_mt_simd';
import wp2EncMtSimdWasm from 'url:codecs/wp2/enc/wp2_enc_mt_simd.wasm';
import * as wp2EncMtWorker from 'entry-data:codecs/wp2/enc/wp2_enc_mt.worker.js'; import * as wp2EncMtWorker from 'entry-data:codecs/wp2/enc/wp2_enc_mt.worker.js';
import * as wp2EncMt from 'entry-data:codecs/wp2/enc/wp2_enc_mt'; import * as wp2EncMt from 'entry-data:codecs/wp2/enc/wp2_enc_mt';
import wp2EncMtWasm from 'url:codecs/wp2/enc/wp2_enc_mt.wasm'; import wp2EncMtWasm from 'url:codecs/wp2/enc/wp2_enc_mt.wasm';
@@ -105,14 +97,8 @@ import * as wp2Enc from 'entry-data:codecs/wp2/enc/wp2_enc';
import wp2EncWasm from 'url:codecs/wp2/enc/wp2_enc.wasm'; import wp2EncWasm from 'url:codecs/wp2/enc/wp2_enc.wasm';
export const theRest = (async () => { export const theRest = (async () => {
const [ const [supportsThreads, supportsWebP, supportsAvif] = await Promise.all([
supportsThreads,
supportsSimd,
supportsWebP,
supportsAvif,
] = await Promise.all([
threads(), threads(),
simd(),
...[webpDataUrl, avifDataUrl].map(async (dataUrl) => { ...[webpDataUrl, avifDataUrl].map(async (dataUrl) => {
if (!self.createImageBitmap) return false; if (!self.createImageBitmap) return false;
const response = await fetch(dataUrl); const response = await fetch(dataUrl);
@@ -153,15 +139,7 @@ export const theRest = (async () => {
} }
// JXL // JXL
if (supportsThreads && supportsSimd) { if (supportsThreads) {
items.push(
jxlEncMtSimdWorker.main,
...jxlEncMtSimdWorker.deps,
jxlEncMtSimd.main,
...jxlEncMtSimd.deps,
jxlEncMtSimdWasm,
);
} else if (supportsThreads) {
items.push( items.push(
jxlEncMtWorker.main, jxlEncMtWorker.main,
...jxlEncMtWorker.deps, ...jxlEncMtWorker.deps,
@@ -181,22 +159,10 @@ export const theRest = (async () => {
} }
// WebP // WebP
if (supportsSimd) { items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm);
items.push(webpEncSimd.main, ...webpEncSimd.deps, webpEncSimdWasm);
} else {
items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm);
}
// WP2 // WP2
if (supportsThreads && supportsSimd) { if (supportsThreads) {
items.push(
wp2EncMtSimdWorker.main,
...wp2EncMtSimdWorker.deps,
wp2EncMtSimd.main,
...wp2EncMtSimd.deps,
wp2EncMtSimdWasm,
);
} else if (supportsThreads) {
items.push( items.push(
wp2EncMtWorker.main, wp2EncMtWorker.main,
...wp2EncMtWorker.deps, ...wp2EncMtWorker.deps,