diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33faaa8..2fac8f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: cd .. git clone https://github.com/emscripten-core/emsdk.git cd emsdk - ./emsdk install latest + ./emsdk install 3.1.24 - name: Clone DepotTools run: | cd .. @@ -25,7 +25,7 @@ jobs: - name: Build run: | cd ../emsdk - ./emsdk activate latest + ./emsdk activate 3.1.24 source "emsdk_env.sh" cd ../depot_tools export PATH=$(pwd):$PATH diff --git a/Core/twgsl/CMakeLists.txt b/Core/twgsl/CMakeLists.txt index 50c3804..6ebe598 100644 --- a/Core/twgsl/CMakeLists.txt +++ b/Core/twgsl/CMakeLists.txt @@ -7,6 +7,8 @@ target_compile_options(twgsl PUBLIC "SHELL:-s ALLOW_MEMORY_GROWTH=1") target_link_libraries(twgsl PRIVATE libtint) target_link_options(twgsl PRIVATE -s EXPORTED_FUNCTIONS=["_test","_spirv_to_wgsl","_free","_malloc"]) target_link_options(twgsl PRIVATE -s --js-library ${CMAKE_CURRENT_SOURCE_DIR}/Source/callbacks.js) +target_link_options(twgsl PRIVATE --extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/head.js) +target_link_options(twgsl PRIVATE --extern-post-js ${CMAKE_CURRENT_SOURCE_DIR}/tail.js) target_link_options(twgsl PUBLIC "SHELL:-s ALLOW_MEMORY_GROWTH=1") target_link_options(twgsl PRIVATE -Oz) target_link_options(twgsl PRIVATE -flto) diff --git a/Core/twgsl/head.js b/Core/twgsl/head.js new file mode 100644 index 0000000..d65e349 --- /dev/null +++ b/Core/twgsl/head.js @@ -0,0 +1,2 @@ +var Module = function(Module) { + Module = Module || {}; diff --git a/Core/twgsl/tail.js b/Core/twgsl/tail.js new file mode 100644 index 0000000..ccc79cf --- /dev/null +++ b/Core/twgsl/tail.js @@ -0,0 +1,49 @@ +return Module; +}; +(function tryToExport(root, factory) { + if (typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if (typeof define === 'function' && define.amd) + define("twgsl", [], factory); + else if (typeof exports === 'object') + exports["twgsl"] = factory(); + else root["twgsl"] = factory(); + })(typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this, () => { + const initialize = (wasmPath) => { + wasmPath = wasmPath || 'twgsl.wasm' return new Promise(resolve => { + Module({ + locateFile() { + return wasmPath; + }, + onRuntimeInitialized() { + var twgsl = this; + var wgsl = ""; + var textDecoder = new TextDecoder(); + var convertSpirV2WGSL = (code) => { + if (!twgsl._return_string_callback) { + twgsl._return_string_callback = (data, length) => { + const bytes = new Uint8ClampedArray(twgsl.HEAPU8.subarray(data, data + length)); + wgsl = textDecoder.decode(bytes); + }; + } + let addr = twgsl._malloc(code.byteLength); + twgsl.HEAPU32.set(code, addr / 4); + twgsl._spirv_to_wgsl(addr, code.byteLength); + twgsl._free(addr); + return wgsl; + }; + resolve({ + convertSpirV2WGSL: convertSpirV2WGSL, + }); + }, + }); + }); + }; + let instance; + return (wasmPath) => { + if (!instance) { + instance = initialize(wasmPath); + } + return instance; + }; +}); diff --git a/Dependencies/CMakeLists.txt b/Dependencies/CMakeLists.txt index 4c93218..5482c9d 100644 --- a/Dependencies/CMakeLists.txt +++ b/Dependencies/CMakeLists.txt @@ -6,14 +6,3 @@ option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" OFF) option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) add_subdirectory(tint EXCLUDE_FROM_ALL) -# Patch compile option -function(tint_patch_compile_options TARGET) - set(COMMON_CLANG_OPTIONS -Wno-unsafe-buffer-usage) - target_compile_options(${TARGET} PRIVATE ${COMMON_CLANG_OPTIONS}) -endfunction() - -tint_patch_compile_options(tint_diagnostic_utils) -tint_patch_compile_options(tint_utils_io) -tint_patch_compile_options(tint_val) -tint_patch_compile_options(libtint) -tint_patch_compile_options(tint)