PDA

View Full Version : Group draws by least changes in programs, states, program inputs etc



Gessos Paul
01-28-2017, 03:04 AM
I am implementing my own glsl-friendly 3d model format specification.
In implementation (not specification), all meshes and skins, are break into draws.
Every draw has:
- glDrawElements/glDrawArrays parameters.
- Material (glsl program, gl states, glAttribPointers, glAttrib, glUniform, buffers etc.)

I am trying to sort FAST these draws, so from N-th draw go to N+1-th draw as efficient I can.
So, I sort draws by material with this order:
- Same GLSL program from one draw to another
- Least size of glAttrib*, glUniform* data send from one draw to another
- Least gl state changes from one draw to another
- Least buffer changes from one draw to another

Of course is platform dependent and super-bulky, but can anyone assume, that whole this thing has meaning at all?
If yes, the order of non-efficient changes, is correct?

Silence
01-28-2017, 04:24 AM
As a general rule, the less you'll call OpenGL, the less you will change GL states, the more efficient you can be.
But some calls are likely to cost more than others. For example, switching from one shader to another will take far more time than sending an uniform value to the GPU. There was a known table from nvidia about this, but unfortunately I can't find it again...
But I found some links that might be useful for you (the latter is a bit old however):

http://www.nvidia.fr/object/doc_performance.html

https://www.nvidia.com/docs/IO/8228/BatchBatchBatch.pdf

You should also keep in mind that you might have the best practice code and still have something slow. This depends a lot on how you can sort and remove invisible geometry prior to sending them to the GPU.

Spoops
01-30-2017, 11:30 AM
Beyond Porting by Cass Everitt covers costs of state changes and resource bindings : 2335

Full slides here (http://www.slideshare.net/CassEveritt/beyond-porting).

Silence
01-31-2017, 04:52 AM
Beyond Porting by Cass Everitt covers costs of state changes and resource bindings : 2335

Full slides here (http://www.slideshare.net/CassEveritt/beyond-porting).

Thanks for the link !