mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #2163] [MERGED] d3d12: a slot-133 shadow keeps the GPU's writes where the title's bytes did not change (RT-SHADOW-KEEP-GPU-WRITES) #2166
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2166
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2163
Author: @DadaCap
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142
Base:
main← Head:shadow-keep-gpu-writes📝 Commits (5)
0ebd428d3d12: a slot-133 shadow keeps the GPU's writes where the title's bytes did not change (LEONIDA_SHADOW_KEEP)4d811fcMerge remote-tracking branch 'origin/main' into shadow-keep-gpu-writesd6b97a9Merge main into shadow-keep-gpu-writes: shadow_keep and console_heap_copy tests side by side in CMakeLists71f54beshadow keep: a newly filled target brings its pieces to the other targets and the sums (review by lixonik)b59ff42Merge main into shadow-keep-gpu-writes: main removed the console heap mirror test (#2370); the shadow_keep test stays📊 Changes
7 files changed (+374 additions, -4 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+9 -0)📝
runtime/CMakeLists.txt(+12 -0)📝
runtime/README.md(+1 -0)📝
runtime/shims/d3d12_vulkan_device.cpp(+77 -4)➕
runtime/src/shadow_keep.h(+72 -0)📝
runtime/test/d3d12_title_va_test.cpp(+62 -0)➕
runtime/test/shadow_keep_test.cpp(+141 -0)📄 Description
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7178046531
Depends on: none. It merges cleanly with current
main(which now includes #2098), and conflicts with #1897 and #1867. #1897 movesShadowPagestoruntime/src/shadow_pages.h, so itsd3d12_vulkan_device.cpphunks conflict. #1867 conflicts only in itsruntime/README.mdrow next to this one. Whichever lands second redoes those lines. It merges cleanly with #2032 and #2129.What and why
ShadowPagescopies 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_changedcompares 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.forgetclears sums so their pieces get copied again.ShadowPageskeeps the sums (sums_, per piece from its first page; grown byextend, carried over byabsorb). WithLEONIDA_SHADOW_KEEPon (the default), every copy job reads the title's page once into a buffer (still through the guardedcopy_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=0restores the old behaviour (every job copied whole). There is a row for it inruntime/README.mdand a paragraph indocs/d3d12_vulkan.mdunder the copies.Limits:
Tested
New
shadow_keep_test(ctestshadow_keep, CPU only, no GPU and no game data). The title and the copy are arrays with made-up bytes:It passes with the change (
shadow_keep: OK). Withcopy_changedchanged 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 withctest. 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_boundsandvk_host_at_aliasing. Thed3d12_*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.pyon 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
mainplus 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
mainwith #2098, plus this change), the same retail scene, 420 s each, one run per setting, over the same 150-300 s window:LEONIDA_SHADOW_KEEP0(as before)On
mainmost 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; withLEONIDA_SHADOW_KEEP=0that path is as onmain. 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator rule)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.