Massive sequential writing to SSBO from loop causes a driver exeption

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

I have made a simple project to reproduce this behaviour - https://github.com/DrCorvax/SSBOfault

The problem was in Timeout detection and recovery (TDR). By default Windows force GPU driver recovery if shader runs more than 2 seconds. After increasing the timeout, the program was able to finish correctly.

1 Like

Hi there @drcorvax!

Issue posted, debugged and solved before anyone could welcome you here! Amazing!

Thank you for updating with the solution and belated welcome to the NVIDIA developer forums!

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