Skip to content

Commit

Permalink
Remove WebGPU native platform support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottTodd committed Oct 4, 2022
1 parent e787f3d commit 5189b1e
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 1,107 deletions.
37 changes: 13 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ else()
endif()

# WebGPU is disabled by default as it's experimental.
# TODO(benvanik): FindPackage the deps or default to on when under emscripten?
# TODO(benvanik): FindPackage the deps or default to on when under Emscripten?
# (also see iree_copts.cmake and anywhere that uses IREE_HAL_DRIVER_WEBGPU)
set(IREE_HAL_DRIVER_WEBGPU_DEFAULT OFF)
set(IREE_HAL_WEBGPU_PLATFORM_DEFAULT "dawn")
set(IREE_HAL_WEBGPU_PLATFORM "${IREE_HAL_WEBGPU_PLATFORM_DEFAULT}"
CACHE STRING "Native WebGPU implementation ('dawn' or 'wgpu-native').")

option(IREE_HAL_DRIVER_CUDA "Enables the 'cuda' runtime HAL driver" ${IREE_HAL_DRIVER_CUDA_DEFAULT})
option(IREE_HAL_DRIVER_LOCAL_SYNC "Enables the 'local-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
Expand Down Expand Up @@ -659,7 +657,6 @@ include(flatbuffer_c_library)
add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/wgpu-native EXCLUDE_FROM_ALL)

iree_set_googletest_cmake_options()
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
Expand Down Expand Up @@ -706,35 +703,27 @@ if(IREE_BUILD_PYTHON_BINDINGS)
endif()

if(IREE_TARGET_BACKEND_METAL_SPIRV)
iree_set_spirv_cross_cmake_options()
# SPIRV-Cross is needed to cross compile SPIR-V into MSL source code.
iree_set_spirv_cross_cmake_options()
add_subdirectory(third_party/spirv_cross EXCLUDE_FROM_ALL)
endif()

if(IREE_TARGET_BACKEND_WEBGPU OR
(IREE_HAL_DRIVER_WEBGPU AND ("${IREE_HAL_WEBGPU_PLATFORM}" STREQUAL "dawn")))
# NOTE: these all need to be synchronized with Dawn.
# set(IREE_SPIRV_TOOLS_TAG "37d2396cabe56b29d37551ea55d0d745d5748ded")
set(IREE_SPIRV_TOOLS_TAG "ff07cfd86fa229525659f6b81058b3171a67bef1") # 2021-12-10
# https://dawn.googlesource.com/dawn/+/refs/heads/main/DEPS
# https://chromium.googlesource.com/vulkan-deps/+/main/DEPS
# set(IREE_TINT_TAG "5aca651c524caca8ac85962d1dff378238671eba")
set(IREE_TINT_TAG "188b1fb8f5be52299fb7fbc6db17dbb0c07dbb7e") # 2021-12-16
set(IREE_DAWN_ABSEIL_TAG "789af048b388657987c59d4da406859034fe310f")
set(IREE_DAWN_GLFW_TAG "62e175ef9fae75335575964c845a302447c012c7")
set(IREE_DAWN_TAG "2f1b0dc47d8316f3db6e5b9a55b873cd3079cea5")

if(IREE_TARGET_BACKEND_WEBGPU)
# Tint is needed to compile SPIR-V into WGSL source code.
# Tint also requires SPIRV-Tools, which requires SPIRV-Headers.
# Dawn needs Tint (and thus SPIRV-Tools), but only at runtime.
# Order matters here, unfortunately.

# NOTE: these can be synced by referencing one of these repositories:
# * https://dawn.googlesource.com/dawn/
# * https://dawn.googlesource.com/tint/
# * https://chromium.googlesource.com/vulkan-deps/+/refs/heads/main/DEPS
# or they can be updated independently
set(IREE_TINT_TAG "200492e32b94f042d9942154fb4fa7f93bb8289a") # 2022-08-17
set(IREE_SPIRV_TOOLS_TAG "ff07cfd86fa229525659f6b81058b3171a67bef1") # 2021-12-10

iree_set_spirv_headers_cmake_options()
add_subdirectory(third_party/spirv_headers EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/spirv-tools EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/tint EXCLUDE_FROM_ALL)
if(IREE_HAL_DRIVER_WEBGPU AND ("${IREE_HAL_WEBGPU_PLATFORM}" STREQUAL "dawn"))
add_subdirectory(build_tools/third_party/dawn EXCLUDE_FROM_ALL)
endif()
endif()

#-------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
"@cpuinfo": ["${IREE_CPUINFO_TARGET}"],
"@vulkan_memory_allocator//:impl_header_only": ["vulkan_memory_allocator"],
"@webgpu_headers": [],
"@wgpu-native//:static": ["wgpu-native-static"],
}


Expand Down
1 change: 1 addition & 0 deletions build_tools/cmake/iree_copts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ iree_select_compiler_opts(IREE_DEFAULT_LINKOPTS
if(EMSCRIPTEN AND IREE_HAL_DRIVER_WEBGPU)
iree_select_compiler_opts(IREE_DEFAULT_LINKOPTS
ALL
# TODO(scotttodd): Only add when using WebGPU in a library/binary?
"-sUSE_WEBGPU"
# Hack: Used to create sync versions of requestAdapter and requestDevice
# TODO(scotttodd): Only set for test binaries, avoid sync code in apps
Expand Down
58 changes: 0 additions & 58 deletions build_tools/third_party/dawn/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion build_tools/third_party/dawn/dummy.c

This file was deleted.

14 changes: 6 additions & 8 deletions build_tools/third_party/tint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ set(TINT_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_TESTS OFF CACHE BOOL "" FORCE)

# Our usage at compile time primarily needs the SPIR-V reader and WGSL writer,
# but usage at runtime through Dawn needs a broader set. WebGPU on native is
# not a supported production use case and is only for development/testing and
# as such we don't get too particular about minimizing its size here.
# Our usage at compile time primarily needs the SPIR-V reader and WGSL writer.
# Other readers and writers could be enabled, but we want to keep this small.

set(TINT_BUILD_SPV_READER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_READER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_READER OFF CACHE BOOL "" FORCE)

set(TINT_BUILD_GLSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "" FORCE)
set(TINT_BUILD_HLSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_MSL_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_SPV_WRITER OFF CACHE BOOL "" FORCE)
set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(tint)
Expand Down
64 changes: 0 additions & 64 deletions build_tools/third_party/wgpu-native/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion experimental/web/sample_webgpu/build_sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ emcmake "${CMAKE_BIN?}" -G Ninja .. \
-DIREE_HAL_DRIVER_LOCAL_SYNC=OFF \
-DIREE_HAL_DRIVER_LOCAL_TASK=OFF \
-DIREE_HAL_DRIVER_WEBGPU=ON \
-DIREE_HAL_WEBGPU_PLATFORM=emscripten \
-DIREE_BUILD_COMPILER=OFF \
-DIREE_BUILD_TESTS=OFF

Expand Down
1 change: 0 additions & 1 deletion experimental/web/testing/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ emcmake "${CMAKE_BIN?}" -G Ninja .. \
-DIREE_BUILD_COMPILER=OFF \
-DIREE_HAL_DRIVER_DEFAULTS=OFF \
-DIREE_HAL_DRIVER_WEBGPU=ON \
-DIREE_HAL_WEBGPU_PLATFORM=emscripten \
-DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
-DIREE_HAL_DRIVER_LOCAL_TASK=ON \
-DIREE_HAL_EXECUTABLE_LOADER_DEFAULTS=OFF \
Expand Down
1 change: 0 additions & 1 deletion runtime/src/iree/hal/allocator_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ IREE_API_EXPORT iree_status_t iree_hal_allocator_create_heap(
IREE_ASSERT_ARGUMENT(out_allocator);
*out_allocator = NULL;
IREE_TRACE_ZONE_BEGIN(z0);
*out_allocator = NULL;

iree_hal_heap_allocator_t* allocator = NULL;
iree_host_size_t total_size =
Expand Down
19 changes: 13 additions & 6 deletions runtime/src/iree/hal/drivers/webgpu/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ static iree_status_t iree_hal_webgpu_builtins_initialize_fill_buffer(
"failed to create fill_buffer builtin pipeline layout");
}

const char* code = iree_hal_webgpu_builtins_find_code("fill_buffer.wgsl");
const WGPUShaderModuleWGSLDescriptor wgsl_descriptor = {
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
.source = iree_hal_webgpu_builtins_find_code("fill_buffer.wgsl"),
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
#if defined(__EMSCRIPTEN__)
// Emscripten uses this older name.
.source = code,
#else
// Spec uses this name: https://www.w3.org/TR/webgpu/#shader-module-creation
.code = code,
#endif
};
const WGPUShaderModuleDescriptor module_descriptor = {
.nextInChain = &wgsl_descriptor.chain,
Expand Down
18 changes: 12 additions & 6 deletions runtime/src/iree/hal/drivers/webgpu/executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ static iree_status_t iree_hal_webgpu_create_wgsl_shader_module(
const char* code = iree_WGSLShaderModuleDef_code_get(shader_module_def);

const WGPUShaderModuleWGSLDescriptor descriptor = {
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
.source = code,
.chain =
{
.next = NULL,
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
},
#if defined(__EMSCRIPTEN__)
// Emscripten uses this older name.
.source = code,
#else
// Spec uses this name: https://www.w3.org/TR/webgpu/#shader-module-creation
.code = code,
#endif
};
const WGPUShaderModuleDescriptor module_descriptor = {
.nextInChain = &descriptor.chain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ IREEWGPUBufferMapSyncStatus iree_wgpuBufferMapSync(WGPUDevice device,
WGPUBuffer buffer,
WGPUMapModeFlags mode,
size_t offset, size_t size) {
IREEWGPUBufferMapSyncStatus status = IREEWGPUBufferMapSyncStatus_Unknown;
wgpuBufferMapAsync(buffer, mode, offset, size,
iree_hal_webgpu_buffer_map_sync_callback, &status);
// TODO(scotttodd): poll / wait somehow, or implement sync mapping differently
// wgpuDevicePoll(device, /*force_wait=*/true);
return status;
// WebGPU (browser/Emscripten) does not support synchronous buffer mapping.
return IREEWGPUBufferMapSyncStatus_Error;
}
42 changes: 0 additions & 42 deletions runtime/src/iree/hal/drivers/webgpu/platform/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,3 @@ iree_cc_library(
iree::hal::drivers::webgpu::platform
PUBLIC
)

if(${IREE_HAL_WEBGPU_PLATFORM} STREQUAL "dawn")
target_compile_definitions(
iree_hal_drivers_webgpu_platform_native_native
PUBLIC
"IREE_HAL_WEBGPU_PLATFORM_DAWN=1"
)
target_sources(
iree_hal_drivers_webgpu_platform_native_native
PRIVATE
"dawn_util.cc"
"native_driver_dawn.cc"
)
target_link_libraries(
iree_hal_drivers_webgpu_platform_native_native
PUBLIC
dawn_internal_config
dawncpp
dawn_proc
dawn_common
dawn_native
dawn_wire
dawn_utils
)
elseif(${IREE_HAL_WEBGPU_PLATFORM} STREQUAL "wgpu-native")
target_compile_definitions(
iree_hal_drivers_webgpu_platform_native_native
PUBLIC
"IREE_HAL_WEBGPU_PLATFORM_WGPU_NATIVE=1"
)
target_sources(
iree_hal_drivers_webgpu_platform_native_native
PRIVATE
"native_driver_wgpu.cc"
"wgpu_util.c"
)
target_link_libraries(
iree_hal_drivers_webgpu_platform_native_native
PUBLIC
wgpu-native-static
)
endif()
Loading

0 comments on commit 5189b1e

Please sign in to comment.