Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_shader_interface.mm
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | void MTLShaderInterface::init() | ||||
| total_uniform_blocks_ = 0; | total_uniform_blocks_ = 0; | ||||
| max_uniformbuf_index_ = 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; | for (int i = 0; i < ARRAY_SIZE(sampler_argument_buffer_bind_index_); i++) { | ||||
| sampler_argument_buffer_bind_index_frag_ = -1; | sampler_argument_buffer_bind_index_[i] = -1; | ||||
| } | |||||
fclem: It does raise the question as to why not just add `sampler_argument_buffer_bind_index_comp_`? I… | |||||
Not Done Inline ActionsYeah, likely best to just use an extra parameter. The original thinking was to avoid diverging the functions which fetch the offset, but likely introducing more confusion than solving. MichaelPW: Yeah, likely best to just use an extra parameter. The original thinking was to avoid diverging… | |||||
| /* NULL initialize uniform location markers for builtins. */ | /* NULL initialize uniform location markers for builtins. */ | ||||
| for (const int u : IndexRange(GPU_NUM_UNIFORMS)) { | for (const int u : IndexRange(GPU_NUM_UNIFORMS)) { | ||||
| builtins_[u] = -1; | builtins_[u] = -1; | ||||
| } | } | ||||
| for (const int ubo : IndexRange(GPU_NUM_UNIFORM_BLOCKS)) { | for (const int ubo : IndexRange(GPU_NUM_UNIFORM_BLOCKS)) { | ||||
| builtin_blocks_[ubo] = -1; | builtin_blocks_[ubo] = -1; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if ((size % 16) != 0) { | ||||
| size += 16 - (size % 16); | size += 16 - (size % 16); | ||||
| } | } | ||||
| 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::ANY; | ||||
| max_uniformbuf_index_ = max_ii(max_uniformbuf_index_, buffer_index); | 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; | ||||
| /* Size starts at zero and grows as uniforms are added. */ | /* Size starts at zero and grows as uniforms are added. */ | ||||
| push_constant_block_.size = 0; | push_constant_block_.size = 0; | ||||
| push_constant_block_.current_offset = 0; | push_constant_block_.current_offset = 0; | ||||
| push_constant_block_.stage_mask = ShaderStage::BOTH; | push_constant_block_.stage_mask = ShaderStage::ANY; | ||||
| } | } | ||||
| void MTLShaderInterface::add_uniform(uint32_t name_offset, eMTLDataType type, int array_len) | void MTLShaderInterface::add_uniform(uint32_t name_offset, eMTLDataType type, int array_len) | ||||
| { | { | ||||
| BLI_assert(array_len > 0); | BLI_assert(array_len > 0); | ||||
| BLI_assert(total_uniforms_ < MTL_MAX_UNIFORMS_PER_BLOCK); | BLI_assert(total_uniforms_ < MTL_MAX_UNIFORMS_PER_BLOCK); | ||||
| if (total_uniforms_ >= MTL_MAX_UNIFORMS_PER_BLOCK) { | if (total_uniforms_ >= MTL_MAX_UNIFORMS_PER_BLOCK) { | ||||
| MTL_LOG_WARNING( | MTL_LOG_WARNING( | ||||
| ▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | void MTLShaderInterface::prepare_common_shader_inputs() | ||||
| current_input = &inputs_[attr_len_ + ubo_len_ + uniform_len_]; | current_input = &inputs_[attr_len_ + ubo_len_ + uniform_len_]; | ||||
| /* Map builtin uniform indices to uniform binding locations. */ | /* Map builtin uniform indices to uniform binding locations. */ | ||||
| this->map_builtins(); | this->map_builtins(); | ||||
| } | } | ||||
| void MTLShaderInterface::set_sampler_properties(bool use_argument_buffer, | void MTLShaderInterface::set_sampler_properties(bool use_argument_buffer, | ||||
| uint32_t argument_buffer_bind_index_vert, | uint32_t argument_buffer_bind_index_vert, | ||||
| uint32_t argument_buffer_bind_index_frag) | uint32_t argument_buffer_bind_index_frag, | ||||
| uint32_t argument_buffer_bind_index_compute) | |||||
| { | { | ||||
| sampler_use_argument_buffer_ = use_argument_buffer; | sampler_use_argument_buffer_ = use_argument_buffer; | ||||
| sampler_argument_buffer_bind_index_vert_ = argument_buffer_bind_index_vert; | sampler_argument_buffer_bind_index_[get_shader_stage_index(ShaderStage::VERTEX)] = | ||||
| sampler_argument_buffer_bind_index_frag_ = argument_buffer_bind_index_frag; | argument_buffer_bind_index_vert; | ||||
| sampler_argument_buffer_bind_index_[get_shader_stage_index(ShaderStage::FRAGMENT)] = | |||||
| argument_buffer_bind_index_frag; | |||||
| sampler_argument_buffer_bind_index_[get_shader_stage_index(ShaderStage::COMPUTE)] = | |||||
| argument_buffer_bind_index_compute; | |||||
| } | } | ||||
| /* Attributes. */ | /* Attributes. */ | ||||
| const MTLShaderInputAttribute &MTLShaderInterface::get_attribute(uint index) const | const MTLShaderInputAttribute &MTLShaderInterface::get_attribute(uint index) const | ||||
| { | { | ||||
| BLI_assert(index < MTL_MAX_VERTEX_INPUT_ATTRIBUTES); | BLI_assert(index < MTL_MAX_VERTEX_INPUT_ATTRIBUTES); | ||||
| BLI_assert(index < get_total_attributes()); | BLI_assert(index < get_total_attributes()); | ||||
| return attributes_[index]; | return attributes_[index]; | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | uint32_t MTLShaderInterface::get_total_textures() const | ||||
| return total_textures_; | return total_textures_; | ||||
| } | } | ||||
| uint32_t MTLShaderInterface::get_max_texture_index() const | uint32_t MTLShaderInterface::get_max_texture_index() const | ||||
| { | { | ||||
| return max_texture_index_; | return max_texture_index_; | ||||
| } | } | ||||
| bool MTLShaderInterface::get_use_argument_buffer_for_samplers( | bool MTLShaderInterface::uses_argument_buffer_for_samplers() const | ||||
| int *vertex_arg_buffer_bind_index, int *fragment_arg_buffer_bind_index) const | |||||
| { | { | ||||
| /* Returns argument buffer binding slot for each shader stage. | |||||
| * The exact bind slot may be different, as each stage has different buffer inputs. */ | |||||
| *vertex_arg_buffer_bind_index = sampler_argument_buffer_bind_index_vert_; | |||||
| *fragment_arg_buffer_bind_index = sampler_argument_buffer_bind_index_frag_; | |||||
| return sampler_use_argument_buffer_; | return sampler_use_argument_buffer_; | ||||
| } | } | ||||
| int MTLShaderInterface::get_argument_buffer_bind_index(ShaderStage stage) const | |||||
| { | |||||
| return sampler_argument_buffer_bind_index_[get_shader_stage_index(stage)]; | |||||
| } | |||||
| id<MTLArgumentEncoder> MTLShaderInterface::find_argument_encoder(int buffer_index) const | id<MTLArgumentEncoder> MTLShaderInterface::find_argument_encoder(int buffer_index) const | ||||
| { | { | ||||
| id encoder = nil; | id encoder = nil; | ||||
| for (const int i : IndexRange(ARGUMENT_ENCODERS_CACHE_SIZE)) { | for (const int i : IndexRange(ARGUMENT_ENCODERS_CACHE_SIZE)) { | ||||
| encoder = arg_encoders_[i].buffer_index == buffer_index ? arg_encoders_[i].encoder : encoder; | encoder = arg_encoders_[i].buffer_index == buffer_index ? arg_encoders_[i].encoder : encoder; | ||||
| } | } | ||||
| return encoder; | return encoder; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines | |||||
It does raise the question as to why not just add sampler_argument_buffer_bind_index_comp_? I don't think saving space inside MTLShaderInterface is critical.