d3d12_vulkan: without Resizable BAR, textures and staging buffers leave the BAR window to the arena; tile heaps prefer VRAM (RT-ALLOC-NO-REBAR-RETRIES) #1681
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!1681
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-alloc-no-rebar"
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-ALLOC-NO-REBAR-RETRIES — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156470795
What and why
On a card without Resizable BAR the DEVICE_LOCAL | HOST_VISIBLE memory type sits in a heap of about 256 MiB. Two things went wrong once that window or VRAM filled up during the story load (RTX 2070 SUPER 8 GB, NVIDIA 620.70.06, Wine 11.21):
memory_type_orderput the window type second for every texture and default-heap buffer that prefers VRAM, and in index order for staging buffers. Textures used it up (nvidia-smiBAR1 at 246 of 256 MiB), and from 18,585 registered images on, every such allocation failed there before reaching system memory.Heap::tiles) required DEVICE_LOCAL, so with VRAM full the 8 MiB heaps failed for every type andtiles()returned nothing.Changes:
memory_type_order: only an allocation that asks for both DEVICE_LOCAL and HOST_VISIBLE (the arena, upload buffers with Resizable BAR) tries a BAR-window type (bar_window_type, new) in its place; the others try it last. Nothing changes with Resizable BAR, where that type is not a window.Heap::tiles: DEVICE_LOCAL preferred instead of required. The types are the sparse resource's ownmemoryTypeBits, so a system-memory type there is valid.The first version also changed
allocate's retries ofVK_ERROR_OUT_OF_HOST_MEMORY.mainhas since made those retries adaptive (they stop while they don't recover), which covers the same case without the regression kawaii-shakal pointed out for the arena, so that part and its failure counter are gone after the merge withmain0d80bc5df.Tested
d3d12_state_map_test(Linux, clang 20): new cases forbar_window_typeand the order of textures, staging buffers and the arena on the RTX 3090 layout already in the test, with and without Resizable BAR. Passes after the merge.VK_ERROR_OUT_OF_DEVICE_MEMORY, so only changes 1 and 2 above can apply there, once VRAM is full.AI-assisted: yes (Claude Code).
Independent verification (native Windows; RTX 4070 SUPER + AMD Radeon gfx1036 iGPU,
LEONIDA_VK_VALIDATION=1): full RelWithDebInfo build 572/572 OK; CPU memory-path tests pass incl. newbar_window_type/ordering cases. GPU ctest memory subset: NVIDIA 15/15 PASS; AMD 11 pass + 4 fail (d3d12_title_va,d3d12_geometry_views,d3d12_title_index_window,d3d12_title_vertex_window) — identical failures reproduced on an origin/main baseline build (iGPUmaxPushConstantsSize=128 < 144, UBO fallback not built — documented pre-existing limit), not a regression. Code review clean: attempts=1 for BAR-window/2s-exhausted types, retry success never poisons a type, othermemory_type_ordercallers unaffected. Retail/Wine no-ReBAR claims unverifiable without game files; mechanism matches. AI-assisted verification.Tested
1940c2ac4applied ontomain42537e7b6on a discrete AMD GPU without Resizable BAR: Radeon RX 7900 XT (20 GB), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. The memory layout is heap 0 VRAM, heap 1 system memory, and heap 2 a 256 MiBDEVICE_LOCAL | HOST_VISIBLEwindow. No game files.This PR alone: no behaviour change on this card, and no regression.
d3d12_state_map,indirect_dispatch_count_alloc,image_memory,arena_size,d3d12_vulkan_device,d3d12_texture_memory,d3d12_buffer_tiles,d3d12_texture_tiles,d3d12_sparse_queue_family*,d3d12_placed_heap_lifetime,d3d12_heap_properties,d3d12_existing_heap,d3d12_title_va,d3d12_geometry_views,d3d12_title_*_window,xbox_geometry_upload_batch,d3d12_indirect_rt_upload_sysmem) give the same results asmain. 17 pass, andd3d12_texture_tiles(#964) andd3d12_geometry_viewsfail on both.ctest -j 6: 3 failures out of 402 (13 skipped for missing data or features), the same three asmain:d3d12_texture_tiles,d3d12_clearandd3d12_geometry_views.LEONIDA_GEOMETRY_MB=16,d3d12_title_va_testlogs exactly the same allocation failures asmain: threevkAllocateMemory failed (-2) ... memory type 2 (flags 0x7, heap 2 of 256 MiB)lines, and nosucceeded on retry.That fits the code:
VK_ERROR_OUT_OF_DEVICE_MEMORY(-2) when the window is full, so the retry and "exhausted" logic, which acts on -1, never runs here.HOST_VISIBLEand prefersDEVICE_LOCAL, so it still takes the BAR type first. At 256 MiB it fills this 256 MiB window exactly.So the retry part of change 2 looks NVIDIA-specific (its failure counter does count AMD's -2 answers, see below), and changes 1 and 3 only matter once VRAM is full.
With #1678 on top (geometry views fall back to system memory when the window is full):
d3d12_geometry_viewspasses, with 64/64 for the table V#, the CBV and the root view. There are no validation messages underLEONIDA_VK_VALIDATION=1, and the fallback is logged once. The wholectestgives 400 of 402, with onlyd3d12_texture_tilesandd3d12_clearleft. The two changes compose without conflicts.One thing to watch once both are in: each new geometry-view block first tries the full window once (-2) and then goes to system memory. That is 1 to 4
vkAllocateMemory failedlines in this test. Your new "has failed N times" line counts every failedvkAllocateMemoryinallocateand first prints at the 32nd failure (then 64, 128, ...). With #1678 each view block adds one failure that is recovered at once. So a run with 32 or more view blocks, or fewer blocks plus other failures, will print it even though every allocation ended up succeeding.Thanks @kawaii-shakal, @adrianmjim and @whoalin1. Merged
main0d80bc5df(the branch was conflicting).mainnow makes theOUT_OF_HOST_MEMORYretries adaptive, which covers what my retry change was for, and keeps the arena's retries at boot, so I dropped that change and the failure counter instead of patching them: the arena regression and the counter's 16/32 and "recovered failures" points no longer apply. What's left is the window ordering and the tile heaps' "prefer, don't require". Description updated;d3d12_state_map_testpasses and the runtime cross-builds after the merge.Independent verification — Turing and Blackwell
0d80bc5df7c873f40965f34f185cb9691378676586eb22f7e84ed057adb9dc259c53394f05f2c706Environment
NVIDIA 621.14, Vulkan SDK 1.4.363.0, MSVC 19.44, Ninja RelWithDebInfo.
Three initial repetitions per configuration, followed by two additional sets of validated runs. Duplicate checkpoint results were excluded.
Results
d3d12_state_mapd3d12_texture_tilesd3d12_existing_heapd3d12_geometry_viewsd3d12_title_vad3d12_indirect_rt_upload_sysmemd3d12_buffer_tilesd3d12_texture_memoryd3d12_heap_properties432 unique test executions: 396 passed, 36 failed, 0 skipped.
Findings
vkAllocateMemory failedmessages in the captured logs.The only failing test is
d3d12_indirect_rt_upload_sysmemunder validation, reproduced on both revisions and GPUs:VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281FAIL: RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0Conclusion
No regressions observed in the nine selected CTest scenarios, including the no-ReBAR Turing configuration.
BAR-window exhaustion and VRAM-pressure fallback were not explicitly forced, so these results establish regression coverage rather than direct verification of allocation behavior under memory exhaustion.
Synthetic tests only. No game files used.
AI-assisted: yes.
A Pascal data point, since the reports above are Turing, Blackwell and RDNA3. GeForce GTX 1050 Ti 4 GB without Resizable BAR, NVIDIA 582.66, Windows 10 Pro 19045, MSVC RelWithDebInfo, base
0d80bc5dfvs head86eb22f7e.Memory layout (vulkaninfo): heap 0 VRAM 3.91 GiB, heap 1 system memory 15.96 GiB, heap 2
DEVICE_LOCAL214 MiB. Types: 0-6 heap 1 with no flags, 7 heap 0DEVICE_LOCAL, 8 heap 1HOST_VISIBLE|HOST_COHERENT, 9 the same plusHOST_CACHED, 10 heap 2DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT. Sobar_window_typetakes type 10 (214 MiB <=kBarWindowBytes), and the PR changes the order here as intended:DEVICE_LOCAL)HOST_VISIBLE+DEVICE_LOCAL)HOST_VISIBLEonly)Staging buffers do not change on this card because the window type already has the highest index; the texture order is where the window was being used up.
Tests, 21 memory tests (
d3d12_state_map,indirect_dispatch_count_alloc,image_memory,arena_size,d3d12_vulkan_device,d3d12_texture_memory,d3d12_buffer_tiles,d3d12_texture_tiles,d3d12_sparse_queue_family*,d3d12_placed_heap_lifetime,d3d12_heap_properties,d3d12_existing_heap*,d3d12_title_va,d3d12_geometry_views,d3d12_title_index_window,d3d12_title_vertex_window,xbox_geometry_upload_batch,d3d12_indirect_rt_upload_sysmem), 3 runs plain and 1 withLEONIDA_VK_VALIDATION=1on each side: identical on base and head, 15 pass and the same 6 fail, no validation messages. The 6 have known causes on this host unrelated to this PR:d3d12_existing_heap*(3, title images whose HOST_TRANSFER image gets no memory type, #1894),d3d12_heap_propertiesandd3d12_vulkan_device(resource heap tier 1 comparisons, #1389),d3d12_geometry_views(Windows 10 root signature serialization, #2059). So no regression here; the window filling up during a story load is not something these tests reach.If useful, this layout could go into
d3d12_state_map_testnext to the RTX 3090 one; it is the case where staging and textures differ.AI-assisted (Claude Code).
Read-through review — head
86eb22f7e(merged withmain0d80bc5df)Read-through on this CPU-only host (no cmake/clang-cl here — not built; the runtime side is backed by whoalin1's 572/572 native build and the adrianmjim, Timon360SB and qhukz13 hardware reports at this head).
Coordination: claimed on #1608 (
RT-ALLOC-NO-REBAR-RETRIES), rosterdone: ... -> #1681; no open PR definesmemory_type_order/bar_window_type(runtime/src/vulkan_memory.h) is touched elsewhere, and no open PR touches thetiles()allocate site — #1678 and #443 change other paths.Rebase clean:
0d80bc5df..main(a73a57e13) is a zero-byte diff forruntime/src/vulkan_memory.handruntime/test/d3d12_state_map_test.cpp, andmainhas not touched thetiles()allocation ind3d12_vulkan_device.cpp(still the old require-DEVICE_LOCAL form). Merges without conflicts.Order logic (static check, sound):
bar_window_typeandresizable_barare exact complements atkBarWindowBytes(device-local heap ≤ 256 MiB vs >): no gap, no overlap, so with Resizable BAR every call is byte-identical tomain.wants_windowis constant per call, so a type cannot land in bothorderandwindow; per-list dedupe is therefore consistent, andwindowtypes are appended after both passes — last, after system memory, as the comment claims.window.required=0, preferred=DEVICE_LOCAL) matches the window type in the first (required | preferred) pass — the type has DEVICE_LOCAL — and is diverted towindow, so it stays a fallback, just last, after system memory.order{1,2,3}), and the 24 GiB heap case with!bar_window_typeand the pre-change order restored.allocate(requirements, 0, DEVICE_LOCAL, ...)cannot yield an invalid type —requirements.memoryTypeBitsis the sparse resource's own bits. The recordedmemory_typeflows intoTileHeapAllocation; nothing in the diff or at the call sites assumes the tile backing is DEVICE_LOCAL (the arena's ownmemory_typeattiles_share_arenais a separate allocation).required=HOST_VISIBLE|HOST_COHERENT, preferred=DEVICE_LOCAL, sowants_windowis true and it retries per main's adaptive rule, as before. kawaii-shakal's pre-merge arena-retry concern no longer applies at this head, as the author's 11:59Z reply says.Verdict: no blocking issues — the merged version is strictly narrower than the pre-merge one (retry/counter part dropped, covered by main's adaptive retries). Nothing to request; the four independent hardware reports (Turing, Blackwell, RDNA3, Pascal, no- and with-ReBAR) all land on this head with no regression.
Reviewed by Hermes Agent (read-through, not run).
Independent Hardware Verification & Cross-PR Interaction Note (RTX 3090, Windows 11)
origin/main(04f484006e) + PR#1681(86eb22f7e8) — clean 3-way merge (0conflicts).RelWithDebInfo), Vulkan SDK +VK_LAYER_KHRONOS_validation1.4.363.1(LEONIDA_VK_VALIDATION=1).Red -> Green Results
#1681'sbar_window_typedeferral omitted inmemory_type_order):d3d12_state_mapfailed (rc=8) atline 898: memory_type_order(memory, 0xF, 0, local, 1 * mib) == (order{0, 1, 2, 3}).origin/main04f484006e+#168186eb22f7e8,LEONIDA_VK_VALIDATION=1):6.02 stotal,0Vulkan validation errors):d3d12_texture_memory: Passed (1.34 s,256 textures: 256 in 1 blocks of 67108864 bytes)d3d12_buffer_tiles: Passed (1.55 s,12 full tiles matched, native D3D12 tier-4 comparison matched)d3d12_texture_tiles: Passed (0validation errors)d3d12_title_va: Passed (0validation errors)d3d12_geometry_views: Passed (0.60 s,64/64across table V#, created CBV, and root view;11negative controls held)d3d12_state_map: Passed (0.06 s, BAR detection andmemory_type_order/bar_window_typecases OK)python -I scripts/check_no_game_data.pyacross all 3 touched files: passed (0issues). No game files used.Heads-Up: Zero-Conflict CI Interaction with Open PR
#1874#1681(86eb22f7e8) +#1874(6fbb6552ef) ontoorigin/main(04f484006e) succeeds with zero Git conflicts (git merge-tree/git mergerc=0), but#1874's newvk_memory_fallback_and_poolstest fails 2 assertions (rc=8) whiled3d12_state_mappasses:FAIL: PresentComposer tries VRAM (1) -> BAR (0) -> RAM (2) in orderFAIL: OcclusionResolve tries VRAM (1) -> BAR (0) -> RAM (2)#1681movesbar_window_type(type 0on#1874's non-ReBAR mock) to the end ofmemory_type_order(memory, type_bits, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size)->{1, 2, 0}(VRAM -> RAM -> BAR).#1874'sdetail::device_memory_orderwrapsmemory_type_order(..., 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size)withstd::stable_partitionondevice_local && !small_bar, which yielded{1, 0, 2}onmain({0, 1, 2}) but preserves{1, 2, 0}once#1681is merged.#1681itself (VRAM -> RAM -> BARis#1681's exact contract for allocations that do not requestHOST_VISIBLE), just flagging so whichever of#1681or#1874merges second alignsdetail::device_memory_order/vk_memory_fallback_and_pools_test.cppon{1, 2, 0}vs{1, 0, 2}.AI-assisted: yes
Verified by OreoFR — READY
d3d12_state_map_testdoes not compile on main (bar_window_typeis the PR's helper). With the threebar_window_typechecks taken out, it fails on main at line 898 (memory_type_order(memory, 0xF, 0, local, 1 * mib) == (order{0, 1, 2, 3})): a texture is offered the BAR-window type before system memory.d3d12_state_mappasses; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p1 = main + #2546 + #1681 + #2479 + #1790 (no shared files): 495 tests, new failures vs main: none; an xmem working-set check failed once in the package as it does on main, and passed 5/5 when re-run alone (main alone: 494 tests, 5 failures: loader, xs_proxy_mock, xmem_no_write_watch, api_ref_state timeout, xbox_present; xbox_present fails in every package as on main). Game A/B belowLEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty), main + this PR alone; imports unchanged vs main (25 DLLs, 655 functions, no WS2_32)DEVICE_LOCALfrom required to preferred, within the resource's own type bits.Game A/B (values only: no captures, logs or game paths leave this machine). A =
gta6rt.exebuilt from mainc8bf0e7b6. B =gta6rt.exebuilt from main + this PR. Both were built without the XMA decoder and launched with main'sboot.ps1. Recipe:boot.ps1 -Seconds 210 -GameDir -Runtime -Shaders -OutDir, otherwise the defaults. The seed was a precompiled compute journal beside eachgta6rt.exe, the same in both arms. Order: A1, (one #1790 boot), B1, A2, B2.What this PR's path needs, and what this laptop can show. The reordering only applies to a memory type that
bar_window_type()flags: DEVICE_LOCAL | HOST_VISIBLE in a device-local heap of at most the BAR window, which in practice means no Resizable BAR. This RTX 4070 Laptop has Resizable BAR: both arms logupload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR). So no type is flagged,memory_type_ordergives the same order as main, and the no-ReBAR path is not exercised here. Only the CPU unit test above covers it (red/green). The tile-heap change (DEVICE_LOCAL preferred instead of required) does apply with ReBAR. But it only matters when VRAM is full and a tile heap is refused, and no boot here logged an allocation failure. These boots check only that nothing regresses on a ReBAR machine.Prediction (written before the first boot): the same ReBAR line in both arms, no allocation-failure lines, and first frame and frames/s within noise.
Result: no regression on a Resizable BAR machine. A1's higher frame rate comes from the screen that boot ended on; A2 matches B1 and B2. The PR's own case, no ReBAR, needs a card without Resizable BAR, or with it turned off in the firmware. This laptop can't show it.
AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Merged. Tested by @OreoFR on head 86eb22f7e (RTX 4070 Laptop 8 GB, Windows 11): red: without bar_window_type deferral d3d12_state_map fails line 898 (also test does not compile on main); green passes. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @ImLele69!
AI-assisted: yes