From 5065767abdadac6cb0b2597ccb1ea47af3549bb4 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sun, 3 Jul 2022 20:47:31 -0500 Subject: [PATCH] VideoBackends:Metal: Avoid submitting draw calls with no vertices/indices --- Source/Core/VideoBackends/Metal/MTLStateTracker.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm index 66ae33b733..b221644640 100644 --- a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm +++ b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm @@ -80,6 +80,10 @@ bool Metal::StateTracker::UsageTracker::PrepareForAllocation(u64 last_draw, size size_t Metal::StateTracker::UsageTracker::Allocate(u64 current_draw, size_t amt) { + // Allocation of zero bytes would make the buffer think it's full + // Zero bytes is useless anyways, so don't mark usage in that case + if (!amt) + return m_pos; if (m_usage.empty() || m_usage.back().drawno != current_draw) m_usage.push_back({current_draw, m_pos}); size_t ret = m_pos; @@ -886,6 +890,8 @@ void Metal::StateTracker::PrepareCompute() void Metal::StateTracker::Draw(u32 base_vertex, u32 num_vertices) { + if (!num_vertices) + return; PrepareRender(); [m_current_render_encoder drawPrimitives:m_state.render_pipeline->Prim() vertexStart:base_vertex @@ -894,6 +900,8 @@ void Metal::StateTracker::Draw(u32 base_vertex, u32 num_vertices) void Metal::StateTracker::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) { + if (!num_indices) // Happens in Metroid Prime, Metal API validation doesn't like this + return; PrepareRender(); [m_current_render_encoder drawIndexedPrimitives:m_state.render_pipeline->Prim() indexCount:num_indices