Blender V5.3
blender::gpu::MTLShader Class Reference

#include <mtl_shader.hh>

Inherits blender::gpu::Shader.

Public Member Functions

void init (const shader::ShaderCreateInfo &, bool) override
bool finalize_compute (const shader::ShaderCreateInfo *info)
bool is_valid ()
bool has_compute_shader_lib ()
bool has_parent_shader ()
MTLRenderPipelineStateDescriptor & get_current_pipeline_state ()
MTLShaderInterface & get_interface ()
MTLPushConstantBuf * get_push_constant_buf ()
std::string resources_declare (const shader::ShaderCreateInfo &) const override
std::string vertex_interface_declare (const shader::ShaderCreateInfo &) const override
std::string fragment_interface_declare (const shader::ShaderCreateInfo &) const override
std::string geometry_interface_declare (const shader::ShaderCreateInfo &) const override
std::string geometry_layout_declare (const shader::ShaderCreateInfo &) const override
std::string compute_layout_declare (const shader::ShaderCreateInfo &) const override
const MTLComputePipelineStateCommon & get_compute_common_state ()
Creation / Destruction.
 MTLShader (MTLContext *ctx, const char *name)
 ~MTLShader ()
const shader::ShaderCreateInfo & patch_create_info (const shader::ShaderCreateInfo &original_info) override
Shader Binding.
void warm_cache (int limit) override
void bind (const shader::SpecializationConstants *constants_state) override
void unbind () override
void uniform_float (int location, int comp_len, int array_size, const float *data) override
void uniform_int (int location, int comp_len, int array_size, const int *data) override
Bake Pipeline State Objects
MTLRenderPipelineStateInstance * bake_current_pipeline_state (MTLContext *ctx, MTLPrimitiveTopologyClass prim_type)
MTLRenderPipelineStateInstance * bake_graphic_pipeline_state (MTLContext *ctx, MTLPrimitiveTopologyClass prim_type, const MTLRenderPipelineStateDescriptor &pipeline_descriptor)
MTLComputePipelineStateInstance * bake_compute_pipeline_state (MTLContext *ctx, MTLComputePipelineStateDescriptor &compute_pipeline_descriptor)
Public Member Functions inherited from blender::gpu::Shader
StringRefNull name_get () const
void parent_set (Shader *parent)
Shader * parent_get () const
 Shader (const char *name)
virtual ~Shader ()
void specialization_constants_init (const shader::ShaderCreateInfo &info)

Shader stage creation.

void vertex_shader_from_glsl (const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
void geometry_shader_from_glsl (const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
void fragment_shader_from_glsl (const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
void compute_shader_from_glsl (const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
bool finalize (const shader::ShaderCreateInfo *info=nullptr) override

Additional Inherited Members

Static Public Member Functions inherited from blender::gpu::Shader
static std::string defines_declare (const shader::ShaderCreateInfo &info)
static void dump_source_to_disk (StringRef shader_name, StringRef shader_name_with_stage_name, StringRef extension, StringRef source)
static void set_scene_linear_to_xyz_uniform (gpu::Shader *shader)
static void set_srgb_uniform (Context *ctx, gpu::Shader *shader)
static void set_framebuffer_srgb_target (int use_srgb_to_linear)
static std::string run_preprocessor (StringRef source, bool no_dead_code_elimination)
Public Attributes inherited from blender::gpu::Shader
ShaderInterface * interface = nullptr
uint16_t fragment_output_bits = 0
std::unique_ptr< const shader::SpecializationConstants > constants
bool is_polyline = false
bool skip_preprocessor = false
Protected Member Functions inherited from blender::gpu::Shader
void print_log (Span< StringRefNull > sources, const char *log, const char *stage, bool error, GPULogParser *parser)
Protected Attributes inherited from blender::gpu::Shader
char name [64]
Shader * parent_shader_ = nullptr
std::unique_ptr< PatchedShaderCreateInfo > patched_info_

Detailed Description

MTLShader implements shader compilation, Pipeline State Object (PSO) creation for rendering and uniform data binding. Shaders can either be created from native MSL, or generated from a GLSL source shader using #GPUShaderCreateInfo.

Shader creation process:

  • Create MTLShader:
    • Convert GLSL to MSL source if required.
  • set MSL source.
  • set Vertex/Fragment function names.
  • Create and populate MTLShaderInterface.

Definition at line 125 of file mtl_shader.hh.

Constructor & Destructor Documentation

◆ MTLShader()

blender::gpu::MTLShader::MTLShader ( MTLContext * ctx,
const char * name )

◆ ~MTLShader()

blender::gpu::MTLShader::~MTLShader ( )

Definition at line 96 of file mtl_shader.mm.

References is_valid().

Member Function Documentation

◆ bake_compute_pipeline_state()

◆ bake_current_pipeline_state()

MTLRenderPipelineStateInstance * blender::gpu::MTLShader::bake_current_pipeline_state ( MTLContext * ctx,
MTLPrimitiveTopologyClass prim_type )

Bakes or fetches a pipeline state using the current MTLRenderPipelineStateDescriptor state.

This state contains information on shader inputs/outputs, such as the vertex descriptor, used to control vertex assembly for current vertex data, and active render target information, describing the output attachment pixel formats.

Other rendering parameters such as global point-size, blend state, color mask etc; are also used. See mtl_shader.h for full #MLRenderPipelineStateDescriptor.

Populate global pipeline descriptor and use this to prepare new PSO.

Definition at line 667 of file mtl_shader.mm.

References blender::gpu::MTLContextGlobalShaderPipelineState::alpha_blend_op, blender::gpu::MTLRenderPipelineStateDescriptor::alpha_blend_op, bake_graphic_pipeline_state(), blender::gpu::MTLContextGlobalShaderPipelineState::blending_enabled, blender::gpu::MTLRenderPipelineStateDescriptor::blending_enabled, blender::BLI_assert(), blender::gpu::MTLContextGlobalShaderPipelineState::clip_distance_enabled, blender::gpu::MTLRenderPipelineStateDescriptor::clipping_plane_enable_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_format, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_mask, blender::gpu::MTLContextGlobalShaderPipelineState::color_write_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_write_mask, blender::gpu::MTLRenderPipelineStateDescriptor::depth_attachment_format, blender::gpu::MTLContextGlobalShaderPipelineState::dest_alpha_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::dest_alpha_blend_factor, blender::gpu::MTLContextGlobalShaderPipelineState::dest_rgb_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::dest_rgb_blend_factor, blender::gpu::Texture::format_get(), blender::gpu::MTLContext::get(), blender::gpu::MTLFrameBuffer::get_color_attachment(), blender::gpu::MTLContext::get_current_framebuffer(), blender::gpu::MTLFrameBuffer::get_depth_attachment(), get_interface(), blender::gpu::MTLFrameBuffer::get_is_srgb(), blender::gpu::MTLStateManager::get_pipeline_descriptor(), blender::gpu::MTLFrameBuffer::get_srgb_enabled(), blender::gpu::MTLFrameBuffer::get_stencil_attachment(), GPU_FB_MAX_COLOR_ATTACHMENT, blender::gpu::gpu_texture_format_to_metal(), blender::gpu::MTLAttachment::ignored, blender::IndexRange::IndexRange(), blender::gpu::Shader::interface, is_valid(), blender::gpu::MTLRenderPipelineStateDescriptor::num_color_attachments, blender::gpu::MTLContext::pipeline_state, blender::gpu::MTLContextGlobalShaderPipelineState::point_size, blender::gpu::MTLRenderPipelineStateDescriptor::point_size, blender::gpu::MTLVertexDescriptor::prim_topology_class, blender::gpu::MTLContextGlobalShaderPipelineState::rgb_blend_op, blender::gpu::MTLRenderPipelineStateDescriptor::rgb_blend_op, blender::gpu::MTLRenderPipelineStateDescriptor::specialization_state, blender::gpu::MTLContextGlobalShaderPipelineState::src_alpha_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::src_alpha_blend_factor, blender::gpu::MTLContextGlobalShaderPipelineState::src_rgb_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::src_rgb_blend_factor, blender::gpu::Context::state_manager, blender::gpu::MTLRenderPipelineStateDescriptor::stencil_attachment_format, blender::gpu::MTLAttachment::texture, blender::gpu::MTLAttachment::used, and blender::gpu::MTLRenderPipelineStateDescriptor::vertex_descriptor.

Referenced by blender::gpu::MTLContext::ensure_render_pipeline_state().

◆ bake_graphic_pipeline_state()

MTLRenderPipelineStateInstance * blender::gpu::MTLShader::bake_graphic_pipeline_state ( MTLContext * ctx,
MTLPrimitiveTopologyClass prim_type,
const MTLRenderPipelineStateDescriptor & pipeline_descriptor )

Definition at line 758 of file mtl_shader.mm.

References blender::gpu::MTLRenderPipelineStateDescriptor::alpha_blend_op, blender::gpu::ShaderInterface::attr_len_, blender::gpu::MTLVertexDescriptor::attributes, blender::bitscan_reverse_uint(), blender::gpu::MTLRenderPipelineStateDescriptor::blending_enabled, blender::BLI_assert(), BLI_assert_msg, blender::gpu::MTLVertexAttributeDescriptorPSO::buffer_index, blender::gpu::MTLVertexDescriptor::buffer_layouts, blender::gpu::MTLVertexBufferLayoutDescriptorPSO::buffer_slot, CLOG_DEBUG, CLOG_ERROR, CLOG_WARN, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_format, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_write_mask, blender::gpu::Shader::constants, blender::gpu::MTLRenderPipelineStateDescriptor::depth_attachment_format, blender::gpu::MTLRenderPipelineStateDescriptor::dest_alpha_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::dest_rgb_blend_factor, blender::gpu::MTLContext::device, fabsf, blender::gpu::MTLVertexAttributeDescriptorPSO::format, blender::gpu::MTLRenderPipelineStateInstance::frag, blender::gpu::FRAGMENT, get_interface(), GPU_FB_MAX_COLOR_ATTACHMENT, blender::gpu::gpu_type_to_metal_vertex_format(), blender::gpu::MTLRenderPipelineStateDescriptor::hash(), blender::IndexRange::IndexRange(), blender::gpu::ShaderInterface::inputs_, blender::gpu::Shader::interface, is_valid(), blender::gpu::LOG, blender::gpu::MTLVertexDescriptor::max_attribute_value, blender::gpu::mtl_format_supports_blending(), MTL_LOG_ERROR, MTL_MAX_BUFFER_BINDINGS, blender::gpu::MTLRenderPipelineStateInstance::null_attribute_buffer_index, blender::gpu::MTLVertexDescriptor::num_vert_buffers, blender::gpu::MTLVertexAttributeDescriptorPSO::offset, options, blender::gpu::MTLRenderPipelineStateInstance::parse_reflection_data(), blender::gpu::MTLRenderPipelineStateDescriptor::point_size, blender::gpu::populate_specialization_constant_values(), blender::gpu::MTLVertexDescriptor::prim_topology_class, blender::gpu::MTLRenderPipelineStateInstance::prim_type, blender::gpu::MTLRenderPipelineStateInstance::pso, reset(), blender::gpu::MTLRenderPipelineStateDescriptor::rgb_blend_op, blender::gpu::MTLRenderPipelineStateInstance::shader_pso_index, blender::gpu::MTLRenderPipelineStateDescriptor::specialization_state, blender::gpu::MTLRenderPipelineStateDescriptor::src_alpha_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::src_rgb_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::stencil_attachment_format, blender::gpu::MTLVertexBufferLayoutDescriptorPSO::step_function, blender::gpu::MTLVertexBufferLayoutDescriptorPSO::step_rate, blender::gpu::MTLVertexBufferLayoutDescriptorPSO::stride, blender::gpu::MTLRenderPipelineStateInstance::used_buf_vert_mask, blender::gpu::MTLRenderPipelineStateInstance::vert, blender::gpu::VERTEX, and blender::gpu::MTLRenderPipelineStateDescriptor::vertex_descriptor.

Referenced by bake_current_pipeline_state(), and warm_cache().

◆ bind()

◆ compute_layout_declare()

std::string blender::gpu::MTLShader::compute_layout_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 233 of file mtl_shader.hh.

◆ compute_shader_from_glsl()

void blender::gpu::MTLShader::compute_shader_from_glsl ( const shader::ShaderCreateInfo & info,
MutableSpan< StringRefNull > sources )
overridevirtual

Implements blender::gpu::Shader.

Definition at line 363 of file mtl_shader.mm.

References blender::gpu::COMPUTE.

◆ finalize()

◆ finalize_compute()

bool blender::gpu::MTLShader::finalize_compute ( const shader::ShaderCreateInfo * info)

References warm_cache().

◆ fragment_interface_declare()

std::string blender::gpu::MTLShader::fragment_interface_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 221 of file mtl_shader.hh.

◆ fragment_shader_from_glsl()

void blender::gpu::MTLShader::fragment_shader_from_glsl ( const shader::ShaderCreateInfo & info,
MutableSpan< StringRefNull > sources )
overridevirtual

Implements blender::gpu::Shader.

Definition at line 357 of file mtl_shader.mm.

References blender::gpu::FRAGMENT.

◆ geometry_interface_declare()

std::string blender::gpu::MTLShader::geometry_interface_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 225 of file mtl_shader.hh.

◆ geometry_layout_declare()

std::string blender::gpu::MTLShader::geometry_layout_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 229 of file mtl_shader.hh.

◆ geometry_shader_from_glsl()

void blender::gpu::MTLShader::geometry_shader_from_glsl ( const shader::ShaderCreateInfo & info,
MutableSpan< StringRefNull > sources )
overridevirtual

Implements blender::gpu::Shader.

Definition at line 351 of file mtl_shader.mm.

References MTL_LOG_ERROR.

◆ get_compute_common_state()

const MTLComputePipelineStateCommon & blender::gpu::MTLShader::get_compute_common_state ( )
inline

◆ get_current_pipeline_state()

MTLRenderPipelineStateDescriptor & blender::gpu::MTLShader::get_current_pipeline_state ( )
inline

Definition at line 194 of file mtl_shader.hh.

◆ get_interface()

MTLShaderInterface & blender::gpu::MTLShader::get_interface ( )
inline

◆ get_push_constant_buf()

◆ has_compute_shader_lib()

bool blender::gpu::MTLShader::has_compute_shader_lib ( )
inline

Definition at line 186 of file mtl_shader.hh.

◆ has_parent_shader()

bool blender::gpu::MTLShader::has_parent_shader ( )
inline

Definition at line 190 of file mtl_shader.hh.

References blender::gpu::Shader::parent_shader_.

◆ init()

void blender::gpu::MTLShader::init ( const shader::ShaderCreateInfo & ,
bool  )
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 160 of file mtl_shader.hh.

Referenced by bake_compute_pipeline_state(), and finalize().

◆ is_valid()

◆ patch_create_info()

◆ resources_declare()

std::string blender::gpu::MTLShader::resources_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 213 of file mtl_shader.hh.

◆ unbind()

void blender::gpu::MTLShader::unbind ( )
overridevirtual

◆ uniform_float()

void blender::gpu::MTLShader::uniform_float ( int location,
int comp_len,
int array_size,
const float * data )
overridevirtual

◆ uniform_int()

void blender::gpu::MTLShader::uniform_int ( int location,
int comp_len,
int array_size,
const int * data )
overridevirtual

Implements blender::gpu::Shader.

Definition at line 503 of file mtl_shader.mm.

References blender::data, float, and uniform_float().

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

◆ vertex_interface_declare()

std::string blender::gpu::MTLShader::vertex_interface_declare ( const shader::ShaderCreateInfo & ) const
inlineoverridevirtual

Implements blender::gpu::Shader.

Definition at line 217 of file mtl_shader.hh.

◆ vertex_shader_from_glsl()

void blender::gpu::MTLShader::vertex_shader_from_glsl ( const shader::ShaderCreateInfo & info,
MutableSpan< StringRefNull > sources )
overridevirtual

Implements blender::gpu::Shader.

Definition at line 345 of file mtl_shader.mm.

References blender::gpu::VERTEX.

◆ warm_cache()


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