[PR #443] d3d12/vulkan: add 4 GB low-VRAM budget steering, priority/pageable memory, and LEONIDA_RT_AS=off (VK-LOW-VRAM-BUDGET) #494

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/443
Author: @jujumoneylol
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: pr/vulkan-low-vram


📝 Commits (2)

  • d62f113 d3d12/vulkan: add 4 GB low-VRAM budget steering, priority/pageable memory, and LEONIDA_RT_AS=off
  • 9222350 d3d12/vulkan: cap VRAM budget in d3d12_low_vram_test for >4.5 GiB GPUs and document env vars

📊 Changes

7 files changed (+738 additions, -34 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+14 -1)
📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/shims/d3d12_com.h (+27 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+255 -32)
📝 runtime/src/vulkan_memory.h (+145 -0)
➕ runtime/test/d3d12_low_vram_test.cpp (+207 -0)
📝 runtime/test/d3d12_state_map_test.cpp (+81 -0)

📄 Description

Claimed in the coordination issue as: VK-LOW-VRAM-BUDGET (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122816234)

What and why

Adds an automatic low-VRAM survival layer in the Vulkan D3D12 shim for discrete GPUs with <= 4.5 GiB dedicated VRAM (e.g., 4 GB GTX 1650 / RTX 3050 4 GB) while leaving larger GPUs (>= 6 GB) and UMA iGPUs untouched by default.

  • Vulkan memory management extensions: opportunistically enables VK_EXT_memory_budget, VK_EXT_memory_priority, and VK_EXT_pageable_device_local_memory when advertised by the driver, chaining VkMemoryPriorityAllocateInfoEXT (1.0 for critical render targets / depth-stencil / arena allocations vs 0.25 for spillable textures/buffers).
  • Proactive VRAM budget steering (runtime/src/vulkan_memory.h, runtime/shims/d3d12_vulkan_device.cpp):
    • Auto-enables on discrete GPUs with <= 4.5 GiB DEVICE_LOCAL VRAM (overridable via LEONIDA_LOW_VRAM=on|off|auto, LEONIDA_VRAM_RESERVE_MB, LEONIDA_VRAM_CAP_MB, LEONIDA_VRAM_LOG=1).
    • Preserves a default 512 MiB DEVICE_LOCAL headroom reserve for critical RT/DS targets; once live VK_EXT_memory_budget headroom drops below the reserve, spillable allocations are proactively routed to system RAM (HOST_VISIBLE) instead of evicting render targets or causing VK_ERROR_OUT_OF_DEVICE_MEMORY.
    • Allows sparse tile heaps (Heap::tiles) to fall back to system memory when VRAM is exhausted instead of returning E_OUTOFMEMORY.
    • Leaves pipeline cache persistence untouched so this does not overlap #218.
  • Ray-tracing opt-out (LEONIDA_RT_AS=off): cleanly disables RT acceleration structures on non-RT / low-VRAM GPUs and answers GetRaytracingAccelerationStructurePrebuildInfo with minimal 256-byte aligned sizes so callers do not allocate or divide by zero.
  • Tests: adds unit tests for the budget/placement policy in runtime/test/d3d12_state_map_test.cpp and a live GPU stress test (runtime/test/d3d12_low_vram_test.cpp) that oversubscribes VRAM past 100% and verifies critical RT/DS pinning + spillable steering + LEONIDA_RT_AS=off.

Tested

  • Built d3d12_state_map_test, d3d12_low_vram_test, and d3d12_vulkan_device_test with MSVC 19.44 (vcvars64) + Ninja on top of main 8f481cf16.
  • d3d12_state_map_test: PASSED (including new low-VRAM policy & placement unit tests).
  • d3d12_low_vram_test: ALL CHECKS PASSED on GTX 1650 (3,935 MiB VRAM, budget=1 priority=1 pageable=1, 512 MiB reserve):
    • Oversubscribed 277 × 16 MiB (4,432 MiB) spillable textures + 6 critical RT/DS targets: 173 textures in VRAM, 104 (1,664 MiB) proactively steered to system RAM, 0 forced spills, 6/6 critical RT/DS pinned in VRAM.
    • Verified LEONIDA_RT_AS=off disables RT and returns 256-byte prebuild sizes.
  • d3d12_vulkan_device_test: PASSED (60/60 resolves matched, 20/20 ID3D12Heap::GetDesc matched, host-image/staging copies, castable formats, and Xbox-ABI proxy checks matched).
  • py -3.13 -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/d3d12_com.h runtime/shims/d3d12_vulkan_device.cpp runtime/src/vulkan_memory.h runtime/test/d3d12_low_vram_test.cpp runtime/test/d3d12_state_map_test.cpp: clean.

GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200)

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. (n/a — Vulkan D3D12 runtime only)

🔄 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/443 **Author:** [@jujumoneylol](https://github.com/jujumoneylol) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/vulkan-low-vram` --- ### 📝 Commits (2) - [`d62f113`](https://github.com/ubiquitarianism/leonida/commit/d62f113a105ab1e91bf38f9fc57768ae6f4d7170) d3d12/vulkan: add 4 GB low-VRAM budget steering, priority/pageable memory, and LEONIDA_RT_AS=off - [`9222350`](https://github.com/ubiquitarianism/leonida/commit/922235029ad22817509d68b3cfe4cb389c0fa8f8) d3d12/vulkan: cap VRAM budget in d3d12_low_vram_test for >4.5 GiB GPUs and document env vars ### 📊 Changes **7 files changed** (+738 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+14 -1) 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/shims/d3d12_com.h` (+27 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+255 -32) 📝 `runtime/src/vulkan_memory.h` (+145 -0) ➕ `runtime/test/d3d12_low_vram_test.cpp` (+207 -0) 📝 `runtime/test/d3d12_state_map_test.cpp` (+81 -0) </details> ### 📄 Description Claimed in the coordination issue as: VK-LOW-VRAM-BUDGET (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7122816234) ### What and why Adds an automatic low-VRAM survival layer in the Vulkan D3D12 shim for discrete GPUs with <= 4.5 GiB dedicated VRAM (e.g., 4 GB GTX 1650 / RTX 3050 4 GB) while leaving larger GPUs (>= 6 GB) and UMA iGPUs untouched by default. - **Vulkan memory management extensions**: opportunistically enables `VK_EXT_memory_budget`, `VK_EXT_memory_priority`, and `VK_EXT_pageable_device_local_memory` when advertised by the driver, chaining `VkMemoryPriorityAllocateInfoEXT` (`1.0` for critical render targets / depth-stencil / arena allocations vs `0.25` for spillable textures/buffers). - **Proactive VRAM budget steering** (`runtime/src/vulkan_memory.h`, `runtime/shims/d3d12_vulkan_device.cpp`): - Auto-enables on discrete GPUs with <= 4.5 GiB `DEVICE_LOCAL` VRAM (overridable via `LEONIDA_LOW_VRAM=on|off|auto`, `LEONIDA_VRAM_RESERVE_MB`, `LEONIDA_VRAM_CAP_MB`, `LEONIDA_VRAM_LOG=1`). - Preserves a default 512 MiB `DEVICE_LOCAL` headroom reserve for critical RT/DS targets; once live `VK_EXT_memory_budget` headroom drops below the reserve, spillable allocations are proactively routed to system RAM (`HOST_VISIBLE`) instead of evicting render targets or causing `VK_ERROR_OUT_OF_DEVICE_MEMORY`. - Allows sparse tile heaps (`Heap::tiles`) to fall back to system memory when VRAM is exhausted instead of returning `E_OUTOFMEMORY`. - Leaves pipeline cache persistence untouched so this does not overlap #218. - **Ray-tracing opt-out (`LEONIDA_RT_AS=off`)**: cleanly disables RT acceleration structures on non-RT / low-VRAM GPUs and answers `GetRaytracingAccelerationStructurePrebuildInfo` with minimal 256-byte aligned sizes so callers do not allocate or divide by zero. - **Tests**: adds unit tests for the budget/placement policy in `runtime/test/d3d12_state_map_test.cpp` and a live GPU stress test (`runtime/test/d3d12_low_vram_test.cpp`) that oversubscribes VRAM past 100% and verifies critical RT/DS pinning + spillable steering + `LEONIDA_RT_AS=off`. ### Tested - Built `d3d12_state_map_test`, `d3d12_low_vram_test`, and `d3d12_vulkan_device_test` with MSVC 19.44 (`vcvars64`) + Ninja on top of `main` `8f481cf16`. - `d3d12_state_map_test`: PASSED (including new low-VRAM policy & placement unit tests). - `d3d12_low_vram_test`: ALL CHECKS PASSED on GTX 1650 (3,935 MiB VRAM, `budget=1 priority=1 pageable=1`, 512 MiB reserve): - Oversubscribed 277 × 16 MiB (4,432 MiB) spillable textures + 6 critical RT/DS targets: 173 textures in VRAM, 104 (1,664 MiB) proactively steered to system RAM, 0 forced spills, 6/6 critical RT/DS pinned in VRAM. - Verified `LEONIDA_RT_AS=off` disables RT and returns 256-byte prebuild sizes. - `d3d12_vulkan_device_test`: PASSED (60/60 resolves matched, 20/20 `ID3D12Heap::GetDesc` matched, host-image/staging copies, castable formats, and Xbox-ABI proxy checks matched). - `py -3.13 -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/d3d12_com.h runtime/shims/d3d12_vulkan_device.cpp runtime/src/vulkan_memory.h runtime/test/d3d12_low_vram_test.cpp runtime/test/d3d12_state_map_test.cpp`: clean. GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200) 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. (n/a — Vulkan D3D12 runtime only) --- <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#494
No description provided.