Tint WGSL compiler fails to parse SPIR-V with specializations...

249 views
Skip to first unread message

Andrey Honich

unread,
May 15, 2023, 12:39:36 AM5/15/23
to Dawn Graphics
Hello,

in my engine i'm using uber GLSL shaders with specialization constants, which are declared like this:

layout(constant_id = 10)const bool VARIANT_HAS_ALBEDO_MAP = false;
layout(constant_id = 11)const bool VARIANT_HAS_OCCLUSION_MAP = false;
layout(constant_id = 12)const bool VARIANT_HAS_EMISSIVE_MAP = false;
layout(constant_id = 13)const bool VARIANT_HAS_VERTEX_UV0 = false;
layout(constant_id = 14)const bool VARIANT_HAS_VERTEX_UV1 = false;
layout(constant_id = 15)const bool VARIANT_HAS_TEXTURE_TRANSFORM = false;
layout(constant_id = 16)const bool VARIANT_HAS_CHROMA_KEY = false;

Inside the code i'm using them this way:

                        if (VARIANT_HAS_VERTEX_UV0 && VARIANT_HAS_VERTEX_UV1)
                        {
                            uv = vec4(getUV0(), getUV1());
                        }
                        else
                        if (VARIANT_HAS_VERTEX_UV0 && !VARIANT_HAS_VERTEX_UV1)
                        {
                            uv = vec4(getUV0(), getUV0());
                        }
                        else
                        if (!VARIANT_HAS_VERTEX_UV0 && VARIANT_HAS_VERTEX_UV1)
                        {
                            uv = vec4(getUV1(), getUV1());
                        }

And for some reason tint spir-v reader doesn't like this and throwns errors:

error: unhandled expression for ID 348
%348 = OpSpecConstantOp %37 LogicalAnd %346 %347
error: unhandled expression for ID 374
%374 = OpSpecConstantOp %40 LogicalAnd %372 %373

If i modify my code this way (without specializations):

                            uv = vec4(getUV0(), getUV0());

Then it parses fine, without errors.

What is wrong with my code? Why WGSL compiler doesn't like this ?

Regards,
Andrey

Corentin Wallez

unread,
May 15, 2023, 7:48:46 AM5/15/23
to Andrey Honich, Dawn Graphics
Hey Andrey,

It looks like Tint might not support operations on specialization constants in the SPIR-V input path yet. Could you file an issue on crbug.com/tint?

Cheers,

Corentin

--
You received this message because you are subscribed to the Google Groups "Dawn Graphics" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dawn-graphic...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dawn-graphics/b0343759-f32b-45dc-bb20-9d0079a7726dn%40googlegroups.com.

Andrey Honich

unread,
May 15, 2023, 4:53:51 PM5/15/23
to Dawn Graphics
I'm pretty sure Tint SPIR-V reader supports specializations, because it generates declarations inside WGSL like this:

@id(13) override VARIANT_HAS_VERTEX_UV0 : bool = false;
@id(14) override VARIANT_HAS_VERTEX_UV1 : bool = false;
@id(10) override VARIANT_HAS_ALBEDO_MAP : bool = false;
@id(15) override VARIANT_HAS_TEXTURE_TRANSFORM : bool = false;
@id(11) override VARIANT_HAS_OCCLUSION_MAP : bool = false;
@id(12) override VARIANT_HAS_EMISSIVE_MAP : bool = false;
@id(16) override VARIANT_HAS_CHROMA_KEY : bool = false;
@id(17) override VARIANT_HAS_PICKING : bool = false;

But for some reason I cannot use logical operations between the constants, like &&, || or !.
Anyway i had to use workaround avoiding logical ops, and now it compilable.

But..., i didn't find the way how to setup those constants from the WebGPU API level.

Vertex and Fragment states inside RenderPipelineDescriptor have some ConstantEntry pointers. 
Not sure about it, as it has only double types there.

Tried to gogle, didn't find as well.

Regards,
Andrey

Corentin Wallez

unread,
May 16, 2023, 8:17:51 AM5/16/23
to Andrey Honich, Dawn Graphics
WGSL supports operations on specialization constants, so they should be possible to translate on the SPIR-V -> WGSL path. I'd still suggest opening an issue on crbug.com/tint so that this defect is tracked and eventually fixed (even if you found a workaround, which is good!)

Mark Sibly

unread,
May 16, 2023, 5:39:03 PM5/16/23
to Corentin Wallez, Andrey Honich, Dawn Graphics
> Vertex and Fragment states inside RenderPipelineDescriptor have some ConstantEntry pointers. 
> Not sure about it, as it has only double types there.

I have successfully used ConstantEntry values with 'override' variables in wgsl shaders (though not with && or || ops), you just need to cast the constant data to double when setting the ConstantEntry values, so in this case use 1.0 for true, 0.0 for false.

The js docs are here:


Bye!
Mark



Reply all
Reply to author
Forward
0 new messages