Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 2 CMake build options of Dawn #23096

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ option(onnxruntime_USE_WEBNN "Build with WebNN support. Enable hardware accelera
option(onnxruntime_USE_WEBGPU "Build with WebGPU support. Enable WebGPU via C/C++ interface." OFF)
option(onnxruntime_USE_EXTERNAL_DAWN "Build with treating Dawn as external dependency. Will not link Dawn at build time." OFF)
option(onnxruntime_CUSTOM_DAWN_SRC_PATH "Path to custom Dawn src dir.")
option(onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY "Build Dawn as a monolithic library" OFF)
# The following 2 options are only for Windows
option(onnxruntime_ENABLE_DAWN_BACKEND_VULKAN "Enable Vulkan backend for Dawn (on Windows)" OFF)
option(onnxruntime_ENABLE_DAWN_BACKEND_D3D12 "Enable D3D12 backend for Dawn (on Windows)" ON)

# Options related to reducing the binary size produced by the build
# XNNPACK EP requires the internal NHWC contrib ops to be available, so this option must be OFF when onnxruntime_USE_XNNPACK is ON
Expand Down Expand Up @@ -955,9 +959,18 @@ if (onnxruntime_USE_WEBGPU)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_WEBGPU=1)
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_WEBGPU=1)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES webgpu)
if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
list(APPEND ORT_PROVIDER_FLAGS -DBUILD_DAWN_MONOLITHIC_LIBRARY=1)
endif()
if (onnxruntime_USE_EXTERNAL_DAWN)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_EXTERNAL_DAWN=1)
endif()
if (onnxruntime_ENABLE_DAWN_BACKEND_VULKAN)
list(APPEND ORT_PROVIDER_FLAGS -DDAWN_ENABLE_VULKAN=1)
endif()
if (onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
list(APPEND ORT_PROVIDER_FLAGS -DDAWN_ENABLE_D3D12=1)
endif()
endif()
if (onnxruntime_USE_CANN)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_CANN=1)
Expand Down
41 changes: 33 additions & 8 deletions cmake/external/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,19 @@ if (onnxruntime_USE_WEBGPU)
)
endif()

# 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)
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_INSTALL OFF CACHE BOOL "" FORCE)
set(DAWN_ENABLE_NULL OFF CACHE BOOL "" FORCE)
set(DAWN_FETCH_DEPENDENCIES ON CACHE BOOL "" FORCE)

Expand Down Expand Up @@ -667,18 +676,34 @@ if (onnxruntime_USE_WEBGPU)
set(DAWN_USE_BUILT_DXC ON CACHE BOOL "" FORCE)
set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "" FORCE)

# Vulkan may optionally be included in a Windows build. Exclude until we have an explicit use case that requires it.
set(DAWN_ENABLE_VULKAN OFF 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()

onnxruntime_fetchcontent_makeavailable(dawn)

if (NOT onnxruntime_USE_EXTERNAL_DAWN)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES dawn::dawn_native)
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()

set(onnxruntime_LINK_DIRS)
Expand Down
22 changes: 19 additions & 3 deletions cmake/onnxruntime_providers_webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,25 @@
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)
if (NOT onnxruntime_USE_EXTERNAL_DAWN)
target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_native)

if (onnxruntime_BUILD_DAWN_MONOLITHIC_LIBRARY)
target_link_libraries(onnxruntime_providers_webgpu dawn::webgpu_dawn)

if (onnxruntime_ENABLE_DELAY_LOADING_WIN_DLLS)
list(APPEND onnxruntime_DELAYLOAD_FLAGS "/DELAYLOAD:webgpu_dawn.dll")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to use delayloading ?
First, it only works on Windows.
Second, it has a lot of limitations and has created a lot of troubles for us. If you have time, try to see if it could work in python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand it only works on Windows. The onnxruntime_DELAYLOAD_FLAGS is only used in Windows build anyway.

For python build, if it does not work, we will not build dawn monolithic library. instead, we will static link the dawn library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to delay load this DLL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to build a onnxruntime.dll that can do both of the following:

  • work on WebGPU EP when webgpu_dawn.dll is in the folder
  • work on CPU EP when webgpu_dawn.dll is missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the list of functions that webgpu_dawn.dll exports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dumpbin /exports webgpu_dawn.dll

Microsoft (R) COFF/PE Dumper Version 14.42.34435.0
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file C:\code\onnxruntime\build_monolib\Release\Release\webgpu_dawn.dll

File Type: DLL

Section contains the following exports for webgpu_dawn.dll

00000000 characteristics
FFFFFFFF time date stamp
    0.00 version
       1 ordinal base
     339 number of functions
     339 number of names

ordinal hint RVA      name

      1    0 00002230 ??0Adapter@native@dawn@@QEAA@AEBV012@@Z
      2    1 00002260 ??0Adapter@native@dawn@@QEAA@PEAVAdapterBase@12@@Z
      3    2 00002290 ??0Adapter@native@dawn@@QEAA@XZ
      4    3 000022A0 ??0DawnInstanceDescriptor@native@dawn@@QEAA@XZ
      5    4 000022D0 ??0ExternalImageDescriptor@native@dawn@@IEAA@W4ExternalImageType@12@@Z
      6    5 000022E0 ??0ExternalImageExportInfo@native@dawn@@IEAA@W4ExternalImageType@12@@Z
      7    6 000022F0 ??0Instance@native@dawn@@QEAA@PEAVInstanceBase@12@@Z
      8    7 00002330 ??0Instance@native@dawn@@QEAA@PEBUWGPUInstanceDescriptor@@@Z
      9    8 00002360 ??0MemoryDump@native@dawn@@QEAA@XZ
     10    9 00003010 ??0RequestAdapterOptionsLUID@d3d@native@dawn@@QEAA@XZ
     11    A 000030E0 ??0SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAA@$$QEAU0123@@Z
     12    B 00003110 ??0SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAA@AEBU0123@@Z
     13    C 00003140 ??0SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAA@XZ
     14    D 00002650 ??1Adapter@native@dawn@@QEAA@XZ
     15    E 00002680 ??1Instance@native@dawn@@QEAA@XZ
     16    F 000026D0 ??1MemoryDump@native@dawn@@MEAA@XZ
     17   10 00003170 ??1SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAA@XZ
     18   11 00002700 ??4Adapter@native@dawn@@QEAAAEAV012@AEBV012@@Z
     19   12 00002740 ??4DawnInstanceDescriptor@native@dawn@@QEAAAEAU012@$$QEAU012@@Z
     20   13 00002780 ??4DawnInstanceDescriptor@native@dawn@@QEAAAEAU012@AEBU012@@Z
     21   14 000027B0 ??4ExternalImageDescriptor@native@dawn@@QEAAAEAU012@$$QEAU012@@Z
     22   15 000027D0 ??4ExternalImageDescriptor@native@dawn@@QEAAAEAU012@AEBU012@@Z
     23   16 000027E0 ??4ExternalImageExportInfo@native@dawn@@QEAAAEAU012@$$QEAU012@@Z
     24   17 000027F0 ??4ExternalImageExportInfo@native@dawn@@QEAAAEAU012@AEBU012@@Z
     25   18 00003060 ??4RequestAdapterOptionsLUID@d3d@native@dawn@@QEAAAEAU0123@$$QEAU0123@@Z
     26   19 00003080 ??4RequestAdapterOptionsLUID@d3d@native@dawn@@QEAAAEAU0123@AEBU0123@@Z
     27   1A 000031A0 ??4SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAAAEAU0123@$$QEAU0123@@Z
     28   1B 000031F0 ??4SharedBufferMemoryD3D12ResourceDescriptor@d3d12@native@dawn@@QEAAAEAU0123@AEBU0123@@Z
     29   1C 00002800 ??8DawnInstanceDescriptor@native@dawn@@QEBA_NAEBU012@@Z
     30   1D 00002840 ??BAdapter@native@dawn@@QEBA_NXZ
     31   1E 00424910 ??_7MemoryDump@native@dawn@@6B@
     32   1F 000028D0 ??_FInstance@native@dawn@@QEAAXXZ
     33   20 00002960 ?AllToggleInfos@native@dawn@@YA?AV?$vector@PEBUToggleInfo@native@dawn@@V?$allocator@PEBUToggleInfo@native@dawn@@@std@@@std@@XZ
     34   21 00002980 ?CheckIsErrorForTesting@native@dawn@@YA_NPEAX@Z
     35   22 00002990 ?ComputeEstimatedMemoryUsage@native@dawn@@YA_KPEAUWGPUDeviceImpl@@@Z
     36   23 000029D0 ?CreateDevice@Adapter@native@dawn@@QEAAPEAUWGPUDeviceImpl@@PEBUDeviceDescriptor@wgpu@@@Z
     37   24 000029D0 ?CreateDevice@Adapter@native@dawn@@QEAAPEAUWGPUDeviceImpl@@PEBUWGPUDeviceDescriptor@@@Z
     38   25 000029E0 ?DeviceTick@native@dawn@@YA_NPEAUWGPUDeviceImpl@@@Z
     39   26 000029F0 ?DisconnectDawnPlatform@Instance@native@dawn@@QEAAXXZ
     40   27 00002A00 ?DumpMemoryStatistics@native@dawn@@YAXPEAUWGPUDeviceImpl@@PEAVMemoryDump@12@@Z
     41   28 00002A50 ?EnumerateAdapters@Instance@native@dawn@@QEBA?AV?$vector@VAdapter@native@dawn@@V?$allocator@VAdapter@native@dawn@@@std@@@std@@PEBURequestAdapterOptions@wgpu@@@Z
     42   29 00002A70 ?EnumerateAdapters@Instance@native@dawn@@QEBA?AV?$vector@VAdapter@native@dawn@@V?$allocator@VAdapter@native@dawn@@@std@@@std@@PEBUWGPURequestAdapterOptions@@@Z
     43   2A 00002BA0 ?Get@Adapter@native@dawn@@QEBAPEAUWGPUAdapterImpl@@XZ
     44   2B 00002BA0 ?Get@Instance@native@dawn@@QEBAPEAUWGPUInstanceImpl@@XZ
     45   2C 00002BB0 ?GetAllocatedSizeForTesting@native@dawn@@YA_KPEAUWGPUBufferImpl@@@Z
     46   2D 00003240 ?GetD3D12Device@d3d12@native@dawn@@YA?AV?$ComPtr@UID3D12Device@@@WRL@Microsoft@@PEAUWGPUDeviceImpl@@@Z
     47   2E 000030A0 ?GetDXGIAdapter@d3d@native@dawn@@YA?AV?$ComPtr@UIDXGIAdapter@@@WRL@Microsoft@@PEAUWGPUAdapterImpl@@@Z
     48   2F 00002BC0 ?GetDeprecationWarningCountForTesting@Instance@native@dawn@@QEBA_KXZ
     49   30 00002BD0 ?GetDeviceCountForTesting@Instance@native@dawn@@QEBA_KXZ
     50   31 00002BE0 ?GetFeatureInfo@native@dawn@@YAPEBUFeatureInfo@12@W4FeatureName@wgpu@@@Z
     51   32 00002C20 ?GetInfo@Adapter@native@dawn@@QEBA?AW4Status@wgpu@@PEAUAdapterInfo@5@@Z
     52   33 00002C20 ?GetInfo@Adapter@native@dawn@@QEBA?AW4Status@wgpu@@PEAUWGPUAdapterInfo@@@Z
     53   34 00002C30 ?GetLazyClearCountForTesting@native@dawn@@YA_KPEAUWGPUDeviceImpl@@@Z
     54   35 00002C40 ?GetLimits@Adapter@native@dawn@@QEBA?AUConvertibleStatus@wgpu@@PEAUWGPUSupportedLimits@@@Z
     55   36 00002C60 ?GetObjectLabelForTesting@native@dawn@@YAPEBDPEAX@Z
     56   37 00002C80 ?GetProcMapNamesForTesting@native@dawn@@YA?AV?$vector@V?$basic_string_view@DU?$char_traits@D@std@@@std@@V?$allocator@V?$basic_string_view@DU?$char_traits@D@std@@@std@@@2@@std@@XZ
     57   38 00002CA0 ?GetProcs@native@dawn@@YAAEBUDawnProcTable@@XZ
     58   39 00002CB0 ?GetSupportedFeatures@Adapter@native@dawn@@QEBA?AV?$vector@PEBDV?$allocator@PEBD@std@@@std@@XZ
     59   3A 00002D00 ?GetToggleInfo@Instance@native@dawn@@QEAAPEBUToggleInfo@23@PEBD@Z
     60   3B 00002D10 ?GetTogglesUsed@native@dawn@@YA?AV?$vector@PEBDV?$allocator@PEBD@std@@@std@@PEAUWGPUDeviceImpl@@@Z
     61   3C 00002D30 ?GetType@ExternalImageDescriptor@native@dawn@@QEBA?AW4ExternalImageType@23@XZ
     62   3D 00002D40 ?GetType@ExternalImageExportInfo@native@dawn@@QEBA?AW4ExternalImageType@23@XZ
     63   3E 00002D50 ?InstanceProcessEvents@native@dawn@@YA_NPEAUWGPUInstanceImpl@@@Z
     64   3F 00002D60 ?IsTextureSubresourceInitialized@native@dawn@@YA_NPEAUWGPUTextureImpl@@IIIIW4WGPUTextureAspect@@@Z
     65   40 00002DF0 ?PerformIdleTasks@native@dawn@@YAXAEBVDevice@wgpu@@@Z
     66   41 00002E30 ?ReduceMemoryUsage@native@dawn@@YAXPEAUWGPUDeviceImpl@@@Z
     67   42 00002E70 ?RequestDevice@Adapter@native@dawn@@QEAAX$$TP6AXW4WGPURequestDeviceStatus@@PEAUWGPUDeviceImpl@@UWGPUStringView@@PEAX@Z4@Z
     68   43 00002E70 ?RequestDevice@Adapter@native@dawn@@QEAAXPEBUDeviceDescriptor@wgpu@@P6AXW4WGPURequestDeviceStatus@@PEAUWGPUDeviceImpl@@UWGPUStringView@@PEAX@Z4@Z
     69   44 00002E70 ?RequestDevice@Adapter@native@dawn@@QEAAXPEBUWGPUDeviceDescriptor@@P6AXW4WGPURequestDeviceStatus@@PEAUWGPUDeviceImpl@@UWGPUStringView@@PEAX@Z4@Z
     70   45 00002E80 ?ResetInternalDeviceForTesting@Adapter@native@dawn@@QEAAXXZ
     71   46 00002F20 ?SetBackendValidationLevel@Instance@native@dawn@@QEAAXW4BackendValidationLevel@23@@Z
     72   47 00003270 ?SetExternalMemoryReservation@d3d12@native@dawn@@YA_KPEAUWGPUDeviceImpl@@_KW4MemorySegment@123@@Z
     73   48 00002F30 ?SetUseTieredLimits@Adapter@native@dawn@@QEAAX_N@Z
     74   49 00002F40 ?SupportsExternalImages@Adapter@native@dawn@@QEBA_NXZ
     75   4A 00424850 ?kNameObjectCount@MemoryDump@native@dawn@@2QBDB
     76   4B 00424848 ?kNameSize@MemoryDump@native@dawn@@2QBDB
     77   4C 00424860 ?kUnitsBytes@MemoryDump@native@dawn@@2QBDB
     78   4D 00424868 ?kUnitsObjects@MemoryDump@native@dawn@@2QBDB
     79   4E 00001040 wgpuAdapterAddRef
     80   4F 00001050 wgpuAdapterCreateDevice
     81   50 00001060 wgpuAdapterGetFeatures
     82   51 00001070 wgpuAdapterGetFormatCapabilities
     83   52 00001080 wgpuAdapterGetInfo
     84   53 00001090 wgpuAdapterGetInstance
     85   54 000010A0 wgpuAdapterGetLimits
     86   55 000010B0 wgpuAdapterHasFeature
     87   56 000010C0 wgpuAdapterInfoFreeMembers
     88   57 00001110 wgpuAdapterPropertiesMemoryHeapsFreeMembers
     89   58 00001140 wgpuAdapterRelease
     90   59 00001150 wgpuAdapterRequestDevice
     91   5A 00001160 wgpuAdapterRequestDevice2
     92   5B 000011A0 wgpuAdapterRequestDeviceF
     93   5C 00001040 wgpuBindGroupAddRef
     94   5D 00001040 wgpuBindGroupLayoutAddRef
     95   5E 00001140 wgpuBindGroupLayoutRelease
     96   5F 000011D0 wgpuBindGroupLayoutSetLabel
     97   60 00001140 wgpuBindGroupRelease
     98   61 000011D0 wgpuBindGroupSetLabel
     99   62 00001040 wgpuBufferAddRef
    100   63 000011F0 wgpuBufferDestroy
    101   64 00001200 wgpuBufferGetConstMappedRange
    102   65 00001210 wgpuBufferGetMapState
    103   66 00001220 wgpuBufferGetMappedRange
    104   67 00001230 wgpuBufferGetSize
    105   68 00001240 wgpuBufferGetUsage
    106   69 00001250 wgpuBufferMapAsync
    107   6A 00001260 wgpuBufferMapAsync2
    108   6B 000012A0 wgpuBufferMapAsyncF
    109   6C 00001140 wgpuBufferRelease
    110   6D 000011D0 wgpuBufferSetLabel
    111   6E 000012E0 wgpuBufferUnmap
    112   6F 00001040 wgpuCommandBufferAddRef
    113   70 00001140 wgpuCommandBufferRelease
    114   71 000011D0 wgpuCommandBufferSetLabel
    115   72 00001040 wgpuCommandEncoderAddRef
    116   73 000012F0 wgpuCommandEncoderBeginComputePass
    117   74 00001300 wgpuCommandEncoderBeginRenderPass
    118   75 00001310 wgpuCommandEncoderClearBuffer
    119   76 00001320 wgpuCommandEncoderCopyBufferToBuffer
    120   77 00001330 wgpuCommandEncoderCopyBufferToTexture
    121   78 00001340 wgpuCommandEncoderCopyTextureToBuffer
    122   79 00001350 wgpuCommandEncoderCopyTextureToTexture
    123   7A 00001360 wgpuCommandEncoderFinish
    124   7B 00001370 wgpuCommandEncoderInjectValidationError
    125   7C 00001390 wgpuCommandEncoderInsertDebugMarker
    126   7D 000013B0 wgpuCommandEncoderPopDebugGroup
    127   7E 000013C0 wgpuCommandEncoderPushDebugGroup
    128   7F 00001140 wgpuCommandEncoderRelease
    129   80 000013E0 wgpuCommandEncoderResolveQuerySet
    130   81 000013F0 wgpuCommandEncoderSetLabel
    131   82 00001410 wgpuCommandEncoderWriteBuffer
    132   83 00001420 wgpuCommandEncoderWriteTimestamp
    133   84 00001040 wgpuComputePassEncoderAddRef
    134   85 00001430 wgpuComputePassEncoderDispatchWorkgroups
    135   86 00001440 wgpuComputePassEncoderDispatchWorkgroupsIndirect
    136   87 00001450 wgpuComputePassEncoderEnd
    137   88 00001460 wgpuComputePassEncoderInsertDebugMarker
    138   89 00001480 wgpuComputePassEncoderPopDebugGroup
    139   8A 00001490 wgpuComputePassEncoderPushDebugGroup
    140   8B 00001140 wgpuComputePassEncoderRelease
    141   8C 000014B0 wgpuComputePassEncoderSetBindGroup
    142   8D 000013F0 wgpuComputePassEncoderSetLabel
    143   8E 000014C0 wgpuComputePassEncoderSetPipeline
    144   8F 000014D0 wgpuComputePassEncoderWriteTimestamp
    145   90 00001040 wgpuComputePipelineAddRef
    146   91 000014E0 wgpuComputePipelineGetBindGroupLayout
    147   92 00001140 wgpuComputePipelineRelease
    148   93 000011D0 wgpuComputePipelineSetLabel
    149   94 000014F0 wgpuCreateInstance
    150   95 00001500 wgpuDeviceAddRef
    151   96 00001510 wgpuDeviceCreateBindGroup
    152   97 00001520 wgpuDeviceCreateBindGroupLayout
    153   98 00001530 wgpuDeviceCreateBuffer
    154   99 00001540 wgpuDeviceCreateCommandEncoder
    155   9A 00001550 wgpuDeviceCreateComputePipeline
    156   9B 00001560 wgpuDeviceCreateComputePipelineAsync
    157   9C 00001570 wgpuDeviceCreateComputePipelineAsync2
    158   9D 000015B0 wgpuDeviceCreateComputePipelineAsyncF
    159   9E 000015E0 wgpuDeviceCreateErrorBuffer
    160   9F 000015F0 wgpuDeviceCreateErrorExternalTexture
    161   A0 00001600 wgpuDeviceCreateErrorShaderModule
    162   A1 00001620 wgpuDeviceCreateErrorTexture
    163   A2 00001630 wgpuDeviceCreateExternalTexture
    164   A3 00001640 wgpuDeviceCreatePipelineLayout
    165   A4 00001650 wgpuDeviceCreateQuerySet
    166   A5 00001660 wgpuDeviceCreateRenderBundleEncoder
    167   A6 00001670 wgpuDeviceCreateRenderPipeline
    168   A7 00001680 wgpuDeviceCreateRenderPipelineAsync
    169   A8 00001690 wgpuDeviceCreateRenderPipelineAsync2
    170   A9 000016D0 wgpuDeviceCreateRenderPipelineAsyncF
    171   AA 00001700 wgpuDeviceCreateSampler
    172   AB 00001710 wgpuDeviceCreateShaderModule
    173   AC 00001720 wgpuDeviceCreateTexture
    174   AD 00001730 wgpuDeviceDestroy
    175   AE 00001740 wgpuDeviceForceLoss
    176   AF 00001760 wgpuDeviceGetAHardwareBufferProperties
    177   B0 00001770 wgpuDeviceGetAdapter
    178   B1 00001780 wgpuDeviceGetAdapterInfo
    179   B2 00001790 wgpuDeviceGetFeatures
    180   B3 000017A0 wgpuDeviceGetLimits
    181   B4 000017B0 wgpuDeviceGetQueue
    182   B5 000017C0 wgpuDeviceHasFeature
    183   B6 000017D0 wgpuDeviceImportSharedBufferMemory
    184   B7 000017E0 wgpuDeviceImportSharedFence
    185   B8 000017F0 wgpuDeviceImportSharedTextureMemory
    186   B9 00001800 wgpuDeviceInjectError
    187   BA 00001820 wgpuDevicePopErrorScope
    188   BB 00001830 wgpuDevicePopErrorScope2
    189   BC 00001860 wgpuDevicePopErrorScopeF
    190   BD 00001890 wgpuDevicePushErrorScope
    191   BE 000018A0 wgpuDeviceRelease
    192   BF 000018B0 wgpuDeviceSetLabel
    193   C0 000018D0 wgpuDeviceSetLoggingCallback
    194   C1 000018E0 wgpuDeviceTick
    195   C2 000018F0 wgpuDeviceValidateTextureDescriptor
    196   C3 00001110 wgpuDrmFormatCapabilitiesFreeMembers
    197   C4 00001040 wgpuExternalTextureAddRef
    198   C5 000011F0 wgpuExternalTextureDestroy
    199   C6 00001900 wgpuExternalTextureExpire
    200   C7 00001910 wgpuExternalTextureRefresh
    201   C8 00001140 wgpuExternalTextureRelease
    202   C9 000011D0 wgpuExternalTextureSetLabel
    203   CA 00001920 wgpuGetInstanceFeatures
    204   CB 00001930 wgpuGetProcAddress
    205   CC 00001500 wgpuInstanceAddRef
    206   CD 00001950 wgpuInstanceCreateSurface
    207   CE 00001960 wgpuInstanceEnumerateWGSLLanguageFeatures
    208   CF 00001970 wgpuInstanceHasWGSLLanguageFeature
    209   D0 00001980 wgpuInstanceProcessEvents
    210   D1 000018A0 wgpuInstanceRelease
    211   D2 00001990 wgpuInstanceRequestAdapter
    212   D3 000019A0 wgpuInstanceRequestAdapter2
    213   D4 000019E0 wgpuInstanceRequestAdapterF
    214   D5 00001A10 wgpuInstanceWaitAny
    215   D6 00001040 wgpuPipelineLayoutAddRef
    216   D7 00001140 wgpuPipelineLayoutRelease
    217   D8 000011D0 wgpuPipelineLayoutSetLabel
    218   D9 00001040 wgpuQuerySetAddRef
    219   DA 000011F0 wgpuQuerySetDestroy
    220   DB 00001A20 wgpuQuerySetGetCount
    221   DC 00001A30 wgpuQuerySetGetType
    222   DD 00001140 wgpuQuerySetRelease
    223   DE 000011D0 wgpuQuerySetSetLabel
    224   DF 00001040 wgpuQueueAddRef
    225   E0 00001A40 wgpuQueueCopyExternalTextureForBrowser
    226   E1 00001A50 wgpuQueueCopyTextureForBrowser
    227   E2 00001A60 wgpuQueueOnSubmittedWorkDone
    228   E3 00001A70 wgpuQueueOnSubmittedWorkDone2
    229   E4 00001AA0 wgpuQueueOnSubmittedWorkDoneF
    230   E5 00001140 wgpuQueueRelease
    231   E6 000011D0 wgpuQueueSetLabel
    232   E7 00001AD0 wgpuQueueSubmit
    233   E8 00001AE0 wgpuQueueWriteBuffer
    234   E9 00001AF0 wgpuQueueWriteTexture
    235   EA 00001040 wgpuRenderBundleAddRef
    236   EB 00001040 wgpuRenderBundleEncoderAddRef
    237   EC 00001B00 wgpuRenderBundleEncoderDraw
    238   ED 00001B10 wgpuRenderBundleEncoderDrawIndexed
    239   EE 00001B20 wgpuRenderBundleEncoderDrawIndexedIndirect
    240   EF 00001B30 wgpuRenderBundleEncoderDrawIndirect
    241   F0 00001B40 wgpuRenderBundleEncoderFinish
    242   F1 00001460 wgpuRenderBundleEncoderInsertDebugMarker
    243   F2 00001480 wgpuRenderBundleEncoderPopDebugGroup
    244   F3 00001490 wgpuRenderBundleEncoderPushDebugGroup
    245   F4 00001140 wgpuRenderBundleEncoderRelease
    246   F5 00001B50 wgpuRenderBundleEncoderSetBindGroup
    247   F6 00001B60 wgpuRenderBundleEncoderSetIndexBuffer
    248   F7 000013F0 wgpuRenderBundleEncoderSetLabel
    249   F8 00001B70 wgpuRenderBundleEncoderSetPipeline
    250   F9 00001B80 wgpuRenderBundleEncoderSetVertexBuffer
    251   FA 00001140 wgpuRenderBundleRelease
    252   FB 000011D0 wgpuRenderBundleSetLabel
    253   FC 00001040 wgpuRenderPassEncoderAddRef
    254   FD 00001B90 wgpuRenderPassEncoderBeginOcclusionQuery
    255   FE 00001B00 wgpuRenderPassEncoderDraw
    256   FF 00001B10 wgpuRenderPassEncoderDrawIndexed
    257  100 00001B20 wgpuRenderPassEncoderDrawIndexedIndirect
    258  101 00001B30 wgpuRenderPassEncoderDrawIndirect
    259  102 00001BA0 wgpuRenderPassEncoderEnd
    260  103 00001BB0 wgpuRenderPassEncoderEndOcclusionQuery
    261  104 00001BC0 wgpuRenderPassEncoderExecuteBundles
    262  105 00001460 wgpuRenderPassEncoderInsertDebugMarker
    263  106 00001BD0 wgpuRenderPassEncoderMultiDrawIndexedIndirect
    264  107 00001BE0 wgpuRenderPassEncoderMultiDrawIndirect
    265  108 00001BF0 wgpuRenderPassEncoderPixelLocalStorageBarrier
    266  109 00001480 wgpuRenderPassEncoderPopDebugGroup
    267  10A 00001490 wgpuRenderPassEncoderPushDebugGroup
    268  10B 00001140 wgpuRenderPassEncoderRelease
    269  10C 00001B50 wgpuRenderPassEncoderSetBindGroup
    270  10D 00001C00 wgpuRenderPassEncoderSetBlendConstant
    271  10E 00001B60 wgpuRenderPassEncoderSetIndexBuffer
    272  10F 000013F0 wgpuRenderPassEncoderSetLabel
    273  110 00001B70 wgpuRenderPassEncoderSetPipeline
    274  111 00001C10 wgpuRenderPassEncoderSetScissorRect
    275  112 00001C20 wgpuRenderPassEncoderSetStencilReference
    276  113 00001B80 wgpuRenderPassEncoderSetVertexBuffer
    277  114 00001C30 wgpuRenderPassEncoderSetViewport
    278  115 00001C40 wgpuRenderPassEncoderWriteTimestamp
    279  116 00001040 wgpuRenderPipelineAddRef
    280  117 000014E0 wgpuRenderPipelineGetBindGroupLayout
    281  118 00001140 wgpuRenderPipelineRelease
    282  119 000011D0 wgpuRenderPipelineSetLabel
    283  11A 00001040 wgpuSamplerAddRef
    284  11B 00001140 wgpuSamplerRelease
    285  11C 000011D0 wgpuSamplerSetLabel
    286  11D 00001C50 wgpuShaderModuleAddRef
    287  11E 00001C60 wgpuShaderModuleGetCompilationInfo
    288  11F 00001C70 wgpuShaderModuleGetCompilationInfo2
    289  120 00001CA0 wgpuShaderModuleGetCompilationInfoF
    290  121 00001CD0 wgpuShaderModuleRelease
    291  122 000011D0 wgpuShaderModuleSetLabel
    292  123 00001040 wgpuSharedBufferMemoryAddRef
    293  124 00001CE0 wgpuSharedBufferMemoryBeginAccess
    294  125 00001CF0 wgpuSharedBufferMemoryCreateBuffer
    295  126 00001D00 wgpuSharedBufferMemoryEndAccess
    296  127 00001D10 wgpuSharedBufferMemoryEndAccessStateFreeMembers
    297  128 00001D40 wgpuSharedBufferMemoryGetProperties
    298  129 00001D50 wgpuSharedBufferMemoryIsDeviceLost
    299  12A 00001140 wgpuSharedBufferMemoryRelease
    300  12B 000011D0 wgpuSharedBufferMemorySetLabel
    301  12C 00001040 wgpuSharedFenceAddRef
    302  12D 00001D60 wgpuSharedFenceExportInfo
    303  12E 00001140 wgpuSharedFenceRelease
    304  12F 00001040 wgpuSharedTextureMemoryAddRef
    305  130 00001D70 wgpuSharedTextureMemoryBeginAccess
    306  131 00001D80 wgpuSharedTextureMemoryCreateTexture
    307  132 00001D90 wgpuSharedTextureMemoryEndAccess
    308  133 00001D10 wgpuSharedTextureMemoryEndAccessStateFreeMembers
    309  134 00001DA0 wgpuSharedTextureMemoryGetProperties
    310  135 00001D50 wgpuSharedTextureMemoryIsDeviceLost
    311  136 00001140 wgpuSharedTextureMemoryRelease
    312  137 000011D0 wgpuSharedTextureMemorySetLabel
    313  138 00001DB0 wgpuSupportedFeaturesFreeMembers
    314  139 00001040 wgpuSurfaceAddRef
    315  13A 00001DD0 wgpuSurfaceCapabilitiesFreeMembers
    316  13B 00001E10 wgpuSurfaceConfigure
    317  13C 00001E20 wgpuSurfaceGetCapabilities
    318  13D 00001E30 wgpuSurfaceGetCurrentTexture
    319  13E 00001E40 wgpuSurfacePresent
    320  13F 00001140 wgpuSurfaceRelease
    321  140 00001E50 wgpuSurfaceSetLabel
    322  141 00001E70 wgpuSurfaceUnconfigure
    323  142 00001040 wgpuTextureAddRef
    324  143 00001E80 wgpuTextureCreateErrorView
    325  144 00001E90 wgpuTextureCreateView
    326  145 000011F0 wgpuTextureDestroy
    327  146 00001EA0 wgpuTextureGetDepthOrArrayLayers
    328  147 00001EB0 wgpuTextureGetDimension
    329  148 00001EC0 wgpuTextureGetFormat
    330  149 00001ED0 wgpuTextureGetHeight
    331  14A 00001EE0 wgpuTextureGetMipLevelCount
    332  14B 00001EF0 wgpuTextureGetSampleCount
    333  14C 00001F00 wgpuTextureGetUsage
    334  14D 00001F10 wgpuTextureGetWidth
    335  14E 00001140 wgpuTextureRelease
    336  14F 000011D0 wgpuTextureSetLabel
    337  150 00001040 wgpuTextureViewAddRef
    338  151 00001140 wgpuTextureViewRelease
    339  152 000011D0 wgpuTextureViewSetLabel

Summary

   20000 .data
   22000 .pdata
   F4000 .rdata
    6000 .reloc
    1000 .rsrc
  423000 .text

endif()

# Copy webgpu_dawn.dll to the output directory
add_custom_command(
TARGET onnxruntime_providers_webgpu
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:dawn::webgpu_dawn>" "$<TARGET_FILE_DIR:onnxruntime_providers_webgpu>"
VERBATIM )
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)

set_target_properties(onnxruntime_providers_webgpu PROPERTIES FOLDER "ONNXRuntime")
8 changes: 5 additions & 3 deletions onnxruntime/core/providers/webgpu/webgpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ void WebGpuContext::Initialize(const WebGpuExecutionProviderInfo& webgpu_ep_info
// Initialization.Step.1 - Create wgpu::Instance
if (instance_ == nullptr) {
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.");
#else
#if !defined(USE_EXTERNAL_DAWN)
if (dawn_procs == nullptr) {
dawn_procs = &dawn::native::GetProcs();
Expand All @@ -36,6 +39,7 @@ void WebGpuContext::Initialize(const WebGpuExecutionProviderInfo& webgpu_ep_info
ORT_ENFORCE(dawn_procs != nullptr, "DawnProcTable must be provided.");
#endif
dawnProcSetProcs(dawn_procs);
#endif

wgpu::InstanceDescriptor instance_desc{};
instance_desc.features.timedWaitAnyEnable = true;
Expand All @@ -49,9 +53,7 @@ void WebGpuContext::Initialize(const WebGpuExecutionProviderInfo& webgpu_ep_info
wgpu::RequestAdapterOptions req_adapter_options = {};
wgpu::DawnTogglesDescriptor adapter_toggles_desc = {};
req_adapter_options.nextInChain = &adapter_toggles_desc;
#ifdef _WIN32
req_adapter_options.backendType = wgpu::BackendType::D3D12;
#endif
req_adapter_options.backendType = static_cast<wgpu::BackendType>(webgpu_ep_info.backend_type);
req_adapter_options.powerPreference = wgpu::PowerPreference::HighPerformance;

auto enabled_adapter_toggles = GetEnabledAdapterToggles();
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/providers/webgpu/webgpu_execution_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct WebGpuExecutionProviderInfo {
WebGpuExecutionProviderInfo(DataLayout data_layout, bool enable_graph_capture)
: data_layout{data_layout},
enable_graph_capture{enable_graph_capture},
backend_type{},
storage_buffer_cache_mode{},
uniform_buffer_cache_mode{},
query_resolve_buffer_cache_mode{},
Expand All @@ -36,6 +37,7 @@ struct WebGpuExecutionProviderInfo {

DataLayout data_layout;
bool enable_graph_capture;
int backend_type;
webgpu::BufferCacheMode storage_buffer_cache_mode;
webgpu::BufferCacheMode uniform_buffer_cache_mode;
webgpu::BufferCacheMode query_resolve_buffer_cache_mode;
Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/core/providers/webgpu/webgpu_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ std::shared_ptr<IExecutionProviderFactory> WebGpuProviderFactoryCreator::Create(
}
LOGS_DEFAULT(VERBOSE) << "WebGPU EP graph capture enable: " << webgpu_ep_info.enable_graph_capture;

std::string backend_type_str;
if (config_options.TryGetConfigEntry(kDawnBackendType, backend_type_str)) {
#ifdef _WIN32
// Setup Windows default backend type based on the build configuration
#if defined(onnxruntime_ENABLE_DAWN_BACKEND_D3D12)
webgpu_ep_info.backend_type = static_cast<int>(WGPUBackendType_D3D12);
#elif defined(onnxruntime_ENABLE_DAWN_BACKEND_VULKAN)
webgpu_ep_info.backend_type = static_cast<int>(WGPUBackendType_Vulkan);
#endif
#endif
if (backend_type_str == kDawnBackendType_D3D12) {
webgpu_ep_info.backend_type = static_cast<int>(WGPUBackendType_D3D12);
} else if (backend_type_str == kDawnBackendType_Vulkan) {
webgpu_ep_info.backend_type = static_cast<int>(WGPUBackendType_Vulkan);
} else {
ORT_THROW("Invalid Dawn backend type: ", backend_type_str);
}
}
LOGS_DEFAULT(VERBOSE) << "WebGPU EP Dawn backend type: " << webgpu_ep_info.backend_type;

auto parse_buffer_cache_mode = [&config_options](const std::string& config_entry_str,
webgpu::BufferCacheMode default_value) -> webgpu::BufferCacheMode {
std::string buffer_cache_mode_str;
Expand Down
5 changes: 5 additions & 0 deletions onnxruntime/core/providers/webgpu/webgpu_provider_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ constexpr const char* kEnableGraphCapture = "WebGPU:enableGraphCapture";

constexpr const char* kDawnProcTable = "WebGPU:dawnProcTable";

constexpr const char* kDawnBackendType = "WebGPU:dawnBackendType";

constexpr const char* kDeviceId = "WebGPU:deviceId";
constexpr const char* kWebGpuInstance = "WebGPU:webgpuInstance";
constexpr const char* kWebGpuAdapter = "WebGPU:webgpuAdapter";
Expand All @@ -30,6 +32,9 @@ constexpr const char* kForceCpuNodeNames = "WebGPU:forceCpuNodeNames";

// The following are the possible values for the provider options.

constexpr const char* kDawnBackendType_D3D12 = "D3D12";
constexpr const char* kDawnBackendType_Vulkan = "Vulkan";

constexpr const char* kPreferredLayout_NCHW = "NCHW";
constexpr const char* kPreferredLayout_NHWC = "NHWC";

Expand Down
Loading