From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

GPU API Safety Checks

WITH_GPU_SAFETY

Building Blender with the WITH_GPU_SAFETY option turned on will enable a lot of extra checks which help to ensure that the graphics API is being used correctly.

No GPU_SAFETY check should ever fail!

For that reason it is preferable that the WITH_ASSERT_ABORT option is also enabled. Since this will trigger a break point and allow the state of Blender to be preserved enough that the reason for the failure can be determined.

Macros

Header File: GPU_safety.h

The GPU_SAFETY macro is defined to either 0 or 1 depending on if WITH_GPU_SAFETY is defined.

The GPU_ASSERT(pred) macro will abort the program if pred is false. The pred will never be executed if WITH_GPU_SAFETY is disabled so do not place code that always needs to execute inside of GPU_ASSERT.

GPU_ABORT() will unconditionally abort Blender if execution reaches it and WITH_GPU_SAFETY is enabled.

The GPU_CHECK_NO_ERROR() is strategically placed throughout the code to make sure that there are no unchecked OpenGL errors. Code that directly calls OpenGL should have a GPU_CHECK_NO_ERROR() before and after those calls. However, there is no need to check every single OpenGL call (at that would be both tedious and make reading the code difficult). The goal is that any misuse of the OpenGL API will be cause immediately and close to where the error occurred. OpenGL errors are almost all caused by misuse of the API (akin to a syntax error) and not by runtime problems (such as an out of memory error).

GPU_CHECK(expr) is equivalent to putting GPU_CHECK_NO_ERROR() before and after a function. Unlike GPU_ASSERT() the expr will not disappear in non-debug builds.