I’m trying to create a raytracer with OpenGL’s compute shader, but the SSBO that’s supposed to receive the data doesn’t contain anything on my nvidia GPU, but it does on my laptop with an intel iGPU. I’m creating the buffer like this:
ssbo = glGenBuffer();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, 0, (IntPtr)null, GL_DYNAMIC_DRAW);
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, ssbo, 0, 0);
Where data will be assigned later on with this:
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, ssbo, totalSSBOSize, totalSSBOSize + vertexData.Length * sizeof(float));
glBufferSubData(GL_SHADER_STORAGE_BUFFER, totalSSBOSize, vertexData.Length * sizeof(float), vertexData);
totalSSBOSize += vertexData.Length;
The shader itself is called every frame with this code:
glActiveProgram(compProg);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ssbo);
glBindImageTexture(0, texture, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
glDispatchCompute((uint)Math.Ceiling((double)Width / 8), (uint)Math.Ceiling((double)Height / 8), 1);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
the shader is a simple way to test if there’s any values in the buffer, the screen is green if there is, red if there isn’t:
#version 460 core
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout (rgba32f) uniform image2D img;
layout(std430, binding = 0) buffer Data
{
float data[];
};
void main()
{
ivec2 texelCoord = ivec2(gl_GlobalInvocationID.xy);
if (data.length() == 0)
imageStore(img, texelCoord, vec4(1, 0, 0, 1));
else
imageStore(img, texelCoord, vec4(0, 1, 0, 1));
}
The screen is green with my UHD graphics, but red with my GTX 970.