Repository navigation
d3d12/vulkan + rdna2spirv: staged VRAM arena, DMA readback batching, parallel shadows, stream-pool fix & wave64 perf (RT-ARENA-DEVICE-LOCAL-STAGED) - #2865
Conversation
KelboLive
left a comment
There was a problem hiding this comment.
The arena/readback/shadow work looks directionally sound, and the translator side reproduces exactly here: scripts/run_semantic_tests.py tests/semantic = 555 files, 6,727 tests, 0 failed; test_lane_masks, semantic/test_ballot_bit_loop, semantic/test_mesh_native_wave32, test_text_write_line_endings pass; arena_staging_test.cpp compiles and runs (MSVC 14.44, /std:c++20 /W4 /permissive-, Vulkan SDK 1.4.363); check_no_game_data clean on all 14 changed files.
Two blockers.
- The staged slabs are not a budgeted pool.
TitleBufferWindowsallocates a full 64 MiB slab for every staged allocation (d3d12_title_buffer_windows.h:27,:258), never destroys one when it goes empty (:449), counts only the VRAM half inreserved_(:390), and its host mirror is allocated with nomemory_breakdown::Owner(:298-305) — outside both the budget and the memory report.d3d12_vulkan_device.cpp:4567passescap = UINT64_MAX. A title that churns large windows can accumulate 64 MiB VRAM + 64 MiB sysmem per slab without a cap, and the main arena's staging mirror is a second full-size allocation that is not part of its budget either. - The Windows test expectations were not updated.
d3d12_existing_heap_test.cpp:3699,:3707and:3722still asserttitle_shadow_refresh_queries(...) == 1for the reserved (uncommitted) tail. Withunchanged()now skippingkZeropages (d3d12_vulkan_device.cpp:1161-1163), that tail is skipped and the count is 0. Only the other test's expectation (:839) was changed — so the Windows GPU test was built, not run.
Unmentioned semantic reversal. This diff also drops the geometry.cap() gate on the GPU console-heap pass (:10890), rewrites T# index words on the GPU (:11586, :11635-11637), and flips vsharp_address's fourth argument to !geometry.cap() (:11794). That reverses the documented invariant "the pass does not write the T# index word the shaders read; heaps are fixed on the CPU" and has no dedicated test. It belongs in the description at minimum.
Claims. wb 27.62 → 1.75-2.35 ms, shadows 26.91 → 10.2-11.1, before-execute 70-75 → 21.8-22.9 are credible and name a machine (RTX 3090, non-ReBAR, GE-Proton, 590.48.01). The 0.40 → 4.80-5.00 fps (~12.5x) is a composite of arena + readback batching + parallel shadows + --compute-serial-waves + --spirv-opt, with no per-change attribution. And those flags cannot be requested through make_game.py: FALLBACK_FLAGS (make_game.py:2016-2021) is a closed allowlist with no argparse options for --compute-serial-waves, --spirv-opt or --mesh-native-wave32, and they are not recorded in translator_flags.txt, so a make_game.py shaders re-run would silently drop them. --spirv-opt's help still says 750 KiB while SPIRV_OPT_LARGE_BYTES = 512 * 1024 (tools/rdna2spirv.py:23960 vs :23726), and the new docs/design.md row says 551 files / 6,680 tests (stale).
Readback ordering is sound (sorted/coalesced, only retired tickets), but two things to note: the DMA copy is ordered against the producer only by the host-side completion check, not a semaphore (:5217, :6460-6470), and Map() can block the graphics queue up to 5 s (vulkan_backend.h:38) while sync_retired_readbacks_to_host runs under shadow_mutex (:5250-5268) — a shadow_mutex -> submit_mutex_ order not in the documented hierarchy.
Please split it. Land the console-heap T#/geometry.cap() rework as its own PR first — it reverses a documented invariant, has no test, and is unmentioned. Keep arena staging + readback batching + shadow parallelism as a second PR, with arena_staging_test (it passes here) plus a unit test for the slab accounting and the corrected Windows expectations.
|
Thanks for the thorough review @KelboLive! Addressed all the technical points in
|
…ows, stream-pool fix On top of PR ProjectLeonida#2566 (8db8335), combines verified runtime performance and correctness improvements for non-ReBAR Vulkan GPUs (tested on Linux / Wine / RTX 3090 24 GB, BAR1 = 246 MiB, driver 590.48.01): - Stage 4 GiB GPU address arena + overflow TitleBufferWindows slabs in DEVICE_LOCAL VRAM with HOST_VISIBLE staging mirrors (arena_staging.h, arena_staging_test.cpp). - Fix startup glibc realloc() race by caching max_compute_shared_memory_size, sharing mutex-guarded VkPipelineLayouts, and eagerly loading pipeline_cache() during single-threaded Device construction. - Stage 9a-1: batch retired arena + external window host readbacks into a single copy_buffers_sync() submission on the dedicated DMA copy queue (wb: 27.6 ms -> 2.35 ms/frame). - Stage 9a-2: parallelize ShadowPages::refresh across 4 persistent threads via ShadowRefreshPool (shadows: 26.9 ms -> 10.2 ms/frame). - Fix resolve_pool_memory() zeroing out root descriptors probed with kRootViewBytes (64 KiB) near the end of committed stream-pool blocks (stream pool unbacked: 131,072 -> 16-33, root view unbacked: 0). AI-assisted. Verified with 151/151 portable Linux CTest passing and Windows MSVC build + retail boots on RTX 3090 (590.48.01).
…e32, --spirv-opt On top of PR ProjectLeonida#2566 (8db8335), combines verified translator performance and correctness improvements for NVIDIA Wave32 GPUs (tested on RTX 3090 24 GB, driver 590.48.01): - Cherry-pick PR ProjectLeonida#2501 lane_masks.insert_data_merges (TO_DATA) fixing lib_cs_03010 bit-scanning loops (91-370 ms/call -> < 2.5 ms/frame). - Add --compute-serial-waves for >64-thread barrier/LDS/atomic-free compute shaders (lib_cs_00977 + lib_cs_00986: 160 ms/frame -> < 2.4 ms/frame) while preserving unmodified PR ProjectLeonida#2566 d88b2de VulkanMemoryModel coherency. - Add --mesh-native-wave32 for strictly partition-invariant mesh shaders (9,116 / 9,282 dxbc MS shaders), running all threads natively in 1 Wave32 pass with zero %x_buf LDS/barriers (-13% to -35% on hot mesh shaders). - Add --spirv-opt (-O below 750 KiB, safe SSA pass set at >= 750 KiB to avoid NVIDIA 590.48.01 --scalar-replacement=0 compiler segfaults, with automatic fallback + spirv-val check). AI-assisted. Verified with semantic tests and retail boots on RTX 3090 (590.48.01).
…-spirv-opt SSA threshold to 512 KiB - Exclude v_readfirstlane from --mesh-native-wave32 until per-use uniformity analysis proves the source wave-uniform (with ms_native_readfirstlane.asm and test_mesh_native_wave32.py regression test + docs/design.md update). - Lower SPIRV_OPT_LARGE_BYTES from 750 KiB to 512 KiB so library/lib_cs_03245 and siblings use the safe SSA pass set instead of --scalar-replacement=0 (avoiding NVIDIA 590.48.01 compiler SIGSEGV during warmup). AI-assisted.
…test fixes & CLI wiring
57579a3 to
8ebe7cc
Compare
|
I rebuilt Win64 Release from the current head 8ebe7cc. With staging enabled, the unmodified arena_staging_test and d3d12_existing_heap_test passed under Wine 11.22 on Radeon Raphael (RADV 26.3.1) and RTX 4070 SUPER (620.73.04). The heap suite reached the Vulkan shadow and guarded-page stress cases. Its Microsoft host-D3D12 comparisons were skipped under Wine. The runtime subtree is identical after a clean merge onto 43c7b34. A separate staging-map failure injection exposed a remaining fallback issue on both devices. I wrapped the Vulkan calls for a 64 MiB staged arena, forced only the first vkMapMemory of the staging mirror to return VK_ERROR_MEMORY_MAP_FAILED, and intercepted a second bind of the same arena buffer before forwarding to the driver. On stock 8ebe7cc the counters were 1 staging refusal, 1 successful arena bind, 1 duplicate bind attempt and no mapped host fallback. The successful permanent arena bind precedes the failed staging map. In a local test patch, I completed staging setup before binding the arena buffer. Both devices then reported 1 refusal, 1 successful bind, zero duplicate attempts and a mapped host fallback. The same setup ordering can be used for external staged windows. My injected device-creation case covers the main arena. MEASURED with a synthetic frame-free device. AI-assisted (Codex). |
…LEONIDA_EXTERNAL_WINDOWS_MB
|
Great catch @merzleckeier — thank you for testing on both RADV (Radeon Raphael) and RTX 4070 SUPER and catching that bind-order fallback bug! Fixed in
|
|
Retested the fix at 4a305d0 merged into 88a9f13 on Radeon Raphael (RADV 26.3.1) and RTX 4070 SUPER (620.73.04), Win64 Release under Wine 11.22. The stock arena_staging_test, including the new external-slab failure case, and d3d12_existing_heap_test passed on both GPUs. Under Wine the latter skips Microsoft host-D3D12 comparisons. I also checked both main-arena fault paths on both GPUs. Repeating the original forced staging map refusal gave zero duplicate binds and a mapped host fallback. In a separate injection I let the staging mirror map successfully, then failed the first VRAM bind of the arena before forwarding it. The PR unmapped staging exactly once before mapping the host fallback, with one successful arena bind and zero duplicate attempts. The original symptom is fixed in this repro. MEASURED with synthetic fault injection on physical GPUs. AI-assisted (Codex). |
Claimed in the coordination issue as: RT-ARENA-DEVICE-LOCAL-STAGED (#2570)
Depends on: #2501 (included in this branch — see note below)
What and why
Brings RTX 3090 retail performance from 0.40 fps → 4.80–5.00 fps (non-ReBAR
BAR1 = 256 MiB, ~12.5× composite speedup) and from 3.78 fps → 4.60 fps (+22% on 32 GiB ReBAR withLEONIDA_DEVICE_LOCAL_ARENA=1), fixes intermittently missing world/character meshes caused by unbacked stream-pool root views, and adds aHOST_CACHEDDMA readback path for uncached ReBAR BAR1 memory.Runtime (
d3d12_vulkan,vulkan_backend,arena_staging,d3d12_title_buffer_windows)DEVICE_LOCALVRAM arena & budgeted overflow slabs (runtime/src/arena_staging.h,runtime/shims/d3d12_title_buffer_windows.h,runtime/test/arena_staging_test.cpp): Keeps the 4 GiB GPU address arena and overflowTitleBufferWindowsslabs inDEVICE_LOCALVRAM paired with aHOST_CACHEDstaging mirror (LEONIDA_DEVICE_LOCAL_ARENA=auto|1|0), avoiding host-visible sysmem fallback on non-ReBAR GPUs and also beating direct WC BAR1 on 32 GiB ReBAR (+22%FPS). Both VRAM (Consumer::windows) and host staging (Consumer::staging) bytes are tracked inmemory_breakdown::Ownerand counted againstreserved_and a bounded cap (LEONIDA_EXTERNAL_WINDOWS_MB, default 4 GiB total staged / 2 GiB unstaged); empty staged slabs beyond 1 spare are reclaimed.RebarReadbackScratch+ShadowPages::ReadbackLookup): When running unstaged on ReBAR (DEVICE_LOCAL | HOST_VISIBLEwithoutHOST_CACHED),ShadowPages::write_backpreviously read directly from WC BAR1 viastd::memcmp/memcpy(wb = 62.9–165.0 ms). Now batches retired ranges viacopy_buffers_syncinto aHOST_VISIBLE | HOST_COHERENT | HOST_CACHEDscratch buffer (Consumer::staging), dropping ReBAR menu/loadwbfrom62.9–165.0 ms → 0.01–1.17 ms(loading FPS6.04 → 18.3–29.3 fps).VulkanContext::copy_buffers_sync,TitleBufferWindows::collect_host_readbacks): Batches retired host readbacks into one command buffer submission per family viareadback_channels_, cutting stagedwbfrom27.62 ms → 1.56–2.35 ms/frame(-91.5%). (Lock order: callers holdshadow_mutex,copy_buffers_syncacquiressubmit_mutex_; no path acquiresshadow_mutexundersubmit_mutex_.)ShadowRefreshPool(d3d12_vulkan_device.cpp): Persistent 3-helper + caller-thread pool parallelizingShadowPages::refreshacross independent trackers, cuttingshadowsfrom26.91 ms → 10.2–11.1 ms/frame(-62%) and totalbefore-executefrom70–75 ms → 21.8–22.9 ms/frame(-68%).d3d12_vulkan_device.cpp): Cachesmax_compute_shared_memory_size, mutex-guards the sharedVkPipelineLayout, and loadspipeline_cache()eagerly (0 startup crashes across 25+ boots).resolve_pool_memory,d3d12_vulkan_device.cpp): ClampskRootViewBytes = 65536root-view probes to the committed stream-pool block while preservingvsharp_addressroom < byteschecks, droppingstream pool: ... got no GPU copyfrom131,072 → 16–33(root viewunbacked =0) and restoring missing world/character meshes.geometry.cap()(d3d12_vulkan_device.cpp): Drops thegeometry.cap()gate onLEONIDA_CONSOLE_HEAP_GPU=1/LEONIDA_CONSOLE_HEAP_ARENA=1so the GPU console-heap pass and T# index word updates can run withLEONIDA_GEOMETRY_MB=0, and flipsvsharp_address's fourth argument to!geometry.cap().Shader translator & build wiring (
tools/lane_masks.py,tools/rdna2spirv.py,make_game.py,docs/design.md)TO_DATAmerges (tools/lane_masks.py,tests/semantic/test_ballot_bit_loop.py): Insertss_mask_to_data_b32at CFG merges where a lane mask meets scalar data; documented indocs/design.md. Fixeslib_cs_03010(91–370 ms/call → < 2.5 ms/frame).--compute-serial-waves(opt-in, default off): Serializes wave64-emulated compute loops while preservingVulkanMemoryModelcoherency; fixeslib_cs_00977+lib_cs_00986(160 ms/frame → < 2.4 ms/frame).--spirv-opt(opt-in, default off): Runsspirv-opt -Obelow512 KiBand safe SSA passes at>= 512 KiB, with automatic fallback andspirv-valverification.--mesh-native-wave32(opt-in, default off) +v_readfirstlaneguard (tests/semantic/ms_native_readfirstlane.asm,tests/semantic/test_mesh_native_wave32.py).make_game.pywiring: Added--compute-serial-waves,--mesh-native-wave32, and--spirv-opttoFALLBACK_FLAGSand CLI somake_game.py shadersforwards and records them intranslator_flags.txt.Tested
python3 -I scripts/run_semantic_tests.py tests/semanticon rebasedmain4009a3426):555 files, 6,727 tests, 0 failurescheck_no_game_data.py(all 15 touched files clean),compileall,make_game.py --help,tests/test_text_write_line_endings.py(3/3),tests/test_lane_masks.py(ok),test_ballot_bit_loop.py(2/2),test_mesh_native_wave32.py(4/4)leonida-dev):160 / 160 passed, 0 failures(includingarena_stagingwithtest_staged_slab_budget_and_reclamation)clang-cl+xwinSDK):gta6rt.exe,arena_staging_test.exe, andd3d12_existing_heap_test.exebuilt and linked with exit 0arena_staging_test.exe: PASSd3d12_existing_heap_test.exe: PASS (vulkan slot-133 shadow adopts geometry_writes read-only guard: ok,vulkan slot-133 heap-lock faults: 20272 submissions ... no deadlock)47,840 / 47,840translated andspirv-val-valid (0regressions)590.48.01, 1080pPROFILE=0):BAR1 = 256 MiB, staged arena + DMA readback + parallel shadows +--compute-serial-waves+--spirv-opton 4,131 active shaders):0.40 fps → 4.80–5.00 fps(50 frames / 10.1 s)wb):27.62 ms → 1.75–2.21 ms/frame(-91.5%)ShadowRefreshPool(shadows):26.91 ms → 10.65–11.11 ms/frame(-62%)before-execute:70–75 ms → 21.8–22.9 ms/frame(-68%)TO_DATA(lib_cs_03010):91–370 ms/call → < 2.5 ms/frame--compute-serial-waves(lib_cs_00977+lib_cs_00986):160 ms/frame → < 2.4 ms/framemain4009a3426):wb 62.91–165.04 ms,6.04 fpsloadingRebarReadbackScratch:wb 0.01–1.17 msloading (18.3–29.3 fps),3.75–3.80 fpssteady-state world (before-execute 49.1–50.8 ms,wb 21.45–22.60 ms,lists 24.2–26.3 ms)LEONIDA_DEVICE_LOCAL_ARENA=1:4.54–4.60 fpssteady-state world (+22% over ReBAR direct;before-execute 25.15–27.27 ms,wb 1.56–2.02 ms,lists 3.55–4.49 ms,0crashes /0DEVICE_LOST)GPUs tested: NVIDIA GeForce RTX 3090 24 GB (both non-ReBAR
BAR1 = 256 MiBand 32 GiB ReBAR), driver 590.48.01, Linux (GE-Proton)AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.