-
Notifications
You must be signed in to change notification settings - Fork 815
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
bool is converted to uint32 #170
Comments
Today, I find this issue is ubiquitous. See this fragment shader:
We have such SPIR-V tokens;
The instruction "Store 18 16" violates the SPIR-V spec, which requires the destination and source operand should have the same type. |
I have made a fix in 2725323. Please have a review. |
This bug actually goes a bit deeper. Any time you have a bvecN in a UBO/SSBO, the code that's supposed to insert the int -> bool conversion simply doesn't. Also, I think that just making them integers is somewhat bad policy. What happens if you have do a full struct copy out of a UBO and that struct happens to have booleans in it. What do you do with that? Do you have to emit the load from the UBO one basic type at a time? Do you have to do extract operations to get to the booleans, convert them, and then build the struct back up? It's pretty trivial for the driver to insert the int -> bool conversion as it does the load but as of the commit in question, it no longer has the information. |
Yes, you are definitely right. I have this shader showing the problem you mentioned.
The instruction |
This basic issue was covered by issue #162, which discusses that this is partially implemented.
It is the client APIs (at least Vulkan and OpenGL) that say how a bool is represented as a 32-bit integer in a UBO/SSBO. It is SPIR-V that says a bool is abstract, and provides enough instructions to convert.
The design should not include bitcasts. It is OpSelect and OpNotEqual, etc, that convert between a bool and an int. Maybe I missed a subtler point?
Agreed the full implementation of |
Yes, I do it in my posted change exactly as you expect. I will think about how to handle |
This has been fixed for a while. Too many instances of this issue. ;) |
Co-authored-by: Arkadiusz Sarwa <arkadiusz.sarwa@amd.com>
Hi,
I have this shader:
The output SPIR-V tokens have these two instructions:
From the SPIR-V, we have this limitation:
OpBranchConditional:
Condition must be a Boolean type scalar.
OpPhi:
All Variables must have a type matching Result Type.
Also, OpAny (use any()) also has this problem because the source operand is uint32 instead of bool now, which violates the SPIR-V spec.
I know there is a change (103bef9) converting bool to uint32 implicitly (if the bool variable is defined in block). It is OK to have a uint32 variable loaded from the block. But I think a bitcast instruction should be inserted before using this uint32 variable in all instructions which expect a bool variable (based on SPIR-V spec). Otherwise, this is confusing and makes the output SPIR-V tokens look inconsistent.
Thank you for double checking it.
The text was updated successfully, but these errors were encountered: