Repository navigation
Shaders: lower v_min3/v_max3/v_med3 to DXIL integer min/max - #3027
Ingenioeren wants to merge 3 commits into
Conversation
Synthetic compute shaders emit 20 DXIL instructions for min3 and max3, down from 22, and 22 for med3, down from 26. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed 62b44820 against main (63bcca43; emit/lower.rs is 521,445 bytes, safely under the 512 KiB limit):
- Correctly maps
v_{min3,max3,med3}_{i32,u32}to DXILdx.op.binary.i32(37=IMax,38=IMin,39=UMax,40=UMin) withAttr::ReadNone, preserving exact integer min/max/median semantics while cuttingcmp+selectpairs in half (22 -> 20formin3/max3,26 -> 22formed3). Module::written_instructionsaccurately counts live phis, live body instructions, and one terminator per laid-out block, and CI is green.
|
I ran In each signed or unsigned shader that computes all three operations, I also timed a longer dependency chain on the RTX with D3D12 GPU timestamps. Each dispatch processed 65,536 lanes through 64 dependent operations with rotating runtime inputs. Each timed window covered 64 dispatches of the same PSO with UAV barriers between them. I alternated the parent and PR per round, discarded three warmup rounds and used the median of 15, in two fresh processes. All timed readbacks matched the CPU reference. Paired PR/parent medians across the six forms ranged from 0.982 to 1.021. I can confirm the smaller DXIL and the arithmetic results. This workload showed no consistent RTX timing improvement. AI-assisted with Codex. Synthetic inputs throughout. |
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — DXIL codes correct (IMin38/IMax37/UMin40/UMax39); med3 lowers to max(min(a,b), min(max(a,b), d)) — the median valid under total order. The instruction-count test (22→20, 26→22) discriminates via the new written_instructions counter.
|
Automated triage for the maintainers. Thanks, the test now checks what this PR changes. Merge candidate. The lowering is as reviewed before, and an RTX 5080 and WARP readback in the thread found 0 wrong results out of 393,216 per adapter. Expect smaller DXIL, not faster frames: the timing showed no measurable difference. CI: passing. Recommending a look, not approving. Generated by Claude Code |
|
Thanks for the triage. I replaced the total-instruction test (head The regression checks the exact |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll):
cargo test -p victory-shader min3 -- --test-threads=1(RTX 5090 & WARP): 2 passed, 0 failed on both (min3_max3_med3_use_dxil_integer_min_maxandv_min3_max3_med3_integer_forms_match_rdna2).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).
|
From a tester working with Claude (AI-assisted, Claude Code): a whole-pack check of this PR, plus one problem we hit at pipeline creation. Offline (fine): merged alone onto a At pipeline creation (a hang): on an RX 9070 XT (RDNA4, RADV / Mesa 26.3.1, vkd3d-proton 3.2 under GE-Proton 11-14), the pipeline pre-build stalls with exactly 8 compute pipelines begun and never finished (pipeline begin/end log). One worker thread spins for 40+ minutes, reproduced 3 times at the same point. All 8 are programs this PR changes, and the same tree without this PR builds all of them:
They are ray-tracing and traversal kernels with long loops. Since standalone dxil-spirv converts them, my guess is the host compiler (NIR/ACO) loops on the integer min/max in a loop bound, or vkd3d-proton's own bundled dxil-spirv does, but I have no stack to show for it. Not tested: NVIDIA, WARP, or a native compile of just these 8. Hashes and counts only, no program contents. |
|
Offline validation on the retail corpus, with the current main as the baseline:
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 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. |
|
Thanks, @Anzymanz and @YaBulochka, for running this on the whole pack. @YaBulochka: you're right that parity is the expected result. This PR doesn't change which programs translate or validate. It only changes how @Anzymanz: the hang on RADV is worth taking seriously, even though the emitted code computes the same values. If the spinning thread stays inside pipeline creation on DXIL that standalone dxil-spirv converts, the loop is most likely in the host compiler: vkd3d-proton's bundled dxil-spirv, or NIR/ACO when they analyse a loop whose bound now goes through Until that's known, the maintainers can treat this as a Linux/RDNA4 risk and hold the PR. I'll keep it as it is rather than guess at a workaround I can't test. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
The signed and unsigned dx.op.binary.i32 lowering (IMax=37, IMin=38, UMax=39, UMin=40) and the max(min(a, b), min(max(a, b), c)) median formulation are sound. The updated min3_max3_med3_use_dxil_integer_min_max test in 238c2189 cleanly removes written_instructions and verifies the exact emitted binary.i32 opcodes and (icmp, select) counts against the v_xor3_b32 control.
However, the RX 9070 XT (RADV / Mesa 26.3.1 / vkd3d-proton 3.2) report in the thread remains a merge blocker: eight ray-tracing/traversal compute pipelines repeatedly stalled during pipeline creation with this lowering applied, while the same base tree without it created all eight. Offline conversion and arithmetic readbacks do not exercise that runtime pipeline compilation path, and 238c2189 leaves production lowering unchanged. Please hold merging pending a spinning-thread backtrace / minimal reproducer isolating the hang (bundled dxil-spirv vs NIR/ACO) or a workaround verified on the affected stack.
Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, 238c2189):
cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::bitcode::tests: 12 passed, 0 failed (1 ignored bench)emit::lower::tests: 34 passed, 0 failedmin3 -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 2 passed, 0 failed on both (min3_max3_med3_use_dxil_integer_min_maxandv_min3_max3_med3_integer_forms_match_rdna2)
…to DXIL integer min/max # Conflicts: # crates/victory-shader/src/emit/lower.rs
…to DXIL integer min/max # Conflicts: # crates/victory-shader/src/emit/lower.rs
What
The six signed and unsigned
v_min3,v_max3andv_med3forms now emit onedx.op.binary.i32per min/max. The signed forms use IMax (37) and IMin (38). The unsigned forms use UMax (39) and UMin (40). Min3 and max3 take two picks. Med3 takes four, usingmax(min(a,b), min(max(a,b), c)).DXIL size
The previous lowering used a compare and a select per pick. The new lowering saves two instructions for min3 and max3, and four for med3. The independent RTX 5080 comparison in the thread found no measurable runtime difference. The reported benefit is smaller DXIL.
Verification
dx.op.binary.i32calls above the same load/store fixture, with zero added compares or selects. It omits a whole-shader instruction count, so unrelated changes to the fixture setup do not affect the assertion.dfa3ae3, both tests selected byVICTORY_WARP=1 cargo test --locked --offline -p victory-shader --lib min3_max3_med3 -- --test-threads=1passed. The numeric test covers 125 triples of five boundary values for each of the six forms.cargo clippy --locked --offline -p victory-shader --all-targets -- -D warningsandcargo run --locked --offline -p xtask -- policy --stagedpassed. The test inputs are synthetic.AI assistance: OpenAI Codex helped prepare the original contribution and this review update.