Revert "Remove SIMD for now (#1025)"

This reverts commit f779e13bc8.
This commit is contained in:
Ingvar Stepanyan
2021-05-25 12:04:10 +00:00
committed by Ingvar Stepanyan
parent 31b263fc27
commit dd0adba6b1
4 changed files with 69 additions and 7 deletions

View File

@@ -14,17 +14,28 @@ 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 } from 'wasm-feature-detect'; import { threads, simd } 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,12 +14,18 @@ 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,17 +14,28 @@ 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 } from 'wasm-feature-detect'; import { threads, simd } 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 } from 'wasm-feature-detect'; import { threads, simd } 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,6 +75,9 @@ 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';
@@ -86,10 +89,15 @@ 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';
@@ -97,8 +105,14 @@ 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 [supportsThreads, supportsWebP, supportsAvif] = await Promise.all([ const [
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);
@@ -139,7 +153,15 @@ export const theRest = (async () => {
} }
// JXL // JXL
if (supportsThreads) { if (supportsThreads && supportsSimd) {
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,
@@ -159,10 +181,22 @@ export const theRest = (async () => {
} }
// WebP // 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 // WP2
if (supportsThreads) { if (supportsThreads && supportsSimd) {
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,