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
1.96k stars 549 forks source link

hlsl: Geometry shader generation produces unsupported execution model exception #2334

Closed TheArheus closed 3 weeks ago

TheArheus commented 3 weeks ago

Hi, I have an issue with compiling my shader from glsl to hlsl. I don't know why, but I've got this exception: Unsupported execution model. This is what glslangValidator have generated for me(I didn't know how much of the shader is needed to resolve this issue, so here is a whole just in case):

// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 212

                              Capability Geometry
               1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint Geometry 4  "main" 15 76 177 183 187 188 193 196 202 205
                              ExecutionMode 4 Triangles
                              ExecutionMode 4 Invocations 1
                              ExecutionMode 4 OutputTriangleStrip
                              ExecutionMode 4 OutputVertices 3
                              Source GLSL 460
                              Name 4  "main"
                              Name 9  "FaceNormal"
                              Name 15  "CoordIn"
                              Name 38  "Axis"
                              Name 52  "VoxelSceneScale"
                              Name 58  "global_world_data"
                              MemberName 58(global_world_data) 0  "View"
                              MemberName 58(global_world_data) 1  "DebugView"
                              MemberName 58(global_world_data) 2  "Proj"
                              MemberName 58(global_world_data) 3  "LightView"
                              MemberName 58(global_world_data) 4  "LightProj"
                              MemberName 58(global_world_data) 5  "CameraPos"
                              MemberName 58(global_world_data) 6  "CameraDir"
                              MemberName 58(global_world_data) 7  "GlobalLightPos"
                              MemberName 58(global_world_data) 8  "SceneScale"
                              MemberName 58(global_world_data) 9  "SceneCenter"
                              MemberName 58(global_world_data) 10  "GlobalLightSize"
                              MemberName 58(global_world_data) 11  "PointLightSourceCount"
                              MemberName 58(global_world_data) 12  "SpotLightSourceCount"
                              MemberName 58(global_world_data) 13  "CascadeSplits"
                              MemberName 58(global_world_data) 14  "ScreenWidth"
                              MemberName 58(global_world_data) 15  "ScreenHeight"
                              MemberName 58(global_world_data) 16  "NearZ"
                              MemberName 58(global_world_data) 17  "FarZ"
                              MemberName 58(global_world_data) 18  "DebugColors"
                              MemberName 58(global_world_data) 19  "LightSourceShadowsEnabled"
                              Name 59  "b0"
                              MemberName 59(b0) 0  "WorldUpdate"
                              Name 61  ""
                              Name 75  "OutPos"
                              Name 76  "CoordClip"
                              Name 166  "i"
                              Name 175  "gl_PerVertex"
                              MemberName 175(gl_PerVertex) 0  "gl_Position"
                              MemberName 175(gl_PerVertex) 1  "gl_PointSize"
                              MemberName 175(gl_PerVertex) 2  "gl_ClipDistance"
                              MemberName 175(gl_PerVertex) 3  "gl_CullDistance"
                              Name 177  ""
                              Name 183  "CoordOut"
                              Name 187  "NormOut"
                              Name 188  "NormIn"
                              Name 193  "TextCoordOut"
                              Name 196  "TextCoordIn"
                              Name 202  "MatIdxOut"
                              Name 205  "MatIdxIn"
                              Decorate 15(CoordIn) Location 1
                              Decorate 54 ArrayStride 64
                              Decorate 55 ArrayStride 64
                              Decorate 57 ArrayStride 4
                              MemberDecorate 58(global_world_data) 0 ColMajor
                              MemberDecorate 58(global_world_data) 0 Offset 0
                              MemberDecorate 58(global_world_data) 0 MatrixStride 16
                              MemberDecorate 58(global_world_data) 1 ColMajor
                              MemberDecorate 58(global_world_data) 1 Offset 64
                              MemberDecorate 58(global_world_data) 1 MatrixStride 16
                              MemberDecorate 58(global_world_data) 2 ColMajor
                              MemberDecorate 58(global_world_data) 2 Offset 128
                              MemberDecorate 58(global_world_data) 2 MatrixStride 16
                              MemberDecorate 58(global_world_data) 3 ColMajor
                              MemberDecorate 58(global_world_data) 3 Offset 192
                              MemberDecorate 58(global_world_data) 3 MatrixStride 16
                              MemberDecorate 58(global_world_data) 4 ColMajor
                              MemberDecorate 58(global_world_data) 4 Offset 384
                              MemberDecorate 58(global_world_data) 4 MatrixStride 16
                              MemberDecorate 58(global_world_data) 5 Offset 576
                              MemberDecorate 58(global_world_data) 6 Offset 592
                              MemberDecorate 58(global_world_data) 7 Offset 608
                              MemberDecorate 58(global_world_data) 8 Offset 624
                              MemberDecorate 58(global_world_data) 9 Offset 640
                              MemberDecorate 58(global_world_data) 10 Offset 656
                              MemberDecorate 58(global_world_data) 11 Offset 660
                              MemberDecorate 58(global_world_data) 12 Offset 664
                              MemberDecorate 58(global_world_data) 13 Offset 668
                              MemberDecorate 58(global_world_data) 14 Offset 684
                              MemberDecorate 58(global_world_data) 15 Offset 688
                              MemberDecorate 58(global_world_data) 16 Offset 692
                              MemberDecorate 58(global_world_data) 17 Offset 696
                              MemberDecorate 58(global_world_data) 18 Offset 700
                              MemberDecorate 58(global_world_data) 19 Offset 704
                              MemberDecorate 59(b0) 0 NonWritable
                              MemberDecorate 59(b0) 0 Offset 0
                              Decorate 59(b0) BufferBlock
                              Decorate 61 DescriptorSet 0
                              Decorate 61 Binding 0
                              Decorate 76(CoordClip) Location 0
                              MemberDecorate 175(gl_PerVertex) 0 BuiltIn Position
                              MemberDecorate 175(gl_PerVertex) 1 BuiltIn PointSize
                              MemberDecorate 175(gl_PerVertex) 2 BuiltIn ClipDistance
                              MemberDecorate 175(gl_PerVertex) 3 BuiltIn CullDistance
                              Decorate 175(gl_PerVertex) Block
                              Decorate 183(CoordOut) Location 0
                              Decorate 187(NormOut) Location 1
                              Decorate 188(NormIn) Location 2
                              Decorate 193(TextCoordOut) Location 2
                              Decorate 196(TextCoordIn) Location 3
                              Decorate 202(MatIdxOut) Location 3
                              Decorate 205(MatIdxIn) Location 4
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeFloat 32
               7:             TypeVector 6(float) 3
               8:             TypePointer Function 7(fvec3)
              10:             TypeVector 6(float) 4
              11:             TypeInt 32 0
              12:     11(int) Constant 3
              13:             TypeArray 10(fvec4) 12
              14:             TypePointer Input 13
     15(CoordIn):     14(ptr) Variable Input
              16:             TypeInt 32 1
              17:     16(int) Constant 1
              18:             TypePointer Input 10(fvec4)
              22:     16(int) Constant 0
              27:     16(int) Constant 2
              37:             TypePointer Function 6(float)
              39:     11(int) Constant 0
              42:     11(int) Constant 1
              45:     11(int) Constant 2
              50:             TypeVector 6(float) 2
              51:             TypePointer Function 50(fvec2)
              53:             TypeMatrix 10(fvec4) 4
              54:             TypeArray 53 12
              55:             TypeArray 53 12
              56:     11(int) Constant 4
              57:             TypeArray 6(float) 56
58(global_world_data):             TypeStruct 53 53 53 54 55 10(fvec4) 10(fvec4) 10(fvec4) 10(fvec4) 10(fvec4) 6(float) 11(int) 11(int) 57 6(float) 6(float) 6(float) 6(float) 11(int) 11(int)
          59(b0):             TypeStruct 58(global_world_data)
              60:             TypePointer Uniform 59(b0)
              61:     60(ptr) Variable Uniform
              62:     16(int) Constant 8
              63:             TypePointer Uniform 10(fvec4)
              70:             TypeBool
              74:             TypePointer Function 13
   76(CoordClip):     14(ptr) Variable Input
              80:    6(float) Constant 1065353216
              85:             TypePointer Function 10(fvec4)
             165:             TypePointer Function 11(int)
             174:             TypeArray 6(float) 42
175(gl_PerVertex):             TypeStruct 10(fvec4) 6(float) 174 174
             176:             TypePointer Output 175(gl_PerVertex)
             177:    176(ptr) Variable Output
             181:             TypePointer Output 10(fvec4)
   183(CoordOut):    181(ptr) Variable Output
    187(NormOut):    181(ptr) Variable Output
     188(NormIn):     14(ptr) Variable Input
             192:             TypePointer Output 50(fvec2)
193(TextCoordOut):    192(ptr) Variable Output
             194:             TypeArray 50(fvec2) 12
             195:             TypePointer Input 194
196(TextCoordIn):    195(ptr) Variable Input
             198:             TypePointer Input 50(fvec2)
             201:             TypePointer Output 11(int)
  202(MatIdxOut):    201(ptr) Variable Output
             203:             TypeArray 11(int) 12
             204:             TypePointer Input 203
   205(MatIdxIn):    204(ptr) Variable Input
             207:             TypePointer Input 11(int)
         4(main):           2 Function None 3
               5:             Label
   9(FaceNormal):      8(ptr) Variable Function
        38(Axis):     37(ptr) Variable Function
52(VoxelSceneScale):     51(ptr) Variable Function
      75(OutPos):     74(ptr) Variable Function
          166(i):    165(ptr) Variable Function
              19:     18(ptr) AccessChain 15(CoordIn) 17
              20:   10(fvec4) Load 19
              21:    7(fvec3) VectorShuffle 20 20 0 1 2
              23:     18(ptr) AccessChain 15(CoordIn) 22
              24:   10(fvec4) Load 23
              25:    7(fvec3) VectorShuffle 24 24 0 1 2
              26:    7(fvec3) FSub 21 25
              28:     18(ptr) AccessChain 15(CoordIn) 27
              29:   10(fvec4) Load 28
              30:    7(fvec3) VectorShuffle 29 29 0 1 2
              31:     18(ptr) AccessChain 15(CoordIn) 22
              32:   10(fvec4) Load 31
              33:    7(fvec3) VectorShuffle 32 32 0 1 2
              34:    7(fvec3) FSub 30 33
              35:    7(fvec3) ExtInst 1(GLSL.std.450) 68(Cross) 26 34
              36:    7(fvec3) ExtInst 1(GLSL.std.450) 4(FAbs) 35
                              Store 9(FaceNormal) 36
              40:     37(ptr) AccessChain 9(FaceNormal) 39
              41:    6(float) Load 40
              43:     37(ptr) AccessChain 9(FaceNormal) 42
              44:    6(float) Load 43
              46:     37(ptr) AccessChain 9(FaceNormal) 45
              47:    6(float) Load 46
              48:    6(float) ExtInst 1(GLSL.std.450) 40(FMax) 44 47
              49:    6(float) ExtInst 1(GLSL.std.450) 40(FMax) 41 48
                              Store 38(Axis) 49
              64:     63(ptr) AccessChain 61 22 62
              65:   10(fvec4) Load 64
              66:   50(fvec2) VectorShuffle 65 65 0 1
                              Store 52(VoxelSceneScale) 66
              67:     37(ptr) AccessChain 9(FaceNormal) 39
              68:    6(float) Load 67
              69:    6(float) Load 38(Axis)
              71:    70(bool) FOrdEqual 68 69
                              SelectionMerge 73 None
                              BranchConditional 71 72 103
              72:               Label
              77:     18(ptr)   AccessChain 76(CoordClip) 22
              78:   10(fvec4)   Load 77
              79:    7(fvec3)   VectorShuffle 78 78 2 1 0
              81:    6(float)   CompositeExtract 79 0
              82:    6(float)   CompositeExtract 79 1
              83:    6(float)   CompositeExtract 79 2
              84:   10(fvec4)   CompositeConstruct 81 82 83 80
              86:     85(ptr)   AccessChain 75(OutPos) 22
                                Store 86 84
              87:     18(ptr)   AccessChain 76(CoordClip) 17
              88:   10(fvec4)   Load 87
              89:    7(fvec3)   VectorShuffle 88 88 2 1 0
              90:    6(float)   CompositeExtract 89 0
              91:    6(float)   CompositeExtract 89 1
              92:    6(float)   CompositeExtract 89 2
              93:   10(fvec4)   CompositeConstruct 90 91 92 80
              94:     85(ptr)   AccessChain 75(OutPos) 17
                                Store 94 93
              95:     18(ptr)   AccessChain 76(CoordClip) 27
              96:   10(fvec4)   Load 95
              97:    7(fvec3)   VectorShuffle 96 96 2 1 0
              98:    6(float)   CompositeExtract 97 0
              99:    6(float)   CompositeExtract 97 1
             100:    6(float)   CompositeExtract 97 2
             101:   10(fvec4)   CompositeConstruct 98 99 100 80
             102:     85(ptr)   AccessChain 75(OutPos) 27
                                Store 102 101
                                Branch 73
             103:               Label
             104:     37(ptr)   AccessChain 9(FaceNormal) 42
             105:    6(float)   Load 104
             106:    6(float)   Load 38(Axis)
             107:    70(bool)   FOrdEqual 105 106
                                SelectionMerge 109 None
                                BranchConditional 107 108 134
             108:                 Label
             110:     18(ptr)     AccessChain 76(CoordClip) 22
             111:   10(fvec4)     Load 110
             112:    7(fvec3)     VectorShuffle 111 111 0 2 1
             113:    6(float)     CompositeExtract 112 0
             114:    6(float)     CompositeExtract 112 1
             115:    6(float)     CompositeExtract 112 2
             116:   10(fvec4)     CompositeConstruct 113 114 115 80
             117:     85(ptr)     AccessChain 75(OutPos) 22
                                  Store 117 116
             118:     18(ptr)     AccessChain 76(CoordClip) 17
             119:   10(fvec4)     Load 118
             120:    7(fvec3)     VectorShuffle 119 119 0 2 1
             121:    6(float)     CompositeExtract 120 0
             122:    6(float)     CompositeExtract 120 1
             123:    6(float)     CompositeExtract 120 2
             124:   10(fvec4)     CompositeConstruct 121 122 123 80
             125:     85(ptr)     AccessChain 75(OutPos) 17
                                  Store 125 124
             126:     18(ptr)     AccessChain 76(CoordClip) 27
             127:   10(fvec4)     Load 126
             128:    7(fvec3)     VectorShuffle 127 127 0 2 1
             129:    6(float)     CompositeExtract 128 0
             130:    6(float)     CompositeExtract 128 1
             131:    6(float)     CompositeExtract 128 2
             132:   10(fvec4)     CompositeConstruct 129 130 131 80
             133:     85(ptr)     AccessChain 75(OutPos) 27
                                  Store 133 132
                                  Branch 109
             134:                 Label
             135:     37(ptr)     AccessChain 9(FaceNormal) 45
             136:    6(float)     Load 135
             137:    6(float)     Load 38(Axis)
             138:    70(bool)     FOrdEqual 136 137
                                  SelectionMerge 140 None
                                  BranchConditional 138 139 140
             139:                   Label
             141:     18(ptr)       AccessChain 76(CoordClip) 22
             142:   10(fvec4)       Load 141
             143:    7(fvec3)       VectorShuffle 142 142 0 1 2
             144:    6(float)       CompositeExtract 143 0
             145:    6(float)       CompositeExtract 143 1
             146:    6(float)       CompositeExtract 143 2
             147:   10(fvec4)       CompositeConstruct 144 145 146 80
             148:     85(ptr)       AccessChain 75(OutPos) 22
                                    Store 148 147
             149:     18(ptr)       AccessChain 76(CoordClip) 17
             150:   10(fvec4)       Load 149
             151:    7(fvec3)       VectorShuffle 150 150 0 1 2
             152:    6(float)       CompositeExtract 151 0
             153:    6(float)       CompositeExtract 151 1
             154:    6(float)       CompositeExtract 151 2
             155:   10(fvec4)       CompositeConstruct 152 153 154 80
             156:     85(ptr)       AccessChain 75(OutPos) 17
                                    Store 156 155
             157:     18(ptr)       AccessChain 76(CoordClip) 27
             158:   10(fvec4)       Load 157
             159:    7(fvec3)       VectorShuffle 158 158 0 1 2
             160:    6(float)       CompositeExtract 159 0
             161:    6(float)       CompositeExtract 159 1
             162:    6(float)       CompositeExtract 159 2
             163:   10(fvec4)       CompositeConstruct 160 161 162 80
             164:     85(ptr)       AccessChain 75(OutPos) 27
                                    Store 164 163
                                    Branch 140
             140:                 Label
                                  Branch 109
             109:               Label
                                Branch 73
              73:             Label
                              Store 166(i) 39
                              Branch 167
             167:             Label
                              LoopMerge 169 170 None
                              Branch 171
             171:             Label
             172:     11(int) Load 166(i)
             173:    70(bool) ULessThan 172 12
                              BranchConditional 173 168 169
             168:               Label
             178:     11(int)   Load 166(i)
             179:     85(ptr)   AccessChain 75(OutPos) 178
             180:   10(fvec4)   Load 179
             182:    181(ptr)   AccessChain 177 22
                                Store 182 180
             184:     11(int)   Load 166(i)
             185:     18(ptr)   AccessChain 15(CoordIn) 184
             186:   10(fvec4)   Load 185
                                Store 183(CoordOut) 186
             189:     11(int)   Load 166(i)
             190:     18(ptr)   AccessChain 188(NormIn) 189
             191:   10(fvec4)   Load 190
                                Store 187(NormOut) 191
             197:     11(int)   Load 166(i)
             199:    198(ptr)   AccessChain 196(TextCoordIn) 197
             200:   50(fvec2)   Load 199
                                Store 193(TextCoordOut) 200
             206:     11(int)   Load 166(i)
             208:    207(ptr)   AccessChain 205(MatIdxIn) 206
             209:     11(int)   Load 208
                                Store 202(MatIdxOut) 209
                                EmitVertex
                                Branch 170
             170:               Label
             210:     11(int)   Load 166(i)
             211:     11(int)   IAdd 210 17
                                Store 166(i) 211
                                Branch 167
             169:             Label
                              EndPrimitive
                              Return
                              FunctionEnd

I don't know why, I get this error, which I don't know how to solve, even though my original shader have no issues.

cdavis5e commented 3 weeks ago

That's because SPIRV-Cross doesn't know how to transpile geometry shaders to HLSL yet. That's what that error means.

TheArheus commented 3 weeks ago

That's because SPIRV-Cross doesn't know how to transpile geometry shaders to HLSL yet. That's what that error means.

I thought geometry shaders are already supported, as it is said in the description

cdavis5e commented 3 weeks ago

I thought geometry shaders are already supported, as it is said in the description

They are, but only for GLSL output. See here.

EDIT: Clarified that geometry shaders are only supported for GLSL output, as opposed to input.

HansKristian-Work commented 3 weeks ago

Yes, HLSL geometry shaders are not supported for output. Same with HLSL tessellation. Given my very limited time to work on SPIRV-Cross these days, I don't see this happening any time soon. Based on how I understand HLSL, it might not be possible to translate SPIR-V to HLSL geometry shaders due to how vertices are emitted.

TheArheus commented 3 weeks ago

Got it, thanks