First of all I don’t really have any major experience with OpenGl so I might have done some real rookie mistakes.
I’m currently working on a project where I need to send 3 groups of around 100,000 vec3 down to the compute shader. To begin with I’ve limited myself to passing one of these groups and later adding in the other two when the first is working. However I’m having no luck thus far.
First attempt was to simply state “uniform vec3[100000] positions”. While this gave no errors it did result in a linking time of 8 minutes give or take. Not a viable option and I’m not sure why I don’t get any errors but that’s another matter.
Second attempt was to use Shader Storage Buffer Objects. This is where I am now but I am unable to get this to work.
Setup is as follows:
void Renderer::setBuffer(char* name, std::vector<vec3f>* data){
GLuint buffHandle;
glGenBuffers(1, &buffHandle);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffHandle);
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, buffHandle, 0, sizeof(vec3f)*100000);
glBufferData(GL_SHADER_STORAGE_BUFFER, data->size()*sizeof(vec3f), data, GL_STATIC_READ);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
data->setHandle(buffHandle);
}
Then when running the compute shader I do the following:
void Renderer::compute(ShaderProgram* sp, GLuint buffer){
GL_CHECK_ERRORS();
auto handle = (GLShaderProgramHandle_t *) sp->getHandle();
auto programId = handle->sp_id;
glUseProgram(programId);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
glShaderStorageBlockBinding(programId, 0, 0);
glDispatchCompute(512/16, 512/16, 1);
GL_CHECK_ERRORS();
}
And the shader storage block in the shader looks as follows:
layout(std430, binding = 0) buffer list
{
vec3 pos[];
};
I am only calling set buffer once (during the init section of my program).
When I read from pos[] the only information I’m getting is pure 1’s (0xFFFFFFFF…) it seems. I’m assuming this is some standard response when the buffer isn’t setup correctly.