From 116636717ee333aff38b77530fbcb885ad46f0a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Tue, 24 Jan 2017 04:48:56 +0100
Subject: [PATCH] d3d11: Implement CSSetUnorderedAccessViews for deferred
 contexts.

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

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index b1f148a..3c475e7 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -58,6 +58,8 @@ enum deferred_cmd
     DEFERRED_PSSETCONSTANTBUFFERS,      /* constant_buffers_info */
     DEFERRED_VSSETCONSTANTBUFFERS,      /* constant_buffers_info */
 
+    DEFERRED_CSSETUNORDEREDACCESSVIEWS, /* unordered_view */
+
     DEFERRED_DRAWINDEXED,               /* draw_indexed_info */
     DEFERRED_DRAWINDEXEDINSTANCED,      /* draw_indexed_inst_info */
 
@@ -166,6 +168,13 @@ struct deferred_call
         } constant_buffers_info;
         struct
         {
+            UINT start_slot;
+            UINT num_views;
+            ID3D11UnorderedAccessView **views;
+            UINT *initial_counts;
+        } unordered_view;
+        struct
+        {
             UINT count;
             UINT start_index;
             INT  base_vertex;
@@ -426,6 +435,15 @@ static void free_deferred_calls(struct list *commands)
                 }
                 break;
             }
+            case DEFERRED_CSSETUNORDEREDACCESSVIEWS:
+            {
+                for (i = 0; i < call->unordered_view.num_views; i++)
+                {
+                    if (call->unordered_view.views[i])
+                        ID3D11UnorderedAccessView_Release(call->unordered_view.views[i]);
+                }
+                break;
+            }
             case DEFERRED_DRAWINDEXED:
             case DEFERRED_DRAWINDEXEDINSTANCED:
             {
@@ -595,6 +613,12 @@ static void exec_deferred_calls(ID3D11DeviceContext1 *iface, struct list *comman
                         call->constant_buffers_info.num_buffers, call->constant_buffers_info.buffers);
                 break;
             }
+            case DEFERRED_CSSETUNORDEREDACCESSVIEWS:
+            {
+                ID3D11DeviceContext1_CSSetUnorderedAccessViews(iface, call->unordered_view.start_slot,
+                        call->unordered_view.num_views, call->unordered_view.views, call->unordered_view.initial_counts);
+                break;
+            }
             case DEFERRED_DRAWINDEXED:
             {
                 ID3D11DeviceContext1_DrawIndexed(iface, call->draw_indexed_info.count,
@@ -4456,8 +4480,27 @@ static void STDMETHODCALLTYPE d3d11_deferred_context_CSSetShaderResources(ID3D11
 static void STDMETHODCALLTYPE d3d11_deferred_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
         UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
 {
-    FIXME("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p stub!\n",
+    struct d3d11_deferred_context *context = impl_from_deferred_ID3D11DeviceContext(iface);
+    struct deferred_call *call;
+    int i;
+
+    TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
             iface, start_slot, view_count, views, initial_counts);
+
+    if (!(call = add_deferred_call(context, view_count * (sizeof(*views) + sizeof(UINT)))))
+        return;
+
+    call->cmd = DEFERRED_CSSETUNORDEREDACCESSVIEWS;
+    call->unordered_view.start_slot = start_slot;
+    call->unordered_view.num_views = view_count;
+    call->unordered_view.views = (void *)(call + 1);
+    call->unordered_view.initial_counts = (void *)&call->unordered_view.views[view_count];
+    for (i = 0; i < view_count; i++)
+    {
+        if (views[i]) ID3D11UnorderedAccessView_AddRef(views[i]);
+        call->unordered_view.views[i] = views[i];
+        call->unordered_view.initial_counts[i] = initial_counts[i];
+    }
 }
 
 static void STDMETHODCALLTYPE d3d11_deferred_context_CSSetShader(ID3D11DeviceContext *iface,
-- 
1.9.1

