d3d12/vulkan + rdna2spirv: staged VRAM arena, DMA readback batching, parallel shadows, stream-pool fix & wave64 perf (RT-ARENA-DEVICE-LOCAL-STAGED) #2865
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2865
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/rtx3090-vram-perf-and-translator"
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 successfully merged and closed
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.Thanks for the thorough review @KelboLive! Addressed all the technical points in
57579a34dand updated the PR description (keeping this as one PR for now):TitleBufferWindowsnow tags VRAM allocations withmemory_breakdown::Consumer::windowsand host staging mirrors withConsumer::staging, counts both VRAM + host staging bytes inreserved_against a bounded cap (LEONIDA_EXTERNAL_WINDOWS_MB, default 4 GiB total staged / 2 GiB unstaged instead ofUINT64_MAX), and reclaims empty staged slabs beyond 1 spare. Addedtest_staged_slab_budget_and_reclamationinarena_staging_test.cpp.d3d12_existing_heap_test.cpp:3699, 3707, 3722to== 0for the skippedkZeroreserved tail, and ran botharena_staging_test.exeandd3d12_existing_heap_test.exelive under Proton on RTX 3090 — both pass (vulkan slot-133 shadow adopts geometry_writes read-only guard: ok,vulkan slot-133 heap-lock faults: 20272 submissions ... no deadlock).geometry.cap(): Documented explicitly in the PR description (enablesLEONIDA_CONSOLE_HEAP_GPU=1/LEONIDA_CONSOLE_HEAP_ARENA=1withLEONIDA_GEOMETRY_MB=0).--compute-serial-waves,--mesh-native-wave32, and--spirv-optintomake_game.py'sFALLBACK_FLAGSand CLI (recorded intranslator_flags.txt), fixed--spirv-opthelp text (512 KiB), updateddocs/design.mdtest counts (555 files, 6,727 tests), and broke out per-component timing attribution in the PR description.63–165 msWC BAR1 readback stall in unstagedShadowPages::write_backand addedRebarReadbackScratch(Consumer::staging) +ShadowPages::ReadbackLookupso unstaged ReBAR readbacks usecopy_buffers_synctoo (and verifiedLEONIDA_DEVICE_LOCAL_ARENA=1still beats ReBAR direct by +22% FPS in world:3.78 -> 4.60 fps).I rebuilt Win64 Release from the current head 8ebe7cc2. 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 43c7b343a.
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 8ebe7cc2 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).
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
4a305d066:d3d12_vulkan_device.cpp) and external staged slabs (d3d12_title_buffer_windows.h) now bind and map the staging buffer first and only callvkBindBufferMemoryon the VRAM buffer aftervkMapMemorysucceeds (unmapping staging cleanly if the VRAM bind itself fails). Added avkMapMemoryfailure-injection check totest_staged_slab_budget_and_reclamationinarena_staging_test.cppasserting every buffer is bound at most once on host fallback.test_docs_env_vars.py): DocumentedLEONIDA_EXTERNAL_WINDOWS_MBindocs/d3d12_vulkan.md(test_docs_env_vars.py5/5 OK).Retested the fix at 4a305d06 merged into 88a9f133e 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).