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 from upstream-pr/1678 into main
adrianmjim commented 2026-11-25 07:54:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T07:54:03Z.


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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487379609 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1678). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T07:54:03Z. --- 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 commented 2026-11-25 08:11:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Copilot on 2026-11-25T08:11:04Z.

Code review location: docs/d3d12_vulkan.md; line 1627

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

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4692054657 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054657). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:11:04Z. **Code review location:** `docs/d3d12_vulkan.md`; line 1627 ~~~~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').
copilot-pull-request-reviewer[bot] commented 2026-11-25 08:11:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T08:11:05Z.

Review: COMMENTED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6053933264 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1678#pullrequestreview-6053933264). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:11:05Z. **Review:** COMMENTED --- > [!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>
Copilot commented 2026-11-25 08:11:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Copilot on 2026-11-25T08:11:05Z.

Code review location: runtime/shims/d3d12_title_buffer_windows.h; line 81

@@ -63,9 +64,21 @@ class TitleBufferWindows {
             vk.vkDestroyBuffer(d.info.device, b.buffer, nullptr);
             return false;
         }
-        b.memory = d.allocate(req, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
-                                  (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0),
+        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));
+            }
+        }

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4692054734 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692054734). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:11:05Z. **Code review location:** `runtime/shims/d3d12_title_buffer_windows.h`; line 81 ~~~~diff @@ -63,9 +64,21 @@ class TitleBufferWindows { vk.vkDestroyBuffer(d.info.device, b.buffer, nullptr); return false; } - b.memory = d.allocate(req, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0), + 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)); + } + } ~~~~ --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T08:52:15Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157574931 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#issuecomment-7157574931). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T08:52:15Z. --- 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 commented 2026-11-25 09:04:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T09:04:55Z.

Code review location: docs/d3d12_vulkan.md; line 1627

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

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4692583200 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692583200). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T09:04:55Z. **Code review location:** `docs/d3d12_vulkan.md`; line 1627 ~~~~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.
adrianmjim commented 2026-11-25 09:04:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T09:04:56Z.

Code review location: runtime/shims/d3d12_title_buffer_windows.h; line 81

@@ -63,9 +64,21 @@ class TitleBufferWindows {
             vk.vkDestroyBuffer(d.info.device, b.buffer, nullptr);
             return false;
         }
-        b.memory = d.allocate(req, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
-                                  (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0),
+        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));
+            }
+        }

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4692583496 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#discussion_r4692583496). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T09:04:56Z. **Code review location:** `runtime/shims/d3d12_title_buffer_windows.h`; line 81 ~~~~diff @@ -63,9 +64,21 @@ class TitleBufferWindows { vk.vkDestroyBuffer(d.info.device, b.buffer, nullptr); return false; } - b.memory = d.allocate(req, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0), + 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)); + } + } ~~~~ --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T14:42:41Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7165695259 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1678#issuecomment-7165695259). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T14:42:41Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-27T20:26:43Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7227513128 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1678#issuecomment-7227513128). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-27T20:26:43Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1678
No description provided.