FosterFramework / Foster

A small C# game framework
MIT License
435 stars 38 forks source link

Room for more render performance #33

Closed MrBrixican closed 10 months ago

MrBrixican commented 10 months ago

There is room for much more performance in respect to degenerate and standard cases where Graphics.Submit must be called frequently:

The main detractor from performance in those scenarios is redundant calls to OpenGL methods.

Luckily, most redundant calls are pretty simple to catch, as we can just keep track of what we set/used previously and ignore the call if the same parameters will be used. This method was used in the original Foster to great effect.

I have personally tested this and received a 4x speedup in the Froggymark sample (using built in Batcher) when drawing alternating textures (causing a draw call each). I (very roughly) implemented the following adjustments:

There are a few more possible tweaks, but they will require more involved solutions:

NoelFB commented 10 months ago

This all sounds good to me. I think at some point I had them check for some these more often but removed it because I assumed drivers would just not do redundant work. But yeah, I agree it's better to just check since, as you've pointed out, not all are nice about it haha.

If you've already made changes to the rendering in the C library I'd be happy to merge that in. I can look into the texture/uniform binding as well.

NoelFB commented 10 months ago

I've pushed changes that handle most of these, with the exception of uniforms/texture binding. I'll look into those more later; might make a new PR for it. But the majority of cases should now be resolved!

MrBrixican commented 10 months ago

Looks excellent! Great work! Way cleaner than the slapdash solution I had, haha.

NoelFB commented 10 months ago

Alright I've got improved a lot of glActiveTexture/glBindTexture/updating Sampler states now. The only thing that could potentially also be improved is caching Shader Uniform values but I think it's not worth the trouble, or should maybe happen from the C# side.

https://github.com/NoelFB/Foster/commit/36088f6be8db594d439d7e5f049ac748662cdfac

Will close this!