glslvulkanspir-v

error: 'subgroup op' : requires SPIR-V 1.3


I am compiling a GLSL file to SPIR-V using the command:

C:/VulkanSDK/1.2.148.1/Bin/glslc C:/Users/jonat/Projects/sum.comp -o C:/Users/jonat/Projects/sum.spv

Getting the error:

error: 'subgroup op' : requires SPIR-V 1.3

The error occurs on lines 32 and 45, which are both sum = subgroupAdd(sum);

The full GLSL code:

#version 450
#extension GL_KHR_shader_subgroup_arithmetic : enable

layout(std430, binding = 0) buffer Input
{
   float inputs[];
};

layout(std430, binding = 1) buffer Output
{
   float outputs[];
};

layout (local_size_x_id = 1) in;
layout (constant_id = 2) const int sumSubGroupSize = 64;

layout(push_constant) uniform PushConsts
{
  int n;
} consts;

shared float sdata[sumSubGroupSize];

void main()
{
    float sum = 0.0;
    if (gl_GlobalInvocationID.x < consts.n)
    {
        sum = inputs[gl_GlobalInvocationID.x];
    }

    sum = subgroupAdd(sum);

    if (gl_SubgroupInvocationID == 0)
    {
        sdata[gl_SubgroupID] = sum;
    }

    memoryBarrierShared();
    barrier();

    if (gl_SubgroupID == 0)
    {
        sum = gl_SubgroupInvocationID < gl_NumSubgroups ? sdata[gl_SubgroupInvocationID] : 0;
        sum = subgroupAdd(sum);
    }

    if (gl_LocalInvocationID.x == 0)
    {
        outputs[gl_WorkGroupID.x] = sum;
    }
}

I have got the latest version of VulkanSDK.


Solution

  • Looks like you need --target-env=vulkan1.1 for glslc to emit SPIR-V 1.3:

    4.2.6. --target-env=

    ...

    Generated code uses SPIR-V 1.0, except for code compiled for Vulkan 1.1, which uses SPIR-V 1.3, and code compiled for Vulkan 1.5, which uses SPIR-V 1.5.

    If this option is not specified, a default of vulkan1.0 is used.