Skip to content

FramePacer: schedule frame event 2 independently of the origin - #7135

Open
Stalkerino wants to merge 1 commit into
ItsNotRexed:mainfrom
Stalkerino:contrib/frame-event-type-2
Open

Stalkerino wants to merge 1 commit into
ItsNotRexed:mainfrom
Stalkerino:contrib/frame-event-type-2

Conversation

@Stalkerino

Copy link
Copy Markdown

Tracking the secondary frame event from the retail startup sequence. Coordination claim

The title configures a 33,333 µs interval with three frames of latency, schedules the origin and then schedules numeric event 2. Both registrations use offset zero, zero flags and no ancillary argument. The presentation FramePacer currently returns E_INVALIDARG on the second registration.

This change gives the secondary event its own deadline on the interval clock. Waiting for it leaves the origin token untouched and works while a previous frame is in flight. Tests cover distinct offsets, missed events, timeouts, interval changes and suspend. The behavioral reference is the public XCL implementation cited by the ABI investigation. XCL frame clock · ABI investigation

The CPU frame_pacer test passes on native Linux and as a Windows test under Wine. Its new case fails on the parent. A Clang ASan/UBSan run passed with leak checks disabled.

I also compared two local integration builds in a visible Wine session using the retail title and a Radeon RX 9070 XT. The device slots in that setup use the same frame clock as the queue presenter. Before this change the clock rejected type 2. After it, the game progressed through a 185 MiB reservation and five subranges to Xbox device slot 133, still at frame 0. Current upstream #6935 has its own provisional device-slot handler. Bringing that handler onto the presentation clock is a separate integration change.

AI-assisted.

After the origin has been registered, the XboxPresentation scheduler now handles event 2 with zero flags on the same period and a separate offset. Waiting consumes its signal, coalesces missed intervals, and leaves the origin token and presentation latency alone. Suspend clears both registrations.

Behavioural reference: ivall/xcl, crates/xcl/src/hle/d3d12x/frame.rs at 95bda116cfc1b118156901984052ff5698dbf4cc, cited by Kam471 in Leonida ItsNotRexed#6522. This independently written clock model retains the FramePacer HRESULT conventions; event 2 is a numeric value, not a recovered SDK name. The detached early-device stand-ins in ItsNotRexed#6935 are outside this change.

A title run under Wine on a local build connecting XboxPresentation's clock to the device registered event 0 then event 2 with zero offset, flags and ancillary pointer. The new manual-clock coverage checks offsets, independent waits under backpressure, token preservation, missed ticks, interval changes and suspension. AI-assisted.
@tikD1337

Copy link
Copy Markdown
Contributor

The implementation looks sound for the documented provisional frame-pacing contract. I found no blocking code defect in the supplied diff. The outstanding verification gap is that the reported targeted-test list is empty, so the new C++ regression coverage has not been demonstrated to build or pass.

Code analysis

The change adds numeric frame event 2 with its own registration, offset and next deadline. It shares the interval’s epoch and period with the origin, while keeping event consumption separate:

  • Scheduling type 2 requires an established interval and an armed origin. Out-of-range offsets and nonzero type 2 flags are rejected before changing its registration.
  • next_phase2_after() computes the first grid point strictly after the supplied time. After scheduling or consuming an event, its next deadline is in the future; a second immediate poll therefore cannot consume the same signal.
  • Missed intervals coalesce into one successful wait. Advancing from the current time preserves the interval grid without replaying every missed event or accumulating drift.
  • Type 2 waits bypass the origin’s frame-latency gate and never write the caller’s token, increment issued_, or create frame-statistics records. Origin waits retain their existing token and latency behavior.
  • Interval changes preserve an armed type 2 registration, clamp its offset below the new period, recompute its deadline against the new epoch and notify waiters. Suspension and resumption clear both registrations.

The shared mutex protects registration, deadline calculation and consumption. Both event types use the existing waiter accounting, so the destructor’s shutdown-and-drain mechanism also covers secondary-event waits.

The finite-timeout check is particularly useful: success requires the pending event’s deadline to be at or before the wait’s timeout deadline. A thread waking late can consume a signal that was due within its timeout, but cannot turn an event first due after that timeout into success. Checking readiness before timeout also gives zero-timeout polling the expected behavior when a signal is already pending.

One boundary worth preserving explicitly is that type 2 can first fire at epoch + offset, before the first origin wait succeeds. With offset zero, scheduling at the epoch selects the next interval instead. The new test exercises this distinction; it is consistent with scheduling an independent point on the interval grid.

The pinned XCL implementation supports the narrow rationale: secondary events use auto-reset events, and only origin waits issue tokens. This remains third-party behavioral evidence, rather than confirmation of the complete console API contract. Keeping Leonida’s definitions marked provisional is appropriate.

Verification

The supplied Windows 11 / CPython 3.13 run reports these checks passing without game files:

  • git diff --check
  • Python compileall
  • check_no_game_data.py
  • make_game.py --help

These checks establish formatting, Python syntax, the game-data guard and CLI startup. They do not compile or execute the modified C++.

The added frame_pacer_test.cpp assertions cover registration order, invalid offsets and flags, deadline boundaries, token preservation, operation while frame latency is exhausted, repeated polling, independent origin consumption, rescheduling, interval rebasing, missed-event coalescing and registration invalidation after suspend/resume.

Before merge, build and run the native test with MSVC using the repository’s runtime workflow:

cmake -S runtime -B runtime/build
cmake --build runtime/build --config RelWithDebInfo --target frame_pacer_test
ctest --test-dir runtime/build -C RelWithDebInfo -R '^frame_pacer$' --output-on-failure

Additional useful coverage would exercise a blocked type 2 waiter through a finite timeout, rescheduling, interval rebasing and suspension. The new assertions use zero-timeout polls, so they do not directly exercise the secondary wait loop’s blocking and notification behavior. This test needs neither Vulkan nor a GPU; no GPU or driver validation is claimed here.

Project adherence

The diff contains only implementation code, documentation and synthetic clock-based tests. It adds no game data, keys, decryption or protection workaround, and no Xbox Live or Rockstar service access. It follows the fix-don’t-disable principle by implementing the previously rejected event with an explicit contract and regression assertions. No shader-translator rule changes, so no translator contract-table entry is required.

AI-assisted.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows validation of 5ca77a1:

  • Configured with MSVC 19.44.35228, Windows SDK 10.0.26100.0 and the project's pinned Vulkan headers.
  • Built frame_pacer_test successfully.
  • ctest -C RelWithDebInfo -R ^frame_pacer$ --output-on-failure: 1/1 passed (1.09 s).
  • Direct execution also passed: frame_pacer_test: all cases pass; its real-clock smoke test completed 5 origins at 10 ms in 78 ms.
  • git diff --check: clean.

CPU-only test; no game data or GPU involved. AI-assisted.

@philip-roy-jones

Copy link
Copy Markdown

I compared the same numeric frame-pacing calls on 5ca77a17 and its parent f25ba44e on native Windows 11 x64 with MSVC 19.51. This adds a parent control to the existing Windows CTest run.

On the PR, with the origin armed and a 1,000 µs interval, polling event 2 timed out at 199 µs and succeeded at 200 µs. Consuming it left the caller's token at the sentinel value 77 and the issued-token count at zero. The origin then returned token 1 at 1,000 µs. When both events were due at the same tick, I consumed event 2 and immediately got token 2 from the origin.

On the parent, scheduling and waiting for numeric event 2 after arming the origin both returned E_INVALIDARG. Origin tokens 1 and 2 still arrived. The same public-API probe passed 12/12 checkpoints on the PR and 4/12 on the parent. These were zero-timeout polls on a manual clock. The repository's frame_pacer CTest also passed 1/1. AI-assisted.

@Pierrot1398

Copy link
Copy Markdown

Tested 5ca77a1 on NVIDIA GeForce RTX 5060 Ti, driver 621.24 (32.0.16.2124), Windows 11 Pro 26300, MSVC (VS 18 Build Tools) RelWithDebInfo, Vulkan headers via -DLEONIDA_VULKAN_HEADERS_FETCH=ON: pass.

  • frame_pacer_test: 3/3 runs, all cases pass (includes the new secondary-event case).
  • xbox_present_test: 3/3 runs, all cases pass (PresentX path that uses the pacer).

Read the diff first: logic and test only, no I/O or build changes. No game files. AI-assisted (Claude Code).

@justrealyme

Copy link
Copy Markdown

Tested 5ca77a1 on NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 build 26300, VS 2022 Build Tools (MSVC 19.44), Windows SDK 10.0.26100, RelWithDebInfo: pass.

Built frame_pacer_test and ran ctest -R ^frame_pacer: Passed (1.1 s).

AI-assisted (Claude Code).

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5ca77a1 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo. Built frame_pacer_test, xbox_present_test and d3d12_present_test (the two users of the pacer on the GPU path).
  • frame_pacer, xbox_present, d3d12_present and xbox_present_readback_size: 4/4 pass with LEONIDA_VK_VALIDATION=0 and 4/4 with =1, each run 3 times in a row, no failure.
  • Negative control: runtime/src/frame_pacer.h and runtime/shims/xbox_present.h put back to the merge base (f25ba44), plus only the one-line frame_event_type_2 constant so the test compiles. frame_pacer then fails at frame_pacer_test.cpp:521 (the first type 2 schedule is not refused as invalid_state). With the PR's headers it passes.
  • This is a first AMD run. The pacer test is CPU only, so it only shows the result does not depend on the GPU; the two present tests show the pacer change does not disturb the Vulkan present path on AMD.
  • Not done: the retail boot check in the description (needs the game). Not run against the retail executable.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants