mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #444] d3d12: upload and readback buffers live in the GPU address arena (RT-UPLOAD-ARENA) #495
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#495
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/444
Author: @Kokonotcu
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:pr/m8-upload-arena📝 Commits (2)
5a52674d3d12: upload and readback buffers live in the GPU address arena (RT-UPLOAD-ARENA)a902c78d3d12: readback buffers stay out of the GPU address arena (review of #444)📊 Changes
9 files changed (+466 additions, -15 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+12 -5)📝
runtime/CMakeLists.txt(+35 -0)📝
runtime/shims/d3d12_com.h(+4 -1)📝
runtime/shims/d3d12_vulkan_device.cpp(+51 -3)📝
runtime/test/d3d12_indirect_rt_test.cpp(+11 -6)➕
runtime/test/d3d12_readback_arena_test.cpp(+118 -0)➕
runtime/test/d3d12_upload_arena_test.cpp(+211 -0)➕
runtime/test/shaders/cs_upload_read.asm(+23 -0)📝
scripts/run_gpu_tests.py(+1 -0)📄 Description
RT-UPLOAD-ARENA
Claimed in the coordination issue as: RT-UPLOAD-ARENA (upload and readback buffers live in the GPU address arena, so a V# can hold their VA)
What and why
Committed upload and readback buffers had memory of their own, and their console VA was their device address minus
the arena's (
heap_base): negative on the test GPUs. Root descriptors and vertex/index views resolve such a VA, buta V# keeps 48 bits of it, so a shader that reads an upload buffer through a descriptor (per-frame constants in an
upload heap behind a table, the usual case) goes to a wild address and the submission is lost. This is the failure
docs/d3d12_vulkan.mdmeasured as D3D-53; the 32-bit descriptor-table pointers most shaders use and the BVHbuilder's 2^40 rule cannot hold such a VA either.
Translating the VA at every use cannot fix the V# case: the descriptor bytes are written by the title (or the layer)
into heap memory the GPU reads, where no translation follows them. So this moves the buffers instead:
create_bufferplaces every CPU-visible committed buffer (UPLOAD, READBACK, CPU-visible CUSTOM) in the arena,which is host-visible and coherent: console VA = arena offset,
Mapreturns the arena's mapping at that offset,the bytes start zeroed there, and the range is registered with the arena buffer like a default-heap buffer and
returned with the resource. Every VA consumer (root descriptors, VBV/IBV, indirect arguments, copies, BVH inputs,
host_at) already resolves arena ranges. Placed buffers in upload/readback heaps were arena ranges already.LEONIDA_ARENA_MB(256 MiB by default) and the arena's memory type, which prefersDEVICE_LOCAL | HOST_VISIBLE(Resizable BAR), so a CPU read of a readback buffer there is uncached. A buffer thearena has no room for keeps its own memory with the old VA, logged once;
LEONIDA_UPLOAD_SYSMEM=1keeps uploadbuffers out of the arena that way.
rt::d3d12::vulkan_buffer_range(for tests) gives theVkBufferand offset that hold a buffer;d3d12_indirect_rt_testuses it for its upload/readback buffers, which no longer have aVkBufferof their own.docs/d3d12_vulkan.mdsection 3.3 and the measured D3D-53 paragraph.Tested
New
d3d12_upload_arena(translator-outputcs_upload_read.asm): a compute shader reads an UPLOAD buffer through araw SRV V# in a descriptor table and writes a default-heap UAV, the result is copied to a READBACK buffer and read
through its
Mappointer: VAs 0x20000 and 0x40000, 256 of 256 words match, clean underLEONIDA_VK_VALIDATION=1.With the upload buffer kept out of the arena (
LEONIDA_UPLOAD_SYSMEM=1, the old placement) its VA is0xfffffffd905f0000 and the test fails before dispatching.
Full
ctest -C RelWithDebInfo -j 4on this branch (then based ond2cd6c0d9; rebased ontoe21080465afterwards,whose new commits touch none of these files): 296 of 304 pass, including
d3d12_upload_arena,d3d12_indirect_rt,d3d12_computeandd3d12_vulkan_device. The 8 that fail do so for reasons outside this change on this PC:d3d12_subgroup(SegFault) andd3d12_set_descriptor_heaps(line 341: CHECK failed: !blob.empty()) fail the sameway on
maine21080465without this commit;root_signature_oracle,d3d12_close_parity,d3d12_pso_validationand
d3d12_root_args_validationcompare with the host D3D12 runtime / WARP of this Windows 10 machine and fail on rowsthat do not involve buffer placement;
d3d12_texture_tilesfails on this NVIDIA driver;xdxr_build_checktimed outunder the parallel load.
GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 617.42, Windows 10 22H2 (19045), Intel Core i7-11800H
AI-assisted: yes (Claude Code)
Checklist
main(d2cd6c0d9) and merges cleanly.docs/design.md(no translator change).🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.