Skip to content

Runtime: upload heaps in Resizable BAR memory when the GPU has it (D3D-96) - #815

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
etcetera-yt:d3d-96
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
etcetera-yt:d3d-96

Conversation

@etcetera-yt

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-96 (claim)

What and why

D3D-96 asks for the arena and upload memory to use Resizable BAR when the GPU has it. Before writing anything I checked every allocation site on main and in the open stack:

Changes:

  • runtime/src/vulkan_memory.h: new leonida::resizable_bar(memory properties). It returns true when a DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT type sits in a device-local heap larger than 256 MiB. Without Resizable BAR that type is a window of 256 MiB or less (214 MiB on the RTX 3090 in f921105) that every upload buffer would share.
  • Resource::create_buffer: upload-heap buffers prefer DEVICE_LOCAL on top of HOST_VISIBLE | HOST_COHERENT when the device has Resizable BAR. If VRAM is full, DeviceState::allocate's existing fallback order puts them in system memory. Readback buffers still prefer HOST_CACHED.
  • The device logs [rt] d3d12: upload heaps in VRAM (...) or ... system memory (...). LEONIDA_UPLOAD_SYSMEM=1 keeps upload buffers in system memory so the two placements can be compared on one machine.
  • vulkan_memory_flags(ID3D12Resource*) and device_upload_in_vram(ID3D12Device*) expose the choice for tests (d3d12_com.h).
  • docs/d3d12_vulkan.md: new bullet in the memory type policy.

Placed resources on upload heaps (#286) allocate elsewhere. Once #286 lands, they can use the same device_.upload_in_vram check.

Tested

Windows 10 Home 19045, NVIDIA GeForce RTX 5060 Ti, driver 621.14, Resizable BAR on (the DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT type is in the 15.67 GiB VRAM heap). MSVC 19.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363. RelWithDebInfo build on 8df277f.

  • d3d12_state_map passes. The new checks cover the heap layouts of this RTX 5060 Ti, an RTX 3090 without Resizable BAR, a 256 MiB window (no for exactly 256 MiB, yes for one byte more), an integrated GPU, and the negative cases: no HOST_COHERENT, a heap without DEVICE_LOCAL, an out-of-range heap index, and empty properties.
  • Full ctest: 30 of 31 pass. d3d12_vulkan_device fails at EXPECT(feature_mismatches <= 0), and it fails there on unmodified main too (line 1339 there, line 1340 here because of the new include). The Windows 10 runtime refuses shader models 6.7–6.9 and root signature 1.2 from D3D-86: answer SHADER_MODEL and ROOT_SIGNATURE in CheckFeatureSupport #704. I posted it as a finding: Coordinating who works on what (3) (moved to #1006) #634 (comment)
  • To get past that check locally, I ran d3d12_vulkan_device_test with that one EXPECT turned into a print. That edit is not in this PR. Results:
    • Default: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR), the upload buffer is DEVICE_LOCAL, and all later copies from it match. Exit 0.
    • LEONIDA_UPLOAD_SYSMEM=1: upload heaps in system memory (LEONIDA_UPLOAD_SYSMEM), and all copies match. Exit 0.
    • LEONIDA_VK_VALIDATION=1: both placements give the same 10 messages, all synchronization WRITE_AFTER_WRITE hazards on vkCmdCopyImage / vkCmdCopyBufferToImage writing images. The system-memory run follows the same allocation path as before this change, so the hazards are not caused by it. Clean main exits at line 1339 before reaching them.
  • Not tested: a GPU with Resizable BAR off. That case is covered by the unit-test layouts only. I'll add a run with it switched off in the BIOS if wanted.

No game files used. AI-assisted (Claude Code).

Checklist

  • 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. (Not applicable: no translator change.)

🤖 Generated with Claude Code

…D-96)

Upload-heap buffers asked for HOST_VISIBLE | HOST_COHERENT memory only, so the GPU read every vertex, index and
constant buffer a game uploads over PCIe from system memory. They now prefer DEVICE_LOCAL | HOST_VISIBLE |
HOST_COHERENT when the device has Resizable BAR: such a type in a device-local heap larger than the 256 MiB BAR
window (leonida::resizable_bar, runtime/src/vulkan_memory.h). Without Resizable BAR that type is a window of
256 MiB or less that every upload buffer would share, so they stay in system memory there. A full VRAM heap falls
back to system memory through DeviceState::allocate's existing order.

The device logs where upload heaps live, LEONIDA_UPLOAD_SYSMEM=1 keeps them in system memory for comparison, and
vulkan_memory_flags / device_upload_in_vram report the choice to tests. d3d12_state_map_test checks the detection
on the heap layouts of an RTX 5060 Ti with Resizable BAR, an RTX 3090 without it, a 256 MiB window and an
integrated GPU; d3d12_vulkan_device_test checks that its upload buffer is placed accordingly, and its GPU copies
then read that buffer in both placements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants