vk::ext_type_def fails to compile
The following code, as detailed in the wiki, fails to compile:
[[vk::ext_type_def(/* Unique id for type */ 0, /* OpTypeInt */ 21)]] void createTypeInt([[vk::ext_literal]] int sizeInBits, [[vk::ext_literal]] int signedness); createTypeInt(/* sizeInBits */ 12, /* signedness */ 0); .. vk::ext_type</* Unique id for type */ 0> foo = 3;
At a quick glance, I believe the wiki is incorrect and misleading.
First the createTypeInt(/* sizeInBits */ 12, /* signedness */ 0) needs to be inside a function. A function call in that location does not parse. This is the misleading part.
The wrong parts are first you cannot have a 12 bit integer. If I fix this up to be able to parse, you can see the error. Try
[[vk::ext_type_def(0, 21)]]
void createTypeInt([[vk::ext_literal]] int sizeInBits,
[[vk::ext_literal]] int signedness);
vk::ext_type<0> foo;
float main() : SV_Target
{
createTypeInt(12, 0);
return 0.0;
}
I get the error:
fatal error: generated SPIR-V is invalid: Invalid number of bits (12) used for OpTypeInt. %spirvIntrinsicType = OpTypeInt 12 0
The second error is the assigment vk::ext_type</* Unique id for type */ 0> foo = 3. The compiler cannot do anything with this because it does not know that the ext_type is an integer. As far as the compiler is concerned there is a type mismatch.
@forbiddencactus Thanks for bring this up. I have recently pointed a few people to this wiki and suggested they try it. I assumed it all worked. This will need to be fixed up.
No worries!
In general GL_EXT_spirv_intrinsics is a bit patchy, edge cases that don't work and that sort of thing. I can't remember the other issues off the top of my head but will begin reporting them as I find them again. :)
I have opened https://github.com/microsoft/hlsl-specs/pull/59 to try to clean up the spec. The documentation will be updated once we have updated the HLSL spec. I don't want to update it multiple times.
Now that we have finished updating the inline spir-v, could you update the wiki that is pointed to above?
We have fixed up the inline spir-v. We will be updating the documention at some point. Closing as a duplicate of the issue to update the documentation.
Duplicate of #6412.