View Full Version : Problem with GL_SHADER_STORAGE_BUFFER

Crazy Sage
02-06-2017, 04:32 AM
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;


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(QVecto r2D));

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);

QVector2D* data = (QVector2D*)output_buffer.map(QOpenGLBuffer::ReadO nly);