Problem with GL_SHADER_STORAGE_BUFFER

I’m writing ray-tracing on OGL computing shaders, to pass data to and from shaders I use buffers.

When size of vec2 output buffer (which is equal to number of rays multiplied by number of faces) reaches ~30Mb attempt of mapping buffer is stable returning NULL pointer. Range mapping also fails.

It seems strange, because MAX_SHADER_STORAGE_BLOCK_SIZE value is around 2Gb, and I don’t see if I do something wrong, according to tutorials.
What may cause such behavior and how it can be avoided?

Data declaration in shader:

#version 450
layout(std430, binding=0) buffer rays{
    vec4 r[];
};
layout(std430, binding=1) buffer faces{
    vec4 f[];
};
layout(std430, binding=2) buffer outputs{
    vec2 o[];
};
uniform int face_count;
uniform vec4 origin;

Calling code (using some Qt5 wrappers):

QOpenGLBuffer ray_buffer;
QOpenGLBuffer face_buffer;
QOpenGLBuffer output_buffer;

QVector<QVector2D> output;

output.resize(rays[r].size()*faces.size());

if(!ray_buffer.create()) { /*...*/ }
if(!ray_buffer.bind()) { /*...*/ }
ray_buffer.allocate(rays.data(), rays.size()*sizeof(QVector4D));

if(!face_buffer.create()) { /*...*/ }
if(!face_buffer.bind()) { /*...*/ }
face_buffer.allocate(faces.data(), faces.size()*sizeof(QVector4D));

if(!output_buffer.create()) { /*...*/ }
if(!output_buffer.bind()) { /*...*/ }

output_buffer.allocate(output.size()*sizeof(QVector2D));

ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ray_buffer.bufferId());
ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, face_buffer.bufferId());
ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, output_buffer.bufferId());

int face_count = faces.size();

compute.setUniformValue("face_count", face_count);
compute.setUniformValue("origin", pos);

ogl->glDispatchCompute(rays.size()/256, faces.size(), 1);

ray_buffer.destroy();
face_buffer.destroy();
QVector2D* data = (QVector2D*)output_buffer.map(QOpenGLBuffer::ReadOnly);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.