Repository navigation
d3d12: a slot-133 shadow keeps the GPU's writes where the title's bytes did not change (RT-SHADOW-KEEP-GPU-WRITES) - #2163
Conversation
…es did not change (LEONIDA_SHADOW_KEEP) 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
# Conflicts: # runtime/shims/d3d12_vulkan_device.cpp
|
On an RTX 4090, the next submission preserved 64/64 GPU-written words with the default setting and 0/64 with
To reproduce, I extended All eight combinations of tracking mode, feature setting and Vulkan validation matched the table on both page types. The PR’s CPU-only AI-assisted with OpenAI Codex ( |
|
@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). |
lixonik
left a comment
There was a problem hiding this comment.
I reproduced an overlapping-target refresh regression using the PR's ShadowPages on native Windows and an ordinary committed page. AI-assisted.
| 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( |
There was a problem hiding this comment.
[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.
…pump coalescing & 16-bit/indirect completeness (Wave 29A) Adapts and integrates: - GPU-to-CPU title-window write-back with retire-ticket fencing, xmem dirty-stamp + byte-level CPU-write precedence, and LEONIDA_TITLE_WRITEBACK=0 kill switch (ubiquitarianism/leonida#2129, GPL-3.0). - Slot-133 shadow GPU-write preservation via 256-byte piece sums (LEONIDA_SHADOW_KEEP, ubiquitarianism/leonida#2163, GPL-3.0), saved-snapshot advancement after partial merge (Marvisak/VIctory#3031, GPL-3.0), and read-only hash skip for foreign PAGE_READONLY pages (ubiquitarianism/leonida#1897, GPL-3.0). - Held-batch fence-pump fix: snapshot has_shader_work / internal_staging on ExecuteCommandLists thread in VulkanQueue::Deferred and coalesce redundant back-to-back refresh_shadows() / refresh_console_heaps() inside a single QueueHolds::pump_ready() sweep when xmem epochs and shadow registry are unchanged. - Transient dedicated command-pool renewal for long recordings above LEONIDA_CMD_POOL_RENEW (default 512, Rubenpannen/VIctory-RTX5070@5df4fb3, GPL-3.0). - Complete 16-bit packed colour widening for B5G6R5_UNORM RT/UAV, B4G4R4A4_UNORM RT/UAV, and B5G5R5A1_UNORM RT/UAV (Marvisak/VIctory#2936, GPL-3.0; californiaAlmonds/OpenScarlett@ee7153c, MIT). - Compound graphics ExecuteIndirect host-visible expansion, Tier 1.1 incrementing-constant stride fix, and D3D12 state-leakage binding reset (ubiquitarianism/leonida#1937, GPL-3.0). AI-assisted; verified on NVIDIA GeForce RTX 3080 (Windows 11, VS 18 MSVC 19.51) with LEONIDA_VK_VALIDATION=1 (18/18 CTests passed, 0 validation errors).
|
Independent validation on Linux/Wine + NVIDIA RTX 3070 Ti (AI-assisted):
No game data included. |
|
World run with this PR: RTX 4070 SUPER (12 GB), NVIDIA 621.01, Windows 11, 64 GB. Counts only. Tree: Mean per-submission costs from the runtime's "submit phases" lines, over each run's last 40 lines (in the world):
AI-assisted (Claude Code). |
…copy tests side by side in CMakeLists Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
…gets and the sums (review by lixonik) 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
|
@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 71f54be: (Reply written with Claude Code.) |
… mirror test (ProjectLeonida#2370); the shadow_keep test stays Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
|
Merging.
Follow-ups, none blocking:
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) |
|
I checked the remaining before/after question in the merge note on native Windows 11 with an RTX 4090, NVIDIA 616.64. The new
I kept the regression test and its CMake registration from AI-assisted hardware verification with OpenAI Codex (GPT-6). |
One conflict, runtime/README.md: this branch rewrote the LEONIDA_SHADOW_ALIAS_MS row, main (ProjectLeonida#2163) added the LEONIDA_SHADOW_KEEP row after it. Both rows kept; the keep row's "aliased" now reads "aliased while they can't be guarded at every address", since aliased pages are no longer copied without a sign of a write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: #1608 (comment)
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 Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) #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 Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) #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