I have a GPU implementation of Marching Cubes which uses a sequence of 6 GL compute shaders, with each reading from buffers written to by previous shaders, after the appropriate memory barriers. The buffers used in earlier stages hold temporary marker variables, and should be resized to 0 when no longer needed, but not deleted as I'll want them again for later runs.
In some stages, I need to read from a buffer in a shader then deallocate it immediately after the shader completes, before allocating buffers for the next shader stage. My question is how to do this safely. The memory barrier docs talk about ensuring all writes are completed before allowing another shader to read, but say nothing about reads in the first shader.
If I do:
glUseProgram(firstShader);
glDispatchCompute(size,1,1);
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
glNamedBufferData(firstBuffer,0,NULL,GL_DYNAMIC_DRAW);
glNamedBufferData(secondBuffer,1000000,&data,GL_DYNAMIC_DRAW);
glUseProgram(secondShader);
glDispatchCompute(size,1,1);
is firstBuffer
guaranteed not to be resized until firstShader
is done reading from it? If not, how do I make this happen?