Repository navigation
d3d12: keep a Resizable BAR arena in VRAM when the driver excludes it from a very large buffer (RT-ARENA-REBAR-FIT) - #1732
Conversation
… from a very large buffer (RT-ARENA-REBAR-FIT) On an RTX 5070 Ti (NVIDIA 617.42) a 4,090 MiB arena-shaped buffer may use the DEVICE_LOCAL | HOST_VISIBLE type and a 4,092 MiB one may not, so LEONIDA_ARENA_MB=4096 (4,095 MiB, the workaround from ProjectLeonida#1537) placed the whole arena in system memory: 4 GiB more host commit, and every default-heap buffer read over PCIe. With Resizable BAR, create_arena now tries 16 MiB smaller sizes, by at most an eighth, and keeps the largest whose buffer may still use that type (device_local_arena_bytes in arena_size.h). The cap is logged like the other device caps. Without Resizable BAR nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The retail boot you list as not done, on a second card: 96bbe55 against its base 3de22a1, 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: Boot,
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
left a comment
There was a problem hiding this comment.
The stock arena_size_test passed on Ubuntu under WSL at 96bbe55c and its merge base 3de22a19. A separate CPU-only test of the new probe block, using synthetic Vulkan requirements and the runtime's actual memory_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.
| VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | | ||
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | ||
| for (std::uint32_t i = 0; i < state_.memory.memoryTypeCount; ++i) | ||
| if ((bits & (1u << i)) && (state_.memory.memoryTypes[i].propertyFlags & wanted) == wanted) return true; |
There was a problem hiding this comment.
The probe checks the type bit and flags here. Allocation also requires requirements.size to 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, but memory_type_order drops 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 full VkMemoryRequirements so the search continues when the heap is too small?
AI-assisted by Codex.
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Clean-Room & Technical Verification
- Mergeability: 3-way merge against upstream
main(bcaa13dad) is 100% clean with zero merge conflicts. - Clean-Room Compliance: 100% clean-room. Vulkan memory sizing algorithms and unit test cases only; zero retail binaries, game data, or keys (
check_no_game_data.pyclean). - Technical Rigor & Hardware Reality:
- Addresses driver memory type filtering on high-end GPUs (e.g. RTX 5070 Ti) where buffers exceeding ~4,090 MiB exclude
DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTfrommemoryTypeBits, pushing the entire 4 GiB arena into system RAM and exhausting host commit. - Implements
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. - Correctly verifies heap capacity and allocation limits via
device_local_arena_fits(). - Comprehensive unit test coverage added in
runtime/test/arena_size_test.cpp. - Thoroughly documented in
docs/d3d12_vulkan.md.
- Addresses driver memory type filtering on high-end GPUs (e.g. RTX 5070 Ti) where buffers exceeding ~4,090 MiB exclude
LGTM! Approved.
|
Merged. Thank you, @kawaii-shakal, and thanks to @lixonik for the heap-size point and to @quartz-heron-58 for the RTX 4080 boot.
AI-assisted (Claude Code, Claude Opus 5.5). |
Claim: RT-ARENA-REBAR-FIT, #1608 (comment) (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