d3d12: remap directly-indexed heaps to arena shader VA (RT-DIRECT-HEAP-ARENA-REMAP) #2141

Manually merged
github merged 1 commit from gh-pr/2141/head into gh-pr/2141/base 2026-11-26 10:19:55 +00:00
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 22:58 UTC · original
abnalstlll-byte:feat/rt-direct-heap-arena-remap → main · +36 −10 · 3 files · 1 commits · merged 2026-11-25 23:27 UTC

Remap directly indexed CBV/SRV/UAV and sampler heap console base addresses to arena shader virtual addresses in user SGPRs.

Problem

In write_direct_heaps(), the bound resource and sampler heaps were passed into user SGPRs using raw cbv_srv_uav_base_ and sampler_base_. For console descriptor heaps shadowed in the GPU address arena (where the title's pages are mirrored/shadowed into the GPU address arena so that heap_base + VA reaches them), passing raw console base addresses gave shaders the host title virtual address (e.g. 0x34ab42000) rather than the arena copy's shader VA (console_shader_va_).

When compute shaders (such as lib_cs_01405/01410/01455/00863/00867) or graphics shaders index directly into the resource heap using s[end] during the world load transition (~200s), adding heap_base + s[end] attempted to read unmapped memory outside the arena, triggering GPU device loss (READ_INVALID). Notice that record_dispatch() diagnostic logging already distinguished bound-heap (raw console base) from shader-heap (console_descriptor_table_va(cbv_srv_uav_base_)), but write_direct_heaps() and note_direct_heap_indexing() passed the raw console base.

Solution

  1. In write_direct_heaps(): pass console_descriptor_table_va(cbv_srv_uav_base_) and console_descriptor_table_va(sampler_base_) into the user SGPR data dwords. For ordinary unshadowed heaps, console_descriptor_table_va() returns the address unchanged.
  2. In note_direct_heap_indexing(): track remember_table(console_descriptor_table_va(cbv_srv_uav_base_), ...) using the translated shader VA so table origin tracking correlates properly.
  3. In graphics_user_data(): log the remapped shader VA for diagnostic consistency.
  4. In runtime/test/d3d12_set_descriptor_heaps_test.cpp: assert that recorded dispatch user data dwords receive the remapped console_descriptor_table_va addresses at compute_arguments_end.
  5. Updated docs/d3d12_vulkan.md with the direct heap arena remapping contract.

Verification

  • python -I scripts/check_no_game_data.py runtime/shims/d3d12_com.cpp runtime/test/d3d12_set_descriptor_heaps_test.cpp docs/d3d12_vulkan.md -> 0 violations.
  • python -I tests/test_text_write_line_endings.py -> 3/3 PASS.
  • python -m compileall -q make_game.py tools tests -> Clean.
  • ninja -C runtime/build_portable descriptor_table_test root_signature_test title_va_alias_test console_heap_vsharp_slots_test -> All PASS.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 22:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2141) `abnalstlll-byte:feat/rt-direct-heap-arena-remap` → `main` · +36 −10 · 3 files · 1 commits · merged 2026-11-25 23:27 UTC Remap directly indexed CBV/SRV/UAV and sampler heap console base addresses to arena shader virtual addresses in user SGPRs. ### Problem In `write_direct_heaps()`, the bound resource and sampler heaps were passed into user SGPRs using raw `cbv_srv_uav_base_` and `sampler_base_`. For console descriptor heaps shadowed in the GPU address arena (where the title's pages are mirrored/shadowed into the GPU address arena so that `heap_base + VA` reaches them), passing raw console base addresses gave shaders the host title virtual address (e.g. `0x34ab42000`) rather than the arena copy's shader VA (`console_shader_va_`). When compute shaders (such as `lib_cs_01405/01410/01455/00863/00867`) or graphics shaders index directly into the resource heap using `s[end]` during the world load transition (~200s), adding `heap_base + s[end]` attempted to read unmapped memory outside the arena, triggering GPU device loss (`READ_INVALID`). Notice that `record_dispatch()` diagnostic logging already distinguished `bound-heap` (raw console base) from `shader-heap` (`console_descriptor_table_va(cbv_srv_uav_base_)`), but `write_direct_heaps()` and `note_direct_heap_indexing()` passed the raw console base. ### Solution 1. In `write_direct_heaps()`: pass `console_descriptor_table_va(cbv_srv_uav_base_)` and `console_descriptor_table_va(sampler_base_)` into the user SGPR data dwords. For ordinary unshadowed heaps, `console_descriptor_table_va()` returns the address unchanged. 2. In `note_direct_heap_indexing()`: track `remember_table(console_descriptor_table_va(cbv_srv_uav_base_), ...)` using the translated shader VA so table origin tracking correlates properly. 3. In `graphics_user_data()`: log the remapped shader VA for diagnostic consistency. 4. In `runtime/test/d3d12_set_descriptor_heaps_test.cpp`: assert that recorded dispatch user data dwords receive the remapped `console_descriptor_table_va` addresses at `compute_arguments_end`. 5. Updated `docs/d3d12_vulkan.md` with the direct heap arena remapping contract. ### Verification - `python -I scripts/check_no_game_data.py runtime/shims/d3d12_com.cpp runtime/test/d3d12_set_descriptor_heaps_test.cpp docs/d3d12_vulkan.md` -> 0 violations. - `python -I tests/test_text_write_line_endings.py` -> 3/3 PASS. - `python -m compileall -q make_game.py tools tests` -> Clean. - `ninja -C runtime/build_portable descriptor_table_test root_signature_test title_va_alias_test console_heap_vsharp_slots_test` -> All PASS. AI-assisted (Claude Code, Claude Opus 5.5).
In write_direct_heaps(), the bound resource and sampler heaps were passed using raw cbv_srv_uav_base_ and sampler_base_. For console descriptor heaps shadowed in the GPU address arena, this supplied the title's host console VA rather than the shader VA where GPU descriptor reads land, triggering GPU device loss (READ_INVALID) in compute/graphics passes during world transition.

Remap the bound bases through console_descriptor_table_va() before writing them to user SGPRs and tracking in remember_table() and graphics_user_data(). Update d3d12_set_descriptor_heaps_test to assert that recorded dispatch user data receives the remapped console_descriptor_table_va addresses.

AI-assisted (Claude Code, Claude Opus 5.5).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:19:50 +00:00
github manually merged commit 92170fe7af into gh-pr/2141/base 2026-11-26 10:19:55 +00:00
Author
Owner

@⁠ZroIsHere on GitHub · 2026-11-25 23:20 UTC · original

I reproduced the test failure and pushed a testable fix on the integration branch: github.com/ZroIsHere/leonida@3b613c512

It factors the runtime packing into write_direct_heap_bases() and tests that exact helper rather than dispatching without a compute PSO. Focused MSVC/Vulkan checks pass: dstorage_test (551), title_memory_map_test (21), d3d12_set_descriptor_heaps_test, and queue_holds_report_test. No game files used.

**@⁠ZroIsHere** on GitHub · 2026-11-25 23:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2141#issuecomment-7177432638) I reproduced the test failure and pushed a testable fix on the integration branch: https://github.com/ZroIsHere/leonida/commit/3b613c512 It factors the runtime packing into `write_direct_heap_bases()` and tests that exact helper rather than dispatching without a compute PSO. Focused MSVC/Vulkan checks pass: `dstorage_test` (551), `title_memory_map_test` (21), `d3d12_set_descriptor_heaps_test`, and `queue_holds_report_test`. No game files used.
This discussion has been locked. Commenting is limited to contributors.
No description provided.