Closed MrBrixican closed 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.
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!
Looks excellent! Great work! Way cleaner than the slapdash solution I had, haha.
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!
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.
FosterDraw_OpenGL
calls a lot of methods to set values that may already be set correctly (glUseProgram
,glBindFramebuffer
,glTexParameteri
,glEnable
, etc).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:glUseProgram
calls inFosterDraw_OpenGL
andFosterShaderSetUniform_OpenGL
are ignored if the shader has already been setglTexParameteri
calls are ignored if the texture has already been set to use those parametersglBindVertexArray(0)
from end and avoid redundantly callingfgl.glBindVertexArray(mesh->id)
There are a few more possible tweaks, but they will require more involved solutions:
glActiveTexture
,glBindTexture
, and possiblyglUniform1iv
calls if textures/slots haven't changed