GPU: a frame wait takes its tick before it sleeps #174
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/174"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-24T01:06:04Z.
The
frame.rsmodule doc says each event kind (origin, vblank, flip) happens once per tick, so two waits for the same kind never end on the same tick.waitpicked the next tick innext_tickunder the clock's lock, but marked it as taken (LAST[kind]) only afterstd::thread::sleep, with the lock released. Two threads waiting for one kind at the same time therefore both read the sameLAST, both got tick T, and both returnedS_OKon it. For the origin, that begins two frames (FRAME+= 2) in one interval.next_ticknow takes alimit(the wait's time-out). When the tick comes within it,next_tickrecords the tick under the clock's lock, before anyone sleeps. A wait that times out takes no tick, as before. Sequential waits behave as before.Testing
cargo test --workspace: 265 passed, 4 ignored (need external files). Includes 1 new test,waits_begun_together_take_different_ticks: twonext_tickcalls before any sleep get different ticks, and a timed-out call leavesLASTalone. It fails on the old behaviour ("1 after 1"), checked by putting it back.cargo clippy --workspace --all-targets: no new warnings. The two that remain (xmem.rsandhost.rs:267) are onmain.cargo xtask policy: pass.rustfmt --checkonframe.rs: clean.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:21:42Z.
Tested
810f442under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build withcargo xwin ... --target x86_64-pc-windows-msvcand a native Microsoftd3dcompiler_47: pass, no regression.victory_gpu: 42 passed, 2 failed, 1 ignored, including the 1 test this PR adds.a_rejected_blob_gives_an_empty_library(vkd3d needs a non-empty blob) and #128.host::batch::texture_checks_per_submission(benchmark).No game data used.
Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:25Z.
The
diagnosticsbuild no longer compiles with this change.waitnow drops the tick (let (_, wait) = next_tick(kind, limit);atcrates/victory-gpu/src/frame.rs:133), but the#[cfg(feature = "diagnostics")]tracing::debug!further down still logstick(frame.rs:156), so thediagbuild fails with E0425. Keeping the binding (let (tick, wait) = ...) fixes it. The logic change itself looks right to me.Static review, not built or run.
Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:29:46Z.
Review note: merged onto current
main(d2a4bae), the default build is fine but the diagnostics build does not compile:(
cargo check -p victory-gpu --features diagnostics;mainalone builds with that feature.)waitno longer bindstick, and the tracing call underdiagnosticsstill names it. Testers use the diagnostics build for device-removal reports, so it is worth fixing before this goes in.From building only; I have no copy of the title.
Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-24T07:46:09Z.
Thanks @Sunkiller-qc and @r4tedx, you are right. Fixed on the new head
882664e:waitbinds the tick again for thediagnosticslog (withunused_variablesallowed when the feature is off).cargo check -p victory-gpunow passes with and without--features diagnostics, no warnings, and the frame tests pass.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:26:53Z.
Review: APPROVED
Tested
882664eon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed), includingwaits_begun_together_take_different_ticks.The race is real.
next_tickchose the tick under the clock lock, butLASTwas only bumped after the sleep, with the lock released, so two concurrent waits for one kind could both end on tick T (twoFRAMEincrements for the origin). Taking the tick insidenext_tickwhenwait <= limit, and taking none on a time-out, fixes it.Interaction with #319, which touches the same function. #319 adds an early return to
next_tickfor a late non-origin wait (return (passed, Duration::ZERO)) and relies onwaitto mark that tick afterwards. This PR removes the mark inwaitand adds its own mark only at the end ofnext_tick, so with both applied the early-return path never takes its tick. Merging this onto a branch with #319 confirms it:frame::tests::waits_end_on_ticks_and_count_framesfails atframe.rs:254(theLAST == flipped + 1check). Git reports no textual conflict, so this would slip through.Fix for whichever lands second: in #319's early-return branch, take the tick before returning, i.e.
last(kind).fetch_max(passed, Ordering::Relaxed); return (passed, Duration::ZERO);. Itslimitcheck is trivially true, since the wait is zero.Approving this PR's own change. I have not merged it into our fork, which already has #319.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T18:45:49Z.
Heads-up: #319 (
b36bd4c1) and #174 (882664e1) each pass onmain, but merged togetherframe::tests::waits_end_on_ticks_and_count_framesfails on every run (left: 10, right: 11atframe.rs:254).#174 moves taking the tick (
last(kind).fetch_max) intonext_tick. #319 adds an earlyreturn (passed, Duration::ZERO)for a late flip wait, before that point, so the late wait's tick is never taken. Taking it in the early return too fixes it. The tests pass (710 in the merge train):Whichever of the two lands second needs this. It is in
e3f72c57on the train branch.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:21:01Z.
Automated triage for the maintainers.
Merge candidate. In
crates/victory-gpu/src/frame.rs,waitchose its tick innext_tickunder the clock lock but recorded it inLASTonly after sleeping, so two threads waiting for the same kind could both end on one tick (for the origin wait, two frames in one interval).next_ticknow takes the time-out and records the tick under the lock when the wait will not time out; timed-out waits still take no tick, and single-thread behaviour is unchanged. Thediagnosticsbuild issue raised in review is fixed on this head, and the new test fails on the old order.Note for whoever merges: #319 adds an early return in
next_tickthat would also need to record its tick, so whichever lands second needs that line.CI: no check runs on the head commit.
Generated by Claude Code
upstream-sync referenced this pull request2026-11-25 01:07:58 +00:00