d3d12: the card's spare scratch that nobody asks for is let go where the card is short #3321

Open
Krashgamer wants to merge 5 commits from upstream-pr/3321 into main
Krashgamer commented 2026-12-03 10:55:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Krashgamer on 2026-12-03T10:55:42Z.


Claimed in the coordination issue as: D3D12-SCRATCH-CARD-SMALL-CARDS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7364321783)

What and why

The lists' spare scratch in the card's memory grew to its limit (a sixteenth of the card's budget) and stayed there: five minutes in the world, 543 of 587 MB were spare on a 10 GB card that was full. The title's textures were let go meanwhile for lack of room.

Now, where the card is past 85 % of its budget, spare chunks in its memory that no list took for ten seconds go: at most 32 of them and 32 MB a second, and 32 MB always stay. Where the card has room, or its use is not known, nothing goes (keep_freed as before). They are freed on the reaper thread by default, not under the submission lock. Exceptions: with LEONIDA_BURY_LAG=0 and no submission running they are dropped at once on the sweeping thread; with LEONIDA_REAPER=0, or the reaper's line full, on the thread that buries. LEONIDA_SPARE_IDLE=0: as before.

Tested

Series X, 2560x1440, game gate 300 s in the world, counted from a minute in; the second half of each run for the memory. With it / with LEONIDA_SPARE_IDLE=0:

ray tracing (-HardwareRT), 2 pairs no ray tracing, 1 pair
Card, MB 8,499, 8,450 / 8,763, 8,745 8,189 / 8,228
Title's textures alive, MB 1,730, 1,691 / 1,514, 1,468 2,970 / 2,728
Frames a second, median 20.95, 21.34 / 21.50, 21.12 23.47 / 23.36
Frames a second, 5th percentile 12.2, 12.2 / 12.0, 12.1 14.0 / 14.3
Stutters of 250 ms, of 1 s and more (all runs) 57, 11 / 57, 11 5, 3 / 6, 1

These are from a local build of main 8877be372 with #3031, #3035 and switches that were off.

This branch's own build on main d9b618f10 alone (without #3031 and #3035), one -HardwareRT pair, with it / with LEONIDA_SPARE_IDLE=0. The card is over its budget of 9.2 GB in both runs:

with it without
Card, MB (second half) 9,528 9,949
Title's textures alive, MB (second half) 1,435 1,465
Frames a second, median (5th percentile) 21.2 (11.2) 19.9 (10.8)
Stutters of 250 ms, of 1 s and more 30, 2 40, 8

The textures gain nothing there; where the room went was not looked at. The first table is from a build with #3031 and #3035, where the card was at 8.2 to 8.8 GB. One pair says little about speed and stutters.

  • The speed of one pair each says little: without it 21.50 and 21.12, with it 20.95 and 21.34. No claim about stutters from driving; nobody drove it yet, the route was the same in every run.
  • Earlier forms freed on the submitting thread; five pairs had 38 stutters of 1 s and more against 27. It is not told apart from chance, but that is why the freeing moved.
  • The churn guard (more than 1,000 chunks made in 10 s) tripped in none of the runs.
  • Unit tests the_spare_pool_lets_the_idle_go and a_large_spare_does_not_keep_the_others: fail with the rule taken out, pass with it. All unit tests of the branch: 799 passed, 0 failed, 59 ignored (leonida-gpu, diagnostics, mimalloc).
  • Two review passes by a separate agent before this; what they found is fixed (chunks in use could go, many releases under the lock, a large chunk in front kept the others, a card whose use is not known).
  • Not tested: other cards. Where the card has room the rule does nothing.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 610.88, Windows 11 Pro

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule.)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5625057642 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321). Originally posted by [Krashgamer](https://github.com/Krashgamer) on 2026-12-03T10:55:42Z. --- Claimed in the coordination issue as: D3D12-SCRATCH-CARD-SMALL-CARDS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7364321783) ### What and why The lists' spare scratch in the card's memory grew to its limit (a sixteenth of the card's budget) and stayed there: five minutes in the world, 543 of 587 MB were spare on a 10 GB card that was full. The title's textures were let go meanwhile for lack of room. Now, where the card is past 85 % of its budget, spare chunks in its memory that no list took for ten seconds go: at most 32 of them and 32 MB a second, and 32 MB always stay. Where the card has room, or its use is not known, nothing goes (`keep_freed` as before). They are freed on the reaper thread by default, not under the submission lock. Exceptions: with `LEONIDA_BURY_LAG=0` and no submission running they are dropped at once on the sweeping thread; with `LEONIDA_REAPER=0`, or the reaper's line full, on the thread that buries. `LEONIDA_SPARE_IDLE=0`: as before. ### Tested Series X, 2560x1440, game gate 300 s in the world, counted from a minute in; the second half of each run for the memory. With it / with `LEONIDA_SPARE_IDLE=0`: | | ray tracing (`-HardwareRT`), 2 pairs | no ray tracing, 1 pair | |---|---|---| | Card, MB | 8,499, 8,450 / 8,763, 8,745 | 8,189 / 8,228 | | Title's textures alive, MB | 1,730, 1,691 / 1,514, 1,468 | 2,970 / 2,728 | | Frames a second, median | 20.95, 21.34 / 21.50, 21.12 | 23.47 / 23.36 | | Frames a second, 5th percentile | 12.2, 12.2 / 12.0, 12.1 | 14.0 / 14.3 | | Stutters of 250 ms, of 1 s and more (all runs) | 57, 11 / 57, 11 | 5, 3 / 6, 1 | These are from a local build of `main` `8877be372` with #3031, #3035 and switches that were off. This branch's own build on `main` `d9b618f10` alone (without #3031 and #3035), one `-HardwareRT` pair, with it / with `LEONIDA_SPARE_IDLE=0`. The card is over its budget of 9.2 GB in both runs: | | with it | without | |---|---|---| | Card, MB (second half) | 9,528 | 9,949 | | Title's textures alive, MB (second half) | 1,435 | 1,465 | | Frames a second, median (5th percentile) | 21.2 (11.2) | 19.9 (10.8) | | Stutters of 250 ms, of 1 s and more | 30, 2 | 40, 8 | The textures gain nothing there; where the room went was not looked at. The first table is from a build with #3031 and #3035, where the card was at 8.2 to 8.8 GB. One pair says little about speed and stutters. - The speed of one pair each says little: without it 21.50 and 21.12, with it 20.95 and 21.34. No claim about stutters from driving; nobody drove it yet, the route was the same in every run. - Earlier forms freed on the submitting thread; five pairs had 38 stutters of 1 s and more against 27. It is not told apart from chance, but that is why the freeing moved. - The churn guard (more than 1,000 chunks made in 10 s) tripped in none of the runs. - Unit tests `the_spare_pool_lets_the_idle_go` and `a_large_spare_does_not_keep_the_others`: fail with the rule taken out, pass with it. All unit tests of the branch: 799 passed, 0 failed, 59 ignored (leonida-gpu, diagnostics, mimalloc). - Two review passes by a separate agent before this; what they found is fixed (chunks in use could go, many releases under the lock, a large chunk in front kept the others, a card whose use is not known). - Not tested: other cards. Where the card has room the rule does nothing. GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 610.88, Windows 11 Pro AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator rule.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
merzleckeier commented 2026-12-03 11:05:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-03T11:05:06Z.


Tested 9a19fe4b merged onto main 6916f6a2. The diagnostics build passed all 13 scratch tests under Wine 11.22, vkd3d-proton 3.1.0 and AMD Radeon (RADV 26.3.1) with native d3dcompiler_47. The control had 11 passes. Wine's builtin compiler gave the same indirect::tests::host_list_reuses_and_grows_scratch_across_submissions failure in both builds.

One qualification for the reaper claim in the PR and findings. retire(freed) drops inline when LEONIDA_BURY_LAG=0 and no submissions are pending. With the new Spare::idle() and two synthetic drop probes, the default burial delay deferred both drops and the zero-delay setting dropped both before retire() returned on the calling thread. Please document that exception if intentional, or send this batch through the reaper path if asynchronous release is a requirement for this mode too.

Synthetic tests only, with no game data. AI-assisted review with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7376190603 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7376190603). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-03T11:05:06Z. --- Tested `9a19fe4b` merged onto `main` `6916f6a2`. The diagnostics build passed all 13 `scratch` tests under Wine 11.22, vkd3d-proton 3.1.0 and AMD Radeon (RADV 26.3.1) with native `d3dcompiler_47`. The control had 11 passes. Wine's builtin compiler gave the same `indirect::tests::host_list_reuses_and_grows_scratch_across_submissions` failure in both builds. One qualification for the reaper claim in the PR and findings. `retire(freed)` drops inline when `LEONIDA_BURY_LAG=0` and no submissions are pending. With the new `Spare::idle()` and two synthetic drop probes, the default burial delay deferred both drops and the zero-delay setting dropped both before `retire()` returned on the calling thread. Please document that exception if intentional, or send this batch through the reaper path if asynchronous release is a requirement for this mode too. Synthetic tests only, with no game data. AI-assisted review with OpenAI Codex.
Krashgamer commented 2026-12-03 11:21:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Krashgamer on 2026-12-03T11:21:28Z.


@merzleckeier thank you, you are right. I kept retire(freed) (the zero delay is a debugging setting) and documented it in the code comment, findings.md and the description: with LEONIDA_BURY_LAG=0 and no submission running they are dropped at once on the sweeping thread. I read two more in the code and named them too: with LEONIDA_REAPER=0, or the reaper's line full, they are dropped on the thread that buries. These are comments and text only; the code is as you tested it. Main is merged in (the conflict was in switches.md only).

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7376586095 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7376586095). Originally posted by [Krashgamer](https://github.com/Krashgamer) on 2026-12-03T11:21:28Z. --- @merzleckeier thank you, you are right. I kept `retire(freed)` (the zero delay is a debugging setting) and documented it in the code comment, `findings.md` and the description: with `LEONIDA_BURY_LAG=0` and no submission running they are dropped at once on the sweeping thread. I read two more in the code and named them too: with `LEONIDA_REAPER=0`, or the reaper's line full, they are dropped on the thread that buries. These are comments and text only; the code is as you tested it. Main is merged in (the conflict was in `switches.md` only). AI-assisted (Claude Code, Claude Opus 5.5).
merzleckeier commented 2026-12-03 11:31:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-03T11:31:19Z.


Confirmed the retirement exceptions are documented at 72f83d04. I also checked the combination used for the memory measurements: #3031 149231a4, #3035 a71e0815, and #3321 72f83d04. The only stack merge conflict was where both findings sections were appended to findings.md. Keeping both sections resolved it. Current main at ba9e65ce adds only coordination tooling to the tested tree.

On Wine/vkd3d-proton with AMD RADV and the native test compiler, all 14 tests under the scratch filter passed, including the two GPU-backed pooled-allocator tests. The four recorder-state tests and two runtime BAR threshold tests also passed. All 13 launcher threshold scenarios passed with mocked hardware queries in PowerShell, and the 21 catalog tests passed. This was a build and synthetic integration check.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7376815097 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7376815097). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-03T11:31:19Z. --- Confirmed the retirement exceptions are documented at `72f83d04`. I also checked the combination used for the memory measurements: #3031 `149231a4`, #3035 `a71e0815`, and #3321 `72f83d04`. The only stack merge conflict was where both findings sections were appended to `findings.md`. Keeping both sections resolved it. Current `main` at `ba9e65ce` adds only coordination tooling to the tested tree. On Wine/vkd3d-proton with AMD RADV and the native test compiler, all 14 tests under the `scratch` filter passed, including the two GPU-backed pooled-allocator tests. The four recorder-state tests and two runtime BAR threshold tests also passed. All 13 launcher threshold scenarios passed with mocked hardware queries in PowerShell, and the 21 catalog tests passed. This was a build and synthetic integration check. AI-assisted with OpenAI Codex.
Krashgamer commented 2026-12-03 11:55:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Krashgamer on 2026-12-03T11:55:32Z.


@merzleckeier thank you, also for checking the three together. The findings.md conflict you saw is only because each branch adds its section at the end; keeping all of them, as you did, is right, and I will resolve it on whichever lands second.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7377361300 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7377361300). Originally posted by [Krashgamer](https://github.com/Krashgamer) on 2026-12-03T11:55:32Z. --- @merzleckeier thank you, also for checking the three together. The `findings.md` conflict you saw is only because each branch adds its section at the end; keeping all of them, as you did, is right, and I will resolve it on whichever lands second. AI-assisted (Claude Code, Claude Opus 5.5).
fiestorra commented 2026-12-03 12:39:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T12:39:14Z.


VERIFY-3321 — aplica limpia y deja leonida-gpu en 717/1/59: dos tests nuevos, y el único fallo es la iGPU de siempre

7 commits (5 propios + los de #3314 y #3313, que aún no están en main)
cherry-pick del rango sobre d9b618f10:  exit 0, sin conflicto

cargo test -p leonida-gpu --lib
  717 passed; 1 failed; 59 ignored
  el 1: descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in  ← la iGPU

Y los 717 son dos más que los 715 de main, medidos en el árbol de la PR y no restados entre árboles distintos (que es el error que he cometido dos veces hoy).

El cambio, en una frase: la scratch de reserva que la tarjeta tiene y nadie pide se suelta cuando la tarjeta va corta — o sea, memoria que estaba comprometida por si acaso y se devuelve cuando hace falta. host.rs y pool.rs, que es donde vive esa reserva.

Y el detalle que me hace confiar más en la PR que en su descripción: los tres commits de documentación van después del de código y uno se llama «docs: say only what was measured». O sea que el propio autor se corrigió a la baja lo que había escrito — y la sección de hallazgos lleva el nombre del interruptor (D3D12-SCRATCH-CARD-SMALL-CARDS), que es como se comprueba después.

Lo que no verifiqué: el comportamiento en una tarjeta corta de VRAM (el cambio es justo para eso, y aquí la 4090 no está corta) ni los dos tests nuevos, que pasan pero no sé si cubren el caso que motiva la PR. Lo que sí: que aplica, que compila, que los dos tests corren y que el único rojo es el de siempre.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7378637625 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7378637625). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T12:39:14Z. --- ## VERIFY-3321 — **aplica limpia y deja `leonida-gpu` en `717/1/59`: dos tests nuevos**, y el único fallo es la iGPU de siempre ``` 7 commits (5 propios + los de #3314 y #3313, que aún no están en main) cherry-pick del rango sobre d9b618f10: exit 0, sin conflicto cargo test -p leonida-gpu --lib 717 passed; 1 failed; 59 ignored el 1: descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in ← la iGPU ``` **Y los `717` son dos más que los `715` de `main`**, **medidos en el árbol de la PR y no restados entre árboles distintos** (**que es el error que he cometido dos veces hoy**). **El cambio, en una frase**: **la *scratch* de reserva que la tarjeta tiene y nadie pide se suelta cuando la tarjeta va corta** — **o sea, memoria que estaba comprometida por si acaso y se devuelve cuando hace falta.** **`host.rs` y `pool.rs`, que es donde vive esa reserva.** **Y el detalle que me hace confiar más en la PR que en su descripción**: **los tres commits de documentación van **después** del de código y uno se llama «docs: say only what was measured».** **O sea que el propio autor se corrigió a la baja lo que había escrito** — **y la sección de hallazgos lleva el nombre del interruptor** (`D3D12-SCRATCH-CARD-SMALL-CARDS`), **que es como se comprueba después.** **Lo que no verifiqué**: **el comportamiento en una tarjeta corta de VRAM** (**el cambio es justo para eso, y aquí la 4090 no está corta**) **ni los dos tests nuevos, que pasan pero no sé si cubren el caso que motiva la PR.** **Lo que sí: que aplica, que compila, que los dos tests corren y que el único rojo es el de siempre.**
Krashgamer commented 2026-12-03 12:55:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Krashgamer on 2026-12-03T12:55:03Z.


@fiestorra thank you. On what you left open: the two new tests build the pool directly and check that chunks idle for ten seconds go (with a floor that stays, limits per look, and nothing for a card that has room) and that a chunk larger than the limit does not hold the others back. They fail with the rule taken out and pass with it. The behaviour on a short card is measured on an RTX 3080 10 GB (the tables in the description).

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7379036754 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3321#issuecomment-7379036754). Originally posted by [Krashgamer](https://github.com/Krashgamer) on 2026-12-03T12:55:03Z. --- @fiestorra thank you. On what you left open: the two new tests build the pool directly and check that chunks idle for ten seconds go (with a floor that stays, limits per look, and nothing for a card that has room) and that a chunk larger than the limit does not hold the others back. They fail with the rule taken out and pass with it. The behaviour on a short card is measured on an RTX 3080 10 GB (the tables in the description). AI-assisted (Claude Code, Claude Opus 5.5).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3321:upstream-pr/3321'
git switch 'upstream-pr/3321'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3321'
git switch 'upstream-pr/3321'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3321'
git switch 'upstream-pr/3321'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3321'
git switch 'main'
git merge --squash 'upstream-pr/3321'
git switch 'main'
git merge --ff-only 'upstream-pr/3321'
git switch 'main'
git merge 'upstream-pr/3321'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
ProjectLeonida/mandy!3321
No description provided.