[PR #1732] [MERGED] d3d12: keep a Resizable BAR arena in VRAM when the driver excludes it from a very large buffer (RT-ARENA-REBAR-FIT) #1746

Closed
opened 2026-11-26 21:18:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1732
Author: @kawaii-shakal
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: arena-rebar-cap


📝 Commits (2)

  • 96bbe55 d3d12: keep a Resizable BAR arena in VRAM when the driver excludes it from a very large buffer (RT-ARENA-REBAR-FIT)
  • a607b77 d3d12: check heap eligibility when sizing the ReBAR arena

📊 Changes

4 files changed (+101 additions, -6 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+9 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+26 -3)
📝 runtime/src/arena_size.h (+30 -1)
📝 runtime/test/arena_size_test.cpp (+36 -2)

📄 Description

Claim: RT-ARENA-REBAR-FIT, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159118394 (step 2 of #1702)

What and why

On the retail boot with LEONIDA_ARENA_MB=4096, which is #1537's workaround for the world-start device loss, the memory probe showed the 4,095 MiB arena in system memory (type 2, HOST_VISIBLE | HOST_COHERENT). That was on an RTX 5070 Ti that does have Resizable BAR: [rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR). The cost: 4 GiB more host commit (that run ended with commit and RAM exhausted, #1702), and every default-heap buffer, descriptor heap and shader program read over PCIe.

The cause is the buffer's memoryTypeBits, not the allocation. A standalone Vulkan probe on the same machine (RTX 5070 Ti, NVIDIA 617.42, Windows 11 Pro 26300) shows this:

  • a 4,095 MiB allocation succeeds in every host-visible type, the DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT one included;
  • but a buffer with the arena's usage flags reports memoryTypeBits 0x1f up to 4,090 MiB and 0xf from 4,092 MiB, so the ReBAR type is excluded;
  • memory_type_order then never offers that type, and the arena goes to the first host-visible coherent one.
arena-shaped buffer memoryTypeBits
256 MiB to 4,090 MiB 0x1f (type 4, ReBAR, allowed)
4,092, 4,093, 4,094, 4,095 MiB 0xf (type 4 excluded)
  • runtime/src/arena_size.h: device_local_arena_bytes(bytes, fits). It returns bytes when it fits. Otherwise it returns the largest size below, in 16 MiB steps and losing at most an eighth, that does. If nothing in reach fits it returns bytes unchanged. It also adds a new cap bit, arena_cap_bar, with its name.
  • runtime/shims/d3d12_vulkan_device.cpp, create_arena: with Resizable BAR (leonida::resizable_bar), fits creates a probe buffer of that size and checks whether its memoryTypeBits has a DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT type. Each size tried costs one probe buffer. The cap is logged like the existing ones. Without Resizable BAR nothing changes.
  • docs/d3d12_vulkan.md: the memory type policy (section 3.3) says this.

Test

  • arena_size_test: new resizable_bar_fit case with a synthetic fits. It covers:
    • the 5070 Ti limit (4,095 MiB becomes 4,080 MiB);
    • already fitting, and a small arena (both unchanged);
    • a limit more than an eighth away, and nothing fitting (both unchanged);
    • the number of probes per step;
    • the cap's name.
  • On the RTX 5070 Ti, d3d12_title_va_test with LEONIDA_ARENA_MB=4096 logs GPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types for a buffer that large and passes. With LEONIDA_ARENA_MB=1024 it logs no cap and passes. At 4,080 MiB the probe above gives 0x1f, so memory_type_order picks the ReBAR type first.
  • scripts/check_no_game_data.py is clean.

Not done here: a retail boot with this branch, so the memory-probe line arena 4080 MiB (type 4) and the effect on host commit are not yet measured. Other vendors' limits are not measured either: a driver that keeps the type for every size takes the first branch and nothing changes.

AI-assisted: yes (Claude Code, Claude Opus 5.5).

🤖 Generated with 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/1732 **Author:** [@kawaii-shakal](https://github.com/kawaii-shakal) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `arena-rebar-cap` --- ### 📝 Commits (2) - [`96bbe55`](https://github.com/ubiquitarianism/leonida/commit/96bbe55ce88ab79ccdbfaf26f78ce34154ac47b7) d3d12: keep a Resizable BAR arena in VRAM when the driver excludes it from a very large buffer (RT-ARENA-REBAR-FIT) - [`a607b77`](https://github.com/ubiquitarianism/leonida/commit/a607b779c4342436ca7d408630733223fac49246) d3d12: check heap eligibility when sizing the ReBAR arena ### 📊 Changes **4 files changed** (+101 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+9 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+26 -3) 📝 `runtime/src/arena_size.h` (+30 -1) 📝 `runtime/test/arena_size_test.cpp` (+36 -2) </details> ### 📄 Description Claim: RT-ARENA-REBAR-FIT, https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159118394 (step 2 of #1702) ### What and why On the retail boot with `LEONIDA_ARENA_MB=4096`, which is #1537's workaround for the world-start device loss, the memory probe showed the 4,095 MiB arena in system memory (type 2, `HOST_VISIBLE | HOST_COHERENT`). That was on an RTX 5070 Ti that does have Resizable BAR: `[rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR)`. The cost: 4 GiB more host commit (that run ended with commit and RAM exhausted, #1702), and every default-heap buffer, descriptor heap and shader program read over PCIe. The cause is the buffer's `memoryTypeBits`, not the allocation. A standalone Vulkan probe on the same machine (RTX 5070 Ti, NVIDIA 617.42, Windows 11 Pro 26300) shows this: - a 4,095 MiB allocation succeeds in every host-visible type, the `DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT` one included; - but a buffer with the arena's usage flags reports `memoryTypeBits` `0x1f` up to 4,090 MiB and `0xf` from 4,092 MiB, so the ReBAR type is excluded; - `memory_type_order` then never offers that type, and the arena goes to the first host-visible coherent one. | arena-shaped buffer | memoryTypeBits | |---|---| | 256 MiB to 4,090 MiB | `0x1f` (type 4, ReBAR, allowed) | | 4,092, 4,093, 4,094, 4,095 MiB | `0xf` (type 4 excluded) | - `runtime/src/arena_size.h`: `device_local_arena_bytes(bytes, fits)`. It returns `bytes` when it fits. Otherwise it returns the largest size below, in 16 MiB steps and losing at most an eighth, that does. If nothing in reach fits it returns `bytes` unchanged. It also adds a new cap bit, `arena_cap_bar`, with its name. - `runtime/shims/d3d12_vulkan_device.cpp`, `create_arena`: with Resizable BAR (`leonida::resizable_bar`), `fits` creates a probe buffer of that size and checks whether its `memoryTypeBits` has a `DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT` type. Each size tried costs one probe buffer. The cap is logged like the existing ones. Without Resizable BAR nothing changes. - `docs/d3d12_vulkan.md`: the memory type policy (section 3.3) says this. ### Test - `arena_size_test`: new `resizable_bar_fit` case with a synthetic `fits`. It covers: - the 5070 Ti limit (4,095 MiB becomes 4,080 MiB); - already fitting, and a small arena (both unchanged); - a limit more than an eighth away, and nothing fitting (both unchanged); - the number of probes per step; - the cap's name. - On the RTX 5070 Ti, `d3d12_title_va_test` with `LEONIDA_ARENA_MB=4096` logs `GPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types for a buffer that large` and passes. With `LEONIDA_ARENA_MB=1024` it logs no cap and passes. At 4,080 MiB the probe above gives `0x1f`, so `memory_type_order` picks the ReBAR type first. - `scripts/check_no_game_data.py` is clean. Not done here: a retail boot with this branch, so the memory-probe line `arena 4080 MiB (type 4)` and the effect on host commit are not yet measured. Other vendors' limits are not measured either: a driver that keeps the type for every size takes the first branch and nothing changes. AI-assisted: yes (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:18:49 +01:00
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#1746
No description provided.