Writing to SSBO from computer shader for-loop causes driver exception. The shader to reproduce is
#version 430 core
layout ( local_size_x = 1, local_size_y = 1, local_size_z = 1 ) in;
layout ( std430, binding = 0 ) buffer Output
{
uint value;
};
void main ()
{
for ( uint i = 0u; i < 130700001u; ++i )
{
value = i;
}
}
The shader compiles and links without errors. Shader is started with glDispatchCompute(1, 1, 1)
and followed with glMemoryBarrier (GL_ALL_BARRIER_BITS)
. SSBO creation, binding and readback is trivial and works fine for small loop counter value. But it crashes with huge repetiiton count. I’ve got an exeption not in glDispatchCompute but during next call for any OpenGL function. On my PC with 3060RTX the magic number is 130’700’001. With 130’700’000 repetitions all is OK.
As I can see from shader compilation binary output the shader code is same for all cases and looks like this
NVcp5.0
OPTION NV_internal;
OPTION NV_shader_storage_buffer;
OPTION NV_bindless_texture;
GROUP_SIZE 1;
STORAGE sbo_buf0[] = { program.storage[0] };
TEMP R0;
TEMP T;
MOV.U R0.x, {0, 0, 0, 0};
REP.S {130700001, 0, 0, 0};
STB.U32 R0, sbo_buf0[0];
ADD.U R0.x, R0, {1, 0, 0, 0};
ENDREP;
END