DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

vk::ext_type_def fails to compile

Open forbiddencactus opened this issue 2 years ago • 5 comments

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;

forbiddencactus avatar May 03 '23 02:05 forbiddencactus

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.

s-perron avatar May 03 '23 20:05 s-perron

@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.

s-perron avatar May 03 '23 20:05 s-perron

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. :)

forbiddencactus avatar May 08 '23 05:05 forbiddencactus

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.

s-perron avatar Jun 13 '23 18:06 s-perron

Now that we have finished updating the inline spir-v, could you update the wiki that is pointed to above?

s-perron avatar Jan 30 '24 18:01 s-perron

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.

s-perron avatar Aug 23 '24 15:08 s-perron