From 375ee0ba9640c213bba727e85c15493700425557 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sun, 8 Dec 2019 18:08:00 -0300
Subject: [PATCH] Fix draw indexed flag not being cleared for instanced draws,
 also avoid state updates in the middle of a indexed draw

---
 Ryujinx.Graphics.Gpu/Engine/MethodDraw.cs | 30 ++++++++++++++---------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodDraw.cs b/Ryujinx.Graphics.Gpu/Engine/MethodDraw.cs
index b7e8a64b2f..5c5a1deeb2 100644
--- a/Ryujinx.Graphics.Gpu/Engine/MethodDraw.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/MethodDraw.cs
@@ -26,29 +26,35 @@ namespace Ryujinx.Graphics.Gpu.Engine
 
         private void DrawEnd(GpuState state, int argument)
         {
+            if (_instancedDrawPending)
+            {
+                _drawIndexed = false;
+
+                return;
+            }
+
             UpdateState(state);
 
             bool instanced = _vsUsesInstanceId || _isAnyVbInstanced;
 
             if (instanced)
             {
-                if (!_instancedDrawPending)
-                {
-                    _instancedDrawPending = true;
+                _instancedDrawPending = true;
 
-                    _instancedIndexed = _drawIndexed;
+                _instancedIndexed = _drawIndexed;
 
-                    _instancedFirstIndex    = _firstIndex;
-                    _instancedFirstVertex   = state.Get<int>(MethodOffset.FirstVertex);
-                    _instancedFirstInstance = state.Get<int>(MethodOffset.FirstInstance);
+                _instancedFirstIndex    = _firstIndex;
+                _instancedFirstVertex   = state.Get<int>(MethodOffset.FirstVertex);
+                _instancedFirstInstance = state.Get<int>(MethodOffset.FirstInstance);
 
-                    _instancedIndexCount = _indexCount;
+                _instancedIndexCount = _indexCount;
 
-                    var drawState = state.Get<VertexBufferDrawState>(MethodOffset.VertexBufferDrawState);
+                var drawState = state.Get<VertexBufferDrawState>(MethodOffset.VertexBufferDrawState);
 
-                    _instancedDrawStateFirst = drawState.First;
-                    _instancedDrawStateCount = drawState.Count;
-                }
+                _instancedDrawStateFirst = drawState.First;
+                _instancedDrawStateCount = drawState.Count;
+
+                _drawIndexed = false;
 
                 return;
             }