Skip to content

Shader tests: share one D3D12 queue per adapter - #3093

Open
neonbyte1 wants to merge 4 commits into
Marvisak:mainfrom
neonbyte1:pr/shader-test-queue
Open

neonbyte1 wants to merge 4 commits into
Marvisak:mainfrom
neonbyte1:pr/shader-test-queue

Conversation

@neonbyte1

Copy link
Copy Markdown

Split out of #2973, as asked in its review: this changes how every victory-shader GPU test runs, Windows included.

The shader tests made a D3D12 device and a command queue for every test. They now share one device and one queue per adapter for the whole test process, and each test waits for its own work to finish, as before.

Why: under Wine/vkd3d-proton, victory-shader's test process was killed with SIGKILL at exit: hundreds of queues were still being torn down when the process ended. With one queue per adapter it exits normally.

Tested (Linux, GE-Proton11-14 Wine, RTX 5090): victory-shader tests under cargo xtask wine-test (#1218), 298 passed, 4 failed, no SIGKILL. All four failures happen on main without this change too:

Not tested on Windows: I have no Windows machine. A run of cargo test -p victory-shader --lib on a Windows GPU, and once with WARP, would close that gap. A test that left the queue in a bad state would now affect the tests after it; on this run none did.

AI-assisted (Claude); measured on my machine, no game data shared.

The shader host made a command queue for every draw, dispatch and FMad
probe, and each vkd3d-proton queue starts its own queue and fence
threads: the five valu tests alone left about 11,600 of each. Under
Wine, the process was still tearing them down at exit when wineserver
killed it 0.5 s later, so the suite ended in SIGKILL after its last
test. A device and queue per adapter are now shared, as WARP's device
already was; each call keeps its own fence, so parallel tests wait only
for their own work.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • cargo test -p victory-shader emit::host -- --test-threads=1: 1 passed, 0 failed (parallel_warp_pipelines_and_draws).
  • cargo test -p victory-shader a_branch_to_fallthrough_keeps_both_values_at_a_join -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

Independent WARP verification of this PR at dc56cd73 against its pre-series base 63bcca43 (the claim is #1633 (comment)). No source changes and no PR from me.

Setup: Windows 11, x86_64-pc-windows-msvc, Rust 1.98.1, --locked. Separate binaries per tree, run with VICTORY_WARP=1. I confirmed the adapter with a throwaway probe test first: Microsoft Basic Render Driver, software flag set, 0 dedicated video memory. The physical GPU was not used, so the PR's hardware-adapter queue (HARDWARE_DEVICE) was never exercised. The SDK dxil.dll was present. Synthetic inputs only, no game data.

Queue creation: CreateCommandQueue appears 3 times in victory-shader on base and once on head, in create_queue. The three submission sites now call Host::queue().

Repeated parallel runs. The full victory-shader lib suite, default test threads, 10 runs each, alternating base and head:

exit failures suite time
base 101 in 10/10 the same 4 in 10/10 13.0 to 15.6 s
head 101 in 10/10 the same 4 in 10/10 10.0 to 13.3 s (9 of 10 within 10.0 to 11.9 s)

The four failing tests are the same on both and are hardware-lane checks that WARP does not satisfy. Skipping those four, 6 further runs each exited 0 on both (298 passed, 0 failed, 3 ignored). The head was also exit 0 at --test-threads=1 (10.0 s) and --test-threads=16 (11.9 s). No hang, crash or changed result between base and head. The head is about 3 to 4 s faster, which fits one queue instead of one per call. That is only a WARP timing from this machine.

Limits: this does not test the PR's stated reason (Wine/vkd3d-proton SIGKILL at exit), and it does not cover a hardware adapter or the "a test leaves the queue in a bad state" risk the description mentions. On WARP, Host work is already serialised by WARP_LOCK, so a poisoned queue would be less visible here than on a GPU.

AI use: Claude Code (Claude Sonnet 5.5) ran the verification, coordinated by Codex (gpt-6.2-sol).

@YaBulochka

Copy link
Copy Markdown

Offline validation on the retail corpus, with the current main as the baseline:

  • baseline: main 63bcca4 — 24 850 programs validated
  • this branch (pull/3093/head) — 24 850 programs validated

So no regression and no change in the count on this corpus. Environment: Wine 11.22 on CachyOS (kernel 7.3.5), retail 1.0.2.1 shaders.rpf (26,503 containers), built with --features diagnostics, victory translate <shaders.rpf> --validate --list, unchanged prefix and settings for both runs.

If the change is meant to move that number, it does not on this dump; if it is about correctness of the emitted DXIL for an instruction shape the corpus does not hit, then parity is the expected result and this says only that nothing else moved.

Numbers only, no game files or dumps.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. crates/victory-shader/src/emit/host.rs: Host::new now hands out one device and one direct queue per adapter kind (HARDWARE_DEVICE / WARP_DEVICE), and the three submission sites use Host::queue() in place of a new queue per call. Each submission still makes its own fence and waits on it, and the WARP path still creates its device under WARP_LOCK. A Host::from_device host (used by victory-gpu's fuses_fmad probe) makes its queue once, lazily. Host::new(false) is also used by victory translate (apps/victory/src/translate.rs), which only makes pipelines there, so the shared queue does not affect it.

A Windows WARP run comparing this branch with main has been posted here. The hardware-adapter path is still not run on Windows; a run of cargo test -p victory-shader --lib on a Windows GPU would close that gap.

CI: passing.


Generated by Claude Code

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wall-clock improvement on real hardware is huge! Tested locally on Windows 11 (RTX 5090, running the victory-shader lib suite excluding the pre-existing heap_direct_texture_reads_mark_their_heap_index crash):

  • Base 63bcca43: 523.12s (298 passed, 3 pre-existing failures)
  • This PR dc56cd73: 33.56s (298 passed, same 3 pre-existing failures) — a 15.6x speedup, and concurrent submission is sound on the happy path because each call owns its own allocator, command list, resources, and fence.

However, caching the hardware (device, queue) permanently in a LazyLock introduces a few correctness issues in crates/victory-shader/src/emit/host.rs:

  1. Host::new(false) permanently returns a removed device after DEVICE_REMOVED (emit/host.rs:183-188, 206-224): Once HARDWARE_DEVICE initializes to Ok(...), any subsequent Host::new(false) clones and returns the same device/queue even if the GPU has since entered DEVICE_REMOVED. Previously, create_device(false) surfaced device removal when callers like emit/semantics_tests.rs:577-585 requested a fresh Host after a failure. Please check GetDeviceRemovedReason() on construction (and decide/document whether an initial creation failure should stay cached forever).
  2. pub device can diverge from the private cached queue (emit/host.rs:17-20, 191-195, 215-234): Host.device is pub, so replacing it leaves the cached queue bound to the old device while fuses_fmad / draw / dispatch create allocators, lists, and fences on the new device. Keeping device and queue paired behind read-only access (or rebuilding the queue when the device changes) prevents mismatched-device submissions.
  3. Fence completion loops treat UINT64_MAX (DEVICE_REMOVED) as success in fuses_fmad and dispatch (emit/host.rs:751-763, 2011-2023): draw checks GetDeviceRemovedReason() after exiting the wait loop (:1285-1288), but fuses_fmad and dispatch only check it inside while fence.GetCompletedValue() < 1. On DEVICE_REMOVED, GetCompletedValue() returns u64::MAX, exiting the loop immediately and mapping incomplete readback data. Now that a removed device is shared across tests, sharing a single completion-check helper across all three paths is much more important.
  4. Hardware concurrency coverage: The new test (:2055-2097) currently exercises the serialized WARP_LOCK path. Adding a hardware-path concurrency test (when not forced to WARP) with distinct per-thread readback payloads would directly cover the concurrent queue path this PR enables.

@steven-seagull27

Copy link
Copy Markdown

@neonbyte1 @fuzeofficlal I ran the hardware concurrency check requested in review item 4. On dc56cd73, eight RTX 5080 workers using the shared D3D12 queue each got back their own value on every dispatch. The same test applies to the parent, 63bcca43. Test-only commit

Adapter Parent PR head
RTX 5080, driver 621.40 512/512 payloads correct 512/512 payloads correct
Windows WARP, 10.0.26100.10068 512/512 payloads correct 512/512 payloads correct

Each cell covers four fresh processes. In each process, eight workers synchronized after pipeline creation, then each submitted 16 dispatches with distinct root constants. The shader wrote one word of a two-word UAV. The untouched neighbor stayed zero in every readback. The test identified the adapter by its D3D12 device LUID. WARP used its existing serialization. This run covers successful submissions; the device-removal questions in the review are still open.

To try it on this PR:

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3093-concurrent-readback
git cherry-pick 5b871f8170440350c11ad5532e6260ac7a574be2
$env:VICTORY_WARP = '0'
cargo test --locked -p victory-shader --lib emit::valu_tests::parallel_dispatches_keep_each_workers_readback -- --exact --test-threads=1 --nocapture

Set VICTORY_WARP=1 for the software control. Each completed run prints the adapter name and 128 matched readbacks. AI-assisted test and write-up, run locally on Windows.

Address PR review: replace a removed cached device and queue, keep the pair
private behind a read-only accessor, wait through one fence helper in all
three readback paths, and cover concurrent hardware dispatches.
@neonbyte1

Copy link
Copy Markdown
Author

Thanks for the Windows hardware run and the four points. All four are addressed in a follow-up commit, deedac2:

  1. Removed device. The cached hardware (and WARP) device and queue sit in a mutex as one pair. Host::new checks GetDeviceRemovedReason() and, if the cached device is removed, drops the pair and makes a new one. Creation failures aren't cached: before this PR, Host::new(false) tried again on every call, and an adapter that appears later should still work.
  2. Device and queue paired. Host::device is private now, behind a read-only device() accessor. The cache only hands out the device and its queue together, so nothing can swap a device under a cached queue. In-tree callers are updated.
  3. Completion. fuses_fmad, draw and dispatch share one wait_for_completion(). It treats u64::MAX and any GetDeviceRemovedReason() error as failure, and checks again after the last fence read, before any readback is mapped.
  4. Hardware concurrency. New test parallel_hardware_dispatches_on_shared_queue: eight threads take hosts on the shared hardware queue, each dispatch writes its own token, and each thread checks its own readback. It deliberately ignores VICTORY_WARP. It skips, with a message, only when there's no SM 6.6 hardware adapter.

Tested on the RTX 5090 under Wine (vkd3d-proton):

  • The new test passes. With the fence wait removed, as a mutation check, it fails.
  • The whole victory-shader lib suite has 299 passed and the same 4 failures as main under Wine, and no SIGKILL at exit.
  • Clippy with and without diagnostics, and cargo xtask policy, are clean.

Not run on native Windows.

AI-assisted (Claude); measured on my machine, no game data shared.

@steven-seagull27

Copy link
Copy Markdown

@neonbyte1 I ran your new parallel_hardware_dispatches_on_shared_queue at deedac2e7 on native Windows. It passed in four fresh processes on the RTX 5080, with eight workers checking their own token each time (32/32 readbacks).

I also reran the longer test from my earlier comment, updated to use the new device() accessor. In four fresh processes per adapter, each worker made 16 submissions. The RTX 5080 returned 512/512 correct payloads, and all 512 untouched neighbor words stayed zero. Windows inbox WARP returned the same counts through its serialized path. Optional 16-round test on your new revision

I found one failure path in the new test itself. If one worker fails host or pipeline setup, it panics before reaching the eight-worker barrier. I injected one setup error on a healthy device. All seven peers reached the barrier, none reached dispatch, and I stopped the test after 10 seconds. Carrying the setup result across the barrier let the seven peers return their correct tokens and the test report the injected error in 0.25 seconds. With the injected error removed, the fix passed 24/24 worker readbacks across three RTX runs. Affected lines · Test-only fix

To pick up just the barrier fix on deedac2e7

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3093-worker-setup-barrier
git cherry-pick a205dde3bc745f006d1f14920935d82f741d2d1d

Windows 11, NVIDIA driver 621.40, inbox WARP 10.0.26100.10068. The injected error exercised worker setup on a healthy adapter. Hardware device-removal recovery remains untested here. AI-assisted testing with synthetic inputs.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deedac2e cleanly addresses the earlier review items: SharedDevice pairs device and queue and recreates on GetDeviceRemovedReason(), Host::device is private behind device(), and fuses_fmad/draw/dispatch share wait_for_completion with u64::MAX and pre/post-read device-removal checks.

One blocker in the new parallel_hardware_dispatches_on_shared_queue test (emit/host.rs:2221-2238): each of the eight spawned threads calls Host::new_for(false).expect(...) and host.compute_pipeline(shader).expect(...) inside std::thread::scope before barrier.wait(). If any worker fails during host setup or PSO creation, the remaining workers deadlock permanently on barrier.wait() and thread::scope never returns. Please complete fallible setup before entering the fixed-count barrier (or propagate setup failures). It would also help to assert queue sharing alongside first.device() == second.device(), and to only skip when adapter creation itself fails rather than on CreateCommandQueue errors.

Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, deedac2e):

  • cargo run --locked -p xtask -- policy & cargo check --workspace --all-targets --locked: passed
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean
  • emit::host::tests (--test-threads=1 and default parallel on RTX 5090, plus VICTORY_WARP=1): 2 passed, 0 failed
  • emit::tests / emit::semantics_tests (parallel on RTX 5090 and VICTORY_WARP=1): 17 / 34 passed, 0 failed (1 ignored)

steven-seagull27 and others added 2 commits November 26, 2026 11:28
…a device

The concurrent dispatch test checks that two hosts and every worker get the same queue, not just the same device. It skips only when no hardware SM 6.6 device can be made; a failed queue creation on a working device fails the test.
@neonbyte1

Copy link
Copy Markdown
Author

@fuzeofficlal @steven-seagull27 Thanks both. Two new commits:

  1. Barrier deadlock (@fuzeofficlal's blocker, @steven-seagull27's reproduction): I cherry-picked @steven-seagull27's fix unchanged, with your authorship, as b0fed71. Each worker's host and pipeline setup is now a Result carried across the barrier, so a worker whose setup fails still releases the others, and the test reports the error afterwards. To check it, I made one worker's setup return an error before any GPU work. The test then failed in 0.8 s with hardware Host::new: "injected setup error" instead of hanging. The injected error is removed again.
  2. Queue sharing (@fuzeofficlal): 076c0e7 checks that two hosts get the same queue, not just the same device. Each of the eight workers also checks that its host has that same queue.
  3. Skip (@fuzeofficlal): the test now skips only when no hardware SM 6.6 device can be created. If the device can be made but Host::new still fails, for example in CreateCommandQueue, the test fails.

@steven-seagull27, thanks also for the native Windows runs and the 16-round test (50342b8). I didn't add it because it covers the same shared-queue readbacks as this test. It's a good heavier stress check to run by hand, and your 512/512 results on the RTX 5080 and on WARP are a useful record here.

Tested on the RTX 5090 under Wine (vkd3d-proton):

  • The new test passed in three runs.
  • The whole victory-shader lib suite has 299 passed and the same 4 failures as main under Wine, and no SIGKILL at exit.
  • Clippy (with and without diagnostics), policy and format checks are clean.

Not run on native Windows.

AI-assisted (Claude); measured on my machine, no game data shared.

@steven-seagull27

Copy link
Copy Markdown

@neonbyte1 I retested 076c0e7 on native Windows 11 with the RTX 5080 (driver 621.40). The upstream identity test passed in four fresh processes. In each process both initial hosts shared the same device and queue, and all eight workers used that queue. All 32 worker tokens matched.

I also checked both failure paths on the RTX. Giving worker 0 a second queue on the same D3D12 device triggered thread 0 has its own queue. Injecting a setup error in worker 0 made the test fail normally after the barrier. Its seven peers returned the correct tokens in both runs.

The separate 16-round stress test passed in four fresh processes per adapter. The RTX returned 512/512 expected tokens and Windows WARP (10.0.26100.10068) returned 512/512. The adjacent word stayed zero on every readback. Stress test used

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the updates in 076c0e7e on RTX 5090 and WARP: moving Host::new_for(false) and compute_pipeline ahead of barrier.wait(), asserting shared device/queue identity across all 8 worker threads (first.queue() == second.queue() and matching own.as_raw() while keeping first alive), and distinguishing hardware adapter absence from queue failure all cleanly resolve the previous review blockers.

Verified locally on Windows 11 x64 (076c0e7e):

  • rustfmt --edition 2024 --check on all 6 modified files, cargo run --locked -p xtask -- policy (191 files ok), cargo check --workspace --all-targets, and cargo clippy --workspace --all-targets -- -D warnings (default and --all-features): clean.
  • RTX 5090 (--test-threads=1 and default parallel) & VICTORY_WARP=1: emit::host::tests 2/2, emit::tests 17/17, emit::semantics_tests 34/34 (1 ignored).

Two minor edge notes (non-blocking):

  1. In parallel_hardware_dispatches_on_shared_queue, if Host::new_for(false) succeeds at device creation and fails queue creation, and the fallback create_device(false) check then fails transiently, the test would still skip instead of surfacing the original queue failure stage.
  2. Host::from_device uses a per-instance OnceLock<Result<ID3D12CommandQueue, String>>, so unlike shared() (which checks removed() and retries), a transient or post-removal queue error on an externally created device remains cached for the lifetime of that Host.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants