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

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

我正在使用以下命令将 GLSL 文件编译为 SPIR-V:

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

出现错误:

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

错误出现在第32行和第45行,都是sum = subgroupAdd(sum);

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;
    }
}

我有最新版本的VulkanSDK。

看起来你需要 --target-env=vulkan1.1 glslc 才能发出 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.