Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: glMultiDrawElements or glPrimitiveRestartindex?

  1. #1
    Member Newbie
    Join Date
    Dec 2010
    Posts
    40

    glMultiDrawElements or glPrimitiveRestartindex?

    From what I understand they are basically the same. The wiki confirmed my impression. So I don't see what the advantages would be of one over the other. Is it just the memory management overhead in glMultiDrawElements? Should I prefer glPrimitiveRestartindex for that reason?
    I actually might prefer glMultiDrawElements. It looks "cleaner"

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Well, consider this: glMultiDrawElements uses a client-side array that specifies offsets into the buffer object for rendering. Primitive restart-based rendering is all done on the GPU. It's entirely possible that multi-draw is done with a loop right on the CPU and therefore doesn't buy you any performance gains you couldn't get yourself.

    Also, primitive restart works in combination with all other rendering methods. There's no glMultiDrawRangeElements, for example, nor is there glMultiDrawElementsInstanced.

  3. #3
    Member Newbie
    Join Date
    Dec 2010
    Posts
    40

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Thanks for the answer

    Quote Originally Posted by Alfonse Reinheart
    Well, consider this: glMultiDrawElements uses a client-side array that specifies offsets into the buffer object for rendering. Primitive restart-based rendering is all done on the GPU. It's entirely possible that multi-draw is done with a loop right on the CPU and therefore doesn't buy you any performance gains you couldn't get yourself.
    Really? Isn't the purpose of methods like this to send a batch to your dedicated hardware? If it is like you say glMultiDrawElements is basically useless. Why would I need something like that?

    Quote Originally Posted by Alfonse Reinheart
    Also, primitive restart works in combination with all other rendering methods. There's no glMultiDrawRangeElements, for example, nor is there glMultiDrawElementsInstanced.
    I'm not sure of what you mean. If I understand correctly I can do both of these with glMultiDrawElements. Do you mean it's easier to do that with glPrimitiveRestartindex?

    EDIT: actually maybe I can't do the instanced part that easily

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,671

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Really? Isn't the purpose of methods like this to send a batch to your dedicated hardware? If it is like you say glMultiDrawElements is basically useless. Why would I need something like that?
    Because, at some point in the past, it sounded like a good idea.

    Also, that doesn't mean that there's a guarantee of zero performance improvement with its use. There are some things that drivers need to do (verify that buffer objects exist and are on the GPU, get their pointers, etc) that would have to be done with multiple repeated calls.

    As with anything else, if performance is important, you should test and see what happens.

    If I understand correctly I can do both of these with glMultiDrawElements.
    Not according to the quick reference card. There are only 3 multi-draw functions: MultiDrawArrays, MultiDrawElements, and MultiDrawElementsBaseVertex.

  5. #5
    Member Newbie
    Join Date
    Dec 2010
    Posts
    40

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Quote Originally Posted by Alfonse Reinheart
    Because, at some point in the past, it sounded like a good idea.

    Also, that doesn't mean that there's a guarantee of zero performance improvement with its use. There are some things that drivers need to do (verify that buffer objects exist and are on the GPU, get their pointers, etc) that would have to be done with multiple repeated calls.

    As with anything else, if performance is important, you should test and see what happens.
    Or I can use glPrimitiveRestartindex
    I could stand some extra memory management, and I'm not even sure about that. But if this is the price I have to pay I'll go straight with primitive restart. At this point I don't see a real advantage in using glMultiDrawElements. Why isn't it deprecated?

    Quote Originally Posted by Alfonse Reinheart
    Not according to the quick reference card. There are only 3 multi-draw functions: MultiDrawArrays, MultiDrawElements, and MultiDrawElementsBaseVertex.
    I know that. I always do my research
    What I mean is that I could get the same result as a hypothetical glMultiDrawRangeElements using glMultiDrawElements, since I can specify my range there. Doing instanced drawing seems a bit more problematic though.

    However, I would say this is now more of academic interest, as glPrimitiveRestartindex seems the way to go.
    I wold just be curious to know why glMultiDrawElements is still in the specification.

  6. #6
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Actually just using GL_TRIANGLES as the primitive type would be what I'd recommend. No need for any special case handling, multiple complex chains of triangles can be grouped together, you can keep the same vertexes in the same order as before, and you still get all the benefits of indexing.

  7. #7
    Member Newbie
    Join Date
    Dec 2010
    Posts
    40

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Quote Originally Posted by mhagain
    Actually just using GL_TRIANGLES as the primitive type would be what I'd recommend. No need for any special case handling, multiple complex chains of triangles can be grouped together, you can keep the same vertexes in the same order as before, and you still get all the benefits of indexing.
    I've seen a few discussions about using triangles or strips. At the end, as far as I understand, the problem is just the maximization of hits in the vertex cache. At the moment I'm favoring strips, but I'll have to look in detail at this issue later. I already have a question I want to ask about that
    Indeed this is a point for triangles. You don't need restarting.

  8. #8
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    This topic is probably exhausted, but I want to add some lines from my personal experience:

    1. glDrawElements using primitive restart is certainly faster than glMultiDrawElements. The reason is not in the execution speed on the GPU (there is a difference of only about several percents), but in the way drivers interpret glMultiDrawElements command. I don't know what exactly happens in drivers, but it seems that they execute glDrawElements in a loop. (I think Alfonse also stated that several years ago, but I can't find that post). The reason I believe this happens is in the fact that I got 400% of speed up in my code when I turned to primitive restart. But that speedup was only in CPU time! GPU time almost stays the same. So, restart primitives may unload your CPU, but would not make your drawing faster. Please, don't misunderstand what I said; unloading CPU is a very useful effect of primitive restart approach.

    2. Although indexing enables more flexible use of GL_TRIANGLES primitive, GL_TRIANGLE_STRIPS are not for the recycle bin yet. For many regular structures (like regular grids), GL_TRIANGLE_STRIPS enables more compact index buffers. For example, for NxN regular grid
    - GL_TRIANGLES requires 3*2*(N-1)*(N-1) = 6(N^2-2N+1) = 6N^2 indices
    - GL_TRIANGLE_STRIPS requires 2*N*(N-1) = 2N^2-2N = 2N^2 indices
    - GL_TRIANGLE_STRIPS with cache optimization proposed by Ignacio Castaño requires 2N^2 – 2N + floor(N/(cacheSize-1))*2N vertices
    It would be interesting to discuss about the efficiency of vertex post-transform cache, but on the first glance it seems that new cards are less sensitive to this optimization (I need to carry out some experiments in order to prove or reject this statement/premise). But the point is that STRIPS consumes about three times less memory space for the regular grid representation comparing to triangles.

  9. #9
    Member Newbie
    Join Date
    Dec 2010
    Posts
    40

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    Quote Originally Posted by Aleksandar
    This topic is probably exhausted, but I want to add some lines from my personal experience:

    1. glDrawElements using primitive restart is certainly faster than glMultiDrawElements. The reason is not in the execution speed on the GPU (there is a difference of only about several percents), but in the way drivers interpret glMultiDrawElements command. I don't know what exactly happens in drivers, but it seems that they execute glDrawElements in a loop. (I think Alfonse also stated that several years ago, but I can't find that post). The reason I believe this happens is in the fact that I got 400% of speed up in my code when I turned to primitive restart. But that speedup was only in CPU time! GPU time almost stays the same. So, restart primitives may unload your CPU, but would not make your drawing faster. Please, don't misunderstand what I said; unloading CPU is a very useful effect of primitive restart approach.

    2. Although indexing enables more flexible use of GL_TRIANGLES primitive, GL_TRIANGLE_STRIPS are not for the recycle bin yet. For many regular structures (like regular grids), GL_TRIANGLE_STRIPS enables more compact index buffers. For example, for NxN regular grid
    - GL_TRIANGLES requires 3*2*(N-1)*(N-1) = 6(N^2-2N+1) = 6N^2 indices
    - GL_TRIANGLE_STRIPS requires 2*N*(N-1) = 2N^2-2N = 2N^2 indices
    - GL_TRIANGLE_STRIPS with cache optimization proposed by Ignacio Castaño requires 2N^2 – 2N + floor(N/(cacheSize-1))*2N vertices
    It would be interesting to discuss about the efficiency of vertex post-transform cache, but on the first glance it seems that new cards are less sensitive to this optimization (I need to carry out some experiments in order to prove or reject this statement/premise). But the point is that STRIPS consumes about three times less memory space for the regular grid representation comparing to triangles.
    Obviously the topic wasn't really exhausted

    Both points are interesting, but I find the second one especially interesting, for the simple reason that I have never heard of this strips with cache optimization. I did know the name of Ignacio Castano though. I believe he wrote some stripifying code.
    My first thought is that indeed strips are more convenient, because you need less data. It's the reason why I use them. However, I found this thread, where there are some points in favor of triangles. I still have to clearly understand what it says though.
    For what I see the point is basically the maximization of the cache. It would be ideal to know the capabilities of your cache, so you can optimize your strips/triangles based on the hardware you have. But I'm afraid it's not so easy.
    Another point is that you might have to do the stripification every time before the rendering, overloading the CPU, but this is not necessary if you have a fixed set of objects. In that case you need to do that only once, maybe even offline.

    The first point is for me a useful confirmation that multidraw has to go into the trashcan. Utterly useless method.

  10. #10
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: glMultiDrawElements or glPrimitiveRestartindex?

    I missed that thread.
    Now it is several months old so I'll not add new comments.

    mhagain little bit overemphasizes influence of vertex post-transform cache taking into account vertices only. Currently I'm trying totally to remove vertex attributes from my renderings. In that case indices are the only data that is streamed to the GPU (along with textures). Having three times less data is significant in that case. When reading the thread that you've quoted carefully read what Daniel (aqnuep) and Dark Photon said.

    You can read more about Ignacio's method here: Optimal Grid rendering But I get almost the same rendering speed with simple primitive restart. That's why I said that I have to carry out more experiments. Vertex shaders I used were pretty simple.

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2014, 03:12 PM
  2. glMultiDrawElements
    By holyll in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-16-2013, 04:46 AM
  3. glPrimitiveRestartIndex()
    By debinair in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 06-28-2012, 02:41 PM
  4. glPrimitiveRestartIndex()
    By debinair in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 06-27-2012, 06:20 AM
  5. glMultiDrawElements + VBO
    By Alessandro_dup1 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-13-2012, 10:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean