D3D12.X: console_list binds RootSignature before DescriptorHeaps (#1419), ClearUAV uses uninitialized g.pc_gpu_uav after inline copy, and MSAA companion SRV / null UAV desc bugs #2461

Open
opened 2026-11-26 05:31:21 +00:00 by github-bot · 0 comments
Owner

@⁠microwave805 on GitHub · 2026-11-25 19:30 UTC · original

Static audit on main @ c7e1799 found four D3D12 descriptor-heap / view validation bugs in recently merged code (#2323, #1291, #1914) that trigger D3D12 debug-layer errors or device removal (0x887A0001):

1. console_list::close() binds SetComputeRootSignature before SetDescriptorHeaps (D3D12 #1419 / #1420)

  • Where: crates/xcl/src/hle/d3d12x/console_list.rs:902-906, crates/xcl/src/gpu/recomp/pso.rs:1350
  • Root cause: Every translated ABI root signature unconditionally sets D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (pso.rs:1350). D3D12 SM 6.6 requires SetDescriptorHeaps before SetComputeRootSignature (compare bind.rs:994 vs 1031), yet console_list::close() calls SetComputeRootSignature (lines 902-905) before ensure_dispatch_heaps (line 906).
  • Fix: Move ensure_dispatch_heaps(&list, &mut bound_heaps, &mut has_sampler_heap); above line 901.

2. ensure_view_heap and ensure_dispatch_heaps gate global_heap() on XCL_HEAP_WINDOWS=1 despite unconditionally setting CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED

  • Where: crates/xcl/src/hle/d3d12x/list_x.rs:3697-3701, crates/xcl/src/hle/d3d12x/console_list.rs:725, crates/xcl/src/gpu/recomp/pso.rs:1350
  • Root cause: Both helpers only bind the shader-visible CBV/SRV/UAV global_heap() when pso::heap_windows() (XCL_HEAP_WINDOWS=1, OFF by default) is enabled, and neither lazily calls console_heap::shared_heap(dev). Under default settings, a fresh compute list (or any list after SetDescriptorHeaps(0, NULL)) dispatching a translated shader binds only GLOBAL_SAMPLER with 0 CBV/SRV/UAV heaps bound, violating CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12 #1419 / 0x887A0001).
  • Fix: Remove the pso::heap_windows() gate at list_x.rs:3697 and console_list.rs:725 and lazily initialize console_heap::shared_heap(dev) when global_heap() is None.

3. ClearUnorderedAccessView* passes uninitialized g.pc_gpu_uav when a title copies UAV descriptors via inline RAM memcpy (CopyDescriptorsSimple)

  • Where: crates/xcl/src/hle/d3d12x/list_x.rs:4226-4232, crates/xcl/src/hle/d3d12x/console_list.rs:830-831 (with console_heap.rs:13-20, 454-461, real.rs:2653-2656)
  • Root cause: With GLOBAL shared hosting active (default), creating a UAV in a CPU-only console heap publishes it into GLOBAL at c.pc_gpu_uav. When a title copies that 32-byte descriptor into a shader-visible console heap via inline RAM memcpy (CopyDescriptorsSimple, bypassing ID3D12Device::CopyDescriptors*), g.pc_gpu_uav is uninitialized (its page may even be freshly allocated on the fly by console_heap::slot(gpu)). Both uav_clear_handles and console_list.rs:830-831 pass g.pc_gpu_uav instead of c.pc_gpu_uav.
  • Fix: When c.shared_srv != 0 && g.shared_srv != 0 (both hosted in GLOBAL), use c.pc_gpu_uav as the GPU handle.

4. Invalid null UAV desc (ArraySize = 0 / WSize = 0) in dev_create_uav_checked_x and non-MS companion SRV for MSAA textures in uav_companion_srv

  • Where: crates/xcl/src/hle/d3d12x/real.rs:2117-2123, 2480-2538, 2702-2708 (with device_x.rs:806)
  • Root cause:
    1. When !pc_typed_uav_supported, dev_create_uav_checked_x (real.rs:2118-2122) constructs null_desc with ..Default::default(), leaving Texture1DArray.ArraySize == 0, Texture2DArray.ArraySize == 0, and Texture3D.WSize == 0 (CREATEUNORDEREDACCESSVIEW_INVALIDDIMENSIONS), instead of reusing null_uav_desc(desc.as_ref(), Some(&rd)).
    2. device_x::pc_resource_desc strips ALLOW_UNORDERED_ACCESS from MSAA textures (samples > 1), so dev_create_uav_x emits a null PC UAV — but then creates the #1914 companion SRV (real.rs:2702-2708) with non-null res and uav_companion_srv emits non-MS D3D12_SRV_DIMENSION_TEXTURE2D / TEXTURE2DARRAY for a multisampled resource (CREATESHADERRESOURCEVIEW_INVALIDDESC / 0x887A0001). Also, when no_uav == true on a non-depth typeless texture with desc == NULL or Format == UNKNOWN, line 2529 copies the raw *_TYPELESS format into the SRV (CREATESHADERRESOURCEVIEW_INVALIDFORMAT).
  • Fix: Use null_uav_desc at real.rs:2117-2122; in uav_companion_srv, map dim == 4 / 5 to TEXTURE2DMS / TEXTURE2DMSARRAY when !null_resource && rd.SampleDesc.Count > 1, and avoid emitting raw *_TYPELESS formats for non-null SRVs.

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ c7e1799 and issue drafting.
**@⁠microwave805** on GitHub · 2026-11-25 19:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/2461) Static audit on `main @ c7e1799` found four D3D12 descriptor-heap / view validation bugs in recently merged code (#2323, #1291, #1914) that trigger D3D12 debug-layer errors or device removal (`0x887A0001`): ### 1. `console_list::close()` binds `SetComputeRootSignature` before `SetDescriptorHeaps` (D3D12 #1419 / #1420) - **Where:** `crates/xcl/src/hle/d3d12x/console_list.rs:902-906`, `crates/xcl/src/gpu/recomp/pso.rs:1350` - **Root cause:** Every translated ABI root signature unconditionally sets `D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED` (`pso.rs:1350`). D3D12 SM 6.6 requires `SetDescriptorHeaps` **before** `SetComputeRootSignature` (compare `bind.rs:994` vs `1031`), yet `console_list::close()` calls `SetComputeRootSignature` (lines 902-905) before `ensure_dispatch_heaps` (line 906). - **Fix:** Move `ensure_dispatch_heaps(&list, &mut bound_heaps, &mut has_sampler_heap);` above line 901. ### 2. `ensure_view_heap` and `ensure_dispatch_heaps` gate `global_heap()` on `XCL_HEAP_WINDOWS=1` despite unconditionally setting `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` - **Where:** `crates/xcl/src/hle/d3d12x/list_x.rs:3697-3701`, `crates/xcl/src/hle/d3d12x/console_list.rs:725`, `crates/xcl/src/gpu/recomp/pso.rs:1350` - **Root cause:** Both helpers only bind the shader-visible CBV/SRV/UAV `global_heap()` when `pso::heap_windows()` (`XCL_HEAP_WINDOWS=1`, OFF by default) is enabled, and neither lazily calls `console_heap::shared_heap(dev)`. Under default settings, a fresh compute list (or any list after `SetDescriptorHeaps(0, NULL)`) dispatching a translated shader binds only `GLOBAL_SAMPLER` with 0 CBV/SRV/UAV heaps bound, violating `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` (D3D12 #1419 / `0x887A0001`). - **Fix:** Remove the `pso::heap_windows()` gate at `list_x.rs:3697` and `console_list.rs:725` and lazily initialize `console_heap::shared_heap(dev)` when `global_heap()` is `None`. ### 3. `ClearUnorderedAccessView*` passes uninitialized `g.pc_gpu_uav` when a title copies UAV descriptors via inline RAM `memcpy` (`CopyDescriptorsSimple`) - **Where:** `crates/xcl/src/hle/d3d12x/list_x.rs:4226-4232`, `crates/xcl/src/hle/d3d12x/console_list.rs:830-831` (with `console_heap.rs:13-20, 454-461`, `real.rs:2653-2656`) - **Root cause:** With `GLOBAL` shared hosting active (default), creating a UAV in a CPU-only console heap publishes it into `GLOBAL` at `c.pc_gpu_uav`. When a title copies that 32-byte descriptor into a shader-visible console heap via inline RAM `memcpy` (`CopyDescriptorsSimple`, bypassing `ID3D12Device::CopyDescriptors*`), `g.pc_gpu_uav` is uninitialized (its page may even be freshly allocated on the fly by `console_heap::slot(gpu)`). Both `uav_clear_handles` and `console_list.rs:830-831` pass `g.pc_gpu_uav` instead of `c.pc_gpu_uav`. - **Fix:** When `c.shared_srv != 0 && g.shared_srv != 0` (both hosted in `GLOBAL`), use `c.pc_gpu_uav` as the GPU handle. ### 4. Invalid null UAV desc (`ArraySize = 0` / `WSize = 0`) in `dev_create_uav_checked_x` and non-MS companion SRV for MSAA textures in `uav_companion_srv` - **Where:** `crates/xcl/src/hle/d3d12x/real.rs:2117-2123`, `2480-2538`, `2702-2708` (with `device_x.rs:806`) - **Root cause:** 1. When `!pc_typed_uav_supported`, `dev_create_uav_checked_x` (`real.rs:2118-2122`) constructs `null_desc` with `..Default::default()`, leaving `Texture1DArray.ArraySize == 0`, `Texture2DArray.ArraySize == 0`, and `Texture3D.WSize == 0` (`CREATEUNORDEREDACCESSVIEW_INVALIDDIMENSIONS`), instead of reusing `null_uav_desc(desc.as_ref(), Some(&rd))`. 2. `device_x::pc_resource_desc` strips `ALLOW_UNORDERED_ACCESS` from MSAA textures (`samples > 1`), so `dev_create_uav_x` emits a null PC UAV — but then creates the #1914 companion SRV (`real.rs:2702-2708`) with non-null `res` and `uav_companion_srv` emits non-MS `D3D12_SRV_DIMENSION_TEXTURE2D` / `TEXTURE2DARRAY` for a multisampled resource (`CREATESHADERRESOURCEVIEW_INVALIDDESC` / `0x887A0001`). Also, when `no_uav == true` on a non-depth typeless texture with `desc == NULL` or `Format == UNKNOWN`, line 2529 copies the raw `*_TYPELESS` format into the SRV (`CREATESHADERRESOURCEVIEW_INVALIDFORMAT`). - **Fix:** Use `null_uav_desc` at `real.rs:2117-2122`; in `uav_companion_srv`, map `dim == 4 / 5` to `TEXTURE2DMS / TEXTURE2DMSARRAY` when `!null_resource && rd.SampleDesc.Count > 1`, and avoid emitting raw `*_TYPELESS` formats for non-null SRVs. ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ c7e1799` and issue drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:31:21 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.