View Full Version : glMultiDrawElementsIndirect() problems

04-18-2015, 07:56 AM

I am having trouble tracking down an issue with glMultiDrawElementsIndirect() on a Radeon 5870 on Windows (tested with a few versions of the most recent drivers). It seems to work fine on an Intel HD4000 and an nVidia GTX680. I have no errors from the debug output extension.

The strange thing is if I execute the equivalent draw calls individually with glDrawElementsInstancedBaseVertexBaseInstance() or even glMultiDrawElementsIndirect() it works fine. However when batched into a single glMultiDrawElementsIndirect() of not more than 36 draws, and I randomly get draws seemingly dropping out of existence on the Radeon 5870.

It seems like a driver bug but I have written a different program using similar drawing methods before that works fine and I am struggling to pinpoint the difference.

I have tried persistently mapped buffers and per frame mapped ones (which very rarely sometimes seem to fail for unknown reasons with an invalid range specified even though I am 100% sure I locked the whole buffer at a correct size). I have also experienced complete system hangs when glMultiDrawElementsIndirect() is given zero things to draw.

One important thing I am doing is adjusting firstIndex and baseVertexIndex depending on visibility for multiple objects packed in a large index/vertex buffer that the draws pull from.

I also have a second vertex buffer for per instance data ie:

glVertexAttribIPointer(2, 4, GL_INT, 0, 0);
glVertexAttribDivisor(2, 1);

The sizes of my used buffers are currently:

TextureArraySize: 128 MB
DrawCommandBufferSize: 5 KB
InstanceDataBufferSize: 4 KB
VertexBufferSize: 19 MB
IndexBufferSize: 11 MB

Right now I can only think there is possibly some alignment between the objects packed in the index/vertex buffers I am not respecting that the AMD card doesn't like in a multiple draw or something else weird. I have double checked my structs for draw commands etc are all the right size and #pragma(pack,1) etc stuff to make sure no strange padding is happening.

Has anyone encountered similar problems or any suggestions of what this could be if it isn't a driver bug?



I found the cause - it seems AMD doesn't like a zero count of elements in the indirect draw structs for some reason? If I remove said null elements its all fine. But that's a bit worrying if I want to eventually generate those draws on the GPU instead of CPU...