Sfoglia il codice sorgente

Add WebAssembly SIMD support

Adam Scott 3 mesi fa
parent
commit
f114a8d1d1
2 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 6 0
      modules/jolt_physics/SCsub
  2. 5 0
      platform/web/detect.py

+ 6 - 0
modules/jolt_physics/SCsub

@@ -6,6 +6,12 @@ Import("env_modules")
 
 
 env_jolt = env_modules.Clone()
 env_jolt = env_modules.Clone()
 
 
+# Platform specific flags.
+if env["platform"] == "web" and env["wasm_simd"]:
+    # Enable SSE 4.2 so that WebAssembly SIMD can benefit from it.
+    # SSE 4.2 is the highest version supported by WebAssembly SIMD.
+    env_jolt.Append(CCFLAGS=["-msse4.2"])
+
 # Thirdparty source files
 # Thirdparty source files
 
 
 thirdparty_dir = "#thirdparty/jolt_physics/"
 thirdparty_dir = "#thirdparty/jolt_physics/"

+ 5 - 0
platform/web/detect.py

@@ -57,6 +57,7 @@ def get_opts():
             "Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
             "Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
             False,
             False,
         ),
         ),
+        BoolVariable("wasm_simd", "Use WebAssembly SIMD to improve CPU performance", True),
     ]
     ]
 
 
 
 
@@ -276,6 +277,10 @@ def configure(env: "SConsEnvironment"):
         # https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
         # https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
         env.Append(LINKFLAGS=["-sTEXTDECODER=0"])
         env.Append(LINKFLAGS=["-sTEXTDECODER=0"])
 
 
+    # Enable WebAssembly SIMD
+    if env["wasm_simd"]:
+        env.Append(CCFLAGS=["-msimd128"])
+
     # Reduce code size by generating less support code (e.g. skip NodeJS support).
     # Reduce code size by generating less support code (e.g. skip NodeJS support).
     env.Append(LINKFLAGS=["-sENVIRONMENT=web,worker"])
     env.Append(LINKFLAGS=["-sENVIRONMENT=web,worker"])