Repository navigation
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
Conversation
…nd stop retrying it when full Without Resizable BAR the DEVICE_LOCAL | HOST_VISIBLE type sits in a heap of about 256 MiB. memory_type_order put it second for every texture and default-heap buffer that prefers VRAM, so once VRAM filled up each such allocation failed there too, and the NVIDIA driver's VK_ERROR_OUT_OF_HOST_MEMORY answer was retried six times with sleeps under memory_mutex before falling back to system memory. Only allocations that ask for both DEVICE_LOCAL and HOST_VISIBLE now try the window in its place; the others try it last, and an out-of-host-memory answer from the window is believed the first time. Failures past the first 16 are counted at powers of two.
With VRAM full the NVIDIA driver answers VK_ERROR_OUT_OF_HOST_MEMORY for the device-local heap too, so every texture that spilled to system memory first slept through five retries under memory_mutex. After a type fails all six tries, allocate tries it once for the next two seconds. The driver's spurious answer with memory free still gets its retries, since a retry that succeeds never marks the type.
…iring it ID3D12Heap tiles for reserved resources were allocated with DEVICE_LOCAL required, so once VRAM was full (an 8 GB card without Resizable BAR, during the story load) the allocation failed for every type and tiles() returned nothing. The memory types are the sparse resource's own memoryTypeBits, so a system-memory type there is valid, and the heap now comes from it when VRAM has no room.
|
Independent verification (native Windows; RTX 4070 SUPER + AMD Radeon gfx1036 iGPU, |
kawaii-shakal
left a comment
There was a problem hiding this comment.
Review (read-only, not run). Moving the BAR-window type to the end for allocations that don't ask for host access, and the tile heaps' "prefer, don't require", both look right, and the order tests are clear. One possible regression:
The arena gets one try in the BAR window instead of six. attempts is 1 for any bar_window_type type, including for an allocation that wants both DEVICE_LOCAL and HOST_VISIBLE, the arena among them. The six retries existed because the NVIDIA driver also returns a spurious VK_ERROR_OUT_OF_HOST_MEMORY that succeeds on retry (your description keeps retries for that case elsewhere). On a no-ReBAR card the arena is the one allocation that should land in the window. A single spurious answer would now send it to system memory for the whole run, silently, apart from the placement log. Suggest keeping the retries when wants_window, or for the first allocation in that type, and limiting the single try to allocations that only reached the window as a fallback.
Minor: the failures counter's first message prints at 32 (failed > 16 and a power of two). If 16 was meant, use >=.
AI-assisted review (Claude Code, Claude Opus 5.5).
|
Tested This PR alone: no behaviour change on this card, and no regression.
That fits the code:
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): 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 |
…o rt-alloc-no-rebar # Conflicts: # runtime/shims/d3d12_vulkan_device.cpp # runtime/test/d3d12_state_map_test.cpp
|
Thanks @kawaii-shakal, @adrianmjim and @whoalin1. Merged |
Independent verification — Turing and Blackwell
Environment
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
432 unique test executions: 396 passed, 36 failed, 0 skipped. Findings
The only failing test is
ConclusionNo 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. |
|
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 Memory layout (vulkaninfo): heap 0 VRAM 3.91 GiB, heap 1 system memory 15.96 GiB, heap 2
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 ( If useful, this layout could go into AI-assisted (Claude Code). |
Read-through review — head
|
Claimed in the coordination issue as: RT-ALLOC-NO-REBAR-RETRIES — #1608 (comment)
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).