70 if (active_mtl_shader ==
nullptr || !active_mtl_shader->
is_valid() ||
74 const char *
ptr = (active_mtl_shader) ? active_mtl_shader->
name_get() :
nullptr;
76 "MTLImmediate::end -- cannot perform draw as active shader is NULL or invalid (likely "
77 "unimplemented) (shader %p '%s')",
84 id<MTLRenderCommandEncoder> rec = context_->ensure_begin_render_pass();
95 [rec pushDebugGroup:[NSString
96 stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
99 [rec insertDebugSignpost:[NSString stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
126 active_mtl_shader->ssbo_vertex_fetch_bind_attributes_begin();
129 int uniform_ssbo_use_indexed = active_mtl_shader->uni_ssbo_uses_indexed_rendering;
130 BLI_assert_msg(uniform_ssbo_use_indexed != -1,
131 "Expected valid uniform location for ssbo_uses_indexed_rendering.");
132 int uses_indexed_rendering = 0;
133 active_mtl_shader->uniform_int(uniform_ssbo_use_indexed, 1, 1, &uses_indexed_rendering);
138 for (
int i = 0; i <
interface->get_total_attributes(); i++) {
156 attr = check_attribute;
163 "Could not find expected attribute in immediate mode vertex format.");
164 if (attr ==
nullptr) {
166 "MTLImmediate::end Could not find matching attribute '%s' from Shader Interface in "
167 "Vertex Format! - TODO: Bind Dummy attribute",
174 MTLVertexFormat convertedFormat;
176 mtl_shader_attribute.
format,
182 if (can_use_implicit_conversion) {
196 BLI_assert(convertedFormat != MTLVertexFormatInvalid);
206 MTLVertexFormat converted_format;
210 mtl_shader_attribute.
format;
222 "All attributes should be in buffer index zero");
224 mtl_shader_attribute.
index,
227 this->vertex_format.stride,
248 uchar *buffer_data =
reinterpret_cast<uchar *
>(current_allocation_.data);
260 "ssbo_input_prim_type uniform location invalid!");
262 "ssbo_input_vert_count uniform location invalid!");
267 (
const int *)(&this->prim_type));
272 (
const int *)(&this->vertex_idx));
276 if (context_->ensure_render_pipeline_state(mtl_prim_type)) {
289 bool rendered =
false;
299 "Topology emulation for TriangleFan not supported with SSBO Vertex Fetch mode");
306 uint32_t fan_index_count = num_triangles * 3;
313 context_->get_scratchbuffer_manager().scratch_buffer_allocate_range_aligned(
318 for (
int i = 0; i < num_triangles; i++) {
319 index_buffer[a++] = 0;
320 index_buffer[a++] = i + 1;
321 index_buffer[a++] = i + 2;
326 id<MTLBuffer> index_buffer_mtl = nil;
336 context_->ensure_depth_stencil_state(MTLPrimitiveTypeTriangle);
340 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
343 [rec drawIndexedPrimitives:MTLPrimitiveTypeTriangle
344 indexCount:fan_index_count
345 indexType:MTLIndexTypeUInt32
346 indexBuffer:index_buffer_mtl
347 indexBufferOffset:index_buffer_offset];
348 context_->main_command_buffer.register_draw_counters(fan_index_count);
361 MTLPrimitiveType primitive_type = metal_primitive_type_;
366 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
369 context_->ensure_depth_stencil_state(primitive_type);
374 id<MTLBuffer> null_buffer = context_->get_null_buffer();
395 int output_num_verts = num_input_primitives *
401 "Output Vertex count is not compatible with the requested output vertex primitive "
406 vertexCount:output_num_verts];
407 context_->main_command_buffer.register_draw_counters(output_num_verts);
411 [rec drawPrimitives:primitive_type vertexStart:0 vertexCount:vertex_count];
412 context_->main_command_buffer.register_draw_counters(vertex_count);
423 if (current_allocation_.metal_buffer) {
424 [current_allocation_.metal_buffer release];
425 current_allocation_.metal_buffer = nil;
static MTLContext * get()