GPU: load an optional D3D12 Agility SDK #3033

Open
github-bot wants to merge 2 commits from github-bot/gh-3033 into main AGit
Owner

@⁠Auroraooy on GitHub · 2026-11-26 04:06 UTC · original
Auroraooy:feat/agility-sdk → main · +378 −22 · 9 files · 2 commits · open

Windows 10's inbox D3D12Core.dll stops at Shader Model 6.5, even on GPUs and drivers that support SM 6.6. This adds an optional app-local Agility SDK loader so a Windows 10 / Turing machine can provide SM 6.6 without changing the OS.

Search order for D3D12Core.dll:

  1. %VICTORY_D3D12_DIR% (explicit; a bad path is reported instead of silently ignored),
  2. <exe_dir>\D3D12,
  3. <exe_dir>,
  4. %LOCALAPPDATA%\Victory\D3D12.

When a valid SDK is found, ID3D12SDKConfiguration1::CreateDeviceFactory creates the device factory and ApplyToGlobalState makes free functions dispatch through the app-local runtime. Host now creates its device and debug/DRED interfaces through this loader; without an SDK it falls back to inbox D3D12CreateDevice / D3D12GetDebugInterface.

Validation:

  • Rust 1.98.1, CARGO_BUILD_JOBS=18 (2 cores left for the system).
  • cargo build -p victory-gpu: clean.
  • cargo test -p victory-gpu --lib agility::tests -- --test-threads=18: 3 passed, including a real SDK check that reads D3D12SDKVersion from Microsoft's Microsoft.Direct3D.D3D12 1.620.2 D3D12Core.dll.
  • No game files were used.

This does not by itself make wave64 shader emulation or GFX10 translation work; it only fixes the D3D12 runtime/SM 6.6 detection gap.

AI use: AI-assisted (WorkBuddy) for drafting the patch and tests; build/test results are from real local runs.

**@⁠Auroraooy** on GitHub · 2026-11-26 04:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033) `Auroraooy:feat/agility-sdk` → `main` · +378 −22 · 9 files · 2 commits · open Windows 10's inbox `D3D12Core.dll` stops at Shader Model 6.5, even on GPUs and drivers that support SM 6.6. This adds an optional app-local Agility SDK loader so a Windows 10 / Turing machine can provide SM 6.6 without changing the OS. Search order for `D3D12Core.dll`: 1. `%VICTORY_D3D12_DIR%` (explicit; a bad path is reported instead of silently ignored), 2. `<exe_dir>\D3D12`, 3. `<exe_dir>`, 4. `%LOCALAPPDATA%\Victory\D3D12`. When a valid SDK is found, `ID3D12SDKConfiguration1::CreateDeviceFactory` creates the device factory and `ApplyToGlobalState` makes free functions dispatch through the app-local runtime. `Host` now creates its device and debug/DRED interfaces through this loader; without an SDK it falls back to inbox `D3D12CreateDevice` / `D3D12GetDebugInterface`. Validation: - Rust 1.98.1, `CARGO_BUILD_JOBS=18` (2 cores left for the system). - `cargo build -p victory-gpu`: clean. - `cargo test -p victory-gpu --lib agility::tests -- --test-threads=18`: 3 passed, including a real SDK check that reads `D3D12SDKVersion` from Microsoft's `Microsoft.Direct3D.D3D12` 1.620.2 `D3D12Core.dll`. - No game files were used. This does not by itself make wave64 shader emulation or GFX10 translation work; it only fixes the D3D12 runtime/SM 6.6 detection gap. AI use: AI-assisted (WorkBuddy) for drafting the patch and tests; build/test results are from real local runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:02 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:15 UTC · original · edited 2026-11-26 07:20 UTC

Automated triage for the maintainers.

Needs work; needs the maintainer's decision. Thanks for rebasing; it now merges cleanly. The new head adds a victory-agility crate (workspace Cargo.toml, Cargo.lock, and dependencies in victory-gpu and victory-shader). It also changes how the host D3D12 runtime is chosen: D3D12Core.dll is now picked up from VICTORY_D3D12_DIR, <exe_dir>, <exe_dir>\D3D12 or %LOCALAPPDATA%\Victory\D3D12. That means VIctory loads and runs a native DLL from user-writable folders, so a maintainer has to decide whether to take this, not triage. It also affects every user, not only Windows 10 machines without SM 6.6, whenever such a folder exists.

Before that review, CI must pass. cargo clippy ... -D warnings fails in crates/victory-agility/src/lib.rs resolve_get_interface, as noted in the comments: use c"D3D12GetInterface" instead of the b"...\0" literal, and annotate the transmute types. It would also help to explain why the inbox runtime's SM 6.5 cap needs fixing in VIctory itself rather than by updating Windows.

CI: failing (check, clippy).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#issuecomment-7182437938) · edited 2026-11-26 07:20 UTC <!-- victory-triage v1 head=7e2e129411385420023dcac6f304add97a1d0cd9 verdict=needs-work at=2026-11-26T07:20:14Z --> Automated triage for the maintainers. **Needs work; needs the maintainer's decision.** Thanks for rebasing; it now merges cleanly. The new head adds a `victory-agility` crate (workspace `Cargo.toml`, `Cargo.lock`, and dependencies in `victory-gpu` and `victory-shader`). It also changes how the host D3D12 runtime is chosen: `D3D12Core.dll` is now picked up from `VICTORY_D3D12_DIR`, `<exe_dir>`, `<exe_dir>\D3D12` or `%LOCALAPPDATA%\Victory\D3D12`. That means VIctory loads and runs a native DLL from user-writable folders, so a maintainer has to decide whether to take this, not triage. It also affects every user, not only Windows 10 machines without SM 6.6, whenever such a folder exists. Before that review, CI must pass. `cargo clippy ... -D warnings` fails in `crates/victory-agility/src/lib.rs` `resolve_get_interface`, as noted in the comments: use `c"D3D12GetInterface"` instead of the `b"...\0"` literal, and annotate the `transmute` types. It would also help to explain why the inbox runtime's SM 6.5 cap needs fixing in VIctory itself rather than by updating Windows. CI: failing (`check`, clippy). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Auroraooy on GitHub · 2026-11-26 04:16 UTC · original

Update: the loader is now a shared victory-agility crate, used by both victory-gpu and victory-shader's D3D12 test host. This means VICTORY_D3D12_DIR also applies to the shader/host SM 6.6 checks, not only the runtime device.

Validation on RTX 2080 Ti (Turing, SM 6.5 hardware) with Microsoft Microsoft.Direct3D.D3D12 1.620.2:

cargo check -p victory-gpu -p victory-shader --tests   # clean, 18 threads
cargo test -p victory-agility --lib                    # 3 passed; 0 failed
cargo test -p victory-shader --lib emit::semantics_tests::hosts_that_do_not_fuse_are_named -- --exact --nocapture
  hardware adapter fuses FMad: true
  test result: ok. 1 passed; 0 failed

The last line confirms Host::new(false) now creates a hardware D3D12 device through the app-local Agility SDK on Windows 10; previously this machine reported SM 0x65 only. No game files were used.

**@⁠Auroraooy** on GitHub · 2026-11-26 04:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#issuecomment-7182457813) Update: the loader is now a shared `victory-agility` crate, used by both `victory-gpu` and `victory-shader`'s D3D12 test host. This means `VICTORY_D3D12_DIR` also applies to the shader/host SM 6.6 checks, not only the runtime device. Validation on RTX 2080 Ti (Turing, SM 6.5 hardware) with Microsoft `Microsoft.Direct3D.D3D12` 1.620.2: ```text cargo check -p victory-gpu -p victory-shader --tests # clean, 18 threads cargo test -p victory-agility --lib # 3 passed; 0 failed cargo test -p victory-shader --lib emit::semantics_tests::hosts_that_do_not_fuse_are_named -- --exact --nocapture hardware adapter fuses FMad: true test result: ok. 1 passed; 0 failed ``` The last line confirms `Host::new(false)` now creates a hardware D3D12 device through the app-local Agility SDK on Windows 10; previously this machine reported `SM 0x65 only`. No game files were used.
Author
Owner

@⁠Auroraooy on GitHub · 2026-11-26 05:24 UTC · original

Rebased onto current main (63bcca4) and squashed to one commit (7e2e129) after the automated triage marked this needs-rebase. The four touchpoints that conflicted (README, victory-gpu/src/host.rs, victory-shader's host, workspace Cargo.toml) were re-applied on top of the new code, including the shader-host changes from #244. Verified with 18 build threads on the machine from the report (RTX 2080 Ti, Windows 10): cargo check -p victory-gpu -p victory-shader --tests clean, and cargo test -p victory-agility --lib 3 passed, including the real Microsoft Agility SDK 1.620.2 D3D12Core.dll version-parse test.

AI use: WorkBuddy agent re-applied the patch and ran the checks; the account owner reviewed the result.

**@⁠Auroraooy** on GitHub · 2026-11-26 05:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#issuecomment-7183454781) Rebased onto current `main` (`63bcca4`) and squashed to one commit (`7e2e129`) after the automated triage marked this needs-rebase. The four touchpoints that conflicted (README, `victory-gpu/src/host.rs`, `victory-shader`'s host, workspace Cargo.toml) were re-applied on top of the new code, including the shader-host changes from #244. Verified with 18 build threads on the machine from the report (RTX 2080 Ti, Windows 10): `cargo check -p victory-gpu -p victory-shader --tests` clean, and `cargo test -p victory-agility --lib` 3 passed, including the real Microsoft Agility SDK 1.620.2 `D3D12Core.dll` version-parse test. AI use: WorkBuddy agent re-applied the patch and ran the checks; the account owner reviewed the result.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 06:19 UTC · original

Checked the CI failure on 7e2e1294 — cargo clippy --workspace --all-targets --locked -- -D warnings failed on two lints in crates/victory-agility/src/lib.rs:

  • Line 172 (clippy::manual_c_str_literals): b"D3D12GetInterface\0".as_ptr() → c"D3D12GetInterface".as_ptr().cast()
  • Line 175 (clippy::missing_transmute_annotations): replace _ with the explicit source FARPROC fn type (unsafe extern "system" fn() -> isize).

Happy to re-review once CI is green.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 06:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#issuecomment-7184321125) Checked the CI failure on `7e2e1294` — `cargo clippy --workspace --all-targets --locked -- -D warnings` failed on two lints in `crates/victory-agility/src/lib.rs`: - Line 172 (`clippy::manual_c_str_literals`): `b"D3D12GetInterface\0".as_ptr()` → `c"D3D12GetInterface".as_ptr().cast()` - Line 175 (`clippy::missing_transmute_annotations`): replace `_` with the explicit source `FARPROC` fn type (`unsafe extern "system" fn() -> isize`). Happy to re-review once CI is green.
- clippy::manual_c_str_literals (lib.rs:172)
- clippy::missing_transmute_annotations (lib.rs:175)

Verified locally: cargo clippy -p victory-agility --all-targets --locked -- -D warnings clean; cargo test -p victory-agility --lib 3 passed.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 04:15 UTC · original · requested changes

Several issues to address on 2b9e580b:

  1. Merge conflict & Clippy failure in crates/victory-gpu/src/host.rs:

    • The branch currently conflicts with origin/main at host.rs:198 (where main queries D3D12_FEATURE_D3D12_OPTIONS2 for depth_bounds_supported); please rebase and preserve that query on the created device.
    • The nested if dred_on() { if let Ok(dred) = ... } (host.rs:176-182) will trip clippy::collapsible_if under CI's -D warnings (collapse with if dred_on() && let Ok(dred) = ...).
  2. No inbox fallback once State::Loaded is cached (crates/victory-gpu/src/agility.rs:244-252, host.rs:187-196):

    • Once CreateDeviceFactory succeeds, agility::create_device propagates factory.CreateDevice(...)? with no fallback to inbox D3D12CreateDevice. If the selected D3D12Core.dll fails to create a device on the host driver or WARP adapter, host() caches None for the lifetime of the process and disables GPU execution even when inbox D3D12 would succeed.
  3. Process-wide state mutation & ANSI/UTF-8 path mismatch (agility.rs:141-150, agility.rs:191-193):

    • Calling factory.ApplyToGlobalState() mutates process-wide D3D12 state (affecting independent D3D12CreateDevice callers like victory-shader/src/emit/host.rs:110 and preventing clean fallback to inbox D3D12CreateDevice). Keeping device creation scoped to the factory avoids leaking optional SDK state globally.
    • format_sdk_path passes UTF-8 bytes to CreateDeviceFactory's PCSTR (which interprets the string in the process ANSI code page unless a UTF-8 ACP manifest is active), whereas probe_dir opens D3D12Core.dll via wide Win32 paths. Non-ASCII directories (e.g. C:\Users\José\D3D12) can pass probe_dir and fail to resolve in CreateDeviceFactory.
  4. PE export bounds & implicit candidate fallback (agility.rs:70-96, agility.rs:112-137, agility.rs:165):

    • rva_to_offset falls back to Some(rva as usize) when an RVA lies outside every section (treating an unmapped RVA as a file offset) and does not check delta + 4 <= section.file_size, allowing a 4-byte read across a section boundary.
    • For implicit directories (<exe_dir>\D3D12, <exe_dir>, %LOCALAPPDATA%\Victory\D3D12), resolve_dir stops at the first candidate with a parseable D3D12SDKVersion export — if that candidate fails CreateDeviceFactory, remaining implicit candidates are skipped.
    • Minor: in resolve_get_interface, if GetProcAddress fails after LoadLibraryExW, releasing the loaded module handle with FreeLibrary avoids leaking the extra d3d12.dll reference.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 04:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#pullrequestreview-6068466078) · **requested changes** Several issues to address on `2b9e580b`: 1. **Merge conflict & Clippy failure in `crates/victory-gpu/src/host.rs`**: - The branch currently conflicts with `origin/main` at `host.rs:198` (where `main` queries `D3D12_FEATURE_D3D12_OPTIONS2` for `depth_bounds_supported`); please rebase and preserve that query on the created device. - The nested `if dred_on() { if let Ok(dred) = ... }` (`host.rs:176-182`) will trip `clippy::collapsible_if` under CI's `-D warnings` (collapse with `if dred_on() && let Ok(dred) = ...`). 2. **No inbox fallback once `State::Loaded` is cached (`crates/victory-gpu/src/agility.rs:244-252`, `host.rs:187-196`)**: - Once `CreateDeviceFactory` succeeds, `agility::create_device` propagates `factory.CreateDevice(...)?` with no fallback to inbox `D3D12CreateDevice`. If the selected `D3D12Core.dll` fails to create a device on the host driver or WARP adapter, `host()` caches `None` for the lifetime of the process and disables GPU execution even when inbox D3D12 would succeed. 3. **Process-wide state mutation & ANSI/UTF-8 path mismatch (`agility.rs:141-150`, `agility.rs:191-193`)**: - Calling `factory.ApplyToGlobalState()` mutates process-wide D3D12 state (affecting independent `D3D12CreateDevice` callers like `victory-shader/src/emit/host.rs:110` and preventing clean fallback to inbox `D3D12CreateDevice`). Keeping device creation scoped to the factory avoids leaking optional SDK state globally. - `format_sdk_path` passes UTF-8 bytes to `CreateDeviceFactory`'s `PCSTR` (which interprets the string in the process ANSI code page unless a UTF-8 ACP manifest is active), whereas `probe_dir` opens `D3D12Core.dll` via wide Win32 paths. Non-ASCII directories (e.g. `C:\Users\José\D3D12`) can pass `probe_dir` and fail to resolve in `CreateDeviceFactory`. 4. **PE export bounds & implicit candidate fallback (`agility.rs:70-96`, `agility.rs:112-137`, `agility.rs:165`)**: - `rva_to_offset` falls back to `Some(rva as usize)` when an RVA lies outside every section (treating an unmapped RVA as a file offset) and does not check `delta + 4 <= section.file_size`, allowing a 4-byte read across a section boundary. - For implicit directories (`<exe_dir>\D3D12`, `<exe_dir>`, `%LOCALAPPDATA%\Victory\D3D12`), `resolve_dir` stops at the first candidate with a parseable `D3D12SDKVersion` export — if that candidate fails `CreateDeviceFactory`, remaining implicit candidates are skipped. - Minor: in `resolve_get_interface`, if `GetProcAddress` fails after `LoadLibraryExW`, releasing the loaded module handle with `FreeLibrary` avoids leaking the extra `d3d12.dll` reference.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 04:40 UTC · original · requested changes

Extracting crates/victory-agility and cleaning up the dred_on() if let in host.rs are nice improvements, but several items from the previous review still remain on 6170e8ee:

  1. Merge conflict (crates/victory-gpu/src/host.rs): The branch is still behind origin/main (842b0cb7 / 63bcca43) and currently reports mergeable: dirty around create() / depth_bounds_supported. Please rebase onto main.
  2. No inbox fallback when factory.CreateDevice fails (crates/victory-agility/src/lib.rs:247): create_device still returns factory.CreateDevice(...)? directly without falling back to D3D12CreateDevice, so an incompatible Agility runtime or unsupported adapter path will fail device creation instead of falling back to inbox D3D12 as documented.
  3. Unconditional ApplyToGlobalState() (crates/victory-agility/src/lib.rs:197): Calling ApplyToGlobalState() mutates process-wide D3D12 state globally for all subsequent callers (including tests and victory-shader WARP/host tests).
  4. ANSI vs UTF-8 path encoding (crates/victory-agility/src/lib.rs:146-155): format_sdk_path encodes Rust UTF-8 into a CString and passes it as PCSTR to CreateDeviceFactory, which interprets it using the system ANSI code page rather than UTF-8 on non-UTF-8 Windows locales.
  5. PE RVA mapping & implicit directory fallback (crates/victory-agility/src/lib.rs:72-104, 129-137):
    • rva_to_offset still returns Some(rva as usize) when no section contains rva (line 84), and line 77 only checks delta >= section.file_size without checking that all 4 bytes (delta..delta + 4) lie within section.file_size.
    • resolve_dir returns on the first parseable D3D12Core.dll (line 130); if create_factory then fails for that candidate, implicit fallback does not try remaining candidate directories.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#pullrequestreview-6068637196) · **requested changes** Extracting `crates/victory-agility` and cleaning up the `dred_on()` `if let` in `host.rs` are nice improvements, but several items from the previous review still remain on `6170e8ee`: 1. **Merge conflict (`crates/victory-gpu/src/host.rs`)**: The branch is still behind `origin/main` (`842b0cb7` / `63bcca43`) and currently reports `mergeable: dirty` around `create()` / `depth_bounds_supported`. Please rebase onto `main`. 2. **No inbox fallback when `factory.CreateDevice` fails (`crates/victory-agility/src/lib.rs:247`)**: `create_device` still returns `factory.CreateDevice(...)?` directly without falling back to `D3D12CreateDevice`, so an incompatible Agility runtime or unsupported adapter path will fail device creation instead of falling back to inbox D3D12 as documented. 3. **Unconditional `ApplyToGlobalState()` (`crates/victory-agility/src/lib.rs:197`)**: Calling `ApplyToGlobalState()` mutates process-wide D3D12 state globally for all subsequent callers (including tests and `victory-shader` WARP/host tests). 4. **ANSI vs UTF-8 path encoding (`crates/victory-agility/src/lib.rs:146-155`)**: `format_sdk_path` encodes Rust UTF-8 into a `CString` and passes it as `PCSTR` to `CreateDeviceFactory`, which interprets it using the system ANSI code page rather than UTF-8 on non-UTF-8 Windows locales. 5. **PE RVA mapping & implicit directory fallback (`crates/victory-agility/src/lib.rs:72-104`, `129-137`)**: - `rva_to_offset` still returns `Some(rva as usize)` when no section contains `rva` (line 84), and line 77 only checks `delta >= section.file_size` without checking that all 4 bytes (`delta..delta + 4`) lie within `section.file_size`. - `resolve_dir` returns on the first parseable `D3D12Core.dll` (line 130); if `create_factory` then fails for that candidate, implicit fallback does not try remaining candidate directories.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 04:42 UTC · original · approved these changes

LGTM — correct SDK mechanics: D3D12SDKVersion export validated via PE parse before activation, ApplyToGlobalState+ALLOW_RETURNING_EXISTING covers late direct D3D12CreateDevice callers, and configuration_interface goes through the factory so debug interfaces match the device's runtime. Explicit-dir failures reported not skipped; clean inbox fallback everywhere.

**@⁠kotekompotek** on GitHub · 2026-11-26 04:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#pullrequestreview-6068650543) · **approved these changes** LGTM — correct SDK mechanics: D3D12SDKVersion export validated via PE parse before activation, ApplyToGlobalState+ALLOW_RETURNING_EXISTING covers late direct D3D12CreateDevice callers, and configuration_interface goes through the factory so debug interfaces match the device's runtime. Explicit-dir failures reported not skipped; clean inbox fallback everywhere.
Author
Owner

@⁠Auroraooy on GitHub · 2026-11-26 11:51 UTC · original

Thanks @⁠fuzeofficlal for the precise report — both lints fixed in 18db812 (c-string literal + explicit FARPROC transmute annotation). Verified locally: cargo clippy -p victory-agility --all-targets --locked -- -D warnings clean, cargo test -p victory-agility --lib 3 passed. CI should re-run on the new head.

**@⁠Auroraooy** on GitHub · 2026-11-26 11:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3033#issuecomment-7191261111) Thanks @⁠fuzeofficlal for the precise report — both lints fixed in `18db812` (c-string literal + explicit `FARPROC` transmute annotation). Verified locally: `cargo clippy -p victory-agility --all-targets --locked -- -D warnings` clean, `cargo test -p victory-agility --lib` 3 passed. CI should re-run on the new head.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3033/head:github-bot/gh-3033'
git switch 'github-bot/gh-3033'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3033'
git switch 'github-bot/gh-3033'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3033'
git switch 'github-bot/gh-3033'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3033'
git switch 'main'
git merge --squash 'github-bot/gh-3033'
git switch 'main'
git merge --ff-only 'github-bot/gh-3033'
git switch 'main'
git merge 'github-bot/gh-3033'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3033
No description provided.