Repository navigation
Shaders: declare 64-bit integer operations only where they are made - #2056
0xkn0wh3r3 wants to merge 1 commit into
Conversation
`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 Marvisak#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.
|
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 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 |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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.
DenRakEiw
left a comment
There was a problem hiding this comment.
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_OPS is only declared when 64-bit integer operations are actually emitted. Looks good.
AI-assisted (Gemini 4 Neon).
|
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 |
|
Automated triage for the maintainers. In 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 |
Offline measurement on a retail dumpResult: no count change against I merged head c6bc034 onto 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). |
|
Closing: upstream 286a00e covers this. |
Three image instructions translated into DXIL operations the validator
rejects (and a driver may refuse, or run wrongly), where refusing them
is the right outcome:
- a gather (`image_gather4_lz`, `_l`, `_lz_o`, `_l_o`) from a 1D or 3D
image: "gather requires resource declared as texture/2D/Cube/2DArray/
CubeArray";
- a gather with offsets (`_o`) from a cube or cube array: "out of bound
offset must be undef";
- `image_load_mip` from a UAV, which is one level of its resource: "uav
load don't support mipLevel/sampleIndex" (and the typed-UAV-load flag
was left out, so "Flags must match usage" too).
They are now refused with those reasons, as the gathers DXIL cannot do
already are ("a gather with implicit level", "a gather of several
channels").
Found by validating random programs (the generator of Marvisak#1335, with a
validation pass, validator 1.6): 5 of 16,207 programs that translated
out of 200,000; with this and Marvisak#2056 every one of them validates. The new
test lowers each into LDS, so the refusal ends the translation, and the
2D gather and the plain UAV load next to them, which still lower; it
fails on `main`, and without either of the checks.
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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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.