shader: lower wave prefixes of min and max #470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Loggerten on 2026-11-24T03:47:53Z.
What
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.
Imported from Marvisak/VIctory. Originally posted by towiice on 2026-11-24T03:50:08Z.
Review: COMMENTED
Tested:
stable-x86_64-pc-windows-gnullvm(llvm-mingw 23.1.6).cargo +stable-x86_64-pc-windows-gnullvm test -p victory-shaderemit::lower::tests::a_wave_prefix_of_min_lowerspasses cleanly and lowers the wave32 inclusive min prefix without the previous refusal panic.Clean diff, well-scoped mapping matching the DXIL
WaveOpKindspecification.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:28:14Z.
Review: APPROVED
Tested
6dd6d5fon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed).(kind, sop)matches the DXIL enums: Sum 0, Product 1, Min 2, Max 3, and signed 0, unsigned 1. Inclusive min and max fold the lane's own term back with the right compare for each type (ULT/UGT, SLT/SGT, OLT/OGT). For floats,select(olt(r, arg), r, arg)returnsargwhenris NaN. That differs fromfmin's NaN rule, but matches what a scan built fromv_min_f32sees only if the input is NaN-free. That's acceptable.WavePrefixSumandWavePrefixProduct, so DXC never emitswavePrefixOpwith Min or Max. I checked whether the validator accepts it anyway. I temporarily made the test'slowers_withrun the emitted container throughdxil.dll, anda_wave_prefix_of_min_lowersvalidated OK. Validation is not execution, though: drivers have never seen prefix Min/Max from DXC, so a GPU test (valu_tests::run_cases) comparing lanes on hardware and WARP would be the real proof.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:51:03Z.
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).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T05:30:48Z.
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.
Imported from Marvisak/VIctory. Originally posted by Halfect on 2026-11-24T11:52:43Z.
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.Imported from Marvisak/VIctory. Originally posted by Loggerten on 2026-11-24T11:57:29Z.
@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.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:38:29Z.
Review: COMMENTED
Test-merge with current main (
ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touchedlower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.Imported from Marvisak/VIctory. Originally posted by rouges78 on 2026-11-24T16:05:17Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:19:50Z.
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
Imported from Marvisak/VIctory. Originally posted by Loggerten on 2026-11-26T20:08:36Z.
Rebased onto current main (
63bcca4, merged as73e01c5). Thelower.rsconflict resolves onto main's current test helpers (lowers(words, rsrc2)withstructure::structure+ four-argresource::track); no branch copies of helpers were kept, andprefix_scans/heap_handlesboth survive in the lowered struct. Windows run:cargo test -p victory-shader303 passed / 3 ignored;cargo clippy --workspace --all-targets --locked -- -D warningsclean.Imported from Marvisak/VIctory. Originally posted by Loggerten on 2026-11-26T20:21:08Z.
CI caught the asset-policy size cap: the merged
lower.rswas 530501 bytes, over the 512 KiB limit (main itself sits at 520563).ed2d2c8moves the test module toemit/lower_tests.rsunchanged, solower.rsis 476269 bytes andcargo xtask policyreports 192 files ok. Merged-tree Windows run after the move: 303 passed / 3 ignored.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T20:57:28Z.
This head and #395 both move the same lowering test module. I resolved that conflict in
ec7c106with both exact PR heads as parents. The min-prefix scan test and both restrictions on compressed target formats are retained. The DXIL validator accepted the prefix scan, and the new independent compressed-export draw read all four channels correctly on WARP. The focused lowering suite passed in three runs, with strict Clippy and the asset policy check passing too.Full test details in #395. If either PR lands first, the same resolution applies to the other. If you fold the resolution into another commit, please keep the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.