Shaders: declare 64-bit integer operations only where they are made #2056
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!2056
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2056/head"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 04:13 UTC · original
0xkn0wh3r3:shaders/int64-flag-only-for-emitted-ops→main· +43 −1 · 1 files · 1 commits · closed without mergingThe 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.`Lower::src64` raised the module's 64-bit integer flag (`flags::INT64`) before reading its operand. When the read failed (a register pair with no DXIL value, "an unread operand") the instruction was left out, and when nothing read its result the program still translated: with the flag and no 64-bit instruction. The validator refuses such a module ("Flags must match usage", the declared flags with bit 20 the actual ones lack). An inline or literal constant raised it too, and is no instruction: a 64-bit compare whose other source then failed left the same mismatch. The flag is now raised by the instructions themselves: `src64` where it builds the value from a register pair or zero-extends a 32-bit one, and its callers (the 64-bit shifts, `v_mad_u64_u32`/`v_mad_i64_i32` and the 64-bit compares) at their own 64-bit instruction, once every source was read. Found by validating random programs (the generator of #1335, run on `main` with a validation pass, validator 1.6): 82 of 8,079 programs that translated out of 100,000 failed with "Flags must match usage", all of them for this flag; with the change, none of 16,207 out of 200,000. The new test lowers a 64-bit shift and compare of `s[0:1]` (user SGPRs no root parameter fills) and checks the flag stays down (it is up on `main`), and of `v[0:1]`, where both are made, that it is up.@Dathinel on GitHub · 2026-11-25 04:22 UTC · original
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.@0xkn0wh3r3 on GitHub · 2026-11-25 06:35 UTC · original
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.@Marvisak on GitHub · 2026-11-25 09:23 UTC · original
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
@sinan-cmyk on GitHub · 2026-11-25 09:29 UTC · original
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).
@0xkn0wh3r3 on GitHub · 2026-11-25 18:51 UTC · original
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