Skip to content

d3d12: geometry views fall back to system memory when the BAR window is full (RT-GEOMETRY-VIEWS-NO-REBAR) - #1678

Closed
adrianmjim wants to merge 2 commits into
ProjectLeonida:mainfrom
adrianmjim:fix/geometry-views-no-rebar
Closed

adrianmjim wants to merge 2 commits into
ProjectLeonida:mainfrom
adrianmjim:fix/geometry-views-no-rebar

Conversation

@adrianmjim

Copy link
Copy Markdown

Claimed in the coordination issue as: RT-GEOMETRY-VIEWS-NO-REBAR (#1608 (comment))

What and why

d3d12_geometry_views fails on an RX 7900 XT without Resizable BAR, on every run, on main 42537e7b6:

[rt] d3d12: vkAllocateMemory failed (-2): 4194304 bytes, memory type 2 (flags 0x7, heap 2 of 256 MiB), device address 1
title memory (a constant ring): CPU-written table V# 0/64 (rewritten before the submission: yes), created CBV 0/64, root view 0/64; ...
line 492: raw_ok == kElements && cbv_ok == kElements && root_ok == kElements

The cause:

  • LEONIDA_GEOMETRY_MB views are allocated through TitleBufferWindows::allocate(..., device_local = true), which requires DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT.
  • Without Resizable BAR the only such heap is the 256 MiB BAR window. The default 256 MiB GPU address arena (required HOST_VISIBLE | HOST_COHERENT, preferred DEVICE_LOCAL) fits it exactly, since memory_type_order accepts a heap as large as the request, so the arena takes the whole BAR heap.
  • Every 4 MiB view block then fails with VK_ERROR_OUT_OF_DEVICE_MEMORY, no view is made, and the translated shader reads zeros.

The driver is not refusing the allocation itself: a standalone probe on the same machine allocates 64 KiB to 64 MiB from that memory type, with and without VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT, when the heap is empty. And main passes with LEONIDA_ARENA_MB set to 128, 224 or 240.

The fix: a device-local view block that cannot be allocated now goes to host-visible system memory, logged once. It is the same memory the non-geometry title windows already fall back to, and it keeps the 47-bit offset check, so a block the shaders could not reach is still refused. Views that fit in the BAR stay there.

Docs:

  • LEONIDA_GEOMETRY_MB is now described as the cap for the views wherever they are, since the cap also counts fallback blocks.
  • The arena note in docs/d3d12_vulkan.md said the 256 MiB default arena lands in system memory without Resizable BAR. That holds for a smaller BAR heap (the RTX 3090's 214 MiB), but a heap of exactly 256 MiB holds it, so the note now says so.

Follow-up (not here): whether the arena should take the whole BAR heap when there is no Resizable BAR is a policy question. The arena holds the default-heap buffers, descriptor heaps and shader code, so moving it to system memory is not obviously better. This change only makes the views work whichever way that goes.

Tested

AMD Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (26.11.2), no Resizable BAR, Windows 11 build 26300, VS 2022, RelWithDebInfo, on main 42537e7b6:

GPUs tested: AMD Radeon RX 7900 XT (RDNA3), AMD 32.0.32029.2010, Windows 11 26300, Resizable BAR off

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

…is full (RT-GEOMETRY-VIEWS-NO-REBAR)

LEONIDA_GEOMETRY_MB views required DEVICE_LOCAL | HOST_VISIBLE memory. Without
Resizable BAR the only such heap is the 256 MiB BAR window, and the default
256 MiB GPU address arena (host-visible, preferring device-local) takes all of
it. Every 4 MiB view block then failed with VK_ERROR_OUT_OF_DEVICE_MEMORY, no
view was made, and translated shaders read zeros: d3d12_geometry_views failed
on an RX 7900 XT without Resizable BAR (CPU-written table V# 0/64).

A device-local block that cannot be allocated now goes to host-visible system
memory, logged once. Views that fit in the BAR stay there.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Ensures d3d12_geometry_views works on systems without Resizable BAR by allowing streamed geometry view allocations to fall back to host-visible system memory when the BAR window is exhausted.

Changes:

  • Add host-visible system-memory fallback for device-local view blocks when device-local host-visible heap allocation fails (logged once).
  • Update documentation for LEONIDA_GEOMETRY_MB semantics and clarify BAR heap sizing behavior without Resizable BAR.
File Description
runtime/​shims/​d3d12_title_buffer_windows.h Implements device-local allocation fallback to host-visible system memory with one-time logging when BAR heap is full.
docs/​d3d12_vulkan.md Updates LEONIDA_GEOMETRY_MB docs and clarifies default arena behavior on exact-256MiB BAR heaps.

Review effort: Lite

Comment thread docs/d3d12_vulkan.md Outdated
Comment on lines +1626 to +1627
The copies go in device-local host-visible memory. Without Resizable BAR that is the 256 MiB BAR window, which
the default arena can fill; a block that finds no room there goes to host-visible system memory (logged once).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's a preference now. Reworded in 3db487a81 to "The copies prefer device-local host-visible memory", followed by the fallback sentence.

Comment on lines +67 to +81
constexpr VkMemoryPropertyFlags host_access =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
b.memory = d.allocate(req, host_access | (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0),
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr, true);
if (!b.memory && device_local) {
// Without Resizable BAR the only device-local host-visible heap is the 256 MiB BAR window, and the
// default GPU address arena can fill it. A view in system memory is slower to read but still correct.
b.memory = d.allocate(req, host_access, 0, nullptr, true);
if (b.memory && !logged_host_fallback_) {
logged_host_fallback_ = true;
std::fprintf(stderr, "[rt] d3d12: no device-local host-visible memory left for a %llu KiB block of "
"buffer views, so it is in system memory\n",
static_cast<unsigned long long>(b.capacity >> 10));
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this one as it is:

  • Size: b.capacity is the 4 MiB block size, or the view's size when that is larger, so >> 10 loses nothing that matters in a once-only log line.
  • Format: %llu with static_cast<unsigned long long> is how the rest of this header and d3d12_geometry_views.h print sizes, and it is portable on every compiler the runtime builds with.

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (native Windows; RTX 4070 SUPER + AMD gfx1036 iGPU, validation on): header-only + docs, build 120/120 OK; same ctest results as #1681 — NVIDIA 15/15, AMD same 4 pre-existing 128B-pushconst failures identical on baseline. Interplay with #1681 checked: git merge-tree merges cleanly (different files) and semantics compose correctly — geometry views request DEVICE_LOCAL|HOST_VISIBLE so #1681 keeps the window type early; on window-full the single attempt fails fast and this PR's preferred=0 fallback lands in system memory. Copilot's 2 cosmetic comments are doc-wording/ log-truncation nits only. AI-assisted verification.

@aslan2142

Copy link
Copy Markdown
Collaborator

Thanks, @adrianmjim. The diagnosis is right, but #1723 (merged today) already covers the code fix:

  • TitleBufferWindows::allocate now only prefers DEVICE_LOCAL.
  • DeviceState::allocate moves to the next type when one fails, so a -2 from the BAR window lands in host-visible coherent memory, and after one refusal later blocks go straight there (logged).

Merged with main, your header change drops out. What still helps is the docs: main still calls LEONIDA_GEOMETRY_MB a "device-local memory cap", and your note about a heap of exactly 256 MiB is new. Could you merge main and keep only the docs part (or close it if you prefer)? A confirmation that d3d12_geometry_views passes on main on your 7900 XT without Resizable BAR would be welcome too.

AI-assisted (Claude Code, Claude Opus 5.5).

@adrianmjim

Copy link
Copy Markdown
Author

Closing this: #1723 covers the code fix, as @aslan2142 says. TitleBufferWindows::allocate now only prefers DEVICE_LOCAL, and DeviceState::allocate falls through to the next memory type.

On current main (cf1c34128), on an RX 7900 XT without Resizable BAR (AMD 32.0.32029.2010, Windows 11 26300), d3d12_geometry_views and d3d12_title_va pass. The default arena is used, with no LEONIDA_ARENA_MB.

The docs part (LEONIDA_GEOMETRY_MB is no longer a device-local cap; the 256 MiB BAR heap note) can go in a small docs pull request of its own if that's useful.

@adrianmjim adrianmjim closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants