From 75c6f6d16da4d5ba06acfcaffde94bde9bf1f31b Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jan 2024 15:30:05 +0800 Subject: [PATCH] fixed #16248: .wasm / .asm.js files are both downloaded on web platform (#16679) --- cc.config.json | 6 +- cocos/3d/misc/mesh-codec.ts | 37 +++++----- cocos/misc/webassembly-support.ts | 10 +-- cocos/physics-2d/box2d-wasm/instantiated.ts | 34 ++++----- cocos/physics/bullet/instantiated.ts | 36 +++++----- cocos/physics/physx/physx-adapter.ts | 76 ++++++++++----------- cocos/spine/lib/instantiated.ts | 40 +++++------ cocos/webgpu/instantiated.ts | 8 +-- package-lock.json | 8 +-- package.json | 2 +- pal/system-info/enum-type/feature.ts | 4 +- tests/constants-for-test.ts | 4 +- 12 files changed, 133 insertions(+), 132 deletions(-) diff --git a/cc.config.json b/cc.config.json index c99721b0c75..2c17f03842c 100644 --- a/cc.config.json +++ b/cc.config.json @@ -650,10 +650,10 @@ "value": false, "internal": true }, - "WASM_SUPPORT_MODE": { - "comment": "Whether support wasm, here we provide 3 options:\n0: The platform doesn't support WASM\n1: The platform supports WASM\n2: The platform may support WASM, especially on Web platform", + "NATIVE_CODE_BUNDLE_MODE": { + "comment": "Native code (wasm/asmjs) bundle mode, 0: asmjs, 1: wasm, 2: both", "type": "number", - "value": "($HTML5 || $BYTEDANCE) ? 2 : ($NATIVE ? (($OPEN_HARMONY||$IOS)?0:1): ($MINIGAME? ($WECHAT?1:0) :0))", + "value": 2, "internal": true }, "WASM_SUBPACKAGE": { diff --git a/cocos/3d/misc/mesh-codec.ts b/cocos/3d/misc/mesh-codec.ts index 7558d2dba7f..c2428931c21 100644 --- a/cocos/3d/misc/mesh-codec.ts +++ b/cocos/3d/misc/mesh-codec.ts @@ -21,13 +21,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { CULL_MESHOPT, WASM_SUPPORT_MODE } from 'internal:constants'; +import { CULL_MESHOPT, NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm'; -import { sys, logID } from '../../core'; +import { sys, logID, error } from '../../core'; import { game } from '../../game'; -import { WebAssemblySupportMode } from '../../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; export const MeshoptDecoder = {} as any; @@ -63,9 +63,9 @@ function initDecoderWASM (wasm_factory: any, wasm_url: string): Promise { } function shouldUseWasmModule (): boolean { - if (WASM_SUPPORT_MODE === (WebAssemblySupportMode.MAYBE_SUPPORT as number)) { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { return sys.hasFeature(sys.Feature.WASM); - } else if (WASM_SUPPORT_MODE === (WebAssemblySupportMode.SUPPORT as number)) { + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { return true; } else { return false; @@ -73,21 +73,22 @@ function shouldUseWasmModule (): boolean { } export function InitDecoder (): Promise { - return ensureWasmModuleReady().then(() => Promise.all([ - import('external:emscripten/meshopt/meshopt_decoder.asm.js'), - import('external:emscripten/meshopt/meshopt_decoder.wasm.js'), - import('external:emscripten/meshopt/meshopt_decoder.wasm.wasm'), - ]).then(([ - { default: meshopt_asm_factory }, - { default: meshopt_wasm_factory }, - { default: meshopt_wasm_url }, - ]) => { - if (shouldUseWasmModule() && meshopt_wasm_url) { - return initDecoderWASM(meshopt_wasm_factory, meshopt_wasm_url); + const errorReport = (msg: any): void => { error(msg); }; + return ensureWasmModuleReady().then(() => { + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/meshopt/meshopt_decoder.wasm.js'), + import('external:emscripten/meshopt/meshopt_decoder.wasm.wasm'), + ]).then(([ + { default: meshopt_wasm_factory }, + { default: meshopt_wasm_url }, + ]) => initDecoderWASM(meshopt_wasm_factory, meshopt_wasm_url)); } else { - return initDecoderASM(meshopt_asm_factory); + return import('external:emscripten/meshopt/meshopt_decoder.asm.js').then( + ({ default: meshopt_asm_factory }) => initDecoderASM(meshopt_asm_factory), + ); } - })); + }).catch(errorReport); } if (!CULL_MESHOPT) { diff --git a/cocos/misc/webassembly-support.ts b/cocos/misc/webassembly-support.ts index a9c8d75437a..f7c0df00828 100644 --- a/cocos/misc/webassembly-support.ts +++ b/cocos/misc/webassembly-support.ts @@ -1,8 +1,8 @@ /** - * An enum type for WASM_SUPPORT_MODE constant, making the support mode more readable. + * An enum type for NATIVE_CODE_BUNDLE_MODE constant, making the support mode more readable. */ -export const enum WebAssemblySupportMode { - NONE = 0, - SUPPORT = 1, - MAYBE_SUPPORT = 2, +export const enum NativeCodeBundleMode { + ASMJS = 0, + WASM = 1, + BOTH = 2, } diff --git a/cocos/physics-2d/box2d-wasm/instantiated.ts b/cocos/physics-2d/box2d-wasm/instantiated.ts index afbb9aa7605..f59cfcfee20 100644 --- a/cocos/physics-2d/box2d-wasm/instantiated.ts +++ b/cocos/physics-2d/box2d-wasm/instantiated.ts @@ -23,11 +23,11 @@ */ import { instantiateWasm, ensureWasmModuleReady } from 'pal/wasm'; -import { WASM_SUPPORT_MODE } from 'internal:constants'; +import { NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; import { game } from '../../game'; import { error, sys, IVec2Like, log } from '../../core'; -import { WebAssemblySupportMode } from '../../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; // eslint-disable-next-line import/no-mutable-exports export let B2 = {} as any; @@ -164,9 +164,9 @@ function initAsm (asmFactory): Promise { } function shouldUseWasmModule (): boolean { - if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT as number) { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { return sys.hasFeature(sys.Feature.WASM); - } else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT as number) { + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { return true; } else { return false; @@ -175,21 +175,21 @@ function shouldUseWasmModule (): boolean { export function waitForBox2dWasmInstantiation (): Promise { const errorReport = (msg: any): void => { error(msg); }; - return ensureWasmModuleReady().then(() => Promise.all([ - import('external:emscripten/box2d/box2d.release.wasm.js'), - import('external:emscripten/box2d/box2d.release.wasm.wasm'), - import('external:emscripten/box2d/box2d.release.asm.js'), - ]).then(([ - { default: wasmFactory }, - { default: wasmUrl }, - { default: asmFactory }, - ]) => { - if (shouldUseWasmModule() && wasmUrl) { - return initWasm(wasmFactory, wasmUrl); + return ensureWasmModuleReady().then(() => { + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/box2d/box2d.release.wasm.js'), + import('external:emscripten/box2d/box2d.release.wasm.wasm'), + ]).then(([ + { default: wasmFactory }, + { default: wasmUrl }, + ]) => initWasm(wasmFactory, wasmUrl)); } else { - return initAsm(asmFactory); + return import('external:emscripten/box2d/box2d.release.asm.js').then( + ({ default: asmFactory }) => initAsm(asmFactory), + ); } - })).catch(errorReport); + }).catch(errorReport); } game.onPostInfrastructureInitDelegate.add(waitForBox2dWasmInstantiation); diff --git a/cocos/physics/bullet/instantiated.ts b/cocos/physics/bullet/instantiated.ts index 47811bdb47a..26c71542e84 100644 --- a/cocos/physics/bullet/instantiated.ts +++ b/cocos/physics/bullet/instantiated.ts @@ -23,10 +23,10 @@ */ import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm'; -import { WASM_SUPPORT_MODE } from 'internal:constants'; +import { NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; import { game } from '../../game'; import { error, log, sys } from '../../core'; -import { WebAssemblySupportMode } from '../../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; //corresponds to bulletType in bullet-compile export enum EBulletType{ @@ -126,11 +126,9 @@ function initASM (asmFactory): Promise { } function shouldUseWasmModule (): boolean { - // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison - if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT) { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { return sys.hasFeature(sys.Feature.WASM); - // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison - } else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT) { + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { return true; } else { return false; @@ -139,21 +137,21 @@ function shouldUseWasmModule (): boolean { export function waitForAmmoInstantiation (): Promise { const errorReport = (msg: any): void => { error(msg); }; - return ensureWasmModuleReady().then(() => Promise.all([ - import('external:emscripten/bullet/bullet.release.wasm.js'), - import('external:emscripten/bullet/bullet.release.wasm.wasm'), - import('external:emscripten/bullet/bullet.release.asm.js'), - ]).then(([ - { default: bulletWasmFactory }, - { default: bulletWasmUrl }, - { default: bulletAsmFactory }, - ]) => { - if (shouldUseWasmModule() && bulletWasmUrl) { - return initWASM(bulletWasmFactory, bulletWasmUrl); + return ensureWasmModuleReady().then(() => { + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/bullet/bullet.release.wasm.js'), + import('external:emscripten/bullet/bullet.release.wasm.wasm'), + ]).then(([ + { default: bulletWasmFactory }, + { default: bulletWasmUrl }, + ]) => initWASM(bulletWasmFactory, bulletWasmUrl)); } else { - return initASM(bulletAsmFactory); + return import('external:emscripten/bullet/bullet.release.asm.js').then( + ({ default: bulletAsmFactory }) => initASM(bulletAsmFactory), + ); } - })).catch(errorReport); + }).catch(errorReport); } game.onPostInfrastructureInitDelegate.add(waitForAmmoInstantiation); diff --git a/cocos/physics/physx/physx-adapter.ts b/cocos/physics/physx/physx-adapter.ts index eb1ce8860f6..b960a690b54 100644 --- a/cocos/physics/physx/physx-adapter.ts +++ b/cocos/physics/physx/physx-adapter.ts @@ -30,10 +30,10 @@ /* eslint-disable no-lonely-if */ /* eslint-disable import/order */ -import { WebAssemblySupportMode } from '../../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; import { ensureWasmModuleReady, instantiateWasm } from 'pal/wasm'; -import { BYTEDANCE, DEBUG, EDITOR, TEST, WASM_SUPPORT_MODE } from 'internal:constants'; -import { IQuatLike, IVec3Like, Quat, RecyclePool, Vec3, cclegacy, geometry, Settings, settings, sys, Color } from '../../core'; +import { BYTEDANCE, DEBUG, EDITOR, TEST, NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; +import { IQuatLike, IVec3Like, Quat, RecyclePool, Vec3, cclegacy, geometry, Settings, settings, sys, Color, error, IVec3 } from '../../core'; import { shrinkPositions } from '../utils/util'; import { IRaycastOptions } from '../spec/i-physics-world'; import { IPhysicsConfig, PhysicsRayResult, PhysicsSystem, CharacterControllerContact } from '../framework'; @@ -67,23 +67,22 @@ export function InitPhysXLibs (): Promise { resolve(); }); } else { - return ensureWasmModuleReady().then(() => Promise.all([ - import('external:emscripten/physx/physx.release.wasm.js'), - import('external:emscripten/physx/physx.release.wasm.wasm'), - import('external:emscripten/physx/physx.release.asm.js'), - ]).then(([ - { default: physxWasmFactory }, - { default: physxWasmUrl }, - { default: physxAsmFactory }, - ]) => InitPhysXLibsInternal(physxWasmFactory, physxWasmUrl, physxAsmFactory))); - } -} - -function InitPhysXLibsInternal (physxWasmFactory, physxWasmUrl: string, physxAsmFactory): any { - if (shouldUseWasmModule() && physxWasmUrl) { - return initWASM(physxWasmFactory, physxWasmUrl); - } else { - return initASM(physxAsmFactory); + const errorReport = (msg: any): void => { error(msg); }; + return ensureWasmModuleReady().then(() => { + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/physx/physx.release.wasm.js'), + import('external:emscripten/physx/physx.release.wasm.wasm'), + ]).then(([ + { default: physxWasmFactory }, + { default: physxWasmUrl }, + ]) => initWASM(physxWasmFactory, physxWasmUrl)); + } else { + return import('external:emscripten/physx/physx.release.asm.js').then( + ({ default: physxAsmFactory }) => initASM(physxAsmFactory), + ); + } + }).catch(errorReport); } } @@ -131,9 +130,9 @@ function initWASM (physxWasmFactory, physxWasmUrl: string): any { } function shouldUseWasmModule (): boolean { - if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT) { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { return sys.hasFeature(sys.Feature.WASM); - } else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT) { + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { return true; } else { return false; @@ -286,22 +285,22 @@ export function copyPhysXTransform (node: Node, transform: any): void { const dontUpdate = physXEqualsCocosVec3(transform, wp) && physXEqualsCocosQuat(transform, wr); if (dontUpdate) return; if (USE_BYTEDANCE) { - node.setWorldPosition(transform.p); - node.setWorldRotation(transform.q); + node.setWorldPosition(transform.p as Vec3); + node.setWorldRotation(transform.q as Quat); } else { - node.setWorldPosition(transform.translation); - node.setWorldRotation(transform.rotation); + node.setWorldPosition(transform.translation as Vec3); + node.setWorldRotation(transform.rotation as Quat); } } export function physXEqualsCocosVec3 (trans: any, v3: IVec3Like): boolean { const pos = USE_BYTEDANCE ? trans.p : trans.translation; - return Vec3.equals(pos, v3, PX.EPSILON); + return Vec3.equals(pos as IVec3Like, v3, PX.EPSILON as number); } export function physXEqualsCocosQuat (trans: any, q: IQuatLike): boolean { const rot = USE_BYTEDANCE ? trans.q : trans.rotation; - return Quat.equals(rot, q, PX.EPSILON); + return Quat.equals(rot as IQuatLike, q, PX.EPSILON as number); } export function applyImpulse (isGlobal: boolean, impl: any, vec: IVec3Like, rp: IVec3Like): void { @@ -351,13 +350,14 @@ export function getShapeFlags (isTrigger: boolean): any { return new PX.PxShapeFlags(flag); } +// eslint-disable-next-line default-param-last export function getShapeWorldBounds (shape: any, actor: any, i = 1.01, out: geometry.AABB): void { if (USE_BYTEDANCE) { const b3 = PX.RigidActorExt.getWorldBounds(shape, actor, i); - geometry.AABB.fromPoints(out, b3.minimum, b3.maximum); + geometry.AABB.fromPoints(out, b3.minimum as IVec3, b3.maximum as IVec3); } else { const b3 = shape.getWorldBounds(actor, i); - geometry.AABB.fromPoints(out, b3.minimum, b3.maximum); + geometry.AABB.fromPoints(out, b3.minimum as IVec3, b3.maximum as IVec3); } } @@ -592,7 +592,7 @@ export function raycastAll ( const block = r[i]; const collider = getWrapShape(block.shapeData).collider; const result = pool.add(); - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); results.push(result); } return true; @@ -619,7 +619,7 @@ export function raycastAll ( const block = blocks.get(i); const collider = getWrapShape(block.getShape()).collider; const result = pool.add(); - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); results.push(result); } return true; @@ -654,7 +654,7 @@ export function raycastClosest (world: PhysXWorld, worldRay: geometry.Ray, optio ); if (block) { const collider = getWrapShape(block.shapeData).collider; - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); return true; } } else { @@ -674,7 +674,7 @@ export function raycastClosest (world: PhysXWorld, worldRay: geometry.Ray, optio ); if (r) { const collider = getWrapShape(block.getShape()).collider; - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); return true; } } @@ -722,7 +722,7 @@ export function sweepAll ( const block = blocks.get(i); const collider = getWrapShape(block.getShape()).collider; const result = pool.add(); - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); results.push(result); } return true; @@ -768,7 +768,7 @@ export function sweepClosest ( ); if (r) { const collider = getWrapShape(block.getShape()).collider; - result._assign(block.position, block.distance, collider, block.normal); + result._assign(block.position as IVec3Like, block.distance as number, collider, block.normal as IVec3Like); return true; } @@ -846,7 +846,7 @@ export function initializeWorld (world: any): void { */ export function getContactPosition (pxContactOrOffset: any, out: IVec3Like, buf: any): void { if (USE_BYTEDANCE) { - Vec3.fromArray(out, new Float32Array(buf, pxContactOrOffset, 3)); + Vec3.fromArray(out, new Float32Array(buf as ArrayBufferLike, pxContactOrOffset as number, 3)); } else { Vec3.copy(out, pxContactOrOffset.position); } @@ -854,7 +854,7 @@ export function getContactPosition (pxContactOrOffset: any, out: IVec3Like, buf: export function getContactNormal (pxContactOrOffset: any, out: IVec3Like, buf: any): void { if (USE_BYTEDANCE) { - Vec3.fromArray(out, new Float32Array(buf, (pxContactOrOffset as number) + 12, 3)); + Vec3.fromArray(out, new Float32Array(buf as ArrayBufferLike, (pxContactOrOffset as number) + 12, 3)); } else { Vec3.copy(out, pxContactOrOffset.normal); } diff --git a/cocos/spine/lib/instantiated.ts b/cocos/spine/lib/instantiated.ts index 4cb925e7909..0b8cef06e21 100644 --- a/cocos/spine/lib/instantiated.ts +++ b/cocos/spine/lib/instantiated.ts @@ -23,10 +23,10 @@ */ import { instantiateWasm, fetchBuffer, ensureWasmModuleReady } from 'pal/wasm'; -import { JSB, WASM_SUPPORT_MODE } from 'internal:constants'; +import { JSB, NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; import { game } from '../../game'; import { getError, error, sys } from '../../core'; -import { WebAssemblySupportMode } from '../../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../../misc/webassembly-support'; import { overrideSpineDefine } from './spine-define'; const PAGESIZE = 65536; // 64KiB @@ -88,9 +88,9 @@ function initAsmJS (asmFactory, asmJsMemUrl: string): Promise { } function shouldUseWasmModule (): boolean { - if (WASM_SUPPORT_MODE === WebAssemblySupportMode.MAYBE_SUPPORT) { + if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.BOTH as number)) { return sys.hasFeature(sys.Feature.WASM); - } else if (WASM_SUPPORT_MODE === WebAssemblySupportMode.SUPPORT) { + } else if (NATIVE_CODE_BUNDLE_MODE === (NativeCodeBundleMode.WASM as number)) { return true; } else { return false; @@ -99,23 +99,25 @@ function shouldUseWasmModule (): boolean { export function waitForSpineWasmInstantiation (): Promise { const errorReport = (msg: any): void => { error(msg); }; - return ensureWasmModuleReady().then(() => Promise.all([ - import('external:emscripten/spine/spine.asm.js'), - import('external:emscripten/spine/spine.js.mem'), - import('external:emscripten/spine/spine.wasm.js'), - import('external:emscripten/spine/spine.wasm'), - ]).then(([ - { default: asmFactory }, - { default: asmJsMemUrl }, - { default: wasmFactory }, - { default: spineWasmUrl }, - ]) => { - if (shouldUseWasmModule() && spineWasmUrl) { - return initWasm(wasmFactory, spineWasmUrl); + return ensureWasmModuleReady().then(() => { + if (shouldUseWasmModule()) { + return Promise.all([ + import('external:emscripten/spine/spine.wasm.js'), + import('external:emscripten/spine/spine.wasm'), + ]).then(([ + { default: wasmFactory }, + { default: spineWasmUrl }, + ]) => initWasm(wasmFactory, spineWasmUrl)); } else { - return initAsmJS(asmFactory, asmJsMemUrl); + return Promise.all([ + import('external:emscripten/spine/spine.asm.js'), + import('external:emscripten/spine/spine.js.mem'), + ]).then(([ + { default: asmFactory }, + { default: asmJsMemUrl }, + ]) => initAsmJS(asmFactory, asmJsMemUrl)); } - })).catch(errorReport); + }).catch(errorReport); } if (!JSB) { diff --git a/cocos/webgpu/instantiated.ts b/cocos/webgpu/instantiated.ts index 92d548d1fae..370134d669a 100644 --- a/cocos/webgpu/instantiated.ts +++ b/cocos/webgpu/instantiated.ts @@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import { WASM_SUPPORT_MODE, WEBGPU } from 'internal:constants'; +import { NATIVE_CODE_BUNDLE_MODE, WEBGPU } from 'internal:constants'; import webgpuUrl from 'external:emscripten/webgpu/webgpu_wasm.wasm'; import glslangUrl from 'external:emscripten/webgpu/glslang.wasm'; import twgslUrl from 'external:emscripten/webgpu/twgsl.wasm' @@ -36,7 +36,7 @@ import wasmDevice from 'external:emscripten/webgpu/webgpu_wasm.js'; import glslangLoader from 'external:emscripten/webgpu/glslang.js'; import twgslLoader from 'external:emscripten/webgpu/twgsl.js' import { legacyCC } from '../core/global-exports'; -import { WebAssemblySupportMode } from '../misc/webassembly-support'; +import { NativeCodeBundleMode } from '../misc/webassembly-support'; export const glslangWasmModule: any = { glslang: null, @@ -57,7 +57,7 @@ export const webgpuAdapter: any = { }; export const promiseForWebGPUInstantiation = (() => { - if (WEBGPU && WASM_SUPPORT_MODE !== WebAssemblySupportMode.NONE) { + if (WEBGPU && NATIVE_CODE_BUNDLE_MODE !== NativeCodeBundleMode.ASMJS) { // TODO: we need to support AsmJS fallback option return Promise.all([ glslangLoader(new URL(glslangUrl, import.meta.url).href).then((res) => { @@ -92,7 +92,7 @@ export const promiseForWebGPUInstantiation = (() => { return Promise.resolve(); })(); -if (WEBGPU && WASM_SUPPORT_MODE !== WebAssemblySupportMode.NONE) { +if (WEBGPU && NATIVE_CODE_BUNDLE_MODE !== NativeCodeBundleMode.ASMJS) { const intervalId = setInterval(() => { if (legacyCC.game) { legacyCC.game.onPreInfrastructureInitDelegate.add(() => promiseForWebGPUInstantiation); diff --git a/package-lock.json b/package-lock.json index 6a64a74dbe6..ba710eaaf53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@cocos/box2d": "1.0.1", "@cocos/cannon": "1.2.8", - "@cocos/ccbuild": "~2.1.0", + "@cocos/ccbuild": "2.2.1", "@cocos/dragonbones-js": "^1.0.1" }, "devDependencies": { @@ -2330,9 +2330,9 @@ } }, "node_modules/@cocos/ccbuild": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@cocos/ccbuild/-/ccbuild-2.1.0.tgz", - "integrity": "sha512-9vAaFn/uAvqr9mWwRA546DMhESUttr3VKmICJOE/RaCg9aQpYC73Z7RJTiF4luqy1GoaFPOhiTrQUVngQ16lBQ==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@cocos/ccbuild/-/ccbuild-2.2.1.tgz", + "integrity": "sha512-ssmn2V0VnmgW1muTJPKmTHDyjL1xkQDIwcW68lUgmm4nDC1bDSh/AfOV4dYuPJDPLUShHFCcqOLaLVO/bNtArg==", "dependencies": { "@babel/core": "^7.20.12", "@babel/helper-module-imports": "7.18.6", diff --git a/package.json b/package.json index 45b9a0cdd3f..2a62dd6d1d1 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@cocos/box2d": "1.0.1", "@cocos/cannon": "1.2.8", - "@cocos/ccbuild": "~2.1.0", + "@cocos/ccbuild": "2.2.1", "@cocos/dragonbones-js": "^1.0.1" } } diff --git a/pal/system-info/enum-type/feature.ts b/pal/system-info/enum-type/feature.ts index 502efd8d74a..43aeefc19a4 100644 --- a/pal/system-info/enum-type/feature.ts +++ b/pal/system-info/enum-type/feature.ts @@ -107,9 +107,9 @@ export enum Feature { */ EVENT_HANDHELD = 'EVENT_HANDHELD', /** - * @en Check whether Webassembly is supported at runtime. Generally, it needs to be checked when the constant `WASM_SUPPORT_MODE` is 2. + * @en Check whether Webassembly is supported at runtime. Generally, it needs to be checked when the constant `NATIVE_CODE_BUNDLE_MODE` is 2. * If it is not supported, you need to fallback to the Asm solution. - * @zh 运行时检测是否支持 Webassembly,一般在宏 `WASM_SUPPORT_MODE` 为 2 时需要检测,如果不支持,需要回滚到 Asm 方案 + * @zh 运行时检测是否支持 Webassembly,一般在宏 `NATIVE_CODE_BUNDLE_MODE` 为 2 时需要检测,如果不支持,需要回滚到 Asm 方案 */ WASM = 'WASM', } diff --git a/tests/constants-for-test.ts b/tests/constants-for-test.ts index 5c7e25ad31d..b643b681087 100644 --- a/tests/constants-for-test.ts +++ b/tests/constants-for-test.ts @@ -1,4 +1,4 @@ -import { WebAssemblySupportMode } from "../cocos/misc/webassembly-support"; +import { NativeCodeBundleMode } from "../cocos/misc/webassembly-support"; const _globalThis = typeof global === 'undefined' ? globalThis : global; const _global = typeof window === 'undefined' ? _globalThis : window; @@ -41,4 +41,4 @@ export const VIVO = tryDefineGlobal('CC_VIVO', false); // @ts-expect-error: 'loadRuntime' exits only in runtime environment. export const SUPPORT_JIT = tryDefineGlobal('CC_SUPPORT_JIT', (typeof loadRuntime === 'function')); export const SERVER_MODE = false; -export const WASM_SUPPORT_MODE = WebAssemblySupportMode.SUPPORT; +export const NATIVE_CODE_BUNDLE_MODE = NativeCodeBundleMode.WASM;