Repository navigation
Do not fuse scalar operations in vector_ops when a scalar operand has another type than the result - #707
Do not fuse scalar operations in vector_ops when a scalar operand has another type than the result#707greenhat wants to merge 1 commit into
vector_ops when a scalar operand has another type than the result#707Conversation
…an the result `vector_ops` packs the scalar operands of a fused operation into a vector of the result type. A shift amount can have another signedness than the shifted value (`UVec3 >> 1`, the literal is an `i32`), so the packed `OpCompositeConstruct` was invalid and `spirv-val` rejected the module. Such operations now stay scalar.
Firestar99
left a comment
There was a problem hiding this comment.
I will need some extra time to properly resolve this, I'm unsure:
- why spirv-val if failing here, cause they define themselves that signed and unsigned doesn't actually matter, what matters is the operands themselves.
- if the current fix doesn't affect other stuff
- if we're better off just abandoning signed integers and only emit unsigned. Tried this, but need some other fixups first that will probably ripple through the entire codebase...
|
I see. I was thinking about it as a simple "result type's components must have the same type as the types of the operands" mechanical check for |
|
FWIW, one thing I noticed that might matter for the unsigned-only option. For some instructions naga takes the signedness from the types, not from the instruction. I ran a few modules through its SPIR-V frontend and backend ( The frontend reads |
Shifting a
glaminteger vector by an amount of the other signedness does not build.UVec3 >> 1(the literal is ani32) fails inspirv-val:UVec3 >> i32,IVec3 << u32andUVec3 >> IVec3fail the same way.UVec3 >> 1u32builds.The fix and the test were written with an AI coding agent. I reviewed and checked them.
Details
The code emitted for
UVec3 >> 1before the fix:vector_ops(linker/peephole_opts.rs) packs the scalar operands of a fused operation into a vector of the result type. This skips the fusion when a scalar operand has another type than the lane result. These shifts stay scalar: threeOpShiftRightLogical %uintand theOpCompositeConstructof their results, as the pass received them. The fix adds no new instructions, so I did not add a difftest.The new compile test
ui/dis/vector_shift_mixed_signfails without the fix. Its last case (UVec3 >> u32) is still fused into oneOpShiftRightLogical %v3uint, and the expected output of the otherui/distests does not change.Alternatively, we can keep the fused shift and pack the amounts into a vector of their own type (
OpShiftRightLogicalallows it). I did not do it sincevector_opswould have to add anOpTypeVectorto the module when it is missing. Let me know if you want me to implement it.