Skip to content
Merged
Changes from 2 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
18 changes: 16 additions & 2 deletions src/dml/dml_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,26 @@ DmlObjects CreateDmlObjects(const std::string& current_module_path, PLUID device
// Get the version from https://devblogs.microsoft.com/directx/directx12agility/. We are currently using 1.614.0.
constexpr uint32_t agility_sdk_version = 614;

bool agility_device_created = false;
if (SUCCEEDED(D3D12GetInterface(CLSID_D3D12SDKConfiguration, IID_PPV_ARGS(&d3d12_sdk_config))) &&
SUCCEEDED(d3d12_sdk_config->CreateDeviceFactory(agility_sdk_version, current_module_path.c_str(), IID_PPV_ARGS(&d3d12_factory)))) {
THROW_IF_FAILED(d3d12_factory->CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&dml_objects.d3d12_device)));
// The Agility SDK device factory can fail even when the factory itself was created successfully.
// A known case is DXGI_ERROR_ALREADY_EXISTS (0x887A0036): the process already holds a D3D12 device
// created with the system runtime (e.g. the XAML/WinUI compositor in a packaged app), and devices
// from different D3D12 runtimes cannot coexist in one process. Fall back to the system runtime
// instead of failing model creation.
HRESULT create_device_hr = d3d12_factory->CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&dml_objects.d3d12_device));
if (SUCCEEDED(create_device_hr)) {
agility_device_created = true;
} else {
printf("Warning: Unable to create a device from version 1.614.0 of the DirectX 12 Agility SDK (HRESULT 0x%08X). Falling back to the system D3D12 runtime; some scenarios may not work.\n", static_cast<unsigned int>(create_device_hr));
Comment thread
kunal-vaishnavi marked this conversation as resolved.
Outdated
Comment thread
gianlucamazza marked this conversation as resolved.
Outdated
}
} else {
printf("Warning: Unable to create a device from version 1.614.0 of the DirectX 12 Agility SDK. You can still use this library, but some scenarios may not work.\n");
printf("The given module path: %s", current_module_path.c_str());
printf("The given module path: %s\n", current_module_path.c_str());
}

if (!agility_device_created) {
THROW_IF_FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&dml_objects.d3d12_device)));
}

Expand Down
Loading