|
Blender V4.5
|
#include <mtl_shader.hh>
Inherits blender::gpu::Shader.
Additional Inherited Members | |
| Static Public Member Functions inherited from blender::gpu::Shader | |
| static void | set_srgb_uniform (Context *ctx, GPUShader *shader) |
| static void | set_framebuffer_srgb_target (int use_srgb_to_linear) |
| 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 |
| 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 |
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:
Definition at line 166 of file mtl_shader.hh.
| blender::gpu::MTLShader::MTLShader | ( | MTLContext * | ctx, |
| const char * | name ) |
Definition at line 72 of file mtl_shader.mm.
References i, blender::gpu::Shader::name, and blender::gpu::Shader::Shader().
Referenced by MTLShader(), and warm_cache().
| blender::gpu::MTLShader::MTLShader | ( | MTLContext * | ctx, |
| MTLShaderInterface * | interface, | ||
| const char * | name, | ||
| NSString * | input_vertex_source, | ||
| NSString * | input_fragment_source, | ||
| NSString * | vertex_function_name_, | ||
| NSString * | fragment_function_name_ ) |
Definition at line 93 of file mtl_shader.mm.
References BLI_assert, finalize(), blender::gpu::Shader::interface, length(), MTLShader(), blender::gpu::Shader::name, set_fragment_function_name(), set_interface(), set_vertex_function_name(), and shader_source_from_msl().
| blender::gpu::MTLShader::~MTLShader | ( | ) |
Definition at line 112 of file mtl_shader.mm.
References is_valid(), and MEM_freeN().
| MTLComputePipelineStateInstance * blender::gpu::MTLShader::bake_compute_pipeline_state | ( | MTLContext * | ctx, |
| MTLComputePipelineStateDescriptor & | compute_pipeline_descriptor ) |
If Max Total threads per threadgroup tuning parameters are specified, compile with these. This enables the compiler to make informed decisions based on the upper bound of threads issued for a given compute call. This per-shader tuning can reduce the static register memory allocation by reducing the worst-case allocation and increasing thread occupancy.
NOTE: This is only enabled on Apple M1 and M2 GPUs. Apple M3 GPUs feature dynamic caching which controls register allocation dynamically based on the runtime state.
Definition at line 1374 of file mtl_shader.mm.
References blender::gpu::APPLE_GPU_M1, blender::gpu::APPLE_GPU_M2, blender::gpu::MTLComputePipelineStateInstance::base_storage_buffer_index, blender::gpu::MTLComputePipelineStateInstance::base_uniform_buffer_index, BLI_assert, blender::gpu::MTLComputePipelineStateInstance::compute, blender::gpu::Shader::constants, blender::gpu::MTLContext::device, ELEM, error(), blender::gpu::MTLBackend::get_capabilities(), get_interface(), blender::gpu::MTLShaderInterface::get_total_uniform_blocks(), blender::gpu::MTLCapabilities::gpu, init(), is_valid(), MTL_LOG_INFO, MTL_LOG_WARNING, blender::gpu::Shader::name, options, blender::gpu::populate_specialization_constant_values(), blender::gpu::MTLComputePipelineStateInstance::pso, blender::gpu::MTLComputePipelineStateInstance::shader_pso_index, and blender::gpu::MTLComputePipelineStateDescriptor::specialization_state.
Referenced by blender::gpu::MTLContext::ensure_compute_pipeline_state(), and finalize().
| 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 813 of file mtl_shader.mm.
References blender::gpu::MTLContextGlobalShaderPipelineState::alpha_blend_op, blender::gpu::MTLRenderPipelineStateDescriptor::alpha_blend_op, bake_pipeline_state(), blender::gpu::MTLContextGlobalShaderPipelineState::blending_enabled, blender::gpu::MTLRenderPipelineStateDescriptor::blending_enabled, BLI_assert, blender::gpu::MTLContextGlobalShaderPipelineState::clip_distance_enabled, blender::gpu::MTLRenderPipelineStateDescriptor::clipping_plane_enable_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_format, blender::gpu::MTLContextGlobalShaderPipelineState::color_write_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_write_mask, blender::gpu::MTLContext::constants_state, 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(), 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(), 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, blender::gpu::shader::SpecializationConstants::values, and blender::gpu::MTLRenderPipelineStateDescriptor::vertex_descriptor.
| MTLRenderPipelineStateInstance * blender::gpu::MTLShader::bake_pipeline_state | ( | MTLContext * | ctx, |
| MTLPrimitiveTopologyClass | prim_type, | ||
| const MTLRenderPipelineStateDescriptor & | pipeline_descriptor ) |
Definition at line 898 of file mtl_shader.mm.
References blender::gpu::MTLRenderPipelineStateDescriptor::alpha_blend_op, blender::gpu::MTLVertexDescriptor::attributes, blender::gpu::MTLRenderPipelineStateInstance::base_storage_buffer_index, blender::gpu::MTLRenderPipelineStateInstance::base_uniform_buffer_index, blender::gpu::MTLRenderPipelineStateDescriptor::blending_enabled, BLI_assert, BLI_assert_msg, blender::gpu::MTLRenderPipelineStateInstance::buffer_bindings_reflection_data_frag, blender::gpu::MTLRenderPipelineStateInstance::buffer_bindings_reflection_data_vert, blender::gpu::MTLVertexAttributeDescriptorPSO::buffer_index, blender::gpu::MTLVertexDescriptor::buffer_layouts, blender::StringRefNull::c_str(), blender::gpu::MTLContextGlobalShaderPipelineState::clip_distance_enabled, blender::gpu::MTLRenderPipelineStateDescriptor::clipping_plane_enable_mask, blender::gpu::MTLRenderPipelineStateDescriptor::color_attachment_format, blender::gpu::MTLRenderPipelineStateDescriptor::color_write_mask, blender::gpu::Shader::constants, count, blender::gpu::MTLRenderPipelineStateDescriptor::depth_attachment_format, blender::gpu::MTLRenderPipelineStateDescriptor::dest_alpha_blend_factor, blender::gpu::MTLRenderPipelineStateDescriptor::dest_rgb_blend_factor, blender::gpu::MTLContext::device, error(), fabsf, blender::gpu::MTLShaderInputAttribute::format, blender::gpu::MTLVertexAttributeDescriptorPSO::format, blender::gpu::MTLVertexAttributeDescriptorPSO::format_conversion_mode, blender::gpu::MTLRenderPipelineStateInstance::frag, blender::gpu::MTLShaderInterface::get_argument_buffer_bind_index(), blender::gpu::MTLShaderInterface::get_attribute(), get_interface(), blender::gpu::MTLShaderInterface::get_name(), blender::gpu::MTLShaderInterface::get_name_at_offset(), blender::gpu::MTLShaderInterface::get_total_attributes(), blender::gpu::MTLShaderInterface::get_total_uniform_blocks(), GPU_FB_MAX_COLOR_ATTACHMENT, GPU_FETCH_INT_TO_FLOAT_UNIT, GPU_VERT_ATTR_MAX_LEN, blender::gpu::MTLRenderPipelineStateDescriptor::hash(), i, is_valid(), isActive(), blender::gpu::MTLShaderInputAttribute::location, blender::gpu::MTLVertexDescriptor::max_attribute_value, max_ii(), blender::gpu::mtl_format_supports_blending(), MTL_LOG_INFO, MTL_LOG_WARNING, MTL_MAX_BUFFER_BINDINGS, blender::gpu::Shader::name, blender::gpu::MTLShaderInputAttribute::name_offset, blender::gpu::MTLRenderPipelineStateInstance::null_attribute_buffer_index, blender::gpu::MTLVertexDescriptor::num_vert_buffers, blender::gpu::MTLVertexAttributeDescriptorPSO::offset, options, blender::gpu::MTLContext::pipeline_state, blender::gpu::MTLRenderPipelineStateDescriptor::point_size, blender::gpu::populate_specialization_constant_values(), blender::gpu::MTLVertexDescriptor::prim_topology_class, blender::gpu::MTLRenderPipelineStateInstance::prim_type, blender::gpu::Shader::print_log(), printf, blender::gpu::MTLRenderPipelineStateInstance::pso, blender::gpu::MTLRenderPipelineStateInstance::reflection_data_available, reset(), blender::gpu::MTLRenderPipelineStateDescriptor::rgb_blend_op, shader_debug_printf, blender::gpu::MTLRenderPipelineStateInstance::shader_pso_index, blender::gpu::MTLShaderInputAttribute::size, 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::MTLShaderInterface::uses_argument_buffer_for_samplers(), blender::gpu::MTLRenderPipelineStateInstance::vert, and blender::gpu::MTLRenderPipelineStateDescriptor::vertex_descriptor.
Referenced by bake_current_pipeline_state(), and warm_cache().
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 473 of file mtl_shader.mm.
References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLContext::get(), blender::gpu::Shader::interface, is_valid(), MTL_LOG_WARNING, blender::gpu::Shader::name_get(), blender::gpu::MTLContext::pipeline_state, and blender::gpu::MTLContext::specialization_constants_set().
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 318 of file mtl_shader_generator.mm.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 241 of file mtl_shader.mm.
References BLI_assert, i, blender::MutableSpan< T >::size(), and SOURCES_INDEX_VERSION.
|
overridevirtual |
Extract desired custom parameters from CreateInfo.
Implements blender::gpu::Shader.
Definition at line 258 of file mtl_shader.mm.
References blender::gpu::ANY, bake_compute_pipeline_state(), BLI_assert, BLI_assert_msg, BLI_assert_unreachable, blender::gpu::shader::ShaderCreateInfo::builtins_, blender::gpu::COMPUTE, blender::gpu::Shader::constants, datatoc_mtl_shader_common_msl, error(), blender::gpu::FRAGMENT, get_interface(), blender::gpu::MTLShaderInterface::get_push_constant_block(), init(), is_valid(), length(), MEM_callocN(), MTL_LOG_ERROR, blender::gpu::Shader::name, blender::gpu::Shader::name_get(), options, blender::gpu::Shader::print_log(), push_constant_bindstate_mark_dirty(), set_interface(), blender::gpu::MTLShaderBufferBlock::size, str, blender::gpu::shader::ShaderCreateInfo::subpass_inputs_, blender::gpu::shader::TEXTURE_ATOMIC, blender::gpu::to_string(), and blender::gpu::VERTEX.
Referenced by MTLShader().
| bool blender::gpu::MTLShader::finalize_compute | ( | const shader::ShaderCreateInfo * | info | ) |
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 279 of file mtl_shader_generator.mm.
References blender::gpu::shader::ShaderCreateInfo::fragment_outputs_, input, output, blender::gpu::shader::ShaderCreateInfo::subpass_inputs_, and blender::gpu::to_string().
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 223 of file mtl_shader.mm.
References BLI_assert, i, blender::MutableSpan< T >::size(), and SOURCES_INDEX_VERSION.
|
overridevirtual |
Implements blender::gpu::Shader.
References data, and blender::gpu::Shader::interface.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 312 of file mtl_shader_generator.mm.
References BLI_assert_msg.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 218 of file mtl_shader.mm.
References MTL_LOG_ERROR.
|
inline |
Definition at line 312 of file mtl_shader.hh.
|
inline |
Definition at line 263 of file mtl_shader.hh.
|
inline |
Definition at line 267 of file mtl_shader.hh.
Referenced by bake_compute_pipeline_state(), bake_pipeline_state(), blender::gpu::MTLImmediate::end(), finalize(), uniform_float(), and uniform_int().
|
inline |
Definition at line 271 of file mtl_shader.hh.
| bool blender::gpu::MTLShader::get_push_constant_is_dirty | ( | ) |
Definition at line 671 of file mtl_shader.mm.
|
inline |
Definition at line 255 of file mtl_shader.hh.
|
inline |
Definition at line 259 of file mtl_shader.hh.
References blender::gpu::Shader::parent_shader_.
|
inlineoverridevirtual |
Implements blender::gpu::Shader.
Definition at line 237 of file mtl_shader.hh.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 190 of file mtl_shader.mm.
Referenced by bake_compute_pipeline_state(), and finalize().
|
inline |
Definition at line 251 of file mtl_shader.hh.
Referenced by bake_compute_pipeline_state(), bake_current_pipeline_state(), bake_pipeline_state(), bind(), blender::gpu::MTLImmediate::end(), finalize(), uniform_float(), uniform_int(), and ~MTLShader().
| void blender::gpu::MTLShader::push_constant_bindstate_mark_dirty | ( | bool | is_dirty | ) |
Definition at line 676 of file mtl_shader.mm.
Referenced by finalize(), uniform_float(), and uniform_int().
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 234 of file mtl_shader_generator.mm.
References blender::gpu::shader::ShaderCreateInfo::batch_resources_, blender::gpu::shader::ShaderCreateInfo::geometry_resources_, blender::gpu::shader::ShaderCreateInfo::pass_resources_, and blender::gpu::print_resource().
| void blender::gpu::MTLShader::set_compute_function_name | ( | NSString * | compute_function_name | ) |
Definition at line 729 of file mtl_shader.mm.
| void blender::gpu::MTLShader::set_fragment_function_name | ( | NSString * | fragment_function_name | ) |
Definition at line 724 of file mtl_shader.mm.
Referenced by MTLShader().
| void blender::gpu::MTLShader::set_interface | ( | MTLShaderInterface * | interface | ) |
Definition at line 750 of file mtl_shader.mm.
References BLI_assert, and blender::gpu::Shader::interface.
Referenced by finalize(), and MTLShader().
| void blender::gpu::MTLShader::set_vertex_function_name | ( | NSString * | vetex_function_name | ) |
Definition at line 719 of file mtl_shader.mm.
Referenced by MTLShader().
| void blender::gpu::MTLShader::shader_compute_source_from_msl | ( | NSString * | input_compute_source | ) |
Definition at line 743 of file mtl_shader.mm.
References BLI_assert.
| void blender::gpu::MTLShader::shader_source_from_msl | ( | NSString * | input_vertex_source, |
| NSString * | input_fragment_source ) |
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 488 of file mtl_shader.mm.
References blender::gpu::MTLContextGlobalShaderPipelineState::active_shader, blender::gpu::MTLContext::get(), and blender::gpu::MTLContext::pipeline_state.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 494 of file mtl_shader.mm.
References blender::gpu::MTLShaderUniform::array_len, BLI_assert, BLI_assert_msg, blender::gpu::MTLShaderUniform::byte_offset, data, get_interface(), blender::gpu::MTLShaderInterface::get_total_uniforms(), blender::gpu::MTLShaderInterface::get_uniform(), i, is_valid(), MTL_DATATYPE_FLOAT3, MTL_DATATYPE_FLOAT3x3, MTL_LOG_WARNING, blender::gpu::Shader::name_get(), push_constant_bindstate_mark_dirty(), shader_debug_printf, blender::gpu::MTLShaderUniform::size_in_bytes, and blender::gpu::MTLShaderUniform::type.
|
overridevirtual |
Determine size of data to copy.
Implements blender::gpu::Shader.
Definition at line 597 of file mtl_shader.mm.
References BLI_assert, BLI_assert_msg, blender::gpu::MTLShaderUniform::byte_offset, data, get_interface(), blender::gpu::MTLShaderInterface::get_total_textures(), blender::gpu::MTLShaderInterface::get_total_uniforms(), blender::gpu::MTLShaderInterface::get_uniform(), is_valid(), mtl_get_data_type_alignment(), MTL_LOG_WARNING, blender::gpu::Shader::name_get(), ptr, push_constant_bindstate_mark_dirty(), blender::gpu::MTLShaderUniform::size_in_bytes, and blender::gpu::MTLShaderUniform::type.
Referenced by blender::gpu::MTLContext::ensure_texture_bindings(), and blender::gpu::MTLContext::ensure_texture_bindings().
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 264 of file mtl_shader_generator.mm.
References ShaderCreateInfo::VertIn::name, blender::gpu::to_string(), ShaderCreateInfo::VertIn::type, and blender::gpu::shader::ShaderCreateInfo::vertex_inputs_.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 201 of file mtl_shader.mm.
References BLI_assert, i, blender::MutableSpan< T >::size(), and SOURCES_INDEX_VERSION.
|
overridevirtual |
Implements blender::gpu::Shader.
Definition at line 683 of file mtl_shader.mm.
References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), bake_pipeline_state(), blender::gpu::MTLContext::get(), i, min_ii(), MTLShader(), blender::gpu::Shader::parent_shader_, blender::gpu::MTLRenderPipelineStateInstance::prim_type, and blender::Vector< T, InlineBufferCapacity, Allocator >::size().