Blender V5.0
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  ContextShared

Functions

Draw GPU Context
void DRW_gpu_context_enable_ex (bool)
void DRW_gpu_context_disable_ex (bool restore)
static void drw_gpu_preview_context_enable ()
static void drw_gpu_preview_context_disable ()
void DRW_gpu_context_enable ()
bool DRW_gpu_context_try_enable ()
bool DRW_gpu_context_is_enabled ()
void DRW_gpu_context_disable ()
void DRW_system_gpu_render_context_enable (void *re_system_gpu_context)
void DRW_system_gpu_render_context_disable (void *re_system_gpu_context)
void DRW_blender_gpu_render_context_enable (void *re_gpu_context)
void DRW_blender_gpu_render_context_disable (void *)
void DRW_render_context_enable (Render *render)
void 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 DRW_gpu_context_release ()
void 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 TicketMutexdraw_mutex = nullptr
static TicketMutexsubmission_mutex = nullptr
void DRW_mutexes_init ()
void DRW_mutexes_exit ()
void DRW_lock_start ()
void DRW_lock_end ()
void DRW_submission_start ()
void 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 ContextSharedviewport_context = nullptr
static ContextSharedpreview_context = nullptr
void DRW_gpu_context_create ()
void DRW_gpu_context_destroy ()

Function Documentation

◆ DRW_blender_gpu_render_context_disable()

void DRW_blender_gpu_render_context_disable ( void * re_gpu_context)

Definition at line 280 of file draw_gpu_context.cc.

References GPU_context_active_set(), and GPU_flush().

Referenced by DRW_render_context_disable().

◆ DRW_blender_gpu_render_context_enable()

void DRW_blender_gpu_render_context_enable ( void * re_gpu_context)

◆ DRW_gpu_context_activate()

◆ DRW_gpu_context_create()

void DRW_gpu_context_create ( )

Definition at line 166 of file draw_gpu_context.cc.

References BLI_assert, DRW_mutexes_init(), preview_context, and viewport_context.

Referenced by WM_init_gpu().

◆ DRW_gpu_context_destroy()

void DRW_gpu_context_destroy ( )

◆ DRW_gpu_context_disable()

◆ DRW_gpu_context_disable_ex()

void DRW_gpu_context_disable_ex ( bool restore)

◆ DRW_gpu_context_enable()

◆ DRW_gpu_context_enable_ex()

void DRW_gpu_context_enable_ex ( bool restore)

Never use this. Only for closing blender.

Definition at line 196 of file draw_gpu_context.cc.

References viewport_context.

Referenced by DRW_engine_external_free(), DRW_gpu_context_enable(), DRW_gpu_context_try_enable(), and WM_exit_ex().

◆ DRW_gpu_context_is_enabled()

bool DRW_gpu_context_is_enabled ( )

Returns true if the DRW_gpu_context is enabled on the calling thread.

Definition at line 247 of file draw_gpu_context.cc.

References viewport_context.

Referenced by DRW_engine_external_free().

◆ DRW_gpu_context_release()

◆ DRW_gpu_context_try_enable()

bool DRW_gpu_context_try_enable ( )

Tries to bind the draw GPU context to the active thread. Returns true on success, false if the draw GPU context does not exists.

Definition at line 238 of file draw_gpu_context.cc.

References DRW_gpu_context_enable_ex(), and viewport_context.

Referenced by RE_engines_exit().

◆ drw_gpu_preview_context_disable()

void drw_gpu_preview_context_disable ( )
static

Definition at line 220 of file draw_gpu_context.cc.

References preview_context.

Referenced by DRW_render_context_disable().

◆ drw_gpu_preview_context_enable()

void drw_gpu_preview_context_enable ( )
static

Definition at line 212 of file draw_gpu_context.cc.

References preview_context.

Referenced by DRW_render_context_enable().

◆ DRW_lock_end()

void DRW_lock_end ( )

◆ DRW_lock_start()

◆ DRW_mutexes_exit()

void DRW_mutexes_exit ( )

Definition at line 40 of file draw_gpu_context.cc.

References BLI_ticket_mutex_free(), draw_mutex, and submission_mutex.

Referenced by DRW_gpu_context_destroy().

◆ DRW_mutexes_init()

void DRW_mutexes_init ( )

Definition at line 34 of file draw_gpu_context.cc.

References BLI_ticket_mutex_alloc(), draw_mutex, and submission_mutex.

Referenced by DRW_gpu_context_create().

◆ DRW_render_context_disable()

◆ DRW_render_context_enable()

◆ DRW_submission_end()

◆ DRW_submission_start()

◆ DRW_system_gpu_render_context_disable()

void DRW_system_gpu_render_context_disable ( void * re_system_gpu_context)

Definition at line 266 of file draw_gpu_context.cc.

References DRW_lock_end(), and WM_system_gpu_context_release().

Referenced by DRW_render_context_disable().

◆ DRW_system_gpu_render_context_enable()

void DRW_system_gpu_render_context_enable ( void * re_system_gpu_context)

Variable Documentation

◆ draw_mutex

TicketMutex* draw_mutex = nullptr
static

◆ preview_context

ContextShared* preview_context = nullptr
static

Unique context used by Preview jobs.

Definition at line 164 of file draw_gpu_context.cc.

Referenced by DRW_gpu_context_create(), DRW_gpu_context_destroy(), drw_gpu_preview_context_disable(), and drw_gpu_preview_context_enable().

◆ submission_mutex

TicketMutex* submission_mutex = nullptr
static

◆ viewport_context