r/opengl • u/GreatCircleGames • 3h ago
gl_DrawID as SSBO array index produces incorrect results.
Hey everyone,
I'm working on some OpenGL code that is producing strange results and I'm starting to wonder if it's a driver bug. I'm trying to render line segments with two SSBOs, one containing line parameters (e.g. color, width, base_point) and one containing the points of all the line segments I want to render. I'm trying to do this using glMultiDrawArrays since segments can have a different number of points which I can control with the count parameter. In the shader I use gl_DrawID as an index to get the line parameters and a combination of base_point (from the line parameters) and gl_VertexID as an index to get the segment point.
The problem is that when I hit ~60 draw calls, the output is not what I expect. I'm trying to render a grid using line segments and the first 59 lines are correct but after that the behavior is unpredictable. Sometimes they seem to overlap existing lines or just draw in the incorrect place.
I'm not sure how clear this will be but I've attached screenshots of the RenderDoc output for draw calls 58, 59, and 60. Between 58 and 59 you can see an extra grid line being added at the correct spacing but for draw call 60 the line is in the incorrect place. The weird thing is RenderDoc shows the correct gl_Position for these different draw calls (i.e. the MeshViewer shows the line segment in the correct VS Out location) but the actual output in the framebuffer is not right. I've also tried debugging by using gl_DrawID as an increasing color parameter and everything looks right in RenderDoc.
Additionally, if I switch to using glDrawArraysInstanced and index in the SSBOs using gl_InstanceID, everything works correctly. Note that I would prefer to use a multi draw since instancing requires that each line segment have the same number of points (which is true for this grid but not true for what I want to do generally).
Anyone have any ideas? Anything else I can provide to help debug? I'm wondering if it's a driver bug because this problem only happens on my Linux laptop but works fine on my Windows desktop. Thanks!


