[PR #1681] 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) #1695

Open
opened 2026-11-26 20:22:08 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1681
Author: @ImLele69
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt-alloc-no-rebar


📝 Commits (4)

  • 798077b d3d12_vulkan: leave the BAR window to host-visible VRAM allocations and stop retrying it when full
  • 092cc9e d3d12_vulkan: try a memory type once while its last six tries all failed
  • 1940c2a d3d12_vulkan: a tile heap prefers device-local memory instead of requiring it
  • 86eb22f Merge branch 'main' of https://github.com/ubiquitarianism/leonida into rt-alloc-no-rebar

📊 Changes

3 files changed (+42 additions, -6 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+3 -1)
📝 runtime/src/vulkan_memory.h (+22 -2)
📝 runtime/test/d3d12_state_map_test.cpp (+17 -3)

📄 Description

Claimed in the coordination issue as: RT-ALLOC-NO-REBAR-RETRIES — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156470795

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1681 **Author:** [@ImLele69](https://github.com/ImLele69) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-alloc-no-rebar` --- ### 📝 Commits (4) - [`798077b`](https://github.com/ubiquitarianism/leonida/commit/798077b7cbf71bc2869301c394f3d467d1360e52) d3d12_vulkan: leave the BAR window to host-visible VRAM allocations and stop retrying it when full - [`092cc9e`](https://github.com/ubiquitarianism/leonida/commit/092cc9e07efb0d04e1fca0094a87b36a423b3ed4) d3d12_vulkan: try a memory type once while its last six tries all failed - [`1940c2a`](https://github.com/ubiquitarianism/leonida/commit/1940c2ac4636f614132a778f171f7fcf23987a06) d3d12_vulkan: a tile heap prefers device-local memory instead of requiring it - [`86eb22f`](https://github.com/ubiquitarianism/leonida/commit/86eb22f7e84ed057adb9dc259c53394f05f2c706) Merge branch 'main' of https://github.com/ubiquitarianism/leonida into rt-alloc-no-rebar ### 📊 Changes **3 files changed** (+42 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+3 -1) 📝 `runtime/src/vulkan_memory.h` (+22 -2) 📝 `runtime/test/d3d12_state_map_test.cpp` (+17 -3) </details> ### 📄 Description Claimed in the coordination issue as: RT-ALLOC-NO-REBAR-RETRIES — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156470795 ### 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1695
No description provided.