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

Open
github-bot wants to merge 4 commits from github-bot/gh-1681 into main AGit
Owner

@⁠ImLele69 on GitHub · 2026-11-25 07:59 UTC · original
ImLele69:rt-alloc-no-rebar → main · +42 −6 · 3 files · 4 commits · open

Claimed in the coordination issue as: RT-ALLOC-NO-REBAR-RETRIES — #1608

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

  1. memory_type_order put 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-smi BAR1 at 246 of 256 MiB), and from 18,585 registered images on, every such allocation failed there before reaching system memory.
  2. Tile heaps for reserved resources (Heap::tiles) required DEVICE_LOCAL, so with VRAM full the 8 MiB heaps failed for every type and tiles() 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 own memoryTypeBits, so a system-memory type there is valid.

The first version also changed allocate's retries of VK_ERROR_OUT_OF_HOST_MEMORY. main has 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 with main 0d80bc5df.

Tested

  • d3d12_state_map_test (Linux, clang 20): new cases for bar_window_type and 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.
  • Windows runtime cross-build (clang-cl 20 + xwin) after the merge.
  • Retail 1.0.2.1 boots under Wine 11.21, RTX 2070 SUPER 8 GB, i9-9900KF, 16 GB RAM, counts only: with the first version, no allocation failure was logged up to 26,800-38,900 registered images over several runs (16 in the window before, by 18,585 images). Not repeated with the merged retry logic.
  • Independent runs by whoalin1 (RTX 4070 SUPER, AMD iGPU) and adrianmjim (RX 7900 XT without Resizable BAR) above: no regression. On AMD the window answers 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).

**@⁠ImLele69** on GitHub · 2026-11-25 07:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681) `ImLele69:rt-alloc-no-rebar` → `main` · +42 −6 · 3 files · 4 commits · open Claimed in the coordination issue as: RT-ALLOC-NO-REBAR-RETRIES — https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### 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): 1. `memory_type_order` put 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-smi` BAR1 at 246 of 256 MiB), and from 18,585 registered images on, every such allocation failed there before reaching system memory. 2. Tile heaps for reserved resources (`Heap::tiles`) required DEVICE_LOCAL, so with VRAM full the 8 MiB heaps failed for every type and `tiles()` 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 own `memoryTypeBits`, so a system-memory type there is valid. The first version also changed `allocate`'s retries of `VK_ERROR_OUT_OF_HOST_MEMORY`. `main` has 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 with `main` `0d80bc5df`. ### Tested - `d3d12_state_map_test` (Linux, clang 20): new cases for `bar_window_type` and 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. - Windows runtime cross-build (clang-cl 20 + xwin) after the merge. - Retail 1.0.2.1 boots under Wine 11.21, RTX 2070 SUPER 8 GB, i9-9900KF, 16 GB RAM, counts only: with the first version, no allocation failure was logged up to 26,800-38,900 registered images over several runs (16 in the window before, by 18,585 images). Not repeated with the merged retry logic. - Independent runs by whoalin1 (RTX 4070 SUPER, AMD iGPU) and adrianmjim (RX 7900 XT without Resizable BAR) above: no regression. On AMD the window answers `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).
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.
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.
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/test/d3d12_state_map_test.cpp
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:36 +00:00
Author
Owner

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

Independent verification (native Windows; RTX 4070 SUPER + AMD Radeon gfx1036 iGPU, LEONIDA_VK_VALIDATION=1): full RelWithDebInfo build 572/572 OK; CPU memory-path tests pass incl. new bar_window_type/ordering cases. GPU ctest memory subset: NVIDIA 15/15 PASS; AMD 11 pass + 4 fail (d3d12_title_va, d3d12_geometry_views, d3d12_title_index_window, d3d12_title_vertex_window) — identical failures reproduced on an origin/main baseline build (iGPU maxPushConstantsSize=128 < 144, UBO fallback not built — documented pre-existing limit), not a regression. Code review clean: attempts=1 for BAR-window/2s-exhausted types, retry success never poisons a type, other memory_type_order callers unaffected. Retail/Wine no-ReBAR claims unverifiable without game files; mechanism matches. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7157574347) Independent verification (native Windows; RTX 4070 SUPER + AMD Radeon gfx1036 iGPU, `LEONIDA_VK_VALIDATION=1`): full RelWithDebInfo build 572/572 OK; CPU memory-path tests pass incl. new `bar_window_type`/ordering cases. GPU ctest memory subset: NVIDIA **15/15 PASS**; AMD 11 pass + 4 fail (`d3d12_title_va`, `d3d12_geometry_views`, `d3d12_title_index_window`, `d3d12_title_vertex_window`) — **identical failures reproduced on an origin/main baseline build** (iGPU `maxPushConstantsSize=128 < 144`, UBO fallback not built — documented pre-existing limit), not a regression. Code review clean: attempts=1 for BAR-window/2s-exhausted types, retry success never poisons a type, other `memory_type_order` callers unaffected. Retail/Wine no-ReBAR claims unverifiable without game files; mechanism matches. AI-assisted verification.
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 09:45 UTC · original · reviewed

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

**@⁠kawaii-shakal** on GitHub · 2026-11-25 09:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#pullrequestreview-6055209045) · **reviewed** 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).
Author
Owner

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

Tested 1940c2ac4 applied onto main 42537e7b6 on a discrete AMD GPU without Resizable BAR: Radeon RX 7900 XT (20 GB), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. The memory layout is heap 0 VRAM, heap 1 system memory, and heap 2 a 256 MiB DEVICE_LOCAL | HOST_VISIBLE window. No game files.

This PR alone: no behaviour change on this card, and no regression.

  • The 19 memory tests (d3d12_state_map, indirect_dispatch_count_alloc, image_memory, arena_size, d3d12_vulkan_device, d3d12_texture_memory, d3d12_buffer_tiles, d3d12_texture_tiles, d3d12_sparse_queue_family*, d3d12_placed_heap_lifetime, d3d12_heap_properties, d3d12_existing_heap, d3d12_title_va, d3d12_geometry_views, d3d12_title_*_window, xbox_geometry_upload_batch, d3d12_indirect_rt_upload_sysmem) give the same results as main. 17 pass, and d3d12_texture_tiles (#964) and d3d12_geometry_views fail on both.
  • Whole ctest -j 6: 3 failures out of 402 (13 skipped for missing data or features), the same three as main: d3d12_texture_tiles, d3d12_clear and d3d12_geometry_views.
  • With LEONIDA_GEOMETRY_MB=16, d3d12_title_va_test logs exactly the same allocation failures as main: three vkAllocateMemory failed (-2) ... memory type 2 (flags 0x7, heap 2 of 256 MiB) lines, and no succeeded on retry.

That fits the code:

  • AMD answers VK_ERROR_OUT_OF_DEVICE_MEMORY (-2) when the window is full, so the retry and "exhausted" logic, which acts on -1, never runs here.
  • Textures still get VRAM type 0 first.
  • The arena still asks for HOST_VISIBLE and prefers DEVICE_LOCAL, so it still takes the BAR type first. At 256 MiB it fills this 256 MiB window exactly.

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): d3d12_geometry_views passes, with 64/64 for the table V#, the CBV and the root view. There are no validation messages under LEONIDA_VK_VALIDATION=1, and the fallback is logged once. The whole ctest gives 400 of 402, with only d3d12_texture_tiles and d3d12_clear left. The two changes compose without conflicts.

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 vkAllocateMemory failed lines in this test. Your new "has failed N times" line counts every failed vkAllocateMemory in allocate and first prints at the 32nd failure (then 64, 128, ...). With #1678 each view block adds one failure that is recovered at once. So a run with 32 or more view blocks, or fewer blocks plus other failures, will print it even though every allocation ended up succeeding.

**@⁠adrianmjim** on GitHub · 2026-11-25 11:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7161008864) Tested `1940c2ac4` applied onto `main` `42537e7b6` on a discrete AMD GPU without Resizable BAR: Radeon RX 7900 XT (20 GB), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. The memory layout is heap 0 VRAM, heap 1 system memory, and heap 2 a 256 MiB `DEVICE_LOCAL | HOST_VISIBLE` window. No game files. **This PR alone: no behaviour change on this card, and no regression.** - The 19 memory tests (`d3d12_state_map`, `indirect_dispatch_count_alloc`, `image_memory`, `arena_size`, `d3d12_vulkan_device`, `d3d12_texture_memory`, `d3d12_buffer_tiles`, `d3d12_texture_tiles`, `d3d12_sparse_queue_family*`, `d3d12_placed_heap_lifetime`, `d3d12_heap_properties`, `d3d12_existing_heap`, `d3d12_title_va`, `d3d12_geometry_views`, `d3d12_title_*_window`, `xbox_geometry_upload_batch`, `d3d12_indirect_rt_upload_sysmem`) give the same results as `main`. 17 pass, and `d3d12_texture_tiles` (#964) and `d3d12_geometry_views` fail on both. - Whole `ctest -j 6`: 3 failures out of 402 (13 skipped for missing data or features), the same three as `main`: `d3d12_texture_tiles`, `d3d12_clear` and `d3d12_geometry_views`. - With `LEONIDA_GEOMETRY_MB=16`, `d3d12_title_va_test` logs exactly the same allocation failures as `main`: three `vkAllocateMemory failed (-2) ... memory type 2 (flags 0x7, heap 2 of 256 MiB)` lines, and no `succeeded on retry`. That fits the code: - AMD answers `VK_ERROR_OUT_OF_DEVICE_MEMORY` (-2) when the window is full, so the retry and "exhausted" logic, which acts on -1, never runs here. - Textures still get VRAM type 0 first. - The arena still asks for `HOST_VISIBLE` and prefers `DEVICE_LOCAL`, so it still takes the BAR type first. At 256 MiB it fills this 256 MiB window exactly. 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): `d3d12_geometry_views` passes, with 64/64 for the table V#, the CBV and the root view. There are no validation messages under `LEONIDA_VK_VALIDATION=1`, and the fallback is logged once. The whole `ctest` gives 400 of 402, with only `d3d12_texture_tiles` and `d3d12_clear` left. The two changes compose without conflicts. 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 `vkAllocateMemory failed` lines in this test. Your new "has failed N times" line counts every failed `vkAllocateMemory` in `allocate` and first prints at the 32nd failure (then 64, 128, ...). With #1678 each view block adds one failure that is recovered at once. So a run with 32 or more view blocks, or fewer blocks plus other failures, will print it even though every allocation ended up succeeding.
Author
Owner

@⁠ImLele69 on GitHub · 2026-11-25 11:59 UTC · original

Thanks @⁠kawaii-shakal, @⁠adrianmjim and @⁠whoalin1. Merged main 0d80bc5df (the branch was conflicting). main now makes the OUT_OF_HOST_MEMORY retries adaptive, which covers what my retry change was for, and keeps the arena's retries at boot, so I dropped that change and the failure counter instead of patching them: the arena regression and the counter's 16/32 and "recovered failures" points no longer apply. What's left is the window ordering and the tile heaps' "prefer, don't require". Description updated; d3d12_state_map_test passes and the runtime cross-builds after the merge.

**@⁠ImLele69** on GitHub · 2026-11-25 11:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7161776950) Thanks @⁠kawaii-shakal, @⁠adrianmjim and @⁠whoalin1. Merged `main` `0d80bc5df` (the branch was conflicting). `main` now makes the `OUT_OF_HOST_MEMORY` retries adaptive, which covers what my retry change was for, and keeps the arena's retries at boot, so I dropped that change and the failure counter instead of patching them: the arena regression and the counter's 16/32 and "recovered failures" points no longer apply. What's left is the window ordering and the tile heaps' "prefer, don't require". Description updated; `d3d12_state_map_test` passes and the runtime cross-builds after the merge.
Author
Owner

@⁠Timon360SB on GitHub · 2026-11-25 14:30 UTC · original

Independent verification — Turing and Blackwell

  • Base: 0d80bc5df7c873f40965f34f185cb96913786765
  • Head: 86eb22f7e84ed057adb9dc259c53394f05f2c706

Environment

GPU Windows 11 build Resizable BAR
RTX 5070 (12 GB) 26200 Enabled
RTX 2060 SUPER (8 GB) 28000 Unavailable

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

Test Base Head
d3d12_state_map 24/24 24/24
d3d12_texture_tiles 24/24 24/24
d3d12_existing_heap 24/24 24/24
d3d12_geometry_views 24/24 24/24
d3d12_title_va 24/24 24/24
d3d12_indirect_rt_upload_sysmem 6/24 6/24
d3d12_buffer_tiles 24/24 24/24
d3d12_texture_memory 24/24 24/24
d3d12_heap_properties 24/24 24/24
Total 198/216 198/216

432 unique test executions: 396 passed, 36 failed, 0 skipped.

Findings

  • VulkanInfo reports a separate 214 MiB DEVICE_LOCAL / HOST_VISIBLE heap on the RTX 2060 SUPER.
  • Upload heaps use system memory on the RTX 2060 SUPER and VRAM on the RTX 5070.
  • Geometry views and title-memory checks pass on both revisions, with 64/64 expected values for CPU-written tables, created CBVs and root views.
  • No vkAllocateMemory failed messages in the captured logs.

The only failing test is d3d12_indirect_rt_upload_sysmem under validation, reproduced on both revisions and GPUs:

VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281

FAIL: RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0

Conclusion

No 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.
AI-assisted: yes.

**@⁠Timon360SB** on GitHub · 2026-11-25 14:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7165389523) ## Independent verification — Turing and Blackwell - **Base:** `0d80bc5df7c873f40965f34f185cb96913786765` - **Head:** `86eb22f7e84ed057adb9dc259c53394f05f2c706` ### Environment | GPU | Windows 11 build | Resizable BAR | |---|---|---| | RTX 5070 (12 GB) | 26200 | Enabled | | RTX 2060 SUPER (8 GB) | 28000 | Unavailable | 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 | Test | Base | Head | |---|---:|---:| | `d3d12_state_map` | 24/24 | 24/24 | | `d3d12_texture_tiles` | 24/24 | 24/24 | | `d3d12_existing_heap` | 24/24 | 24/24 | | `d3d12_geometry_views` | 24/24 | 24/24 | | `d3d12_title_va` | 24/24 | 24/24 | | `d3d12_indirect_rt_upload_sysmem` | 6/24 | 6/24 | | `d3d12_buffer_tiles` | 24/24 | 24/24 | | `d3d12_texture_memory` | 24/24 | 24/24 | | `d3d12_heap_properties` | 24/24 | 24/24 | | **Total** | **198/216** | **198/216** | 432 unique test executions: 396 passed, 36 failed, 0 skipped. ### Findings - VulkanInfo reports a separate 214 MiB DEVICE_LOCAL / HOST_VISIBLE heap on the RTX 2060 SUPER. - Upload heaps use system memory on the RTX 2060 SUPER and VRAM on the RTX 5070. - Geometry views and title-memory checks pass on both revisions, with 64/64 expected values for CPU-written tables, created CBVs and root views. - No `vkAllocateMemory failed` messages in the captured logs. The only failing test is `d3d12_indirect_rt_upload_sysmem` under validation, reproduced on both revisions and GPUs: `VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281` `FAIL: RayQueryKHR ARRAY expected hit=1 miss=0, got hit=0 miss=0` ### Conclusion No 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. AI-assisted: yes.
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-25 22:25 UTC · original

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 0d80bc5df vs head 86eb22f7e.

Memory layout (vulkaninfo): heap 0 VRAM 3.91 GiB, heap 1 system memory 15.96 GiB, heap 2 DEVICE_LOCAL 214 MiB. Types: 0-6 heap 1 with no flags, 7 heap 0 DEVICE_LOCAL, 8 heap 1 HOST_VISIBLE|HOST_COHERENT, 9 the same plus HOST_CACHED, 10 heap 2 DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT. So bar_window_type takes type 10 (214 MiB <= kBarWindowBytes), and the PR changes the order here as intended:

allocation main this PR
texture / default buffer (prefers DEVICE_LOCAL) 7, 10, 0-6, 8, 9 7, 0-6, 8, 9, 10
arena (HOST_VISIBLE + DEVICE_LOCAL) 10 first 10 first
staging (HOST_VISIBLE only) 8, 9, 10 8, 9, 10

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 (d3d12_state_map, indirect_dispatch_count_alloc, image_memory, arena_size, d3d12_vulkan_device, d3d12_texture_memory, d3d12_buffer_tiles, d3d12_texture_tiles, d3d12_sparse_queue_family*, d3d12_placed_heap_lifetime, d3d12_heap_properties, d3d12_existing_heap*, d3d12_title_va, d3d12_geometry_views, d3d12_title_index_window, d3d12_title_vertex_window, xbox_geometry_upload_batch, d3d12_indirect_rt_upload_sysmem), 3 runs plain and 1 with LEONIDA_VK_VALIDATION=1 on each side: identical on base and head, 15 pass and the same 6 fail, no validation messages. The 6 have known causes on this host unrelated to this PR: d3d12_existing_heap* (3, title images whose HOST_TRANSFER image gets no memory type, #1894), d3d12_heap_properties and d3d12_vulkan_device (resource heap tier 1 comparisons, #1389), d3d12_geometry_views (Windows 10 root signature serialization, #2059). So no regression here; the window filling up during a story load is not something these tests reach.

If useful, this layout could go into d3d12_state_map_test next to the RTX 3090 one; it is the case where staging and textures differ.

AI-assisted (Claude Code).

**@⁠qhukz13** on GitHub · 2026-11-25 22:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7176346174) 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 `0d80bc5df` vs head `86eb22f7e`. **Memory layout (vulkaninfo):** heap 0 VRAM 3.91 GiB, heap 1 system memory 15.96 GiB, heap 2 `DEVICE_LOCAL` 214 MiB. Types: 0-6 heap 1 with no flags, 7 heap 0 `DEVICE_LOCAL`, 8 heap 1 `HOST_VISIBLE|HOST_COHERENT`, 9 the same plus `HOST_CACHED`, 10 heap 2 `DEVICE_LOCAL|HOST_VISIBLE|HOST_COHERENT`. So `bar_window_type` takes type 10 (214 MiB <= `kBarWindowBytes`), and the PR changes the order here as intended: | allocation | main | this PR | |---|---|---| | texture / default buffer (prefers `DEVICE_LOCAL`) | 7, **10**, 0-6, 8, 9 | 7, 0-6, 8, 9, **10** | | arena (`HOST_VISIBLE` + `DEVICE_LOCAL`) | 10 first | 10 first | | staging (`HOST_VISIBLE` only) | 8, 9, 10 | 8, 9, 10 | 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 (`d3d12_state_map`, `indirect_dispatch_count_alloc`, `image_memory`, `arena_size`, `d3d12_vulkan_device`, `d3d12_texture_memory`, `d3d12_buffer_tiles`, `d3d12_texture_tiles`, `d3d12_sparse_queue_family*`, `d3d12_placed_heap_lifetime`, `d3d12_heap_properties`, `d3d12_existing_heap*`, `d3d12_title_va`, `d3d12_geometry_views`, `d3d12_title_index_window`, `d3d12_title_vertex_window`, `xbox_geometry_upload_batch`, `d3d12_indirect_rt_upload_sysmem`), 3 runs plain and 1 with `LEONIDA_VK_VALIDATION=1` on each side: identical on base and head, 15 pass and the same 6 fail, no validation messages. The 6 have known causes on this host unrelated to this PR: `d3d12_existing_heap*` (3, title images whose HOST_TRANSFER image gets no memory type, #1894), `d3d12_heap_properties` and `d3d12_vulkan_device` (resource heap tier 1 comparisons, #1389), `d3d12_geometry_views` (Windows 10 root signature serialization, #2059). So no regression here; the window filling up during a story load is not something these tests reach. If useful, this layout could go into `d3d12_state_map_test` next to the RTX 3090 one; it is the case where staging and textures differ. AI-assisted (Claude Code).
Author
Owner

@⁠GrahamboJangles on GitHub · 2026-11-26 08:19 UTC · original

Read-through review — head 86eb22f7e (merged with main 0d80bc5df)

Read-through on this CPU-only host (no cmake/clang-cl here — not built; the runtime side is backed by whoalin1's 572/572 native build and the adrianmjim, Timon360SB and qhukz13 hardware reports at this head).

Coordination: claimed on #1608 (RT-ALLOC-NO-REBAR-RETRIES), roster done: ... -> #1681; no open PR defines memory_type_order/bar_window_type (runtime/src/vulkan_memory.h) is touched elsewhere, and no open PR touches the tiles() allocate site — #1678 and #443 change other paths.

Rebase clean: 0d80bc5df..main (a73a57e13) is a zero-byte diff for runtime/src/vulkan_memory.h and runtime/test/d3d12_state_map_test.cpp, and main has not touched the tiles() allocation in d3d12_vulkan_device.cpp (still the old require-DEVICE_LOCAL form). Merges without conflicts.

Order logic (static check, sound):

  • bar_window_type and resizable_bar are exact complements at kBarWindowBytes (device-local heap ≤ 256 MiB vs >): no gap, no overlap, so with Resizable BAR every call is byte-identical to main.
  • wants_window is constant per call, so a type cannot land in both order and window; per-list dedupe is therefore consistent, and window types are appended after both passes — last, after system memory, as the comment claims.
  • The VUID-01713 heap-size filter runs before the classification, so an undersized window heap never sneaks in via window.
  • A texture (required=0, preferred=DEVICE_LOCAL) matches the window type in the first (required | preferred) pass — the type has DEVICE_LOCAL — and is diverted to window, so it stays a fallback, just last, after system memory.
  • Tests cover both flips: window-last for texture/staging, window-first for the arena (order{1,2,3}), and the 24 GiB heap case with !bar_window_type and the pre-change order restored.
  • Tile heaps: allocate(requirements, 0, DEVICE_LOCAL, ...) cannot yield an invalid type — requirements.memoryTypeBits is the sparse resource's own bits. The recorded memory_type flows into TileHeapAllocation; nothing in the diff or at the call sites assumes the tile backing is DEVICE_LOCAL (the arena's own memory_type at tiles_share_arena is a separate allocation).
  • Arena keeps its window-first slot here: the call is required=HOST_VISIBLE|HOST_COHERENT, preferred=DEVICE_LOCAL, so wants_window is true and it retries per main's adaptive rule, as before. kawaii-shakal's pre-merge arena-retry concern no longer applies at this head, as the author's 11:59Z reply says.

Verdict: no blocking issues — the merged version is strictly narrower than the pre-merge one (retry/counter part dropped, covered by main's adaptive retries). Nothing to request; the four independent hardware reports (Turing, Blackwell, RDNA3, Pascal, no- and with-ReBAR) all land on this head with no regression.

Reviewed by Hermes Agent (read-through, not run).

**@⁠GrahamboJangles** on GitHub · 2026-11-26 08:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1681#issuecomment-7186458808) ## Read-through review — head `86eb22f7e` (merged with `main` `0d80bc5df`) Read-through on this CPU-only host (no cmake/clang-cl here — not built; the runtime side is backed by whoalin1's 572/572 native build and the adrianmjim, Timon360SB and qhukz13 hardware reports at this head). Coordination: claimed on #1608 (`RT-ALLOC-NO-REBAR-RETRIES`), roster `done: ... -> #1681`; no open PR defines `memory_type_order`/`bar_window_type` (`runtime/src/vulkan_memory.h`) is touched elsewhere, and no open PR touches the `tiles()` allocate site — #1678 and #443 change other paths. Rebase clean: `0d80bc5df..main` (`a73a57e13`) is a zero-byte diff for `runtime/src/vulkan_memory.h` and `runtime/test/d3d12_state_map_test.cpp`, and `main` has not touched the `tiles()` allocation in `d3d12_vulkan_device.cpp` (still the old require-DEVICE_LOCAL form). Merges without conflicts. Order logic (static check, sound): - `bar_window_type` and `resizable_bar` are exact complements at `kBarWindowBytes` (device-local heap ≤ 256 MiB vs >): no gap, no overlap, so with Resizable BAR every call is byte-identical to `main`. - `wants_window` is constant per call, so a type cannot land in both `order` and `window`; per-list dedupe is therefore consistent, and `window` types are appended after both passes — last, after system memory, as the comment claims. - The VUID-01713 heap-size filter runs before the classification, so an undersized window heap never sneaks in via `window`. - A texture (`required=0, preferred=DEVICE_LOCAL`) matches the window type in the first (`required | preferred`) pass — the type has DEVICE_LOCAL — and is diverted to `window`, so it stays a fallback, just last, after system memory. - Tests cover both flips: window-last for texture/staging, window-first for the arena (`order{1,2,3}`), and the 24 GiB heap case with `!bar_window_type` and the pre-change order restored. - Tile heaps: `allocate(requirements, 0, DEVICE_LOCAL, ...)` cannot yield an invalid type — `requirements.memoryTypeBits` is the sparse resource's own bits. The recorded `memory_type` flows into `TileHeapAllocation`; nothing in the diff or at the call sites assumes the tile backing is DEVICE_LOCAL (the arena's own `memory_type` at `tiles_share_arena` is a separate allocation). - Arena keeps its window-first slot here: the call is `required=HOST_VISIBLE|HOST_COHERENT, preferred=DEVICE_LOCAL`, so `wants_window` is true and it retries per main's adaptive rule, as before. kawaii-shakal's pre-merge arena-retry concern no longer applies at this head, as the author's 11:59Z reply says. Verdict: no blocking issues — the merged version is strictly narrower than the pre-merge one (retry/counter part dropped, covered by main's adaptive retries). Nothing to request; the four independent hardware reports (Turing, Blackwell, RDNA3, Pascal, no- and with-ReBAR) all land on this head with no regression. Reviewed by Hermes Agent (read-through, not run).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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