Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_context.mm
| Show First 20 Lines • Show All 989 Lines • ▼ Show 20 Lines | bool MTLContext::ensure_uniform_buffer_bindings( | ||||
| /* Iterate through expected UBOs in the shader interface, and check if the globally bound ones | /* Iterate through expected UBOs in the shader interface, and check if the globally bound ones | ||||
| * match. This is used to support the gpu_uniformbuffer module, where the uniform data is global, | * match. This is used to support the gpu_uniformbuffer module, where the uniform data is global, | ||||
| * and not owned by the shader instance. */ | * and not owned by the shader instance. */ | ||||
| for (const uint ubo_index : IndexRange(shader_interface->get_total_uniform_blocks())) { | for (const uint ubo_index : IndexRange(shader_interface->get_total_uniform_blocks())) { | ||||
| const MTLShaderUniformBlock &ubo = shader_interface->get_uniform_block(ubo_index); | const MTLShaderUniformBlock &ubo = shader_interface->get_uniform_block(ubo_index); | ||||
| if (ubo.buffer_index >= 0) { | if (ubo.buffer_index >= 0) { | ||||
| const uint32_t buffer_index = ubo.buffer_index; | /* Uniform Buffer index offset by 1 as the first shader buffer binding slot is reserved for | ||||
| * the uniform PushConstantBlock. */ | |||||
| const uint32_t buffer_index = ubo.buffer_index + 1; | |||||
| int ubo_offset = 0; | int ubo_offset = 0; | ||||
| id<MTLBuffer> ubo_buffer = nil; | id<MTLBuffer> ubo_buffer = nil; | ||||
| int ubo_size = 0; | int ubo_size = 0; | ||||
| bool bind_dummy_buffer = false; | bool bind_dummy_buffer = false; | ||||
| if (this->pipeline_state.ubo_bindings[buffer_index].bound) { | if (this->pipeline_state.ubo_bindings[ubo_index].bound) { | ||||
| /* Fetch UBO global-binding properties from slot. */ | /* Fetch UBO global-binding properties from slot. */ | ||||
| ubo_offset = 0; | ubo_offset = 0; | ||||
| ubo_buffer = this->pipeline_state.ubo_bindings[buffer_index].ubo->get_metal_buffer( | ubo_buffer = this->pipeline_state.ubo_bindings[ubo_index].ubo->get_metal_buffer( | ||||
| &ubo_offset); | &ubo_offset); | ||||
| ubo_size = this->pipeline_state.ubo_bindings[buffer_index].ubo->get_size(); | ubo_size = this->pipeline_state.ubo_bindings[ubo_index].ubo->get_size(); | ||||
| /* Use dummy zero buffer if no buffer assigned -- this is an optimization to avoid | /* Use dummy zero buffer if no buffer assigned -- this is an optimization to avoid | ||||
| * allocating zero buffers. */ | * allocating zero buffers. */ | ||||
| if (ubo_buffer == nil) { | if (ubo_buffer == nil) { | ||||
| bind_dummy_buffer = true; | bind_dummy_buffer = true; | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(ubo_buffer != nil); | BLI_assert(ubo_buffer != nil); | ||||
| ▲ Show 20 Lines • Show All 752 Lines • Show Last 20 Lines | |||||