-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MSL] Invalid MSL when casting 16-bit types #2046
Comments
This is annoying. I think the only correct way to do this is to cast after an arithmetic operation that has implicit promotion. For example. If we consider
|
I did some more testing and found that the integer promotion behavior doesn't seem to affect vector types. As in, this gets promoted:
but this does not:
Since
and that'd be enough to fix the issue? (Assuming is_integer_promotion_implicit() only returns true on MSL, and some fixup is done inside optimize_read_modify_write() in order to pass the shader regression tests) Would that be an acceptable approach? |
Thank you for fixing this! I can confirm that #2049 fixes my local shaders as well. 🙂 |
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
Original issue: godotengine#51679 (comment) And related fix in SPIRV-Cross: KhronosGroup/SPIRV-Cross#2046
I seem to be running into some problems with the MSL generated by SPIRV-Cross when 16-bit types are used with casts.
Simple Repro:
HLSL:
SPIR-V (Compiled with
dxc -spirv -enable-16bit-types -T cs_6_2 -E Msl16Test msl16test.hlsl
):MSL (Compiled with
spirv-cross --msl msl16test.spv
):Metal Compilation (
metal msl16test.metal
):Based on the error message, it looks like the ushort types from the SPIR-V are being promoted to full width integers during the subtraction operation in MSL. I believe this happens for other operations like bit shifts as well.
I hacked the code a bit to get it to insert an extra integer cast in spirv_glsl.cpp:6129 (CompilerGLSL::emit_binary_op_cast) like this:
This gives me the following MSL which compiles successfully:
I created an issue rather than a PR since I know this change isn't robust.
Is there a reasonable way to inject some logic like this that only affects the MSL backend?
I see that there's already some references to this issue in the MSL specific code here (spirv_msl.cpp:15054):
What would be the best way to solve this? I imagine this will require some new hooks in CompilerMSL? Or maybe there's another way?
Thanks!
The text was updated successfully, but these errors were encountered: