From 2b8aa187dc5d42baae67d42d91589343c2fe6cda Mon Sep 17 00:00:00 2001
From: Johannes Specht <jojos_band@gmx.net>
Date: Mon, 4 Sep 2017 02:21:30 +0200
Subject: [PATCH] d3d11: Implement CopySubresourceRegion for deferred contexts.

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

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 22e2c8f..0c5360a 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -42,6 +42,7 @@ enum deferred_cmd
 
     DEFERRED_COPYRESOURCE,              /* copy_resource_info */
     DEFERRED_SETRESOURCEMINLOD,         /* set_resource_min_lod_info */
+    DEFERRED_COPYSUBRESOURCEREGION,     /* copy_subresource_region_info */
 
     DEFERRED_CSSETSHADER,               /* cs_info */
     DEFERRED_DSSETSHADER,               /* ds_info */
@@ -154,6 +155,17 @@ struct deferred_call
         } set_resource_min_lod_info;
         struct
         {
+            ID3D11Resource *dst_resource;
+            UINT dst_subresource_idx;
+            UINT dst_x;
+            UINT dst_y;
+            UINT dst_z;
+            ID3D11Resource *src_resource;
+            UINT src_subresource_idx;
+            D3D11_BOX *src_box;
+        } copy_subresource_region_info;
+        struct
+        {
             ID3D11ComputeShader *shader;
             /* FIXME: add class instances */
         } cs_info;
@@ -443,6 +455,14 @@ static void free_deferred_calls(struct list *commands)
                     ID3D11Resource_Release(call->set_resource_min_lod_info.resource);
                 break;
             }
+            case DEFERRED_COPYSUBRESOURCEREGION:
+            {
+                if (call->copy_subresource_region_info.dst_resource)
+                    ID3D11Resource_Release(call->copy_subresource_region_info.dst_resource);
+                if (call->copy_subresource_region_info.src_resource)
+                    ID3D11Resource_Release(call->copy_subresource_region_info.src_resource);
+                break;
+            }
             case DEFERRED_CSSETSHADER:
             {
                 if (call->cs_info.shader)
@@ -654,6 +674,19 @@ static void exec_deferred_calls(ID3D11DeviceContext1 *iface, struct list *comman
                         call->set_resource_min_lod_info.min_lod);
                 break;
             }
+            case DEFERRED_COPYSUBRESOURCEREGION:
+            {
+                ID3D11DeviceContext1_CopySubresourceRegion(iface,
+                        call->copy_subresource_region_info.dst_resource,
+                        call->copy_subresource_region_info.dst_subresource_idx,
+                        call->copy_subresource_region_info.dst_x,
+                        call->copy_subresource_region_info.dst_y,
+                        call->copy_subresource_region_info.dst_z,
+                        call->copy_subresource_region_info.src_resource,
+                        call->copy_subresource_region_info.src_subresource_idx,
+                        call->copy_subresource_region_info.src_box);
+                break;
+            }
             case DEFERRED_CSSETSHADER:
             {
                 ID3D11DeviceContext1_CSSetShader(iface, call->cs_info.shader, NULL, 0);
@@ -4555,10 +4588,37 @@ static void STDMETHODCALLTYPE d3d11_deferred_context_CopySubresourceRegion(ID3D1
         ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
         ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
 {
-    FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
-            "src_resource %p, src_subresource_idx %u, src_box %p stub!\n",
+    struct d3d11_deferred_context *context = impl_from_deferred_ID3D11DeviceContext(iface);
+    struct deferred_call *call;
+
+    TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
+            "src_resource %p, src_subresource_idx %u, src_box %p.\n",
             iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
             src_resource, src_subresource_idx, src_box);
+
+    if (!(call = add_deferred_call(context, src_box ? sizeof(D3D11_BOX) : 0)))
+        return;
+
+    if (dst_resource) ID3D11Resource_AddRef(dst_resource);
+    if (src_resource) ID3D11Resource_AddRef(src_resource);
+
+    call->cmd = DEFERRED_COPYSUBRESOURCEREGION;
+    call->copy_subresource_region_info.dst_resource = dst_resource;
+    call->copy_subresource_region_info.dst_subresource_idx = dst_subresource_idx;
+    call->copy_subresource_region_info.dst_x = dst_x;
+    call->copy_subresource_region_info.dst_y = dst_y;
+    call->copy_subresource_region_info.dst_z = dst_z;
+    call->copy_subresource_region_info.src_resource = src_resource;
+    call->copy_subresource_region_info.src_subresource_idx = src_subresource_idx;
+    if (src_box)
+    {
+        call->copy_subresource_region_info.src_box = (void *)(call + 1);
+        *call->copy_subresource_region_info.src_box = *src_box;
+    }
+    else
+    {
+        call->copy_subresource_region_info.src_box = NULL;
+    }
 }
 
 static void STDMETHODCALLTYPE d3d11_deferred_context_CopyResource(ID3D11DeviceContext *iface,
-- 
1.9.1

