-
Notifications
You must be signed in to change notification settings - Fork 853
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
Incorrect codegen when there is redundant float16_t conversion #3616
Comments
Thanks for the detailed bug report, this is definitely an issue that needs to be fixed, probably in the core of glslang as apparently the way it generates these conversions is wrong. |
…int8_t, uint16_t/uint8_t constructors - Original Bug Report: KhronosGroup#3616
I read the GL_EXT_shader_16bit_storage extension spec, here: https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GL_EXT_shader_16bit_storage.txt It says the following about float16_t and types alike: This means we can do the following things to avoid generating invalid SPIR-V bitcode:
I've a applied a temporary fix for the solution no 3, i.e. which now generates the following instructions:
Which also passes the spir-v validator. I'll raise a pull request once I've verified the existing test case to make sure my changes doesn't break anything. |
Thanks for your work. I'm not an expert in GLSL spec, I just feel the method 3 is too wired. Personally I think the method 2 (skip it since it's redundant) is actually what the standard implies. Although the GL_EXT_shader_16bit_storage extension spec does not explicit list Instead, Chapter 5.4 (Operators and Expressions/Conversion) says "Identity constructors, like float(float) are also legal, but of little use.". In summary, GL_EXT_shader_16bit_storage'x text should be read together with Chapter 5.4. Although the text does not explicitly says identity conversions are noop, |
Somebody has added the following comment when generating intermediate representation for float16_t constructor in ParserHelper.cpp:TParseContext::constructBuiltIn:
Is that true? I see that constructing composites (vec4 etc.) of float16_t is completely possible. |
I've applied a correct fix for it and all tests are passing: 100% tests passed, 0 tests failed out of 2 Total Test time (real) = 45.92 sec However, I suspect we do not check the generated SPIR-V using FileCheck like tools or do we? |
Disclaimer: I'm not an expert of GLSL expert and I'm not familiar with glslang, I just happened to write some GLSL code before. All the below are my personal understandings.
Yes for GL_EXT_shader_16bit_storage. The ext spec text explicit says, "Constructors of or using 8-bit and 16-bit vector types must construct from a type with the same number of components. The following is a complete list of such constructors" I interpret it as GL_EXT_shader_16bit_storage does not allow constucting a However, EXT_shader_explicit_arithmetic_types does allow constructing f16vec from float16_t scalar components.
The code seems somewhat reasonable? However, I think it should only be applied to composite types (Vec and Mat), not be applied to 8/16-bit scalar types. |
Applied the fix and raised a pull request here: #3622 Yes, you're correct we do not need to remove the code. |
For background, you may see google/shaderc#1418
I just understand this is actually a glslang bug, so I raise the issue here.
For the compute shader,
glslang
generates ill-formed spirv binary, demonstrated by the following commandsI take a look at the disassembly, it is indeed incorrect. The spec on
OPFConvert
says that "The component width must not equal the component width in Result Type.", so the op actually should be eliminated.Version
I also test the bug also exists on current master.
OS: ArchLinux
The text was updated successfully, but these errors were encountered: