Shaders: lower v_min3/v_max3/v_med3 to DXIL integer min/max #3027
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!3027
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3027"
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?
@Ingenioeren on GitHub · 2026-11-26 03:50 UTC · original
Ingenioeren:perf/v-med3-u32→main· +97 −20 · 2 files · 3 commits · openWhat
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.
@fuzeofficlal on GitHub · 2026-11-26 04:00 UTC · original · approved these changes
Reviewed
62b44820againstmain(63bcca43;emit/lower.rsis 521,445 bytes, safely under the 512 KiB limit):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.@steven-seagull27 on GitHub · 2026-11-26 04:11 UTC · original
I ran
62b4482and its parent63bcca4on an RTX 5080 (621.40), Windows WARP 10.0.26100.10068 and app-local WARP 1.0.22. Each adapter returned 0 wrong out of 393,216 arithmetic results on each revision. The six forms used the same 65,536 triples of runtime inputs, including all combinations of 14 edge values, tied inputs and seeded 32-bit values. The fourth output word also preserved its guard in every row. The existing 750-comparison test passed on all three adapters.In each signed or unsigned shader that computes all three operations,
dxc -dumpbinshowed 10 compares and 10 selects on the parent. The PR emitted eight integer min/max calls, two compares and two selects. Both shader containers validated.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 on GitHub · 2026-11-26 04:39 UTC · original · approved these changes
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.
@Marvisak on GitHub · 2026-11-26 06:17 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Thanks, the test now checks what this PR changes.
min3_max3_med3_use_dxil_integer_min_maxincrates/victory-shader/src/emit/lower.rscompares each of the six forms against av_xor3_b32control lowering. It asserts the exactdx.op.binary.i32opcodes added (IMin 38, IMax 37, UMin 40, UMax 39; two for min3/max3, four for med3) and that no extraicmp/selectis left.written_instructions()is gone. The test-only helpers inbitcode.rsshare one iterator with the existingwritten_calls. The VOP3 opcodes in the test (0x152 to 0x159) match the RDNA2 encodings.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
@Ingenioeren on GitHub · 2026-11-26 06:50 UTC · original
Thanks for the triage. I replaced the total-instruction test (head
238c218):The regression checks the exact
dx.op.binary.i32opcode counts for all six signed and unsigned min3/max3/med3 forms, using av_xor3_b32control to account for theicmpandselectfrom the shared setup.written_instructions()and its counter plumbing are gone.The focused test failed with the
origin/mainlowering, which emitted zero IMin calls and two extra compare/select pairs forv_min3_i32, and passed with the branch lowering restored.cargo test --locked --offline -p victory-shaderreported 301 unit tests passed, two known local DXIL validator failures, and three ignored.cargo clippy --locked --offline -p victory-shader --all-targetsandcargo run --locked --offline -p xtask -- policy --stagedboth passed.@Dukestar69 on GitHub · 2026-11-26 07:28 UTC · original · approved these changes
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).
@Anzymanz on GitHub · 2026-11-26 07:40 UTC · original
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
63bcca4-based tree, 1,853 of the title's 25,889 programs' output changes (1,008 pixel, 954 compute, 15 vertex). None is refused, and all 1,853 convert with dxil-spirv (master).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:
02737aba304c298a,0fa0a1fcb90a8d21,306e8053bb5c7b83,3adb6fc86da11a5b,47c46db387f30d7e,51ada146938b49a2,9701445db7a7e2f9,f656e96a62bb116bThey 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.
@YaBulochka on GitHub · 2026-11-26 08:10 UTC · original
Offline validation on the retail corpus, with the current main as the baseline:
main63bcca4— 24 850 programs validatedpull/3027/head) — 24 850 programs validatedSo 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.
@Ingenioeren on GitHub · 2026-11-26 08:31 UTC · original
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
v_min3/v_max3/v_med3(i32/u32) are emitted: asIMin/IMax/UMin/UMaxinstead of compare+select. The results are the same value for value. The tests check this on GPU and WARP, and steven-seagull27 checked it on an RTX 5080.@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
imin/umin. I can't reproduce it here, because this machine is Windows on an RDNA2 card with no RADV. One thing would show which layer it is: a backtrace of the spinning thread (for examplegdb -p <pid>, thenthread apply all bt, or a fewperf topsamples on that thread). A stack insidelibvkd3d-proton/dxil-spirv versuslibvulkan_radeon(nir_*/aco::*) answers it. If it's NIR/ACO, it's a Mesa bug and should be reported there with the SPIR-V.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 on GitHub · 2026-11-26 09:48 UTC · original · requested changes
The signed and unsigned
dx.op.binary.i32lowering (IMax=37,IMin=38,UMax=39,UMin=40) and themax(min(a, b), min(max(a, b), c))median formulation are sound. The updatedmin3_max3_med3_use_dxil_integer_min_maxtest in238c2189cleanly removeswritten_instructionsand verifies the exact emittedbinary.i32opcodes and(icmp, select)counts against thev_xor3_b32control.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
238c2189leaves production lowering unchanged. Please hold merging pending a spinning-thread backtrace / minimal reproducer isolating the hang (bundleddxil-spirvvs 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)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.