flibitijibibo/MonoGame — pull request #125 by sulix (2013-12-02 13:17:41+00:00)
Title: Give the GL driver some more info to optimize buffer uploads

Codename RobotnikNo (on Intel/Mesa at least) triggers a number of performance warnings about buffers still being in-use when glBufferSubData is called, requiring the driver to create a temp. buffer to store the contents and later blit that into the right part of the original buffer when it's no longer in use.

These patches try (not entirely successfully) to alleviate the problem by using glDrawRangeElements instead of glDrawElements to hint to the driver what parts of the buffer are in use. They also use the *BaseVertex variants of the draw calls to let the driver optimize that if possible.

It turns out this doesn't increase performance noticeably on my machine (largely because there's a huge performance issue with Parallel.ForEach<> which is overshadowing any benefit one could get from these smaller improvements), and it does require the GL_EXT_draw_range_elements and GL_ARB_draw_elements_base_vertex extensions. I don't think this is a big deal (Mesa has supported them since forever, and I doubt anything that can do instancing won't have them), but I understand if you'd rather not take the chance. I'd write fallbacks, but OpenTK's GL bindings give me a headache.

Tried it with both RobotnikNo and Naddachance, no rendering issues or performance regressions.

— David