Skip to content

Commit af26e50

Browse files
committed
Enable D3D12 Agility SDK support for Dawn WebGPU builds
1 parent 9cbf665 commit af26e50

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

cmake/deps.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extensions;https://github.com/microsoft/onnxruntime-extensions/archive/c24b7bab0
5959
directx_headers;https://github.com/microsoft/DirectX-Headers/archive/refs/tags/v1.613.1.zip;47653509a3371eabb156360f42faf582f314bf2e
6060
cudnn_frontend;https://github.com/NVIDIA/cudnn-frontend/archive/refs/tags/v1.27.0.zip;1e4c9a464d3437e388ab0163f3be068dba783c08
6161
dawn;https://github.com/google/dawn/archive/refs/tags/v20260817.213942.zip;a89b0c394bd078f559e2737b80a1fe49fde4ccc1
62+
dawn_agility_sdk;https://www.nuget.org/api/v2/package/Microsoft.Direct3D.D3D12/1.721.0-preview;fbeb58268d47626027ab670928817cbb955755db
6263
kleidiai;https://github.com/ARM-software/kleidiai/archive/refs/tags/v1.20.0.tar.gz;6895e72b3d5cf1173358164cb3d64c9d7d33cc84
6364
# kleidiai-qmx is pinned to a specific commit as there are no tagged releases. When an appropriate tagged release becomes available,
6465
# this entry will be updated to use refs/tags/<version> instead of the raw commit hash.

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,15 @@ endif()
637637

638638

639639
if (onnxruntime_USE_WEBGPU)
640+
if (DAWN_USE_AGILITY_SDK)
641+
if (NOT WIN32)
642+
message(FATAL_ERROR "DAWN_USE_AGILITY_SDK is only supported on Windows.")
643+
endif()
644+
if (NOT onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
645+
message(FATAL_ERROR "DAWN_USE_AGILITY_SDK requires the Dawn D3D12 backend.")
646+
endif()
647+
endif()
648+
640649
# TODO: the following code is used to disable building Dawn using vcpkg temporarily
641650
# until we figure out how to resolve the packaging pipeline failures
642651
#
@@ -832,7 +841,40 @@ if (onnxruntime_USE_WEBGPU)
832841
)
833842
endif()
834843

844+
if (DAWN_USE_AGILITY_SDK)
845+
# Set Dawn's expected Chromium CIPD layout before configuring Dawn. The SDK
846+
# package is populated below, before any Dawn target is compiled.
847+
if (onnxruntime_CUSTOM_DAWN_SRC_PATH)
848+
set(ONNXRUNTIME_DAWN_SRC_DIR "${onnxruntime_CUSTOM_DAWN_SRC_PATH}")
849+
else()
850+
if (FETCHCONTENT_BASE_DIR)
851+
set(ONNXRUNTIME_DAWN_SRC_DIR "${FETCHCONTENT_BASE_DIR}/dawn-src")
852+
else()
853+
set(ONNXRUNTIME_DAWN_SRC_DIR "${CMAKE_BINARY_DIR}/_deps/dawn-src")
854+
endif()
855+
endif()
856+
set(DAWN_AGILITY_SDK_DIR "${ONNXRUNTIME_DAWN_SRC_DIR}/third_party/agility-sdk"
857+
CACHE PATH "Directory containing the D3D12 Agility SDK" FORCE)
858+
message(STATUS "Dawn Agility SDK directory: ${DAWN_AGILITY_SDK_DIR}")
859+
endif()
860+
835861
onnxruntime_fetchcontent_makeavailable(dawn)
862+
863+
if (DAWN_USE_AGILITY_SDK)
864+
onnxruntime_fetchcontent_declare(
865+
dawn_agility_sdk
866+
URL ${DEP_URL_dawn_agility_sdk}
867+
URL_HASH SHA1=${DEP_SHA1_dawn_agility_sdk}
868+
SOURCE_DIR "${DAWN_AGILITY_SDK_DIR}/src"
869+
EXCLUDE_FROM_ALL
870+
)
871+
onnxruntime_fetchcontent_makeavailable(dawn_agility_sdk)
872+
if (NOT EXISTS "${DAWN_AGILITY_SDK_DIR}/src/build/native/include/d3d12.h")
873+
message(FATAL_ERROR
874+
"The Agility SDK package does not contain build/native/include/d3d12.h: "
875+
"${DAWN_AGILITY_SDK_DIR}/src")
876+
endif()
877+
endif()
836878
endif()
837879

838880
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")

tools/ci_build/build.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def generate_build_tree(
499499
"-Donnxruntime_USE_JSEP=" + ("ON" if args.use_jsep else "OFF"),
500500
"-Donnxruntime_USE_WEBGPU=" + ("ON" if args.use_webgpu else "OFF"),
501501
"-Donnxruntime_USE_EXTERNAL_DAWN=" + ("ON" if args.use_external_dawn else "OFF"),
502+
"-DDAWN_USE_AGILITY_SDK=" + ("ON" if args.use_dawn_agility_sdk else "OFF"),
502503
# Training related flags
503504
"-Donnxruntime_ENABLE_NVTX_PROFILE=" + ("ON" if args.enable_nvtx_profile else "OFF"),
504505
"-Donnxruntime_ENABLE_TRAINING=" + ("ON" if args.enable_training else "OFF"),
@@ -898,7 +899,8 @@ def generate_build_tree(
898899
if not args.use_webgpu:
899900
if args.use_external_dawn:
900901
raise BuildError("External Dawn (--use_external_dawn) must be enabled with WebGPU (--use_webgpu).")
901-
902+
if args.use_dawn_agility_sdk:
903+
raise BuildError("Dawn Agility SDK (--use_dawn_agility_sdk) must be enabled with WebGPU (--use_webgpu).")
902904
if is_windows():
903905
if args.enable_pix_capture:
904906
raise BuildError(
@@ -910,6 +912,9 @@ def generate_build_tree(
910912
if args.build_wasm:
911913
raise BuildError("Only static library build of WebGPU EP is supported for WebAssembly build.")
912914

915+
if args.use_dawn_agility_sdk and not is_windows():
916+
raise BuildError("Dawn Agility SDK (--use_dawn_agility_sdk) is only supported on Windows.")
917+
913918
if args.use_snpe:
914919
cmake_args += ["-Donnxruntime_USE_SNPE=ON"]
915920

tools/ci_build/build_args.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,11 @@ def add_execution_provider_args(parser: argparse.ArgumentParser) -> None:
828828
webgpu_group.add_argument(
829829
"--use_external_dawn", action="store_true", help="Use external Dawn dependency for WebGPU."
830830
)
831+
webgpu_group.add_argument(
832+
"--use_dawn_agility_sdk",
833+
action="store_true",
834+
help="Build Dawn's D3D12 backend with the Agility SDK (Windows only).",
835+
)
831836
webgpu_group.add_argument(
832837
"--wgsl_template",
833838
choices=["static"],

0 commit comments

Comments
 (0)