Fall back to the system D3D12 runtime when the Agility SDK device factory cannot create a device - #2280
Merged
kunal-vaishnavi merged 3 commits intoJul 13, 2026
Conversation
…tory cannot create a device The Agility SDK device factory path in CreateDmlObjects throws on any CreateDevice failure instead of reaching the existing system-runtime fallback branch. A known failure 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. Whether this path fails is OS-dependent: on systems whose in-box D3D12 is older than the requested SDK version, CreateDeviceFactory fails and the fallback already runs; an OS update silently flips the branch and breaks model load. Treat a factory CreateDevice failure like a factory creation failure: log a warning with the HRESULT and fall back to D3D12CreateDevice. Validated on Xbox Series S (Dev Mode UWP, OS 26100): a XAML app calling OgaCreateModel with the DML EP failed with 887A0036 before this change and loads and runs correctly through the fallback with it.
Gianluca Mazza (gianlucamazza)
added a commit
to gianlucamazza/xllama
that referenced
this pull request
Jul 7, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot started reviewing on behalf of
Gianluca Mazza (gianlucamazza)
July 7, 2026 20:52
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves DirectML initialization robustness on Windows by allowing CreateDmlObjects to fall back to the in-box (system) D3D12 runtime when the D3D12 Agility SDK device factory is present but fails to create a device (e.g., DXGI_ERROR_ALREADY_EXISTS in XAML/WinUI hosts that already created a system-runtime D3D12 device).
Changes:
- Treat Agility
ID3D12DeviceFactory::CreateDevicefailures as non-fatal and fall back toD3D12CreateDevice. - Add diagnostics that include the failing HRESULT when the Agility factory device creation fails.
Contributor
Author
|
@microsoft-github-policy-service agree |
Address review feedback on microsoft#2280: the diagnostic strings hardcoded 1.614.0 while the factory used the agility_sdk_version constant, so the two could drift apart when the SDK is updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0152PPkDwULuMR9hshirPXQx
kunal-vaishnavi
approved these changes
Jul 8, 2026
kunal-vaishnavi
enabled auto-merge (squash)
July 8, 2026 17:21
kunal-vaishnavi
disabled auto-merge
July 13, 2026 19:18
This was referenced Jul 14, 2026
Gianluca Mazza (gianlucamazza)
deleted the
fix/dml-device-factory-fallback
branch
July 17, 2026 10:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CreateDmlObjects(src/dml/dml_helpers.cpp) tries the Agility SDK device factory first and throws on anyCreateDevicefailure instead of reaching the existing system-runtime fallback branch:A known failure 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 creates one atWindow.Activate()— and devices from different D3D12 runtimes cannot coexist in one process. The plainD3D12CreateDevicebranch handles exactly this situation, but is unreachable.Whether this bites is OS-dependent: if the in-box D3D12 is older than the requested SDK version (614),
CreateDeviceFactoryitself fails and the fallback runs — an OS update silently flips the branch and breaksOgaCreateModelin XAML hosts.Fix
Treat a factory
CreateDevicefailure like a factory creation failure: log a warning with the HRESULT and fall back toD3D12CreateDevice.No regression for #612 (which introduced the Agility path): the new fallback only runs when the in-box runtime is >= the requested SDK version — i.e. the system runtime already contains the fixes the Agility dependency was added for. Related: #1054 (the pre-existing fallback branch for factory-creation failure).
Validation (real hardware)
Xbox Series S, Dev Mode UWP (OS 26100), ORT GenAI 0.13.2 DirectML + ORT 1.24.4, SmolLM2-360M INT4 (DML model built with the model builder):
887A0036atOgaCreateModel(reproduced 3x)