Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_shader_interface.mm
| Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* Ensure Size is 16 byte aligned to guarantees alignment rules are satisfied. */ | /* Ensure Size is 16 byte aligned to guarantees alignment rules are satisfied. */ | ||||
| if ((size % 16) != 0) { | 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; | ||||
| /* We offset the buffer binding index by one, as the first slot is reserved for push constant | uni_block.buffer_index = buffer_index; | ||||
| * data. */ | |||||
| uni_block.buffer_index = buffer_index + 1; | |||||
| 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; | ||||
| 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) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | void MTLShaderInterface::prepare_common_shader_inputs() | ||||
| 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_)) { | ||||
| MTLShaderUniformBlock &shd_ubo = ubos_[ubo_index]; | MTLShaderUniformBlock &shd_ubo = ubos_[ubo_index]; | ||||
| current_input->name_offset = shd_ubo.name_offset; | current_input->name_offset = shd_ubo.name_offset; | ||||
| current_input->name_hash = BLI_hash_string(this->get_name_at_offset(shd_ubo.name_offset)); | current_input->name_hash = BLI_hash_string(this->get_name_at_offset(shd_ubo.name_offset)); | ||||
| /* Location refers to the index in the ubos_ array. */ | /* Location refers to the index in the ubos_ array. */ | ||||
| current_input->location = ubo_index; | current_input->location = ubo_index; | ||||
| /* Final binding location refers to the buffer binding index within the shader (Relative to | /* Binding location refers to the UBO bind slot in | ||||
| * MTL_uniform_buffer_base_index). */ | * #MTLContextGlobalShaderPipelineState::ubo_bindings. The buffer bind index [[buffer(N)]] | ||||
| * within the shader will apply an offset for bound vertex buffers and the default uniform | |||||
| * PushConstantBlock. */ | |||||
| current_input->binding = shd_ubo.buffer_index; | current_input->binding = shd_ubo.buffer_index; | ||||
| current_input++; | current_input++; | ||||
| } | } | ||||
| /* Uniforms. */ | /* Uniforms. */ | ||||
| BLI_assert(&inputs_[attr_len_ + ubo_len_] >= current_input); | BLI_assert(&inputs_[attr_len_ + ubo_len_] >= current_input); | ||||
| current_input = &inputs_[attr_len_ + ubo_len_]; | current_input = &inputs_[attr_len_ + ubo_len_]; | ||||
| for (const int uniform_index : IndexRange(total_uniforms_)) { | for (const int uniform_index : IndexRange(total_uniforms_)) { | ||||
| ▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines | |||||