Blender V5.3
draw_gpu_context.cc File Reference
#include "BKE_global.hh"
#include "GPU_capabilities.hh"
#include "GPU_context.hh"
#include "GPU_state.hh"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "DRW_engine.hh"
#include "DRW_render.hh"
#include "WM_api.hh"
#include "wm_window.hh"

Go to the source code of this file.

Classes

class  blender::ContextShared

Namespaces

namespace  blender
 BMesh Iterators.

Functions

Draw GPU Context
void blender::DRW_gpu_context_enable_ex (bool restore)
void blender::DRW_gpu_context_disable_ex (bool restore)
static void blender::drw_gpu_preview_context_enable ()
static void blender::drw_gpu_preview_context_disable ()
void blender::DRW_gpu_context_enable ()
bool blender::DRW_gpu_context_try_enable ()
bool blender::DRW_gpu_context_is_enabled ()
void blender::DRW_gpu_context_disable ()
void blender::DRW_system_gpu_render_context_enable (GHOST_IContext *re_system_gpu_context)
void blender::DRW_system_gpu_render_context_disable (GHOST_IContext *re_system_gpu_context)
void blender::DRW_blender_gpu_render_context_enable (void *re_gpu_context)
void blender::DRW_blender_gpu_render_context_disable (void *re_gpu_context)
void blender::DRW_render_context_enable (Render *render)
void blender::DRW_render_context_disable (Render *render)
Draw manager context release/activation

These functions are used in cases when an GPU context creation is needed during the draw. This happens, for example, when an external engine needs to create its own GPU context from the engine initialization.

Example of context creation:

const bool drw_state = DRW_gpu_context_release(); viewport_system_gpu_context = WM_system_gpu_context_create(); DRW_gpu_context_activate(drw_state);

Example of context destruction:

const bool drw_state = DRW_gpu_context_release(); WM_system_gpu_context_activate(viewport_system_gpu_context); WM_system_gpu_context_dispose(viewport_system_gpu_context); DRW_gpu_context_activate(drw_state);

NOTE: Will only perform context modification when on main thread. This way these functions can be used in an engine without check on whether it is a draw manager which manages GPU context on the current thread. The downside of this is that if the engine performs GPU creation from a non-main thread, that thread is supposed to not have GPU context ever bound by Blender.

bool blender::DRW_gpu_context_release ()
void blender::DRW_gpu_context_activate (bool drw_state)

Submission critical section

The usage of gpu::Shader objects is currently not thread safe. Since they are shared resources between render engine instances, we cannot allow pass submissions in a concurrent manner.

static TicketMutex * blender::draw_mutex = nullptr
static TicketMutex * blender::submission_mutex = nullptr
void blender::DRW_mutexes_init ()
void blender::DRW_mutexes_exit ()
void blender::DRW_lock_start ()
void blender::DRW_lock_end ()
void blender::DRW_submission_start ()
void blender::DRW_submission_end ()

GPU & System Context

A global GPUContext is used for rendering every viewports (even on different windows). This is because some resources cannot be shared between contexts (GPUFramebuffers, GPUBatch).

static ContextShared * blender::viewport_context = nullptr
static ContextShared * blender::preview_context = nullptr
void blender::DRW_gpu_context_create ()
void blender::DRW_gpu_context_destroy ()