startup: select an Agility SDK runtime before the first device (X2W_D3D12_AGILITY) #3464
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3464"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 noshader 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 callID3D12SDKConfiguration::SetSDKVersionfirst, using the version read from thatD3D12Core.dll's export. The firstcall in the process decides. Unset, nothing is read or called.
X2W_D3D12_AGILITYD3D12Core.dll), so the SDK directory goes on the executable's drive. A junction works.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/startup-runtime.md.Tests:
startup_agility_sdk(relative paths, the ANSI conversion, the device loads the selected DLL, a second calldoes nothing, a child process selects for itself),
startup_agility_sdk_no_select_control(switch unset, must fail theloaded-DLL check) and
startup_agility_sdk_entry_{shim,permissive,xg}(the first device of a fresh process, througheach stand-in's own entry, must load the selected DLL). All skip (77) without
OFFSCREEN_AGILITY_620_DIRorDeveloper 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 withOFFSCREEN_AGILITY_620_DIRand skip on release and dev; thedevice-site family (
ctest -R "^(startup_agility|d3d12_xs_shim|startup_xg|xg_)", 25 tests) has 0 failures on allthree, with 5
xg_capability skips (and the 5 Agility skips on release and dev).🤖 Generated with Claude Code
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_sdktestsX2W_D3D12_AGILITY_SELECTEDand then sets it (src/startup_stubs/agility_sdk.h:100,:104).X2W_D3D12_AGILITYset never selects the runtime. A value already present in the parent environment has the same effect. Both returnS_FALSEat:100-103with no log line.:100and both callSetSDKVersion; the header comment (:4) says a call after the first device removes that device.A named object keyed by the process id (
CreateMutexWplusERROR_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, andSetSDKVersiongets a different path. PassingWC_NO_BEST_FIT_CHARSandlpUsedDefaultChar, and refusing when it is set, would make the log line true.3. The call sites are untested.
tests/startup_agility_sdk_check.cppcalls 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.dllfor them);D3D12Core.dllis first mapped as data, so reading its version runs none of its code (:57); withX2W_D3D12_AGILITYunset the function returns at:100and behaviour is unchanged.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T01:13:31Z.
Thanks, all three addressed in
8bdb9044andd2b178c1(main merged ine571e5ae).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 returnsS_FALSEand 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.
WideCharToMultiBytenow getsWC_NO_BEST_FIT_CHARSandlpUsedDefaultChar; 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 throughD3D12XboxCreateDevicewithout a parameter block, with one underX2W_D3D12_PERMISSIVE, and through an XG texture layout, and require the selectedD3D12Core.dll. The main check adds (d) the conversion and (e) a child process.Mutants, each applied alone (w10 build with
OFFSCREEN_AGILITY_620_DIR):d3d12_xs_shim.cpp)entry_shimonlyd3d12_xs_device.cpp)entry_permissiveonlyxg_xs.cpp)entry_xgonlystartup_agility_sdk(e)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) withoutOFFSCREEN_AGILITY_620_DIR.In a 90 s start-up run of the application on
e571e5ae, the log hasSetSDKVersion(620, "D3D12\") -> 0x00000000once andalready decided earlier in this processonce, from the later stand-in.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 beforeX2W_D3D12_DEBUGand the first device (src/startup_stubs/d3d12_xs_device.cpp:8419).src/startup_stubs/agility_sdk.h:140-151: a relativeX2W_D3D12_AGILITY(for exampleD3D12) shares no root with the executable's directory, soagility_relative_pathreturns empty and the log says "another drive?" (:159-161), even whenagility_sdk_versionfound the file (:142-143). CallingGetFullPathNameWon the value first would fix this. A log line saying that the path must be absolute would also work.