D3D12.X Memory, Sync & GDK Drift: overlapping VRAM arenas, cross-queue texture upload state mismatch, SetPredicationBufferX state, and pre-Signal QUEUE_SHIFTED slot #18 overflow #104

Open
opened 2026-11-26 04:10:17 +00:00 by github-bot · 2 comments
Owner

@⁠raylitebull on GitHub · 2026-11-23 11:15 UTC · original

Summary

Verified 4 structural D3D12.X memory, synchronization, and GDK-version-drift bugs during an audit of crates/xcl/src/hle/d3d12x/ (on main 60599a9):

1. vram::arena_for creates overlapping ID3D12Heap arenas — breaks texture aliasing & leaks 128 MiB+ VRAM (crates/xcl/src/hle/d3d12x/vram.rs)

  • arena_for only checks whether an existing arena fully contains [va, va + bytes).
  • If a later placement starts before an existing arena's base or straddles its base + size boundary (e.g., [0x1_0400_0000, +16 MiB) then [0x1_0200_0000, +48 MiB)), arena_for allocates a new, separate ID3D12Heap overlapping the existing arena in title VA space.
  • Placed resources that alias in console memory end up on distinct PC heaps (breaking aliasing), and ARENAS has no eviction/budget cap so each miss leaks >= 128 MiB of DEFAULT VRAM.

2. title_textures::refresh re-uploads on a separate queue without GPU sync and uses stale creation state (crates/xcl/src/hle/d3d12x/title_textures.rs, crates/xcl/src/gpu/texture.rs)

  • upload_all executes on XCL's own upload_queue without GPU-waiting for in-flight work on the title's queue that may still be sampling the texture.
  • upload_batch transitions each texture e.state -> COPY_DEST -> e.state using its initial creation state recorded at CreatePlacedResourceX. Once the title transitions a texture (e.g., COMMON -> PIXEL_SHADER_RESOURCE, or COPY_DEST -> ALL_SHADER_RESOURCE) and CPU-writes to it (or a neighbor sharing the same 4 KiB write-watched page), record_upload emits an invalid BEFORE_AFTER transition (or zero barriers if e.state == COPY_DEST).

3. SetPredicationBufferX immediately transitions predication buffer back to COMMON (crates/xcl/src/hle/d3d12x/list_x.rs)

  • set_predication_buffer_x emits:
    1. COMMON -> PREDICATION
    2. SetPredication(b, off, op)
    3. PREDICATION -> COMMON
  • D3D12 reads the predication buffer on every subsequent Draw/Dispatch/Copy until SetPredication(NULL, ...); transitioning b back to COMMON immediately invalidates its state before any predicated command executes, and conflicts if a subsequent UMA shader/copy uses the same window buffer as UNORDERED_ACCESS / COPY_DEST.

4. Lazy QUEUE_SHIFTED detection on newer GDK layouts overflows 8-byte out-param on slot #18 and collides on list slots #83/#84 (crates/xcl/src/hle/d3d12x/real.rs)

  • QUEUE_SHIFTED starts false and only flips on the first call to queue slot #16 or #17 with a fence.
  • If a newer-layout title calls GetTimestampFrequency(UINT64 *pFreq) (newer slot #18) before its first Signal/Wait, queue_dispatch routes it to older slot #18 (GetDesc), writing a 16-byte D3D12_COMMAND_QUEUE_DESC into an 8-byte UINT64 out-parameter (8-byte stack/heap buffer overflow).
  • Even after QUEUE_SHIFTED flips true, NEWER_LIST_SLOTS leaves list slots #83 and #84 bound to older #83 (copy_texture_region_flags_x) / #84 (copy_resource_flags_x), colliding with shifted DrawIndexedX (81 + 2 = 83) on newer layouts.
  • (Note: Verifying the exact lower bound of the command-list shift requires a newer-GDK retail binary, while the #18 pre-Signal overflow and #83/#84 collision are directly visible in real.rs.)
**@⁠raylitebull** on GitHub · 2026-11-23 11:15 UTC · [original](https://github.com/xcl-dev/xcl/issues/104) ## Summary Verified 4 structural D3D12.X memory, synchronization, and GDK-version-drift bugs during an audit of `crates/xcl/src/hle/d3d12x/` (on `main` `60599a9`): ### 1. `vram::arena_for` creates overlapping `ID3D12Heap` arenas — breaks texture aliasing & leaks 128 MiB+ VRAM (`crates/xcl/src/hle/d3d12x/vram.rs`) - `arena_for` only checks whether an existing arena *fully contains* `[va, va + bytes)`. - If a later placement starts before an existing arena's `base` or straddles its `base + size` boundary (e.g., `[0x1_0400_0000, +16 MiB)` then `[0x1_0200_0000, +48 MiB)`), `arena_for` allocates a **new, separate `ID3D12Heap`** overlapping the existing arena in title VA space. - Placed resources that alias in console memory end up on distinct PC heaps (breaking aliasing), and `ARENAS` has no eviction/budget cap so each miss leaks >= 128 MiB of `DEFAULT` VRAM. ### 2. `title_textures::refresh` re-uploads on a separate queue without GPU sync and uses stale creation state (`crates/xcl/src/hle/d3d12x/title_textures.rs`, `crates/xcl/src/gpu/texture.rs`) - `upload_all` executes on XCL's own `upload_queue` without GPU-waiting for in-flight work on the title's queue that may still be sampling the texture. - `upload_batch` transitions each texture `e.state -> COPY_DEST -> e.state` using its **initial creation state** recorded at `CreatePlacedResourceX`. Once the title transitions a texture (e.g., `COMMON -> PIXEL_SHADER_RESOURCE`, or `COPY_DEST -> ALL_SHADER_RESOURCE`) and CPU-writes to it (or a neighbor sharing the same 4 KiB write-watched page), `record_upload` emits an invalid `BEFORE_AFTER` transition (or zero barriers if `e.state == COPY_DEST`). ### 3. `SetPredicationBufferX` immediately transitions predication buffer back to `COMMON` (`crates/xcl/src/hle/d3d12x/list_x.rs`) - `set_predication_buffer_x` emits: 1. `COMMON -> PREDICATION` 2. `SetPredication(b, off, op)` 3. `PREDICATION -> COMMON` - D3D12 reads the predication buffer on every subsequent Draw/Dispatch/Copy until `SetPredication(NULL, ...)`; transitioning `b` back to `COMMON` immediately invalidates its state before any predicated command executes, and conflicts if a subsequent UMA shader/copy uses the same window buffer as `UNORDERED_ACCESS` / `COPY_DEST`. ### 4. Lazy `QUEUE_SHIFTED` detection on newer GDK layouts overflows 8-byte out-param on slot `#18` and collides on list slots `#83`/`#84` (`crates/xcl/src/hle/d3d12x/real.rs`) - `QUEUE_SHIFTED` starts `false` and only flips on the first call to queue slot `#16` or `#17` with a fence. - If a newer-layout title calls `GetTimestampFrequency(UINT64 *pFreq)` (newer slot `#18`) before its first `Signal`/`Wait`, `queue_dispatch` routes it to older slot `#18` (`GetDesc`), writing a **16-byte `D3D12_COMMAND_QUEUE_DESC`** into an **8-byte `UINT64`** out-parameter (8-byte stack/heap buffer overflow). - Even after `QUEUE_SHIFTED` flips `true`, `NEWER_LIST_SLOTS` leaves list slots `#83` and `#84` bound to older `#83` (`copy_texture_region_flags_x`) / `#84` (`copy_resource_flags_x`), colliding with shifted `DrawIndexedX` (`81 + 2 = 83`) on newer layouts. - *(Note: Verifying the exact lower bound of the command-list shift requires a newer-GDK retail binary, while the `#18` pre-`Signal` overflow and `#83`/`#84` collision are directly visible in `real.rs`.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:17 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 11:42 UTC · original

Thanks. Triage against current main:

  • 1. overlapping vram arenas – confirmed (arena_for only reuses an arena that fully contains the range; a straddling placement gets a new heap over the same title addresses). A fix needs a non-overlapping arena layout (e.g. extend by allocating the remainder, or reserve larger aligned ranges) – PR welcome, with a test that places the straddling sequence you describe.
  • 2. title texture refresh on XCL's queue with the creation state – known (HANDOFF lists "the state if the title moved the texture out of its initial one" as not done); a PR that tracks the title's transitions for kept-in-step textures would be welcome.
  • 3. SetPredicationBufferX back to COMMON – the window buffers are buffers in COMMON, which D3D12 promotes implicitly to read states; we have not seen a debug-layer complaint or a wrong result from it. Happy to take a change if you have one that shows a problem.
  • 4. QUEUE_SHIFTED before the first Signal – the #18 ambiguity is real on the newer layout; the only title we run on it (Unicorn Overlord) signals first. A safer route for #18 until the layout is known (e.g. treating the out-param as 8 bytes) would be a good small PR.
**@⁠ivall** on GitHub · 2026-11-23 11:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/104#issuecomment-7099992535) Thanks. Triage against current `main`: - **1. overlapping `vram` arenas – confirmed** (`arena_for` only reuses an arena that fully contains the range; a straddling placement gets a new heap over the same title addresses). A fix needs a non-overlapping arena layout (e.g. extend by allocating the remainder, or reserve larger aligned ranges) – PR welcome, with a test that places the straddling sequence you describe. - **2. title texture refresh on XCL's queue with the creation state** – known (HANDOFF lists "the state if the title moved the texture out of its initial one" as not done); a PR that tracks the title's transitions for kept-in-step textures would be welcome. - **3. `SetPredicationBufferX` back to COMMON** – the window buffers are buffers in COMMON, which D3D12 promotes implicitly to read states; we have not seen a debug-layer complaint or a wrong result from it. Happy to take a change if you have one that shows a problem. - **4. `QUEUE_SHIFTED` before the first Signal** – the `#18` ambiguity is real on the newer layout; the only title we run on it (Unicorn Overlord) signals first. A safer route for `#18` until the layout is known (e.g. treating the out-param as 8 bytes) would be a good small PR.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:14 UTC · original

Progress: the overlapping VRAM arenas are gone for GPU-owned textures - they are tiled resources on 64 KiB pages of video memory now, one per page of the title's address (38b05b7); arenas remain only for what the driver will not tile (D32S8, MSAA). The cross-queue texture upload state is #135 (merged).

**@⁠ivall** on GitHub · 2026-11-23 21:14 UTC · [original](https://github.com/xcl-dev/xcl/issues/104#issuecomment-7114204637) Progress: the overlapping VRAM arenas are gone for GPU-owned textures - they are tiled resources on 64 KiB pages of video memory now, one per page of the title's address (38b05b7); arenas remain only for what the driver will not tile (D32S8, MSAA). The cross-queue texture upload state is #135 (merged).
This discussion has been locked. Commenting is limited to contributors.
No description provided.