Skip to content

GPU: load an app-local D3D12 Agility SDK runtime when present - #463

Open
Shaun-Fong wants to merge 1 commit into
Marvisak:mainfrom
Shaun-Fong:fix/win10-agility-runtime
Open

Shaun-Fong wants to merge 1 commit into
Marvisak:mainfrom
Shaun-Fong:fix/win10-agility-runtime

Conversation

@Shaun-Fong

Copy link
Copy Markdown

Windows 10's inbox D3D12 runtime stops at shader model 6.5, while the shaders victory translates target 6.6 and bind through descriptor heaps. The title's root signatures (flags 0xc01) therefore fail to serialize, its renderer never finishes initializing, and it crashes during Game Init.

When target//D3D12/D3D12Core.dll exists, export the loader's D3D12SDKVersion (614) and D3D12SDKPath (.\D3D12) opt-in symbols so d3d12.dll loads that runtime instead of the system copy, and warn when the runtime is missing at run time. The build script enables the exports only when the file is present, so builds without it behave unchanged.

Verified on Windows 10 19045 with an i5-10400F and an RTX 2070 SUPER: the device reports shader model 6.6, the title's root signatures serialize, and its menus render and respond at 30 fps.

Windows 10's inbox D3D12 runtime stops at shader model 6.5, while the
shaders victory translates target 6.6 and bind through descriptor
heaps. The title's root signatures (flags 0xc01) therefore fail to
serialize, its renderer never finishes initializing, and it crashes
during Game Init.

When target/<profile>/D3D12/D3D12Core.dll exists, export the loader's
D3D12SDKVersion (614) and D3D12SDKPath (.\D3D12\) opt-in symbols so
d3d12.dll loads that runtime instead of the system copy, and warn when
the runtime is missing at run time. The build script enables the
exports only when the file is present, so builds without it behave
unchanged.

Verified on Windows 10 19045 with an i5-10400F and an RTX 2070 SUPER:
the device reports shader model 6.6, the title's root signatures
serialize, and its menus render and respond at 30 fps.
@DaviTostes

Copy link
Copy Markdown

The head f47a36e does not build its tests against current main (d2a4bae):

error[E0428]: the name `tests` is defined multiple times
  --> crates/victory-gpu/src/host.rs:1974:1
   |
252 | mod tests {          <- from main
...
1974 | mod tests {         <- this branch

The branch carries its own mod tests while main now already has one in host.rs (same class as #134/#135/#161/#175/#193). A rebase onto current main should fix it; until then cargo test -p victory-gpu fails at compile time, so the change cannot be verified.

No game data here, so the Agility SDK loading itself was not exercised either.

@upipibi upipibi mentioned this pull request Nov 24, 2026
mercuryVM pushed a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
Windows 10's in-box D3D12 runtime stops at shader model 6.5, so `Host::new`
returns `Err` and the seven `emit::valu_tests` panic on `assert!(ran > 0)`.
The application has an opt-in for this (Marvisak#463); the test binaries do not, so
`cargo test -p victory-shader` keeps running against the in-box runtime and
those seven tests keep failing on a Windows 10 host.

`build.rs` looks for the runtime where the application puts it,
`target/<profile>/D3D12/D3D12Core.dll`, mirrors it into
`target/<profile>/deps/D3D12/` because the loader resolves `D3D12SDKPath`
next to the running module and test binaries run from `deps`, then exports
`D3D12SDKVersion` and `D3D12SDKPath`. Both steps happen only when the file is
present, so a build without it behaves exactly as before.

The two symbols are exported with the linker's `/EXPORT:...,DATA` rather than
a `.def` file, because `.def` is not on the asset-policy allowlist.

Before: 62 passed; 7 failed
After:  69 passed; 0 failed

The version in `agility.rs` must match the shipped runtime's
`D3D12_SDK_VERSION`; with a mismatched pair the loader silently falls back to
the in-box runtime and the tests fail again with no warning.
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I merged f47a36e into ffe310e in an isolated checkout. The GPU library tests built and ran on Windows 10 (50 passed, one benchmark ignored).

I found an incremental build issue. After a build without the SDK, I copied D3D12Core.dll from Agility 1.614.1 with its original, older timestamp. The next cargo build reused victory.exe, and its PE export table still lacked both SDK symbols. Forcing the build script to rerun enabled them.

Watching the D3D12 directory lets Cargo detect the newer directory entry. I verified that copying the older DLL into a newly created directory or an existing empty directory enabled the exports. Removing the DLL from the directory disabled them on the next build. A second build with the DLL still in place did not relink.

The rebuilt CLI passed the startup SM 6.6 check with Agility 614 and WARP 1.0.22, and accepted one header-only synthetic DXBC container. With the same WARP package and no Agility exports, the CLI reported SM 6.5. The opt-in executable also printed its missing-runtime warning when copied without D3D12Core.dll.

AI-assisted. Verified with synthetic input and software D3D12.

Incremental patch on f47a36e
diff --git a/apps/victory/build.rs b/apps/victory/build.rs
index 80f65f2..5ed6983 100644
--- a/apps/victory/build.rs
+++ b/apps/victory/build.rs
@@ -38,8 +38,11 @@ fn main() {
     else {
         return;
     };
-    let runtime = profile_dir.join("D3D12").join("D3D12Core.dll");
-    println!("cargo:rerun-if-changed={}", runtime.display());
+    let runtime_dir = profile_dir.join("D3D12");
+    // A copied DLL can have an older timestamp than the last build. The
+    // directory changes when the DLL is added or removed.
+    println!("cargo:rerun-if-changed={}", runtime_dir.display());
+    let runtime = runtime_dir.join("D3D12Core.dll");
     if !runtime.is_file() {
         return;
     }

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: README.md). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

naixue2233 added a commit to naixue2233/VIctory that referenced this pull request Nov 25, 2026
Windows 10's in-box D3D12 runtime stops at shader model 6.5, so `Host::new`
returns `Err` and the seven `emit::valu_tests` panic on `assert!(ran > 0)`.
The application has an opt-in for this (Marvisak#463); the test binaries do not, so
`cargo test -p victory-shader` keeps running against the in-box runtime and
those seven tests keep failing on a Windows 10 host.

`build.rs` looks for the runtime where the application puts it,
`target/<profile>/D3D12/D3D12Core.dll`, mirrors it into
`target/<profile>/deps/D3D12/` because the loader resolves `D3D12SDKPath`
next to the running module and test binaries run from `deps`, then exports
`D3D12SDKVersion` and `D3D12SDKPath`. Both steps happen only when the file is
present, so a build without it behaves exactly as before.

The two symbols are exported with the linker's `/EXPORT:...,DATA` rather than
a `.def` file, because `.def` is not on the asset-policy allowlist.

Before: 62 passed; 7 failed
After:  69 passed; 0 failed

The version in `agility.rs` must match the shipped runtime's
`D3D12_SDK_VERSION`; with a mismatched pair the loader silently falls back to
the in-box runtime and the tests fail again with no warning.

Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
naixue2233 pushed a commit to naixue2233/VIctory that referenced this pull request Nov 25, 2026
`cargo:rustc-link-arg` applies to every target of the package, so asking for
`/EXPORT:D3D12SDKVersion,DATA` broke the `guard_runs` bench with LNK2001: the
bench links this crate without `cfg(test)`, so it defines neither symbol the
export names. `cargo:rustc-link-arg-tests` is not an option either — the SM 6.6
checks are library unit tests, and cargo rejects that instruction outright for a
package with no `#[test]` target ("The package victory-shader does not have a
test target").

Put the directive in the module that defines the symbols instead. The linker
reads `.drectve` sections out of object files as extra command-line options, so
a `#[used] #[link_section = ".drectve"]` static carries both `/EXPORT` options in
the one object that has the statics. A binary that does not compile this module
is never asked to export anything, which also keeps the selectors out of a
binary that defines its own copy (`apps/victory`, Marvisak#463) — two definitions in one
binary collide at link time.

`build.rs` now only reports whether the runtime is staged, with
`cfg(agility_runtime)`, and the symbols and the directive sit behind it:
exporting them without the DLL next to the executable makes the loader refuse to
create a device (`0x887e0003`), so a build that has not staged the runtime has
to stay opted out rather than export and fail.

`rerun-if-changed` on the runtime moves below the `is_file` check, which was the
other review point: watching a path that does not exist reran this script on
every build.

Verified on Windows 10 19045 + RTX 3080, runtime staged:

- `cargo build -p victory-shader --benches` links clean, and the bench binary
  exports nothing.
- `cargo test -p victory-shader valu_tests`: 28 passed, 0 failed, no
  "no SM 6.6 hardware device" skip line.
- `cargo build -p victory`: links clean, no duplicate selector symbols.
- The test binary's export table lists `D3D12SDKVersion` and `D3D12SDKPath`.
  Moving `target/<profile>/deps/D3D12/D3D12Core.dll` away afterwards makes
  device creation fail with "the host exe's D3D12 SDK version configuration is
  invalid", which is what shows the loader is reading those exports and not
  silently falling back to the in-box runtime.

Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
@reboot0000-cmd

Copy link
Copy Markdown

Two small additions to the verifications above, from a third host (Windows 10 IoT Enterprise LTSC 2021 19044.7846, RTX 4090, Agility 1.614.1 as staged, #463 + #486 cherry-picked with the same single README.md conflict the triage bot flags):

  1. The opt-in fails silently, and the failure looks like a GPU problem. Without target\<profile>\D3D12\D3D12Core.dll the exports are simply not emitted, the build succeeds, and the run dies with Error: the device supports SM 0x65 only — on a 4090, which reads as a driver or hardware limitation rather than a missing file. A cargo:warning= in the else branch (something like "no app-local D3D12 runtime found; the host will stay at SM 6.5") would turn a confusing half hour into a one-line answer. This is separate from @andrewpozdnakov7-jpg's timestamp finding, where the file is present but the export table goes stale: same silent outcome, different cause, and both are worth covering.
  2. Confirmed both halves of the loader's behaviour, which the incremental report leaves partly implicit: with the exports present and the DLL removed, the run refuses with the D3D12 SDK version configuration of the host exe is invalid rather than falling back to the in-box runtime; and putting System32\D3D12Core.dll (10.0.19041.7291 here) in the app-local slot gives the same refusal, because the export announces 614. So the opt-in is genuinely read and version-checked — it is not merely the presence of a DLL that changes the shader model.

The downstream value of merging this is a hardware picture nobody can publish without it: with the opt-in we completed a full translate --validate --pipelines over the title's shader archive on this machine in ~43 minutes with no device removal, which is posted on #1247. Without #463, that stage cannot be measured at all on a Windows 10 host. Counts and offsets only, per the asset policy.

@leonidaavenger

Copy link
Copy Markdown

Tested on Windows 10 with an RTX 4070 Ti: works. With this PR the title gets past the root-signature failure, into the world and through the opening cutscene to the Prologue, with no device removal.

Setup: Windows 10 22H2 (19045), RTX 4070 Ti 12 GB, driver 621.14, i9-12900K, 32 GB.

Build: this PR's apps/victory/build.rs and src/main.rs (f47a36e) applied on fxceless/victory-fork 310c6eb. It applies cleanly there; I left out the README hunk because the fork's README differs. I did not test it on this PR's own base. Diag build, Series X, VICTORY_RELAY=0 VICTORY_LATE_WAIT=0 VICTORY_D3D12_DRED=1.

Runtime: Microsoft.Direct3D.D3D12 1.614.1 from nuget.org (Authenticode: Microsoft Corporation). I put D3D12Core.dll and d3d12SDKLayers.dll in target\diag\D3D12\ before building.

  • The build printed opting the host D3D12 runtime into Agility SDK 614 (…\target\diag\D3D12\D3D12Core.dll).
  • dumpbin /exports lists D3D12SDKPath and D3D12SDKVersion.
  • At run time the process loaded D3D12Core.dll 1.614.1.0.20240716.3 from target\diag\D3D12\, beside the system d3d12.dll 10.0.19041.5794.

Without the opt-in (same tree): every root signature is refused with Unsupported bit-flag set (root signature flags c01), nothing draws, and the title crashes at about 3 s.

With this PR:

Two things worth knowing:

  1. Changing the runtime version invalidates the host pipeline library. Under 1.614, the library saved under 1.620.2 failed to load (host pipeline library rejected; starting an empty one … 0x80070057). The first run after switching therefore rebuilds every pipeline. For a few minutes the world flickers grey or black (dropped 1282.0/frame without a host pipeline: being made), then fills in. victory handles this correctly, but a README line would save people from thinking it's broken.
  2. 1.614.1 looked better here than 1.620.2. On the same tree, an earlier run with D3D12SDKVersion = 620 and 1.620.2 showed blocky corruption and missing geometry in the cutscene. With 1.614.1 the cutscene rendered cleanly. That is one run each and the shots aren't frame-matched, so treat it as a hint, not a result. It does support pinning 614 as this PR does.

Note: Nsight Aftermath's Global mode was off for these runs; with it on, the world load hangs here (see #71). No game files or captures attached.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine, read the logs, and drafted this comment.

@walterwallaceson

Copy link
Copy Markdown

With a runtime in target/<profile>/D3D12, cargo test -p victory fails to link: rustc-link-arg also applies the two /EXPORTs to the integration tests, which don't define the symbols. rustc-link-arg-bins fixes it.

Reproduced on main 63bcca4 + this PR (f47a36e, merged), Windows 10 22H2 (19045), MSVC, with D3D12Core.dll in target/debug/D3D12:

LINK : error LNK2001: unresolved external symbol D3D12SDKPath
LINK : error LNK2001: unresolved external symbol D3D12SDKVersion
... census-....lib : fatal error LNK1120: 2 unresolved externals
error: could not compile `victory` (test "translate") due to 1 previous error
error: could not compile `victory` (test "census") due to 1 previous error
error: could not compile `victory` (test "census_unreadable") due to 1 previous error

Without a runtime, the exports aren't emitted and the tests build. That's probably why CI and the earlier test runs here didn't hit it.

The change in apps/victory/build.rs:

-    println!("cargo:rustc-link-arg=/EXPORT:D3D12SDKVersion");
-    println!("cargo:rustc-link-arg=/EXPORT:D3D12SDKPath");
+    println!("cargo:rustc-link-arg-bins=/EXPORT:D3D12SDKVersion");
+    println!("cargo:rustc-link-arg-bins=/EXPORT:D3D12SDKPath");

With it, cargo test -p victory --no-run links all four test binaries, and the victory binary still loads the app-local runtime. I've used this change for about 25 runs on an RTX 3070 under Windows 10, where the title needs the Agility runtime to start. If the package ever gains another binary, rustc-link-arg-bin=victory=... would scope it to just the one that defines the symbols.

I'm testing with Claude's help, and Claude drafted this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants