From bc87e99378af8515cfd0a409cb209d33a82ea9ae Mon Sep 17 00:00:00 2001
From: Johannes Specht <jojos_band@gmx.net>
Date: Mon, 4 Sep 2017 04:15:31 +0200
Subject: [PATCH] d3d11: Implement SOSetTargets for deferred contexts.

---
 dlls/d3d11/device.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 96dd4e1..728a90b 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -77,6 +77,7 @@ enum deferred_cmd
     DEFERRED_VSSETCONSTANTBUFFERS,      /* constant_buffers_info */
 
     DEFERRED_CSSETUNORDEREDACCESSVIEWS, /* unordered_view */
+    DEFERRED_SOSETTARGETS,              /* so_set_targets_info */
 
     DEFERRED_DRAW,                      /* draw_info */
     DEFERRED_DRAWINDEXED,               /* draw_indexed_info */
@@ -205,6 +206,12 @@ struct deferred_call
         } render_targets_and_unordered_access_views_info;
         struct
         {
+            UINT buffer_count;
+            ID3D11Buffer **buffers;
+            UINT *offsets;
+        } so_set_targets_info;
+        struct
+        {
             ID3D11ComputeShader *shader;
             /* FIXME: add class instances */
         } cs_info;
@@ -647,6 +654,15 @@ static void free_deferred_calls(struct list *commands)
                 }
                 break;
             }
+            case DEFERRED_SOSETTARGETS:
+            {
+                for (i = 0; i < call->so_set_targets_info.buffer_count; i++)
+                {
+                    if (call->so_set_targets_info.buffers[i])
+                        ID3D11Buffer_Release(call->so_set_targets_info.buffers[i]);
+                }
+                break;
+            }
             case DEFERRED_DRAW:
             case DEFERRED_DRAWINDEXED:
             case DEFERRED_DRAWINDEXEDINSTANCED:
@@ -992,6 +1008,14 @@ static void exec_deferred_calls(ID3D11DeviceContext1 *iface, struct list *comman
                         call->unordered_view.num_views, call->unordered_view.views, call->unordered_view.initial_counts);
                 break;
             }
+            case DEFERRED_SOSETTARGETS:
+            {
+                ID3D11DeviceContext1_SOSetTargets(iface,
+                        call->so_set_targets_info.buffer_count,
+                        call->so_set_targets_info.buffers,
+                        call->so_set_targets_info.offsets);
+                break;
+            }
             case DEFERRED_DRAW:
             {
                 ID3D11DeviceContext1_Draw(iface, call->draw_info.count, call->draw_info.start);
@@ -4747,10 +4771,29 @@ static void STDMETHODCALLTYPE d3d11_deferred_context_OMSetDepthStencilState(ID3D
     call->stencil_state_info.stencil_ref = stencil_ref;
 }
 
-static void STDMETHODCALLTYPE d3d11_deferred_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
-        ID3D11Buffer *const *buffers, const UINT *offsets)
+static void STDMETHODCALLTYPE d3d11_deferred_context_SOSetTargets(ID3D11DeviceContext *iface,
+        UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *offsets)
 {
-    FIXME("iface %p, buffer_count %u, buffers %p, offsets %p stub!\n", iface, buffer_count, buffers, offsets);
+    struct d3d11_deferred_context *context = impl_from_deferred_ID3D11DeviceContext(iface);
+    struct deferred_call *call;
+    UINT i;
+
+    TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
+
+    if (!(call = add_deferred_call(context, (sizeof(ID3D11Buffer *) + sizeof(UINT)) * buffer_count)))
+        return;
+
+    call->cmd = DEFERRED_SOSETTARGETS;
+    call->so_set_targets_info.buffer_count = buffer_count;
+    call->so_set_targets_info.buffers = (void *)(call + 1);
+    call->so_set_targets_info.offsets = (void *)&call->so_set_targets_info.buffers[buffer_count];
+
+    for (i = 0; i < buffer_count; i++)
+    {
+        if (buffers[i]) ID3D11Buffer_AddRef(buffers[i]);
+        call->so_set_targets_info.buffers[i] = buffers[i];
+        call->so_set_targets_info.offsets[i] = offsets[i];
+    }
 }
 
 static void STDMETHODCALLTYPE d3d11_deferred_context_DrawAuto(ID3D11DeviceContext *iface)
-- 
1.9.1

