Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_shader.mm
| Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | if (this->is_valid()) { | ||||
| pso_cache_.clear(); | pso_cache_.clear(); | ||||
| /* NOTE(Metal): #ShaderInterface deletion is handled in the super destructor `~Shader()`. */ | /* NOTE(Metal): #ShaderInterface deletion is handled in the super destructor `~Shader()`. */ | ||||
| } | } | ||||
| valid_ = false; | valid_ = false; | ||||
| if (shd_builder_ != nullptr) { | if (shd_builder_ != nullptr) { | ||||
| delete shd_builder_; | delete shd_builder_; | ||||
| shd_builder_ = nullptr; | |||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Shader stage creation. | /** \name Shader stage creation. | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (!success) { | ||||
| BLI_assert_msg(false, "Shader translation from GLSL to MSL has failed. \n"); | BLI_assert_msg(false, "Shader translation from GLSL to MSL has failed. \n"); | ||||
| /* Create empty interface to allow shader to be silently used. */ | /* Create empty interface to allow shader to be silently used. */ | ||||
| MTLShaderInterface *mtl_interface = new MTLShaderInterface(this->name_get()); | MTLShaderInterface *mtl_interface = new MTLShaderInterface(this->name_get()); | ||||
| this->set_interface(mtl_interface); | this->set_interface(mtl_interface); | ||||
| /* Release temporary compilation resources. */ | /* Release temporary compilation resources. */ | ||||
| delete shd_builder_; | delete shd_builder_; | ||||
| shd_builder_ = nullptr; | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* Ensure we have a valid shader interface. */ | /* Ensure we have a valid shader interface. */ | ||||
| MTLShaderInterface *mtl_interface = this->get_interface(); | MTLShaderInterface *mtl_interface = this->get_interface(); | ||||
| BLI_assert(mtl_interface != nullptr); | BLI_assert(mtl_interface != nullptr); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (int src_stage = 0; src_stage <= 1; src_stage++) { | ||||
| if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location == | if ([[error localizedDescription] rangeOfString:@"Compilation succeeded"].location == | ||||
| NSNotFound) { | NSNotFound) { | ||||
| NSLog( | NSLog( | ||||
| @"Compile Error - Metal Shader Library (Stage: %d), error %@ \n", src_stage, error); | @"Compile Error - Metal Shader Library (Stage: %d), error %@ \n", src_stage, error); | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| /* Release temporary compilation resources. */ | /* Release temporary compilation resources. */ | ||||
| delete shd_builder_; | delete shd_builder_; | ||||
| shd_builder_ = nullptr; | |||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| MTL_LOG_INFO("Successfully compiled Metal Shader Library (Stage: %d) for shader; %s\n", | MTL_LOG_INFO("Successfully compiled Metal Shader Library (Stage: %d) for shader; %s\n", | ||||
| src_stage, | src_stage, | ||||
| name); | name); | ||||
| BLI_assert(library != nil); | BLI_assert(library != nil); | ||||
| Show All 29 Lines | @autoreleasepool { | ||||
| } | } | ||||
| else { | else { | ||||
| push_constant_data_ = nullptr; | push_constant_data_ = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| /* Release temporary compilation resources. */ | /* Release temporary compilation resources. */ | ||||
| delete shd_builder_; | delete shd_builder_; | ||||
| shd_builder_ = nullptr; | |||||
| return true; | return true; | ||||
| } | } | ||||
| void MTLShader::transform_feedback_names_set(Span<const char *> name_list, | void MTLShader::transform_feedback_names_set(Span<const char *> name_list, | ||||
| const eGPUShaderTFBType geom_type) | const eGPUShaderTFBType geom_type) | ||||
| { | { | ||||
| tf_output_name_list_.clear(); | tf_output_name_list_.clear(); | ||||
| for (int i = 0; i < name_list.size(); i++) { | for (int i = 0; i < name_list.size(); i++) { | ||||
| ▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return push_constant_modified_; | return push_constant_modified_; | ||||
| } | } | ||||
| void MTLShader::push_constant_bindstate_mark_dirty(bool is_dirty) | void MTLShader::push_constant_bindstate_mark_dirty(bool is_dirty) | ||||
| { | { | ||||
| push_constant_modified_ = is_dirty; | push_constant_modified_ = is_dirty; | ||||
| } | } | ||||
| void MTLShader::vertformat_from_shader(GPUVertFormat *format) const | |||||
| { | |||||
| GPU_vertformat_clear(format); | |||||
| const MTLShaderInterface *mtl_interface = static_cast<const MTLShaderInterface *>(interface); | |||||
| for (const uint attr_id : IndexRange(mtl_interface->get_total_attributes())) { | |||||
| const MTLShaderInputAttribute &attr = mtl_interface->get_attribute(attr_id); | |||||
| /* Extract type parameters from Metal type. */ | |||||
| GPUVertCompType comp_type = comp_type_from_vert_format(attr.format); | |||||
| uint comp_len = comp_count_from_vert_format(attr.format); | |||||
| GPUVertFetchMode fetch_mode = fetchmode_from_vert_format(attr.format); | |||||
| GPU_vertformat_attr_add(format, | |||||
| mtl_interface->get_name_at_offset(attr.name_offset), | |||||
| comp_type, | |||||
| comp_len, | |||||
| fetch_mode); | |||||
| } | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name METAL Custom Behavior | /** \name METAL Custom Behavior | ||||
| * \{ */ | * \{ */ | ||||
| void MTLShader::set_vertex_function_name(NSString *vert_function_name) | void MTLShader::set_vertex_function_name(NSString *vert_function_name) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 594 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void MTLShader::ssbo_vertex_fetch_bind_attribute(const MTLSSBOAttribute &ssbo_attr) | void MTLShader::ssbo_vertex_fetch_bind_attribute(const MTLSSBOAttribute &ssbo_attr) | ||||
| { | { | ||||
| /* Fetch attribute. */ | /* Fetch attribute. */ | ||||
| MTLShaderInterface *mtl_interface = this->get_interface(); | MTLShaderInterface *mtl_interface = this->get_interface(); | ||||
| BLI_assert(ssbo_attr.mtl_attribute_index >= 0 && | BLI_assert(ssbo_attr.mtl_attribute_index >= 0 && | ||||
| ssbo_attr.mtl_attribute_index < mtl_interface->get_total_attributes()); | ssbo_attr.mtl_attribute_index < mtl_interface->get_total_attributes()); | ||||
| UNUSED_VARS_NDEBUG(mtl_interface); | |||||
| /* Update bind-mask to verify this attribute has been used. */ | /* Update bind-mask to verify this attribute has been used. */ | ||||
| BLI_assert((ssbo_vertex_attribute_bind_mask_ & (1 << ssbo_attr.mtl_attribute_index)) == | BLI_assert((ssbo_vertex_attribute_bind_mask_ & (1 << ssbo_attr.mtl_attribute_index)) == | ||||
| (1 << ssbo_attr.mtl_attribute_index) && | (1 << ssbo_attr.mtl_attribute_index) && | ||||
| "Attribute has already been bound"); | "Attribute has already been bound"); | ||||
| ssbo_vertex_attribute_bind_mask_ &= ~(1 << ssbo_attr.mtl_attribute_index); | ssbo_vertex_attribute_bind_mask_ &= ~(1 << ssbo_attr.mtl_attribute_index); | ||||
| /* Fetch attribute uniform addresses from cache. */ | /* Fetch attribute uniform addresses from cache. */ | ||||
| ▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines | |||||