Frame clock: fire events due at the same point; build a waited-for queued pipeline at once #165

Closed
github-bot wants to merge 2 commits from gh-pr/165/head into gh-pr/165/base
Owner

@⁠KnucklesB on GitHub · 2026-11-23 18:05 UTC · original
KnucklesB:main → main · +113 −46 · 2 files · 2 commits · closed without merging

Two fixes found while bringing up the retail title on main as of db5dc26. Each comes with a test that fails without it.

1. Frame clock: fire every event type due at the same point (frame.rs)

The clock thread picked one event per deadline (min_by_key returns the first one). The retail title schedules frame event types 0 and 2 both at offset 0 µs, so they share every deadline: type 0 always won, type 2 was recomputed for the next frame each time and never fired. The title waits for type 2 with an infinite timeout (WaitFrameEventX(2, INFINITE) from game+0x2482405), so its frame loop stopped after a few frames. After that the activity log showed only 0 presents, 0 submits, 0 frame-event waits.

Now every event due at the earliest deadline fires in that tick.
Test: events_at_the_same_offset_all_fire. Types 0 and 2 at offset 0 both reach their waiters.

2. Background pipelines: a waited-for pipeline still in the queue is built by the waiter (pso_async.rs)

A compute pipeline is waited for at its first bind, but its build sat in the FIFO behind everything submitted before it. The retail title queues thousands of graphics pipelines while loading (5000+), so one bind waited for the whole queue. The build is now taken by whoever gets to it first: a worker, or the waiting thread. The waiting thread runs it on a thread with the workers' 64 MiB stack, because translation recurses deeply.
Test: a_waited_pipeline_does_not_wait_for_the_queue. A pipeline waited for behind 2× the worker count of slow builds is ready at once.

cargo test -p xcl --lib: 537 passed, 19 ignored. Tested on an NVIDIA GPU (Windows 11).

With both fixes the title gets past its first frames (2 → 16 presented). It then still stops in loading on another issue, unrelated to these two.

**@⁠KnucklesB** on GitHub · 2026-11-23 18:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/165) `KnucklesB:main` → `main` · +113 −46 · 2 files · 2 commits · closed without merging Two fixes found while bringing up the retail title on `main` as of db5dc26. Each comes with a test that fails without it. ### 1. Frame clock: fire every event type due at the same point (`frame.rs`) The clock thread picked one event per deadline (`min_by_key` returns the first one). The retail title schedules frame event types 0 and 2 both at offset 0 µs, so they share every deadline: type 0 always won, type 2 was recomputed for the next frame each time and **never fired**. The title waits for type 2 with an infinite timeout (`WaitFrameEventX(2, INFINITE)` from `game+0x2482405`), so its frame loop stopped after a few frames. After that the activity log showed only `0 presents, 0 submits, 0 frame-event waits`. Now every event due at the earliest deadline fires in that tick. Test: `events_at_the_same_offset_all_fire`. Types 0 and 2 at offset 0 both reach their waiters. ### 2. Background pipelines: a waited-for pipeline still in the queue is built by the waiter (`pso_async.rs`) A compute pipeline is waited for at its first bind, but its build sat in the FIFO behind everything submitted before it. The retail title queues thousands of graphics pipelines while loading (5000+), so one bind waited for the whole queue. The build is now taken by whoever gets to it first: a worker, or the waiting thread. The waiting thread runs it on a thread with the workers' 64 MiB stack, because translation recurses deeply. Test: `a_waited_pipeline_does_not_wait_for_the_queue`. A pipeline waited for behind 2× the worker count of slow builds is ready at once. `cargo test -p xcl --lib`: 537 passed, 19 ignored. Tested on an NVIDIA GPU (Windows 11). With both fixes the title gets past its first frames (2 → 16 presented). It then still stops in loading on another issue, unrelated to these two.
The clock thread picked one event per deadline (`min_by_key`, the first one). Two
types scheduled at the same offset – GTA VI schedules types 0 and 2 at 0 µs – then
had the same deadline, type 0 always won, and type 2 was recomputed for the next
frame each time: it never fired. The title's thread waiting for it with an infinite
timeout stopped the frame loop after a few frames (0 submits / presents afterwards).

Now every event due at the earliest deadline fires in that tick. Test: types 0 and
2 at offset 0 both reach their waiters (fails on the previous loop).
A compute pipeline is waited for at its first bind, but its build was queued behind
everything submitted before it (GTA VI: thousands of graphics pipelines while it
loads), so the bind – and the title's frame – waited for the whole queue. The build
is now taken by whoever gets to it first: a worker, or the thread waiting for it
(on a thread with the workers' stack, translation recurses deeply).

Test: a pipeline waited for behind 2× the workers' count of slow builds is ready at
once (fails on the previous queue).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:15 +00:00
github-bot closed this pull request 2026-11-26 04:13:15 +00:00
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 20:41 UTC · original

Both new tests distinguish the PR from its fork point, and both already pass on current main. I ran the PR head directly and carried the two tests verbatim to each control. Windows x64 MSVC, Rust 1.99.0, two pipeline workers. These tests exercise Windows events and synthetic pipeline jobs.

Revision Type 0 and type 2 at offset zero Waiting bind behind four slow jobs
Fork point db5dc26cba45278948dca2549b15ae53b9435d89 Type 2 timed out Waited 600 ms, failed 300 ms bound
Main 956a476bf738a098f39df4f4c8acef682e43030f Passed Passed
PR head 6c88c8a19b31ee016069760a20c53cd7494d6c8e Passed Passed

The PR head passed all 55 D3D12.X tests. On main, the first module run had 55 passes and one failure in the existing origin-statistics test: timestamps went backwards by 74 QPC ticks. A rerun passed all 56. The frame module alone subsequently passed 48/48 test invocations on each revision (12 fresh processes each).

There is a matching ordering gap on both revisions. On the PR head, crates/xcl/src/hle/d3d12x/frame.rs:453 wakes an origin waiter before taking the queue lock and publishing its timestamp. A waiter can acquire the lock first at line 322, find the queue empty and take a fresh QPC reading. The next waiter can then consume the older queued timestamp. Holding the origin-queue lock across the semaphore release and timestamp insertion would close that window. This interleaving explains the observed ordering; the failing run did not trace lock acquisition.

Current main covers both tested behaviors. The two regression tests can be carried independently. No retail timing, driver compilation, or merge build. AI-assisted review.

**@⁠Kalmarv** on GitHub · 2026-11-23 20:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/165#issuecomment-7113420164) Both new tests distinguish the PR from its fork point, and both already pass on current main. I ran the PR head directly and carried the two tests verbatim to each control. Windows x64 MSVC, Rust 1.99.0, two pipeline workers. These tests exercise Windows events and synthetic pipeline jobs. | Revision | Type 0 and type 2 at offset zero | Waiting bind behind four slow jobs | |---|---|---| | Fork point `db5dc26cba45278948dca2549b15ae53b9435d89` | Type 2 timed out | Waited 600 ms, failed 300 ms bound | | Main `956a476bf738a098f39df4f4c8acef682e43030f` | Passed | Passed | | PR head `6c88c8a19b31ee016069760a20c53cd7494d6c8e` | Passed | Passed | The PR head passed all 55 D3D12.X tests. On main, the first module run had 55 passes and one failure in the existing origin-statistics test: timestamps went backwards by 74 QPC ticks. A rerun passed all 56. The frame module alone subsequently passed 48/48 test invocations on each revision (12 fresh processes each). There is a matching ordering gap on both revisions. On the PR head, `crates/xcl/src/hle/d3d12x/frame.rs:453` wakes an origin waiter before taking the queue lock and publishing its timestamp. A waiter can acquire the lock first at line 322, find the queue empty and take a fresh QPC reading. The next waiter can then consume the older queued timestamp. Holding the origin-queue lock across the semaphore release and timestamp insertion would close that window. This interleaving explains the observed ordering; the failing run did not trace lock acquisition. Current main covers both tested behaviors. The two regression tests can be carried independently. No retail timing, driver compilation, or merge build. AI-assisted review.
Author
Owner

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

Closing: both halves are on main now. The frame clock fires every event type due at one deadline (956a476), and a waited-for pipeline that has not started is built by the waiter (pso_async::resolve_wait). The branch also conflicts with main in 2 files. Thanks for the work!

**@⁠ivall** on GitHub · 2026-11-23 20:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/165#issuecomment-7113686078) Closing: both halves are on main now. The frame clock fires every event type due at one deadline (956a476), and a waited-for pipeline that has not started is built by the waiter (`pso_async::resolve_wait`). The branch also conflicts with main in 2 files. Thanks for the work!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.