KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
3.05k stars 836 forks source link

Debug layer error for some Built-in Variables in SPV_KHR_shader_ballot/GL_ARB_shader_ballot #1200

Open AndreasReiten opened 6 years ago

AndreasReiten commented 6 years ago

Hello, thanks for maintaining this software! It has worked flawlessly for me until I ran into the following issue while implementing a cross-platform stream compaction algorithm with the extension GL_ARB_shader_ballot: The following shader compiles just fine in using glslangValidator.exe:

#version 450
#extension GL_ARB_gpu_shader_int64 : require
#extension GL_ARB_shader_ballot : require

layout (local_size_x = 128, local_size_y = 1, local_size_z = 1) in;

void main()
{
    uint64_t A = ballotARB(true); // Works
    uint64_t B = gl_SubGroupEqMaskARB; // Works
    uint C = readFirstInvocationARB(0); // Works
    uint D = readInvocationARB(0, 0); // Works
    uint E = gl_SubGroupInvocationARB; // Debug layer error
    uint F = gl_SubGroupSizeARB; // Debug layer error
}

However, at runtime vkCreateShaderModule reports the following error upon consuming the SPIR-V code: _VK_DEBUG_REPORT_ERROR_BITEXT [SC] SPIR-V module not valid: Operand 3 of Decorate requires one of these capabilities: Kernel (5)

The error only appears when using gl_SubGroupInvocationARB or gl_SubGroupSizeARB, and not for the other variables and functions in the extension. The device is created with the extension VK_EXT_shader_subgroup_ballot and with the shaderInt64 device feature.

Relevant system info: Geforce GTX 1070 - latest drivers. glslang is the latest version, and so is the SDK.

Here is the generated SPIR-V code in human readable format:

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

                              Capability Shader
                              Capability Int64
                              Capability SubgroupBallotKHR
                              Extension  "SPV_KHR_shader_ballot"
               1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint GLCompute 4  "main" 21 35 38
                              ExecutionMode 4 LocalSize 128 1 1
                              Source GLSL 450
                              SourceExtension  "GL_ARB_gpu_shader_int64"
                              SourceExtension  "GL_ARB_shader_ballot"
                              Name 4  "main"
                              Name 8  "A"
                              Name 19  "B"
                              Name 21  "gl_SubGroupEqMaskARB"
                              Name 24  "C"
                              Name 29  "D"
                              Name 33  "E"
                              Name 35  "gl_SubGroupInvocationARB"
                              Name 37  "F"
                              Name 38  "gl_SubGroupSizeARB"
                              Decorate 21(gl_SubGroupEqMaskARB) BuiltIn SubgroupEqMaskKHR
                              Decorate 35(gl_SubGroupInvocationARB) BuiltIn SubgroupLocalInvocationId
                              Decorate 38(gl_SubGroupSizeARB) BuiltIn SubgroupSize
                              Decorate 43 BuiltIn WorkgroupSize
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeInt 64 0
               7:             TypePointer Function 6(int)
               9:             TypeBool
              10:     9(bool) ConstantTrue
              11:             TypeInt 32 0
              12:             TypeVector 11(int) 4
              16:             TypeVector 11(int) 2
              20:             TypePointer Input 6(int)
21(gl_SubGroupEqMaskARB):     20(ptr) Variable Input
              23:             TypePointer Function 11(int)
              25:             TypeInt 32 1
              26:     25(int) Constant 0
              30:     11(int) Constant 0
              34:             TypePointer Input 11(int)
35(gl_SubGroupInvocationARB):     34(ptr) Variable Input
38(gl_SubGroupSizeARB):     34(ptr) Variable Input
              40:             TypeVector 11(int) 3
              41:     11(int) Constant 128
              42:     11(int) Constant 1
              43:   40(ivec3) ConstantComposite 41 42 42
         4(main):           2 Function None 3
               5:             Label
            8(A):      7(ptr) Variable Function
           19(B):      7(ptr) Variable Function
           24(C):     23(ptr) Variable Function
           29(D):     23(ptr) Variable Function
           33(E):     23(ptr) Variable Function
           37(F):     23(ptr) Variable Function
              13:   12(ivec4) SubgroupBallotKHR 10
              14:     11(int) CompositeExtract 13 0
              15:     11(int) CompositeExtract 13 1
              17:   16(ivec2) CompositeConstruct 14 15
              18:      6(int) Bitcast 17
                              Store 8(A) 18
              22:      6(int) Load 21(gl_SubGroupEqMaskARB)
                              Store 19(B) 22
              27:     25(int) SubgroupFirstInvocationKHR 26
              28:     11(int) Bitcast 27
                              Store 24(C) 28
              31:     25(int) SubgroupReadInvocationKHR 26 30
              32:     11(int) Bitcast 31
                              Store 29(D) 32
              36:     11(int) Load 35(gl_SubGroupInvocationARB)
                              Store 33(E) 36
              39:     11(int) Load 38(gl_SubGroupSizeARB)
                              Store 37(F) 39
                              Return
                              FunctionEnd
johnkslang commented 6 years ago

Do I understand that glslang worked correctly, but a validation component does not know about the extension? If so, I think that is an issue to file with the validation component.

johnkslang commented 6 years ago

@chrisforbes do you have any insight here?

AndreasReiten commented 6 years ago

It's a bit out of my depth to say if glslang or the validation layer is the offender. Please let me know if you think I should open an issue with KhronosGroup/Vulkan-LoaderAndValidationLayers.