d3d12: leonida nv-profile, NVIDIA's shader heap at 1-2 GiB in a profile of our own (D3D12-NV-PROFILE) #3519

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "+refs/pull/3519/head:oreofr/nv-profile"
git switch "oreofr/nv-profile"
Open
leonida/mandy
OreoFR wants to merge 3 commits from oreofr/nv-profile into main AGit

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
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/3519/head:oreofr/nv-profile'
git switch 'oreofr/nv-profile'
Member

Item: D3D12-NV-PROFILE (asked by OreoFR, 2026-12-05; claimed in #3312).

Problem. With ray tracing the game reaches some 2,100-2,700 pipelines. NVIDIA's shader heap (512 MiB unless a driver profile says otherwise) then fills up, and the device is lost with 0x887A0005, with no page fault and empty breadcrumbs. Darner's testers stopped these losses on six PCs (RTX 4090 x3, RTX 3090, Windows 10 and 11) with the driver setting 0x001ABC0F at 1 or 2 GiB for the game's exe.

Change. A new subcommand, leonida nv-profile (Windows), in crates/leonida-gpu/src/nvprofile.rs:

  • No option: shows what the driver applies to leonida.exe and leonida_sm.exe. Reads only.
  • --mb 1024|2048: sets the heap in a driver profile of our own, "Mandy (shader heap)", created if missing. An exe the driver already puts in another profile (for example one made with Profile Inspector) gets the setting in that profile. Needs an administrator prompt.
  • --remove: deletes our profile.
  • --exe <name>: adds more exe names.
  • It goes through NVAPI's driver settings (DRS), with nvapi64.dll loaded from System32 only.
  • Nothing runs unless asked: no game start touches the driver's settings. A launcher button (Tools) can come later, through the launcher's owner.
  • Adapted from Darner's nv-profile (TrustNo1/Darner, apps/darner/src/nvprofile.rs, GPL-3.0).

Tested (Windows 11, RTX 4070 Laptop):

  • cargo test -p leonida-gpu nvprofile: 4 tests (structure sizes and versions, heap values, exe names, text round trip).
  • Diag build and clippy: OK. check_no_game_data: clean.
  • The status reads the real driver: leonida.exe: in no profile, shader heap not set (the driver's 512 MiB).
  • Not run: --mb and --remove, since they change the driver's settings. Not measured in game: the first check is a ray-tracing run that loses the device today, with and without the profile.

Added (095221123): asked at PLAY when ray tracing is on, taken away when it is off (OreoFR's choice)

  • On a start with LEONIDA_BVH_BUILDER=1, play-nvidia.ps1 runs leonida nv-profile --check. That flag can come from the launcher's ray tracing box, -RayTracing/-HardwareRT, the F1 menu's file or Advanced. The check reads only, needs no rights, and exits 0 when set, 1 when not, 2 without NVIDIA.
  • When the heap is not raised, Windows' administrator prompt asks to run leonida nv-profile --mb: 1 GiB on cards of 8 GB or less, where the heap memory comes out of the textures', and 2 GiB above.
  • The game starts whatever the answer. A declined prompt comes back at the next start with ray tracing.
  • A start without ray tracing removes the profile this script set, with one more prompt. A profile made by other means is never touched.
  • LEONIDA_NV_PROFILE=0: never asked.
  • tests/test_play_nv_profile.py: 8 tests. The block runs alone with a stand-in for leonida.exe and for the elevated call.
  • --check on the RTX 4070 Laptop: exit 1, "the driver's 512 MiB".
  • The elevated --mb and --remove were not run.
  • Still to measure before this reaches players: VRAM and fps on an 8 GB card with and without the profile, and a ray-tracing run that loses the device today.

Added (2a8187c1d): the NVIDIA shader cache size is read, and a start warns when it is not Unlimited

  • leonida nv-profile reads NVIDIA Control Panel's Shader Cache Size. It is the driver setting "Shader disk cache maximum size", 0x00AC8497 in the global profile, found by listing the driver's setting names on an RTX 4070 Laptop. At Unlimited it reads 0xFFFFFFFF.
  • The status shows it. --cache answers with an exit code: 0 Unlimited, 1 not, 2 no NVIDIA driver. Reads only.
  • play-nvidia.ps1 warns at each start when the cache is limited. A limited cache fills with older translations, then keeps nothing new.
  • Only Unlimited's value is known. The panel's 5, 10 and 100 GB choices are shown raw until read back.
  • Tests: tests/test_play_nv_profile.py now has 10, and nvprofile 7.
  • On the 4070: --cache prints "Unlimited" and exits 0.

AI-assisted (oreofr-agent).

🤖 Generated with Claude Code

Item: D3D12-NV-PROFILE (asked by OreoFR, 2026-12-05; claimed in #3312). **Problem.** With ray tracing the game reaches some 2,100-2,700 pipelines. NVIDIA's shader heap (512 MiB unless a driver profile says otherwise) then fills up, and the device is lost with `0x887A0005`, with no page fault and empty breadcrumbs. Darner's testers stopped these losses on six PCs (RTX 4090 x3, RTX 3090, Windows 10 and 11) with the driver setting `0x001ABC0F` at 1 or 2 GiB for the game's exe. **Change.** A new subcommand, `leonida nv-profile` (Windows), in `crates/leonida-gpu/src/nvprofile.rs`: - **No option:** shows what the driver applies to `leonida.exe` and `leonida_sm.exe`. Reads only. - **`--mb 1024|2048`:** sets the heap in a driver profile of our own, "Mandy (shader heap)", created if missing. An exe the driver already puts in another profile (for example one made with Profile Inspector) gets the setting in that profile. Needs an administrator prompt. - **`--remove`:** deletes our profile. - **`--exe <name>`:** adds more exe names. - It goes through NVAPI's driver settings (DRS), with `nvapi64.dll` loaded from System32 only. - **Nothing runs unless asked:** no game start touches the driver's settings. A launcher button (Tools) can come later, through the launcher's owner. - Adapted from Darner's `nv-profile` (TrustNo1/Darner, `apps/darner/src/nvprofile.rs`, GPL-3.0). **Tested** (Windows 11, RTX 4070 Laptop): - `cargo test -p leonida-gpu nvprofile`: 4 tests (structure sizes and versions, heap values, exe names, text round trip). - Diag build and clippy: OK. `check_no_game_data`: clean. - The status reads the real driver: `leonida.exe: in no profile, shader heap not set (the driver's 512 MiB)`. - **Not run:** `--mb` and `--remove`, since they change the driver's settings. Not measured in game: the first check is a ray-tracing run that loses the device today, with and without the profile. **Added (095221123): asked at PLAY when ray tracing is on, taken away when it is off** (OreoFR's choice) - On a start with `LEONIDA_BVH_BUILDER=1`, `play-nvidia.ps1` runs `leonida nv-profile --check`. That flag can come from the launcher's ray tracing box, `-RayTracing`/`-HardwareRT`, the F1 menu's file or Advanced. The check reads only, needs no rights, and exits 0 when set, 1 when not, 2 without NVIDIA. - When the heap is not raised, Windows' administrator prompt asks to run `leonida nv-profile --mb`: 1 GiB on cards of 8 GB or less, where the heap memory comes out of the textures', and 2 GiB above. - The game starts whatever the answer. A declined prompt comes back at the next start with ray tracing. - A start without ray tracing removes the profile this script set, with one more prompt. A profile made by other means is never touched. - `LEONIDA_NV_PROFILE=0`: never asked. - `tests/test_play_nv_profile.py`: 8 tests. The block runs alone with a stand-in for leonida.exe and for the elevated call. - `--check` on the RTX 4070 Laptop: exit 1, "the driver's 512 MiB". - The elevated `--mb` and `--remove` were not run. - **Still to measure before this reaches players:** VRAM and fps on an 8 GB card with and without the profile, and a ray-tracing run that loses the device today. **Added (2a8187c1d): the NVIDIA shader cache size is read, and a start warns when it is not Unlimited** - `leonida nv-profile` reads NVIDIA Control Panel's Shader Cache Size. It is the driver setting "Shader disk cache maximum size", `0x00AC8497` in the global profile, found by listing the driver's setting names on an RTX 4070 Laptop. At Unlimited it reads `0xFFFFFFFF`. - The status shows it. `--cache` answers with an exit code: 0 Unlimited, 1 not, 2 no NVIDIA driver. Reads only. - `play-nvidia.ps1` warns at each start when the cache is limited. A limited cache fills with older translations, then keeps nothing new. - Only Unlimited's value is known. The panel's 5, 10 and 100 GB choices are shown raw until read back. - Tests: `tests/test_play_nv_profile.py` now has 10, and `nvprofile` 7. - On the 4070: `--cache` prints "Unlimited" and exits 0. AI-assisted (oreofr-agent). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With ray tracing the game reaches some 2,100-2,700 pipelines, and NVIDIA's shader heap (512 MiB unless a
profile says otherwise) is then full: the device is lost with 0x887A0005, no page fault, empty
breadcrumbs. Darner's testers stopped those losses on six PCs with the driver setting 0x001ABC0F at 1 or
2 GiB for the game's exe.

`leonida nv-profile` (Windows): without options it shows what the driver applies to leonida.exe and
leonida_sm.exe (reads only); `--mb 1024|2048` sets the heap in a profile of Mandy's own ("Mandy (shader
heap)", made if missing; an exe already in another profile gets it there), which needs an administrator
prompt; `--remove` deletes that profile. Through NVAPI's driver settings (DRS), nvapi64.dll from System32
only. Nothing runs unless asked: no start of the game touches the driver's settings.

Adapted from Darner's nv-profile (TrustNo1/Darner, apps/darner/src/nvprofile.rs, GPL-3.0).

Tested: cargo test -p leonida-gpu nvprofile (4: structure sizes and versions, heap values, exe names,
texts), the diag build, clippy, check_no_game_data. On an RTX 4070 Laptop: the status reads the driver's
settings ("leonida.exe: in no profile, shader heap not set"). --mb and --remove were not run (they change
the driver's settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As asked by OreoFR: ray tracing on + PLAY asks, ray tracing off + PLAY removes. On a start with
LEONIDA_BVH_BUILDER=1 (the launcher's ray tracing box, -RayTracing or -HardwareRT, the F1 menu's file or
the launcher's Advanced variables, all of which end there), `leonida nv-profile --check` reads the
driver's settings (no rights needed); when the heap is not raised, Windows' administrator prompt asks to
run `leonida nv-profile --mb` (1 GiB on cards of 8 GB or less, where it comes out of the textures'
memory; 2 GiB above). The game starts whatever the answer; a declined prompt comes again at the next
start with ray tracing. A start without ray tracing removes the profile this script set (one more prompt);
a profile made by other means is never touched. LEONIDA_NV_PROFILE=0: never asked.

`leonida nv-profile --check`: exit code 0 when the heap is 1 GiB or more for leonida.exe and
leonida_sm.exe, 1 when not, 2 without an NVIDIA driver.

Tested: tests/test_play_nv_profile.py (8: asks with RT, 1 or 2 GiB by VRAM, nothing when raised or without
NVIDIA, a declined prompt, removal without RT, no mark no prompt, the switch), cargo test -p leonida-gpu
nvprofile (6), the play script tests, test_d3d12_switches, PowerShell parse check, clippy. On an RTX 4070
Laptop: `--check` exits 1 ("not set: ... the driver's 512 MiB"). The elevated --mb/--remove not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`leonida nv-profile` now reads NVIDIA Control Panel's Shader Cache Size: the driver setting "Shader disk
cache maximum size", 0x00AC8497 in the global profile (found by listing the driver's setting names on an
RTX 4070 Laptop; at Unlimited it reads 0xFFFFFFFF). The status shows it, and `--cache` answers with an exit
code (0 Unlimited, 1 not, 2 no NVIDIA driver). Reads only, no rights needed.

play-nvidia.ps1 runs it at each start (LEONIDA_NV_PROFILE=0: not) and warns when the cache is limited:
there it fills with older translations and then keeps nothing new, and the game compiles while it runs
however much was precompiled. Only Unlimited's value is known; the panel's 5, 10 and 100 GB choices are
shown as their raw value until read back.

Tested: cargo test -p leonida-gpu nvprofile (7), tests/test_play_nv_profile.py (10: the warning on a
limited cache, none on Unlimited or without NVIDIA), the play script tests, test_d3d12_switches, clippy,
PowerShell parse check. On the RTX 4070 Laptop: `--cache` prints "Unlimited" and exits 0.

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

Verified at head 2a8187c1, merge base 93b9d90a. d3d12/crates/leonida-gpu/src/nvprofile.rs and tests/test_play_nv_profile.py are new files (absent at 93b9d90a).

Rust unit tests (nvprofile::tests::, 7 new):

cargo test -p leonida-gpu --locked --lib nvprofile::tests::
#   7 passed; 0 failed (850 filtered out)
cargo test -p leonida-gpu --locked --lib nvprofile::tests::versions_carry_the_structure_size -- --exact
cargo test -p leonida-gpu --locked --lib nvprofile::tests::texts_round_trip_and_long_ones_stay_terminated -- --exact
#   1 passed each

PowerShell block tests (10 new):

python -I -m unittest discover -s tests -p test_play_nv_profile.py -v
#   Ran 10 tests in 7.095s — OK

They run the real block in Windows PowerShell with a fake leonida, LOCALAPPDATA pointed at a temp root and $nvElevate stubbed, so no UAC prompt and no driver write; %LOCALAPPDATA%\Leonida\nv-profile-set.txt does not exist on this machine after the run.

Real driver, read-only. Built leonida and ran the two read-only subcommands against this laptop's RTX 5060 (driver 621.40):

leonida nv-profile --cache   -> exit 1: "NVIDIA shader cache size: the driver's default (limited)"
leonida nv-profile --check   -> exit 1: "not set: leonida.exe has a shader heap not set (the driver's 512 MiB)"

So the NVAPI read path works against a real driver, and the exit-code contract the script branches on (0 set/Unlimited, 1 not, 2 no NVIDIA driver) holds for the 1 case here. --mb and --remove were not run: they write a driver profile and need an administrator prompt.

git diff --check against 93b9d90a: clean. scripts/check_no_game_data.py on the six changed files: clean.

Limits. Both read-only commands answer 1 on this card, so the raised/Unlimited side (exit 0) is only covered by the unit tests; the profile write and removal paths stay unexercised here.

AI-assisted (Hy4 flash). GPU: RTX 5060 Laptop, NVIDIA driver 621.40 (Radeon 780M also present). The nv-profile reads above used the NVIDIA driver; no game data used or needed.

Verified at head 2a8187c1, merge base 93b9d90a. `d3d12/crates/leonida-gpu/src/nvprofile.rs` and `tests/test_play_nv_profile.py` are new files (absent at 93b9d90a). **Rust unit tests** (`nvprofile::tests::`, 7 new): ```powershell cargo test -p leonida-gpu --locked --lib nvprofile::tests:: # 7 passed; 0 failed (850 filtered out) cargo test -p leonida-gpu --locked --lib nvprofile::tests::versions_carry_the_structure_size -- --exact cargo test -p leonida-gpu --locked --lib nvprofile::tests::texts_round_trip_and_long_ones_stay_terminated -- --exact # 1 passed each ``` **PowerShell block tests** (10 new): ```powershell python -I -m unittest discover -s tests -p test_play_nv_profile.py -v # Ran 10 tests in 7.095s — OK ``` They run the real block in Windows PowerShell with a fake `leonida`, `LOCALAPPDATA` pointed at a temp root and `$nvElevate` stubbed, so no UAC prompt and no driver write; `%LOCALAPPDATA%\Leonida\nv-profile-set.txt` does not exist on this machine after the run. **Real driver, read-only.** Built `leonida` and ran the two read-only subcommands against this laptop's RTX 5060 (driver 621.40): ``` leonida nv-profile --cache -> exit 1: "NVIDIA shader cache size: the driver's default (limited)" leonida nv-profile --check -> exit 1: "not set: leonida.exe has a shader heap not set (the driver's 512 MiB)" ``` So the NVAPI read path works against a real driver, and the exit-code contract the script branches on (0 set/Unlimited, 1 not, 2 no NVIDIA driver) holds for the 1 case here. `--mb` and `--remove` were **not** run: they write a driver profile and need an administrator prompt. `git diff --check` against 93b9d90a: clean. `scripts/check_no_game_data.py` on the six changed files: clean. **Limits.** Both read-only commands answer 1 on this card, so the raised/Unlimited side (exit 0) is only covered by the unit tests; the profile write and removal paths stay unexercised here. AI-assisted (Hy4 flash). GPU: RTX 5060 Laptop, NVIDIA driver 621.40 (Radeon 780M also present). The nv-profile reads above used the NVIDIA driver; no game data used or needed.
Sign in to join this conversation.
No description provided.