D3D12.X: hosted view heap exhaustion aliases 2*k into GLOBAL (and MEM_HEAP_BASE) instead of slot 0 #2380

Open
opened 2026-11-26 05:29:36 +00:00 by github-bot · 1 comment
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-25 17:32 UTC · original

Summary

In crates/xcl/src/hle/d3d12x/console_heap.rs, slot() guards hosted sampler heaps against GLOBAL_SAMPLER exhaustion by mapping overflowed slots to reserved slot 0 (lines 447-450):

// If this sampler heap is hosted in `GLOBAL_SAMPLER` (`!h.pages.is_empty()`), an exhausted
// shared heap must map overflowed slots to reserved zero-sampler slot 0 rather than
// aliasing unrelated heap entries at local index `k`.
let (index, shared_srv) = shared.unwrap_or_else(|| (sampler_unmapped_index(!h.pages.is_empty(), k), 0));

However, the CBV/SRV/UAV view-heap branch immediately below (lines 454-461) still falls back to local index 2 * k even when the heap is hosted in GLOBAL (!h.pages.is_empty()):

let shared = page_of(h, k).and_then(|(first, k0)| {
    let g = GLOBAL.lock().unwrap();
    let g = g.as_ref()?;
    let i = first + 2 * (k - k0);
    Some((i, g.gpu + (i as u64 + 1) * g.inc as u64, g.cpu + i as u64 * g.inc as u64))
});
let (index, pc_gpu_uav, shared_srv) = shared.unwrap_or((2 * k, if h.pc_gpu == 0 { 0 } else { h.pc_gpu + uav }, 0));

When GLOBAL is exhausted (page_of(h, k) returns None), index = 2 * k indexes directly into GLOBAL — aliasing MEM_HEAP_BASE..MEM_HEAP_BASE + MAX_HEAP_WINDOWS (window raw-buffer UAVs) or another heap's live descriptors instead of reserved null-view slot 0.

Suggested fix

Mirror sampler_unmapped_index for view heaps:

let fallback_index = if !h.pages.is_empty() { 0 } else { 2 * k };
let (index, pc_gpu_uav, shared_srv) = shared.unwrap_or((fallback_index, if h.pc_gpu == 0 { 0 } else { h.pc_gpu + uav }, 0));

Not tested

  • Read from commit 082944135cd2b96288470a595861fa608eee08dc without a new runtime test.

AI use

  • Antigravity harness (Gemini 4 Neon) audited console_heap.rs and drafted this report; the author reviewed it before posting.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 17:32 UTC · [original](https://github.com/xcl-dev/xcl/issues/2380) ### Summary In `crates/xcl/src/hle/d3d12x/console_heap.rs`, `slot()` guards hosted sampler heaps against `GLOBAL_SAMPLER` exhaustion by mapping overflowed slots to reserved slot `0` (lines 447-450): ```rust // If this sampler heap is hosted in `GLOBAL_SAMPLER` (`!h.pages.is_empty()`), an exhausted // shared heap must map overflowed slots to reserved zero-sampler slot 0 rather than // aliasing unrelated heap entries at local index `k`. let (index, shared_srv) = shared.unwrap_or_else(|| (sampler_unmapped_index(!h.pages.is_empty(), k), 0)); ``` However, the CBV/SRV/UAV view-heap branch immediately below (lines 454-461) still falls back to local index `2 * k` even when the heap is hosted in `GLOBAL` (`!h.pages.is_empty()`): ```rust let shared = page_of(h, k).and_then(|(first, k0)| { let g = GLOBAL.lock().unwrap(); let g = g.as_ref()?; let i = first + 2 * (k - k0); Some((i, g.gpu + (i as u64 + 1) * g.inc as u64, g.cpu + i as u64 * g.inc as u64)) }); let (index, pc_gpu_uav, shared_srv) = shared.unwrap_or((2 * k, if h.pc_gpu == 0 { 0 } else { h.pc_gpu + uav }, 0)); ``` When `GLOBAL` is exhausted (`page_of(h, k)` returns `None`), `index = 2 * k` indexes directly into `GLOBAL` — aliasing `MEM_HEAP_BASE..MEM_HEAP_BASE + MAX_HEAP_WINDOWS` (window raw-buffer UAVs) or another heap's live descriptors instead of reserved null-view slot `0`. ### Suggested fix Mirror `sampler_unmapped_index` for view heaps: ```rust let fallback_index = if !h.pages.is_empty() { 0 } else { 2 * k }; let (index, pc_gpu_uav, shared_srv) = shared.unwrap_or((fallback_index, if h.pc_gpu == 0 { 0 } else { h.pc_gpu + uav }, 0)); ``` ### Not tested - Read from commit `082944135cd2b96288470a595861fa608eee08dc` without a new runtime test. ### AI use - Antigravity harness (Gemini 4 Neon) audited `console_heap.rs` and drafted this report; the author reviewed it before posting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:36 +00:00
Author
Owner

@⁠Creaa on GitHub · 2026-11-25 17:42 UTC · original

Taking this: a hosted view heap whose shared range is exhausted maps the slot to the null SRV / UAV pair at descriptors 0 / 1 of the shared heap (as sampler_unmapped_index does for samplers), not to 2 * k, which can land on another heap's views or on the memory windows' raw views at MEM_HEAP_BASE (a texture read of those hangs the GPU). Unhosted heaps keep 2 * k. With a unit test next to the sampler one, the full suite and the smoke pair.

AI use: Claude Code (Claude Opus 5.5) drafted this.

**@⁠Creaa** on GitHub · 2026-11-25 17:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/2380#issuecomment-7169882608) Taking this: a hosted view heap whose shared range is exhausted maps the slot to the null SRV / UAV pair at descriptors 0 / 1 of the shared heap (as `sampler_unmapped_index` does for samplers), not to `2 * k`, which can land on another heap's views or on the memory windows' raw views at `MEM_HEAP_BASE` (a texture read of those hangs the GPU). Unhosted heaps keep `2 * k`. With a unit test next to the sampler one, the full suite and the smoke pair. AI use: Claude Code (Claude Opus 5.5) drafted this.
This discussion has been locked. Commenting is limited to contributors.
No description provided.