Repository navigation
Runtime: upload heaps in Resizable BAR memory when the GPU has it (D3D-96) - #815
Merged
Merged
Conversation
…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>
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mainand in the open stack:mainyet. In Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291 it already prefersDEVICE_LOCAL, and @Ryx69'sf921105(memory_type_order) keeps a 256 MiB arena out of a too-small BAR heap. Nothing left to do there, so this PR doesn't touch it and doesn't depend on Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291.DEVICE_LOCALsince Runtime: put the descriptor table in device-local memory (D3D-76) #696 (D3D-76).HOST_VISIBLE | HOST_COHERENTonly, onmainand in every open PR. That's what this PR changes.Changes:
runtime/src/vulkan_memory.h: newleonida::resizable_bar(memory properties). It returns true when aDEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTtype 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 inf921105) that every upload buffer would share.Resource::create_buffer: upload-heap buffers preferDEVICE_LOCALon top ofHOST_VISIBLE | HOST_COHERENTwhen the device has Resizable BAR. If VRAM is full,DeviceState::allocate's existing fallback order puts them in system memory. Readback buffers still preferHOST_CACHED.[rt] d3d12: upload heaps in VRAM (...)or... system memory (...).LEONIDA_UPLOAD_SYSMEM=1keeps upload buffers in system memory so the two placements can be compared on one machine.vulkan_memory_flags(ID3D12Resource*)anddevice_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_vramcheck.Tested
Windows 10 Home 19045, NVIDIA GeForce RTX 5060 Ti, driver 621.14, Resizable BAR on (the
DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENTtype is in the 15.67 GiB VRAM heap). MSVC 19.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363. RelWithDebInfo build on8df277f.d3d12_state_mappasses. 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: noHOST_COHERENT, a heap withoutDEVICE_LOCAL, an out-of-range heap index, and empty properties.ctest: 30 of 31 pass.d3d12_vulkan_devicefails atEXPECT(feature_mismatches <= 0), and it fails there on unmodifiedmaintoo (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)d3d12_vulkan_device_testwith that oneEXPECTturned into a print. That edit is not in this PR. Results:upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR), the upload buffer isDEVICE_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 synchronizationWRITE_AFTER_WRITEhazards onvkCmdCopyImage/vkCmdCopyBufferToImagewriting images. The system-memory run follows the same allocation path as before this change, so the hazards are not caused by it. Cleanmainexits at line 1339 before reaching them.No game files used. AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code