[spirv] Fix firstbithigh/low signedness #5665
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The SPIR-V backend was incorrectly choosing to emit either FindSMsb or FindUMsb based on whether the result type of the call expression was signed or unsigned. Since the AST result type was always unsigned (and wrapped in a cast if necessary), this meant FindSMsb was never generated. FindSMsB should however be generated when the argument type is signed. This is indicated by the HLSL intrinsic op code (firstbithigh for signed and ufirstbithigh for unsigned). The SPIR-V generated now matches the DXIL generated.
This bug was discovered while investigating #4702, so at the same time some error checking is added to make unimplemented cases explicit. Because the underlying GLSL.std.450 instructions FindSMsb, FindUMsb and FindILsB are currently limited to 32-bit width components, we now emit an error messages when this would otherwise result in invalid SPIR-V.