Blender V4.3
blender::gpu::MTLContext Class Reference

#include <mtl_context.hh>

Inherits blender::gpu::Context.

Public Member Functions

void debug_unbind_all_ubo () override
 
void debug_unbind_all_ssbo () override
 
MTLContextTextureUtilsget_texture_utils ()
 
MTLContextComputeUtilsget_compute_utils ()
 
bool get_active ()
 
bool get_inside_frame ()
 
uint get_current_frame_index ()
 
MTLScratchBufferManagerget_scratchbuffer_manager ()
 
Debug Groups

Useful for debugging through render-doc. This makes all the API calls grouped into "passes".

void debug_group_begin (const char *name, int index) override
 
void debug_group_end () override
 
bool debug_capture_begin (const char *title) override
 
void debug_capture_end () override
 
void * debug_capture_scope_create (const char *name) override
 
bool debug_capture_scope_begin (void *scope) override
 
void debug_capture_scope_end (void *scope) override
 
Texture State Management
void texture_bind (gpu::MTLTexture *mtl_texture, uint texture_unit, bool is_image)
 
void sampler_bind (MTLSamplerState, uint sampler_unit)
 
void texture_unbind (gpu::MTLTexture *mtl_texture, bool is_image)
 
void texture_unbind_all (bool is_image)
 
void sampler_state_cache_init ()
 
id< MTLSamplerStateget_sampler_from_state (MTLSamplerState state)
 
id< MTLSamplerStateget_default_sampler_state ()
 
Global Context State
void pipeline_state_init ()
 
void set_viewport (int origin_x, int origin_y, int width, int height)
 
void set_viewports (int count, const int(&viewports)[GPU_MAX_VIEWPORTS][4])
 
void set_scissor (int scissor_x, int scissor_y, int scissor_width, int scissor_height)
 
void set_scissor_enabled (bool scissor_enabled)
 
Command Encoder and pipeline state

These utilities ensure that all of the globally bound resources and state have been correctly encoded within the current RenderCommandEncoder. This involves managing buffer bindings, texture bindings, depth stencil state and dynamic pipeline state.

We will also trigger compilation of new PSOs where the input state has changed and is required. All of this setup is required in order to perform a valid draw call.

bool ensure_render_pipeline_state (MTLPrimitiveType prim_type)
 
bool ensure_buffer_bindings (id< MTLRenderCommandEncoder > rec, const MTLShaderInterface *shader_interface, const MTLRenderPipelineStateInstance *pipeline_state_instance)
 
bool ensure_buffer_bindings (id< MTLComputeCommandEncoder > rec, const MTLShaderInterface *shader_interface, const MTLComputePipelineStateInstance *pipeline_state_instance)
 
void ensure_texture_bindings (id< MTLRenderCommandEncoder > rec, MTLShaderInterface *shader_interface, const MTLRenderPipelineStateInstance *pipeline_state_instance)
 
void ensure_texture_bindings (id< MTLComputeCommandEncoder > rec, MTLShaderInterface *shader_interface, const MTLComputePipelineStateInstance *pipeline_state_instance)
 
void ensure_depth_stencil_state (MTLPrimitiveType prim_type)
 
Compute dispatch.
const MTLComputePipelineStateInstanceensure_compute_pipeline_state ()
 
void compute_dispatch (int groups_x_len, int groups_y_len, int groups_z_len)
 
void compute_dispatch_indirect (StorageBuf *indirect_buf)
 
Visibility buffer control for MTLQueryPool.
void set_visibility_buffer (gpu::MTLBuffer *buffer)
 
gpu::MTLBufferget_visibility_buffer () const
 
bool is_visibility_dirty () const
 
void clear_visibility_dirty ()
 
- Public Member Functions inherited from blender::gpu::Context
 Context ()
 
virtual ~Context ()
 
bool is_active_on_thread ()
 

Static Public Member Functions

static MTLContextget ()
 
static void global_memory_manager_acquire_ref ()
 
static void global_memory_manager_release_ref ()
 
static MTLBufferPoolget_global_memory_manager ()
 
static void latency_resolve_average (int64_t frame_latency_us)
 
- Static Public Member Functions inherited from blender::gpu::Context
static Contextget ()
 

Public Attributes

MTLContextGlobalShaderPipelineState pipeline_state
 
id< MTLCommandQueue > queue = nil
 
id< MTLDevice > device = nil
 
NSString * label = nil
 
MTLScratchBufferManager memory_manager
 
MTLCommandBufferManager main_command_buffer
 
- Public Attributes inherited from blender::gpu::Context
Shadershader = nullptr
 
FrameBufferactive_fb = nullptr
 
GPUMatrixStatematrix_state = nullptr
 
StateManagerstate_manager = nullptr
 
Immediateimm = nullptr
 
ShaderCompilercompiler = nullptr
 
FrameBufferback_left = nullptr
 
FrameBufferfront_left = nullptr
 
FrameBufferback_right = nullptr
 
FrameBufferfront_right = nullptr
 
DebugStack debug_stack
 
bool debug_is_capturing = false
 
int context_id = 0
 
GPUStorageBuf * printf_buf = nullptr
 

Static Public Attributes

static std::atomic< intmax_drawables_in_flight = 0
 
static std::atomic< int64_tavg_drawable_latency_us = 0
 
static int64_t frame_latency [MTL_FRAME_AVERAGE_COUNT] = {0}
 
static std::mutex global_memory_manager_reflock
 
static int global_memory_manager_refcount = 0
 
static MTLBufferPoolglobal_memory_manager = nullptr
 
- Static Public Attributes inherited from blender::gpu::Context
static int context_counter = 0
 

Friends

class MTLBackend
 
class MTLRenderPassState
 
class MTLComputeState
 

MTLContext

 MTLContext (void *ghost_window, void *ghost_context)
 
 ~MTLContext ()
 
void activate () override
 
void deactivate () override
 
void begin_frame () override
 
void end_frame () override
 
void flush () override
 
void finish () override
 
void memory_statistics_get (int *r_total_mem, int *r_free_mem) override
 
void framebuffer_bind (MTLFrameBuffer *framebuffer)
 
void framebuffer_restore ()
 
id< MTLRenderCommandEncoder > ensure_begin_render_pass ()
 
MTLFrameBufferget_current_framebuffer ()
 
MTLFrameBufferget_default_framebuffer ()
 
MTLShaderget_active_shader ()
 
id< MTLBufferget_null_buffer ()
 
id< MTLBufferget_null_attribute_buffer ()
 
gpu::MTLTextureget_dummy_texture (eGPUTextureType type, eGPUSamplerFormat sampler_format)
 
void free_dummy_resources ()
 
static void check_error (const char *info)
 

Additional Inherited Members

- Protected Attributes inherited from blender::gpu::Context
pthread_t thread_
 
bool is_active_
 
void * ghost_window_
 

Detailed Description

MTLContext – Core render loop and state management.

NOTE(Metal): Partial MTLContext stub to provide wrapper functionality for work-in-progress MTL* classes.

Definition at line 672 of file mtl_context.hh.

Constructor & Destructor Documentation

◆ MTLContext()

◆ ~MTLContext()

Member Function Documentation

◆ activate()

◆ begin_frame()

void blender::gpu::MTLContext::begin_frame ( )
overridevirtual

◆ check_error()

void blender::gpu::MTLContext::check_error ( const char * info)
static

Definition at line 405 of file mtl_context.mm.

◆ clear_visibility_dirty()

void blender::gpu::MTLContext::clear_visibility_dirty ( )

◆ compute_dispatch()

◆ compute_dispatch_indirect()

◆ deactivate()

void blender::gpu::MTLContext::deactivate ( )
overridevirtual

◆ debug_capture_begin()

bool blender::gpu::MTLContext::debug_capture_begin ( const char * title)
overridevirtual

Implements blender::gpu::Context.

Definition at line 62 of file mtl_debug.mm.

References device, error(), and init().

◆ debug_capture_end()

void blender::gpu::MTLContext::debug_capture_end ( )
overridevirtual

Implements blender::gpu::Context.

Definition at line 79 of file mtl_debug.mm.

◆ debug_capture_scope_begin()

bool blender::gpu::MTLContext::debug_capture_scope_begin ( void * scope)
overridevirtual

Implements blender::gpu::Context.

Definition at line 104 of file mtl_debug.mm.

◆ debug_capture_scope_create()

void * blender::gpu::MTLContext::debug_capture_scope_create ( const char * name)
overridevirtual

Implements blender::gpu::Context.

Definition at line 89 of file mtl_debug.mm.

References device.

◆ debug_capture_scope_end()

void blender::gpu::MTLContext::debug_capture_scope_end ( void * scope)
overridevirtual

Implements blender::gpu::Context.

Definition at line 114 of file mtl_debug.mm.

◆ debug_group_begin()

void blender::gpu::MTLContext::debug_group_begin ( const char * name,
int index )
overridevirtual

◆ debug_group_end()

void blender::gpu::MTLContext::debug_group_end ( )
overridevirtual

◆ debug_unbind_all_ssbo()

void blender::gpu::MTLContext::debug_unbind_all_ssbo ( )
inlineoverridevirtual

Implements blender::gpu::Context.

Definition at line 787 of file mtl_context.hh.

◆ debug_unbind_all_ubo()

void blender::gpu::MTLContext::debug_unbind_all_ubo ( )
inlineoverridevirtual

Implements blender::gpu::Context.

Definition at line 786 of file mtl_context.hh.

◆ end_frame()

void blender::gpu::MTLContext::end_frame ( )
overridevirtual

Implements blender::gpu::Context.

Definition at line 394 of file mtl_context.mm.

References BLI_assert, flush(), and get_inside_frame().

Referenced by ~MTLContext().

◆ ensure_begin_render_pass()

◆ ensure_buffer_bindings() [1/2]

bool blender::gpu::MTLContext::ensure_buffer_bindings ( id< MTLComputeCommandEncoder > rec,
const MTLShaderInterface * shader_interface,
const MTLComputePipelineStateInstance * pipeline_state_instance )

Definition at line 1407 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLComputePipelineStateInstance::base_storage_buffer_index, blender::gpu::MTLComputePipelineStateInstance::base_uniform_buffer_index, blender::gpu::MTLComputeState::bind_compute_buffer(), blender::gpu::MTLComputeState::bind_compute_bytes(), BLI_assert, blender::gpu::MTLStorageBufferBinding::bound, blender::gpu::MTLUniformBufferBinding::bound, blender::gpu::MTLShaderBufferBlock::buffer_index, blender::gpu::COMPUTE, blender::gpu::MTLCommandBufferManager::get_compute_state(), blender::gpu::MTLStorageBuf::get_metal_buffer(), blender::gpu::MTLUniformBuf::get_metal_buffer(), blender::gpu::MTLShaderInterface::get_name(), blender::gpu::MTLShaderInterface::get_name_at_offset(), get_null_buffer(), blender::gpu::MTLShaderInterface::get_push_constant_block(), blender::gpu::MTLShader::get_push_constant_data(), blender::gpu::MTLStorageBuf::get_size(), blender::gpu::MTLUniformBuf::get_size(), blender::gpu::MTLShaderInterface::get_storage_block(), blender::gpu::MTLShaderInterface::get_total_storage_blocks(), blender::gpu::MTLShaderInterface::get_total_uniform_blocks(), blender::gpu::MTLShaderInterface::get_uniform_block(), length(), blender::gpu::MTLShaderBufferBlock::location, main_command_buffer, MTL_LOG_SSBO_ERROR, MTL_LOG_UBO_ERROR, MTL_MAX_BUFFER_BINDINGS, blender::gpu::MTLShaderBufferBlock::name_offset, pipeline_state, blender::gpu::MTLShader::push_constant_bindstate_mark_dirty(), blender::gpu::MTLShaderBufferBlock::size, blender::gpu::MTLStorageBufferBinding::ssbo, blender::gpu::MTLContextGlobalShaderPipelineState::ssbo_bindings, blender::gpu::MTLShaderBufferBlock::stage_mask, blender::gpu::MTLUniformBufferBinding::ubo, blender::gpu::MTLContextGlobalShaderPipelineState::ubo_bindings, and UNUSED_VARS_NDEBUG.

◆ ensure_buffer_bindings() [2/2]

bool blender::gpu::MTLContext::ensure_buffer_bindings ( id< MTLRenderCommandEncoder > rec,
const MTLShaderInterface * shader_interface,
const MTLRenderPipelineStateInstance * pipeline_state_instance )

Definition at line 1162 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLRenderPipelineStateInstance::base_storage_buffer_index, blender::gpu::MTLRenderPipelineStateInstance::base_uniform_buffer_index, blender::gpu::MTLRenderPassState::bind_fragment_buffer(), blender::gpu::MTLRenderPassState::bind_fragment_bytes(), blender::gpu::MTLRenderPassState::bind_vertex_buffer(), blender::gpu::MTLRenderPassState::bind_vertex_bytes(), BLI_assert, BLI_assert_msg, blender::gpu::MTLStorageBufferBinding::bound, blender::gpu::MTLUniformBufferBinding::bound, blender::gpu::MTLRenderPipelineStateInstance::buffer_bindings_reflection_data_frag, blender::gpu::MTLRenderPipelineStateInstance::buffer_bindings_reflection_data_vert, blender::gpu::MTLShaderBufferBlock::buffer_index, blender::gpu::MTLRenderPassState::cached_fragment_buffer_bindings, blender::gpu::MTLRenderPassState::cached_vertex_buffer_bindings, blender::gpu::FRAGMENT, blender::gpu::MTLStorageBuf::get_metal_buffer(), blender::gpu::MTLUniformBuf::get_metal_buffer(), blender::gpu::MTLShaderInterface::get_name(), blender::gpu::MTLShaderInterface::get_name_at_offset(), get_null_buffer(), blender::gpu::MTLShaderInterface::get_push_constant_block(), blender::gpu::MTLShader::get_push_constant_data(), blender::gpu::MTLShader::get_push_constant_is_dirty(), blender::gpu::MTLCommandBufferManager::get_render_pass_state(), blender::gpu::MTLStorageBuf::get_size(), blender::gpu::MTLUniformBuf::get_size(), blender::gpu::MTLShaderInterface::get_storage_block(), blender::gpu::MTLShaderInterface::get_total_storage_blocks(), blender::gpu::MTLShaderInterface::get_total_uniform_blocks(), blender::gpu::MTLShaderInterface::get_uniform_block(), blender::gpu::BufferBindingCached::is_bytes, blender::gpu::MTLRenderPassState::last_bound_shader_state, length(), blender::gpu::MTLShaderBufferBlock::location, main_command_buffer, MTL_LOG_SSBO_ERROR, MTL_LOG_UBO_ERROR, MTL_MAX_BUFFER_BINDINGS, blender::gpu::MTLShaderBufferBlock::name_offset, pipeline_state, blender::gpu::MTLBoundShaderState::pso_index_, blender::gpu::MTLShader::push_constant_bindstate_mark_dirty(), blender::gpu::MTLRenderPipelineStateInstance::reflection_data_available, blender::gpu::MTLBoundShaderState::set(), blender::gpu::MTLBoundShaderState::shader_, blender::gpu::MTLRenderPipelineStateInstance::shader_pso_index, blender::gpu::MTLShaderBufferBlock::size, blender::gpu::MTLStorageBufferBinding::ssbo, blender::gpu::MTLContextGlobalShaderPipelineState::ssbo_bindings, blender::gpu::MTLShaderBufferBlock::stage_mask, blender::gpu::MTLUniformBufferBinding::ubo, blender::gpu::MTLContextGlobalShaderPipelineState::ubo_bindings, UNUSED_VARS_NDEBUG, and blender::gpu::VERTEX.

Referenced by compute_dispatch(), compute_dispatch_indirect(), and ensure_render_pipeline_state().

◆ ensure_compute_pipeline_state()

◆ ensure_depth_stencil_state()

void blender::gpu::MTLContext::ensure_depth_stencil_state ( MTLPrimitiveType prim_type)

Prepare Depth-stencil state based on current global pipeline state.

Definition at line 2064 of file mtl_context.mm.

References BLI_assert, blender::gpu::MTLRenderPassState::bound_ds_state, clamp(), blender::gpu::MTLContextDepthStencilState::depth_bias, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_lines, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_points, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_tris, blender::gpu::MTLContextDepthStencilState::depth_function, blender::gpu::MTLContextDepthStencilState::depth_slope_scale, blender::gpu::MTLContextGlobalShaderPipelineState::depth_stencil_state, blender::gpu::MTLContextDepthStencilState::depth_test_enabled, blender::gpu::MTLContextDepthStencilState::depth_write_enable, device, blender::gpu::MTLContextGlobalShaderPipelineState::dirty_flags, fb(), blender::gpu::MTLCommandBufferManager::get_active_render_command_encoder(), get_current_framebuffer(), blender::gpu::MTLCommandBufferManager::get_render_pass_state(), blender::gpu::MTLContextDepthStencilState::has_depth_target, blender::gpu::MTLContextDepthStencilState::has_stencil_target, init(), blender::gpu::MTLRenderPassState::last_used_stencil_ref_value, main_command_buffer, blender::gpu::MTL_PIPELINE_STATE_DEPTHSTENCIL_FLAG, pipeline_state, blender::gpu::MTLContextDepthStencilState::stencil_func, blender::gpu::MTLContextDepthStencilState::stencil_op_back_depth_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_back_depthstencil_pass, blender::gpu::MTLContextDepthStencilState::stencil_op_back_stencil_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_front_depth_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_front_depthstencil_pass, blender::gpu::MTLContextDepthStencilState::stencil_op_front_stencil_fail, blender::gpu::MTLContextDepthStencilState::stencil_read_mask, blender::gpu::MTLContextDepthStencilState::stencil_ref, blender::gpu::MTLContextDepthStencilState::stencil_test_enabled, and blender::gpu::MTLContextDepthStencilState::stencil_write_mask.

Referenced by blender::gpu::MTLImmediate::end(), and blender::gpu::MTLDrawList::submit().

◆ ensure_render_pipeline_state()

bool blender::gpu::MTLContext::ensure_render_pipeline_state ( MTLPrimitiveType prim_type)

Ensure resource bindings.

Dynamic Per-draw Render State on RenderCommandEncoder.

Definition at line 917 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::StateManager::apply_state(), blender::gpu::MTLShader::bake_current_pipeline_state(), blender::gpu::MTLVertBuf::bind(), blender::gpu::MTLRenderPassState::bind_vertex_buffer(), BLI_assert, BLI_assert_unreachable, blender::gpu::MTLRenderPassState::bound_pso, count, blender::gpu::MTLContextGlobalShaderPipelineState::cull_mode, blender::gpu::MTLContextGlobalShaderPipelineState::culling_enabled, blender::gpu::MTLContextDepthStencilState::depth_range_far, blender::gpu::MTLContextDepthStencilState::depth_range_near, blender::gpu::MTLContextGlobalShaderPipelineState::depth_stencil_state, blender::gpu::MTLContextGlobalShaderPipelineState::dirty_flags, double(), ensure_buffer_bindings(), ensure_texture_bindings(), blender::gpu::MTLContextGlobalShaderPipelineState::front_face, G, G_DEBUG_GPU, blender::gpu::MTLCommandBufferManager::get_active_framebuffer(), blender::gpu::MTLCommandBufferManager::get_active_render_command_encoder(), blender::gpu::MTLFrameBuffer::get_default_height(), blender::gpu::MTLFrameBuffer::get_default_width(), blender::gpu::MTLFrameBuffer::get_dirty(), blender::gpu::MTLFrameBuffer::get_height(), blender::gpu::MTLShader::get_interface(), blender::gpu::MTLShaderInterface::get_name(), get_null_attribute_buffer(), blender::gpu::MTLCommandBufferManager::get_render_pass_state(), blender::gpu::MTLShaderInterface::get_total_textures(), blender::gpu::MTLShader::get_transform_feedback_active_buffer(), blender::gpu::MTLFrameBuffer::get_width(), GPU_CLOCKWISE, GPU_CULL_BACK, GPU_CULL_FRONT, GPU_CULL_NONE, GPU_matrix_bind(), GPU_MAX_VIEWPORTS, blender::gpu::MTLContextGlobalShaderPipelineState::initialised, int, blender::gpu::MTLShader::is_valid(), blender::gpu::MTLRenderPassState::last_scissor_rect, main_command_buffer, max_ii(), min_ii(), MTL_LOG_ERROR, MTL_LOG_INFO, MTL_LOG_WARNING, blender::gpu::MTL_PIPELINE_STATE_CULLMODE_FLAG, blender::gpu::MTL_PIPELINE_STATE_FRONT_FACING_FLAG, blender::gpu::MTL_PIPELINE_STATE_SCISSOR_FLAG, blender::gpu::mtl_prim_type_to_topology_class(), blender::gpu::MTLRenderPipelineStateInstance::null_attribute_buffer_index, blender::gpu::MTLContextGlobalShaderPipelineState::num_active_viewports, pipeline_state, blender::gpu::MTLRenderPipelineStateInstance::pso, result, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_enabled, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_height, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_width, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_x, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_y, blender::gpu::Context::state_manager, blender::gpu::MTLRenderPipelineStateInstance::transform_feedback_buffer_index, v, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_height, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_offset_x, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_offset_y, and blender::gpu::MTLContextGlobalShaderPipelineState::viewport_width.

Referenced by blender::gpu::MTLBatch::bind(), and blender::gpu::MTLImmediate::end().

◆ ensure_texture_bindings() [1/2]

void blender::gpu::MTLContext::ensure_texture_bindings ( id< MTLComputeCommandEncoder > rec,
MTLShaderInterface * shader_interface,
const MTLComputePipelineStateInstance * pipeline_state_instance )

Definition at line 1831 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLBufferPool::allocate(), blender::gpu::MTLComputePipelineStateInstance::base_uniform_buffer_index, blender::gpu::MTLStorageBuf::bind(), blender::gpu::MTLComputeState::bind_compute_buffer(), blender::gpu::MTLComputeState::bind_compute_sampler(), blender::gpu::MTLComputeState::bind_compute_texture(), BLI_assert, blender::gpu::MTLShaderTexture::buffer_metadata_uniform_loc, blender::gpu::COMPUTE, blender::gpu::MTLComputePipelineStateInstance::compute, blender::gpu::DEFAULT_SAMPLER_STATE, blender::gpu::MTLShaderInterface::find_argument_encoder(), blender::gpu::MTLBuffer::flush(), blender::gpu::MTLShaderInterface::get_argument_buffer_bind_index(), blender::gpu::MTLCommandBufferManager::get_compute_state(), get_dummy_texture(), get_global_memory_manager(), blender::gpu::MTLShaderInterface::get_max_texture_index(), blender::gpu::MTLBuffer::get_metal_buffer(), blender::gpu::MTLShaderInterface::get_name(), blender::gpu::MTLTexture::get_name(), blender::gpu::MTLShaderInterface::get_name_at_offset(), blender::gpu::MTLTexture::get_storagebuf(), blender::gpu::MTLShaderInterface::get_texture(), blender::gpu::MTLTexture::get_texture_metdata_ptr(), GPU_max_textures(), GPU_TEXTURE_USAGE_ATOMIC, blender::gpu::MTLTexture::has_custom_swizzle(), blender::gpu::MTLContextGlobalShaderPipelineState::image_bindings, blender::gpu::MTLShaderInterface::insert_argument_encoder(), blender::gpu::MTLShaderTexture::is_texture_sampler, blender::gpu::MTLShaderTexture::location, main_command_buffer, max_uu(), MTL_LOG_ERROR, MTL_MAX_TEXTURE_SLOTS, blender::gpu::MTLSamplerArray::mtl_sampler, blender::gpu::MTLShaderTexture::name_offset, blender::gpu::MTLSamplerArray::num_samplers, pipeline_state, blender::gpu::MTLContextGlobalShaderPipelineState::sampler_bindings, blender::gpu::MTLShaderTexture::sampler_format, size(), blender::gpu::MTLShaderTexture::slot_index, blender::gpu::MTLShaderTexture::stage_mask, tex, blender::gpu::MTLContextGlobalShaderPipelineState::texture_bindings, blender::gpu::MTLShaderTexture::texture_buffer_ssbo_location, blender::gpu::MTLShaderTexture::type, blender::gpu::Texture::type_, blender::gpu::MTLShader::uniform_int(), UNUSED_VARS_NDEBUG, blender::gpu::Texture::usage_get(), blender::gpu::MTLSamplerBinding::used, blender::gpu::MTLShaderTexture::used, and blender::gpu::MTLShaderInterface::uses_argument_buffer_for_samplers().

◆ ensure_texture_bindings() [2/2]

void blender::gpu::MTLContext::ensure_texture_bindings ( id< MTLRenderCommandEncoder > rec,
MTLShaderInterface * shader_interface,
const MTLRenderPipelineStateInstance * pipeline_state_instance )

Definition at line 1579 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLBufferPool::allocate(), blender::gpu::MTLRenderPipelineStateInstance::base_uniform_buffer_index, blender::gpu::MTLStorageBuf::bind(), blender::gpu::MTLRenderPassState::bind_fragment_buffer(), blender::gpu::MTLRenderPassState::bind_fragment_sampler(), blender::gpu::MTLRenderPassState::bind_fragment_texture(), blender::gpu::MTLRenderPassState::bind_vertex_buffer(), blender::gpu::MTLRenderPassState::bind_vertex_sampler(), blender::gpu::MTLRenderPassState::bind_vertex_texture(), BLI_assert, blender::gpu::MTLShaderTexture::buffer_metadata_uniform_loc, blender::gpu::DEFAULT_SAMPLER_STATE, blender::gpu::MTLShaderInterface::find_argument_encoder(), blender::gpu::MTLBuffer::flush(), blender::gpu::FRAGMENT, blender::gpu::MTLShaderInterface::get_argument_buffer_bind_index(), get_dummy_texture(), get_global_memory_manager(), blender::gpu::MTLShaderInterface::get_max_texture_index(), blender::gpu::MTLBuffer::get_metal_buffer(), blender::gpu::MTLShaderInterface::get_name(), blender::gpu::MTLTexture::get_name(), blender::gpu::MTLShaderInterface::get_name_at_offset(), blender::gpu::MTLCommandBufferManager::get_render_pass_state(), blender::gpu::MTLTexture::get_storagebuf(), blender::gpu::MTLShaderInterface::get_texture(), blender::gpu::MTLTexture::get_texture_metdata_ptr(), GPU_max_textures(), GPU_TEXTURE_USAGE_ATOMIC, blender::gpu::MTLContextGlobalShaderPipelineState::image_bindings, blender::gpu::MTLShaderInterface::insert_argument_encoder(), blender::gpu::MTLShaderTexture::is_texture_sampler, blender::gpu::MTLShaderTexture::location, main_command_buffer, max_uu(), MTL_LOG_ERROR, MTL_MAX_TEXTURE_SLOTS, blender::gpu::MTLSamplerArray::mtl_sampler, blender::gpu::MTLShaderTexture::name_offset, blender::gpu::MTLSamplerArray::num_samplers, pipeline_state, blender::gpu::MTLContextGlobalShaderPipelineState::sampler_bindings, blender::gpu::MTLShaderTexture::sampler_format, size(), blender::gpu::MTLShaderTexture::slot_index, blender::gpu::MTLShaderTexture::stage_mask, tex, blender::gpu::MTLContextGlobalShaderPipelineState::texture_bindings, blender::gpu::MTLShaderTexture::texture_buffer_ssbo_location, blender::gpu::MTLShaderTexture::type, blender::gpu::Texture::type_, blender::gpu::MTLShader::uniform_int(), UNUSED_VARS_NDEBUG, blender::gpu::Texture::usage_get(), blender::gpu::MTLSamplerBinding::used, blender::gpu::MTLShaderTexture::used, blender::gpu::MTLShaderInterface::uses_argument_buffer_for_samplers(), blender::gpu::MTLRenderPipelineStateInstance::vert, and blender::gpu::VERTEX.

Referenced by compute_dispatch(), compute_dispatch_indirect(), and ensure_render_pipeline_state().

◆ finish()

void blender::gpu::MTLContext::finish ( )
overridevirtual

Implements blender::gpu::Context.

Definition at line 463 of file mtl_context.mm.

References main_command_buffer, and blender::gpu::MTLCommandBufferManager::submit().

Referenced by ~MTLContext().

◆ flush()

void blender::gpu::MTLContext::flush ( )
overridevirtual

◆ framebuffer_bind()

void blender::gpu::MTLContext::framebuffer_bind ( MTLFrameBuffer * framebuffer)

Metal Context Core functions.

Definition at line 475 of file mtl_context.mm.

References blender::gpu::Context::active_fb, and BLI_assert.

Referenced by blender::gpu::MTLFrameBuffer::bind().

◆ framebuffer_restore()

void blender::gpu::MTLContext::framebuffer_restore ( )

◆ free_dummy_resources()

void blender::gpu::MTLContext::free_dummy_resources ( )

◆ get()

static MTLContext * blender::gpu::MTLContext::get ( )
inlinestatic

Definition at line 773 of file mtl_context.hh.

References blender::gpu::Context::get().

Referenced by blender::gpu::MTLFrameBuffer::apply_state(), blender::gpu::MTLStorageBuf::async_flush_to_host(), blender::gpu::MTLShader::bake_current_pipeline_state(), blender::gpu::MTLFrameBuffer::bake_render_pass_descriptor(), blender::gpu::MTLQueryPool::begin_query(), blender::gpu::MTLBatch::bind(), blender::gpu::MTLFrameBuffer::bind(), blender::gpu::MTLShader::bind(), blender::gpu::MTLStorageBuf::bind(), blender::gpu::MTLUniformBuf::bind(), blender::gpu::MTLVertBuf::bind(), blender::gpu::MTLFrameBuffer::blit(), blender::gpu::MTLFrameBuffer::clear(), blender::gpu::MTLStorageBuf::clear(), blender::gpu::MTLTexture::clear(), blender::gpu::MTLFrameBuffer::clear_attachment(), blender::gpu::MTLBackend::compute_dispatch(), blender::gpu::MTLBackend::compute_dispatch_indirect(), blender::gpu::MTLStorageBuf::copy_sub(), blender::gpu::MTLTexture::copy_to(), blender::gpu::MTLVertBuf::duplicate_data(), blender::gpu::MTLImmediate::end(), blender::gpu::MTLQueryPool::end_query(), blender::gpu::MTLBackend::framebuffer_alloc(), blender::gpu::MTLTexture::generate_mipmap(), blender::gpu::MTLContextComputeUtils::get_buffer_clear_pso(), blender::gpu::MTLQueryPool::get_occlusion_result(), blender::gpu::MTLStateManager::image_bind(), blender::gpu::MTLStateManager::image_unbind(), blender::gpu::MTLStateManager::image_unbind_all(), blender::gpu::MTLStorageBuf::init(), blender::gpu::MTLTexture::init_internal(), blender::gpu::MTLStateManager::issue_barrier(), blender::gpu::MTLPixelBuffer::map(), blender::gpu::present(), blender::gpu::MTLIndexBuf::read(), blender::gpu::MTLStorageBuf::read(), blender::gpu::MTLVertBuf::read(), blender::gpu::MTLBackend::shader_alloc(), blender::gpu::MTLFence::signal(), blender::gpu::MTLShader::ssbo_vertex_fetch_bind_attributes_end(), blender::gpu::MTLDrawList::submit(), blender::gpu::MTLStateManager::texture_bind(), blender::gpu::MTLStateManager::texture_unbind(), blender::gpu::MTLStateManager::texture_unbind_all(), blender::gpu::MTLStateManager::texture_unpack_row_length_set(), blender::gpu::MTLShader::unbind(), blender::gpu::MTLStorageBuf::update(), blender::gpu::MTLUniformBuf::update(), blender::gpu::MTLIndexBuf::update_sub(), blender::gpu::MTLTexture::update_sub(), blender::gpu::MTLTexture::update_sub(), blender::gpu::MTLVertBuf::update_sub(), blender::gpu::MTLFence::wait(), blender::gpu::MTLShader::warm_cache(), ~MTLContext(), blender::gpu::MTLFrameBuffer::~MTLFrameBuffer(), blender::gpu::MTLStorageBuf::~MTLStorageBuf(), blender::gpu::MTLTexture::~MTLTexture(), and blender::gpu::MTLUniformBuf::~MTLUniformBuf().

◆ get_active()

bool blender::gpu::MTLContext::get_active ( )
inline

Definition at line 892 of file mtl_context.hh.

References blender::gpu::Context::is_active_.

◆ get_active_shader()

MTLShader * blender::gpu::MTLContext::get_active_shader ( )

◆ get_compute_utils()

MTLContextComputeUtils & blender::gpu::MTLContext::get_compute_utils ( )
inline

Definition at line 887 of file mtl_context.hh.

Referenced by blender::gpu::MTLStorageBuf::clear(), and ~MTLContext().

◆ get_current_frame_index()

◆ get_current_framebuffer()

MTLFrameBuffer * blender::gpu::MTLContext::get_current_framebuffer ( )

◆ get_default_framebuffer()

MTLFrameBuffer * blender::gpu::MTLContext::get_default_framebuffer ( )

Definition at line 551 of file mtl_context.mm.

References blender::gpu::Context::back_left.

Referenced by get_current_framebuffer().

◆ get_default_sampler_state()

◆ get_dummy_texture()

◆ get_global_memory_manager()

◆ get_inside_frame()

◆ get_null_attribute_buffer()

id< MTLBuffer > blender::gpu::MTLContext::get_null_attribute_buffer ( )

◆ get_null_buffer()

id< MTLBuffer > blender::gpu::MTLContext::get_null_buffer ( )

◆ get_sampler_from_state()

◆ get_scratchbuffer_manager()

◆ get_texture_utils()

MTLContextTextureUtils & blender::gpu::MTLContext::get_texture_utils ( )
inline

Definition at line 881 of file mtl_context.hh.

Referenced by MTLContext(), and ~MTLContext().

◆ get_visibility_buffer()

gpu::MTLBuffer * blender::gpu::MTLContext::get_visibility_buffer ( ) const

◆ global_memory_manager_acquire_ref()

static void blender::gpu::MTLContext::global_memory_manager_acquire_ref ( )
inlinestatic

◆ global_memory_manager_release_ref()

static void blender::gpu::MTLContext::global_memory_manager_release_ref ( )
inlinestatic

◆ is_visibility_dirty()

bool blender::gpu::MTLContext::is_visibility_dirty ( ) const

Definition at line 2387 of file mtl_context.mm.

◆ latency_resolve_average()

static void blender::gpu::MTLContext::latency_resolve_average ( int64_t frame_latency_us)
inlinestatic

Definition at line 944 of file mtl_context.hh.

References avg_drawable_latency_us, frame_latency, and MTL_FRAME_AVERAGE_COUNT.

Referenced by blender::gpu::present().

◆ memory_statistics_get()

void blender::gpu::MTLContext::memory_statistics_get ( int * r_total_mem,
int * r_free_mem )
overridevirtual

Implements blender::gpu::Context.

Definition at line 468 of file mtl_context.mm.

◆ pipeline_state_init()

void blender::gpu::MTLContext::pipeline_state_init ( )

Definition at line 726 of file mtl_context.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLContextGlobalShaderPipelineState::alpha_blend_op, blender::gpu::MTLContextGlobalShaderPipelineState::blending_enabled, blender::gpu::MTLStorageBufferBinding::bound, blender::gpu::MTLUniformBufferBinding::bound, blender::gpu::MTLContextGlobalShaderPipelineState::color_write_mask, blender::gpu::MTLContextGlobalShaderPipelineState::cull_mode, blender::gpu::MTLContextGlobalShaderPipelineState::culling_enabled, blender::gpu::MTLContextDepthStencilState::depth_bias, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_lines, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_points, blender::gpu::MTLContextDepthStencilState::depth_bias_enabled_for_tris, blender::gpu::MTLContextDepthStencilState::depth_function, blender::gpu::MTLContextDepthStencilState::depth_range_far, blender::gpu::MTLContextDepthStencilState::depth_range_near, blender::gpu::MTLContextDepthStencilState::depth_slope_scale, blender::gpu::MTLContextGlobalShaderPipelineState::depth_stencil_state, blender::gpu::MTLContextDepthStencilState::depth_test_enabled, blender::gpu::MTLContextDepthStencilState::depth_write_enable, blender::gpu::MTLContextGlobalShaderPipelineState::dest_alpha_blend_factor, blender::gpu::MTLContextGlobalShaderPipelineState::dest_rgb_blend_factor, blender::gpu::MTLContextGlobalShaderPipelineState::front_face, GPU_COUNTERCLOCKWISE, GPU_CULL_NONE, GPU_max_textures(), GPU_MAX_VIEWPORTS, blender::gpu::MTLContextGlobalShaderPipelineState::image_bindings, blender::gpu::MTLContextGlobalShaderPipelineState::initialised, MTL_MAX_BUFFER_BINDINGS, MTL_MAX_SAMPLER_SLOTS, pipeline_state, blender::gpu::MTLContextGlobalShaderPipelineState::rgb_blend_op, blender::gpu::MTLContextGlobalShaderPipelineState::sampler_bindings, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_enabled, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_height, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_width, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_x, blender::gpu::MTLContextGlobalShaderPipelineState::scissor_y, blender::gpu::MTLContextGlobalShaderPipelineState::src_alpha_blend_factor, blender::gpu::MTLContextGlobalShaderPipelineState::src_rgb_blend_factor, blender::gpu::MTLStorageBufferBinding::ssbo, blender::gpu::MTLContextGlobalShaderPipelineState::ssbo_bindings, blender::gpu::MTLContextDepthStencilState::stencil_func, blender::gpu::MTLContextDepthStencilState::stencil_op_back_depth_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_back_depthstencil_pass, blender::gpu::MTLContextDepthStencilState::stencil_op_back_stencil_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_front_depth_fail, blender::gpu::MTLContextDepthStencilState::stencil_op_front_depthstencil_pass, blender::gpu::MTLContextDepthStencilState::stencil_op_front_stencil_fail, blender::gpu::MTLContextDepthStencilState::stencil_read_mask, blender::gpu::MTLContextDepthStencilState::stencil_ref, blender::gpu::MTLContextDepthStencilState::stencil_test_enabled, blender::gpu::MTLContextDepthStencilState::stencil_write_mask, blender::gpu::MTLContextGlobalShaderPipelineState::texture_bindings, blender::gpu::MTLTextureBinding::texture_resource, blender::gpu::MTLUniformBufferBinding::ubo, blender::gpu::MTLContextGlobalShaderPipelineState::ubo_bindings, blender::gpu::MTLContextGlobalShaderPipelineState::unpack_row_length, blender::gpu::MTLSamplerBinding::used, blender::gpu::MTLTextureBinding::used, v, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_height, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_offset_x, blender::gpu::MTLContextGlobalShaderPipelineState::viewport_offset_y, and blender::gpu::MTLContextGlobalShaderPipelineState::viewport_width.

◆ sampler_bind()

void blender::gpu::MTLContext::sampler_bind ( MTLSamplerState sampler_state,
uint sampler_unit )

◆ sampler_state_cache_init()

◆ set_scissor()

◆ set_scissor_enabled()

◆ set_viewport()

◆ set_viewports()

◆ set_visibility_buffer()

void blender::gpu::MTLContext::set_visibility_buffer ( gpu::MTLBuffer * buffer)

◆ texture_bind()

◆ texture_unbind()

◆ texture_unbind_all()

Friends And Related Symbol Documentation

◆ MTLBackend

friend class MTLBackend
friend

Definition at line 673 of file mtl_context.hh.

◆ MTLComputeState

friend class MTLComputeState
friend

Definition at line 675 of file mtl_context.hh.

◆ MTLRenderPassState

friend class MTLRenderPassState
friend

Definition at line 674 of file mtl_context.hh.

Member Data Documentation

◆ avg_drawable_latency_us

std::atomic< int64_t > blender::gpu::MTLContext::avg_drawable_latency_us = 0
static

Definition at line 680 of file mtl_context.hh.

Referenced by latency_resolve_average(), and blender::gpu::present().

◆ device

◆ frame_latency

int64_t blender::gpu::MTLContext::frame_latency = {0}
static

Definition at line 681 of file mtl_context.hh.

Referenced by latency_resolve_average().

◆ global_memory_manager

MTLBufferPool * blender::gpu::MTLContext::global_memory_manager = nullptr
static

◆ global_memory_manager_refcount

int blender::gpu::MTLContext::global_memory_manager_refcount = 0
static

◆ global_memory_manager_reflock

std::mutex blender::gpu::MTLContext::global_memory_manager_reflock
static

◆ label

NSString* blender::gpu::MTLContext::label = nil

Definition at line 693 of file mtl_context.hh.

◆ main_command_buffer

MTLCommandBufferManager blender::gpu::MTLContext::main_command_buffer

Definition at line 703 of file mtl_context.hh.

Referenced by blender::gpu::MTLStorageBuf::async_flush_to_host(), blender::gpu::MTLQueryPool::begin_query(), blender::gpu::MTLBatch::bind(), blender::gpu::MTLVertBuf::bind(), blender::gpu::MTLFrameBuffer::blit(), blender::gpu::MTLStorageBuf::clear(), blender::gpu::MTLTexture::clear(), compute_dispatch(), compute_dispatch_indirect(), blender::gpu::MTLStorageBuf::copy_sub(), blender::gpu::MTLTexture::copy_to(), debug_group_begin(), debug_group_end(), blender::gpu::MTLVertBuf::duplicate_data(), blender::gpu::MTLImmediate::end(), blender::gpu::MTLQueryPool::end_query(), ensure_begin_render_pass(), ensure_buffer_bindings(), ensure_buffer_bindings(), ensure_depth_stencil_state(), ensure_render_pipeline_state(), ensure_texture_bindings(), ensure_texture_bindings(), finish(), flush(), blender::gpu::MTLTexture::generate_mipmap(), blender::gpu::MTLQueryPool::get_occlusion_result(), blender::gpu::MTLStateManager::issue_barrier(), MTLContext(), blender::gpu::MTLIndexBuf::read(), blender::gpu::MTLStorageBuf::read(), blender::gpu::MTLVertBuf::read(), blender::gpu::MTLFence::signal(), blender::gpu::MTLShader::ssbo_vertex_fetch_bind_attributes_end(), blender::gpu::MTLDrawList::submit(), blender::gpu::MTLFrameBuffer::subpass_transition_impl(), blender::gpu::MTLStorageBuf::update(), blender::gpu::MTLIndexBuf::update_sub(), blender::gpu::MTLTexture::update_sub(), blender::gpu::MTLTexture::update_sub(), blender::gpu::MTLVertBuf::update_sub(), blender::gpu::MTLFence::wait(), and blender::gpu::MTLFrameBuffer::~MTLFrameBuffer().

◆ max_drawables_in_flight

std::atomic< int > blender::gpu::MTLContext::max_drawables_in_flight = 0
static

Definition at line 679 of file mtl_context.hh.

Referenced by blender::gpu::present().

◆ memory_manager

MTLScratchBufferManager blender::gpu::MTLContext::memory_manager

◆ pipeline_state

◆ queue

id<MTLCommandQueue> blender::gpu::MTLContext::queue = nil

Definition at line 688 of file mtl_context.hh.

Referenced by blender::gpu::present().


The documentation for this class was generated from the following files: