Search code examples
glslvulkanhlslhlsl2glsl

What's the GLSL equivalent of [[vk::binding(0, 0)]] RWStructuredBuffer<int> in a compute shader


I have this HLSL and I want to write the equivalent in GLSL. If it's any use, I'm trying to run this example https://github.com/mcleary/VulkanHpp-Compute-Sample

[[vk::binding(0, 0)]] RWStructuredBuffer<int> InBuffer;
[[vk::binding(1, 0)]] RWStructuredBuffer<int> OutBuffer;

[numthreads(1, 1, 1)]
void Main(uint3 DTid : SV_DispatchThreadID)
{
    OutBuffer[DTid.x] = InBuffer[DTid.x] * InBuffer[DTid.x];
}

Solution

  • The GLSL equivalent should look something like this:

    layout(std430, binding = 0) buffer InBuffer {
        int inBuffer[ ];
    };
    
    layout(std430, binding = 1) buffer OutBuffer {
        int outBuffer[ ];
    };
    
    layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
    void main() 
    {
        outBuffer[gl_GlobalInvocationID.x] = inBuffer[gl_GlobalInvocationID.x] * inBuffer[gl_GlobalInvocationID.x];
    }