Help with Bindless Graphics

I’ve got a bug with a CUDA particle system that I’ve written. The particle system reads and writes particles to a gpu buffer. gl passes the address of the gpu buffer as a uniform to the vertex shader as an array of floats and the vertex shader indexes into the array using gl_InstanceID.

What’s happening is that the array as far as the shader is concerned is just zeros. I expect it to have the values generated from cuda.

Anyway I anticipate spending today trying to figure out what I’ve done wrong and thought I’d just ask what is the state of the art/ what what I should be doing. If it matters, I only care about 1070/Pascal on Win32 at the moment.

Here are some broad questions about bindless graphics.

  1. Do I need to bind the gpu-pointer-uniform for every draw call? I thought I didn’t, but then if I look at BindlessApp.cpp, it resets the GPU pointer for every draw! Is this necessary?

  2. Should I be using GL_UNIFORM_BUFFER or GL_SHADER_STORAGE_BUFFER as the buffer type?

  3. Do I need to call glMakeBufferResident for every draw call? I don’t know what the rules are.

  4. Do I have to make any memory fence calls between CUDA and GL?

I figured out my bug.

What I found was that I needed to call cudaGraphicsGLRegisterBuffer before calling glMakeBufferResidentNV and glGetBufferParameterui64vNV when creating the SSBO.

This makes a difference in the address of the pointer returned and more importantly makes the interop actually work between opengl and CUDA.

After I fixed that, then regarding my 4 questions the answer appears to be:

  1. No I don’t need to rebind the pointer for every draw
  2. it doesn’t matter if GL_UNIFORM or GL_SHADER_STORAGE is used
  3. No, I don’t need to call GLMakeBufferResident
  4. I don’t know about the memory fence thing. I thought I picked the idea up from an article Mike Bailey wrote about particle systems using opencl (http://blogs.evergreen.edu/vistas/files/2013/03/bailey-g3vis-proof4.pdf) but I can’t see the reference at the moment.