Shaders: lower v_med3_f32 through ordered integer keys #3608
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!3608
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3608"
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-27 20:40 UTC · original
Ingenioeren:perf/v-med3-f32-dxil→main· +148 −1 · 4 files · 2 commits · openv_med3_f32now lowers its numeric median through signed-integer ordered keys and DXIL IMin/IMax. The minimal dynamic-input synthetic compute shader shrinks from 89 to 65 written DXIL instructions: 24 fewer (26.97%), including loads, the UAV store and terminators. This measures DXIL size; runtime throughput was not benchmarked.Reversing the negative half of the f32 bit patterns orders numbers exactly, including
-0 < +0. Denormal operands map directly to their signed-zero keys. NaNs sort above every number; any NaN selects the minimum of the numeric operands, matching the existing med3 rule. Three NaNs retain the original two-FMin chain. The transform back to float bits is exact. Existing source modifiers, output modifiers and guards surround this lowering; it adds no wave operations. The f16 path keeps its existing helper.The DXIL specification defines the signed integer min/max and floating minNum behavior used here. Searches of open upstream PRs for
v_med3_f32,IMin,IMaxand med3 performance found no PR covering this optimization; #3027 covers integer-source forms.The test-only
Module::written_instructionsandLowered.instructionscounter helper is byte-identical to #3525/#3564/#3592/#3600, copied from #3600'sfix/perf-v-perm-b32-dxilbranch and checked against all four branch versions.Validation:
cargo test --locked --offline -p victory-shader v_med3_f32_instruction_count -- --nocapture: written first; failed on the original lowering with actual 89 versus expected 65.cargo test --locked --offline -p victory-shader med3_f32 -- --nocapture: 3 passed, 0 failed after implementation. The new runtime test compares 54,872 input triples over 20 modifier settings on both the RX 6750 XT and WARP: zero CPU-reference mismatches and zero adapter disagreements. It covers signed zeros, positive/negative denormals, ordinary and extreme finite values, infinities, quiet/signalling NaNs in every source, abs/neg, clamp and all output multipliers, across multiple waves.cargo test --locked --offline -p victory-shader: baseline 300 passed, 2 failed, 3 ignored; after 302 passed, 2 failed, 3 ignored. Both runs fail onlyemit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order, with the local dxil.dll errorContainer part 'Pipeline State Validation' does not match expected for module.No tests were weakened or disabled.cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: passed.cargo fmt --check: fails on pristine upstream main and this branch with the same 925 pre-existing formatting hunks; normalized hunk contents are identical, with only line numbers/checkout roots differing. The new code was formatted; unrelated formatting changes were excluded.cargo run --locked --offline -p xtask -- policy --staged: passed, 3 files OK.git diff --check: passed.Execution coverage is limited to this RX 6750 XT and WARP. Other GPUs/drivers and game behavior were not tested. All shader inputs are synthetic; no game was launched and no game files or game-derived content were used.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
@oni-swr on GitHub · 2026-11-27 21:15 UTC · original
Verification of #3608: PASS, with a file-size caveat.
Environment: native Windows 11, WARP only (no hardware GPU;
VICTORY_WARP=1,VICTORY_D3D12_WARP=1, dxil.dll). AI-assisted (Claude).29882eb9is unchanged. It merges onto main63bcca43with no conflicts.cargo test -p victory-shader --lib:emit::synthetic_testsfail on both, so they are not caused by this PR. Three say "no pipeline for a wave of 32", which WARP cannot run.gathers_at_a_level_match_the_hardwarefails on a lane mismatch.v_med3_f32_instruction_countfails on base with 89 against the expected 65, which confirms the 89 -> 65 claim.med3_f32_ordered_keys_match_the_referencepasses on base. It is an equivalence guard, so it does not fail without the change. It passes on the head too, which confirms the new lowering matches the reference.cargo clippy -p victory-shader --all-targets -- -D warningson head: clean.x ^ ((x>>31) & 0x7fffffff)orders -0 (-1) below +0 (0). It is its own inverse.med3rule.least == 0x7fffffffand fall back to the original minNum chain. Only a NaN can have that key, since inf is 0x7f800000.lower.rsis 523,938 bytes on its own. The 524,288-byte limit (xtask/src/policy.rs) leaves 350 bytes of room.lower.rs.lower.rs.@andrewpozdnakov7-jpg on GitHub · 2026-11-27 21:43 UTC · original
I reproduced the file-size issue with the exact current heads
29882eband #3609c444dff. The direct merge giveslower.rs524,485 bytes, andcargo xtask policyrejects it against the 524,288-byte limit.I moved the FP32 median helper into
lower/med3.rs, keeping its original body. That bringslower.rsto 521,718 bytes. The branch preserves both PR histories, including the adopted RNE/RTZ fix from #3609. Integration branch2dda7f5On app-local WARP 1.0.22, all three median tests passed. The matrix reported zero mismatches across 54,872 input triples for each of 20 modifier settings, and the instruction-count test still expects 65 DXIL instructions. Both exp tests passed on
c444dffalone and on the integration, including the 32 RNE/RTZ readbacks with WARP forced for both harness paths. Strict shader Clippy and asset policy passed.If taking the module move, please retain the Git author, or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit. AI-assisted with Codex.@Ingenioeren on GitHub · 2026-11-27 22:03 UTC · original
Thanks @andrewpozdnakov7-jpg for reproducing the overflow and for the module move. I took it into this PR as
d06df15(with you as co-author):Lower::med3_f32now lives unchanged inemit/lower/med3.rs, wired likelower/bvh.rs. I left #3609's changes out.lower.rson this branch: 523,938 -> 521,171 bytes (3,117 bytes of room under the 524,288-byte limit).cargo test --locked --offline -p victory-shader med3: 7 passed (this includesv_med3_f32_instruction_count= 65 andmed3_f32_ordered_keys_match_the_reference).-p victory-shader: 302 passed, 2 failed, 3 ignored. The 2 failures arerect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order. Both fail with "Pipeline State Validation does not match" from this PC's local dxil.dll, and they fail the same way without this commit.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo run -p xtask -- policy --staged: ok.@ColorMeBoom on GitHub · 2026-11-27 23:48 UTC · original
Hardware run on AMD: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head
d06df15on63bcca4.med3_f32_ordered_keys_match_the_referencepasses. All 20 modifier combinations, at 54,872 inputs each, have zero mismatches on the card and on WARP, for example:victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
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.