2

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];
}
Logos King
  • 121
  • 1
  • 6
  • 2
    You already got an answer, but something you might find useful if you have similar questions in future is SPIRV-Cross. It can decompile SPIR-V into relatively readable GLSL. So, if you were to compile that HLSL to SPIR-V, you could then ask SPIRV-Cross to turn it into GLSL to find out the GLSL equivalent. – Andrea Jul 11 '22 at 21:01

1 Answers1

6

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

Sascha Willems
  • 5,280
  • 1
  • 14
  • 21