From a1b44c071715bf9393e2e2da72ea987db7a4146e Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 9 Aug 2017 06:32:43 +0200
Subject: wined3d: Remaining UAV counter changes.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Based on patches by Michael Müller and Józef Kucia.
---
 dlls/d3d11/device.c   | 3 +++
 dlls/wined3d/cs.c     | 2 ++
 dlls/wined3d/device.c | 6 ++++++
 3 files changed, 11 insertions(+)

diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index df754de1..abd7bbcf 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -1075,6 +1075,9 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11D
     TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
             iface, dst_buffer, dst_offset, src_view);
 
+    if (!dst_buffer || !src_view)
+        return;
+
     buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
     uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
 
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 5ea25e99..1417c07b 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -2468,6 +2468,7 @@ static void wined3d_cs_exec_copy_uav_counter(struct wined3d_cs *cs, const void *
     context_release(context);
 
     wined3d_resource_release(&op->buffer->resource);
+    wined3d_resource_release(view->resource);
 }
 
 void wined3d_cs_emit_copy_uav_counter(struct wined3d_cs *cs, struct wined3d_buffer *dst_buffer,
@@ -2482,6 +2483,7 @@ void wined3d_cs_emit_copy_uav_counter(struct wined3d_cs *cs, struct wined3d_buff
     op->view = uav;
 
     wined3d_resource_acquire(&dst_buffer->resource);
+    wined3d_resource_acquire(uav->resource);
 
     wined3d_cs_submit(cs, WINED3D_CS_QUEUE_DEFAULT);
 }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index c90cbdbe..ebe396d7 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4023,6 +4023,12 @@ void CDECL wined3d_device_copy_uav_counter(struct wined3d_device *device,
     TRACE("device %p, dst_buffer %p, offset %u, uav %p.\n",
             device, dst_buffer, offset, uav);
 
+    if (offset + sizeof(GLuint) > dst_buffer->resource.size)
+    {
+        WARN("Offset %u too large.\n", offset);
+        return;
+    }
+
     wined3d_cs_emit_copy_uav_counter(device->cs, dst_buffer, offset, uav);
 }
 
-- 
2.19.1

