d3d12: a slot-133 shadow keeps the GPU's writes where the title's bytes did not change (RT-SHADOW-KEEP-GPU-WRITES) #2163

Manually merged
github merged 5 commits from github-bot/gh-2163 into main 2026-11-26 17:27:24 +00:00 AGit
Owner

@⁠DadaCap on GitHub · 2026-11-26 00:40 UTC · original
DadaCap:shadow-keep-gpu-writes → main · +374 −4 · 7 files · 5 commits · merged 2026-11-26 17:26 UTC

Claimed in the coordination issue as: #1608

Depends on: none. It merges cleanly with current main (which now includes #2098), and conflicts with #1897 and #1867. #1897 moves ShadowPages to runtime/src/shadow_pages.h, so its d3d12_vulkan_device.cpp hunks conflict. #1867 conflicts only in its runtime/README.md row next to this one. Whichever lands second redoes those lines. It merges cleanly with #2032 and #2129.

What and why

ShadowPages copies the title's pages into the slot-133 shadow buffers and title windows before every submission. Some pages are copied at every refresh without any sign that the title wrote them: pages xmem maps at two addresses, pages a guard could not be put on, the 64 KiB block reopened around a written page, write-watched pages and pages pinned for a kernel write. A copy of such a page also overwrote whatever a shader had stored in the shadow since the last refresh, with the title's unchanged bytes.

Seen in the retail title: a 16-byte buffer that a compute program writes for the next frame to read was copied over by the title's old bytes before that frame, so it read back as zero every other frame and half the frames came out black.

The fix:

  • runtime/src/shadow_keep.h (new, portable): a 64-bit sum per 256-byte piece of the title's address space, taken from the bytes last copied. copy_changed compares the title's current bytes with those sums and copies only the pieces that differ. The first and last pieces of a range can be partial. forget clears sums so their pieces get copied again.
  • ShadowPages keeps the sums (sums_, per piece from its first page; grown by extend, carried over by absorb). With LEONIDA_SHADOW_KEEP on (the default), every copy job reads the title's page once into a buffer (still through the guarded copy_run) and passes on only the changed pieces to each target. A page that is zeroed because it went away gets its sums forgotten, so it is copied in full once it comes back. A new target's first copy (fill) is unchanged.
  • LEONIDA_SHADOW_KEEP=0 restores the old behaviour (every job copied whole). There is a row for it in runtime/README.md and a paragraph in docs/d3d12_vulkan.md under the copies.

Limits:

  • A title that writes the same bytes again to reset a value the GPU changed is not seen: the sum still matches, so the GPU's value stays. Fixing that needs the GPU's writes to reach the title's pages (the write-back work in #2032 / #2129, which covers other pages: #2129 drops the GPU's result exactly on the pages that are not guarded or clean, which are the ones this change is about).
  • Every copied page is now read once into a 4 KiB buffer and hashed before the changed pieces are copied out. The sum runs four independent lanes (about 30 GB/s on the test machine's CPU against about 24 GB/s for a plain copy; a first, chained version ran at 13 GB/s and made the refresh five times slower in the game, so the speed matters). The copies are then written only where the title changed, which is most of the gain below.
  • A 64-bit sum can collide, in which case one change is missed until the next one.

Tested

  • New shadow_keep_test (ctest shadow_keep, CPU only, no GPU and no game data). The title and the copy are arrays with made-up bytes:

    • a GPU write into the copy over unchanged title bytes is kept;
    • a title change in one piece copies only that piece, and a GPU write in another piece stays;
    • partial first and last pieces of a range that starts and ends inside pieces;
    • forgotten sums (zeroed copy) copy those pieces once, then nothing;
    • the sum differs for every single-byte change in a piece.

    It passes with the change (shadow_keep: OK). With copy_changed changed back to copying every piece (the old behaviour), 13 checks fail (the kept GPU write, the per-piece copies, the partial pieces and the copy-once after zeroing).

  • Built gta6rt (Windows 11, MSVC, Ninja, RelWithDebInfo) and ran these tests with ctest. All 12 passed: shadow_keep, d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch, d3d12_xmem_placed, d3d12_title_va, d3d12_title_va_shadow, d3d12_title_window_cap, title_va_alias, title_window_plan, title_window_plan_bounds and vk_host_at_aliasing. The d3d12_* tests are the existing GPU tests of the shadows. They use hand-made pages, not game data. Not run: the full ctest suite and the translator suite (this changes no shader or translator code).

  • python -I scripts/check_no_game_data.py on the changed files: clean.

  • The game observation above (the GPU-written buffer reading back as the title's bytes every other frame) was made on a local build of main plus other local work, with a diagnostic trace that is not part of this change. There, with the change, the buffer kept its value from frame to frame and the alternating black frames were gone (one run).

  • Cost, measured with this branch's own build (current main with #2098, plus this change), the same retail scene, 420 s each, one run per setting, over the same 150-300 s window:

    LEONIDA_SHADOW_KEEP Refresh, ms a submission Bytes written to the copies a refresh Submissions a second
    0 (as before) 149 about 3.2 GB 3.9
    on (this change) 88 under 5 MB 4.6

    On main most of those bytes are pages mapped at two addresses, which no guard watches, so they were rewritten into the copies at every submission although they had not changed. With this change on, the pieces are compared on the CPU before anything is written, so #2098's optional GPU copy of aliased runs (gpu_copy, not used by default in these runs) is not reached; with LEONIDA_SHADOW_KEEP=0 that path is as on main. No log lines or captures are quoted here.

GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (game observation and the GPU-side ctest entries).

AI-assisted: yes (Claude Code, 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. (n/a: no translator rule)

🤖 Generated with Claude Code

**@⁠DadaCap** on GitHub · 2026-11-26 00:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163) `DadaCap:shadow-keep-gpu-writes` → `main` · +374 −4 · 7 files · 5 commits · merged 2026-11-26 17:26 UTC Claimed in the coordination issue as: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 Depends on: none. It merges cleanly with current `main` (which now includes #2098), and conflicts with #1897 and #1867. #1897 moves `ShadowPages` to `runtime/src/shadow_pages.h`, so its `d3d12_vulkan_device.cpp` hunks conflict. #1867 conflicts only in its `runtime/README.md` row next to this one. Whichever lands second redoes those lines. It merges cleanly with #2032 and #2129. ### What and why `ShadowPages` copies the title's pages into the slot-133 shadow buffers and title windows before every submission. Some pages are copied at every refresh without any sign that the title wrote them: pages xmem maps at two addresses, pages a guard could not be put on, the 64 KiB block reopened around a written page, write-watched pages and pages pinned for a kernel write. A copy of such a page also overwrote whatever a shader had stored in the shadow since the last refresh, with the title's unchanged bytes. Seen in the retail title: a 16-byte buffer that a compute program writes for the next frame to read was copied over by the title's old bytes before that frame, so it read back as zero every other frame and half the frames came out black. The fix: - `runtime/src/shadow_keep.h` (new, portable): a 64-bit sum per 256-byte piece of the title's address space, taken from the bytes last copied. `copy_changed` compares the title's current bytes with those sums and copies only the pieces that differ. The first and last pieces of a range can be partial. `forget` clears sums so their pieces get copied again. - `ShadowPages` keeps the sums (`sums_`, per piece from its first page; grown by `extend`, carried over by `absorb`). With `LEONIDA_SHADOW_KEEP` on (the default), every copy job reads the title's page once into a buffer (still through the guarded `copy_run`) and passes on only the changed pieces to each target. A page that is zeroed because it went away gets its sums forgotten, so it is copied in full once it comes back. A new target's first copy (`fill`) is unchanged. - `LEONIDA_SHADOW_KEEP=0` restores the old behaviour (every job copied whole). There is a row for it in `runtime/README.md` and a paragraph in `docs/d3d12_vulkan.md` under the copies. Limits: - A title that writes the **same** bytes again to reset a value the GPU changed is not seen: the sum still matches, so the GPU's value stays. Fixing that needs the GPU's writes to reach the title's pages (the write-back work in #2032 / #2129, which covers other pages: #2129 drops the GPU's result exactly on the pages that are not guarded or clean, which are the ones this change is about). - Every copied page is now read once into a 4 KiB buffer and hashed before the changed pieces are copied out. The sum runs four independent lanes (about 30 GB/s on the test machine's CPU against about 24 GB/s for a plain copy; a first, chained version ran at 13 GB/s and made the refresh five times slower in the game, so the speed matters). The copies are then written only where the title changed, which is most of the gain below. - A 64-bit sum can collide, in which case one change is missed until the next one. ### Tested - New `shadow_keep_test` (ctest `shadow_keep`, CPU only, no GPU and no game data). The title and the copy are arrays with made-up bytes: - a GPU write into the copy over unchanged title bytes is kept; - a title change in one piece copies only that piece, and a GPU write in another piece stays; - partial first and last pieces of a range that starts and ends inside pieces; - forgotten sums (zeroed copy) copy those pieces once, then nothing; - the sum differs for every single-byte change in a piece. It passes with the change (`shadow_keep: OK`). With `copy_changed` changed back to copying every piece (the old behaviour), 13 checks fail (the kept GPU write, the per-piece copies, the partial pieces and the copy-once after zeroing). - Built `gta6rt` (Windows 11, MSVC, Ninja, RelWithDebInfo) and ran these tests with `ctest`. All 12 passed: `shadow_keep`, `d3d12_existing_heap`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`, `d3d12_xmem_placed`, `d3d12_title_va`, `d3d12_title_va_shadow`, `d3d12_title_window_cap`, `title_va_alias`, `title_window_plan`, `title_window_plan_bounds` and `vk_host_at_aliasing`. The `d3d12_*` tests are the existing GPU tests of the shadows. They use hand-made pages, not game data. Not run: the full ctest suite and the translator suite (this changes no shader or translator code). - `python -I scripts/check_no_game_data.py` on the changed files: clean. - The game observation above (the GPU-written buffer reading back as the title's bytes every other frame) was made on a local build of `main` plus other local work, with a diagnostic trace that is not part of this change. There, with the change, the buffer kept its value from frame to frame and the alternating black frames were gone (one run). - Cost, measured with this branch's own build (current `main` with #2098, plus this change), the same retail scene, 420 s each, one run per setting, over the same 150-300 s window: | `LEONIDA_SHADOW_KEEP` | Refresh, ms a submission | Bytes written to the copies a refresh | Submissions a second | |---|---|---|---| | `0` (as before) | 149 | about 3.2 GB | 3.9 | | on (this change) | 88 | under 5 MB | 4.6 | On `main` most of those bytes are pages mapped at two addresses, which no guard watches, so they were rewritten into the copies at every submission although they had not changed. With this change on, the pieces are compared on the CPU before anything is written, so #2098's optional GPU copy of aliased runs (`gpu_copy`, not used by default in these runs) is not reached; with `LEONIDA_SHADOW_KEEP=0` that path is as on `main`. No log lines or captures are quoted here. GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (game observation and the GPU-side ctest entries). AI-assisted: yes (Claude Code, 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator rule) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ShadowPages copies pages that carry no sign of a title write (aliased,
unguarded, reopened with their 64 KiB block, write-watched or pinned) at
every refresh, and that copy overwrote what a shader had stored in the
shadow with the title's unchanged bytes. A value a compute program writes
for the next frame then read back as the title's old bytes every other
frame.

Each tracker now keeps a 64-bit sum per 256-byte piece of the bytes it
copied last (runtime/src/shadow_keep.h) and copies a piece only when the
title's bytes differ. Zeroed pages forget their sums. LEONIDA_SHADOW_KEEP=0
copies every job whole, as before. New CPU-only test shadow_keep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:52 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 00:47 UTC · original

On an RTX 4090, the next submission preserved 64/64 GPU-written words with the default setting and 0/64 with LEONIDA_SHADOW_KEEP=0. I tested 4d811fcee90f9a4b4c2988117bb78be96360342d on Windows 11, NVIDIA 616.64, using synthetic slot-133 buffers.

CPU write between submissions Default GPU readback With shadow keep disabled
Change the neighboring 256-byte piece All 64 GPU words survived in the first piece. All 64 new CPU words arrived in the neighbor. The first piece reverted to all 64 original CPU words. All 64 new CPU words arrived in the neighbor.
Then change one 32-bit word inside the first piece The full piece came from the CPU. The changed word arrived, and the other 63 reverted to their original CPU values. Same result.

To reproduce, I extended check_kind in d3d12_title_va_test.cpp. Its existing root-UAV dispatch writes words 0–63. After its fence, I changed words 64–127 and issued a copy-only submission reading back the first 512 bytes. After that fence, I changed word 63 and repeated the readback. I asserted that the resource took the shadow path. I ran both ordinary and write-combined pages, using either kernel_writes::hold or the runtime’s alias marker, with the alias refresh interval at zero.

All eight combinations of tracking mode, feature setting and Vulkan validation matched the table on both page types. The PR’s CPU-only shadow_keep test also passed. This verifies the refresh behavior on a second GPU and shows the 256-byte boundary when CPU and GPU writes share a piece. I did not run the game.

AI-assisted with OpenAI Codex (gpt-6.2-astra).

**@⁠ecox982745** on GitHub · 2026-11-26 00:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7179111726) On an RTX 4090, the next submission preserved **64/64 GPU-written words** with the default setting and **0/64** with `LEONIDA_SHADOW_KEEP=0`. I tested `4d811fcee90f9a4b4c2988117bb78be96360342d` on Windows 11, NVIDIA 616.64, using synthetic slot-133 buffers. | CPU write between submissions | Default GPU readback | With shadow keep disabled | |---|---|---| | Change the neighboring 256-byte piece | All 64 GPU words survived in the first piece. All 64 new CPU words arrived in the neighbor. | The first piece reverted to all 64 original CPU words. All 64 new CPU words arrived in the neighbor. | | Then change one 32-bit word inside the first piece | The full piece came from the CPU. The changed word arrived, and the other 63 reverted to their original CPU values. | Same result. | To reproduce, I extended `check_kind` in `d3d12_title_va_test.cpp`. Its existing root-UAV dispatch writes words 0–63. After its fence, I changed words 64–127 and issued a copy-only submission reading back the first 512 bytes. After that fence, I changed word 63 and repeated the readback. I asserted that the resource took the shadow path. I ran both ordinary and write-combined pages, using either `kernel_writes::hold` or the runtime’s alias marker, with the alias refresh interval at zero. All eight combinations of tracking mode, feature setting and Vulkan validation matched the table on both page types. The PR’s CPU-only `shadow_keep` test also passed. This verifies the refresh behavior on a second GPU and shows the 256-byte boundary when CPU and GPU writes share a piece. I did not run the game. AI-assisted with OpenAI Codex (`gpt-6.2-astra`).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-26 00:49 UTC · original

@⁠ecox982745 thank you, that is the check on a second GPU I could not make, and the second row is exactly the limit to know: the unit of comparison is the 256-byte piece, so a CPU write anywhere in a piece brings the whole piece back from the title, GPU words included. A finer piece costs more sums (8 bytes per piece, so 64-byte pieces would be 1/8 of the covered memory instead of 1/32); 256 bytes kept the measured case (16 bytes written by a compute program, nothing else in its piece written by the CPU) and the refresh cost low. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠DadaCap** on GitHub · 2026-11-26 00:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7179155616) @⁠ecox982745 thank you, that is the check on a second GPU I could not make, and the second row is exactly the limit to know: the unit of comparison is the 256-byte piece, so a CPU write anywhere in a piece brings the whole piece back from the title, GPU words included. A finer piece costs more sums (8 bytes per piece, so 64-byte pieces would be 1/8 of the covered memory instead of 1/32); 256 bytes kept the measured case (16 bytes written by a compute program, nothing else in its piece written by the CPU) and the refresh cost low. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 06:13 UTC · original · reviewed

I reproduced an overlapping-target refresh regression using the PR's ShadowPages on native Windows and an ordinary committed page. AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 06:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#pullrequestreview-6069344590) · **reviewed** I reproduced an overlapping-target refresh regression using the PR's ShadowPages on native Windows and an ordinary committed page. AI-assisted.
@ -1026,0 +1056,4 @@
const std::uintptr_t va = begin_ + at;
const std::size_t n = std::min<std::size_t>(end - at, kPage - (va & (kPage - 1)));
copy_run(page, reinterpret_cast<const std::uint8_t*>(va), n, job.streaming);
leonida::shadow_keep::copy_changed(
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 06:13 UTC · original

[P2] A shared checksum can suppress a refresh needed by a newly filled target. I refreshed target A with the CPU byte at 1, set the CPU byte to 2, added an overlapping target B and filled it, then restored the CPU byte to 1 before refreshing again. With LEONIDA_SHADOW_KEEP=1, the refresh copies zero bytes and B stays at 2. With the flag off both targets end at 1. fill() takes a fresh snapshot for B while copy_changed() compares against the snapshot shared with A. Could the first refresh reconcile the new target's snapshot or track its baseline separately? This case needs no GPU writes.

**@⁠lixonik** on GitHub · 2026-11-26 06:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#discussion_r4704533895) [P2] A shared checksum can suppress a refresh needed by a newly filled target. I refreshed target A with the CPU byte at 1, set the CPU byte to 2, added an overlapping target B and filled it, then restored the CPU byte to 1 before refreshing again. With `LEONIDA_SHADOW_KEEP=1`, the refresh copies zero bytes and B stays at 2. With the flag off both targets end at 1. `fill()` takes a fresh snapshot for B while `copy_changed()` compares against the snapshot shared with A. Could the first refresh reconcile the new target's snapshot or track its baseline separately? This case needs no GPU writes.
Author
Owner

@⁠djrolfes on GitHub · 2026-11-26 09:19 UTC · original

Independent validation on Linux/Wine + NVIDIA RTX 3070 Ti (AI-assisted):

  • Cherry-picked 4d811fcee90f9a4b4c2988117bb78be96360342d onto our local test branch (on a73a57e13 with #2222 and local RT-VSHARP-TITLE-VA-COLLISION).
  • Isolated offline Wine/Vulkan test: shadow_keep passes (5/5 focused Wine tests pass).
  • Controlled retail A/B comparison (same profile, flags, shader corpus, and warm GLCache):
    • Without #2163: slot-133 aliased shadow refreshes copied ~357 MiB per submission; hit zero-fault-address VK_ERROR_DEVICE_LOST at 281 s.
    • With #2163: slot-133 shadow copies dropped to 0.0–0.3 KiB per submission, and survival extended ~3x to 827.4 s (2,024 PresentX, 2,920 submissions, 0 memory faults, 0 Xids, 0 timed-out list-value gates) before hitting the same downstream zero-fault direct-queue stall/timeout.

No game data included.

**@⁠djrolfes** on GitHub · 2026-11-26 09:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7187798709) Independent validation on Linux/Wine + NVIDIA RTX 3070 Ti (AI-assisted): - Cherry-picked `4d811fcee90f9a4b4c2988117bb78be96360342d` onto our local test branch (on `a73a57e13` with `#2222` and local `RT-VSHARP-TITLE-VA-COLLISION`). - Isolated offline Wine/Vulkan test: `shadow_keep` passes (5/5 focused Wine tests pass). - Controlled retail A/B comparison (same profile, flags, shader corpus, and warm GLCache): - Without `#2163`: slot-133 aliased shadow refreshes copied `~357 MiB` per submission; hit zero-fault-address `VK_ERROR_DEVICE_LOST` at `281 s`. - With `#2163`: slot-133 shadow copies dropped to `0.0–0.3 KiB` per submission, and survival extended ~3x to `827.4 s` (`2,024` `PresentX`, `2,920` submissions, 0 memory faults, 0 Xids, 0 timed-out list-value gates) before hitting the same downstream zero-fault direct-queue stall/timeout. No game data included.
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-26 13:29 UTC · original

World run with this PR: RTX 4070 SUPER (12 GB), NVIDIA 621.01, Windows 11, 64 GB. Counts only.

Tree: main a73a57e13 + #1851 #1905 #1957 #1886 #1894 #1914 #1882 #2195 #2113 #1592 #2097 #2233 #2179 #2228 #2260, plus this PR, #2267 and #2230 (all clean merges). Recipe: async pipelines with prewarm, LEONIDA_COMPILE_GATE=0, a local skip list of the 1,009 ray-hit shading programs, LEONIDA_RT_AS=off, Series S device type, LEONIDA_ARENA_MB=1536, LEONIDA_TITLE_WINDOWS_MB=1024, the watchdog kicked, warm caches. F8 also sets LEONIDA_SHADOW_ALIAS_MS=1000 (quartz-heron-58's lead), so the shadow drop below comes from this PR and that setting together, not this PR alone.

Mean per-submission costs from the runtime's "submit phases" lines, over each run's last 40 lines (in the world):

run this PR SHADOW_ALIAS_MS submissions/s shadows textures heaps replay
F6 no default 3.6 80 ms 35 ms 16 ms 69 ms
F8 yes 1000 5.7 14 ms 37 ms 15 ms 526 ms
  • The world was reached in both runs (indirect graphics emitted 65,536). F8's world ran at 13-15 frames a minute from about 1,080 s; F6's ran at 1-7.
  • Replay is now the largest cost per submission in F8.
  • F8 lost the device at 1,243 s (vkWaitSemaphores, retirement), with LEONIDA_DEVICE_FAULT=0, so there is no fault report. VRAM was over the budget at the time (12.9 GB used against 10.6 GB), as in every world run on this 12 GB card. The next run repeats it with fault reporting on.
  • World rendering seen on screen in earlier runs of this recipe family; screenshot kept locally.

AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-26 13:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7193426156) World run with this PR: RTX 4070 SUPER (12 GB), NVIDIA 621.01, Windows 11, 64 GB. Counts only. **Tree:** `main` a73a57e13 + #1851 #1905 #1957 #1886 #1894 #1914 #1882 #2195 #2113 #1592 #2097 #2233 #2179 #2228 #2260, plus this PR, #2267 and #2230 (all clean merges). **Recipe:** async pipelines with prewarm, `LEONIDA_COMPILE_GATE=0`, a local skip list of the 1,009 ray-hit shading programs, `LEONIDA_RT_AS=off`, Series S device type, `LEONIDA_ARENA_MB=1536`, `LEONIDA_TITLE_WINDOWS_MB=1024`, the watchdog kicked, warm caches. F8 also sets `LEONIDA_SHADOW_ALIAS_MS=1000` (quartz-heron-58's lead), so the shadow drop below comes from this PR and that setting together, not this PR alone. Mean per-submission costs from the runtime's "submit phases" lines, over each run's last 40 lines (in the world): | run | this PR | `SHADOW_ALIAS_MS` | submissions/s | shadows | textures | heaps | replay | |---|---|---|---|---|---|---|---| | F6 | no | default | 3.6 | 80 ms | 35 ms | 16 ms | 69 ms | | F8 | yes | 1000 | 5.7 | **14 ms** | 37 ms | 15 ms | 526 ms | - The world was reached in both runs (indirect graphics emitted 65,536). F8's world ran at 13-15 frames a minute from about 1,080 s; F6's ran at 1-7. - Replay is now the largest cost per submission in F8. - F8 lost the device at 1,243 s (`vkWaitSemaphores`, retirement), with `LEONIDA_DEVICE_FAULT=0`, so there is no fault report. VRAM was over the budget at the time (12.9 GB used against 10.6 GB), as in every world run on this 12 GB card. The next run repeats it with fault reporting on. - World rendering seen on screen in earlier runs of this recipe family; screenshot kept locally. AI-assisted (Claude Code).
The sums stand for what every target holds. fill() gave a new target the title's current bytes while the sums kept
the bytes the other targets were refreshed with, so a title that wrote the old bytes back before the next refresh left
the new target behind (no piece differed from its sum). fill() now compares the filled range, widened to whole pieces,
with the sums as a refresh does: the pieces that differ are copied to every target over them and their sums updated.
New test d3d12_shadow_keep_refill (and _off with LEONIDA_SHADOW_KEEP=0): the reviewer's sequence, two overlapping
targets; it failed before this change (A held 1, B held 2) and passes now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
Author
Owner

@⁠DadaCap on GitHub · 2026-11-26 16:42 UTC · original

@⁠lixonik thank you, that was a real hole: the sums stood for what the targets held only until a new target was filled. Fixed in 71f54be48: fill() now compares the filled range, widened to whole pieces, with the sums as a refresh does, and copies the pieces that differ to every target over them before updating the sums, so a title that writes the old bytes back is seen again. Your sequence is now a test, d3d12_shadow_keep_refill (and _off with LEONIDA_SHADOW_KEEP=0): two overlapping targets, A refreshed at 1, byte set to 2, B added and filled, byte back to 1, refresh. It failed before the change (A held 1, B held 2) and passes now; shadow_keep, d3d12_title_va*, d3d12_existing_heap* and console_heap_copy pass too (9/9, RTX 5080, Windows 11).

(Reply written with Claude Code.)

**@⁠DadaCap** on GitHub · 2026-11-26 16:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7197985574) @⁠lixonik thank you, that was a real hole: the sums stood for what the targets held only until a new target was filled. Fixed in 71f54be48: `fill()` now compares the filled range, widened to whole pieces, with the sums as a refresh does, and copies the pieces that differ to every target over them before updating the sums, so a title that writes the old bytes back is seen again. Your sequence is now a test, `d3d12_shadow_keep_refill` (and `_off` with `LEONIDA_SHADOW_KEEP=0`): two overlapping targets, A refreshed at 1, byte set to 2, B added and filled, byte back to 1, refresh. It failed before the change (A held 1, B held 2) and passes now; `shadow_keep`, `d3d12_title_va*`, `d3d12_existing_heap*` and `console_heap_copy` pass too (9/9, RTX 5080, Windows 11). (Reply written with Claude Code.)
github manually merged commit bd6ba97ab6 into main 2026-11-26 17:27:24 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 17:26 UTC · original

Merging.

  • Why: a slot-133 shadow keeps what the GPU wrote until the title's bytes under it change, instead of being overwritten by our copy at every submission. 71f54be48 answers @⁠lixonik's review: a newly filled target now brings its pieces to the other targets and to the sums.
  • Tested on main 935a2cd5b + this PR, on a local merge with the same tree as b59ff4210:
    • Linux runtime ctest on the integrated RDNA2 GPU (RADV, Mesa 26.3.1): 112/112 pass, shadow_keep included.
    • Windows suite under Wine (clang-cl + xwin) on the same GPU: 421 pass and 23 fail, against 417 and 24 on main. No test went from pass to fail; shadow_keep, d3d12_shadow_keep_refill and d3d12_shadow_keep_refill_off are new and pass.
    • test_ci_registration.py, the docs tests and check_no_game_data.py pass.
  • World run: one run on the RX 7900 XTX (RADV, Wine) with this PR at d6b97a97b held 666 s to the title's own breakpoint, and the bytes copied per submission fell to about a tenth. There is no world run from b59ff4210 yet; it is the next run here.
  • Not confirmed by us: that the new refill test fails on the old head. A model of the old bookkeeping fails it.

Follow-ups, none blocking:

  • fill() reads the title's bytes twice. A write-back between the two reads leaves the new target stale; copying from the buffer reconcile read closes that.
  • When a new target moves the tracker's begin_ or end_, the piece at the old edge is summed whole and copied once over GPU writes in it. LEONIDA_SHADOW_KEEP=0 loses those writes too.
  • The docs and the README row name one limit. Missing: a CPU write brings back the whole 256-byte piece, a sum collision can miss a change, and LEONIDA_SHADOW_GPU is ignored while the keep is on.

Thanks @⁠DadaCap, @⁠lixonik for the review, and @⁠ecox982745, @⁠djrolfes and @⁠Tyrannys for the runs.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

**@⁠aslan2142** on GitHub · 2026-11-26 17:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7199020404) Merging. - **Why:** a slot-133 shadow keeps what the GPU wrote until the title's bytes under it change, instead of being overwritten by our copy at every submission. `71f54be48` answers @⁠lixonik's review: a newly filled target now brings its pieces to the other targets and to the sums. - **Tested on `main` `935a2cd5b` + this PR**, on a local merge with the same tree as `b59ff4210`: - Linux runtime `ctest` on the integrated RDNA2 GPU (RADV, Mesa 26.3.1): 112/112 pass, `shadow_keep` included. - Windows suite under Wine (clang-cl + xwin) on the same GPU: 421 pass and 23 fail, against 417 and 24 on `main`. No test went from pass to fail; `shadow_keep`, `d3d12_shadow_keep_refill` and `d3d12_shadow_keep_refill_off` are new and pass. - `test_ci_registration.py`, the docs tests and `check_no_game_data.py` pass. - **World run:** one run on the RX 7900 XTX (RADV, Wine) with this PR at `d6b97a97b` held 666 s to the title's own breakpoint, and the bytes copied per submission fell to about a tenth. There is no world run from `b59ff4210` yet; it is the next run here. - **Not confirmed by us:** that the new refill test fails on the old head. A model of the old bookkeeping fails it. Follow-ups, none blocking: - `fill()` reads the title's bytes twice. A write-back between the two reads leaves the new target stale; copying from the buffer `reconcile` read closes that. - When a new target moves the tracker's `begin_` or `end_`, the piece at the old edge is summed whole and copied once over GPU writes in it. `LEONIDA_SHADOW_KEEP=0` loses those writes too. - The docs and the README row name one limit. Missing: a CPU write brings back the whole 256-byte piece, a sum collision can miss a change, and `LEONIDA_SHADOW_GPU` is ignored while the keep is on. Thanks @⁠DadaCap, @⁠lixonik for the review, and @⁠ecox982745, @⁠djrolfes and @⁠Tyrannys for the runs. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
Author
Owner

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

I checked the remaining before/after question in the merge note on native Windows 11 with an RTX 4090, NVIDIA 616.64. The new d3d12_title_va_test --shadow-keep-refill fails consistently against the old runtime.

Runtime LEONIDA_SHADOW_KEEP=1 LEONIDA_SHADOW_KEEP=0
Before the refill fix, d6b97a97b5 0/6 passed. A held 1, B held 2. 6/6 passed. Both held 1.
Refill fix, 71f54be482 6/6 passed. Both held 1. 6/6 passed. Both held 1.
Merged main, bd6ba97ab6 6/6 passed. Both held 1. 6/6 passed. Both held 1.

I kept the regression test and its CMake registration from 71f54be482 for the old-runtime build. Its only production-file difference from its parent is runtime/shims/d3d12_vulkan_device.cpp, which I restored from that parent before rebuilding. Each table cell includes three fresh processes with Vulkan validation enabled and three with it disabled. The enabled runs reported no VUIDs. The A/B values are the bytes read back after the D3D12 queue copied the two overlapping buffers.

AI-assisted hardware verification with OpenAI Codex (GPT-6).

**@⁠ecox982745** on GitHub · 2026-11-26 17:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2163#issuecomment-7199765330) I checked the remaining before/after question in the [merge note](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/2163) on native Windows 11 with an RTX 4090, NVIDIA 616.64. The new `d3d12_title_va_test --shadow-keep-refill` fails consistently against the old runtime. | Runtime | `LEONIDA_SHADOW_KEEP=1` | `LEONIDA_SHADOW_KEEP=0` | | --- | --- | --- | | Before the refill fix, `d6b97a97b5` | 0/6 passed. A held 1, B held 2. | 6/6 passed. Both held 1. | | Refill fix, `71f54be482` | 6/6 passed. Both held 1. | 6/6 passed. Both held 1. | | Merged main, `bd6ba97ab6` | 6/6 passed. Both held 1. | 6/6 passed. Both held 1. | I kept the regression test and its CMake registration from `71f54be482` for the old-runtime build. Its only production-file difference from its parent is `runtime/shims/d3d12_vulkan_device.cpp`, which I restored from that parent before rebuilding. Each table cell includes three fresh processes with Vulkan validation enabled and three with it disabled. The enabled runs reported no VUIDs. The A/B values are the bytes read back after the D3D12 queue copied the two overlapping buffers. AI-assisted hardware verification with OpenAI Codex (GPT-6).
This discussion has been locked. Commenting is limited to contributors.
No description provided.