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

Closed
opened 2026-11-26 21:20:12 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2141
Author: @abnalstlll-byte
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: feat/rt-direct-heap-arena-remap


📝 Commits (1)

  • 92170fe d3d12: remap directly-indexed heaps to arena shader VA (RT-DIRECT-HEAP-ARENA-REMAP)

📊 Changes

3 files changed (+36 additions, -10 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+4 -1)
📝 runtime/shims/d3d12_com.cpp (+18 -9)
📝 runtime/test/d3d12_set_descriptor_heaps_test.cpp (+14 -0)

📄 Description

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


🔄 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/2141 **Author:** [@abnalstlll-byte](https://github.com/abnalstlll-byte) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `feat/rt-direct-heap-arena-remap` --- ### 📝 Commits (1) - [`92170fe`](https://github.com/ubiquitarianism/leonida/commit/92170fe7af4739242723ff78b6cddd129986e536) d3d12: remap directly-indexed heaps to arena shader VA (RT-DIRECT-HEAP-ARENA-REMAP) ### 📊 Changes **3 files changed** (+36 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+4 -1) 📝 `runtime/shims/d3d12_com.cpp` (+18 -9) 📝 `runtime/test/d3d12_set_descriptor_heaps_test.cpp` (+14 -0) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:12 +01:00
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#2148
No description provided.