Blender V4.3
gpu_context.cc File Reference
#include "GHOST_C-api.h"
#include "BKE_global.hh"
#include "BLI_assert.h"
#include "BLI_utildefines.h"
#include "BLI_vector_set.hh"
#include "GPU_context.hh"
#include "GPU_framebuffer.hh"
#include "GPU_batch.hh"
#include "gpu_backend.hh"
#include "gpu_context_private.hh"
#include "gpu_matrix_private.hh"
#include "gpu_private.hh"
#include "gpu_shader_private.hh"
#include "dummy_backend.hh"
#include <mutex>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  blender
 
namespace  blender::gpu
 

Functions

GPUContextGPU_context_create (void *ghost_window, void *ghost_context)
 
void GPU_context_discard (GPUContext *ctx_)
 
void GPU_context_active_set (GPUContext *ctx_)
 
GPUContextGPU_context_active_get ()
 
void GPU_context_begin_frame (GPUContext *ctx)
 
void GPU_context_end_frame (GPUContext *ctx)
 
GPU Begin/end work blocks

Used to explicitly define a per-frame block within which GPU work will happen. Used for global autoreleasepool flushing in Metal

void GPU_render_begin ()
 
void GPU_render_end ()
 
void GPU_render_step ()
 

Variables

static thread_local Contextactive_ctx = nullptr
 
static std::mutex backend_users_mutex
 
static int num_backend_users = 0
 

Main context global mutex

Used to avoid crash on some old drivers.

static std::mutex main_context_mutex
 
void GPU_context_main_lock ()
 
void GPU_context_main_unlock ()
 

Backend selection

static eGPUBackendType g_backend_type = GPU_BACKEND_OPENGL
 
static std::optional< eGPUBackendTypeg_backend_type_override = std::nullopt
 
static std::optional< bool > g_backend_type_supported = std::nullopt
 
static GPUBackendg_backend = nullptr
 
static GHOST_SystemHandle g_ghost_system = nullptr
 
static void gpu_backend_create ()
 
static void gpu_backend_discard ()
 
void GPU_backend_ghost_system_set (void *ghost_system_handle)
 
void * GPU_backend_ghost_system_get ()
 
void GPU_backend_type_selection_set (const eGPUBackendType backend)
 
eGPUBackendType GPU_backend_type_selection_get ()
 
void GPU_backend_type_selection_set_override (const eGPUBackendType backend_type)
 
bool GPU_backend_type_selection_is_overridden ()
 
bool GPU_backend_type_selection_detect ()
 
static bool gpu_backend_supported ()
 
bool GPU_backend_supported ()
 
void gpu_backend_delete_resources ()
 
eGPUBackendType GPU_backend_get_type ()
 

Detailed Description

Manage GL vertex array IDs in a thread-safe way Use these instead of glGenBuffers & its friends

  • alloc must be called from a thread that is bound to the context that will be used for drawing with this VAO.
  • free can be called from any thread

Definition in file gpu_context.cc.

Function Documentation

◆ gpu_backend_create()

static void gpu_backend_create ( )
static

◆ gpu_backend_delete_resources()

void gpu_backend_delete_resources ( )

Definition at line 370 of file gpu_context.cc.

References BLI_assert, blender::gpu::GPUBackend::delete_resources(), and g_backend.

Referenced by GPU_exit().

◆ gpu_backend_discard()

void gpu_backend_discard ( )
static

Definition at line 376 of file gpu_context.cc.

References g_backend.

Referenced by GPU_context_discard().

◆ GPU_backend_get_type()

◆ GPU_backend_ghost_system_get()

void * GPU_backend_ghost_system_get ( )

◆ GPU_backend_ghost_system_set()

void GPU_backend_ghost_system_set ( void * ghost_system_handle)

◆ GPU_backend_supported()

bool GPU_backend_supported ( )

◆ gpu_backend_supported()

◆ GPU_backend_type_selection_detect()

bool GPU_backend_type_selection_detect ( )

Detect the most suited eGPUBackendType.

  • The detected backend will be set in GPU_backend_type_selection_set.
  • When GPU_backend_type_selection_is_overridden it checks the overridden backend. When not overridden it checks a default list.
  • OpenGL backend will be checked as fallback for Metal.

Returns true when detection found a supported backend, otherwise returns false. When no supported backend is found GPU_backend_type_selection_set is called with GPU_BACKEND_NONE.

Definition at line 279 of file gpu_context.cc.

References blender::VectorSet< Key, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), G, g_backend_type_override, G_FLAG_GPU_BACKEND_FALLBACK, GPU_BACKEND_METAL, GPU_BACKEND_NONE, GPU_BACKEND_OPENGL, GPU_backend_supported(), GPU_backend_type_selection_is_overridden(), and GPU_backend_type_selection_set().

Referenced by wm_init_userdef(), and wm_main_playanim_intern().

◆ GPU_backend_type_selection_get()

◆ GPU_backend_type_selection_is_overridden()

bool GPU_backend_type_selection_is_overridden ( )

Check if the GPU_backend_type_selection_detect is overridden to only test a specific backend.

Definition at line 274 of file gpu_context.cc.

References g_backend_type_override.

Referenced by GPU_backend_type_selection_detect(), and wm_gpu_backend_override_from_userdef().

◆ GPU_backend_type_selection_set()

void GPU_backend_type_selection_set ( const eGPUBackendType backend)

◆ GPU_backend_type_selection_set_override()

void GPU_backend_type_selection_set_override ( eGPUBackendType backend_type)

Alter the GPU_backend_type_selection_detect to only test a specific backend

Definition at line 269 of file gpu_context.cc.

References g_backend_type_override.

Referenced by arg_handle_gpu_backend_set(), and wm_gpu_backend_override_from_userdef().

◆ GPU_context_active_get()

◆ GPU_context_active_set()

◆ GPU_context_begin_frame()

void GPU_context_begin_frame ( GPUContext * ctx)

◆ GPU_context_create()

◆ GPU_context_discard()

◆ GPU_context_end_frame()

void GPU_context_end_frame ( GPUContext * ctx)

◆ GPU_context_main_lock()

void GPU_context_main_lock ( )

Definition at line 184 of file gpu_context.cc.

References main_context_mutex.

Referenced by DRW_render_context_enable(), and wm_draw_update().

◆ GPU_context_main_unlock()

void GPU_context_main_unlock ( )

Definition at line 189 of file gpu_context.cc.

References main_context_mutex.

Referenced by DRW_render_context_disable(), and wm_draw_update().

◆ GPU_render_begin()

void GPU_render_begin ( )

Definition at line 203 of file gpu_context.cc.

References active_ctx, BLI_assert, blender::gpu::GPUBackend::get(), blender::gpu::printf_begin(), blender::gpu::printf_end(), and blender::gpu::GPUBackend::render_begin().

Referenced by drw_deferred_shader_compilation_exec(), DRW_gpu_context_enable_ex(), DRW_render_context_enable(), DRW_render_to_image(), blender::render::RealtimeCompositor::execute(), blender::gpu::tests::gpu_shader_lib_test(), playanim_toscreen_ex(), RE_engine_gpu_context_enable(), RE_PreviewRender(), blender::gpu::GPUTest::SetUp(), blender::gpu::tests::ShaderSpecializationConst::ShaderSpecializationConst(), blender::draw::test_draw_resource_id_gen(), blender::draw::test_draw_visibility(), blender::draw::test_eevee_lut_gen(), blender::draw::test_eevee_shadow_finalize(), blender::draw::test_eevee_shadow_free(), blender::draw::test_eevee_shadow_page_mask_ex(), blender::draw::test_eevee_shadow_shift(), blender::draw::test_eevee_shadow_shift_clear(), blender::draw::test_eevee_shadow_tag_update(), blender::draw::test_eevee_shadow_tilemap_amend(), blender::draw::test_eevee_surfel_list(), blender::gpu::tests::test_framebuffer_cube(), blender::gpu::tests::test_framebuffer_multi_viewport(), blender::gpu::tests::test_framebuffer_subpass_input(), blender::gpu::tests::test_texture_1d(), blender::gpu::tests::test_texture_1d_array(), blender::gpu::tests::test_texture_1d_array_upload(), blender::gpu::tests::test_texture_2d_array(), blender::gpu::tests::test_texture_2d_array_upload(), blender::gpu::tests::test_texture_3d(), blender::gpu::tests::test_texture_copy(), blender::gpu::tests::test_texture_cube(), blender::gpu::tests::test_texture_cube_array(), blender::gpu::tests::test_texture_read(), blender::draw::TestAlloc::TestAlloc(), wm_draw_update(), wm_event_do_handlers(), wm_event_do_notifiers(), WM_init(), wm_main_playanim_intern(), wm_window_events_process(), and wm_window_ghostwindow_add().

◆ GPU_render_end()

void GPU_render_end ( )

Definition at line 215 of file gpu_context.cc.

References active_ctx, BLI_assert, blender::gpu::GPUBackend::get(), blender::gpu::printf_begin(), blender::gpu::printf_end(), and blender::gpu::GPUBackend::render_end().

Referenced by drw_deferred_shader_compilation_exec(), DRW_gpu_context_disable_ex(), DRW_render_context_disable(), DRW_render_to_image(), blender::render::RealtimeCompositor::execute(), blender::gpu::tests::gpu_shader_lib_test(), playanim_toscreen_ex(), RE_engine_gpu_context_disable(), RE_PreviewRender(), blender::gpu::tests::ShaderSpecializationConst::ShaderSpecializationConst(), blender::gpu::GPUTest::TearDown(), blender::draw::test_draw_resource_id_gen(), blender::draw::test_draw_visibility(), blender::draw::test_eevee_lut_gen(), blender::draw::test_eevee_shadow_finalize(), blender::draw::test_eevee_shadow_free(), blender::draw::test_eevee_shadow_page_mask_ex(), blender::draw::test_eevee_shadow_shift(), blender::draw::test_eevee_shadow_shift_clear(), blender::draw::test_eevee_shadow_tag_update(), blender::draw::test_eevee_shadow_tilemap_amend(), blender::draw::test_eevee_surfel_list(), blender::gpu::tests::test_framebuffer_cube(), blender::gpu::tests::test_framebuffer_multi_viewport(), blender::gpu::tests::test_framebuffer_subpass_input(), blender::gpu::tests::test_texture_1d(), blender::gpu::tests::test_texture_1d_array(), blender::gpu::tests::test_texture_1d_array_upload(), blender::gpu::tests::test_texture_2d_array(), blender::gpu::tests::test_texture_2d_array_upload(), blender::gpu::tests::test_texture_3d(), blender::gpu::tests::test_texture_copy(), blender::gpu::tests::test_texture_cube(), blender::gpu::tests::test_texture_cube_array(), blender::gpu::tests::test_texture_read(), blender::draw::TestAlloc::TestAlloc(), wm_draw_update(), wm_event_do_handlers(), wm_event_do_notifiers(), WM_init(), wm_main_playanim_intern(), wm_window_events_process(), and wm_window_ghostwindow_add().

◆ GPU_render_step()

Variable Documentation

◆ active_ctx

◆ backend_users_mutex

std::mutex backend_users_mutex
static

Definition at line 53 of file gpu_context.cc.

Referenced by GPU_context_create(), and GPU_context_discard().

◆ g_backend

◆ g_backend_type

◆ g_backend_type_override

std::optional<eGPUBackendType> g_backend_type_override = std::nullopt
static

◆ g_backend_type_supported

std::optional<bool> g_backend_type_supported = std::nullopt
static

Definition at line 244 of file gpu_context.cc.

Referenced by GPU_backend_supported(), and GPU_backend_type_selection_set().

◆ g_ghost_system

GHOST_SystemHandle g_ghost_system = nullptr
static

Definition at line 246 of file gpu_context.cc.

Referenced by GPU_backend_ghost_system_get(), and GPU_backend_ghost_system_set().

◆ main_context_mutex

std::mutex main_context_mutex
static

Definition at line 182 of file gpu_context.cc.

Referenced by GPU_context_main_lock(), and GPU_context_main_unlock().

◆ num_backend_users

int num_backend_users = 0
static

Definition at line 54 of file gpu_context.cc.

Referenced by GPU_context_create(), and GPU_context_discard().