mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
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:
@@ -14,28 +14,17 @@ import type { JXLModule } from 'codecs/jxl/enc/jxl_enc';
|
||||
import type { EncodeOptions } from '../shared/meta';
|
||||
|
||||
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 wasmUrlWithMT from 'url:codecs/jxl/enc/jxl_enc_mt.wasm';
|
||||
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>;
|
||||
|
||||
async function init() {
|
||||
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');
|
||||
return initEmscriptenModule(jxlEncoder.default, wasmUrlWithMT, workerUrl);
|
||||
}
|
||||
|
||||
@@ -14,18 +14,12 @@ import type { WebPModule } from 'codecs/webp/enc/webp_enc';
|
||||
import type { EncodeOptions } from '../shared/meta';
|
||||
|
||||
import { initEmscriptenModule } from 'features/worker-utils';
|
||||
import { simd } from 'wasm-feature-detect';
|
||||
|
||||
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>;
|
||||
|
||||
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');
|
||||
return initEmscriptenModule(webpEncoder.default, wasmUrl);
|
||||
}
|
||||
|
||||
@@ -14,28 +14,17 @@ import type { WP2Module } from 'codecs/wp2/enc/wp2_enc';
|
||||
import type { EncodeOptions } from '../shared/meta';
|
||||
|
||||
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 wasmUrlWithMT from 'url:codecs/wp2/enc/wp2_enc_mt.wasm';
|
||||
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>;
|
||||
|
||||
async function init() {
|
||||
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');
|
||||
return initEmscriptenModule(wp2Encoder.default, wasmUrlWithMT, workerUrl);
|
||||
}
|
||||
|
||||
@@ -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 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';
|
||||
|
||||
// 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 jxlEncMt from 'entry-data:codecs/jxl/enc/jxl_enc_mt';
|
||||
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';
|
||||
|
||||
// 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 webpEncWasm from 'url:codecs/webp/enc/webp_enc.wasm';
|
||||
|
||||
// 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 wp2EncMt from 'entry-data:codecs/wp2/enc/wp2_enc_mt';
|
||||
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';
|
||||
|
||||
export const theRest = (async () => {
|
||||
const [
|
||||
supportsThreads,
|
||||
supportsSimd,
|
||||
supportsWebP,
|
||||
supportsAvif,
|
||||
] = await Promise.all([
|
||||
const [supportsThreads, supportsWebP, supportsAvif] = await Promise.all([
|
||||
threads(),
|
||||
simd(),
|
||||
...[webpDataUrl, avifDataUrl].map(async (dataUrl) => {
|
||||
if (!self.createImageBitmap) return false;
|
||||
const response = await fetch(dataUrl);
|
||||
@@ -153,15 +139,7 @@ export const theRest = (async () => {
|
||||
}
|
||||
|
||||
// JXL
|
||||
if (supportsThreads && supportsSimd) {
|
||||
items.push(
|
||||
jxlEncMtSimdWorker.main,
|
||||
...jxlEncMtSimdWorker.deps,
|
||||
jxlEncMtSimd.main,
|
||||
...jxlEncMtSimd.deps,
|
||||
jxlEncMtSimdWasm,
|
||||
);
|
||||
} else if (supportsThreads) {
|
||||
if (supportsThreads) {
|
||||
items.push(
|
||||
jxlEncMtWorker.main,
|
||||
...jxlEncMtWorker.deps,
|
||||
@@ -181,22 +159,10 @@ export const theRest = (async () => {
|
||||
}
|
||||
|
||||
// WebP
|
||||
if (supportsSimd) {
|
||||
items.push(webpEncSimd.main, ...webpEncSimd.deps, webpEncSimdWasm);
|
||||
} else {
|
||||
items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm);
|
||||
}
|
||||
items.push(webpEnc.main, ...webpEnc.deps, webpEncWasm);
|
||||
|
||||
// WP2
|
||||
if (supportsThreads && supportsSimd) {
|
||||
items.push(
|
||||
wp2EncMtSimdWorker.main,
|
||||
...wp2EncMtSimdWorker.deps,
|
||||
wp2EncMtSimd.main,
|
||||
...wp2EncMtSimd.deps,
|
||||
wp2EncMtSimdWasm,
|
||||
);
|
||||
} else if (supportsThreads) {
|
||||
if (supportsThreads) {
|
||||
items.push(
|
||||
wp2EncMtWorker.main,
|
||||
...wp2EncMtWorker.deps,
|
||||
|
||||
Reference in New Issue
Block a user