Frame clock: revalidate clock state before committing ScheduleFrameEventX #1621

Open
github-bot wants to merge 1 commit from github-bot/gh-1621 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 18:19 UTC · original
b3IKK:d3d12x/frame-schedule-toctou → main · +60 −22 · 1 files · 1 commits · open

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.
**@⁠b3IKK** on GitHub · 2026-11-24 18:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1621) `b3IKK:d3d12x/frame-schedule-toctou` → `main` · +60 −22 · 1 files · 1 commits · open `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.
schedule_frame_event_x released CLOCK 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 between. That left the clock marked active and
scheduled with `interval_us == 0`, where clock_thread does not run and
WaitFrameEventX hangs indefinitely.

Re-run schedule_invalid() inside commit_schedule() under the CLOCK lock,
closing the duplicated handles and returning E_INVALIDARG if the clock
state became invalid.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:44 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:37 UTC · original

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

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

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7143842418) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:00 UTC · original

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.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7153362513) # 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.
Author
Owner

@⁠afpruivo on GitHub · 2026-11-26 12:18 UTC · original

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, #1607.
  • 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.

**@⁠afpruivo** on GitHub · 2026-11-26 12:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/1621#issuecomment-7191831733) **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://git.gtahub.st/github/xcl-dev--xcl/issues/1607. - **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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1621/head:github-bot/gh-1621'
git switch 'github-bot/gh-1621'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1621'
git switch 'github-bot/gh-1621'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1621'
git switch 'github-bot/gh-1621'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1621'
git switch 'main'
git merge --squash 'github-bot/gh-1621'
git switch 'main'
git merge --ff-only 'github-bot/gh-1621'
git switch 'main'
git merge 'github-bot/gh-1621'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.