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

Merged
abnalstlll-byte merged 1 commit from upstream-pr/2141 into main 2026-11-25 23:27:11 +00:00
abnalstlll-byte commented 2026-11-25 22:58:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T22:58:47Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5500627348 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2141). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T22:58:47Z. --- 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).
ZroIsHere commented 2026-11-25 23:20:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ZroIsHere on 2026-11-25T23:20:38Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7177432638 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2141#issuecomment-7177432638). Originally posted by [ZroIsHere](https://github.com/ZroIsHere) on 2026-11-25T23:20:38Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2141
No description provided.