d3d12: keep a Resizable BAR arena in VRAM when the driver excludes it from a very large buffer (RT-ARENA-REBAR-FIT) #1732
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1732
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1732/head"
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?
@kawaii-shakal on GitHub · 2026-11-25 10:02 UTC · original
kawaii-shakal:arena-rebar-cap→main· +101 −6 · 4 files · 2 commits · merged 2026-11-25 14:38 UTCClaim: RT-ARENA-REBAR-FIT, #1608 (step 2 of #1702)
What and why
On the retail boot with
LEONIDA_ARENA_MB=4096, which is #1537's workaround for the world-start device loss, the memory probe showed the 4,095 MiB arena in system memory (type 2,HOST_VISIBLE | HOST_COHERENT). That was on an RTX 5070 Ti that does have Resizable BAR:[rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR). The cost: 4 GiB more host commit (that run ended with commit and RAM exhausted, #1702), and every default-heap buffer, descriptor heap and shader program read over PCIe.The cause is the buffer's
memoryTypeBits, not the allocation. A standalone Vulkan probe on the same machine (RTX 5070 Ti, NVIDIA 617.42, Windows 11 Pro 26300) shows this:DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTone included;memoryTypeBits0x1fup to 4,090 MiB and0xffrom 4,092 MiB, so the ReBAR type is excluded;memory_type_orderthen never offers that type, and the arena goes to the first host-visible coherent one.0x1f(type 4, ReBAR, allowed)0xf(type 4 excluded)runtime/src/arena_size.h:device_local_arena_bytes(bytes, fits). It returnsbyteswhen it fits. Otherwise it returns the largest size below, in 16 MiB steps and losing at most an eighth, that does. If nothing in reach fits it returnsbytesunchanged. It also adds a new cap bit,arena_cap_bar, with its name.runtime/shims/d3d12_vulkan_device.cpp,create_arena: with Resizable BAR (leonida::resizable_bar),fitscreates a probe buffer of that size and checks whether itsmemoryTypeBitshas aDEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTtype. Each size tried costs one probe buffer. The cap is logged like the existing ones. Without Resizable BAR nothing changes.docs/d3d12_vulkan.md: the memory type policy (section 3.3) says this.Test
arena_size_test: newresizable_bar_fitcase with a syntheticfits. It covers:d3d12_title_va_testwithLEONIDA_ARENA_MB=4096logsGPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types for a buffer that largeand passes. WithLEONIDA_ARENA_MB=1024it logs no cap and passes. At 4,080 MiB the probe above gives0x1f, somemory_type_orderpicks the ReBAR type first.scripts/check_no_game_data.pyis clean.Not done here: a retail boot with this branch, so the memory-probe line
arena 4080 MiB (type 4)and the effect on host commit are not yet measured. Other vendors' limits are not measured either: a driver that keeps the type for every size takes the first branch and nothing changes.AI-assisted: yes (Claude Code, Claude Opus 5.5).
🤖 Generated with Claude Code
@quartz-heron-58 on GitHub · 2026-11-25 10:21 UTC · original
The retail boot you list as not done, on a second card:
96bbe55ceagainst its base3de22a190, RTX 4080 16 GB (NVIDIA 621.24, Resizable BAR on), Windows 11 build 26300, 32 GB RAM, own 1.0.2.1 copy. The placement is confirmed. The host-commit saving is not what I see, so please read the second half.Tests on this head:
arena_sizepasses.d3d12_title_vawithLEONIDA_ARENA_MB=4096logsGPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types for a buffer that largeand passes; with1024it logs no cap and passes. So this card and driver have the same limit as your 5070 Ti.Boot,
LEONIDA_ARENA_MB=4096 LEONIDA_MEM_PROBE=1, 240 s each, one run each. No SDL3 in this build, so no input reaches the title; it is the same unattended four minutes in both. Neither run lost the device. Memory-probe line at t=200 s:Type 1 (device-local) is 1258 x 4882 MiB in both. So the arena moves from system memory to the Resizable BAR type, as intended.
Process counters, sampled from outside every 2 s:
Private bytes are 3 to 4.7 GB higher with the PR, from the first sample on, and the drop in free physical memory is the same in both. On this machine, then, moving the arena to type 4 did not reduce host commit; it looks as if the driver commits host backing for a device-local host-visible allocation of that size, and with the arena in type 2 only the touched part (462 MiB in use, 655 MiB peak) costs RAM. That is my reading of two runs, not something I traced: I did not look at which allocation the extra private bytes belong to, and the two runs started from different amounts of free memory (the base run came second, right after a build).
What this does not measure: read speed over PCIe against VRAM, which is the other half of your motivation, and anything past the title's first screens. If the commit figure matters for #1702, working set and commit charge side by side on your machine would settle whether this is the 4080's driver or general.
Counters and log lines only, no game data. AI-assisted: yes (Claude Code)
@lixonik on GitHub · 2026-11-25 10:23 UTC · original · reviewed
The stock
arena_size_testpassed on Ubuntu under WSL at96bbe55cand its merge base3de22a19. A separate CPU-only test of the new probe block, using synthetic Vulkan requirements and the runtime's actualmemory_type_order, reproduced one mismatch between the fit predicate and allocation policy. Details are inline.AI-assisted. No GPU or game data used for this check.
@lixonik on GitHub · 2026-11-25 10:23 UTC · original
On
runtime/shims/d3d12_vulkan_device.cppline 10258 (outdated):The probe checks the type bit and flags here. Allocation also requires
requirements.sizeto fit the selected type's heap. I reproduced the difference with a 4070 MiB BAR heap: the 4095 MiB buffer offers only system memory, and the 4080 and 4064 MiB buffers both offer the BAR type. The PR stops at 4080 MiB and marks the result BAR-capped, butmemory_type_orderdrops the BAR type, so allocation can only try system memory. At 4064 MiB the same allocation policy selects BAR. Could this predicate reuse the allocation eligibility check with the fullVkMemoryRequirementsso the search continues when the heap is too small?@abnalstlll-byte on GitHub · 2026-11-25 11:03 UTC · original · approved these changes
### Clean-Room & Technical Verification
main(bcaa13dad) is 100% clean with zero merge conflicts.check_no_game_data.pyclean).DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTfrommemoryTypeBits, pushing the entire 4 GiB arena into system RAM and exhausting host commit.device_local_arena_bytes()inruntime/src/arena_size.h, iteratively probing sizes downward in 16 MiB steps (up to an 1/8 reduction floor) to locate the largest size eligible for ReBAR VRAM placement.device_local_arena_fits().runtime/test/arena_size_test.cpp.docs/d3d12_vulkan.md.LGTM! Approved.
@aslan2142 on GitHub · 2026-11-25 14:38 UTC · original
Merged. Thank you, @kawaii-shakal, and thanks to @lixonik for the heap-size point and to @quartz-heron-58 for the RTX 4080 boot.
arena_sizepasses, and its 4070 MiB heap case fails if the heap-size check is removed, so the second commit covers lixonik's point.DEVICE_LOCAL | HOST_VISIBLEtype up to 4,095 MiB, so nothing changes there either.main: nothing goes from pass to fail.main24a29f8b4+a607b779c: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass;check_no_game_data.pyis clean on the 4 changed files.AI-assisted (Claude Code, Claude Opus 5.5).