Shader-Program Batching
I added support for multi-material meshes a while back. These meshes are partitioned into slices for each of which a separate material and draw call is used.
I recently added a partially transparent material. This makes rendering order necessary to consider. My solution for correcting rendering order is to assign draw-orders to each material.
Until this point, I was iterating over the collection of multi-material meshes and rendering all the slices for each mesh. But to respect material draw order, I now collect the slices from each multi-material mesh into bins associated with their materials before sorting the bins according to their material draw order and finally rendering the slices in each bin.
When I say material I pretty-much mean an opengl shader program. Here's a chart from an nvidia powerpoint showing that changing shader programs is one of the more expensive state changes in opengl.
This new rendering technique of binning according to material and then rendering prevents most shader program changes, so I figured I should benchmark the change and see how much better things get.
It turns out, there was a pretty solid performance gain of about 1ms in debug and 0.5ms in release!
I am not totally confident that the improvement can be attributed directly to opengl api usage. I would expect the GPU performance to be about the same in debug and release, so I am not sure why there is such a gain between the debug and release builds. Oh well.


Comments
Post a Comment