Agility SDK: delay-load d3d12.dll, writable D3D12SDKVersion, fall back to the OS runtime (part a of #77) #139

Manually merged
github merged 2 commits from github-bot/gh-139 into gh-pr/139/base 2026-12-06 01:25:39 +00:00 AGit
Owner

@⁠kadiratesdev on GitHub · 2026-12-05 19:31 UTC · original
kadiratesdev:pr/split-a-agility-loader → main · +130 −2 · 5 files · 2 commits · merged 2026-12-06 00:07 UTC

This is part (a) of the split @⁠gamingwithhomie asked for on #77. Part (b) is already up as #126. Part (c) (stack-copy rewrite and watchdog tools) follows as a separate PR. Based on the same main as #126 (334be94). Independent of (b) and (c), except that it keeps main's existing /DELAYLOAD:winmm.dll (from #87) next to the new /DELAYLOAD:d3d12.dll.

Do not merge before the built-binary startup smoke test. That run is in progress on an RTX 3080 Ti / Windows 11 machine; I will post the full results as a comment on this PR. Early results from a scratch copy of bin (real CNF-Larp\bin was not overwritten) are already in, but the checklist is not finished.

What is in it

  • build.rs delay-loads d3d12.dll so Windows reads D3D12SDKVersion on first use, after agility::choose() has run at the start of main.
  • D3D12SDKVersion is an AtomicU32 (same in-memory layout as the previous u32 constant, but writable).
  • agility::choose():
    • LARP_AGILITY=0: asks for Windows' own runtime (the version System32's D3D12Core.dll exports; 4 if that cannot be read).
    • no D3D12\D3D12Core.dll beside the exe: same OS fallback, instead of a loader that makes no device.
    • a D3D12Core.dll of another Agility version: asks for that version, instead of 0x887E0003.
    • a non-Agility file (e.g. System32's 10.0.x file copied into D3D12\): OS runtime, with a log line saying the file is no Agility SDK runtime.
    • a normal 1.620 file: leaves the export at 620 and prints nothing.
  • Docs: LARP_AGILITY in environment-variables.md, and a short note under device-removed troubleshooting. The LARP_AGILITY=0 bisect step is not in #126, so it lives here.

Default behaviour of a normal start with a matching bin\D3D12\D3D12Core.dll is unchanged, apart from d3d12.dll loading on first use rather than at process start.

Testing

  • Cross-built for x86_64-pc-windows-msvc. Same warning set as current main (the extra larp-hle unreachable-pattern / renamed warnings are already on main after the first-person merge).

  • cargo test --release --workspace under Wine: everything passes except the one test that also fails on main: larp-game prompts::font::...within_its_advance (needs a host font Wine lacks). The three new agility unit tests pass.

  • Built-binary startup smoke test: in progress, not finished. Scratch folder CNF-Larp\smoke\, same LARP_CACHE_DIR / LARP_DATA_DIR as the real install, new exe names so the real bin\larp.exe / larp-tr.exe were not touched. So far:

    Case Status
    1. Normal start (1.620 D3D12Core.dll) Seen: no D3D12 runtime: line, device15=true, D3D12Core.dll loaded from the scratch bin\D3D12. Device created, presents at 60 fps.
    2. Missing D3D12\ Seen: D3D12 runtime: asking Windows for SDK version … (no D3D12\D3D12Core.dll beside larp.exe), D3D12Core.dll loaded from C:\Windows\SYSTEM32. Device created, presents at 60 fps.
    3. Mismatched Agility version (1.614.1 in D3D12\) Not run yet. Expect a SDK version 614 line and a normal start. Main's exe should fail with 0x887E0003.
    4. Non-Agility file in D3D12\ (System32's 10.0.x) Not run yet. Expect "is no Agility SDK runtime" and the OS runtime.
    5. LARP_AGILITY=0 with a normal 1.620 folder Not run yet. Expect the OS version in the log and System32's D3D12Core.dll loaded.
    6. Non-GPU commands larp-a.exe config and larp-a.exe nv-profile both exited 0.

    I will also run main's exe on cases 2 and 3 for comparison, then post the finished table here.

**@⁠kadiratesdev** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/gamingwithhomie/larp/pull/139) `kadiratesdev:pr/split-a-agility-loader` → `main` · +130 −2 · 5 files · 2 commits · merged 2026-12-06 00:07 UTC This is part (a) of the split @⁠gamingwithhomie asked for on #77. Part (b) is already up as #126. Part (c) (stack-copy rewrite and watchdog tools) follows as a separate PR. Based on the same `main` as #126 (334be94). Independent of (b) and (c), except that it keeps main's existing `/DELAYLOAD:winmm.dll` (from #87) next to the new `/DELAYLOAD:d3d12.dll`. **Do not merge before the built-binary startup smoke test.** That run is in progress on an RTX 3080 Ti / Windows 11 machine; I will post the full results as a comment on this PR. Early results from a scratch copy of `bin` (real `CNF-Larp\bin` was not overwritten) are already in, but the checklist is not finished. ## What is in it - `build.rs` delay-loads `d3d12.dll` so Windows reads `D3D12SDKVersion` on first use, after `agility::choose()` has run at the start of `main`. - `D3D12SDKVersion` is an `AtomicU32` (same in-memory layout as the previous `u32` constant, but writable). - `agility::choose()`: - `LARP_AGILITY=0`: asks for Windows' own runtime (the version System32's `D3D12Core.dll` exports; 4 if that cannot be read). - no `D3D12\D3D12Core.dll` beside the exe: same OS fallback, instead of a loader that makes no device. - a `D3D12Core.dll` of another Agility version: asks for that version, instead of `0x887E0003`. - a non-Agility file (e.g. System32's 10.0.x file copied into `D3D12\`): OS runtime, with a log line saying the file is no Agility SDK runtime. - a normal 1.620 file: leaves the export at 620 and prints nothing. - Docs: `LARP_AGILITY` in `environment-variables.md`, and a short note under device-removed troubleshooting. The `LARP_AGILITY=0` bisect step is not in #126, so it lives here. Default behaviour of a normal start with a matching `bin\D3D12\D3D12Core.dll` is unchanged, apart from `d3d12.dll` loading on first use rather than at process start. ## Testing - Cross-built for `x86_64-pc-windows-msvc`. Same warning set as current `main` (the extra `larp-hle` unreachable-pattern / `renamed` warnings are already on `main` after the first-person merge). - `cargo test --release --workspace` under Wine: everything passes except the one test that also fails on `main`: `larp-game prompts::font::...within_its_advance` (needs a host font Wine lacks). The three new `agility` unit tests pass. - **Built-binary startup smoke test: in progress, not finished.** Scratch folder `CNF-Larp\smoke\`, same `LARP_CACHE_DIR` / `LARP_DATA_DIR` as the real install, new exe names so the real `bin\larp.exe` / `larp-tr.exe` were not touched. So far: | Case | Status | |---|---| | 1. Normal start (1.620 `D3D12Core.dll`) | Seen: no `D3D12 runtime:` line, `device15=true`, `D3D12Core.dll` loaded from the scratch `bin\D3D12`. Device created, presents at 60 fps. | | 2. Missing `D3D12\` | Seen: `D3D12 runtime: asking Windows for SDK version … (no D3D12\D3D12Core.dll beside larp.exe)`, `D3D12Core.dll` loaded from `C:\Windows\SYSTEM32`. Device created, presents at 60 fps. | | 3. Mismatched Agility version (1.614.1 in `D3D12\`) | Not run yet. Expect a `SDK version 614` line and a normal start. Main's exe should fail with `0x887E0003`. | | 4. Non-Agility file in `D3D12\` (System32's 10.0.x) | Not run yet. Expect "is no Agility SDK runtime" and the OS runtime. | | 5. `LARP_AGILITY=0` with a normal 1.620 folder | Not run yet. Expect the OS version in the log and System32's `D3D12Core.dll` loaded. | | 6. Non-GPU commands | `larp-a.exe config` and `larp-a.exe nv-profile` both exited 0. | I will also run main's exe on cases 2 and 3 for comparison, then post the finished table here.
D3D12SDKVersion becomes writable and agility::choose sets it first thing in
main; build.rs delay-loads d3d12.dll so Windows reads the value set there
(imported the usual way it is loaded before main and reads the constant).

- LARP_AGILITY=0: System32's runtime, by the version its D3D12Core.dll
  exports, to tell a device removal that goes with the 1.620 runtime (and
  byte-offset views, which then fall back to by-element) from one that
  does not.
- No D3D12\D3D12Core.dll beside larp.exe: Windows' own runtime instead of
  a loader that makes no device.
- A D3D12Core.dll of another version: that version, instead of 0x887E0003.

Ported from VIctory-NVIDIA (0f0ada19, e69e39c5), where an RTX 3080 Ti and
an RTX 5080 on Windows 11 were refused Direct3D 12 with a mismatched file.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 19:32:07 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-12-05 19:31 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/gamingwithhomie/larp/pull/139#pullrequestreview-6205473122) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠gamingwithhomie on GitHub · 2026-12-05 20:43 UTC · original

Holding per your own note (built-binary startup smoke test not yet posted). Post the RTX 3080 Ti checklist results and we will test-merge part (a) immediately - parts (b) #126 is already merged. Thank you!

**@⁠gamingwithhomie** on GitHub · 2026-12-05 20:43 UTC · [original](https://github.com/gamingwithhomie/larp/pull/139#issuecomment-7445050533) Holding per your own note (built-binary startup smoke test not yet posted). Post the RTX 3080 Ti checklist results and we will test-merge part (a) immediately - parts (b) #126 is already merged. Thank you!
Author
Owner

@⁠kadiratesdev on GitHub · 2026-12-05 22:43 UTC · original

Built-binary startup smoke test, RTX 3080 Ti (driver 621.47), Windows 11 build 26300 (System32 D3D12Core.dll 10.0.26100.10068, which reports SDK version 616).

Setup: this PR's head a036783, cross-built release, run from a scratch copy of bin as larp-a.exe. Scratch LARP_DATA_DIR for cases 3 to 5, so no real saves were used; the shared shader cache was used. Every run was run <game> --execute --console series-s -- -skipToIIS. Cases 3 to 5 were closed through the window (the close button's SC_CLOSE) and exited with code 0. Cases 1 and 2 ran the day before; my script sent a bare WM_CLOSE, which the title ignores, so those two were ended by hand. That says nothing about this PR. "Main" below is an earlier main build without this change (export fixed at 620).

Case This PR (a036783) Main
1. Normal start, bundled 1.620 D3D12\D3D12Core.dll No D3D12 runtime: line. D3D12Core.dll loaded from bin\D3D12. Device made, device15=true. Presents at 60 fps. not run (unchanged path)
2. No D3D12\ folder D3D12 runtime: asking Windows for SDK version 616 (no D3D12\D3D12Core.dll beside larp.exe). Loaded C:\Windows\SYSTEM32\D3D12Core.dll. Device made, device15=false. Presents at 60 fps. host device: no D3D12 device ... (0x887E0003), then the title throws 0x887e0003 (D3D12SerializeVersionedRootSignature) and the process ends with 0xE06D7363 after about 2 s.
3. Agility 1.614.1 D3D12Core.dll in D3D12\ D3D12 runtime: asking Windows for SDK version 614 (the version of D3D12\D3D12Core.dll). Windows picked the newer System32 runtime (SYSTEM32\D3D12Core.dll), not the 1.614.1 file. Device made, device15=false. Frames presented (53.5 fps in the first 5 s report). Same 0x887E0003 failure and exit as case 2.
4. System32's 10.0.26100 D3D12Core.dll copied into D3D12\ D3D12 runtime: asking Windows for SDK version 616 (D3D12\D3D12Core.dll is no Agility SDK runtime). Loaded SYSTEM32\D3D12Core.dll. Device made, device15=false. 60 fps. not run
5. LARP_AGILITY=0, normal 1.620 folder D3D12 runtime: asking Windows for SDK version 616 (LARP_AGILITY=0). Loaded SYSTEM32\D3D12Core.dll. Device made, device15=false. 60 fps. not run
6. Non-GPU commands config and nv-profile exit 0. not run

Not tested:

  • Cases 1 and 2 ran on 2026-12-05, a few minutes each, to the title's first screens; cases 3 to 5 ran only about 10 s each, to the first frame-rate report. No gameplay and no long session with this build.
  • Case 3 does not show the 1.614.1 runtime actually running, because this Windows build's own runtime is newer, so Windows chose it. A system whose OS runtime is older than 614 would be needed for that.
  • Only one GPU and OS (RTX 3080 Ti on Windows 11 26300). Nothing tested under Wine or on AMD.
**@⁠kadiratesdev** on GitHub · 2026-12-05 22:43 UTC · [original](https://github.com/gamingwithhomie/larp/pull/139#issuecomment-7447005591) Built-binary startup smoke test, RTX 3080 Ti (driver 621.47), Windows 11 build 26300 (System32 `D3D12Core.dll` 10.0.26100.10068, which reports SDK version 616). Setup: this PR's head a036783, cross-built release, run from a scratch copy of `bin` as `larp-a.exe`. Scratch `LARP_DATA_DIR` for cases 3 to 5, so no real saves were used; the shared shader cache was used. Every run was `run <game> --execute --console series-s -- -skipToIIS`. Cases 3 to 5 were closed through the window (the close button's `SC_CLOSE`) and exited with code 0. Cases 1 and 2 ran the day before; my script sent a bare `WM_CLOSE`, which the title ignores, so those two were ended by hand. That says nothing about this PR. "Main" below is an earlier main build without this change (export fixed at 620). | Case | This PR (a036783) | Main | |---|---|---| | 1. Normal start, bundled 1.620 `D3D12\D3D12Core.dll` | No `D3D12 runtime:` line. `D3D12Core.dll` loaded from `bin\D3D12`. Device made, `device15=true`. Presents at 60 fps. | not run (unchanged path) | | 2. No `D3D12\` folder | `D3D12 runtime: asking Windows for SDK version 616 (no D3D12\D3D12Core.dll beside larp.exe)`. Loaded `C:\Windows\SYSTEM32\D3D12Core.dll`. Device made, `device15=false`. Presents at 60 fps. | `host device: no D3D12 device ... (0x887E0003)`, then the title throws `0x887e0003` (`D3D12SerializeVersionedRootSignature`) and the process ends with `0xE06D7363` after about 2 s. | | 3. Agility 1.614.1 `D3D12Core.dll` in `D3D12\` | `D3D12 runtime: asking Windows for SDK version 614 (the version of D3D12\D3D12Core.dll)`. Windows picked the newer System32 runtime (`SYSTEM32\D3D12Core.dll`), not the 1.614.1 file. Device made, `device15=false`. Frames presented (53.5 fps in the first 5 s report). | Same `0x887E0003` failure and exit as case 2. | | 4. System32's 10.0.26100 `D3D12Core.dll` copied into `D3D12\` | `D3D12 runtime: asking Windows for SDK version 616 (D3D12\D3D12Core.dll is no Agility SDK runtime)`. Loaded `SYSTEM32\D3D12Core.dll`. Device made, `device15=false`. 60 fps. | not run | | 5. `LARP_AGILITY=0`, normal 1.620 folder | `D3D12 runtime: asking Windows for SDK version 616 (LARP_AGILITY=0)`. Loaded `SYSTEM32\D3D12Core.dll`. Device made, `device15=false`. 60 fps. | not run | | 6. Non-GPU commands | `config` and `nv-profile` exit 0. | not run | Not tested: - Cases 1 and 2 ran on 2026-12-05, a few minutes each, to the title's first screens; cases 3 to 5 ran only about 10 s each, to the first frame-rate report. No gameplay and no long session with this build. - Case 3 does not show the 1.614.1 runtime actually running, because this Windows build's own runtime is newer, so Windows chose it. A system whose OS runtime is older than 614 would be needed for that. - Only one GPU and OS (RTX 3080 Ti on Windows 11 26300). Nothing tested under Wine or on AMD.
github-bot changed target branch from main to gh-pr/139/base 2026-12-06 00:27:24 +00:00
github-bot referenced this pull request from a commit 2026-12-06 01:25:33 +00:00
github manually merged commit a036783913 into gh-pr/139/base 2026-12-06 01:25:39 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.