From 7943656bfca79d996af984a1a8f9dadaf63aa079 Mon Sep 17 00:00:00 2001
From: Johannes Specht <jojos_band@gmx.net>
Date: Mon, 4 Sep 2017 02:44:05 +0200
Subject: [PATCH] d3d11: Implement DrawInstancedIndirect for deferred contexts.

---
 dlls/d3d11/device.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 7992e39..047b38f 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -81,6 +81,7 @@ enum deferred_cmd
     DEFERRED_DRAWINDEXEDINSTANCED,      /* draw_indexed_inst_info */
     DEFERRED_DRAWAUTO,
     DEFERRED_DRAWINSTANCED,                 /* draw_instanced_info */
+    DEFERRED_DRAWINSTANCEDINDIRECT,         /* draw_instanced_indirect_info */
 
     DEFERRED_MAP,                       /* map_info */
     DEFERRED_DISPATCH,                  /* dispatch_info */
@@ -265,6 +266,11 @@ struct deferred_call
         } draw_instanced_info;
         struct
         {
+            ID3D11Buffer *buffer;
+            UINT offset;
+        } draw_instanced_indirect_info;
+        struct
+        {
             ID3D11Resource *resource;
             UINT subresource_idx;
             D3D11_MAP map_type;
@@ -605,6 +611,12 @@ static void free_deferred_calls(struct list *commands)
             {
                 break; /* nothing to do */
             }
+            case DEFERRED_DRAWINSTANCEDINDIRECT:
+            {
+                if (call->draw_instanced_indirect_info.buffer)
+                    ID3D11Buffer_Release(call->draw_instanced_indirect_info.buffer);
+                break;
+            }
             case DEFERRED_MAP:
             {
                 ID3D11Resource_Release(call->map_info.resource);
@@ -930,6 +942,13 @@ static void exec_deferred_calls(ID3D11DeviceContext1 *iface, struct list *comman
                         call->draw_instanced_info.start_instance_location);
                 break;
             }
+            case DEFERRED_DRAWINSTANCEDINDIRECT:
+            {
+                ID3D11DeviceContext1_DrawInstancedIndirect(iface,
+                        call->draw_instanced_indirect_info.buffer,
+                        call->draw_instanced_indirect_info.offset);
+                break;
+            }
             case DEFERRED_MAP:
             {
                 D3D11_MAPPED_SUBRESOURCE mapped;
@@ -4619,7 +4638,18 @@ static void STDMETHODCALLTYPE d3d11_deferred_context_DrawIndexedInstancedIndirec
 static void STDMETHODCALLTYPE d3d11_deferred_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
         ID3D11Buffer *buffer, UINT offset)
 {
-    FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
+    struct d3d11_deferred_context *context = impl_from_deferred_ID3D11DeviceContext(iface);
+    struct deferred_call *call;
+
+    TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
+
+    if (!(call = add_deferred_call(context, 0)))
+        return;
+
+    call->cmd = DEFERRED_DRAWINSTANCEDINDIRECT;
+    if (buffer) ID3D11Buffer_AddRef(buffer);
+    call->draw_instanced_indirect_info.buffer = buffer;
+    call->draw_instanced_indirect_info.offset = offset;
 }
 
 static void STDMETHODCALLTYPE d3d11_deferred_context_Dispatch(ID3D11DeviceContext *iface,
-- 
1.9.1

