From fd0ce81e3dcf27aef0d4ad4e8273449a7554a394 Mon Sep 17 00:00:00 2001
From: Johannes Specht <jojos_band@gmx.net>
Date: Mon, 4 Sep 2017 02:41:23 +0200
Subject: [PATCH] d3d11: Implement DrawInstanced for deferred contexts.

---
 dlls/d3d11/device.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 57149f5..7992e39 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -80,6 +80,7 @@ enum deferred_cmd
     DEFERRED_DRAWINDEXED,               /* draw_indexed_info */
     DEFERRED_DRAWINDEXEDINSTANCED,      /* draw_indexed_inst_info */
     DEFERRED_DRAWAUTO,
+    DEFERRED_DRAWINSTANCED,                 /* draw_instanced_info */
 
     DEFERRED_MAP,                       /* map_info */
     DEFERRED_DISPATCH,                  /* dispatch_info */
@@ -257,6 +258,13 @@ struct deferred_call
         } draw_indexed_inst_info;
         struct
         {
+            UINT instance_vertex_count;
+            UINT instance_count;
+            UINT start_vertex_location;
+            UINT start_instance_location;
+        } draw_instanced_info;
+        struct
+        {
             ID3D11Resource *resource;
             UINT subresource_idx;
             D3D11_MAP map_type;
@@ -593,6 +601,10 @@ static void free_deferred_calls(struct list *commands)
             {
                 break; /* nothing to do */
             }
+            case DEFERRED_DRAWINSTANCED:
+            {
+                break; /* nothing to do */
+            }
             case DEFERRED_MAP:
             {
                 ID3D11Resource_Release(call->map_info.resource);
@@ -909,6 +921,15 @@ static void exec_deferred_calls(ID3D11DeviceContext1 *iface, struct list *comman
                 ID3D11DeviceContext1_DrawAuto(iface);
                 break;
             }
+            case DEFERRED_DRAWINSTANCED:
+            {
+                ID3D11DeviceContext1_DrawInstanced(iface,
+                        call->draw_instanced_info.instance_vertex_count,
+                        call->draw_instanced_info.instance_count,
+                        call->draw_instanced_info.start_vertex_location,
+                        call->draw_instanced_info.start_instance_location);
+                break;
+            }
             case DEFERRED_MAP:
             {
                 D3D11_MAPPED_SUBRESOURCE mapped;
@@ -4333,10 +4354,22 @@ static void STDMETHODCALLTYPE d3d11_deferred_context_DrawIndexedInstanced(ID3D11
 static void STDMETHODCALLTYPE d3d11_deferred_context_DrawInstanced(ID3D11DeviceContext *iface,
         UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
 {
-    FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
-            "start_instance_location %u stub!\n",
+    struct d3d11_deferred_context *context = impl_from_deferred_ID3D11DeviceContext(iface);
+    struct deferred_call *call;
+
+    TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
+            "start_instance_location %u.\n",
             iface, instance_vertex_count, instance_count, start_vertex_location,
             start_instance_location);
+
+    if (!(call = add_deferred_call(context, 0)))
+        return;
+
+    call->cmd = DEFERRED_DRAWINSTANCED;
+    call->draw_instanced_info.instance_vertex_count = instance_vertex_count;
+    call->draw_instanced_info.instance_count = instance_count;
+    call->draw_instanced_info.start_vertex_location = start_vertex_location;
+    call->draw_instanced_info.start_instance_location = start_instance_location;
 }
 
 static void STDMETHODCALLTYPE d3d11_deferred_context_GSSetConstantBuffers(ID3D11DeviceContext *iface,
-- 
1.9.1

