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

Closed
leonida/mandy
adrianmjim wants to merge 0 commits from fix/geometry-views-no-rebar into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

adrianmjim commented 2026-11-25 07:54:03 +00:00

Claimed in the coordination issue as: RT-GEOMETRY-VIEWS-NO-REBAR (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156374294)

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:

  • ctest -R "^d3d12_(geometry_views|title_va)$": both pass, 3 of 3 runs. Without the change, d3d12_geometry_views fails 3 of 3 and d3d12_title_va passes. The fallback line is printed once.
  • Full ctest on main without the change: 399 of 402. The failures are d3d12_geometry_views (this), d3d12_texture_tiles (#964) and d3d12_clear.
  • tests/test_docs_links.py, tests/test_docs_repeated_lines.py, tests/test_docs_repo_paths.py, tests/test_text_write_line_endings.py: pass.

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.)
Claimed in the coordination issue as: RT-GEOMETRY-VIEWS-NO-REBAR (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156374294) ### 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`: - `ctest -R "^d3d12_(geometry_views|title_va)$"`: both pass, 3 of 3 runs. Without the change, `d3d12_geometry_views` fails 3 of 3 and `d3d12_title_va` passes. The fallback line is printed once. - Full `ctest` on `main` without the change: 399 of 402. The failures are `d3d12_geometry_views` (this), `d3d12_texture_tiles` (#964) and `d3d12_clear`. - `tests/test_docs_links.py`, `tests/test_docs_repeated_lines.py`, `tests/test_docs_repo_paths.py`, `tests/test_text_write_line_endings.py`: pass. GPUs tested: AMD Radeon RX 7900 XT (RDNA3), AMD 32.0.32029.2010, Windows 11 26300, Resizable BAR off AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change.)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 08:11:05 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
> [!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](https://gh.io/AA11tgch) for more details. <!-- ccr-overview-v2 --> ## Copilot review overview <details open> <summary><strong>2 open issues</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [This now supports system-memory fallback, but the sentence &#39;The copies go in device-local…](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054657) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [The log formatting truncates KiB via `b.capacity >> 10` (drops any remainder) and uses a hard-coded…](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054734) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> 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. | </details> <sub>Review effort: Lite</sub> **`docs/d3d12_vulkan.md` line 1627:** > This now supports system-memory fallback, but the sentence 'The copies go in device-local host-visible memory.' is no longer strictly true. Suggest rephrasing to reflect the preference + fallback (e.g., 'The copies prefer device-local host-visible memory…; if unavailable they fall back to host-visible system memory'). **`runtime/shims/d3d12_title_buffer_windows.h` line 81:** > The log formatting truncates KiB via `b.capacity >> 10` (drops any remainder) and uses a hard-coded `%llu` format. Consider using a byte count (or rounded-up KiB) and a portable `PRIu64`-style formatter (or the project’s existing uint64 logging helper) to avoid platform-specific format warnings and to keep the size reporting accurate.
whoalin1 commented 2026-11-25 08:52:15 +00:00

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.

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.
adrianmjim reviewed 2026-11-25 09:04:55 +00:00
adrianmjim left a comment
No description provided.
**`docs/d3d12_vulkan.md` line 1627:** > Right, it's a preference now. Reworded in `3db487a81` to "The copies prefer device-local host-visible memory", followed by the fallback sentence.
adrianmjim reviewed 2026-11-25 09:04:57 +00:00
adrianmjim left a comment
No description provided.
**`runtime/shims/d3d12_title_buffer_windows.h` line 81:** > 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.
aslan2142 commented 2026-11-25 14:42:41 +00:00

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).

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 commented 2026-11-27 20:26:43 +00:00

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.

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.
Sign in to join this conversation.
No description provided.