Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_shader_interface.mm
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return name_buffer_ + offset; | return name_buffer_ + offset; | ||||
| } | } | ||||
| void MTLShaderInterface::init() | void MTLShaderInterface::init() | ||||
| { | { | ||||
| total_attributes_ = 0; | total_attributes_ = 0; | ||||
| total_uniform_blocks_ = 0; | total_uniform_blocks_ = 0; | ||||
| max_uniformbuf_index_ = 0; | |||||
| total_uniforms_ = 0; | total_uniforms_ = 0; | ||||
| total_textures_ = 0; | total_textures_ = 0; | ||||
| max_texture_index_ = -1; | max_texture_index_ = -1; | ||||
| enabled_attribute_mask_ = 0; | enabled_attribute_mask_ = 0; | ||||
| total_vert_stride_ = 0; | total_vert_stride_ = 0; | ||||
| sampler_use_argument_buffer_ = false; | sampler_use_argument_buffer_ = false; | ||||
| sampler_argument_buffer_bind_index_vert_ = -1; | sampler_argument_buffer_bind_index_vert_ = -1; | ||||
| sampler_argument_buffer_bind_index_frag_ = -1; | sampler_argument_buffer_bind_index_frag_ = -1; | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | uint32_t MTLShaderInterface::add_uniform_block(uint32_t name_offset, | ||||
| } | } | ||||
| MTLShaderUniformBlock &uni_block = ubos_[total_uniform_blocks_]; | MTLShaderUniformBlock &uni_block = ubos_[total_uniform_blocks_]; | ||||
| uni_block.name_offset = name_offset; | uni_block.name_offset = name_offset; | ||||
| uni_block.buffer_index = buffer_index; | uni_block.buffer_index = buffer_index; | ||||
| uni_block.size = size; | uni_block.size = size; | ||||
| uni_block.current_offset = 0; | uni_block.current_offset = 0; | ||||
| uni_block.stage_mask = ShaderStage::BOTH; | uni_block.stage_mask = ShaderStage::BOTH; | ||||
| max_uniformbuf_index_ = max_ii(max_uniformbuf_index_, buffer_index); | |||||
| return (total_uniform_blocks_++); | return (total_uniform_blocks_++); | ||||
| } | } | ||||
| void MTLShaderInterface::add_push_constant_block(uint32_t name_offset) | void MTLShaderInterface::add_push_constant_block(uint32_t name_offset) | ||||
| { | { | ||||
| push_constant_block_.name_offset = name_offset; | push_constant_block_.name_offset = name_offset; | ||||
| /* Push constant data block is always uniform buffer index 0. */ | /* Push constant data block is always uniform buffer index 0. */ | ||||
| push_constant_block_.buffer_index = 0; | push_constant_block_.buffer_index = 0; | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | void MTLShaderInterface::add_uniform(uint32_t name_offset, eMTLDataType type, int array_len) | ||||
| BLI_assert_msg( | BLI_assert_msg( | ||||
| current_offset + data_type_size <= push_constant_block_.size, | current_offset + data_type_size <= push_constant_block_.size, | ||||
| "Uniform size and offset sits outside the specified size range for the uniform block"); | "Uniform size and offset sits outside the specified size range for the uniform block"); | ||||
| } | } | ||||
| void MTLShaderInterface::add_texture(uint32_t name_offset, | void MTLShaderInterface::add_texture(uint32_t name_offset, | ||||
| uint32_t texture_slot, | uint32_t texture_slot, | ||||
| eGPUTextureType tex_binding_type, | eGPUTextureType tex_binding_type, | ||||
| eGPUSamplerFormat sampler_format, | |||||
| ShaderStage stage_mask) | ShaderStage stage_mask) | ||||
| { | { | ||||
| BLI_assert(texture_slot >= 0 && texture_slot < GPU_max_textures()); | BLI_assert(texture_slot >= 0 && texture_slot < GPU_max_textures()); | ||||
| BLI_assert(sampler_format < GPU_SAMPLER_TYPE_MAX); | |||||
| if (texture_slot >= 0 && texture_slot < GPU_max_textures()) { | if (texture_slot >= 0 && texture_slot < GPU_max_textures()) { | ||||
| MTLShaderTexture &tex = textures_[texture_slot]; | MTLShaderTexture &tex = textures_[texture_slot]; | ||||
| BLI_assert_msg(tex.used == false, "Texture slot already in-use by another binding"); | BLI_assert_msg(tex.used == false, "Texture slot already in-use by another binding"); | ||||
| tex.name_offset = name_offset; | tex.name_offset = name_offset; | ||||
| tex.slot_index = texture_slot; | tex.slot_index = texture_slot; | ||||
| tex.type = tex_binding_type; | tex.type = tex_binding_type; | ||||
| tex.sampler_format = sampler_format; | |||||
| tex.stage_mask = stage_mask; | tex.stage_mask = stage_mask; | ||||
| tex.used = true; | tex.used = true; | ||||
| total_textures_++; | total_textures_++; | ||||
| max_texture_index_ = max_ii(max_texture_index_, texture_slot); | max_texture_index_ = max_ii(max_texture_index_, texture_slot); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert_msg(false, "Exceeding maximum supported texture count."); | BLI_assert_msg(false, "Exceeding maximum supported texture count."); | ||||
| MTL_LOG_WARNING( | MTL_LOG_WARNING( | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | void MTLShaderInterface::prepare_common_shader_inputs() | ||||
| inputs_ = (ShaderInput *)MEM_callocN(sizeof(ShaderInput) * input_tot_len, __func__); | inputs_ = (ShaderInput *)MEM_callocN(sizeof(ShaderInput) * input_tot_len, __func__); | ||||
| ShaderInput *current_input = inputs_; | ShaderInput *current_input = inputs_; | ||||
| /* Attributes. */ | /* Attributes. */ | ||||
| for (const int attr_index : IndexRange(total_attributes_)) { | for (const int attr_index : IndexRange(total_attributes_)) { | ||||
| MTLShaderInputAttribute &shd_attr = attributes_[attr_index]; | MTLShaderInputAttribute &shd_attr = attributes_[attr_index]; | ||||
| current_input->name_offset = shd_attr.name_offset; | current_input->name_offset = shd_attr.name_offset; | ||||
| current_input->name_hash = BLI_hash_string(this->get_name_at_offset(shd_attr.name_offset)); | current_input->name_hash = BLI_hash_string(this->get_name_at_offset(shd_attr.name_offset)); | ||||
| current_input->location = attr_index; | /* For Metal, we flatten the vertex attribute indices within the shader in order to minimise | ||||
| * complexity. ShaderInput "Location" contains the original attribute location, as can be | |||||
| * fetched using `GPU_shader_get_attribute_info`. ShaderInput binding contains the array index | |||||
| * into the MTLShaderInterface `attributes_` array. */ | |||||
| current_input->location = shd_attr.location; | |||||
| current_input->binding = attr_index; | current_input->binding = attr_index; | ||||
| current_input++; | current_input++; | ||||
| } | } | ||||
| /* UBOs. */ | /* UBOs. */ | ||||
| BLI_assert(&inputs_[attr_len_] >= current_input); | BLI_assert(&inputs_[attr_len_] >= current_input); | ||||
| current_input = &inputs_[attr_len_]; | current_input = &inputs_[attr_len_]; | ||||
| for (const int ubo_index : IndexRange(total_uniform_blocks_)) { | for (const int ubo_index : IndexRange(total_uniform_blocks_)) { | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | const MTLShaderUniformBlock &MTLShaderInterface::get_push_constant_block() const | ||||
| return push_constant_block_; | return push_constant_block_; | ||||
| } | } | ||||
| uint32_t MTLShaderInterface::get_total_uniform_blocks() const | uint32_t MTLShaderInterface::get_total_uniform_blocks() const | ||||
| { | { | ||||
| return total_uniform_blocks_; | return total_uniform_blocks_; | ||||
| } | } | ||||
| uint32_t MTLShaderInterface::get_max_ubo_index() const | |||||
| { | |||||
| return max_uniformbuf_index_; | |||||
| } | |||||
| bool MTLShaderInterface::has_uniform_block(uint32_t block_index) const | bool MTLShaderInterface::has_uniform_block(uint32_t block_index) const | ||||
| { | { | ||||
| return (block_index < total_uniform_blocks_); | return (block_index < total_uniform_blocks_); | ||||
| } | } | ||||
| uint32_t MTLShaderInterface::get_uniform_block_size(uint32_t block_index) const | uint32_t MTLShaderInterface::get_uniform_block_size(uint32_t block_index) const | ||||
| { | { | ||||
| return (block_index < total_uniform_blocks_) ? ubos_[block_index].size : 0; | return (block_index < total_uniform_blocks_) ? ubos_[block_index].size : 0; | ||||
| ▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines | |||||