Repository navigation
d3d12: a heap reserves its arena range when a buffer first needs it, not at CreateHeap - #6257
AwkGrep256 wants to merge 2 commits into
Conversation
…not at CreateHeap Textures placed in a heap never use its GPU address arena range (they get their own image memory) and a D3D12 heap has no VA, so a texture-only heap reserved its whole size in the arena for nothing: with the default 256 MiB arena (2 GiB cap on AMD's Windows driver), large texture heaps ran the arena out at CreateHeap. The range is now reserved by the first placed buffer, or the first buffer tiles that share the arena; that CreatePlacedResource fails with E_OUTOFMEMORY when it doesn't fit. New d3d12_heap_arena_test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hiiva
left a comment
There was a problem hiding this comment.
Independent Windows review at 63c514929c8d6c0c9d870d9d6e32e2f4ec5e4460: the unchanged d3d12_heap_arena CTest passes all seven checks on an RTX 4080. No actionable finding in the first-use reservation change.
Environment: Windows 11 Pro build 26200, NVIDIA GeForce RTX 4080 driver 610.62 (32.0.16.1062), MSVC 19.44.35228, Windows SDK 10.0.26100, Vulkan SDK 1.4.363, RelWithDebInfo. Both runs used LEONIDA_ARENA_MB=64, allocation logging, and requested core/synchronization validation with output captured. The runtime logs identify the RTX 4080 and a 64.0 MiB arena. Neither run emitted VUID, synchronization-hazard, or validation-error diagnostics. This standalone fixture has no test-owned validation-error counter; the diagnostic result is from captured layer output.
- Head: all seven checks pass. Four 128 MiB texture-only heaps each accept a placed texture. A mixed 128 MiB heap also accepts a texture, then returns the expected
E_OUTOFMEMORYwhen a buffer first requires its full arena range. - Unchanged main
561b65a832218fbb9e6d2effd392a8eef093a3f8: the exact same test source, linked to the clean-main library, fails five checks because the large heaps are refused atCreateHeap. The two small-buffer checks still pass. - Address/release controls: both revisions give the two small buffers VAs
0x10000and0x20000, then reuse0x10000for the second heap after the first is released. The head's allocation log contains only the two 1 MiB buffer-heap reservations; the five texture-bearing heaps reserve no arena range. Peak live heap space is 1.0 MiB.
Source review: both first-use entry points hold backing_mutex_; the tiles path calls the already-locked helper, avoiding recursive locking. A successful reservation is retained and reused, and its shared allocation keeps the existing arena-release deleter. The only placed-resource offset access follows a successful reservation; texture creation still bypasses that path. I found no reverse acquisition from the arena allocator into the heap lock.
The head and clean-main production trees are unchanged. The control builds the stock test directly from the PR checkout and links the previously built, hash-verified clean-main library; no fixture, production, or oracle edits. This is a bounded allocation/VA review, with no concurrent stress run, buffer-tiles host comparison, #770 integration result, or retail-game claim. AI-assisted.
Razdva122
left a comment
There was a problem hiding this comment.
A rejected placed-buffer call can retain arena space for the rest of the heap's lifetime. At runtime/shims/d3d12_vulkan_device.cpp:6562, create_placed reserves the entire heap before checking use_as_placed_resource(true). A mixed heap already backing sparse image tiles has tile_allocation_ populated. The latter check therefore returns E_NOTIMPL, but the new arena reservation stays in allocation_ although no buffer was created.
I compiled the head’s reservation methods, compatibility check and call ordering into a CPU probe with a counted arena. With 64 MiB available and a 48 MiB mixed heap in the separate-image-tiles state, the refused placement left 16 MiB available. A subsequent valid 32 MiB buffer heap then failed. The GPU was not emulated in this probe. The existing fixture tests a successful texture placement followed by a buffer request on an oversized heap, which takes a different path.
Please check for incompatible sparse backing, reserve, and mark the heap as having a placed buffer under one backing_mutex_ acquisition. That also prevents a tile mapping from installing incompatible backing between the two calls. A rejected placement should leave the arena available to another heap.
AI-assisted review of 63c514929.
Razdva122 on ItsNotRexed#6257: the arena range was reserved before the check for a heap whose texture tiles have their own sparse backing, so a refused placement kept the range for the heap's lifetime. Heap::place_buffer now checks, reserves and marks the heap under one backing_mutex_ acquisition; place_texture keeps the texture-only check. The test adds that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Razdva122 thanks, you're right: the range was reserved before the separate-tiles check, so a refused placement kept it. Fixed in 4c7150a: The test now covers your case: a 48 MiB mixed heap with a texture tile mapped (separate sparse backing) refuses a placed buffer with Tested 4c7150a under Wine with @Hiiva thanks for the RTX 4080 run and the allocation-log check. AI-assisted. |
|
Head Tested Windows 11, RTX 5070 Ti (32-wide), MSVC 19.44, Vulkan 1.4.363, Ninja RelWithDebInfo with
Verdict: sound. Deferred reservation frees texture-only heaps and changes no address a placed buffer sees. One behaviour change worth stating in the PR: a buffer heap that no longer fits fails at Stack: applies cleanly to current main (4e42451) but not to |
|
@Kam471 thanks for the 5070 Ti run. I added the behaviour change (a heap that no longer fits fails at its first placed buffer, not at AI-assisted. |
|
Tested 4c7150a on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass
AI-assisted (Claude Code). |
|
Tested
AI-assisted (Claude Code). |
Claimed in the coordination issue as a new D3D-layer item: #5781 (comment)
What and why
Heap::Heapreserved the heap's wholeSizeInBytesin the GPU address arena for every heap, andCreateHeapfailed withE_OUTOFMEMORYwhen it didn't fit. Only placed buffers (VA = heap place + offset) and buffer tiles that share the arena use that range. Placed textures never do: onmainthey get their own image memory and a null VA (CreatePlacedResource), and a D3D12 heap has no GPU VA of its own. So a texture-only heap cost its size in the arena for nothing. With the default 256 MiB arena (capped at 2 GiB on AMD's Windows driver), a title that sub-allocates textures from large heaps would run the arena out atCreateHeap.The change (
runtime/shims/d3d12_vulkan_device.cpp):Heap::reserve_arena()reserves the range on first need, under the heap's backing lock; the constructor no longer reserves.CreatePlacedResourcereserves it for a buffer and fails withE_OUTOFMEMORY(and the existing "arena full" log line) when the arena can't take the heap. Textures don't touch it.Heap::tiles()reserves it for buffer tiles that share the arena; when it can't, the mapping gets no backing, as when the heap can't back tiles today.CreateHeapkeeps every other check (arena present, desc refusals) but no longer fails on arena space.Behaviour change: a buffer heap that doesn't fit the arena now fails at its first
CreatePlacedResource(E_OUTOFMEMORY, with the same "arena full" log line) instead of atCreateHeap; a title that only checksCreateHeapgets a null resource there instead of the early failure. A placed buffer refused for another reason (the heap's texture tiles have their own sparse backing,E_NOTIMPL) reserves nothing:Heap::place_buffer()checks, reserves and marks the heap under one lock (review by @Razdva122, second commit).No address the title sees changes: a buffer's VA is still the heap's place plus its offset, and every buffer in a heap shares the one range.
docs/d3d12_vulkan.md: the heap row and theCreatePlacedResourcenote.Interplay with #770 (D3D-88, open): there a default heap's placed textures share one heap-sized
VkDeviceMemoryof their own, still not the arena range, so this change applies the same way; the two touch neighbouring lines inHeapand will need a small rebase whichever lands second.Tested
Windows cross-build (clang-cl + xwin), run under Wine 11 on CachyOS, RADV/Mesa 26.3.1, with
VK_LAYER_KHRONOS_validationon the host Vulkan:d3d12_heap_arena_test(LEONIDA_ARENA_MB=64)New
runtime/test/d3d12_heap_arena_test.cpp(CTestd3d12_heap_arena,LEONIDA_ARENA_MB=64): four 128 MiB texture-only heaps each take a placed texture; a 128 MiB heap for buffers and textures takes a texture and refuses a buffer withE_OUTOFMEMORY; two buffers 64 KiB apart in a 1 MiB heap get VAs 64 KiB apart, and the same again after the first heap is released; a 48 MiB mixed heap with a texture tile mapped refuses a placed buffer, and a 32 MiB buffer heap then still fits (skipped without sparse texture tiles). Negative controls: withmain'sd3d12_vulkan_device.cpp5 of the first 7 checks fail (CreateHeaprefuses the 128 MiB heaps); with the first commit (63c5149) the refused-buffer check fails.Also tested by @Hiiva (RTX 4080, Windows 11) and @Kam471 (RTX 5070 Ti, Windows 11): pass.
Other heap tests on the RX 9070 XT, before and after:
d3d12_placed_dimensions,d3d12_buffer_tiles,d3d12_texture_tiles,d3d12_sparse_queue_family,d3d12_method_variants,d3d12_vulkan_device_test,d3d12_computepass.d3d12_heap_properties(44 mismatches),d3d12_residency(14) andd3d12_indirect_rt(RayQueryKHR ARRAYhit=0) fail identically onmainunder Wine (host comparisons against vkd3d, and the known ray-query case), so they're unrelated.Not tested by me: native Windows, NVIDIA, Intel (see the reviews above for Windows on NVIDIA).
AI-assisted (Claude Code).
🤖 Generated with Claude Code