[PR #444] d3d12: upload and readback buffers live in the GPU address arena (RT-UPLOAD-ARENA) #495

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/444
Author: @Kokonotcu
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: pr/m8-upload-arena


📝 Commits (2)

  • 5a52674 d3d12: upload and readback buffers live in the GPU address arena (RT-UPLOAD-ARENA)
  • a902c78 d3d12: 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, but
a 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.md measured as D3D-53; the 32-bit descriptor-table pointers most shaders use and the BVH
builder'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_buffer places every CPU-visible committed buffer (UPLOAD, READBACK, CPU-visible CUSTOM) in the arena,
    which is host-visible and coherent: console VA = arena offset, Map returns 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.
  • Budget: these buffers now share LEONIDA_ARENA_MB (256 MiB by default) and the arena's memory type, which prefers
    DEVICE_LOCAL | HOST_VISIBLE (Resizable BAR), so a CPU read of a readback buffer there is uncached. A buffer the
    arena has no room for keeps its own memory with the old VA, logged once; LEONIDA_UPLOAD_SYSMEM=1 keeps upload
    buffers out of the arena that way.
  • rt::d3d12::vulkan_buffer_range (for tests) gives the VkBuffer and offset that hold a buffer;
    d3d12_indirect_rt_test uses it for its upload/readback buffers, which no longer have a VkBuffer of their own.
  • Docs: docs/d3d12_vulkan.md section 3.3 and the measured D3D-53 paragraph.

Tested

New d3d12_upload_arena (translator-output cs_upload_read.asm): a compute shader reads an UPLOAD buffer through a
raw SRV V# in a descriptor table and writes a default-heap UAV, the result is copied to a READBACK buffer and read
through its Map pointer: VAs 0x20000 and 0x40000, 256 of 256 words match, clean under LEONIDA_VK_VALIDATION=1.
With the upload buffer kept out of the arena (LEONIDA_UPLOAD_SYSMEM=1, the old placement) its VA is
0xfffffffd905f0000 and the test fails before dispatching.

Full ctest -C RelWithDebInfo -j 4 on this branch (then based on d2cd6c0d9; rebased onto e21080465 afterwards,
whose new commits touch none of these files): 296 of 304 pass, including d3d12_upload_arena, d3d12_indirect_rt,
d3d12_compute and d3d12_vulkan_device. The 8 that fail do so for reasons outside this change on this PC:
d3d12_subgroup (SegFault) and d3d12_set_descriptor_heaps (line 341: CHECK failed: !blob.empty()) fail the same
way on main e21080465 without this commit; root_signature_oracle, d3d12_close_parity, d3d12_pso_validation
and d3d12_root_args_validation compare with the host D3D12 runtime / WARP of this Windows 10 machine and fail on rows
that do not involve buffer placement; d3d12_texture_tiles fails on this NVIDIA driver; xdxr_build_check timed out
under 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

  • Based on current main (d2cd6c0d9) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of 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.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/444 **Author:** [@Kokonotcu](https://github.com/Kokonotcu) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/m8-upload-arena` --- ### 📝 Commits (2) - [`5a52674`](https://github.com/ubiquitarianism/leonida/commit/5a52674a736a9cc84ae72e498a701fd57c7273c2) d3d12: upload and readback buffers live in the GPU address arena (RT-UPLOAD-ARENA) - [`a902c78`](https://github.com/ubiquitarianism/leonida/commit/a902c78ab55e77ba78b43020c921dc0226a36387) d3d12: readback buffers stay out of the GPU address arena (review of #444) ### 📊 Changes **9 files changed** (+466 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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, but a 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.md` measured as D3D-53; the 32-bit descriptor-table pointers most shaders use and the BVH builder'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_buffer` places every CPU-visible committed buffer (UPLOAD, READBACK, CPU-visible CUSTOM) in the arena, which is host-visible and coherent: console VA = arena offset, `Map` returns 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. - Budget: these buffers now share `LEONIDA_ARENA_MB` (256 MiB by default) and the arena's memory type, which prefers `DEVICE_LOCAL | HOST_VISIBLE` (Resizable BAR), so a CPU read of a readback buffer there is uncached. A buffer the arena has no room for keeps its own memory with the old VA, logged once; `LEONIDA_UPLOAD_SYSMEM=1` keeps upload buffers out of the arena that way. - `rt::d3d12::vulkan_buffer_range` (for tests) gives the `VkBuffer` and offset that hold a buffer; `d3d12_indirect_rt_test` uses it for its upload/readback buffers, which no longer have a `VkBuffer` of their own. - Docs: `docs/d3d12_vulkan.md` section 3.3 and the measured D3D-53 paragraph. ### Tested New `d3d12_upload_arena` (translator-output `cs_upload_read.asm`): a compute shader reads an UPLOAD buffer through a raw SRV V# in a descriptor table and writes a default-heap UAV, the result is copied to a READBACK buffer and read through its `Map` pointer: VAs 0x20000 and 0x40000, 256 of 256 words match, clean under `LEONIDA_VK_VALIDATION=1`. With the upload buffer kept out of the arena (`LEONIDA_UPLOAD_SYSMEM=1`, the old placement) its VA is 0xfffffffd905f0000 and the test fails before dispatching. Full `ctest -C RelWithDebInfo -j 4` on this branch (then based on `d2cd6c0d9`; rebased onto `e21080465` afterwards, whose new commits touch none of these files): 296 of 304 pass, including `d3d12_upload_arena`, `d3d12_indirect_rt`, `d3d12_compute` and `d3d12_vulkan_device`. The 8 that fail do so for reasons outside this change on this PC: `d3d12_subgroup` (SegFault) and `d3d12_set_descriptor_heaps` (`line 341: CHECK failed: !blob.empty()`) fail the same way on `main` `e21080465` without this commit; `root_signature_oracle`, `d3d12_close_parity`, `d3d12_pso_validation` and `d3d12_root_args_validation` compare with the host D3D12 runtime / WARP of this Windows 10 machine and fail on rows that do not involve buffer placement; `d3d12_texture_tiles` fails on this NVIDIA driver; `xdxr_build_check` timed out under 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 - [x] Based on current `main` (d2cd6c0d9) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md` (no translator change). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#495
No description provided.