gl_DrawID Always Stuck at 0 in glMultiDrawMeshTasksIndirectNV with GL_DRAW_INDIRECT_BUFFER

Hello,

I’ve read a couple posts here about gl_DrawID stuck at 0 when using glMultiDraw* and the classic OpenGL pipeline, but I’m using the mesh shader pipeline and, for the life of me, I can’t figure out why gl_DrawID does not increment.

Problem Details:

  • I am using glMultiDrawMeshTasksIndirectNV to issue multiple mesh tasks for drawing terrain tiles.
  • My setup includes an indirect buffer (GL_DRAW_INDIRECT_BUFFER), and each draw call has a task count and first task that refer to the specific terrain tile (drawable).
  • I have a drawCommand structure (or equivalent), which contains an array of commands that specify the task count and first task for each draw.
  • The command buffer looks something like this per the spec
  • NV_mesh_shader
struct DrawCommand 
{
    uint taskCount;  // Number of task groups
    uint firstTask;  // First task group to execute
};

  • This command buffer is bound to GL_DRAW_INDIRECT_BUFFER.

  • I have a separate SSBO that contains the mesh IDs, so for a terrain of 16 tiles, my ID’s will be 0, 1, 2, 3, …, 14, 15. My intent is to access this in my task shader using gl_DrawID and then access my mesh data for computing LOD, culling, etc.

  • I insert these mesh IDs into a separate SSBO (meshIDBuffer) and bind it alongside the command buffer.

  • The task count (taskCount) for each drawable is 87 (calculated based on the meshlet count and the number of meshlets per task).

  • In my task shader, I access this SSBO to get the mesh ID

layout(std430, binding = 5) readonly buffer meshIDBuffer
{
// For 16 tiles, this will be 0, 1, 2, 3, ..., 14, 15
    uint meshID[];
};
...
    uint idx = gl_DrawID;
    uint tileID = meshID[idx];

    Mesh m = mesh[tileID];

However, gl_DrawID is always 0. Even though I issue multiple draw tasks using glMultiDrawMeshTasksIndirectNV, it seems the draw ID does not change and stays at 0, meaning I cannot correctly access my mesh ID SSBO based on the draw call index.

My rendering call is

glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 6);
// 16 terrain tiles, 8 byte structure for taskCount and firstTask
glMultiDrawMeshTasksIndirectNV(0, 16, 8); 
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);

My Question:

  • Why is gl_DrawID always 0 in my setup? Is there something I’m missing about how gl_DrawID works with glMultiDrawMeshTasksIndirectNV or indirect buffers?
  • Is there a better way to map each task to a specific mesh ID or drawable index in a multi-draw mesh task scenario?
  • I have verified through Nvidia NSight Graphics that all buffer data is present when running the task and mesh shaders.

I would greatly appreciate any help or insights into what might be going wrong or how to work around this limitation.

Thank you in advance!

DC

I don’t know if that is a bug in the driver or intentional, however, I’ll not that the spec for GLSL_NV_mesh_shader and also NV_mesh_shader (in issue #6 near the end of the file) only talk about gl_DrawIDARB - have you tried with that?

Hello,

Yes. I’ve tried both gl_DrawIDARB and gl_DrawID. Both are stuck at 0.

DC