KhronosGroup / glslang

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

missing error message for atomicAdd on non-global storage #2735

Open roenyroeny opened 3 years ago

roenyroeny commented 3 years ago

The following piece of code produces invalid spirv calling atomicAdd(dst, 1); directly from main instead of from foo works as intended

#version 460
#extension GL_EXT_shader_explicit_arithmetic_types : require

layout(binding = 0) buffer myStorageBuffer { uint dst; };
void foo(inout uint a)
{
    atomicAdd(a, 1);
}
void main()
{
    foo(dst);
    // atomicAdd(dst, 1); // 
}

checking the spirv using spirv-val produces the following output

$ spirv-val.exe comp.spv
error: line 47: AtomicIAdd: Function storage class forbidden when the Shader capability is declared.
  %14 = OpAtomicIAdd %uint %a %uint_1 %uint_0 %uint_1

I'm not entirely sure if taking a reference to a buffer member is legal, but i suppose it shouldn't produce invalid spirv :)

greg-lunarg commented 3 years ago

Actually, GLSL function arguments are NOT by reference, but value-return ie copy to/from local memory. The atomicAdd in foo should therefore cause a compilation error, given the following text from the GLSL spec: Atomic memory functions perform atomic operations on an individual signed or unsigned integer stored in buffer object or shared variable storage.

So glslangValidator is missing a compilation error for this case.

If someone wishes to submit a fix, please contact me before you start coding.