mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
fix build (1)
This commit is contained in:
parent
a82c24eb03
commit
b4f38f4b9e
25 changed files with 1391 additions and 146 deletions
122
cmake/external/onnxruntime_external_deps.cmake
vendored
122
cmake/external/onnxruntime_external_deps.cmake
vendored
|
|
@ -631,78 +631,90 @@ if (onnxruntime_USE_WEBGPU)
|
|||
URL_HASH SHA1=${DEP_SHA1_dawn}
|
||||
# All previous patches are merged into the upstream dawn project. We don't need to apply any patches right now.
|
||||
# if we need to apply patches in the future, we can uncomment the following line.
|
||||
# PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn.patch
|
||||
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn.patch
|
||||
)
|
||||
endif()
|
||||
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
set(DAWN_BUILD_MONOLITHIC_LIBRARY ON CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
||||
|
||||
if (onnxruntime_USE_EXTERNAL_DAWN)
|
||||
message(FATAL_ERROR "onnxruntime_USE_EXTERNAL_DAWN and onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY cannot be enabled at the same time.")
|
||||
endif()
|
||||
else()
|
||||
# use dawn::dawn_native and dawn::dawn_proc instead of the monolithic dawn::webgpu_dawn to minimize binary size
|
||||
set(DAWN_BUILD_MONOLITHIC_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
set(DAWN_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_NULL OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_FETCH_DEPENDENCIES ON CACHE BOOL "" FORCE)
|
||||
|
||||
# disable things we don't use
|
||||
set(DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG OFF)
|
||||
set(DAWN_ENABLE_DESKTOP_GL OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_OPENGLES OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_GLFW OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_WINDOWS_UI OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_X11 OFF CACHE BOOL "" FORCE)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
set(DAWN_EMSCRIPTEN_TOOLCHAIN "${REPO_ROOT}/cmake/external/emsdk/upstream/emscripten" CACHE STRING "" FORCE)
|
||||
|
||||
set(TINT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_CMD_TOOLS OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_GLSL_WRITER OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_GLSL_VALIDATOR OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_IR_BINARY OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_SPV_READER OFF CACHE BOOL "" FORCE) # don't need. disabling is a large binary size saving
|
||||
set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "" FORCE) # needed to create cache key. runtime error if not enabled.
|
||||
# file "${DAWN_EMSCRIPTEN_TOOLCHAIN}/tools/maint/gen_struct_info.py" is missing from emsdk installation.
|
||||
# we should copy if from ${PROJECT_SOURCE_DIR}/patches/
|
||||
file(COPY "${PROJECT_SOURCE_DIR}/patches/emscripten/"
|
||||
DESTINATION "${DAWN_EMSCRIPTEN_TOOLCHAIN}/")
|
||||
else()
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
set(DAWN_BUILD_MONOLITHIC_LIBRARY ON CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
||||
|
||||
# SPIR-V validation shouldn't be required given we're using Tint to create the SPIR-V.
|
||||
set(DAWN_ENABLE_SPIRV_VALIDATION OFF CACHE BOOL "" FORCE)
|
||||
|
||||
if (WIN32)
|
||||
# building this requires the HLSL writer to be enabled in Tint. TBD if that we need either of these to be ON.
|
||||
set(DAWN_USE_BUILT_DXC ON CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "" FORCE)
|
||||
|
||||
if ((NOT onnxruntime_ENABLE_DAWN_BACKEND_VULKAN) AND (NOT onnxruntime_ENABLE_DAWN_BACKEND_D3D12))
|
||||
message(FATAL_ERROR "At least one of onnxruntime_ENABLE_DAWN_BACKEND_VULKAN or onnxruntime_ENABLE_DAWN_BACKEND_D3D12 must be enabled when using Dawn on Windows.")
|
||||
endif()
|
||||
if (onnxruntime_ENABLE_DAWN_BACKEND_VULKAN)
|
||||
set(DAWN_ENABLE_VULKAN ON CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "" FORCE)
|
||||
if (onnxruntime_USE_EXTERNAL_DAWN)
|
||||
message(FATAL_ERROR "onnxruntime_USE_EXTERNAL_DAWN and onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY cannot be enabled at the same time.")
|
||||
endif()
|
||||
else()
|
||||
set(DAWN_ENABLE_VULKAN OFF CACHE BOOL "" FORCE)
|
||||
# use dawn::dawn_native and dawn::dawn_proc instead of the monolithic dawn::webgpu_dawn to minimize binary size
|
||||
set(DAWN_BUILD_MONOLITHIC_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
if (onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
|
||||
set(DAWN_ENABLE_D3D12 ON CACHE BOOL "" FORCE)
|
||||
else()
|
||||
set(DAWN_ENABLE_D3D12 OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# disable things we don't use
|
||||
set(DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG OFF)
|
||||
set(DAWN_ENABLE_DESKTOP_GL OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_ENABLE_OPENGLES OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_GLFW OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_WINDOWS_UI OFF CACHE BOOL "" FORCE)
|
||||
set(DAWN_USE_X11 OFF CACHE BOOL "" FORCE)
|
||||
|
||||
set(TINT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_CMD_TOOLS OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_GLSL_WRITER OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_GLSL_VALIDATOR OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_IR_BINARY OFF CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_SPV_READER OFF CACHE BOOL "" FORCE) # don't need. disabling is a large binary size saving
|
||||
set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "" FORCE) # needed to create cache key. runtime error if not enabled.
|
||||
|
||||
# SPIR-V validation shouldn't be required given we're using Tint to create the SPIR-V.
|
||||
set(DAWN_ENABLE_SPIRV_VALIDATION OFF CACHE BOOL "" FORCE)
|
||||
|
||||
if (WIN32)
|
||||
# building this requires the HLSL writer to be enabled in Tint. TBD if that we need either of these to be ON.
|
||||
set(DAWN_USE_BUILT_DXC ON CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "" FORCE)
|
||||
|
||||
if ((NOT onnxruntime_ENABLE_DAWN_BACKEND_VULKAN) AND (NOT onnxruntime_ENABLE_DAWN_BACKEND_D3D12))
|
||||
message(FATAL_ERROR "At least one of onnxruntime_ENABLE_DAWN_BACKEND_VULKAN or onnxruntime_ENABLE_DAWN_BACKEND_D3D12 must be enabled when using Dawn on Windows.")
|
||||
endif()
|
||||
if (onnxruntime_ENABLE_DAWN_BACKEND_VULKAN)
|
||||
set(DAWN_ENABLE_VULKAN ON CACHE BOOL "" FORCE)
|
||||
set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "" FORCE)
|
||||
else()
|
||||
set(DAWN_ENABLE_VULKAN OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
if (onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
|
||||
set(DAWN_ENABLE_D3D12 ON CACHE BOOL "" FORCE)
|
||||
else()
|
||||
set(DAWN_ENABLE_D3D12 OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
# We are currently always using the D3D12 backend.
|
||||
set(DAWN_ENABLE_D3D11 OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
# We are currently always using the D3D12 backend.
|
||||
set(DAWN_ENABLE_D3D11 OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
onnxruntime_fetchcontent_makeavailable(dawn)
|
||||
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::webgpu_dawn)
|
||||
else()
|
||||
if (NOT onnxruntime_USE_EXTERNAL_DAWN)
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::dawn_native)
|
||||
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::webgpu_dawn)
|
||||
else()
|
||||
if (NOT onnxruntime_USE_EXTERNAL_DAWN)
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::dawn_native)
|
||||
endif()
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::dawn_proc)
|
||||
endif()
|
||||
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::dawn_proc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -21,44 +21,58 @@
|
|||
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_providers_webgpu_cc_srcs})
|
||||
onnxruntime_add_static_library(onnxruntime_providers_webgpu ${onnxruntime_providers_webgpu_cc_srcs})
|
||||
onnxruntime_add_include_to_target(onnxruntime_providers_webgpu
|
||||
onnxruntime_common dawn::dawncpp_headers dawn::dawn_headers onnx onnx_proto flatbuffers::flatbuffers Boost::mp11 safeint_interface)
|
||||
onnxruntime_common onnx onnx_proto flatbuffers::flatbuffers Boost::mp11 safeint_interface)
|
||||
|
||||
set(onnxruntime_providers_webgpu_dll_deps)
|
||||
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::webgpu_dawn)
|
||||
|
||||
if (WIN32)
|
||||
if (onnxruntime_ENABLE_DELAY_LOADING_WIN_DLLS)
|
||||
list(APPEND onnxruntime_DELAYLOAD_FLAGS "/DELAYLOAD:webgpu_dawn.dll")
|
||||
endif()
|
||||
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE:dawn::webgpu_dawn>")
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
||||
# if "-s DISABLE_EXCEPTION_CATCHING=0" is globally set, we need to remove "-fno-exceptions" from emdawnwebgpu_c
|
||||
if (CMAKE_CXX_FLAGS MATCHES "DISABLE_EXCEPTION_CATCHING=0")
|
||||
get_property(EM_DAWN_WEBGPU_C_COMPILE_OPTIONS TARGET emdawnwebgpu_c PROPERTY COMPILE_OPTIONS)
|
||||
list(REMOVE_ITEM EM_DAWN_WEBGPU_C_COMPILE_OPTIONS "-fno-exceptions")
|
||||
set_property(TARGET emdawnwebgpu_c PROPERTY COMPILE_OPTIONS ${EM_DAWN_WEBGPU_C_COMPILE_OPTIONS})
|
||||
endif()
|
||||
|
||||
target_link_libraries(onnxruntime_providers_webgpu PUBLIC emdawnwebgpu_cpp)
|
||||
target_link_options(onnxruntime_providers_webgpu PUBLIC "SHELL:-s ASYNCIFY=1")
|
||||
else()
|
||||
if (NOT onnxruntime_USE_EXTERNAL_DAWN)
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_native)
|
||||
onnxruntime_add_include_to_target(onnxruntime_providers_webgpu dawn::dawncpp_headers dawn::dawn_headers)
|
||||
|
||||
set(onnxruntime_providers_webgpu_dll_deps)
|
||||
|
||||
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::webgpu_dawn)
|
||||
|
||||
if (WIN32)
|
||||
if (onnxruntime_ENABLE_DELAY_LOADING_WIN_DLLS)
|
||||
list(APPEND onnxruntime_DELAYLOAD_FLAGS "/DELAYLOAD:webgpu_dawn.dll")
|
||||
endif()
|
||||
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE:dawn::webgpu_dawn>")
|
||||
endif()
|
||||
else()
|
||||
if (NOT onnxruntime_USE_EXTERNAL_DAWN)
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_native)
|
||||
endif()
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_proc)
|
||||
endif()
|
||||
target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_proc)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
|
||||
# Ensure dxil.dll and dxcompiler.dll exist in the output directory $<TARGET_FILE_DIR:dxcompiler>
|
||||
add_dependencies(onnxruntime_providers_webgpu copy_dxil_dll)
|
||||
add_dependencies(onnxruntime_providers_webgpu dxcompiler)
|
||||
if (WIN32 AND onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
|
||||
# Ensure dxil.dll and dxcompiler.dll exist in the output directory $<TARGET_FILE_DIR:dxcompiler>
|
||||
add_dependencies(onnxruntime_providers_webgpu copy_dxil_dll)
|
||||
add_dependencies(onnxruntime_providers_webgpu dxcompiler)
|
||||
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE_DIR:dxcompiler>/dxil.dll")
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE_DIR:dxcompiler>/dxcompiler.dll")
|
||||
endif()
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE_DIR:dxcompiler>/dxil.dll")
|
||||
list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE_DIR:dxcompiler>/dxcompiler.dll")
|
||||
endif()
|
||||
|
||||
if (onnxruntime_providers_webgpu_dll_deps)
|
||||
# Copy dependency DLLs to the output directory
|
||||
add_custom_command(
|
||||
TARGET onnxruntime_providers_webgpu
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${onnxruntime_providers_webgpu_dll_deps}" "$<TARGET_FILE_DIR:onnxruntime_providers_webgpu>"
|
||||
COMMAND_EXPAND_LISTS
|
||||
VERBATIM )
|
||||
if (onnxruntime_providers_webgpu_dll_deps)
|
||||
# Copy dependency DLLs to the output directory
|
||||
add_custom_command(
|
||||
TARGET onnxruntime_providers_webgpu
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${onnxruntime_providers_webgpu_dll_deps}" "$<TARGET_FILE_DIR:onnxruntime_providers_webgpu>"
|
||||
COMMAND_EXPAND_LISTS
|
||||
VERBATIM )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_dependencies(onnxruntime_providers_webgpu ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
||||
|
|
|
|||
|
|
@ -982,6 +982,9 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|||
set_target_properties(onnxruntime_test_all PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js)
|
||||
set_property(TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " --pre-js \"${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js\"")
|
||||
endif()
|
||||
if (onnxruntime_USE_WEBGPU)
|
||||
set_property(TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " -s ASYNCIFY_STACK_SIZE=131072")
|
||||
endif()
|
||||
|
||||
###
|
||||
### if you want to investigate or debug a test failure in onnxruntime_test_all, replace the following line.
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ if (onnxruntime_BUILD_WEBASSEMBLY_STATIC_LIB)
|
|||
${PROVIDERS_JS}
|
||||
${PROVIDERS_XNNPACK}
|
||||
${PROVIDERS_WEBNN}
|
||||
${PROVIDERS_WEBGPU}
|
||||
onnxruntime_session
|
||||
onnxruntime_util
|
||||
re2::re2
|
||||
|
|
@ -188,6 +189,7 @@ else()
|
|||
${PROVIDERS_JS}
|
||||
${PROVIDERS_XNNPACK}
|
||||
${PROVIDERS_WEBNN}
|
||||
${PROVIDERS_WEBGPU}
|
||||
onnxruntime_session
|
||||
onnxruntime_util
|
||||
re2::re2
|
||||
|
|
@ -391,6 +393,10 @@ jsepDownload:_pp_")
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if (onnxruntime_USE_WEBGPU)
|
||||
target_compile_definitions(onnxruntime_webassembly PRIVATE USE_WEBGPU=1)
|
||||
endif()
|
||||
|
||||
if (onnxruntime_EMSCRIPTEN_SETTINGS)
|
||||
foreach(setting IN LISTS onnxruntime_EMSCRIPTEN_SETTINGS)
|
||||
target_link_options(onnxruntime_webassembly PRIVATE "SHELL:-s ${setting}")
|
||||
|
|
|
|||
118
cmake/patches/dawn/dawn.patch
Normal file
118
cmake/patches/dawn/dawn.patch
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
diff --git a/src/emdawnwebgpu/CMakeLists.txt b/src/emdawnwebgpu/CMakeLists.txt
|
||||
index de673537d3..c98dc46de7 100644
|
||||
--- a/src/emdawnwebgpu/CMakeLists.txt
|
||||
+++ b/src/emdawnwebgpu/CMakeLists.txt
|
||||
@@ -78,6 +78,7 @@ if (${DAWN_ENABLE_EMSCRIPTEN})
|
||||
endif()
|
||||
|
||||
set(ARGS
|
||||
+ ${Python3_EXECUTABLE}
|
||||
"${DAWN_EMSCRIPTEN_TOOLCHAIN}/tools/maint/gen_struct_info.py"
|
||||
-q
|
||||
"${EM_BUILD_GEN_DIR}/struct_info_webgpu.json"
|
||||
diff --git a/third_party/emdawnwebgpu/library_webgpu.js b/third_party/emdawnwebgpu/library_webgpu.js
|
||||
index d1835cb090..df03ea2f94 100644
|
||||
--- a/third_party/emdawnwebgpu/library_webgpu.js
|
||||
+++ b/third_party/emdawnwebgpu/library_webgpu.js
|
||||
@@ -16,10 +16,19 @@
|
||||
throw new Error("To use Dawn's library_webgpu.js, disable -sUSE_WEBGPU and first include Dawn's library_webgpu_struct_info.js and library_webgpu_enum_tables.js (before library_webgpu.js)");
|
||||
}
|
||||
|
||||
+ if (MEMORY64) {
|
||||
+ throw new Error("The current implementation of Dawn's library_webgpu.js does not support MEMORY64 yet");
|
||||
+ }
|
||||
+
|
||||
// Helper functions for code generation
|
||||
globalThis.gpu = {
|
||||
- convertSentinelToUndefined: function(name) {
|
||||
- return `if (${name} == -1) ${name} = undefined;`;
|
||||
+ convertSentinelToUndefined: function(name, isPtr = false) {
|
||||
+ // When `CAN_ADDRESS_2GB` is true, value `-1` is normalized to `0xFFFFFFFF` for pointer.
|
||||
+ if (CAN_ADDRESS_2GB && isPtr) {
|
||||
+ return `if (${name} == 0xFFFFFFFF) ${name} = undefined;`;
|
||||
+ } else {
|
||||
+ return `if (${name} == -1) ${name} = undefined;`;
|
||||
+ }
|
||||
},
|
||||
|
||||
makeGetBool: function(struct, offset) {
|
||||
@@ -700,6 +709,7 @@ var LibraryWebGPU = {
|
||||
{{{ makeSetValue('info', C_STRUCTS.WGPUAdapterInfo.adapterType, 'adapterType', 'i32') }}};
|
||||
{{{ makeSetValue('info', C_STRUCTS.WGPUAdapterInfo.vendorID, '0', 'i32') }}};
|
||||
{{{ makeSetValue('info', C_STRUCTS.WGPUAdapterInfo.deviceID, '0', 'i32') }}};
|
||||
+ return 1;
|
||||
},
|
||||
|
||||
wgpuAdapterGetLimits: (adapterPtr, limitsOutPtr) => {
|
||||
@@ -882,7 +892,7 @@ var LibraryWebGPU = {
|
||||
|
||||
if (size === 0) warnOnce('getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE');
|
||||
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
|
||||
var mapped;
|
||||
try {
|
||||
@@ -909,7 +919,7 @@ var LibraryWebGPU = {
|
||||
|
||||
if (size === 0) warnOnce('getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE');
|
||||
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
|
||||
var mapped;
|
||||
try {
|
||||
@@ -950,7 +960,7 @@ var LibraryWebGPU = {
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
WebGPU.Internals.bufferOnUnmaps[bufferPtr] = [];
|
||||
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
|
||||
{{{ runtimeKeepalivePush() }}}
|
||||
WebGPU.Internals.futureInsert(futureId, buffer.mapAsync(mode, offset, size).then(() => {
|
||||
@@ -1145,7 +1155,7 @@ var LibraryWebGPU = {
|
||||
|
||||
wgpuCommandEncoderClearBuffer: (encoderPtr, bufferPtr, offset, size) => {
|
||||
var commandEncoder = WebGPU.getJsObject(encoderPtr);
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
commandEncoder.clearBuffer(buffer, offset, size);
|
||||
@@ -2103,7 +2113,7 @@ var LibraryWebGPU = {
|
||||
wgpuRenderBundleEncoderSetIndexBuffer: (passPtr, bufferPtr, format, offset, size) => {
|
||||
var pass = WebGPU.getJsObject(passPtr);
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
pass.setIndexBuffer(buffer, WebGPU.IndexFormat[format], offset, size);
|
||||
},
|
||||
|
||||
@@ -2116,7 +2126,7 @@ var LibraryWebGPU = {
|
||||
wgpuRenderBundleEncoderSetVertexBuffer: (passPtr, slot, bufferPtr, offset, size) => {
|
||||
var pass = WebGPU.getJsObject(passPtr);
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
pass.setVertexBuffer(slot, buffer, offset, size);
|
||||
},
|
||||
|
||||
@@ -2211,7 +2221,7 @@ var LibraryWebGPU = {
|
||||
wgpuRenderPassEncoderSetIndexBuffer: (passPtr, bufferPtr, format, offset, size) => {
|
||||
var pass = WebGPU.getJsObject(passPtr);
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
pass.setIndexBuffer(buffer, WebGPU.IndexFormat[format], offset, size);
|
||||
},
|
||||
|
||||
@@ -2234,7 +2244,7 @@ var LibraryWebGPU = {
|
||||
wgpuRenderPassEncoderSetVertexBuffer: (passPtr, slot, bufferPtr, offset, size) => {
|
||||
var pass = WebGPU.getJsObject(passPtr);
|
||||
var buffer = WebGPU.getJsObject(bufferPtr);
|
||||
- {{{ gpu.convertSentinelToUndefined('size') }}}
|
||||
+ {{{ gpu.convertSentinelToUndefined('size', true) }}}
|
||||
pass.setVertexBuffer(slot, buffer, offset, size);
|
||||
},
|
||||
|
||||
573
cmake/patches/emscripten/src/closure-externs/webgpu-externs.js
Normal file
573
cmake/patches/emscripten/src/closure-externs/webgpu-externs.js
Normal file
|
|
@ -0,0 +1,573 @@
|
|||
/*
|
||||
* WebGPU globals
|
||||
* Generated using https://github.com/kainino0x/webidl-to-closure-externs
|
||||
* against the spec's WebIDL: https://gpuweb.github.io/gpuweb/webgpu.idl
|
||||
*/
|
||||
|
||||
/** @type {?GPU} */
|
||||
Navigator.prototype.gpu;
|
||||
|
||||
/** @type {?GPU} */
|
||||
WorkerNavigator.prototype.gpu;
|
||||
|
||||
const GPUBufferUsage = {};
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.MAP_READ;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.MAP_WRITE;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.COPY_SRC;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.COPY_DST;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.INDEX;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.VERTEX;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.UNIFORM;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.STORAGE;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.INDIRECT;
|
||||
/** @type {number} */
|
||||
GPUBufferUsage.QUERY_RESOLVE;
|
||||
|
||||
const GPUMapMode = {};
|
||||
/** @type {number} */
|
||||
GPUMapMode.READ;
|
||||
/** @type {number} */
|
||||
GPUMapMode.WRITE;
|
||||
|
||||
const GPUTextureUsage = {};
|
||||
/** @type {number} */
|
||||
GPUTextureUsage.COPY_SRC;
|
||||
/** @type {number} */
|
||||
GPUTextureUsage.COPY_DST;
|
||||
/** @type {number} */
|
||||
GPUTextureUsage.TEXTURE_BINDING;
|
||||
/** @type {number} */
|
||||
GPUTextureUsage.STORAGE_BINDING;
|
||||
/** @type {number} */
|
||||
GPUTextureUsage.RENDER_ATTACHMENT;
|
||||
|
||||
const GPUShaderStage = {};
|
||||
/** @type {number} */
|
||||
GPUShaderStage.VERTEX;
|
||||
/** @type {number} */
|
||||
GPUShaderStage.FRAGMENT;
|
||||
/** @type {number} */
|
||||
GPUShaderStage.COMPUTE;
|
||||
|
||||
const GPUColorWrite = {};
|
||||
/** @type {number} */
|
||||
GPUColorWrite.RED;
|
||||
/** @type {number} */
|
||||
GPUColorWrite.GREEN;
|
||||
/** @type {number} */
|
||||
GPUColorWrite.BLUE;
|
||||
/** @type {number} */
|
||||
GPUColorWrite.ALPHA;
|
||||
/** @type {number} */
|
||||
GPUColorWrite.ALL;
|
||||
|
||||
/** @constructor */
|
||||
function GPUSupportedLimits() {}
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxTextureDimension1D;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxTextureDimension2D;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxTextureDimension3D;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxTextureArrayLayers;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxBindGroups;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxBindGroupsPlusVertexBuffers;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxBindingsPerBindGroup;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxDynamicUniformBuffersPerPipelineLayout;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxDynamicStorageBuffersPerPipelineLayout;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxSampledTexturesPerShaderStage;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxSamplersPerShaderStage;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxStorageBuffersPerShaderStage;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxStorageTexturesPerShaderStage;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxUniformBuffersPerShaderStage;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxUniformBufferBindingSize;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxStorageBufferBindingSize;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.minUniformBufferOffsetAlignment;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.minStorageBufferOffsetAlignment;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxVertexBuffers;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxBufferSize;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxVertexAttributes;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxVertexBufferArrayStride;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxInterStageShaderComponents;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxInterStageShaderVariables;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxColorAttachments;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxColorAttachmentBytesPerSample;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeWorkgroupStorageSize;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeInvocationsPerWorkgroup;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeWorkgroupSizeX;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeWorkgroupSizeY;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeWorkgroupSizeZ;
|
||||
/** @type {number} */
|
||||
GPUSupportedLimits.prototype.maxComputeWorkgroupsPerDimension;
|
||||
|
||||
/** @constructor */
|
||||
function GPUSupportedFeatures() {}
|
||||
/** @type {number} */
|
||||
GPUSupportedFeatures.prototype.size;
|
||||
/** @return {!Iterable<string>} */
|
||||
GPUSupportedFeatures.prototype.entries = function() {};
|
||||
/** @return {!Iterable<string>} */
|
||||
GPUSupportedFeatures.prototype.keys = function() {};
|
||||
/** @return {!Iterable<string>} */
|
||||
GPUSupportedFeatures.prototype.values = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUSupportedFeatures.prototype.forEach = function() {};
|
||||
/** @return {boolean} */
|
||||
GPUSupportedFeatures.prototype.has = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function WGSLLanguageFeatures() {}
|
||||
/** @type {number} */
|
||||
WGSLLanguageFeatures.prototype.size;
|
||||
/** @return {!Iterable<string>} */
|
||||
WGSLLanguageFeatures.prototype.entries = function() {};
|
||||
/** @return {!Iterable<string>} */
|
||||
WGSLLanguageFeatures.prototype.keys = function() {};
|
||||
/** @return {!Iterable<string>} */
|
||||
WGSLLanguageFeatures.prototype.values = function() {};
|
||||
/** @return {undefined} */
|
||||
WGSLLanguageFeatures.prototype.forEach = function() {};
|
||||
/** @return {boolean} */
|
||||
WGSLLanguageFeatures.prototype.has = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUAdapterInfo() {}
|
||||
/** @type {string} */
|
||||
GPUAdapterInfo.prototype.vendor;
|
||||
/** @type {string} */
|
||||
GPUAdapterInfo.prototype.architecture;
|
||||
/** @type {string} */
|
||||
GPUAdapterInfo.prototype.device;
|
||||
/** @type {string} */
|
||||
GPUAdapterInfo.prototype.description;
|
||||
|
||||
/** @constructor */
|
||||
function GPU() {}
|
||||
/** @return {!Promise<?GPUAdapter>} */
|
||||
GPU.prototype.requestAdapter = function() {};
|
||||
/** @return {string} */
|
||||
GPU.prototype.getPreferredCanvasFormat = function() {};
|
||||
/** @type {!WGSLLanguageFeatures} */
|
||||
GPU.prototype.wgslLanguageFeatures;
|
||||
|
||||
/** @constructor */
|
||||
function GPUAdapter() {}
|
||||
/** @type {!GPUSupportedFeatures} */
|
||||
GPUAdapter.prototype.features;
|
||||
/** @type {!GPUSupportedLimits} */
|
||||
GPUAdapter.prototype.limits;
|
||||
/** @type {boolean} */
|
||||
GPUAdapter.prototype.isFallbackAdapter;
|
||||
/** @return {!Promise<!GPUDevice>} */
|
||||
GPUAdapter.prototype.requestDevice = function() {};
|
||||
/** @return {!Promise<!GPUAdapterInfo>} */
|
||||
GPUAdapter.prototype.requestAdapterInfo = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUDevice() {}
|
||||
/** @type {string} */
|
||||
GPUDevice.prototype.label;
|
||||
/** @type {!GPUSupportedFeatures} */
|
||||
GPUDevice.prototype.features;
|
||||
/** @type {!GPUSupportedLimits} */
|
||||
GPUDevice.prototype.limits;
|
||||
/** @type {!GPUQueue} */
|
||||
GPUDevice.prototype.queue;
|
||||
/** @return {undefined} */
|
||||
GPUDevice.prototype.destroy = function() {};
|
||||
/** @return {!GPUBuffer} */
|
||||
GPUDevice.prototype.createBuffer = function() {};
|
||||
/** @return {!GPUTexture} */
|
||||
GPUDevice.prototype.createTexture = function() {};
|
||||
/** @return {!GPUSampler} */
|
||||
GPUDevice.prototype.createSampler = function() {};
|
||||
/** @return {!GPUExternalTexture} */
|
||||
GPUDevice.prototype.importExternalTexture = function() {};
|
||||
/** @return {!GPUBindGroupLayout} */
|
||||
GPUDevice.prototype.createBindGroupLayout = function() {};
|
||||
/** @return {!GPUPipelineLayout} */
|
||||
GPUDevice.prototype.createPipelineLayout = function() {};
|
||||
/** @return {!GPUBindGroup} */
|
||||
GPUDevice.prototype.createBindGroup = function() {};
|
||||
/** @return {!GPUShaderModule} */
|
||||
GPUDevice.prototype.createShaderModule = function() {};
|
||||
/** @return {!GPUComputePipeline} */
|
||||
GPUDevice.prototype.createComputePipeline = function() {};
|
||||
/** @return {!GPURenderPipeline} */
|
||||
GPUDevice.prototype.createRenderPipeline = function() {};
|
||||
/** @return {!Promise<!GPUComputePipeline>} */
|
||||
GPUDevice.prototype.createComputePipelineAsync = function() {};
|
||||
/** @return {!Promise<!GPURenderPipeline>} */
|
||||
GPUDevice.prototype.createRenderPipelineAsync = function() {};
|
||||
/** @return {!GPUCommandEncoder} */
|
||||
GPUDevice.prototype.createCommandEncoder = function() {};
|
||||
/** @return {!GPURenderBundleEncoder} */
|
||||
GPUDevice.prototype.createRenderBundleEncoder = function() {};
|
||||
/** @return {!GPUQuerySet} */
|
||||
GPUDevice.prototype.createQuerySet = function() {};
|
||||
/** @type {!Promise<!GPUDeviceLostInfo>} */
|
||||
GPUDevice.prototype.lost;
|
||||
/** @return {undefined} */
|
||||
GPUDevice.prototype.pushErrorScope = function() {};
|
||||
/** @return {!Promise<?GPUError>} */
|
||||
GPUDevice.prototype.popErrorScope = function() {};
|
||||
/** @type {!Function} */
|
||||
GPUDevice.prototype.onuncapturederror;
|
||||
|
||||
/** @constructor */
|
||||
function GPUBuffer() {}
|
||||
/** @type {string} */
|
||||
GPUBuffer.prototype.label;
|
||||
/** @type {number} */
|
||||
GPUBuffer.prototype.size;
|
||||
/** @type {number} */
|
||||
GPUBuffer.prototype.usage;
|
||||
/** @type {string} */
|
||||
GPUBuffer.prototype.mapState;
|
||||
/** @return {!Promise<undefined>} */
|
||||
GPUBuffer.prototype.mapAsync = function() {};
|
||||
/** @return {!ArrayBuffer} */
|
||||
GPUBuffer.prototype.getMappedRange = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUBuffer.prototype.unmap = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUBuffer.prototype.destroy = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUTexture() {}
|
||||
/** @type {string} */
|
||||
GPUTexture.prototype.label;
|
||||
/** @return {!GPUTextureView} */
|
||||
GPUTexture.prototype.createView = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUTexture.prototype.destroy = function() {};
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.width;
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.height;
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.depthOrArrayLayers;
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.mipLevelCount;
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.sampleCount;
|
||||
/** @type {string} */
|
||||
GPUTexture.prototype.dimension;
|
||||
/** @type {string} */
|
||||
GPUTexture.prototype.format;
|
||||
/** @type {number} */
|
||||
GPUTexture.prototype.usage;
|
||||
|
||||
/** @constructor */
|
||||
function GPUTextureView() {}
|
||||
/** @type {string} */
|
||||
GPUTextureView.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUExternalTexture() {}
|
||||
/** @type {string} */
|
||||
GPUExternalTexture.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUSampler() {}
|
||||
/** @type {string} */
|
||||
GPUSampler.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUBindGroupLayout() {}
|
||||
/** @type {string} */
|
||||
GPUBindGroupLayout.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUBindGroup() {}
|
||||
/** @type {string} */
|
||||
GPUBindGroup.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUPipelineLayout() {}
|
||||
/** @type {string} */
|
||||
GPUPipelineLayout.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUShaderModule() {}
|
||||
/** @type {string} */
|
||||
GPUShaderModule.prototype.label;
|
||||
/** @return {!Promise<!GPUCompilationInfo>} */
|
||||
GPUShaderModule.prototype.getCompilationInfo = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUCompilationMessage() {}
|
||||
/** @type {string} */
|
||||
GPUCompilationMessage.prototype.message;
|
||||
/** @type {string} */
|
||||
GPUCompilationMessage.prototype.type;
|
||||
/** @type {number} */
|
||||
GPUCompilationMessage.prototype.lineNum;
|
||||
/** @type {number} */
|
||||
GPUCompilationMessage.prototype.linePos;
|
||||
/** @type {number} */
|
||||
GPUCompilationMessage.prototype.offset;
|
||||
/** @type {number} */
|
||||
GPUCompilationMessage.prototype.length;
|
||||
|
||||
/** @constructor */
|
||||
function GPUCompilationInfo() {}
|
||||
/** @type {!Array<!GPUCompilationMessage>} */
|
||||
GPUCompilationInfo.prototype.messages;
|
||||
|
||||
/** @constructor */
|
||||
function GPUPipelineError() {}
|
||||
/** @type {string} */
|
||||
GPUPipelineError.prototype.reason;
|
||||
|
||||
/** @constructor */
|
||||
function GPUComputePipeline() {}
|
||||
/** @type {string} */
|
||||
GPUComputePipeline.prototype.label;
|
||||
/** @return {!GPUBindGroupLayout} */
|
||||
GPUComputePipeline.prototype.getBindGroupLayout = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPURenderPipeline() {}
|
||||
/** @type {string} */
|
||||
GPURenderPipeline.prototype.label;
|
||||
/** @return {!GPUBindGroupLayout} */
|
||||
GPURenderPipeline.prototype.getBindGroupLayout = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUCommandBuffer() {}
|
||||
/** @type {string} */
|
||||
GPUCommandBuffer.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPUCommandEncoder() {}
|
||||
/** @type {string} */
|
||||
GPUCommandEncoder.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.pushDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.popDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.insertDebugMarker = function() {};
|
||||
/** @return {!GPURenderPassEncoder} */
|
||||
GPUCommandEncoder.prototype.beginRenderPass = function() {};
|
||||
/** @return {!GPUComputePassEncoder} */
|
||||
GPUCommandEncoder.prototype.beginComputePass = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.copyBufferToBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.copyBufferToTexture = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.copyTextureToBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.copyTextureToTexture = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.clearBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCommandEncoder.prototype.resolveQuerySet = function() {};
|
||||
/** @return {!GPUCommandBuffer} */
|
||||
GPUCommandEncoder.prototype.finish = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUComputePassEncoder() {}
|
||||
/** @type {string} */
|
||||
GPUComputePassEncoder.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.pushDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.popDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.insertDebugMarker = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.setPipeline = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.dispatchWorkgroups = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.dispatchWorkgroupsIndirect = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUComputePassEncoder.prototype.end = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPURenderPassEncoder() {}
|
||||
/** @type {string} */
|
||||
GPURenderPassEncoder.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.pushDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.popDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.insertDebugMarker = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setPipeline = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setIndexBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setVertexBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.draw = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.drawIndexed = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.drawIndirect = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.drawIndexedIndirect = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setViewport = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setScissorRect = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setBlendConstant = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.setStencilReference = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.beginOcclusionQuery = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.endOcclusionQuery = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.executeBundles = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderPassEncoder.prototype.end = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPURenderBundle() {}
|
||||
/** @type {string} */
|
||||
GPURenderBundle.prototype.label;
|
||||
|
||||
/** @constructor */
|
||||
function GPURenderBundleEncoder() {}
|
||||
/** @type {string} */
|
||||
GPURenderBundleEncoder.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.pushDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.popDebugGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.insertDebugMarker = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.setBindGroup = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.setPipeline = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.setIndexBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.setVertexBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.draw = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.drawIndexed = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.drawIndirect = function() {};
|
||||
/** @return {undefined} */
|
||||
GPURenderBundleEncoder.prototype.drawIndexedIndirect = function() {};
|
||||
/** @return {!GPURenderBundle} */
|
||||
GPURenderBundleEncoder.prototype.finish = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUQueue() {}
|
||||
/** @type {string} */
|
||||
GPUQueue.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPUQueue.prototype.submit = function() {};
|
||||
/** @return {!Promise<undefined>} */
|
||||
GPUQueue.prototype.onSubmittedWorkDone = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUQueue.prototype.writeBuffer = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUQueue.prototype.writeTexture = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUQueue.prototype.copyExternalImageToTexture = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUQuerySet() {}
|
||||
/** @type {string} */
|
||||
GPUQuerySet.prototype.label;
|
||||
/** @return {undefined} */
|
||||
GPUQuerySet.prototype.destroy = function() {};
|
||||
/** @type {string} */
|
||||
GPUQuerySet.prototype.type;
|
||||
/** @type {number} */
|
||||
GPUQuerySet.prototype.count;
|
||||
|
||||
/** @constructor */
|
||||
function GPUCanvasContext() {}
|
||||
/** @type {!HTMLCanvasElement|!OffscreenCanvas} */
|
||||
GPUCanvasContext.prototype.canvas;
|
||||
/** @return {undefined} */
|
||||
GPUCanvasContext.prototype.configure = function() {};
|
||||
/** @return {undefined} */
|
||||
GPUCanvasContext.prototype.unconfigure = function() {};
|
||||
/** @return {!GPUTexture} */
|
||||
GPUCanvasContext.prototype.getCurrentTexture = function() {};
|
||||
|
||||
/** @constructor */
|
||||
function GPUDeviceLostInfo() {}
|
||||
/** @type {string} */
|
||||
GPUDeviceLostInfo.prototype.reason;
|
||||
/** @type {string} */
|
||||
GPUDeviceLostInfo.prototype.message;
|
||||
|
||||
/** @constructor */
|
||||
function GPUError() {}
|
||||
/** @type {string} */
|
||||
GPUError.prototype.message;
|
||||
|
||||
/** @constructor */
|
||||
function GPUValidationError() {}
|
||||
|
||||
/** @constructor */
|
||||
function GPUOutOfMemoryError() {}
|
||||
|
||||
/** @constructor */
|
||||
function GPUInternalError() {}
|
||||
|
||||
/** @constructor */
|
||||
function GPUUncapturedErrorEvent() {}
|
||||
/** @type {!GPUError} */
|
||||
GPUUncapturedErrorEvent.prototype.error;
|
||||
448
cmake/patches/emscripten/tools/maint/gen_struct_info.py
Normal file
448
cmake/patches/emscripten/tools/maint/gen_struct_info.py
Normal file
|
|
@ -0,0 +1,448 @@
|
|||
#!/usr/bin/env python3
|
||||
# coding=utf-8
|
||||
# Copyright 2013 The Emscripten Authors. All rights reserved.
|
||||
# Emscripten is available under two separate licenses, the MIT license and the
|
||||
# University of Illinois/NCSA Open Source License. Both these licenses can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""This tool extracts information about structs and defines from the C headers.
|
||||
|
||||
The JSON input format is as follows:
|
||||
[
|
||||
{
|
||||
'file': 'some/header.h',
|
||||
'structs': {
|
||||
'struct_name': [
|
||||
'field1',
|
||||
'field2',
|
||||
'field3',
|
||||
{
|
||||
'field4': [
|
||||
'nested1',
|
||||
'nested2',
|
||||
{
|
||||
'nested3': [
|
||||
'deep_nested1',
|
||||
...
|
||||
]
|
||||
}
|
||||
...
|
||||
]
|
||||
},
|
||||
'field5'
|
||||
],
|
||||
'other_struct': [
|
||||
'field1',
|
||||
'field2',
|
||||
...
|
||||
]
|
||||
},
|
||||
'defines': [
|
||||
'DEFINE_1',
|
||||
'DEFINE_2',
|
||||
['f', 'FLOAT_DEFINE'],
|
||||
'DEFINE_3',
|
||||
...
|
||||
]
|
||||
},
|
||||
{
|
||||
'file': 'some/other/header.h',
|
||||
...
|
||||
}
|
||||
]
|
||||
|
||||
Please note that the 'f' for 'FLOAT_DEFINE' is just the format passed to printf(), you can put
|
||||
anything printf() understands.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import argparse
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
|
||||
__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))
|
||||
sys.path.insert(0, __rootdir__)
|
||||
|
||||
from tools import building
|
||||
from tools import config
|
||||
from tools import shared
|
||||
from tools import system_libs
|
||||
from tools import utils
|
||||
|
||||
QUIET = (__name__ != '__main__')
|
||||
DEBUG = False
|
||||
|
||||
CFLAGS = [
|
||||
# Avoid parsing problems due to gcc specific syntax.
|
||||
'-D_GNU_SOURCE',
|
||||
]
|
||||
|
||||
INTERNAL_CFLAGS = [
|
||||
'-I' + utils.path_from_root('system/lib/libc/musl/src/internal'),
|
||||
'-I' + utils.path_from_root('system/lib/libc/musl/src/include'),
|
||||
'-I' + utils.path_from_root('system/lib/pthread/'),
|
||||
]
|
||||
|
||||
CXXFLAGS = [
|
||||
'-I' + utils.path_from_root('system/lib/libcxxabi/src'),
|
||||
'-D__EMSCRIPTEN_EXCEPTIONS__',
|
||||
'-I' + utils.path_from_root('system/lib/wasmfs/'),
|
||||
'-std=c++17',
|
||||
]
|
||||
|
||||
DEFAULT_JSON_FILES = [
|
||||
utils.path_from_root('src/struct_info.json'),
|
||||
utils.path_from_root('src/struct_info_internal.json'),
|
||||
utils.path_from_root('src/struct_info_cxx.json'),
|
||||
utils.path_from_root('src/struct_info_webgpu.json'),
|
||||
]
|
||||
|
||||
|
||||
def show(msg):
|
||||
if shared.DEBUG or not QUIET:
|
||||
sys.stderr.write('gen_struct_info: %s\n' % msg)
|
||||
|
||||
|
||||
# The following three functions generate C code. The output of the compiled code will be
|
||||
# parsed later on and then put back together into a dict structure by parse_c_output().
|
||||
#
|
||||
# Example:
|
||||
# c_descent('test1', code)
|
||||
# c_set('item', 'i%i', '111', code)
|
||||
# c_set('item2', 'i%i', '9', code)
|
||||
# c_set('item3', 's%s', '"Hello"', code)
|
||||
# c_ascent(code)
|
||||
# c_set('outer', 'f%f', '0.999', code)
|
||||
#
|
||||
# Will result in:
|
||||
# {
|
||||
# 'test1': {
|
||||
# 'item': 111,
|
||||
# 'item2': 9,
|
||||
# 'item3': 'Hello',
|
||||
# },
|
||||
# 'outer': 0.999
|
||||
# }
|
||||
def c_set(name, type_, value, code):
|
||||
code.append('printf("K' + name + '\\n");')
|
||||
code.append('printf("V' + type_ + '\\n", ' + value + ');')
|
||||
|
||||
|
||||
def c_descent(name, code):
|
||||
code.append('printf("D' + name + '\\n");')
|
||||
|
||||
|
||||
def c_ascent(code):
|
||||
code.append('printf("A\\n");')
|
||||
|
||||
|
||||
def parse_c_output(lines):
|
||||
result = {}
|
||||
cur_level = result
|
||||
parent = []
|
||||
key = None
|
||||
|
||||
for line in lines:
|
||||
arg = line[1:].strip()
|
||||
if '::' in arg:
|
||||
arg = arg.split('::', 1)[1]
|
||||
if line[0] == 'K':
|
||||
# This is a key
|
||||
key = arg
|
||||
elif line[0] == 'V':
|
||||
# A value
|
||||
if arg[0] == 'i':
|
||||
arg = int(arg[1:])
|
||||
elif arg[0] == 'f':
|
||||
arg = float(arg[1:])
|
||||
elif arg[0] == 's':
|
||||
arg = arg[1:]
|
||||
|
||||
cur_level[key] = arg
|
||||
elif line[0] == 'D':
|
||||
# Remember the current level as the last parent.
|
||||
parent.append(cur_level)
|
||||
|
||||
# We descend one level.
|
||||
cur_level[arg] = {}
|
||||
cur_level = cur_level[arg]
|
||||
elif line[0] == 'A':
|
||||
# We return to the parent dict. (One level up.)
|
||||
cur_level = parent.pop()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def gen_inspect_code(path, struct, code):
|
||||
if path[0][-1] == '#':
|
||||
path[0] = path[0].rstrip('#')
|
||||
prefix = ''
|
||||
else:
|
||||
prefix = 'struct '
|
||||
|
||||
c_descent(path[-1], code)
|
||||
|
||||
if len(path) == 1:
|
||||
c_set('__size__', 'i%zu', 'sizeof (' + prefix + path[0] + ')', code)
|
||||
else:
|
||||
c_set('__size__', 'i%zu', 'sizeof ((' + prefix + path[0] + ' *)0)->' + '.'.join(path[1:]), code)
|
||||
# c_set('__offset__', 'i%zu', 'offsetof(' + prefix + path[0] + ', ' + '.'.join(path[1:]) + ')', code)
|
||||
|
||||
for field in struct:
|
||||
if isinstance(field, dict):
|
||||
# We have to recurse to inspect the nested dict.
|
||||
fname = list(field.keys())[0]
|
||||
gen_inspect_code(path + [fname], field[fname], code)
|
||||
else:
|
||||
c_set(field, 'i%zu', 'offsetof(' + prefix + path[0] + ', ' + '.'.join(path[1:] + [field]) + ')', code)
|
||||
|
||||
c_ascent(code)
|
||||
|
||||
|
||||
def generate_c_code(headers):
|
||||
code = ['#include <stdio.h>', '#include <stddef.h>']
|
||||
|
||||
code.extend(f'''#include "{header['name']}"''' for header in headers)
|
||||
|
||||
code.append('int main() {')
|
||||
c_descent('structs', code)
|
||||
for header in headers:
|
||||
for name, struct in header['structs'].items():
|
||||
gen_inspect_code([name], struct, code)
|
||||
|
||||
c_ascent(code)
|
||||
c_descent('defines', code)
|
||||
for header in headers:
|
||||
for name, type_ in header['defines'].items():
|
||||
# Add the necessary python type, if missing.
|
||||
if '%' not in type_:
|
||||
if type_[-1] in {'d', 'i', 'u'}:
|
||||
# integer
|
||||
type_ = 'i%' + type_
|
||||
elif type_[-1] in {'f', 'F', 'e', 'E', 'g', 'G'}:
|
||||
# float
|
||||
type_ = 'f%' + type_
|
||||
elif type_[-1] in {'x', 'X', 'a', 'A', 'c', 's'}:
|
||||
# hexadecimal or string
|
||||
type_ = 's%' + type_
|
||||
|
||||
c_set(name, type_, name, code)
|
||||
|
||||
code.append('return 0;')
|
||||
code.append('}')
|
||||
|
||||
return code
|
||||
|
||||
|
||||
def generate_cmd(js_file_path, src_file_path, cflags):
|
||||
# Compile the program.
|
||||
show('Compiling generated code...')
|
||||
|
||||
if any('libcxxabi' in f for f in cflags):
|
||||
compiler = shared.EMXX
|
||||
else:
|
||||
compiler = shared.EMCC
|
||||
|
||||
node_flags = building.get_emcc_node_flags(shared.check_node_version())
|
||||
|
||||
# -O1+ produces calls to iprintf, which libcompiler_rt doesn't support
|
||||
cmd = [compiler] + cflags + ['-o', js_file_path, src_file_path,
|
||||
'-O0',
|
||||
'-Werror',
|
||||
'-Wno-format',
|
||||
'-nolibc',
|
||||
'-sBOOTSTRAPPING_STRUCT_INFO',
|
||||
'-sINCOMING_MODULE_JS_API=',
|
||||
'-sSTRICT',
|
||||
'-sSUPPORT_LONGJMP=0',
|
||||
'-sASSERTIONS=0'] + node_flags
|
||||
|
||||
# Default behavior for emcc is to warn for binaryen version check mismatches
|
||||
# so we should try to match that behavior.
|
||||
cmd += ['-Wno-error=version-check']
|
||||
|
||||
# TODO(sbc): Remove this one we remove the test_em_config_env_var test
|
||||
cmd += ['-Wno-deprecated']
|
||||
|
||||
show(shared.shlex_join(cmd))
|
||||
return cmd
|
||||
|
||||
|
||||
def inspect_headers(headers, cflags):
|
||||
# Write the source code to a temporary file.
|
||||
src_file_fd, src_file_path = tempfile.mkstemp('.c', text=True)
|
||||
show('Generating C code... ' + src_file_path)
|
||||
code = generate_c_code(headers)
|
||||
os.write(src_file_fd, '\n'.join(code).encode())
|
||||
os.close(src_file_fd)
|
||||
|
||||
js_file_fd, js_file_path = tempfile.mkstemp('.js')
|
||||
# Close the unneeded FD.
|
||||
os.close(js_file_fd)
|
||||
|
||||
cmd = generate_cmd(js_file_path, src_file_path, cflags)
|
||||
|
||||
try:
|
||||
subprocess.check_call(cmd, env=system_libs.clean_env())
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.stderr.write('FAIL: Compilation failed!: %s\n' % e.cmd)
|
||||
sys.exit(1)
|
||||
|
||||
# Run the compiled program.
|
||||
show('Calling generated program... ' + js_file_path)
|
||||
node_args = shared.node_bigint_flags(config.NODE_JS)
|
||||
info = shared.run_js_tool(js_file_path, node_args=node_args, stdout=shared.PIPE).splitlines()
|
||||
|
||||
if not DEBUG:
|
||||
# Remove all temporary files.
|
||||
os.unlink(src_file_path)
|
||||
|
||||
if os.path.exists(js_file_path):
|
||||
os.unlink(js_file_path)
|
||||
wasm_file_path = shared.replace_suffix(js_file_path, '.wasm')
|
||||
os.unlink(wasm_file_path)
|
||||
|
||||
# Parse the output of the program into a dict.
|
||||
return parse_c_output(info)
|
||||
|
||||
|
||||
def merge_info(target, src):
|
||||
for key, value in src['defines'].items():
|
||||
if key in target['defines']:
|
||||
raise Exception('duplicate define: %s' % key)
|
||||
target['defines'][key] = value
|
||||
|
||||
for key, value in src['structs'].items():
|
||||
if key in target['structs']:
|
||||
raise Exception('duplicate struct: %s' % key)
|
||||
target['structs'][key] = value
|
||||
|
||||
|
||||
def inspect_code(headers, cflags):
|
||||
if not DEBUG:
|
||||
info = inspect_headers(headers, cflags)
|
||||
else:
|
||||
info = {'defines': {}, 'structs': {}}
|
||||
for header in headers:
|
||||
merge_info(info, inspect_headers([header], cflags))
|
||||
return info
|
||||
|
||||
|
||||
def parse_json(path):
|
||||
header_files = []
|
||||
|
||||
with open(path, 'r') as stream:
|
||||
# Remove comments before loading the JSON.
|
||||
data = json.loads(re.sub(r'//.*\n', '', stream.read()))
|
||||
|
||||
if not isinstance(data, list):
|
||||
data = [data]
|
||||
|
||||
for item in data:
|
||||
for key in item:
|
||||
if key not in ['file', 'defines', 'structs']:
|
||||
raise 'Unexpected key in json file: %s' % key
|
||||
|
||||
header = {'name': item['file'], 'structs': {}, 'defines': {}}
|
||||
for name, data in item.get('structs', {}).items():
|
||||
if name in header['structs']:
|
||||
show('WARN: Description of struct "' + name + '" in file "' + item['file'] + '" replaces an existing description!')
|
||||
|
||||
header['structs'][name] = data
|
||||
|
||||
for part in item.get('defines', []):
|
||||
if not isinstance(part, list):
|
||||
# If no type is specified, assume integer.
|
||||
part = ['i', part]
|
||||
|
||||
if part[1] in header['defines']:
|
||||
show('WARN: Description of define "' + part[1] + '" in file "' + item['file'] + '" replaces an existing description!')
|
||||
|
||||
header['defines'][part[1]] = part[0]
|
||||
|
||||
header_files.append(header)
|
||||
|
||||
return header_files
|
||||
|
||||
|
||||
def output_json(obj, stream):
|
||||
json.dump(obj, stream, indent=4, sort_keys=True)
|
||||
stream.write('\n')
|
||||
stream.close()
|
||||
|
||||
|
||||
def main(args):
|
||||
global QUIET
|
||||
|
||||
parser = argparse.ArgumentParser(description='Generate JSON infos for structs.')
|
||||
parser.add_argument('json', nargs='*',
|
||||
help='JSON file with a list of structs and their fields (defaults to src/struct_info.json)',
|
||||
default=DEFAULT_JSON_FILES)
|
||||
parser.add_argument('-q', dest='quiet', action='store_true', default=False,
|
||||
help='Don\'t output anything besides error messages.')
|
||||
parser.add_argument('-o', dest='output', metavar='path', default=None,
|
||||
help='Path to the JSON file that will be written. If omitted, the default location under `src` will be used.')
|
||||
parser.add_argument('-I', dest='includes', metavar='dir', action='append', default=[],
|
||||
help='Add directory to include search path')
|
||||
parser.add_argument('-D', dest='defines', metavar='define', action='append', default=[],
|
||||
help='Pass a define to the preprocessor')
|
||||
parser.add_argument('-U', dest='undefines', metavar='undefine', action='append', default=[],
|
||||
help='Pass an undefine to the preprocessor')
|
||||
parser.add_argument('--wasm64', action='store_true',
|
||||
help='use wasm64 architecture')
|
||||
args = parser.parse_args(args)
|
||||
|
||||
QUIET = args.quiet
|
||||
|
||||
extra_cflags = []
|
||||
|
||||
if args.wasm64:
|
||||
# Always use =2 here so that we don't generate a binary that actually requires
|
||||
# memory64 to run. All we care about is that the output is correct.
|
||||
extra_cflags += ['-sMEMORY64=2', '-Wno-experimental']
|
||||
|
||||
# Add the user options to the list as well.
|
||||
for path in args.includes:
|
||||
extra_cflags.append('-I' + path)
|
||||
|
||||
for arg in args.defines:
|
||||
extra_cflags.append('-D' + arg)
|
||||
|
||||
for arg in args.undefines:
|
||||
extra_cflags.append('-U' + arg)
|
||||
|
||||
# Look for structs in all passed headers.
|
||||
info = {'defines': {}, 'structs': {}}
|
||||
|
||||
for f in args.json:
|
||||
# This is a JSON file, parse it.
|
||||
header_files = parse_json(f)
|
||||
# Inspect all collected structs.
|
||||
if 'internal' in f:
|
||||
use_cflags = CFLAGS + extra_cflags + INTERNAL_CFLAGS
|
||||
elif 'cxx' in f:
|
||||
use_cflags = CFLAGS + extra_cflags + CXXFLAGS
|
||||
else:
|
||||
use_cflags = CFLAGS + extra_cflags
|
||||
info_fragment = inspect_code(header_files, use_cflags)
|
||||
merge_info(info, info_fragment)
|
||||
|
||||
if args.output:
|
||||
output_file = args.output
|
||||
elif args.wasm64:
|
||||
output_file = utils.path_from_root('src/struct_info_generated_wasm64.json')
|
||||
else:
|
||||
output_file = utils.path_from_root('src/struct_info_generated.json')
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
output_json(info, f)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
79
js/build_webgpu.bat
Normal file
79
js/build_webgpu.bat
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
@echo off
|
||||
|
||||
rem build_webgpu.bat --- build onnxruntime-web with WebGPU EP
|
||||
rem
|
||||
rem Usage:
|
||||
rem build_webgpu.bat config [clean]
|
||||
rem
|
||||
rem Options:
|
||||
rem config Build configuration, "d" or "r"
|
||||
rem clean Perform a clean build, "clean" or empty
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set ROOT=%~dp0..\
|
||||
set BUILD_DIR=%ROOT%build_webgpu
|
||||
|
||||
:arg1
|
||||
if ["%~1"]==["d"] (
|
||||
set CONFIG=Debug
|
||||
set CONFIG_EXTRA_FLAG=--enable_wasm_profiling --wasm_run_tests_in_browser
|
||||
@rem --cmake_extra_defines onnxruntime_ENABLE_WEBASSEMBLY_OUTPUT_OPTIMIZED_MODEL=1
|
||||
@rem --enable_wasm_debug_info
|
||||
goto :arg2
|
||||
)
|
||||
if ["%~1"]==["r"] (
|
||||
set CONFIG=Release
|
||||
set CONFIG_EXTRA_FLAG=--enable_wasm_api_exception_catching --disable_rtti
|
||||
goto :arg2
|
||||
)
|
||||
echo Invalid configuration "%~1", must be "d"(Debug) or "r"(Release)
|
||||
exit /b 1
|
||||
|
||||
:arg2
|
||||
if ["%~2"]==["clean"] (
|
||||
goto :clean
|
||||
)
|
||||
if not exist "%ROOT%js\web\dist" (
|
||||
goto :npm_ci
|
||||
)
|
||||
|
||||
goto :build_wasm
|
||||
|
||||
:clean
|
||||
if exist "%BUILD_DIR%" (
|
||||
rd /s /q %BUILD_DIR%
|
||||
)
|
||||
|
||||
pushd %ROOT%
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
popd
|
||||
|
||||
:npm_ci
|
||||
pushd %ROOT%js
|
||||
call npm ci
|
||||
popd
|
||||
pushd %ROOT%js\common
|
||||
call npm ci
|
||||
popd
|
||||
pushd %ROOT%js\web
|
||||
call npm ci
|
||||
call npm run pull:wasm
|
||||
popd
|
||||
|
||||
:build_wasm
|
||||
|
||||
set PATH=C:\Program Files\Git\usr\bin;%PATH%
|
||||
|
||||
call %ROOT%build.bat --config %CONFIG% %CONFIG_EXTRA_FLAG% --skip_submodule_sync --build_wasm^
|
||||
--enable_wasm_simd --enable_wasm_threads --use_webgpu --build_dir %BUILD_DIR%
|
||||
|
||||
@REM --target onnxruntime_webassembly
|
||||
|
||||
IF NOT "%ERRORLEVEL%" == "0" (
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
||||
|
||||
@REM copy /Y %BUILD_DIR%\%CONFIG%\ort-wasm-simd-threaded.jsep.wasm %ROOT%js\web\dist\
|
||||
@REM copy /Y %BUILD_DIR%\%CONFIG%\ort-wasm-simd-threaded.jsep.mjs %ROOT%js\web\dist\
|
||||
|
|
@ -116,7 +116,7 @@ Status SkipLayerNorm<simplified>::ComputeInternal(onnxruntime::webgpu::ComputeCo
|
|||
auto* output = context.Output(0, x_shape);
|
||||
auto* input_skip_bias_sum = context.Output(3, x_shape);
|
||||
|
||||
size_t data_size = x_shape.Size();
|
||||
int64_t data_size = x_shape.Size();
|
||||
if (data_size == 0) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "core/framework/session_state.h"
|
||||
#include "core/providers/webgpu/allocator.h"
|
||||
#include "core/providers/webgpu/webgpu_context.h"
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class SimpleCacheManager : public IBufferCacheManager {
|
|||
|
||||
void OnRefresh() override {
|
||||
for (auto& buffer : pending_buffers_) {
|
||||
buffers_[wgpuBufferGetSize(buffer)].push_back(buffer);
|
||||
buffers_[static_cast<size_t>(wgpuBufferGetSize(buffer))].push_back(buffer);
|
||||
}
|
||||
pending_buffers_.clear();
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ class BucketCacheManager : public IBufferCacheManager {
|
|||
// TODO: consider graph capture. currently not supported
|
||||
|
||||
for (auto& buffer : pending_buffers_) {
|
||||
auto buffer_size = wgpuBufferGetSize(buffer);
|
||||
auto buffer_size = static_cast<size_t>(wgpuBufferGetSize(buffer));
|
||||
|
||||
auto it = buckets_.find(buffer_size);
|
||||
if (it != buckets_.end() && it->second.size() < buckets_limit_[buffer_size]) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#include <iosfwd>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
#include "core/framework/execution_provider.h"
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
#include <utility>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "core/providers/webgpu/data_transfer.h"
|
||||
#include "core/providers/webgpu/webgpu_context.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -123,10 +123,10 @@ Status BinaryElementwise::ComputeInternal(ComputeContext& context) const {
|
|||
if (a_last_dim_divisible_by_4 || b_last_dim_divisible_by_4) {
|
||||
vectorize = true;
|
||||
} else {
|
||||
size_t shared_dimension = 1;
|
||||
int64_t shared_dimension = 1;
|
||||
for (size_t i = 1; i < output_shape.NumDimensions(); i++) {
|
||||
size_t dimA = lhs_shape.NumDimensions() >= i ? lhs_shape[lhs_shape.NumDimensions() - i] : 1;
|
||||
size_t dimB = rhs_shape.NumDimensions() >= i ? rhs_shape[rhs_shape.NumDimensions() - i] : 1;
|
||||
int64_t dimA = lhs_shape.NumDimensions() >= i ? lhs_shape[lhs_shape.NumDimensions() - i] : 1;
|
||||
int64_t dimB = rhs_shape.NumDimensions() >= i ? rhs_shape[rhs_shape.NumDimensions() - i] : 1;
|
||||
if (dimA == dimB) {
|
||||
shared_dimension *= dimA;
|
||||
num_shared_dimension++;
|
||||
|
|
|
|||
|
|
@ -85,8 +85,7 @@ Status LayerNorm<simplified>::ComputeInternal(onnxruntime::webgpu::ComputeContex
|
|||
|
||||
auto* output = context.Output(0, x_shape);
|
||||
|
||||
size_t data_size = x_shape.Size();
|
||||
if (data_size == 0) {
|
||||
if (x_shape.Size() == 0) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <webgpu/webgpu_cpp.h>
|
||||
|
||||
#include "core/framework/tensor_shape.h"
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ Status Concat::ComputeInternal(ComputeContext& context) const {
|
|||
|
||||
uint32_t output_size = gsl::narrow_cast<int32_t>(prepare.output_tensor->Shape().Size());
|
||||
|
||||
ConcatProgram program{prepare.axis};
|
||||
size_t axis = static_cast<size_t>(prepare.axis);
|
||||
ConcatProgram program{axis};
|
||||
|
||||
std::vector<uint32_t> sizes_in_concat_axis;
|
||||
sizes_in_concat_axis.reserve(input_count);
|
||||
|
|
@ -118,7 +119,7 @@ Status Concat::ComputeInternal(ComputeContext& context) const {
|
|||
}
|
||||
program.AddInput({input.tensor, ProgramTensorMetadataDependency::TypeAndRank});
|
||||
|
||||
auto axis_size = input.tensor->Shape()[prepare.axis];
|
||||
auto axis_size = input.tensor->Shape()[axis];
|
||||
sum += static_cast<uint32_t>(axis_size);
|
||||
sizes_in_concat_axis.push_back(sum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,8 @@ class Flatten final : public OpKernel {
|
|||
return Status(common::ONNXRUNTIME, common::FAIL, "Invalid value for axis, must be less than or equal to input_rank");
|
||||
}
|
||||
|
||||
int64_t first_dim = 1;
|
||||
for (int64_t i = 0; i < axis; i++) {
|
||||
first_dim *= input_shape[i];
|
||||
}
|
||||
|
||||
int64_t second_dim = 1;
|
||||
for (int64_t i = axis; i < input_rank; i++) {
|
||||
second_dim *= input_shape[i];
|
||||
}
|
||||
int64_t first_dim = input_shape.SizeToDimension(static_cast<size_t>(axis));
|
||||
int64_t second_dim = input_shape.SizeFromDimension(static_cast<size_t>(axis));
|
||||
|
||||
TensorShape output_shape({first_dim, second_dim});
|
||||
Tensor* output_tensor = context->Output(0, output_shape);
|
||||
|
|
@ -59,4 +52,4 @@ class Flatten final : public OpKernel {
|
|||
};
|
||||
|
||||
} // namespace webgpu
|
||||
} // namespace onnxruntime
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ Status GatherElements::ComputeInternal(ComputeContext& context) const {
|
|||
axis += input_rank;
|
||||
}
|
||||
|
||||
auto axis_dim_limit = input_shape[axis];
|
||||
auto axis_dim_limit = input_shape[static_cast<size_t>(axis)];
|
||||
|
||||
auto output_dims = indices_shape.AsShapeVector();
|
||||
TensorShape output_shape(output_dims);
|
||||
|
|
@ -83,4 +83,4 @@ Status GatherElements::ComputeInternal(ComputeContext& context) const {
|
|||
}
|
||||
|
||||
} // namespace webgpu
|
||||
} // namespace onnxruntime
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@
|
|||
#include <memory>
|
||||
#include <cmath>
|
||||
|
||||
#if !defined(__wasm__)
|
||||
#include "dawn/dawn_proc.h"
|
||||
#if !defined(USE_EXTERNAL_DAWN)
|
||||
#include "dawn/native/DawnNative.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "core/common/common.h"
|
||||
#include "core/common/path_string.h"
|
||||
|
|
@ -29,7 +31,7 @@ void WebGpuContext::Initialize(const WebGpuBufferCacheConfig& buffer_cache_confi
|
|||
std::call_once(init_flag_, [this, &buffer_cache_config, backend_type]() {
|
||||
// Create wgpu::Adapter
|
||||
if (adapter_ == nullptr) {
|
||||
#if !defined(__EMSCRIPTEN__) && defined(_MSC_VER) && defined(DAWN_ENABLE_D3D12) && !defined(USE_EXTERNAL_DAWN)
|
||||
#if !defined(__wasm__) && defined(_MSC_VER) && defined(DAWN_ENABLE_D3D12) && !defined(USE_EXTERNAL_DAWN)
|
||||
// If we are using the D3D12 backend on Windows and the build does not use external Dawn, dxil.dll and dxcompiler.dll are required.
|
||||
//
|
||||
// Dawn will try to load them later, but if they are in the different directory to the executable, it may fail to find them.
|
||||
|
|
@ -54,15 +56,19 @@ void WebGpuContext::Initialize(const WebGpuBufferCacheConfig& buffer_cache_confi
|
|||
#endif
|
||||
|
||||
wgpu::RequestAdapterOptions req_adapter_options = {};
|
||||
wgpu::DawnTogglesDescriptor adapter_toggles_desc = {};
|
||||
req_adapter_options.nextInChain = &adapter_toggles_desc;
|
||||
req_adapter_options.backendType = static_cast<wgpu::BackendType>(backend_type);
|
||||
req_adapter_options.powerPreference = wgpu::PowerPreference::HighPerformance;
|
||||
|
||||
#if !defined(__wasm__)
|
||||
auto enabled_adapter_toggles = GetEnabledAdapterToggles();
|
||||
|
||||
wgpu::DawnTogglesDescriptor adapter_toggles_desc = {};
|
||||
adapter_toggles_desc.enabledToggleCount = enabled_adapter_toggles.size();
|
||||
adapter_toggles_desc.enabledToggles = enabled_adapter_toggles.data();
|
||||
|
||||
req_adapter_options.nextInChain = &adapter_toggles_desc;
|
||||
#endif
|
||||
|
||||
ORT_ENFORCE(wgpu::WaitStatus::Success == instance_.WaitAny(instance_.RequestAdapter(
|
||||
&req_adapter_options,
|
||||
wgpu::CallbackMode::WaitAnyOnly,
|
||||
|
|
@ -78,6 +84,8 @@ void WebGpuContext::Initialize(const WebGpuBufferCacheConfig& buffer_cache_confi
|
|||
// Create wgpu::Device
|
||||
if (device_ == nullptr) {
|
||||
wgpu::DeviceDescriptor device_desc = {};
|
||||
|
||||
#if !defined(__wasm__)
|
||||
wgpu::DawnTogglesDescriptor device_toggles_desc = {};
|
||||
device_desc.nextInChain = &device_toggles_desc;
|
||||
|
||||
|
|
@ -88,6 +96,7 @@ void WebGpuContext::Initialize(const WebGpuBufferCacheConfig& buffer_cache_confi
|
|||
auto disabled_device_toggles = GetDisabledDeviceToggles();
|
||||
device_toggles_desc.disabledToggleCount = disabled_device_toggles.size();
|
||||
device_toggles_desc.disabledToggles = disabled_device_toggles.data();
|
||||
#endif
|
||||
|
||||
std::vector<wgpu::FeatureName> required_features = GetAvailableRequiredFeatures(adapter_);
|
||||
if (required_features.size() > 0) {
|
||||
|
|
@ -136,9 +145,12 @@ void WebGpuContext::Initialize(const WebGpuBufferCacheConfig& buffer_cache_confi
|
|||
program_mgr_ = std::make_unique<ProgramManager>(Device(), DeviceLimits());
|
||||
|
||||
// set query type
|
||||
#if !defined(__wasm__)
|
||||
if (device_.HasFeature(wgpu::FeatureName::ChromiumExperimentalTimestampQueryInsidePasses)) {
|
||||
query_type_ = TimestampQueryType::InsidePasses;
|
||||
} else if (device_.HasFeature(wgpu::FeatureName::TimestampQuery)) {
|
||||
} else
|
||||
#endif
|
||||
if (device_.HasFeature(wgpu::FeatureName::TimestampQuery)) {
|
||||
query_type_ = TimestampQueryType::AtPasses;
|
||||
} else {
|
||||
query_type_ = TimestampQueryType::None;
|
||||
|
|
@ -456,7 +468,9 @@ std::vector<const char*> WebGpuContext::GetDisabledDeviceToggles() const {
|
|||
std::vector<wgpu::FeatureName> WebGpuContext::GetAvailableRequiredFeatures(const wgpu::Adapter& adapter) const {
|
||||
std::vector<wgpu::FeatureName> required_features;
|
||||
constexpr wgpu::FeatureName features[]{
|
||||
#if !defined(__wasm__)
|
||||
wgpu::FeatureName::ChromiumExperimentalTimestampQueryInsidePasses,
|
||||
#endif
|
||||
wgpu::FeatureName::TimestampQuery,
|
||||
wgpu::FeatureName::ShaderF16,
|
||||
wgpu::FeatureName::Subgroups,
|
||||
|
|
@ -531,7 +545,7 @@ void WebGpuContext::CollectProfilingData(profiling::Events& events) {
|
|||
|
||||
ORT_ENFORCE(Wait(query_read_buffer.MapAsync(wgpu::MapMode::Read,
|
||||
0,
|
||||
query_read_buffer.GetSize(),
|
||||
static_cast<size_t>(query_read_buffer.GetSize()),
|
||||
wgpu::CallbackMode::WaitAnyOnly,
|
||||
[](wgpu::MapAsyncStatus status, wgpu::StringView message) {
|
||||
ORT_ENFORCE(status == wgpu::MapAsyncStatus::Success, "Failed to download data from buffer: ", std::string_view{message});
|
||||
|
|
@ -658,8 +672,14 @@ WebGpuContext& WebGpuContextFactory::CreateContext(const WebGpuContextConfig& co
|
|||
ORT_ENFORCE(instance == nullptr && adapter == nullptr && device == nullptr,
|
||||
"WebGPU EP default context (contextId=0) must not have custom WebGPU instance, adapter or device.");
|
||||
|
||||
std::call_once(init_default_flag_, [dawn_proc_table = config.dawn_proc_table]() {
|
||||
// Step.1 - setup dawn proc table
|
||||
std::call_once(init_default_flag_, [
|
||||
#if !defined(__wasm__)
|
||||
dawn_proc_table = config.dawn_proc_table
|
||||
#endif
|
||||
]() {
|
||||
// Step.1 - setup dawn proc table (only for non-WASM build)
|
||||
|
||||
#if !defined(__wasm__)
|
||||
const DawnProcTable* dawn_procs = reinterpret_cast<const DawnProcTable*>(dawn_proc_table);
|
||||
#if defined(BUILD_DAWN_MONOLITHIC_LIBRARY)
|
||||
ORT_ENFORCE(dawn_procs == nullptr, "setting DawnProcTable is not allowed when dynamically linked to webgpu_dawn.");
|
||||
|
|
@ -672,12 +692,17 @@ WebGpuContext& WebGpuContextFactory::CreateContext(const WebGpuContextConfig& co
|
|||
ORT_ENFORCE(dawn_procs != nullptr, "DawnProcTable must be provided.");
|
||||
#endif
|
||||
dawnProcSetProcs(dawn_procs);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Step.2 - Create wgpu::Instance
|
||||
#if !defined(__wasm__)
|
||||
wgpu::InstanceDescriptor instance_desc{};
|
||||
instance_desc.features.timedWaitAnyEnable = true;
|
||||
default_instance_ = wgpu::CreateInstance(&instance_desc);
|
||||
#else
|
||||
default_instance_ = wgpu::CreateInstance(nullptr);
|
||||
#endif
|
||||
|
||||
ORT_ENFORCE(default_instance_ != nullptr, "Failed to create wgpu::Instance.");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
#include "core/providers/webgpu/webgpu_execution_provider.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ const gtestReporter = {'reporter:gtest': ['type', function() {
|
|||
};
|
||||
}]};
|
||||
|
||||
// In Node.js v16 and below, 'localhost' is using IPv4, so need to listen to '0.0.0.0'
|
||||
// In Node.js v17+, 'localhost' is using IPv6, so need to listen to '::'
|
||||
const listenAddress = Number.parseInt(process.versions.node.split('.')[0]) >= 17 ? '::' : '0.0.0.0';
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
basePath: '.',
|
||||
|
|
@ -60,6 +64,7 @@ module.exports = function(config) {
|
|||
browserDisconnectTimeout: 600000,
|
||||
// allow running tests for 30 minutes
|
||||
browserNoActivityTimeout: 30 * 60 * 1000,
|
||||
listenAddress,
|
||||
customLaunchers: {
|
||||
ChromeTest: {
|
||||
base: 'ChromeCanary',
|
||||
|
|
|
|||
Loading…
Reference in a new issue