victory-shader: make the test dispatches cheap - an event wait and reused command objects (emit suite -33% wall, -48% CPU) #1733
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1734"
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 pes7 on 2026-11-24T21:31:41Z.
The shader test suite spent most of its time on the harness, not on the shaders. Two things in
emit::host:drawanddispatchwaited for their fence by spinning, callingGetDeviceRemovedReason()on every iteration;emit::valu_testsruns hundreds of dispatches for one shader (every f16 pattern, for two opcodes, on two backends), so both costs multiply.1. Wait on an event, not in a spin
One
waithelper for both call sites: create an event,SetEventOnCompletion, thenWaitForSingleObject(100 ms)in a loop. The timeout is what keeps the device-removal check - a removed device never signals, so anINFINITEwait would hang the run instead of reporting it - andWAIT_FAILEDreturns an error rather than looping.Same shape as the submission wait in
victory-gpu/src/host.rs, which usesINFINITEbecause the runtime owns the device; here the check has to stay.Interleaved A/B, 9 runs each,
emit::with--test-threads=8:CPU -20%, wall unchanged: the GPU work was the critical path and the machine had spare cores. Every event run stayed under 4.66 s of CPU; eight of the nine spin runs were at 4.88 s or above.
2. Make the command objects once per host
Timing the five creations alone (200 iterations, release, hardware device) gives 4.19 ms, against 8.35 ms for a whole dispatch of
emit::valu_tests- half of a dispatch was spent on objects that do not depend on the dispatch's inputs.Hostnow keeps them in aReusedstruct (queue,allocator,list,fence,event, last fence value) and each dispatch bumps the fence value andResets the list with its own PSO. That is safe here because the GPU tests already run one at a time (ONE_AT_A_TIME) and every dispatch waits for its fence before returning, so the allocator is never in use when it is reset.The event is closed by
Drop for Reused;drawstill makes its own, since it is not on the hot path.v_cvt_norm_i16_and_u16_f16_round_the_exact_product(576 dispatches)emit::suite, wallemit::suite, CPUBoth, against the original
emit::wallemit::CPUWhat this does not claim
That it fixes the flaky
v_cvt_norm_i16_and_u16_f16_round_the_exact_product(#1633). I tried to make the flake show up by running two full suites in parallel, four rounds per variant: 0/16 failures in both, so the link is unproven and I am not claiming it.Scope
drawanddispatchare#[cfg(test)], so nothing in the game changes: this is the shader test suite's time.crates/victory-shader/Cargo.tomlgainsWin32_SecurityandWin32_System_Threadingfor the optionalwindowsdependency -CreateEventWsits behind both, andvictory-gpualready enables them.Checks
cargo clippy --workspace --all-targets --locked -- -D warnings, the same with--all-features,cargo test --workspace --locked,cargo xtask policy.To reproduce: build the test binary with and without the change (
target/release/deps/victory_shader-*.exe) and run them alternately,TotalProcessorTimefor CPU and the reported time for the 576-dispatch test.What it gives (to decide the merge): the shader test host waits for its fence on an event instead of spinning, and makes its queue, allocator, list and fence once per host: the
victory-shadersuite took 199 s before the rebase and 115 s after it (302 tests), with the same device-removal reporting.State: MERGEABLE, CI
checkgreen, rebased onto today'smain(f3578e3).Risk: test-only code; a wedged device is still reported instead of waited for.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:41:04Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Windows-gated execution/hardware tests only run on Windows.Emit test harness: wait() on the fence now uses SetEventOnCompletion + WaitForSingleObject(100ms) with a GetDeviceRemovedReason check per timeout instead of spinning — a removed device is reported rather than hung, and the event handle is closed on every path except the wedged one (deliberately leaked, one handle, run is ending anyway). Windows-only test code; macOS compile unaffected.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T22:03:39Z.
@catminou4 - thank you, and one thing changed after your run at
21:41: there is a second commit now (head90ebae3, and the PR title says "reused command objects"). Your approval covered the event wait only, so this is what is new, in case you want to look again.A dispatch also made a new command queue, allocator, list, fence and event on every call. Making those five costs 4.19 ms of an 8.35 ms dispatch (200 iterations, release, hardware device), and
emit::valu_testsruns hundreds of dispatches for one shader -v_cvt_norm_i16_and_u16_f16_round_the_exact_productalone is 576.Hostkeeps them in aReusedstruct now, bumps the fence value per dispatch andResets the list with its own PSO. Safe here because the GPU tests already run one at a time (ONE_AT_A_TIME) and every dispatch waits for its fence before returning, so the allocator is never in use when it is reset.Drop for Reusedcloses the event;drawstill makes its own, since it is not on that path.emit::suite, wallemit::suite, CPUAgainst the original code that is wall 9 080 -> 6 053 ms and CPU 5 562 -> 2 891 ms.
cargo test --workspacereports 4.98 s for this crate's lib tests instead of 8.69 s.Nothing else changed, and it is still
#[cfg(test)]only. Both clippy configurations with-D warnings,cargo test --workspace --lockedandcargo xtask policypass on the head.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T23:05:03Z.
NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug,
0d4ea57(onmain70564ae).cargo test -p victory-shader --locked: 206 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures onmain, not this PR. Wall time for that run: 24 s. A tree without this change (#1757 on the same base, same machine, run right after) took 53 s for 208 tests, consistent with the speed-up described here.AI-assisted (Claude Code). Synthetic tests only.
upstream-sync referenced this pull request2026-11-25 02:06:28 +00:00
upstream-sync referenced this pull request2026-11-25 02:06:28 +00:00
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:16:53Z.
Automated triage for the maintainers.
Merge candidate. Still a test-only speed-up of the GPU test host in
crates/victory-shader/src/emit/host.rs. The fence wait uses an event (wait) and still checksGetDeviceRemovedReasonon each 100 ms timeout and after the wait.Host::dispatchkeeps its queue, allocator, list, fence and event inReused, resets the allocator beforelist.Reset, and drops the objects if a previous recording never reached its fence. All of the new code is#[cfg(test)]. TheCargo.tomlchange only adds two features ofwindows, which is already a dependency.On your reply: the new head (
7d6cff9) is a rebase onto today'smain. I checked that all three constructors (newon its WARP and hardware branches, andfrom_device) initialisereused, and that main'screate_device/WARP setup is kept unchanged. The rest matches what was reviewed at34965a8.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Damokles2 on 2026-11-25T12:18:50Z.
Hi @pes7,
While investigating D3D12 device-loss handling, I noticed that
fuses_fmad()still has a similar gap on both upstream main and your current PR head.If
GetCompletedValue()returnsUINT64_MAXafter device removal, the polling loop can exit and reach readback without explicitly checking the removal reason.Since
fuses_fmad()also runs during production adapter initialization, it appears to be outside the current test-only scope of #1734.Would you prefer to include this small post-wait check in your PR, or would you be comfortable with me investigating and preparing a separate follow-up?
The finding is based on source inspection and Microsoft's documented fence behavior. I haven't reproduced native device removal yet.
AI-assisted investigation using Codex.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T12:46:22Z.
Both fixed in
34965a8- thank you, the first one was a real leak.The allocator is reset now, before the list:
r.alloc.Reset().map_err(err)?inside the sameunsafeblock, after the previous dispatch's fence and beforelist.Reset. Measured cost, in case anyone wonders: four interleaved pairs of theemitsuite, middle two averaged - 10.5 s of CPU with the reset against 11.1 s without, i.e. nothing, and the memory of hundreds of recordings pervalu_testscase no longer accumulates.A failed recording is dropped instead of reused.
Reusedcarriesrecording: Cell<bool>, set just beforelist.Resetand cleared only oncewaithas returned, so "open list / allocator in use" is exactly the state that skips reuse:A case that fails now fails once, and the next dispatch starts from a fresh queue/allocator/list/fence/event.
@Damokles2 - on
fuses_fmad(): a separate PR, please. It runs during adapter initialisation, which is outside everything this one touches (all of it is#[cfg(test)]), and it is your finding with the reasoning behind it - better as its own change with its own reviewer than folded in here. Your reading matches whatwaitdoes in this PR, for what it is worth: it does not consultGetCompletedValue()at all, it waits on an event that a removed device never signals and checksGetDeviceRemovedReasonon each timeout, exactly because a removed fence reportsUINT64_MAXand would let a value comparison pass.Imported from Marvisak/VIctory. Originally posted by Damokles2 on 2026-11-25T12:53:02Z.
Thanks for confirming the finding and clarifying the scope! I'll prepare a separate PR for the
fuses_fmad()device-loss handling, keeping the change focused on the probe and its error propagation.Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T22:22:18Z.
Rebased onto today's
main(f3578e3). Three hunks needed a hand, all from #181's WARP work that landed meanwhile:Hostnow had awarpfield, so the reused objects sit beside it (reused: Mutex<Option<Reused>>), and every constructor (new's WARP branch, its hardware branch,from_device) initialises them;create_device/static WARP, so this branch's own device setup is gone (main's is kept) and only the reused objects remain of it;mod testsblock from #181 is kept as it is.All three commits are there (
cceb602,5b1b9cf,7d6cff9), andcargo test --release -p victory-shaderpasses: 302 tests, 3 ignored, in 115 s (the same suite took 199 s before the rebase, so the win this PR describes still holds on today'smain).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T17:23:05Z.
Review: APPROVED
Verified head
7d6cff93e0804f983f389686744fc304213853fdmerged ontomain(63bcca43) on Windows 11 (Ryzen 9 9950X, RTX 5090 + WARP, Rust 1.98.1 MSVC, and D3D12 Debug Layer).main(and clean co-merge with#1493inemit/host.rs).cargo xtask policy(191 files ok),cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features), andemit::rect::/v_med3_/v_fract_tests (6/6, covering bothHost::drawandHost::dispatch) all pass.v_cvt_norm_i16_and_u16_f16_round_the_exact_product(576 dispatches, debug build, hardware + WARP):33.05 sonmain(33,181 mswall) vs1.41 swith this PR (1,773 mswall).ID3D12InfoQueue) on both RTX 5090 and WARP:Hostproduced zero new warnings/errors (onlymain's pre-existingID=1328onView::RawUav).CreateCommittedResourceerror afterlist.Reset/ beforelist.Close, leavingr.recording == true, then running a valid dispatch on the sameHost) cleanly dropped and recreatedReused, returned the expected output, and produced zero Debug Layer warnings/errors on both adapters.GetProcessHandleCount, without Debug Layer):+0handles across 60 reused dispatches on both RTX 5090 (358 -> 358) and WARP (304 -> 304), and+0across 20 fullHost::new->dispatch->dropcycles on WARP (299 -> 299), confirmingDrop for Reusedcloses the event handle cleanly.Minor non-blocking nit: in
Host::draw(emit/host.rs:1355-1358), ifqueue.Signal(&fence, 1)fails,eventis returned pastCloseHandle(event); creatingeventafterqueue.Signalavoids leaking the handle on that error path.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:30:11Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib emit::crosslane_tests::passed (5/5) on RTX 5090 and underVICTORY_WARP=1Host(with therecordingflag resetting cleanly on mid-dispatch errors andCloseHandleinDrop) is clean and soundcargo clippy -p victory-shader --all-targets -- -D warningsand--all-features --all-targets -- -D warningsboth passed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.