shader: lower wave prefixes of min and max #470
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!470
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-470"
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?
@Loggerten on GitHub · 2026-11-24 03:47 UTC · original
Loggerten:fix/wave-prefix-minmax→main· +223 −3 · 2 files · 9 commits · openWhat
The wave prefix path lowered
wavePrefixOpfor sums only. Every other operation fell out ata wave prefix of an operation other than a sum, even though the active-reduction arm right below it already mapped min and max.This widens the prefix arm to
MinU/MaxU/MinI/MaxI/MinF/MaxF, with a(kind, sop)table that mirrors the active-reduction one. Exclusive prefixes pass through. Inclusive min/max fold the lane's own term back in with an ordering compare plus select, becausewavePrefixOpexcludes it.Bitwise prefixes stay refused, with a corrected message: DXIL
WaveOpKindhas no bitwise member (Sum/Product/Min/Max), sowavePrefixOpcannot express them at all.Signature verified against the DXIL spec:
dx.op.wavePrefixOp.<i32|f32>(121, value, i8 kind, i8 sop).Verified
emit::lower::tests::a_wave_prefix_of_min_lowers: a wave32 whole-wave section that leaves a per-lane inclusiveMinUprefix, consumed by ands_write_b32. Without the fix the store reads the missing value and the program fails witha wave prefix of an operation other than a sum(offset 160). With the fix it lowers.cargo test -p victory-shader: 57 passed, 0 failed (56 baseline + 1).cargo fmt --check -p victory-shaderclean;cargo clippy -p victory-shader --all-targetsno new warnings.cargo xtask policy: 151 files ok.emit/wave.rstracking, not this refusal arm, so no overlap.AI-assisted (Hermes Agent); I reviewed the diff and ran the tests and gates myself.
ccfb029) into fix/wave-prefix-minmax 1c8f41fd1e940d32f) into fix/wave-prefix-minmax 2317bc1086@DaviTostes on GitHub · 2026-11-24 03:51 UTC · original
Verified
6dd6d5fon Arch Linux x86_64 (rustc 1.98.1,cargo test -p victory-shader): 57 passed, 0 failed, 0 ignored.Not covered: wave-prefix min/max on real hardware and title shaders (no game data).
@upipibi on GitHub · 2026-11-24 05:30 UTC · original
Two things on
6dd6d5f, from reading the code (not run):NaN in the inclusive fold (
lower.rs:797-799). The float min/max fold usesselect(r < arg, r, arg)(OLT/OGT), so when either side is NaN the compare is false andargwins. The sequence this replaces is built fromv_min_f32/v_max_f32, which return the non-NaN operand. Example, inclusive min: lane 0 = 1.0, lane 1 = NaN → lane 1 should be 1.0, this gives NaN. Ifargis the one that isn't NaN,r(NaN) is dropped the right way only by luck of the order. Using the sameFMin/FMaxthe translator already emits forv_min_f32/v_max_f32would match.wavePrefixOpwith kind 2 / 3 (Min / Max). DXIL documentsWavePrefixOponly for Sum and Product (HLSL has noWavePrefixMin/WavePrefixMax), so drivers have never been handed this, and the validator or a driver may refuse it.a_wave_prefix_of_min_lowersonly checks that the program lowers. Running that module throughdxil.dllvalidation and on a GPU, as thevalu_testsharness does, would show whether it's accepted. If it isn't, an exclusive prefix min/max can be built fromWaveReadLaneAt/ a log-step scan instead.AI-assisted (Claude Code), read-only review.
@Halfect on GitHub · 2026-11-24 11:52 UTC · original
Independent validation of current head
95212d9on Windows:cargo test --locked -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignored.a_wave_prefix_of_min_lowersto pass the generated container throughdxil.dllvalidation, create a compute pipeline on the default hardware D3D12 adapter, and dispatch one synthetic group. Validation, pipeline creation, and dispatch all succeeded.cargo clippy --locked -p victory-shader --all-targets -- -D warnings: passed.cargo xtask policy: 154 files ok.This confirms that the existing synthetic MinU module is accepted by the validator and this driver; it does not establish numerical correctness for all six min/max operations. In particular, the earlier floating-point NaN concern remains untested: the current inclusive float fold still uses
OLT/OGTplus select, while this test has no result readback and does not exercise NaN inputs. A float NaN readback case is still needed to clear that part.@Loggerten on GitHub · 2026-11-24 11:57 UTC · original
@upipibi Pushed
a754127(on top of the merge with mainffe310e).1. NaN in the inclusive fold — fixed. You were right. The inclusive fold now calls
max_min(false/true, r, arg), which is the sameFMin/FMaxplus signed-zero fix the translator already emits forv_min_f32/v_max_f32. Integer min/max keep the compare and select, where a false compare is the right answer. So inclusive min of lane 0 = 1.0 and lane 1 = NaN now yields 1.0, and the NaN is dropped whichever side it is on.2.
WavePrefixOpkind 2/3 — half answered, and it is the weaker half. Your reading of the producers is correct: LLVM'sDXIL.tddefinesWaveOpKind_Min = 2andWaveOpKind_Max = 3, but the only intrinsics on opcode 121 are sum, usum, product and uproduct. Nothing emits prefix min/max.What I could settle from source:
dxil.dllhas no kind rule to reject them with.lib/DxilValidation/DxilValidation.cppin the DXC tree (main) contains noWavePrefixOphandling at all; the kind operand is only type-checked asi8. So validation passing would tell us the module is well formed, not that anything supports the instruction.The part I have not settled is the driver, and I have no hardware run here. I have not claimed it works.
I added a validation step to
a_wave_prefix_of_min_lowers: it lowers the module again, and wheredxil.dllis loadable it validates it, asserting success and the container hash. That runs on the Windows CI job and on any Windows tester's box, and would catch a malformed instruction even though it cannot catch an unsupported one.If you think an undocumented kind should not ship at all, the fix is a
WaveReadLaneAtscan instead ofwavePrefixOp, which rewrites the lowering rather than correcting it. I would want a hardware result before choosing that.@rouges78 on GitHub · 2026-11-24 16:05 UTC · original
Hardware readback for
a754127, from a synthetic test (no game data), on two GPUs.Setup. One group of 32 threads,
WaveSize(32)declared,dxil.dllvalidation on. Each lane loads its own dword from a structured buffer, a whole-wave section shaped like the one ina_wave_prefix_of_min_lowersscans it (sums userow_shr1, 2, 4, 8), and each lane stores the result to a raw UAV over a sentinel. Compared lane by lane with the section's instructions run on the CPU. Inputs are non-monotonic, never zero and order differently as signed and unsigned; float sets add NaNs in lanes 9 and 20, and in lane 0. An exclusive form is built too: it stores the rawwavePrefixOpresult, with no fold.Each cell holds for both the inclusive and the exclusive form.
0xFFFFFFFF(min) and0(max) in lane 0.CreateComputePipelineStatefails withE_OUTOFMEMORYon every run, and later tests in the same run pass. With kind 0 in place of 2 or 3 the same programs create and run.FMin/FMax(prefix, term)returns the prefix. Neither driver could show it.So on these two drivers only the unsigned min/max on the RTX 4080 work as lowered. This is one GPU and one driver version per vendor, and the Radeon driver dates from September 2025.
Test:
wave_prefix_tests.rs(16 tests on top ofa754127, run on every hardware adapter; 13 fail on this machine).AI-assisted (Claude Code), run on my own hardware.
@Marvisak on GitHub · 2026-11-25 00:19 UTC · original · edited 2026-11-25 15:57 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.