Page MenuHome

BGL deprecation
Confirmed, NormalPublic

Description

For 2.91 we refactored the whole GPU module to be ready for vulkan. In this process we added a state tracking mechanism which removes unneeded state changes by only pushing the state before drawing commands.

The issue is that BGL does not make use of this and directly use the GL API which can lead to unsafe
states.

The current workaround is to push the state to the GL before the callbacks loop starts and just force reset all states after the loop (see rBfe5efccd8fb6ce2a7e5e858e3f8becf5f98bb087).

This is quite ugly since it does not prevent misusage of the BGL API with the pyGPU API (which is using our GPU module states).

So we have things to do here:

  • Polish the pyGPU API and force its usage everywhere: Impractical for 2.91 because there would be no transition period. But we do need to get started already since the API did change a little (see GPUOffscreen). A refactor is in the process here D8826. This is the long term plan.
  • Make wrappers inside the BGL module to make the GPUState undefined if calling a function that modifies it: This would trigger a special path inside gl_state.cc where the state would be ignored. This should fix some of the API mixing issues.
  • But we also need to push the state for commands that need it (like glClear, glDrawArray, glReadPixels, ...).
  • The last remaining issue is our resource binding check that needs to be disable because incompatible with the glUniform + glBindTexture idiom (we now use internal fixed binding points).

We still have to figure how to mitigate:

  • Current framebuffer state: calling glBindFramebuffer(GL_FRAMEBUFFER, id) will break the state tracking.
  • Current bound program state: calling glUseProgam(program) will break the state tracking.
  • ... (any other?)

Other issues with pyGPU:

  • There are still functions to get the raw GL handle for some object (Shader/Texture). Deprecate them.
  • GPUOffscreen / GPUFramebuffer now always store/resets their own Viewport/Scissor bounds. Document the API change.