Frame clock: revalidate clock state before committing ScheduleFrameEventX #1611

Open
b3IKK wants to merge 1 commit from upstream-pr/1621 into main
b3IKK commented 2026-11-24 18:19:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:19:12Z.


schedule_frame_event_x released the CLOCK mutex while duplicating ancillary event handles, then committed c.active = true and k.scheduled = true without re-checking whether another thread had stopped the clock via SetFrameIntervalX(0) in the meantime. That left the clock marked active and scheduled with interval_us == 0, where clock_thread does not run and WaitFrameEventX hangs indefinitely.

This extracts schedule_invalid() and commit_schedule(), re-checking validity under the CLOCK lock before mutating state and closing duplicated handles on E_INVALIDARG.

What is in it

  • crates/xcl/src/hle/d3d12x/frame.rs: add schedule_invalid() and commit_schedule() to revalidate under CLOCK before committing in schedule_frame_event_x; add unit test commit_schedule_rejects_clock_stopped_between_check_and_commit.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1 no heap windows — heap_window_out_of_memory_falls_back_to_the_switch_form)
  • cargo test -p xcl --lib hle::d3d12x::frame::tests: 5 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 39788e8cbe7d12828b1e54a40112340ac0d6adba
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14602 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited frame.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5477869026 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T18:19:12Z. --- `schedule_frame_event_x` released the `CLOCK` mutex while duplicating ancillary event handles, then committed `c.active = true` and `k.scheduled = true` without re-checking whether another thread had stopped the clock via `SetFrameIntervalX(0)` in the meantime. That left the clock marked active and scheduled with `interval_us == 0`, where `clock_thread` does not run and `WaitFrameEventX` hangs indefinitely. This extracts `schedule_invalid()` and `commit_schedule()`, re-checking validity under the `CLOCK` lock before mutating state and closing duplicated handles on `E_INVALIDARG`. **What is in it** - `crates/xcl/src/hle/d3d12x/frame.rs`: add `schedule_invalid()` and `commit_schedule()` to revalidate under `CLOCK` before committing in `schedule_frame_event_x`; add unit test `commit_schedule_rejects_clock_stopped_between_check_and_commit`. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`; 1 `no heap windows` — `heap_window_out_of_memory_falls_back_to_the_switch_form`) - `cargo test -p xcl --lib hle::d3d12x::frame::tests`: 5 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 39788e8cbe7d12828b1e54a40112340ac0d6adba gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1643 (PresentX 1643) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14602 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `frame.rs`, wrote the fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
DavidM1911 commented 2026-11-24 21:09:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:37:51Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7143842418 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7143842418). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T20:37:51Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
JJAutoCompare commented 2026-11-25 05:08:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:00:29Z.


XCL PR #1621 focused Windows verification

Tested head 39788e8cbe7d12828b1e54a40112340ac0d6adba in a clean detached checkout. The PR changes crates/xcl/src/hle/d3d12x/frame.rs.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation x64 (build 26200), AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), DXC 1.9.2609.5, and rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Dev and test builds were unoptimized with debug info and incremental compilation disabled.
  • cargo build --workspace succeeded. cargo test --workspace --no-run compiled all workspace test executables.
  • cargo test -p xcl --lib hle::d3d12x::frame::tests:: -- --nocapture ran with XCL_ADAPTER=NONE_CPU_ONLY. Parsed from pr1621-focused.log — 5 passed, 0 failed, 0 ignored, 0 SKIPPED, 744 filtered out. All three commands ran outside the Arc mutex.
  • The new regression test simulates the clock stopping between the initial check and commit. It verifies that a zero-interval clock returns E_INVALIDARG, stays inactive, and leaves the origin unscheduled. With a 16,667 µs interval, scheduling type 0 returns STARTED_CLOCK, activates the clock, and schedules the origin.
  • The other four tests covered interval validation and deadline arithmetic, origin wake ordering, frame tokens and flip statistics, and ancillary event handle lifetime during rescheduling.

Not tested

Execution was limited to the focused CPU frame-clock tests. The rest of the workspace was compiled only. The full GPU workspace suite and retail-title smoke comparisons were omitted.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1621-focused.log and published.

<!-- greyfinch-sync:ivall/xcl:comment:7153362513 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7153362513). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T05:00:29Z. --- # XCL PR #1621 focused Windows verification Tested head `39788e8cbe7d12828b1e54a40112340ac0d6adba` in a clean detached checkout. The PR changes `crates/xcl/src/hle/d3d12x/frame.rs`. **Tested** - STOR-WINLAB, Windows 11 Enterprise Evaluation x64 (build 26200), AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), DXC 1.9.2609.5, and rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Dev and test builds were unoptimized with debug info and incremental compilation disabled. - `cargo build --workspace` succeeded. `cargo test --workspace --no-run` compiled all workspace test executables. - `cargo test -p xcl --lib hle::d3d12x::frame::tests:: -- --nocapture` ran with `XCL_ADAPTER=NONE_CPU_ONLY`. Parsed from `pr1621-focused.log` — 5 passed, 0 failed, 0 ignored, 0 SKIPPED, 744 filtered out. All three commands ran outside the Arc mutex. - The new regression test simulates the clock stopping between the initial check and commit. It verifies that a zero-interval clock returns `E_INVALIDARG`, stays inactive, and leaves the origin unscheduled. With a 16,667 µs interval, scheduling type 0 returns `STARTED_CLOCK`, activates the clock, and schedules the origin. - The other four tests covered interval validation and deadline arithmetic, origin wake ordering, frame tokens and flip statistics, and ancillary event handle lifetime during rescheduling. **Not tested** Execution was limited to the focused CPU frame-clock tests. The rest of the workspace was compiled only. The full GPU workspace suite and retail-title smoke comparisons were omitted. **AI use** T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1621-focused.log` and published.
afpruivo commented 2026-11-26 13:05:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-26T12:18:22Z.


Tested 39788e8 on an RTX 3090, as part of a batch merged onto main b49be18: no failures, no regression.

  • Batch: #1384 e15ddb2, #1594 6ea563b, #1621 39788e8, #1653 69f70c1. They touch no common file and merged cleanly onto b49be18 (local commit 1e3fb07). Check posted in #1607: B21, https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7191828681.
  • Hardware: RTX 3090 24 GB, driver 621.40, Windows 11 26300, Rust stable MSVC.
  • Suite: cargo test --workspace -- --test-threads=4 (debug): 1,439 passed, 0 failed, 47 ignored. 26 SKIPPED GPU tests, mostly no wave64 on this card; they are not coverage.
  • Smoke: scripts/smoke.ps1, 60 s, retail 1.0.2.1 (title: 3c290c16), release. Peak commit was lower on the batch.
commit frames shown presents per 2 s (last 3) device removals crashes peak commit
main b49be18 1,649 60 60 60 0 0 17,023 MB
batch 1e3fb07 1,627 60 60 60 0 0 15,516 MB
  • I read the diff. schedule_invalid now runs again inside the clock lock in commit_schedule, and the duplicated handles are closed when it refuses. Dropping .max(1) is safe because interval_us == 0 is refused first.

Not tested: a run that reaches this change on purpose (the smoke title only shows that nothing regresses); AMD.

AI use: Claude Code (Claude Opus 5.5) ran the commands on my machine and drafted this. Checked by me before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7191831733 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7191831733). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-11-26T12:18:22Z. --- **Tested `39788e8` on an RTX 3090, as part of a batch merged onto `main` `b49be18`: no failures, no regression.** - **Batch:** #1384 `e15ddb2`, #1594 `6ea563b`, #1621 `39788e8`, #1653 `69f70c1`. They touch no common file and merged cleanly onto `b49be18` (local commit `1e3fb07`). Check posted in #1607: B21, https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7191828681. - **Hardware:** RTX 3090 24 GB, driver 621.40, Windows 11 26300, Rust stable MSVC. - **Suite:** `cargo test --workspace -- --test-threads=4` (debug): 1,439 passed, 0 failed, 47 ignored. 26 `SKIPPED` GPU tests, mostly no wave64 on this card; they are not coverage. - **Smoke:** `scripts/smoke.ps1`, 60 s, retail 1.0.2.1 (`title: 3c290c16`), release. Peak commit was lower on the batch. | | commit | frames shown | presents per 2 s (last 3) | device removals | crashes | peak commit | |---|---|---|---|---|---|---| | `main` | `b49be18` | 1,649 | 60 60 60 | 0 | 0 | 17,023 MB | | batch | `1e3fb07` | 1,627 | 60 60 60 | 0 | 0 | 15,516 MB | - I read the diff. `schedule_invalid` now runs again inside the clock lock in `commit_schedule`, and the duplicated handles are closed when it refuses. Dropping `.max(1)` is safe because `interval_us == 0` is refused first. **Not tested:** a run that reaches this change on purpose (the smoke title only shows that nothing regresses); AMD. **AI use:** Claude Code (Claude Opus 5.5) ran the commands on my machine and drafted this. Checked by me before posting.
github-actions[bot] commented 2026-11-30 08:39:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:39:09Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273173771 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7273173771). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:39:09Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Gevroska commented 2026-11-30 11:07:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-30T11:07:54Z.


@b3IKK Could you rebase this onto main? I checked PR head 39788e8c against main at 9dfbe3ea. The merge conflicts in crates/xcl/src/hle/d3d12x/frame.rs, and the scheduling race your patch addresses is still visible in that revision.

ScheduleFrameEventX validates the clock under the lock, releases it while processing handles, then reacquires it to commit the event. If another thread stops the clock in between, the scheduling thread can still arm the event with interval_us already at zero. Your patch rechecks the clock under the lock immediately before committing.

I verified that sequence in the source. I haven’t reproduced the interleaving at runtime, and the retail game loading traces I checked don’t establish that it happened there.

I used Codex GPT-6.2 Sol for the source and trace review. Codex GPT-6.1 Terra independently checked the findings. Codex GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7276583074 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7276583074). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-11-30T11:07:54Z. --- @b3IKK Could you rebase this onto `main`? I checked PR head `39788e8c` against `main` at `9dfbe3ea`. The merge conflicts in `crates/xcl/src/hle/d3d12x/frame.rs`, and the scheduling race your patch addresses is still visible in that revision. `ScheduleFrameEventX` validates the clock under the lock, releases it while processing handles, then reacquires it to commit the event. If another thread stops the clock in between, the scheduling thread can still arm the event with `interval_us` already at zero. Your patch rechecks the clock under the lock immediately before committing. I verified that sequence in the source. I haven’t reproduced the interleaving at runtime, and the retail game loading traces I checked don’t establish that it happened there. I used Codex GPT-6.2 Sol for the source and trace review. Codex GPT-6.1 Terra independently checked the findings. Codex GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
Foniass commented 2026-12-01 06:18:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:18:54Z.


Triage (#1607) – head 39788e8

No open or merged PR changes this. Main's schedule_frame_event_x still checks validity, drops CLOCK while it duplicates handles, and then commits without checking again. SetFrameIntervalX(0) in that window leaves the clock active with interval_us == 0 (hidden by .max(1)).
The diff checks again under the lock in commit_schedule. On refusal it closes the duplicated handles by dropping Handles. The test covers the refusal.
No problems found in the diff. It conflicts with main's frame.rs.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302731205 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7302731205). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:18:54Z. --- **Triage (#1607)** – head 39788e8 No open or merged PR changes this. Main's `schedule_frame_event_x` still checks validity, drops `CLOCK` while it duplicates handles, and then commits without checking again. `SetFrameIntervalX(0)` in that window leaves the clock active with `interval_us == 0` (hidden by `.max(1)`). The diff checks again under the lock in `commit_schedule`. On refusal it closes the duplicated handles by dropping `Handles`. The test covers the refusal. No problems found in the diff. It conflicts with main's `frame.rs`. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1621:upstream-pr/1621'
git switch 'upstream-pr/1621'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1621'
git switch 'upstream-pr/1621'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1621'
git switch 'upstream-pr/1621'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1621'
git switch 'main'
git merge --squash 'upstream-pr/1621'
git switch 'main'
git merge --ff-only 'upstream-pr/1621'
git switch 'main'
git merge 'upstream-pr/1621'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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!1611
No description provided.