Skip to content

Commit 4a3b63f

Browse files
skottmckayCopilot
andauthored
Weaken dxcore dependency (#24845)
### Description <!-- Describe your changes. --> Do a manual load of dxcore.dll so that old Windows versions are still supported. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> #24771 --------- Co-authored-by: Copilot <[email protected]>
1 parent 89a2ff9 commit 4a3b63f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cmake/onnxruntime_common.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ if(APPLE)
169169
target_link_libraries(onnxruntime_common PRIVATE "-framework Foundation")
170170
endif()
171171

172-
if(MSVC)
173-
target_link_libraries(onnxruntime_common PRIVATE dxcore.lib)
174-
endif()
175-
176172
if(MSVC)
177173
if(onnxruntime_target_platform STREQUAL "ARM64")
178174
set(ARM64 TRUE)

onnxruntime/core/platform/windows/device_discovery.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,31 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoD3D12() {
362362
return device_info;
363363
}
364364

365+
typedef HRESULT(WINAPI* PFN_DXCoreCreateAdapterFactory)(REFIID riid, void** ppvFactory);
366+
365367
// returns LUID to DeviceInfo
366368
std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoDxcore() {
367369
std::unordered_map<uint64_t, DeviceInfo> device_info;
368370

371+
// Load dxcore.dll. We do this manually so there's not a hard dependency on dxcore which is newer.
372+
wil::unique_hmodule dxcore_lib{LoadLibraryExW(L"dxcore.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)};
373+
if (!dxcore_lib) {
374+
LOGS_DEFAULT(INFO) << "Failed to load dxcore.dll. Expected on older Windows version that do not support dxcore.";
375+
return device_info;
376+
}
377+
378+
auto pfnDXCoreCreateAdapterFactory = reinterpret_cast<PFN_DXCoreCreateAdapterFactory>(
379+
GetProcAddress(dxcore_lib.get(), "DXCoreCreateAdapterFactory"));
380+
381+
if (!pfnDXCoreCreateAdapterFactory) {
382+
// this isn't expected to fail so ERROR not WARNING
383+
LOGS_DEFAULT(ERROR) << "Failed to get DXCoreCreateAdapterFactory function address.";
384+
return device_info;
385+
}
386+
369387
// Get all GPUs and NPUs by querying WDDM/MCDM.
370388
wil::com_ptr<IDXCoreAdapterFactory> adapterFactory;
371-
if (FAILED(DXCoreCreateAdapterFactory(IID_PPV_ARGS(&adapterFactory)))) {
389+
if (FAILED(pfnDXCoreCreateAdapterFactory(IID_PPV_ARGS(&adapterFactory)))) {
372390
return device_info;
373391
}
374392

0 commit comments

Comments
 (0)