Shaders: share and serialize WARP host operations across threads #244
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!244
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/244/head"
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?
@AndyLatimer on GitHub · 2026-11-24 01:45 UTC · original
AndyLatimer:fix/shader-warp-parallel-crash→main· +174 −50 · 3 files · 2 commits · merged 2026-11-25 21:37 UTCFixes #181.
Cause
On Windows 11, concurrent
d3d10warp.dllactivity across threads crashes with0xC0000005(STATUS_ACCESS_VIOLATION). Sharing a single process-wide WARPID3D12DeviceviaOnceLockalone was not enough —VICTORY_WARP=1 cargo test -q -p victory-shader --libstill crashed on the first run — showing that concurrent WARP pipeline compilation / execution itself races insided3d10warp.dll.Change
crates/victory-shader/src/emit/host.rs:ID3D12DeviceinHost::newwhenever WARP is used (warp == true,VICTORY_WARP=1, or when DXGI's default adapter carriesDXGI_ADAPTER_FLAG_SOFTWARE).Host::newinitialization,root_signature_bytes/root_signature_for,compute_pipeline_with,pipeline_with,mesh_pipeline_with,draw, anddispatch) behind a process-wideMutex.Host's lifetime) keepsHost's public API intact and preserves multi-threaded IR/lowering/validation parallelism inapps/victory/src/translate.rs(--jobs N), while leaving hardware D3D12 devices completely unserialized.emit::host::tests::parallel_warp_pipelines_and_draws) that launches 8 threads behind aBarrierto create WARP hosts, compile graphics pipelines, and draw concurrently.crates/victory-shader/src/emit/diff_tests.rs:host.device.CreateRootSignature(...)calls withhost.root_signature_bytes(...)so differential tests also serialize underVICTORY_WARP=1.Verification
Tested on Windows 11 (debug build, synthetic tests only — no game data or console SDK used):
d2a4bae)7f95b87)VICTORY_WARP=1 cargo test -q -p victory-shader --lib0xC0000005)VICTORY_WARP=1 cargo test -q -p victory-shader --lib -- --test-threads=16cargo test -q -p victory-shader --lib(default: hardware + WARP)cargo test -p victory-shadercargo clippy -p victory-shader --all-targets -- -D warningscargo clippy -p victory --all-targetsvictory/victory-shaderrustfmt --edition 2024 --check(touched files)cargo xtask policy151 files ok(Sharing one WARP
ID3D12Devicewithout the mutex was also tested and crashed on run 1 with0xC0000005.)AI assistance
Assisted by Google Antigravity in reproducing the crash, isolating that a shared WARP device without serialization still faults, implementing the fix and regression test, and running the stress and verification checks above.
@ghost on GitHub · 2026-11-24 01:49 UTC · original
Verified the fix for #181 with the same runs that reproduced it.
7f95b87merged ontomaind2a4bae(clean merge), AMD Radeon RX 9060 XT, Windows 11 26200 (d3d10warp.dll10.0.26100.9818), Rust 1.98.1, debug:cargo test -q -p victory-shader --libmainVICTORY_WARP=1)cargo test --workspace: 265 passed, 0 failed, 4 ignored.AI use
@rhuantac on GitHub · 2026-11-24 01:57 UTC · original
Tested
7f95b87on an NVIDIA RTX 3060 Ti (driver 32.0.16.1088), Windows 11 build 26300,d3d10warp.dll10.0.26100.9818, debug,victory-shaderlib tests:d2a4bae)7f95b87)VICTORY_WARP=1, default threadsparallel_warp_pipelines_and_drawsaloneNo hangs (each run under a 180 s timeout). Not covered here: a default adapter that is itself WARP, and
victory translate --pipelines.AI use: Claude Code ran the commands and drafted this from the logs; I checked it before posting.
@MisaXz on GitHub · 2026-11-24 02:03 UTC · original
Test report on NVIDIA (#181 lists NVIDIA as not tested).
Tested
cargo test -q -p victory-shader --lib0xC0000005crashesmaind2a4bae7f95b870xC0000005with no test panic, as in the issue).main: 69 passed).Not tested
VICTORY_CONSOLE_DXC).AI use
@Aefekaa on GitHub · 2026-11-24 02:32 UTC · original
One more NVIDIA data point: RTX 4060 (driver 617.42), Windows 11 26200, Rust 1.98.1, debug. Same result as above. With
VICTORY_WARP=1, main crashed 10 of 10 runs and this PR 0 of 10. With default threads, main crashed 1 of 25 and this PR 0 of 55.One thing not mentioned above: twice the test binary hung instead of finishing, once on main and once with this PR (1 of 55 runs). It kept a core busy until my 120 s limit. I couldn't catch which test it was in 30 more runs, so it's probably a separate, rarer race and not caused by this PR. I'm mentioning it in case someone else hits a run that never ends.
AI-assisted: yes
@GamingRipperDoc on GitHub · 2026-11-24 02:53 UTC · original
Windows 10 data point (the reports so far are Windows 11). Short version: #181 cannot happen on Windows 10, because WARP there has no SM 6.6 device; #244 is harmless there, but it conflicts with #175.
Setup: Windows 10 22H2 19045.7846,
d3d10warp.dll10.0.19041.7811, AMD RX 9070 XT (driver 32.0.32015.7029), Rust 1.98.1, debug. On Windows 10 thevictory-shadertests only get an SM 6.6 device at all with the Agility SDK runtime in the test executable, so I tested on top of #175 + #362 (which gives the test executables that runtime).victory-shaderlib tests7f95b87)VICTORY_WARP=1valu_testsfail:neither hardware nor WARP SM 6.6 device availableparallel_warp_pipelines_and_drawsaloneno SM 6.6 warp device; skippedd3d10warp.dllcomes from the OS. So everyHost::new(true)fails, the tests that try WARP skip it, and no two threads ever use WARP at once. #181 does not reproduce there, with or without #244.parallel_warp_pipelines_and_drawspasses without running anything. Not a problem for this PR, just worth knowing: on Windows 10 it guards nothing.crates/victory-shader/src/emit/host.rs: #175 extends the SM 6.5 error message inHost::new; this PR moves that code intocreate_device. Resolving it is mechanical (keep this PR's structure and put #175's message intocreate_device); with that, the table's last column builds and passes,rustfmt --checkis clean, andcargo xtask policypasses (156 files). Whichever of the two merges second needs that rebase.No game data used.
AI-assisted (Claude Code); I ran everything above on my machine.
@lordon1a on GitHub · 2026-11-24 03:07 UTC · original
AI-assisted.
Tested
7f95b87eaon Windows 11 Home 26H2 (build 26200) with Intel(R) Iris(R) Xe Graphics (8086:46a6, driver32.0.101.7088, DXGI Adapter 0) + WARP (Microsoft Basic Render Driver),rustc 1.100.0(x86_64-pc-windows-gnullvm):cargo xtask policy:151 files okcargo test -p victory-shader(default parallel test threads, no--test-threads=1): 69/70 passed in 0.78s, zero0xC0000005WARP crashes (emit::host::tests::parallel_warp_pipelines_and_drawspassed).emit::valu_tests::v_med3_f32_matches_rdna2_with_nan:hardware: v_med3_f32(1.0, 2.0, NaN) = 2 (0x40000000), want 1) is the pre-existing Intel Iris Xefcmp unodriver bug onmain(unrelated to this PR; fixed in #110).cargo test -p victory-shader --lib parallel_warp_pipelines_and_drawspassed 5/5 consecutive runs with zero crashes.Verified clean on Windows 11 26200 + Intel Xe / WARP.
@r4tedx on GitHub · 2026-11-24 03:19 UTC · original
A data point on the hang mentioned above as probably separate: it reproduces here, and it is separate.
Tested
victory-shadertest binary in a loop, filtervalu_tests(the seven tests that run on the hardware adapter and on WARP), 45 s limit per run; a good run takes about 3 s:maind2a4bae7f95b87In a hung run none of the seven tests finishes and one core stays busy. With
--skip valu_testsnothing hung in 14 runs.So on this machine the hang survives serialising WARP alone. Taking a lock around
valu_tests::run_cases, so those tests do not overlap on the hardware adapter either, gave 0 hung of 60 onmain; that is #433 (five lines, tests only). It composes with this PR, which covers every WARP user.The one crash in 60 runs on this PR I cannot explain and did not see again; I did not run
VICTORY_WARP=1, where this PR's effect was measured by others.No game data used. AI-assisted.
@CaravelaLabs on GitHub · 2026-11-25 00:10 UTC · original
@AndyLatimer this is fine on its own. It does not compile once it is on current main.
Main
70564aeprobes fused multiply-adds by buildingHost { device }from the gpu crate (github.com/Marvisak/VIctory@70564ae08c/crates/victory-gpu/src/host.rs (L227), from77053a0). This head adds a privatewarpfield (github.com/Marvisak/VIctory@7f95b87ea9/crates/victory-shader/src/emit/host.rs (L19)), so that literal is no longer legal outside the shader crate. The two edits combine without a text conflict. The Windows workspace check of that merge then stops on the literal.warphas to be set inside the shader crate, on the device the gpu crate already has.Host::newcreates a different device, so it is not a drop-in.@mercuryVM's approval and the reports above are on
7f95b87againstd2a4bae, which does not have this probe. Separate from the text conflict with #175 that @GamingRipperDoc described. #175 is now closed without merging, so that conflict is gone. This compile break is not.Compile only (
cargo xwin check --workspace --all-targets --all-features --locked, Windows target). No tests, no clippy. No title run.AI-assisted; Windows workspace check of the merge, run on this machine.
@Marvisak on GitHub · 2026-11-25 00:27 UTC · original · edited 2026-11-25 10:21 UTC
Automated triage for the maintainers.
Merge candidate. Now merges cleanly into
main, and the compile break @CaravelaLabs reported is fixed. Incrates/victory-shader/src/emit/host.rs,Host::new(true)now shares one process-wide WARP device (OnceLock), and every device operation on WARP goes throughWARP_LOCK(lock_warp): root signatures, the three pipeline builders,draw,dispatchand thefuses_fmaddispatch. The newHost::from_devicesetswarpfrom the adapter's LUID.victory-gpu'screatenow uses it, which removes the struct literal that no longer compiled.fuses_fmadtakes the lock aftercompute_pipelineand does not calldispatch, so it does not lock twice. The diff tests useroot_signature_bytes.Hardware devices are not serialised. The new
parallel_warp_pipelines_and_drawstest covers #181. CI passes onc3ac59e. Earlier test reports were on7f95b87.Generated by Claude Code
@AndyLatimer on GitHub · 2026-11-25 09:38 UTC · original
Merged
main(940d32f) atc3ac59e. This fixes the compile break @CaravelaLabs found.mainnow picks a hardware adapter (or WARP when asked) and refuses a software default adapter. So I dropped this branch'sdefault_adapter_is_warpfallback, and hardware-only checks stay off WARP asmainintends. The shared WARP device andWARP_LOCKstay, usingmain's adapter choice.Host::from_device(device), as you suggested:warpis set inside the shader crate. It takes the WARP lock when the device is on a software adapter (found by its LUID), and serialises if that can't be told.fuses_fmadused to take the lock only to build the pipeline; it now holds it for the dispatch too.Checks (Windows 11, NVIDIA, Rust 1.98.1):
-D warnings, default and--all-features: clean.cargo test --workspace --locked --no-fail-fast: 697 passed, 5 failed. The 5 are the ones #1744 lists, which fail onmaintoo.VICTORY_WARP=1 cargo test -p victory-shader --lib, in parallel (the #181 repro): no access violation; 246 passed, 2 failed. The 2 aregathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out, hardware-only checks thatVICTORY_WARP=1forces onto WARP. They fail the same way onmainwithVICTORY_WARP=1.The earlier approval and test reports were on
7f95b87.