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

Open
github-bot wants to merge 2 commits from github-bot/gh-1678 into main AGit
Owner

@⁠adrianmjim on GitHub · 2026-11-25 07:54 UTC · original
adrianmjim:fix/geometry-views-no-rebar → main · +20 −4 · 2 files · 2 commits · open

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

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.)
**@⁠adrianmjim** on GitHub · 2026-11-25 07:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678) `adrianmjim:fix/geometry-views-no-rebar` → `main` · +20 −4 · 2 files · 2 commits · open Claimed in the coordination issue as: RT-GEOMETRY-VIEWS-NO-REBAR (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.)
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:31 +00:00
Author
Owner

@⁠Copilot on GitHub · 2026-11-25 08:11 UTC · original
On docs/d3d12_vulkan.md line 1627 (outdated):

@@ -1621,8 +1621,10 @@ The copies:
   cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address
   must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply.
   `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena.
-- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0.
+- `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0.
   A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory.
+  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).

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

**@⁠Copilot** on GitHub · 2026-11-25 08:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054657) On `docs/d3d12_vulkan.md` line 1627 (outdated): ```diff @@ -1621,8 +1621,10 @@ The copies: cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. -- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0. +- `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0. A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. + 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). ``` 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').
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 08:11 UTC · original · reviewed

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

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 08:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#pullrequestreview-6053933264) · **reviewed** > [!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://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1678) · 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://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1678) · 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>
@ -69,0 +78,4 @@
"buffer views, so it is in system memory\n",
static_cast<unsigned long long>(b.capacity >> 10));
}
}
Author
Owner

@⁠Copilot on GitHub · 2026-11-25 08:11 UTC · original

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.

**@⁠Copilot** on GitHub · 2026-11-25 08:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054734) 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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 08:52 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#issuecomment-7157574931) 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.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 09:04 UTC · original
On docs/d3d12_vulkan.md line 1627 (outdated):

@@ -1621,8 +1621,10 @@ The copies:
   cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address
   must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply.
   `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena.
-- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0.
+- `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0.
   A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory.
+  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).

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

**@⁠adrianmjim** on GitHub · 2026-11-25 09:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692583200) On `docs/d3d12_vulkan.md` line 1627 (outdated): ```diff @@ -1621,8 +1621,10 @@ The copies: cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. -- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0. +- `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0. A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. + 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). ``` Right, it's a preference now. Reworded in `3db487a81` to "The copies prefer device-local host-visible memory", followed by the fallback sentence.
@ -69,0 +78,4 @@
"buffer views, so it is in system memory\n",
static_cast<unsigned long long>(b.capacity >> 10));
}
}
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 09:04 UTC · original

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.
**@⁠adrianmjim** on GitHub · 2026-11-25 09:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692583496) 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.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 14:42 UTC · original

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

**@⁠aslan2142** on GitHub · 2026-11-25 14:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1678#issuecomment-7165695259) 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).
This pull request has changes conflicting with the target branch.
  • docs/d3d12_vulkan.md
  • runtime/shims/d3d12_title_buffer_windows.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1678/head:github-bot/gh-1678'
git switch 'github-bot/gh-1678'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1678'
git switch 'github-bot/gh-1678'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1678'
git switch 'github-bot/gh-1678'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1678'
git switch 'main'
git merge --squash 'github-bot/gh-1678'
git switch 'main'
git merge --ff-only 'github-bot/gh-1678'
git switch 'main'
git merge 'github-bot/gh-1678'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.