Repository navigation
d3d12: track live console-heap V# slots in a host-RAM bitset (RT-CONSOLE-HEAP-VSHARP-BITSET) - #1887
Conversation
|
Retail evidence for the root cause here, from a local change of the same shape (a per-slot byte map of live V#s in host memory instead of the scan of
The average per submission outside those spikes did not change (about 3.4 ms): that is the copy of the part of the heap under a slot-133 import (27,648 KiB, pinned pages), a different cost. One run each, the second with more captures written. I had planned to send mine and won't, yours was claimed first; note that this one is |
When released_backings or title_va_aliases().invalidations() advances, refresh_console_heap() previously scanned all 32-byte slots of heap.copy linearly to find live buffer V#s (!(w[3] >> 30) && (w[2] || w[6])). When heap.copy sits in arena.mapped (uncached write-combined GPU memory), each buffer release triggered ~180k uncached PCIe reads across a 5.5 MiB heap. Add a portable host-RAM bitset (leonida::ConsoleHeapVsharpSlots in runtime/src/console_heap_vsharp_slots.h) updated at every resource-heap write to heap.copy (fix_console_slot, deferred fix_over zeroing, for_each_zeroed, and add_console_heap reset), and iterate only live V# slots during invalidation passes (0 reads from heap.copy; 64 slots skipped per word via std::countr_zero). Item: RT-CONSOLE-HEAP-VSHARP-BITSET
36d1e08 to
3233b98
Compare
…1887) & staging pool (#781) Wave 11D fixes four d3d12_vulkan_device.cpp hot-path regressions (GPL-3.0, zero non-trivial thread_local): 1. Page-dirty-only console descriptor heap diff + AVX2/SSE2 compare: - Extend leonida::title_shadow::Shadow::refresh() (runtime/src/title_shadow_sync.h) with optional std::vector<DirtyRange>* output recording exact changed 64 KiB page slices (page index, byte offset/length, zeroed flag). - Update DeviceState::refresh_console_copy() to scan ONLY changed 64 KiB pages (instead of all 32 MiB / 1M slots when 1 page changes), skip zeroed pages on initial refresh, fast-clear aligned zeroed pages, and compare 32-byte descriptors via AVX2/SSE2 (equal_descriptor_32 / is_zero_descriptor_32) instead of scalar memcmp. 2. Eliminate uncached WC arena.mapped reads in scan_title_table & host-RAM V# bitset: - Add leonida::ConsoleHeapVsharpSlots (runtime/src/console_heap_vsharp_slots.h, adapted from ubiquitarianism/leonida#1887, author IlyassRS3) tracking live console-heap buffer V# slots in L1-resident host RAM. - Skip console heaps in scan_title_table() (already refreshed & sanitized from cached host RAM by refresh_console_heaps() in before_execute_()). - Add a 128-entry per-submission epoch span cache for layer shader-visible heaps (invalidated on before_execute_(), heap create/destroy, and arena descriptor API writes) and stream-copy cache misses from WC arena.mapped via SSE4.1 MOVNTDQA (_mm_stream_load_si128) in 64-slot chunks, writing back only modified slots. 3. Bounded LIFO size-classed texture upload staging buffer pool: - Adapted from fxceless/victory-fork#781 (GPL-3.0, author marquezinii): 256 MiB cap, 64 KiB steps up to 1 MiB then 8 steps/power-of-two, separate upload vs cached-readback buckets, LIFO reuse, fullest-class oldest eviction outside the pool lock, and clean teardown in ~Device(). Note: ubiquitarianism/leonida#1926 (TitleImagePool / vulkan_title_image_pool.h) does not apply because leonida-ultimate uses VulkanSuballocator (vulkan_suballoc.h, outside W11D file boundary). Verified (RTX 3080, VK_VALIDATION=1, 0 validation errors): - 6/6 GPU CTests passed: d3d12_vulkan_device, d3d12_xmem_shadow, d3d12_unmapped_vsharp, d3d12_subresource_copy, d3d12_console_descriptor_heap, d3d12_console_table_draw - Dirty-page scan: 1-slot write in 16-page heap scanned 1 page (2,048 / 32,768 slots); idle submit scanned 0 pages - Staging pool: 1 created / 3 reused in d3d12_unmapped_vsharp; 2 created / 38 reused in d3d12_subresource_copy - title_shadow_sync_test: 16/16 new dirty-range & ConsoleHeapVsharpSlots checks passed (84/85 total; 1 pre-existing line-139 coalesced-run split check from 8cd13ce) - check_no_game_data.py: 0 violations; test_docs_env_vars.py: 4/4 OK
|
Independent test report for 3233b98 (VERIFY-1887-1957-BLACKWELL, claimed in #1608). Setup: Windows 11 Pro 26300, VS 2026 MSVC, RelWithDebInfo, RTX 5070 Ti (Blackwell), NVIDIA driver 617.42, Full CTest (
The one new test, Repeat runs: AI-assisted (Claude Code, Claude Opus 5.5). |
|
Measured on Windows 11 with an NVIDIA RTX 5090 (driver 32.0.16.2124), retail boot past the opening credits, runtime of current main plus #1867 and a local debug overlay, 900 s runs with the same scripted input, from the
The invalidation rescans still run (982 in the run with #1887); they are simply cheap once they no longer read the write-combined heap copy. I also tried filtering those rescans to the slots that name a released range on top of this PR: no further gain, so this PR alone is the fix. AI-assisted: yes. |
|
Independent run on Windows 10 19045, GTX 1050 Ti (Pascal, 4 GB, no Resizable BAR), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo. Base
AI-assisted (Claude Code). |
|
Independent Wine/RADV report for
Fedora 45, AMD Radeon RX 6700 XT (NAVI22), Mesa RADV 26.2.7, Wine Staging 11.21. A Windows Vulkan probe enumerated only AMD
Synthetic tests only. No retail run or frame-rate measurement. AI-assisted (Codex). Coordination claim. |
|
Correction to the measurement above. The run with this PR recorded 2,725 successful presents in 902 seconds. The reported 5,450 counted each present twice because both the presentation and command queue trace layers reported it. The comparison run recorded 1,225 successful presents in 902 seconds. The 2,725-present run also used different refresh and rescan settings from the comparison run, so the present totals describe the two configurations. They do not isolate this PR's effect. AI-assisted: yes. |
|
Merged, thanks! Maintainer review of
AI-assisted (Claude Code, Claude Opus 5.5). |
Item:
RT-CONSOLE-HEAP-VSHARP-BITSETClaim: #1608 (comment)
Summary
Eliminates uncached write-combined GPU memory reads from
heap.copyduring console resource-heap invalidation scans inrefresh_console_heap()(runtime/shims/d3d12_vulkan_device.cpp).released_backingsortitle_va_aliases().invalidations()advanced,refresh_console_heap()scanned every 32-byte slot ofheap.copylinearly (for (size_t at = 0; at + kDescriptorSize <= heap.bytes; at += kDescriptorSize)) checking!(w[3] >> 30) && (w[2] || w[6]). Whenheap.copyfalls back toarena.mapped(uncached WC GPU memory — e.g. whenimport_console_heapcannot land within 4 GiB ofarena.addressor host-memory import is unavailable), reading 4–5.5+ MiB of WC memory triggers ~130k–180k uncached PCIe reads per buffer release (hundreds of ms/submission); even in cached scratch memory it linearly scans all empty and T# slots.leonida::ConsoleHeapVsharpSlots(runtime/src/console_heap_vsharp_slots.h), a dense host-RAMuint64_tbitset (~22 KiB for a 5.5 MiB heap, L1-resident) with O(1)empty()fast path,clear_range()for zeroed page runs,std::countr_zeroiteration safe against in-place bit clears inside the callback, andis_live_vsharp(w)matching the exact legacy predicate!(w[3] >> 30) && (w[2] || w[6]).heap.live_vsharpssynchronized at every resource-heap write toheap.copy:add_console_heap(reset),fix_console_slot(set),fix_console_slotsdeferred zeroing (clear), andfor_each_zeroed(clear_range).heap.live_vsharps.for_each(...)inrefresh_console_heapinstead of readingheap.copy.No overlap with
#1728or#1867.Verification
d3d12_vulkan_device.cppis Windows-only and verified by inspection + Windows CI)runtime/test/console_heap_vsharp_slots_test.cpp(CTestconsole_heap_vsharp_slots), including a 4,000-step differential model against a linear 32-byte slot buffer (fix_console_slot,not_tsharp, deferred zeroing,clear_range, in-place invalidation clears) and 5.5 MiB sparse heap check:clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=address,undefined: passedclang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=thread: passedclang++ -std=c++20 -Wall -Wextra -Werror -O2(3 runs): passed-O2on Apple Silicon): linear scan60.30 usvs bitset0.93 us(64.9x faster even in cached RAM; eliminates 100% of WC reads fromheap.copywhenheap.copyis inarena.mapped)python3 -I scripts/check_no_game_data.pyon all changed files: passedpython3 -I tests/test_text_write_line_endings.py: passed (3 tests)