88 bool requires_ssbo = (shader->get_uses_ssbo_vertex_fetch());
90 if (
MDI_DISABLED || requires_ssbo || requires_emulation) {
95 if (data_ ==
nullptr) {
102 if (mtl_batch != batch_) {
122 MTLDrawIndexedPrimitivesIndirectArguments *cmd =
123 reinterpret_cast<MTLDrawIndexedPrimitivesIndirectArguments *
>((
char *)data_ +
125 cmd->indexStart = v_first_;
126 cmd->indexCount = v_count_;
127 cmd->instanceCount = i_count;
128 cmd->baseVertex = base_index_;
129 cmd->baseInstance = i_first;
132 MTLDrawPrimitivesIndirectArguments *cmd =
133 reinterpret_cast<MTLDrawPrimitivesIndirectArguments *
>((
char *)data_ + command_offset_);
134 cmd->vertexStart = v_first_;
135 cmd->vertexCount = v_count_;
136 cmd->instanceCount = i_count;
137 cmd->baseInstance = i_first;
140 size_t command_size =
MDI_INDEXED ?
sizeof(MTLDrawIndexedPrimitivesIndirectArguments) :
141 sizeof(MTLDrawPrimitivesIndirectArguments);
143 command_offset_ += command_size;
147 if (command_offset_ + command_size > buffer_size_) {
159 if (command_len_ == 0) {
168 bool can_use_MDI =
false;
176 bool SSBO_MODE = (shader->get_uses_ssbo_vertex_fetch());
184 size_t command_size =
MDI_INDEXED ?
sizeof(MTLDrawIndexedPrimitivesIndirectArguments) :
185 sizeof(MTLDrawPrimitivesIndirectArguments);
186 const bool is_finishing_a_buffer = (command_offset_ + command_size > buffer_size_);
187 can_use_MDI = can_use_MDI && (is_finishing_a_buffer || command_len_ > 2);
191 id<MTLRenderCommandEncoder> rec = batch_->
bind(0);
193 BLI_assert_msg(
false,
"A RenderCommandEncoder should always be available!\n");
204 if (can_use_MDI &&
false) {
214 MTLDrawIndexedPrimitivesIndirectArguments *cmd =
215 (MTLDrawIndexedPrimitivesIndirectArguments *)data_;
217 reinterpret_cast<IndexBuf *
>(batch_->elem));
222 uint32_t index_count = cmd->indexCount;
228 id<MTLBuffer> index_buffer = mtl_elem->
get_index_buffer(final_prim_type, index_count);
234 if (index_buffer != nil) {
239 for (
int i = 0; i < command_len_; i++, cmd++) {
240 [rec drawIndexedPrimitives:mtl_prim_type
241 indexCount:index_count
243 indexBuffer:index_buffer
244 indexBufferOffset:v_first_ofs
245 instanceCount:cmd->instanceCount
246 baseVertex:cmd->baseVertex
247 baseInstance:cmd->baseInstance];
252 BLI_assert_msg(
false,
"Index buffer does not have backing Metal buffer");
256 MTLDrawPrimitivesIndirectArguments *cmd = (MTLDrawPrimitivesIndirectArguments *)data_;
260 BLI_assert_msg(
false,
"topology emulation cases should use fallback.");
267 for (
int i = 0; i < command_len_; i++, cmd++) {
268 [rec drawPrimitives:mtl_prim_type
269 vertexStart:cmd->vertexStart
270 vertexCount:cmd->vertexCount
271 instanceCount:cmd->instanceCount
272 baseInstance:cmd->baseInstance];
void GPU_batch_draw_advanced(blender::gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
static MTLContext * get()
void ensure_depth_stencil_state(MTLPrimitiveType prim_type)
MTLCommandBufferManager main_command_buffer