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

Merged
lukaslw-lab merged 8 commits from upstream-pr/3464 into main 2026-12-01 00:19:50 +00:00
lukaslw-lab commented 2026-11-29 15:02:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-29T15:02:49Z.


Refs #3160, #3449

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 (#3449), 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5551964888 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3464). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-29T15:02:49Z. --- Refs #3160, #3449 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 (#3449), 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)
Leyukaka commented 2026-11-29 16:07:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T16:07:53Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6103675210 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3464#pullrequestreview-6103675210). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T16:07:53Z. **Review:** COMMENTED --- 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.
lukaslw-lab commented 2026-11-30 01:13:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T01:13:31Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7265952184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3464#issuecomment-7265952184). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T01:13:31Z. --- 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.
Leyukaka commented 2026-12-01 00:04:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T00:04:09Z.

Review: APPROVED


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6122772626 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3464#pullrequestreview-6122772626). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T00:04:09Z. **Review:** APPROVED --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3464
No description provided.