47 vertex_alloc_length++;
55 return reinterpret_cast<uchar *
>(current_allocation_.
data);
65 if (context_ && this->
vertex_idx > 0 && this->shader) {
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')",
95 [rec pushDebugGroup:[NSString
96 stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
99 [rec insertDebugSignpost:[NSString stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
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++) {
155 if (strcmp(name, interface->get_name_at_offset(mtl_shader_attribute.
name_offset)) == 0) {
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",
168 interface->get_name_at_offset(mtl_shader_attribute.
name_offset));
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));
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;
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;
343 [rec drawIndexedPrimitives:MTLPrimitiveTypeTriangle
344 indexCount:fan_index_count
345 indexType:MTLIndexTypeUInt32
346 indexBuffer:index_buffer_mtl
347 indexBufferOffset:index_buffer_offset];
361 MTLPrimitiveType primitive_type = metal_primitive_type_;
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];
411 [rec drawPrimitives:primitive_type vertexStart:0 vertexCount:vertex_count];
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
MINLINE int max_ii(int a, int b)
int gpu_get_prim_count_from_type(uint vertex_len, GPUPrimType prim_type)
void GPU_shader_uniform_int_ex(GPUShader *shader, int location, int length, int array_size, const int *value)
void GPU_shader_bind(GPUShader *shader)
struct GPUShader GPUShader
StateManager * state_manager
void register_draw_counters(int vertex_submission)
MTLRenderPassState & get_render_pass_state()
bool ensure_render_pipeline_state(MTLPrimitiveType prim_type)
id< MTLRenderCommandEncoder > ensure_begin_render_pass()
static MTLContext * get()
id< MTLBuffer > get_null_buffer()
void ensure_depth_stencil_state(MTLPrimitiveType prim_type)
MTLCommandBufferManager main_command_buffer
MTLScratchBufferManager & get_scratchbuffer_manager()
void bind_vertex_buffer(id< MTLBuffer > buffer, uint64_t buffer_offset, uint index)
BufferBindingCached cached_vertex_buffer_bindings[MTL_MAX_BUFFER_BINDINGS]
MTLTemporaryBuffer scratch_buffer_allocate_range_aligned(uint64_t alloc_size, uint alignment)
const char * get_name() const
void ssbo_vertex_fetch_bind_attributes_begin()
void ssbo_vertex_fetch_bind_attribute(const MTLSSBOAttribute &ssbo_attr)
int uni_ssbo_input_prim_type_loc
int get_ssbo_vertex_fetch_output_num_verts() const override
void uniform_int(int location, int comp_len, int array_size, const int *data) override
MTLPrimitiveType get_ssbo_vertex_fetch_output_prim_type()
int uni_ssbo_input_vert_count_loc
int uni_ssbo_uses_indexed_rendering
static int ssbo_vertex_type_to_attr_type(MTLVertexFormat attribute_type)
MTLShaderInterface * get_interface()
void ssbo_vertex_fetch_bind_attributes_end(id< MTLRenderCommandEncoder > active_encoder)
bool get_uses_ssbo_vertex_fetch() const override
MTLRenderPipelineStateDescriptor & get_pipeline_descriptor()
const char *const name_get() const
#define MTL_LOG_WARNING(info,...)
#define MTL_LOG_ERROR(info,...)
#define MTL_SSBO_VERTEX_FETCH_MAX_VBOS
#define MTL_SSBO_VERTEX_FETCH_IBO_INDEX
static Context * unwrap(GPUContext *ctx)
bool mtl_vertex_format_resize(MTLVertexFormat mtl_format, uint32_t components, MTLVertexFormat *r_convertedFormat)
static GPUContext * wrap(Context *ctx)
static MTLPrimitiveType gpu_prim_type_to_metal(GPUPrimType prim_type)
static MTLPrimitiveTopologyClass mtl_prim_type_to_topology_class(MTLPrimitiveType prim_type)
static bool mtl_vertex_count_fits_primitive_type(uint32_t vertex_count, MTLPrimitiveType prim_type)
static bool mtl_needs_topology_emulation(GPUPrimType prim_type)
bool mtl_convert_vertex_format(MTLVertexFormat shader_attrib_format, GPUVertCompType component_type, uint32_t component_length, GPUVertFetchMode fetch_mode, MTLVertexFormat *r_convertedFormat)
unsigned __int64 uint64_t
id< MTLBuffer > metal_buffer
id< MTLBuffer > metal_buffer
void reset_vertex_descriptor()
MTLVertexDescriptor vertex_descriptor
GPUVertFetchMode format_conversion_mode
MTLVertexStepFunction step_function
MTLSSBOAttribute ssbo_attributes[GPU_VERT_ATTR_MAX_LEN]
MTLVertexBufferLayoutDescriptorPSO buffer_layouts[GPU_BATCH_VBO_MAX_LEN+GPU_BATCH_INST_VBO_MAX_LEN]
bool uses_ssbo_vertex_fetch
MTLVertexAttributeDescriptorPSO attributes[GPU_VERT_ATTR_MAX_LEN]