Render sort order should consider shared shaders to minimize switching #9164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
painterSortStable
function sorts objects to be rendered by material to minimize switching between materials. However, it doesn't consider that now different materials can share a common shader program. The result is that the renderer may be switching out shader programs more often than necessary.I put together a rough benchmark to test this patch. Here is one using the existing code:
http://output.jsbin.com/tuneso
And here is one using the patched code:
http://output.jsbin.com/nogovi
In Chrome on my Late 2013 MacBook Pro, with 10,000 objects, I'm seeing ~4 fps unpatched and ~13 fps patched. On my new PC w/ GeForce 980, I get ~26 fps vs ~38 fps. Please adjust the object count on your system accordingly.
This is related to #8849.