Skip to content

shader: opt the test binaries into an app-local Agility SDK runtime - #486

Open
naixue2233 wants to merge 3 commits into
Marvisak:mainfrom
naixue2233:shader-tests-agility-runtime
Open

naixue2233 wants to merge 3 commits into
Marvisak:mainfrom
naixue2233:shader-tests-agility-runtime

Conversation

@naixue2233

Copy link
Copy Markdown

What this does

The same opt-in as #463, for the test binaries. #463 covers apps/victory, so victory.exe gets shader model 6.6 on Windows 10 — but cargo test -p victory-shader still runs against the in-box runtime, which reports 6.5, and the seven emit::valu_tests keep panicking with neither hardware nor WARP SM 6.6 device available.

With this branch on Windows 10 19045 + RTX 3080:

before   62 passed; 7 failed
after    69 passed; 0 failed

The seven now execute on the GPU: v_med3 with NaN operands, v_fract near 1.0, v_sin/v_cos turn reduction, signed and unsigned bfe.

How

crates/victory-shader/build.rs:

  • looks for the runtime where the application puts it, target/<profile>/D3D12/D3D12Core.dll;
  • if it is there, mirrors it into target/<profile>/deps/D3D12/, because the loader resolves D3D12SDKPath next to the running module and test binaries run from deps;
  • and exports D3D12SDKVersion / D3D12SDKPath;
  • if it is not there, nothing happens at all — no exports, no copy, byte-for-byte the behaviour of today.

The symbols are exported with the linker's /EXPORT:...,DATA rather than a .def file, because .def is not on the asset-policy allowlist. cargo xtask policy reports 155 files ok with this branch.

Relationship to #463

Disjoint files — this only adds crates/victory-shader/{build.rs, src/agility.rs} and one module line in lib.rs, so the two can land in either order. Together they cover both binaries; #463 alone leaves the test suite red on Windows 10.

If you would rather have one implementation, the two agility.rs files are identical and could move to a shared build helper; I kept them separate to stay out of #463's diff.

Two things that cost me time

  • D3D12SDKPath must be exported as a const char*. As a byte array the loader dereferences the first eight bytes and the process dies in DllMain with 0xC0000142, before main runs.
  • D3D12SDKVersion must match the shipped DLL exactly. With 610 in the code and 620 on disk the loader silently falls back to the in-box runtime — no error, and the tests fail again with the same message. The constant here is 610 to match the runtime I tested; GPU: load an app-local D3D12 Agility SDK runtime when present #463 uses 614. Someone should pin one, probably by deriving it from the package version.

Also worth knowing: WARP stays below 6.6 even with the runtime present (no SM 6.6 warp device; skipped), so the software-adapter half of these tests remains skipped. Only hardware coverage improves.

Testing

Windows 10 Pro 22H2 (19045.0), RTX 3080 10 GB driver 32.0.16.1742, MSVC 14.44.35207, Windows SDK 10.0.26100.0, Rust 1.98.1, Microsoft.Direct3D.D3D12 1.610.5. Base d2a4bae.

  • cargo test -p victory-shader --lib → 69 passed, 0 failed (with target/debug/D3D12/D3D12Core.dll in place, 610).
  • Same command with the folder removed → 62 passed, 7 failed, i.e. unchanged from today.
  • cargo xtask policy → 155 files ok.

@DaviTostes

Copy link
Copy Markdown

Verified 4120d9e on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu, --test-threads=1): 43 passed, 0 failed, 1 ignored.

The Agility SDK path itself is not exercised here: target/release/D3D12/D3D12Core.dll does not exist, so build.rs returns early and emits no exports (which is the documented “no app-local runtime” behaviour). Wine's D3D12 also has no SM 6.6 device, so the seven VALU tests still skip as on main.

To validate the intended effect, copy NuGet Microsoft.Direct3D.D3D12 1.620.2's D3D12Core.dll to target/release/D3D12/ before building the tests — that is also what issue #473 reports on Windows 10.

@naixue2233

Copy link
Copy Markdown
Author

Thanks — the Wine run is worth more than my Windows check here, because it verifies the part I most wanted to keep: no DLL, build.rs returns before emitting anything, no exports, behaviour identical to main. That no-op path is the whole safety argument for the change.

Good catch on 1.620.2. I pushed 6179b10 bumping the constant to 620 and re-verified with that DLL: 69 passed, 0 failed on Windows 10 19045 + RTX 3080. Your instructions now work as written — copy Microsoft.Direct3D.D3D12 1.620.2's D3D12Core.dll into target/release/D3D12/ and the tests should pick it up.

The reason it matters is the one I put in the body: with 610 in the code and a 620 DLL on disk the loader silently falls back to the in-box runtime. No error, no warning — you just see the same seven failures and assume the patch did nothing. I only found it because I had cached a mismatched pair while testing.

Which raises a design question I would like your view on: should the constant be derived rather than typed? D3D12Core.dll carries its version in the resource section (1.620.2.0...), and the package ships d3d12.h with D3D12_SDK_VERSION — so build.rs could read either one and emit the constant, or fail loudly when the pair does not match. That would turn a silent fallback into a build error. Worth doing here, or better left to whoever consolidates this with #463?

On that: #463 uses 614. If both land, one of them has to bend, and I would rather it be mine.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@Zilumz1

Zilumz1 commented Nov 24, 2026

Copy link
Copy Markdown

Tested 6179b10 on Windows 10 Pro + AMD Radeon RX 580 2048SP (Polaris / GCN4), driver 31.0.21925.1001, Rust 1.98.1, MSVC 14.44, debug profile, --test-threads=1.

D3D12Core.dll from NuGet Microsoft.Direct3D.D3D12 1.620.2 (build/native/bin/x64/), copied to target/debug/D3D12/.

cargo test -p victory-shader --lib -- --test-threads=1

without the DLL (build.rs no-op)   62 passed; 7 failed   (neither hardware nor WARP SM 6.6 device available)
with the DLL                       69 passed; 0 failed

All seven emit::valu_tests run on the hardware device with the DLL present: no "no SM 6.6 hardware device" line. WARP still prints no SM 6.6 warp device; skipped, as the description says. build.rs mirrored the runtime into target/debug/deps/D3D12/ as expected.

So the opt-in also works on pre-RDNA AMD hardware: Polaris on the Adrenalin driver reports SM 6.6 through the Agility runtime.

Note: main now has an eighth GPU test (v_cmp_class_f16_matches_rdna2), which fails the same way on this machine. It isn't on this branch's base, so it isn't in these numbers.

AI-assisted (setup and write-up); the test runs above are real runs on my machine.

@EduBertozzi

Copy link
Copy Markdown
Contributor

Tested on Windows 10 + Pascal (GTX 1060 6GB): 76 passed / 13 failed → 89 passed / 0 failed.

Setup: Windows 10 Education 22H2 (19045), NVIDIA GeForce GTX 1060 6GB (Pascal), driver 582.66 (32.0.15.8266), i7-10700K, Rust 1.98.1, main 58fed37 + this branch merged.

Runtime: D3D12Core.dll from Microsoft.Direct3D.D3D12 1.620.2 (nuget.org, SHA-512 matches the catalog, Authenticode signed by Microsoft) in target\debug\D3D12\; build.rs mirrored it to target\debug\deps\D3D12\ as described.

cargo test -p victory-shader:

result
main (in-box runtime) 76 passed; 13 failed, all neither hardware nor WARP SM 6.6 device available
main + this branch + runtime 89 passed; 0 failed; 1 ignored

Notes:

  • The 13 valu_tests ran on the hardware adapter. So Pascal reports SM 6.6 with the Agility runtime, which as far as I can see nobody had confirmed here yet. WARP printed no SM 6.6 warp device; skipped for every test: the package does not ship WARP, so Windows 10's in-box WARP stays at SM 6.5.
  • victory-shader tests don't compile on main right now (victory-shader tests do not compile on main: the s_bitcmp test calls lowers() without rsrc2 #719). I applied the one-line fix from that issue (lowers(&words, 0)) locally for both runs. It is not part of this branch.

AI-assisted (Claude Code); the results are real runs on my machine.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 6179b10 on Windows 11, RTX 5070, MSVC: the workspace passes (195 outside victory-shader; victory-shader --lib with --test-threads=1: 69 passed). This machine has no target/<profile>/D3D12/D3D12Core.dll, so the opt-in stays off here, as designed. Windows 11's in-box runtime already reports SM 6.6. I couldn't test the Windows 10 path.

I read build.rs by hand first, since it runs at build time. It only copies a file already inside target/ and adds two /EXPORT linker args. Nothing is downloaded or executed.

  • Gating the exports on the DLL being present is important: with the exports but no DLL, the loader refuses to create any device (0x887e0003), as the module doc says. A checkout without the runtime is therefore unchanged.
  • #[cfg(test)] on the module keeps the symbols out of the library, so apps/victory (#463) can define its own copy without duplicate symbols.
  • Caveat: rustc-link-arg applies to every binary this package links, so the exports land in every test binary of the crate, which is the intent. Writing into target/<profile>/deps/D3D12/ from a build script is outside OUT_DIR, which cargo tolerates but doesn't track: a cargo clean -p victory-shader won't remove it. That's worth a line in the doc.
  • D3D12SDKVersion = 620 must match the DLL someone places there. A different package version fails device creation with a clear HRESULT rather than silently.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
… app-local Agility SDK runtime

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach for the Agility SDK opt-in — exporting D3D12SDKVersion/D3D12SDKPath from test binaries so d3d12.dll picks up an app-local D3D12Core.dll instead of the in-box one (Win10 caps at SM 6.6-less 6.5).

What I verified:

  • The two symbols are actually defined (agility.rs, #[cfg(test)] + #[no_mangle]), so the /EXPORT:...,DATA link args resolve. Gating to cfg(test) correctly avoids the duplicate-symbol clash with the app's own copy, as the comment notes.
  • D3D12SDKPath as &[u8; 9] = pointer to ".\D3D12\" matches what the loader expects (it dereferences the symbol to get the path).
  • build.rs early-returns on non-Windows, so macOS/Linux builds are unaffected; the OUT_DIR ancestor math (nth(3) → profile dir) is correct for target/<profile>/build/<pkg>-<hash>/out.
  • Test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 96 passed / 0 failed (the new module compiles in test config).

What I could NOT verify on macOS (Windows-only behavior):

  • Whether /EXPORT:D3D12SDKVersion,DATA via cargo:rustc-link-arg from a library build script actually lands on the final test-binary link (build-script link args apply to the package's own bin/test/example targets — test binaries of victory-shader qualify, but the app's own tests would need the same treatment or the symbols from apps/victory).
  • The D3D12SDKVersion = 620 value against the actual Agility SDK package header.
  • The DLL mirroring: rerun-if-changed on a possibly-nonexistent DLL, and whether .\D3D12\ resolves relative to the test exe (deps/) as the comment assumes.

Suggest a Windows run of the SM 6.6 shader tests with an app-local D3D12Core.dll to confirm before merge — the parts I can check are sound.

@wbnm77

wbnm77 commented Nov 24, 2026

Copy link
Copy Markdown

I tested 6179b10dedfffc7e759fc0ab6bdbf0989679359c and its merge base d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989 on Windows 10 Pro 22H2 build 19045, Ryzen 7 5700X, RTX 5060 Ti driver 621.24, and Rust 1.98.1 x64 MSVC. I staged the same Microsoft-signed Agility SDK 1.620.2 runtime for both builds before compiling.

cargo test --locked --offline -p victory-shader emit::valu_tests:: -- --nocapture --test-threads=1 returned 0 passed and 7 failed on the base, and 7 passed on the PR. Running each shader unit binary unfiltered gave 62 passed and 7 failed on the base, and 69 passed on the PR. The base failures reported no SM 6.6 device. Only the PR binary exports both D3D12 SDK symbols. Its VALU tests ran on hardware. WARP cases and four compiler-dependent differential cases skipped. These were synthetic tests. Codex (GPT-6) assisted with setup, test execution and this report.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
A write-watched texture was read and detiled whole whenever any of its
pages was written, without the hash check the unwatched path has: the
title writes next to its textures and rewrites what it wrote, so the
world frame detiled gigabytes of unchanged texels. And every list that
sampled a title texture recorded the copy of its whole staging buffer
into the host texture, unchanged or not, in every submission.

The watched path now hashes what it read and detiles only if the hash
changed (as xcl #486 does). Each detiling bumps the staging buffer's
generation; the host texture notes the generation it was copied from.
The copy moves from the list into the list's submission-time prelude,
after the list's refreshes, and is recorded only when the host texture
lacks the current generation: real state -> copy destination, copies,
then the state the list starts with. Unchanged textures are copied once.

Diagnostics log "texture uploads per frame: N copied X MB, N skipped
unchanged X MB" with the copy counters line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Calvix2k

Copy link
Copy Markdown
Contributor

Independent hardware verification on an AMD RDNA3 card, Windows 10 (not WARP): this branch gets the shader suite its SM 6.6 device.

  • Windows 10 22H2 (10.0.19045), Rust 1.98.1 MSVC, origin/main 13f91ca with the PR head merged in (merge was clean; no conflicts).
  • AMD Radeon RX 7800 XT, driver 32.0.32029.2010 (18.11.2026).
  • Agility runtime 1.620.2 (D3D12Core.dll/d3d12SDKLayers.dll) placed in target/debug/D3D12/; CARGO_TARGET_DIR=E:\cargo-target.
  • cargo test -p victory-shader --lib --locked:
    • main 13f91ca without the branch: 192 passed, 80 failed — every hardware suite ends in "no SM 6.6 device" (hardware and WARP both report 6.5 here).
    • with the branch: 270 passed, 0 failed, 3 ignored, 45 s. The valu_tests that used to panic on "neither hardware nor WARP SM 6.6 device" now execute on the GPU.

No test needed VICTORY_D3D12_WARP; this is the real adapter. That is the first AMD run I can see on this PR, and it matches the RTX 3080 numbers in the description. AI-assisted (DeepSeek V4.1), no game data.

@Calvix2k

Copy link
Copy Markdown
Contributor

Independent check of 2dafa90 on Windows 10, MSVC — the link-arg form publishes the selectors, and it also breaks the bench target once the runtime is staged. Both halves matter, so here is the whole picture.

Environment: Windows 10 22H2 (10.0.19045), Rust 1.98.1 MSVC host, link.exe 14.44.35207, Agility runtime 1.620.2 (D3D12Core.dll, d3d12SDKLayers.dll) in target\debug\D3D12\, separate CARGO_TARGET_DIR.

1. With no runtime staged, cargo build --locked -p victory-shader --benches links. build.rs returns before emitting the link args, so the target is a plain build. That answers the question I left open on the earlier head: the LNK2001 does not appear in the no-runtime configuration.

2. With the runtime staged, the same command fails:

error: linking with `link.exe` failed: exit code: 1120
  = note: ... "/EXPORT:D3D12SDKVersion,DATA" "/EXPORT:D3D12SDKPath,DATA"
  = note: LINK : error LNK2001: Nicht aufgelöstes externes Symbol "D3D12SDKPath".
          LINK : error LNK2001: Nicht aufgelöstes externes Symbol "D3D12SDKVersion".
          guard_runs-74faaca60d9b5feb.lib : fatal error LNK1120: 2 nicht aufgelöste Externe
error: could not compile `victory-shader` (bench "guard_runs") due to 1 previous error

The guard_runs bench does not reference the module, so the archive member is never pulled in and the two data symbols do not exist at link time. This is the hazard in the link-arg form, and it now hits a target this package owns. The unit-test binary is fine: dumpbin /exports on it shows both symbols.

1    0 005E66F0 D3D12SDKPath = D3D12SDKPath
2    1 005E6704 D3D12SDKVersion = D3D12SDKVersion

So the mechanism is right and the bench is the one target that breaks — and it breaks exactly where the runtime is staged, which is the setup the PR's own instructions ask for.

Minimal fix, if useful: have the bench reference the static, e.g. in benches/guard_runs.rs

// The Agility opt-in exports these; a bench links the archive member only if
// something in it refers to them.
#[allow(clippy::no_effect_underscore_binding)]
let _ = &victory_shader::agility::D3D12SDKVersion;

That keeps the link-arg form for every target, gives the bench the SM 6.6 runtime instead of the in-box one, and needs no cfg(test) split.

One documentation point: the missing rerun-if-changed on the staged DLL is deliberate and correct (watching a path that does not exist reruns the script every build), but it means staging the runtime after a build has no effect until cargo clean -p victory-shader. I hit that first: the build "succeeded" in 0.07 s and the binary had no exports. Worth a line next to the staging instructions.

AI-assisted (DeepSeek V4.1), no game data.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
lhnizdo added a commit to lhnizdo/VIctory that referenced this pull request Nov 26, 2026
Review of Marvisak#2878: exported without target\<profile>\D3D12\D3D12Core.dll,
the loader refused to make a device (0x887E0003) instead of using the
in-box runtime, which failed CI's root tests and quietly skipped every
other hardware test. build.rs now sets cfg(agility_runtime) only when the
runtime is there (as Marvisak#486 does for victory-shader), and the exports hang
off it. The comments no longer lean on code that is not in main.

RTX 2080, Windows 10 19045: with the runtime staged, victory-gpu 226
passed, 2 failed (the NVIDIA heap-cap pair, Marvisak#2461); without it, 224
passed, 4 failed, the same failures as main, and no 0x887E0003.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
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.