D3D12.X Presentation & Frame Pacing: multi-plane PresentX, HDR color space, multi-queue fallback lockout, and frame clock handle race #103

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

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

Summary

During a codebase audit of crates/xcl/src/hle/d3d12x/{present.rs, frame.rs, list_x.rs} (on main 60599a9), we verified several presentation and frame-pacing bugs that need deeper design/testing (some needing multi-plane or HDR title traces to verify end-to-end):

1. Multi-plane PresentX drops planes >= 1 (crates/xcl/src/hle/d3d12x/present.rs)

  • present_x_frame reads only plane 0 (planes.add(8) / planes.add(0x10)) and logs when plane_count > 1, silently discarding all additional planes (e.g., separate console HUD/UI overlay planes that need compositing over plane 0).

2. Fallback presentation can permanently lock out PresentX on a second queue (present.rs)

  • If fallback presentation (note_execute / on_queue_console_method) triggers once on Queue A before the first PresentX, new_presenter(queue_A) permanently pins PRESENTER.queue = queue_A.
  • When PresentX later arrives on Queue B, if p.queue != queue { return; } silently drops every PresentX frame forever.

3. HDR swap chains never call IDXGISwapChain3::SetColorSpace1 (present.rs)

  • swap_format creates DXGI_FORMAT_R10G10B10A2_UNORM and DXGI_FORMAT_R16G16B16A16_FLOAT swap chains, but ensure_swapchain never configures DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 / G10_NONE_P709 via SetColorSpace1, leaving HDR10 output displayed as washed-out SDR G22/P709.

4. frame.rs ancillary HANDLE use-after-close race, pipelined origin timestamp, and interval_valid edge values (crates/xcl/src/hle/d3d12x/frame.rs)

  • Use-after-close race: clock_thread clones raw HANDLEs from k.extra, drops the CLOCK mutex, and then calls SetEvent/ReleaseSemaphore on them without holding CLOCK. A concurrent schedule_frame_event_x call drains k.extra and calls CloseHandle(h), allowing clock_thread to signal closed or OS-recycled handles.
  • Pipelined origin timestamp: mark_flipped(token) records LAST_ORIGIN.load(Relaxed) instead of the origin QPC associated with token. With 2–3 frames in flight, GetFrameStatisticsX(token) returns a newer frame's origin timestamp.
  • interval_valid tolerances: near(16667, 16) rejects 16666 µs (1_000_000 / 60), near(66667, 67) rejects 66666 µs, and near(50000, 49) misses NTSC 50050 µs by 1 µs.

5. Write64BitValue* OS QPC timestamp flags write GPU timestamps instead (crates/xcl/src/hle/d3d12x/list_x.rs)

  • When a title requests a system/OS QPC timestamp via Write64BitValue* flags 2 / 8, list_x.rs writes the PC GPU timestamp instead, which can differ from QPC frequency by 100× (e.g., 1 GHz GPU clock vs 10 MHz QPC) and distort dynamic-resolution/frame-time calculations.

Notes

  • Window minimize (0×0 client rect) and Alt-Tab were also audited in present.rs and confirmed safe (swapchain dimensions come from the game's texture descriptor and DXGI_MWA_NO_ALT_ENTER is set).
**@⁠raylitebull** on GitHub · 2026-11-23 11:15 UTC · [original](https://github.com/xcl-dev/xcl/issues/103) ## Summary During a codebase audit of `crates/xcl/src/hle/d3d12x/{present.rs, frame.rs, list_x.rs}` (on `main` `60599a9`), we verified several presentation and frame-pacing bugs that need deeper design/testing (some needing multi-plane or HDR title traces to verify end-to-end): ### 1. Multi-plane `PresentX` drops planes `>= 1` (`crates/xcl/src/hle/d3d12x/present.rs`) - `present_x_frame` reads only plane 0 (`planes.add(8)` / `planes.add(0x10)`) and logs when `plane_count > 1`, silently discarding all additional planes (e.g., separate console HUD/UI overlay planes that need compositing over plane 0). ### 2. Fallback presentation can permanently lock out `PresentX` on a second queue (`present.rs`) - If fallback presentation (`note_execute` / `on_queue_console_method`) triggers once on Queue A before the first `PresentX`, `new_presenter(queue_A)` permanently pins `PRESENTER.queue = queue_A`. - When `PresentX` later arrives on Queue B, `if p.queue != queue { return; }` silently drops every `PresentX` frame forever. ### 3. HDR swap chains never call `IDXGISwapChain3::SetColorSpace1` (`present.rs`) - `swap_format` creates `DXGI_FORMAT_R10G10B10A2_UNORM` and `DXGI_FORMAT_R16G16B16A16_FLOAT` swap chains, but `ensure_swapchain` never configures `DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020` / `G10_NONE_P709` via `SetColorSpace1`, leaving HDR10 output displayed as washed-out SDR G22/P709. ### 4. `frame.rs` ancillary `HANDLE` use-after-close race, pipelined `origin` timestamp, and `interval_valid` edge values (`crates/xcl/src/hle/d3d12x/frame.rs`) - **Use-after-close race:** `clock_thread` clones raw `HANDLE`s from `k.extra`, drops the `CLOCK` mutex, and then calls `SetEvent`/`ReleaseSemaphore` on them without holding `CLOCK`. A concurrent `schedule_frame_event_x` call drains `k.extra` and calls `CloseHandle(h)`, allowing `clock_thread` to signal closed or OS-recycled handles. - **Pipelined `origin` timestamp:** `mark_flipped(token)` records `LAST_ORIGIN.load(Relaxed)` instead of the origin QPC associated with `token`. With 2–3 frames in flight, `GetFrameStatisticsX(token)` returns a newer frame's origin timestamp. - **`interval_valid` tolerances:** `near(16667, 16)` rejects `16666 µs` (`1_000_000 / 60`), `near(66667, 67)` rejects `66666 µs`, and `near(50000, 49)` misses NTSC `50050 µs` by 1 µs. ### 5. `Write64BitValue*` OS QPC timestamp flags write GPU timestamps instead (`crates/xcl/src/hle/d3d12x/list_x.rs`) - When a title requests a system/OS QPC timestamp via `Write64BitValue*` flags `2` / `8`, `list_x.rs` writes the PC GPU timestamp instead, which can differ from QPC frequency by 100× (e.g., 1 GHz GPU clock vs 10 MHz QPC) and distort dynamic-resolution/frame-time calculations. ## Notes - Window minimize (`0×0` client rect) and Alt-Tab were also audited in `present.rs` and confirmed **safe** (swapchain dimensions come from the game's texture descriptor and `DXGI_MWA_NO_ALT_ENTER` is set).
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 for the audit. Triage against current main:

  • 2. fallback presenter pinned to the first queue – confirmed, fixed in ea4bd62: a PresentX from another queue now moves the presenter (and the XCL window's swap chain) to that queue after the old copy completes, instead of dropping every frame.
  • 4. interval_valid – the tolerance part confirmed, fixed in ea4bd62: the check is now either side of the nominal length (16 666 / 66 666 µs accepted). Whether 50 050 µs is a valid console interval we don't know, so it stays out.
  • 4. ancillary HANDLE race / pipelined origin – plausible, not reproduced; a PR with a test that schedules / unschedules while the clock thread fires would be welcome.
  • 1. multi-plane PresentX – true by design for now (plane 0 only). None of the four titles we run presents more than one plane (the log line would show it); worth doing once a title needs it.
  • 3. HDR SetColorSpace1 – true; PRs welcome, ideally with a title that actually outputs HDR10 to check it on screen.
  • 5. Write64 QPC flags – the flag meanings come from observation, not documentation; without a title trace that shows flags 2 / 8 being compared against QPC we'd rather not change it.
**@⁠ivall** on GitHub · 2026-11-23 11:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/103#issuecomment-7099992212) Thanks for the audit. Triage against current `main`: - **2. fallback presenter pinned to the first queue – confirmed, fixed in ea4bd62:** a PresentX from another queue now moves the presenter (and the XCL window's swap chain) to that queue after the old copy completes, instead of dropping every frame. - **4. `interval_valid` – the tolerance part confirmed, fixed in ea4bd62:** the check is now either side of the nominal length (16 666 / 66 666 µs accepted). Whether 50 050 µs is a valid console interval we don't know, so it stays out. - **4. ancillary HANDLE race / pipelined origin** – plausible, not reproduced; a PR with a test that schedules / unschedules while the clock thread fires would be welcome. - **1. multi-plane PresentX** – true by design for now (plane 0 only). None of the four titles we run presents more than one plane (the log line would show it); worth doing once a title needs it. - **3. HDR `SetColorSpace1`** – true; PRs welcome, ideally with a title that actually outputs HDR10 to check it on screen. - **5. Write64 QPC flags** – the flag meanings come from observation, not documentation; without a title trace that shows flags 2 / 8 being compared against QPC we'd rather not change it.
This discussion has been locked. Commenting is limited to contributors.
No description provided.