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

Open
opened 2026-11-23 11:15:38 +00:00 by raylitebull · 1 comment
raylitebull commented 2026-11-23 11:15:38 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-23T11:15:38Z.


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).
<!-- greyfinch-sync:ivall/xcl:issue:6558038659 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/103). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-23T11:15:38Z. --- ## 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).
ivall commented 2026-11-24 07:00:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T11:42:54Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7099992212 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/issues/103#issuecomment-7099992212). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T11:42:54Z. --- 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.
Sign in to join this conversation.
No labels
No milestone
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.

Reference
xcl-dev/xcl#102
No description provided.