startup: select an Agility SDK runtime before the first device (X2W_D3D12_AGILITY) #3466

Manually merged
github merged 8 commits from github-bot/gh-3464 into main 2026-12-01 00:25:21 +00:00 AGit
Owner

@⁠lukaslw-lab on GitHub · 2026-11-29 15:02 UTC · original
lukaslw-lab:runtime/agility-sdk-select → main · +448 −0 · 7 files · 8 commits · merged 2026-12-01 00:19 UTC

Refs #3162, #3451

The title exports no D3D12SDKVersion, so startup runs get the in-box D3D12 runtime. On Windows 10 that has no
shader model 6.6, so no native compute pipeline that needs cs_6_6 can be created. Now that native shaders are on by
default (#3451), Windows 10 machines get no native compute at all.

With the opt-in X2W_D3D12_AGILITY=<dir>, the three stand-ins that create a device call
ID3D12SDKConfiguration::SetSDKVersion first, using the version read from that D3D12Core.dll's export. The first
call in the process decides. Unset, nothing is read or called.

Startup run from a save, 360 s, same build, Windows 10 19045 in-box X2W_D3D12_AGILITY
native compute translations usable 0 of 483 67 of 487
device removed none none
  • Needs Windows Developer Mode. Otherwise the failure is logged and the in-box runtime stays.
  • The path must be relative to the executable (an absolute one makes device creation fail to load
    D3D12Core.dll), so the SDK directory goes on the executable's drive. A junction works.
  • Pipelines whose root signature indexes the heaps directly get other cache keys than on a runtime without
    shader model 6.6: the root blob's DXBC checksum differs. A cache built on the in-box runtime needs their requests
    translated again.
  • Docs: switch row and section "D3D12 Agility SDK runtime" in docs/startup-runtime.md.

Tests: startup_agility_sdk (relative paths, the ANSI conversion, the device loads the selected DLL, a second call
does nothing, a child process selects for itself), startup_agility_sdk_no_select_control (switch unset, must fail the
loaded-DLL check) and startup_agility_sdk_entry_{shim,permissive,xg} (the first device of a fresh process, through
each stand-in's own entry, must load the selected DLL). All skip (77) without OFFSCREEN_AGILITY_620_DIR or
Developer Mode, so CI runs only the path cases. Locally (RTX 3080 Ti, driver 32.0.16.1047, Windows 10 19045,
Developer Mode, e571e5ae): all pass on a build with OFFSCREEN_AGILITY_620_DIR and skip on release and dev; the
device-site family (ctest -R "^(startup_agility|d3d12_xs_shim|startup_xg|xg_)", 25 tests) has 0 failures on all
three, with 5 xg_ capability skips (and the 5 Agility skips on release and dev).

🤖 Generated with Claude Code

**@⁠lukaslw-lab** on GitHub · 2026-11-29 15:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3464) `lukaslw-lab:runtime/agility-sdk-select` → `main` · +448 −0 · 7 files · 8 commits · merged 2026-12-01 00:19 UTC Refs #3162, #3451 The title exports no `D3D12SDKVersion`, so startup runs get the in-box D3D12 runtime. On Windows 10 that has no shader model 6.6, so no native compute pipeline that needs cs_6_6 can be created. Now that native shaders are on by default (#3451), Windows 10 machines get no native compute at all. With the opt-in `X2W_D3D12_AGILITY=<dir>`, the three stand-ins that create a device call `ID3D12SDKConfiguration::SetSDKVersion` first, using the version read from that `D3D12Core.dll`'s export. The first call in the process decides. Unset, nothing is read or called. | Startup run from a save, 360 s, same build, Windows 10 19045 | in-box | `X2W_D3D12_AGILITY` | |---|---|---| | native compute translations usable | 0 of 483 | 67 of 487 | | device removed | none | none | - Needs Windows Developer Mode. Otherwise the failure is logged and the in-box runtime stays. - The path must be relative to the executable (an absolute one makes device creation fail to load `D3D12Core.dll`), so the SDK directory goes on the executable's drive. A junction works. - Pipelines whose root signature indexes the heaps directly get other cache keys than on a runtime without shader model 6.6: the root blob's DXBC checksum differs. A cache built on the in-box runtime needs their requests translated again. - Docs: switch row and section "D3D12 Agility SDK runtime" in `docs/startup-runtime.md`. Tests: `startup_agility_sdk` (relative paths, the ANSI conversion, the device loads the selected DLL, a second call does nothing, a child process selects for itself), `startup_agility_sdk_no_select_control` (switch unset, must fail the loaded-DLL check) and `startup_agility_sdk_entry_{shim,permissive,xg}` (the first device of a fresh process, through each stand-in's own entry, must load the selected DLL). All skip (77) without `OFFSCREEN_AGILITY_620_DIR` or Developer Mode, so CI runs only the path cases. Locally (RTX 3080 Ti, driver 32.0.16.1047, Windows 10 19045, Developer Mode, `e571e5ae`): all pass on a build with `OFFSCREEN_AGILITY_620_DIR` and skip on release and dev; the device-site family (`ctest -R "^(startup_agility|d3d12_xs_shim|startup_xg|xg_)"`, 25 tests) has 0 failures on all three, with 5 `xg_` capability skips (and the 5 Agility skips on release and dev). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The title executable exports no D3D12SDKVersion, so the stand-ins select the runtime through
ID3D12SDKConfiguration::SetSDKVersion before their first device (Developer Mode only). The first
call in the process decides; a later stand-in DLL does nothing. Off unless the switch is set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An absolute SDKPath makes device creation fail (D3D12Core.dll not loaded), and run.ps1 maps the
package root to its own drive letter, so the Agility directory has to be under it (a junction works).
Without a relative path the in-box runtime stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The drive letter in the earlier comment came from a local launcher, not from run.ps1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 15:07:34 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 16:07 UTC · original · reviewed

Diff reading only at 9b4a7450; nothing was built or run. Lines are on the PR head.

1. The once-guard is an environment variable. select_agility_sdk tests X2W_D3D12_AGILITY_SELECTED and then sets it (src/startup_stubs/agility_sdk.h:100, :104).

  • Child processes inherit it, so a child with X2W_D3D12_AGILITY set never selects the runtime. A value already present in the parent environment has the same effect. Both return S_FALSE at :100-103 with no log line.
  • The test and the set are two calls. Two stand-ins creating their first device on two threads can both pass :100 and both call SetSDKVersion; the header comment (:4) says a call after the first device removes that device.

A named object keyed by the process id (CreateMutexW plus ERROR_ALREADY_EXISTS) would be atomic and not inherited. At minimum, log when the guard is found already set.

2. Lossy path conversion. WideCharToMultiByte(CP_ACP, 0, ..., nullptr, nullptr) (:120-121) does not fail on characters outside the code page: it substitutes the default character or a best-fit one. The "none in the ANSI code page" branch (:127-129) is therefore not reached for that case, and SetSDKVersion gets a different path. Passing WC_NO_BEST_FIT_CHARS and lpUsedDefaultChar, and refusing when it is set, would make the log line true.

3. The call sites are untested. tests/startup_agility_sdk_check.cpp calls the header functions directly (:74, :98). Removing any of the three calls (src/d3d12_xs_shim.cpp:249, src/startup_stubs/d3d12_xs_device.cpp:8215, src/startup_stubs/xg_xs.cpp:39), or moving one after the device creation, passes every test in the PR.

Checked and found fine: the bare LoadLibraryW(L"d3d12.dll") (:123) returns the module the stand-ins already import (CMakeLists.txt:433, :584, no /DELAYLOAD:d3d12.dll for them); D3D12Core.dll is first mapped as data, so reading its version runs none of its code (:57); with X2W_D3D12_AGILITY unset the function returns at :100 and behaviour is unchanged.

**@⁠Leyukaka** on GitHub · 2026-11-29 16:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3464#pullrequestreview-6103675210) · **reviewed** Diff reading only at 9b4a7450; nothing was built or run. Lines are on the PR head. **1. The once-guard is an environment variable.** `select_agility_sdk` tests `X2W_D3D12_AGILITY_SELECTED` and then sets it (`src/startup_stubs/agility_sdk.h:100`, `:104`). - Child processes inherit it, so a child with `X2W_D3D12_AGILITY` set never selects the runtime. A value already present in the parent environment has the same effect. Both return `S_FALSE` at `:100-103` with no log line. - The test and the set are two calls. Two stand-ins creating their first device on two threads can both pass `:100` and both call `SetSDKVersion`; the header comment (`:4`) says a call after the first device removes that device. A named object keyed by the process id (`CreateMutexW` plus `ERROR_ALREADY_EXISTS`) would be atomic and not inherited. At minimum, log when the guard is found already set. **2. Lossy path conversion.** `WideCharToMultiByte(CP_ACP, 0, ..., nullptr, nullptr)` (`:120-121`) does not fail on characters outside the code page: it substitutes the default character or a best-fit one. The "none in the ANSI code page" branch (`:127-129`) is therefore not reached for that case, and `SetSDKVersion` gets a different path. Passing `WC_NO_BEST_FIT_CHARS` and `lpUsedDefaultChar`, and refusing when it is set, would make the log line true. **3. The call sites are untested.** `tests/startup_agility_sdk_check.cpp` calls the header functions directly (`:74`, `:98`). Removing any of the three calls (`src/d3d12_xs_shim.cpp:249`, `src/startup_stubs/d3d12_xs_device.cpp:8215`, `src/startup_stubs/xg_xs.cpp:39`), or moving one after the device creation, passes every test in the PR. Checked and found fine: the bare `LoadLibraryW(L"d3d12.dll")` (`:123`) returns the module the stand-ins already import (`CMakeLists.txt:433`, `:584`, no `/DELAYLOAD:d3d12.dll` for them); `D3D12Core.dll` is first mapped as data, so reading its version runs none of its code (`:57`); with `X2W_D3D12_AGILITY` unset the function returns at `:100` and behaviour is unchanged.
- The once-guard is a mutex named after the process id instead of an environment variable: a child process (which
  inherits the environment) selects for itself, and a second stand-in or thread waits for the first decision instead
  of racing it. A later call logs once that the runtime was already decided.
- The relative path is converted with WC_NO_BEST_FIT_CHARS and lpUsedDefaultChar (flags 0 on a UTF-8 ANSI code page);
  a character without an exact form is refused with its own log line instead of naming another directory.
- startup_agility_sdk_entry_{shim,permissive,xg}: the first device of a fresh process comes from that stand-in's own
  entry and must run on the selected D3D12Core.dll. The main check adds (d) the path conversion and (e) a child process.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 01:13 UTC · original

Thanks, all three addressed in 8bdb9044 and d2b178c1 (main merged in e571e5ae).

1. Once-guard. Now a mutex named after the process id (Local\x2w-d3d12-agility-<pid>). The first call creates it owned, decides, and releases it. A later call, from another stand-in or another thread, waits for that decision, then returns S_FALSE and logs once that it was already decided. A child process has another name, so it selects for itself. The environment marker is gone.

2. Lossy path. WideCharToMultiByte now gets WC_NO_BEST_FIT_CHARS and lpUsedDefaultChar; a replaced character refuses the path with its own log line (agility_narrow_path). On a UTF-8 ANSI code page both are invalid, so flags 0 there; that conversion is exact.

3. Call sites. startup_agility_sdk_entry_{shim,permissive,xg} create the first device of a fresh process through D3D12XboxCreateDevice without a parameter block, with one under X2W_D3D12_PERMISSIVE, and through an XG texture layout, and require the selected D3D12Core.dll. The main check adds (d) the conversion and (e) a child process.

Mutants, each applied alone (w10 build with OFFSCREEN_AGILITY_620_DIR):

mutant fails
shim call removed (d3d12_xs_shim.cpp) entry_shim only
permissive call removed (d3d12_xs_device.cpp) entry_permissive only
XG call removed (xg_xs.cpp) entry_xg only
guard name without the pid (as inherited as the old marker) startup_agility_sdk (e)
conversion back to flags 0 startup_agility_sdk (d)

ctest -R "^startup_agility_sdk": 5 of 5 pass on the Agility build (RTX 3080 Ti, driver 32.0.16.1047, Windows 10 19045, Developer Mode, Agility 1.620.2); release and dev build clean, and all 5 skip (77) without OFFSCREEN_AGILITY_620_DIR.

In a 90 s start-up run of the application on e571e5ae, the log has SetSDKVersion(620, "D3D12\") -> 0x00000000 once and already decided earlier in this process once, from the later stand-in.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 01:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3464#issuecomment-7265952184) Thanks, all three addressed in `8bdb9044` and `d2b178c1` (main merged in `e571e5ae`). **1. Once-guard.** Now a mutex named after the process id (`Local\x2w-d3d12-agility-<pid>`). The first call creates it owned, decides, and releases it. A later call, from another stand-in or another thread, waits for that decision, then returns `S_FALSE` and logs once that it was already decided. A child process has another name, so it selects for itself. The environment marker is gone. **2. Lossy path.** `WideCharToMultiByte` now gets `WC_NO_BEST_FIT_CHARS` and `lpUsedDefaultChar`; a replaced character refuses the path with its own log line (`agility_narrow_path`). On a UTF-8 ANSI code page both are invalid, so flags 0 there; that conversion is exact. **3. Call sites.** `startup_agility_sdk_entry_{shim,permissive,xg}` create the first device of a fresh process through `D3D12XboxCreateDevice` without a parameter block, with one under `X2W_D3D12_PERMISSIVE`, and through an XG texture layout, and require the selected `D3D12Core.dll`. The main check adds (d) the conversion and (e) a child process. Mutants, each applied alone (w10 build with `OFFSCREEN_AGILITY_620_DIR`): | mutant | fails | |---|---| | shim call removed (`d3d12_xs_shim.cpp`) | `entry_shim` only | | permissive call removed (`d3d12_xs_device.cpp`) | `entry_permissive` only | | XG call removed (`xg_xs.cpp`) | `entry_xg` only | | guard name without the pid (as inherited as the old marker) | `startup_agility_sdk` (e) | | conversion back to flags 0 | `startup_agility_sdk` (d) | `ctest -R "^startup_agility_sdk"`: 5 of 5 pass on the Agility build (RTX 3080 Ti, driver 32.0.16.1047, Windows 10 19045, Developer Mode, Agility 1.620.2); release and dev build clean, and all 5 skip (77) without `OFFSCREEN_AGILITY_620_DIR`. In a 90 s start-up run of the application on `e571e5ae`, the log has `SetSDKVersion(620, "D3D12\") -> 0x00000000` once and `already decided earlier in this process` once, from the later stand-in.
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-01 00:04 UTC · original · approved these changes

Re-read at e571e5ae, diff only. The three points from my earlier review are addressed: the once-guard is a mutex named after the process id (src/startup_stubs/agility_sdk.h:115-137), a lossy ANSI conversion is refused (:94-101), and each stand-in entry has its own test. In the permissive path the selection runs before X2W_D3D12_DEBUG and the first device (src/startup_stubs/d3d12_xs_device.cpp:8419).

  • NIT src/startup_stubs/agility_sdk.h:140-151: a relative X2W_D3D12_AGILITY (for example D3D12) shares no root with the executable's directory, so agility_relative_path returns empty and the log says "another drive?" (:159-161), even when agility_sdk_version found the file (:142-143). Calling GetFullPathNameW on the value first would fix this. A log line saying that the path must be absolute would also work.
**@⁠Leyukaka** on GitHub · 2026-12-01 00:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3464#pullrequestreview-6122772626) · **approved these changes** Re-read at `e571e5ae`, diff only. The three points from my earlier review are addressed: the once-guard is a mutex named after the process id (`src/startup_stubs/agility_sdk.h:115-137`), a lossy ANSI conversion is refused (`:94-101`), and each stand-in entry has its own test. In the permissive path the selection runs before `X2W_D3D12_DEBUG` and the first device (`src/startup_stubs/d3d12_xs_device.cpp:8419`). - **NIT** `src/startup_stubs/agility_sdk.h:140-151`: a relative `X2W_D3D12_AGILITY` (for example `D3D12`) shares no root with the executable's directory, so `agility_relative_path` returns empty and the log says "another drive?" (`:159-161`), even when `agility_sdk_version` found the file (`:142-143`). Calling `GetFullPathNameW` on the value first would fix this. A log line saying that the path must be absolute would also work.
github manually merged commit e5e785f8c8 into main 2026-12-01 00:25:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.