google / shaderc

A collection of tools, libraries, and tests for Vulkan shader compilation.
Other
1.82k stars 353 forks source link

shaderc internal error using atomics on an inout function parameter #1063

Open kyren opened 4 years ago

kyren commented 4 years ago

Hey, I have the following glsl function:

bool add_particle(inout ParticleBufferHeader header, out uint index) {
    index = atomicAdd(header.count, 1);
    if (index >= header.capacity) {
        return false;
    } else {
        atomicMax(
            header.update_workgroups,
            1 + index / PARTICLE_UPDATE_LOCAL_SIZE
        );
        return true;
    }
}

that causes this error in shaderc:

shaderc: internal error: compilation succeeded but failed to optimize: AtomicIAdd: Function storage class forbidden when the Shader capability is declared.
  %74 = OpAtomicIAdd %uint %71 %uint_1 %uint_0 %uint_1

only when compiling with optimization. I'm not sure whether this is legal in glsl or not, if I change this function to a macro and call it directly on the SSBO field then the error disappears, this is only when trying to call atomics on an inout parameter.

I'm using shaderc through rust through the shaderc-rs crate, so I believe the version here of shaderc is 06b6db68ff7e20d4f097a132dd56a1c6482e8c25. I'm sorry this isn't a more isolated example, if necessary I can make one available.

zoddicus commented 4 years ago

@dneto0 can you take a look at this?

devshgraphicsprogramming commented 4 years ago

we hit a similar issue recently but we use SPIR-V Cross and OpenGL as the backend so it was two bugs on top of each other