KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
2k stars 555 forks source link

SPIRV to GLSL Exception: Cannot resolve expression type. #745

Closed DragonJoker closed 5 years ago

DragonJoker commented 5 years ago

I've been implementing my own SPIR-V writer, and encountered this exception, while validating the output SPIR-V from the following GLSL:

#version 450

void main()
{
        uint x;
        uint y;
        uint c;
        uint r = uaddCarry(x, y, c);
}

To make sure I didn't make any mistake in my own code, I've used glslangvalidator, to generate the SPIR-V (using glslangValidator -V ./test.vert -o test.spv) then feeding SPIRV-Cross with the output SPIR-V (using spirv-cross ./test.spv).

I don't know whether it's a bug in SPIRV-Cross or in glslangvalidator.

Here is the human readable SPIR-V from glslang:

// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 18

                              Capability Shader
               1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint Vertex 4  "main"
                              Source GLSL 430
                              Name 4  "main"
                              Name 8  "r"
                              Name 9  "x"
                              Name 11  "y"
                              Name 13  "c"
                              Name 14  "ResType"
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeInt 32 0
               7:             TypePointer Function 6(int)
     14(ResType):             TypeStruct 6(int) 6(int)
         4(main):           2 Function None 3
               5:             Label
            8(r):      7(ptr) Variable Function
            9(x):      7(ptr) Variable Function
           11(y):      7(ptr) Variable Function
           13(c):      7(ptr) Variable Function
              10:      6(int) Load 9(x)
              12:      6(int) Load 11(y)
              15: 14(ResType) IAddCarry 10 12
              16:      6(int) CompositeExtract 15 1
                              Store 13(c) 16
              17:      6(int) CompositeExtract 15 0
                              Store 8(r) 17
                              Return
                              FunctionEnd

The exception occurs when it tries to retrieve the type of intermediate %15 while parsing the first OpCompositeExtract

DragonJoker commented 5 years ago

Ah, OpIAddCarry is unimplemented...

HansKristian-Work commented 5 years ago

Yes, OpIAddCarry is a known bug. https://github.com/KhronosGroup/SPIRV-Cross/issues/740