Shaders: declare 64-bit integer operations only where they are made #2054
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2056"
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 0xkn0wh3r3 on 2026-11-25T04:13:07Z.
The problem
Some translated programs failed validation with "Flags must match usage": the module declared 64-bit integer operations it did not contain. The validator refuses such a module (the declared flags have bit 20, which the actual ones lack).
The mechanism:
Lower::src64raised the module's 64-bit integer flag (flags::INT64) before reading its operand.Found by validating random programs (the generator of #1335, run on
mainwith a validation pass, validator 1.6):mainThe fix
The flag is now raised by the instructions themselves, once they are made:
src64, where it builds the value from a register pair or zero-extends a 32-bit one.v_mad_u64_u32/v_mad_i64_i32and the 64-bit compares.A constant source alone no longer raises it.
Testing
emit::lower::tests::a_64_bit_operation_left_out_declares_no_64_bit_operations: lowers a 64-bit shift and compare ofs[0:1](user SGPRs no root parameter fills) and checks the flag stays down. It is up onmain(fails with[d7000002, 00000080] left out). It also lowers them onv[0:1], where both are made, and checks the flag is up.cargo test --release -p victory-shader --libon an RTX 5070 Ti: 245 passed. The 3 failures (emit::stride_tests::*x2,emit::synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way onmainon this GPU (#1835).cargo clippy -p victory-shader --all-targets --features host: clean.Related
Independent of #1090 (constant
_f/_t64-bit compares read no operands) and #1599 (64-bit compares on their dwords). With #1599 the compare arm here goes away and the rest still applies.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:26:03Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.145 passed / 0 failed / 2 ignored. 64-bit integer operations declared only where they are made (+1 test) — capability declaration precision for i64 ops; relates to #1599's dword compares and the 64-bit atomics cluster.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:44:45Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib a_64_bit_operation_left_out_declares_no_64_bit_operations— passedcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean fix ensuring
INT64_OPSis only declared when 64-bit integer operations are actually emitted. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T04:22:56Z.
One integration detail for whoever lands #1599 and this PR second: the expectation in the new test needs updating along with the compare arm.
I ran
a_64_bit_operation_left_out_declares_no_64_bit_operationsonc6bc034alone (pass), then merged #1599 at1f6b392locally, retaining its dword comparison at the single source conflict. The unchanged test failed at[d4e2006a, 00020080] made: the register-sourced equality comparison now correctly leaves INT64 clear.In the combined tree I kept the two missing-source assertions unchanged, expected INT64 for the register-sourced shift, and expected it clear for the register-sourced comparison. That passed, as did #1599's
v_cmp_u64_and_i64_order_by_the_high_dwordon the same tree. This is specific to the combined implementation. AI-assisted; tested on Windows.Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:35:30Z.
Thanks @Dathinel for running it combined with #1599 and posting the merged expectation. I've left the test as it is here, since it matches
maintoday. Whichever of the two PRs lands second should take your combined version: the register-sourced comparison leaves INT64 clear once #1599's dword compare is in, and the register-sourced shift still sets it.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:23:49Z.
Automated triage for the maintainers.
Merge candidate.
In
crates/victory-shader/src/emit/lower.rs,Lower::src64setflags::INT64before reading its operand. If that read failed and the instruction was dropped, or if the source was only a constant, the module still declared 64-bit operations it did not have, and the validator rejects that ("Flags must match usage"). The flag is now set only where an i64 instruction is actually emitted: insrc64's register-pair and zero-extend paths, and in its three callers (64-bit shifts,v_mad_{u,i}64_{u32,i32}, 64-bit compares), after all their sources have been read. I checked thatsrc64has no other callers and that no early return sits between the new flag sets and the emitted instructions. This is about DXIL validity only and does not change shader semantics.Overlap: #1599 changes the same compare arm. The thread says the new test's expectation for the compare needs updating if #1599 lands first. #2133 (shifts without INT64) rewrites the same shift arm. Either way, whichever lands second needs a small rebase.
CI: not run (no check runs on this head). A maintainer may need to approve the workflow run.
Recommending a look, not approving.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:29:02Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
c6bc034bontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T18:51:03Z.
Closing: upstream
286a00ecovers this.Shader::finishnow sets and clears the 64-bit integer flag (with the heap and wave-operation flags) from what the DXIL writer actually writes (Module::uses), so a flag can't outlive an operation that was left out.Pull request closed