68 if (active_mtl_shader ==
nullptr || !active_mtl_shader->
is_valid() ||
74 "MTLImmediate::end -- cannot perform draw as active shader is NULL or invalid (likely "
75 "unimplemented) (shader %p '%s')",
82 id<MTLRenderCommandEncoder> rec = context_->ensure_begin_render_pass();
93 [rec pushDebugGroup:[NSString
94 stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
97 [rec insertDebugSignpost:[NSString stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
121 for (
int i = 0;
i <
interface->get_total_attributes();
i++) {
130 for (uint32_t a_idx = 0; a_idx < this->
vertex_format.attr_len && attr ==
nullptr; a_idx++) {
134 for (uint32_t n_idx = 0; n_idx < check_attribute->
name_len; n_idx++) {
139 attr = check_attribute;
146 "Could not find expected attribute in immediate mode vertex format.");
147 if (attr ==
nullptr) {
149 "MTLImmediate::end Could not find matching attribute '%s' from Shader Interface in "
150 "Vertex Format! - TODO: Bind Dummy attribute",
157 MTLVertexFormat convertedFormat;
159 mtl_shader_attribute.
format,
165 if (can_use_implicit_conversion) {
179 BLI_assert(convertedFormat != MTLVertexFormatInvalid);
212 uchar *buffer_data =
reinterpret_cast<uchar *
>(current_allocation_.data);
226 if (context_->ensure_render_pipeline_state(mtl_prim_type)) {
239 bool rendered =
false;
248 uint32_t num_triangles =
max_ii(base_vert_count - 2, 0);
249 uint32_t fan_index_count = num_triangles * 3;
252 uint32_t alloc_size =
sizeof(uint32_t) * fan_index_count;
253 uint32_t *index_buffer =
nullptr;
256 context_->get_scratchbuffer_manager().scratch_buffer_allocate_range_aligned(
258 index_buffer = (uint32_t *)allocation.
data;
261 for (
int i = 0;
i < num_triangles;
i++) {
262 index_buffer[a++] = 0;
263 index_buffer[a++] =
i + 1;
264 index_buffer[a++] =
i + 2;
269 id<MTLBuffer> index_buffer_mtl = nil;
279 context_->ensure_depth_stencil_state(MTLPrimitiveTypeTriangle);
283 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
286 [rec drawIndexedPrimitives:MTLPrimitiveTypeTriangle
287 indexCount:fan_index_count
288 indexType:MTLIndexTypeUInt32
289 indexBuffer:index_buffer_mtl
290 indexBufferOffset:index_buffer_offset];
291 context_->main_command_buffer.register_draw_counters(fan_index_count);
304 MTLPrimitiveType primitive_type = metal_primitive_type_;
309 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
312 context_->ensure_depth_stencil_state(primitive_type);
319 [rec drawPrimitives:primitive_type vertexStart:0 vertexCount:vertex_count];
320 context_->main_command_buffer.register_draw_counters(vertex_count);
329 context_->get_scratchbuffer_manager().unbind_as_ssbo();
342 if (current_allocation_.metal_buffer) {
343 [current_allocation_.metal_buffer release];
344 current_allocation_.metal_buffer = nil;
static MTLContext * get()