From 213c4f62372760c1a3bdcd6f1c03bc9f1926c5be Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 8 Feb 2017 19:35:36 +0100
Subject: Revert "wined3d: Implement wined3d_buffer_upload_data() on top of
 wined3d_buffer_upload_ranges()."

This reverts commit e2dbbec1af8ae2ea8813148d56e14c8c211ee334.
---
 dlls/wined3d/buffer.c          | 30 +++++++++++++++++++-----------
 dlls/wined3d/cs.c              | 13 +++----------
 dlls/wined3d/wined3d_private.h |  2 +-
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index e953e9ad215..d81387291f1 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -532,7 +532,7 @@ ULONG CDECL wined3d_buffer_incref(struct wined3d_buffer *buffer)
 
 /* Context activation is done by the caller. */
 static void wined3d_buffer_upload_ranges(struct wined3d_buffer *buffer, struct wined3d_context *context,
-        const void *data, unsigned int data_offset, unsigned int range_count, const struct wined3d_map_range *ranges)
+        const void *data, unsigned int range_count, const struct wined3d_map_range *ranges)
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
     const struct wined3d_map_range *range;
@@ -543,7 +543,7 @@ static void wined3d_buffer_upload_ranges(struct wined3d_buffer *buffer, struct w
     {
         range = &ranges[range_count];
         GL_EXTCALL(glBufferSubData(buffer->buffer_type_hint,
-                range->offset, range->size, (BYTE *)data + range->offset - data_offset));
+                range->offset, range->size, (BYTE *)data + range->offset));
     }
     checkGLcall("glBufferSubData");
 }
@@ -599,7 +599,7 @@ static void buffer_conversion_upload(struct wined3d_buffer *buffer, struct wined
         }
     }
 
-    wined3d_buffer_upload_ranges(buffer, context, data, 0, buffer->modified_areas, buffer->maps);
+    wined3d_buffer_upload_ranges(buffer, context, data, buffer->modified_areas, buffer->maps);
 
     HeapFree(GetProcessHeap(), 0, data);
 }
@@ -683,7 +683,7 @@ BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer,
         case WINED3D_LOCATION_BUFFER:
             if (!buffer->conversion_map)
                 wined3d_buffer_upload_ranges(buffer, context, buffer->resource.heap_memory,
-                        0, buffer->modified_areas, buffer->maps);
+                        buffer->modified_areas, buffer->maps);
             else
                 buffer_conversion_upload(buffer, context);
             break;
@@ -1215,23 +1215,31 @@ void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_off
     wined3d_buffer_invalidate_range(dst_buffer, ~dst_location, dst_offset, size);
 }
 
-void wined3d_buffer_upload_data(struct wined3d_buffer *buffer, struct wined3d_context *context,
+HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
         const struct wined3d_box *box, const void *data)
 {
-    struct wined3d_map_range range;
+    UINT offset, size;
+    HRESULT hr;
+    BYTE *ptr;
 
     if (box)
     {
-        range.offset = box->left;
-        range.size = box->right - box->left;
+        offset = box->left;
+        size = box->right - box->left;
     }
     else
     {
-        range.offset = 0;
-        range.size = buffer->resource.size;
+        offset = 0;
+        size = buffer->resource.size;
     }
 
-    wined3d_buffer_upload_ranges(buffer, context, data, range.offset, 1, &range);
+    if (FAILED(hr = wined3d_buffer_map(buffer, offset, size, &ptr, 0)))
+        return hr;
+
+    memcpy(ptr, data, size);
+
+    wined3d_buffer_unmap(buffer);
+    return WINED3D_OK;
 }
 
 static ULONG buffer_resource_incref(struct wined3d_resource *resource)
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index a76598ff4ca..f521475d3af 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -2107,18 +2107,11 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi
     if (op->resource->type == WINED3D_RTYPE_BUFFER)
     {
         struct wined3d_buffer *buffer = buffer_from_resource(op->resource);
+        HRESULT hr;
 
-        context = context_acquire(op->resource->device, NULL, 0);
-        if (!wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER))
-        {
-            ERR("Failed to load buffer location.\n");
-            context_release(context);
-            goto done;
-        }
+        if (FAILED(hr = wined3d_buffer_upload_data(buffer, box, op->data.data)))
+            WARN("Failed to update buffer data, hr %#x.\n", hr);
 
-        wined3d_buffer_upload_data(buffer, context, box, op->data.data);
-        wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER);
-        context_release(context);
         goto done;
     }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index f8aeb629c92..371b8b367ac 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3570,7 +3570,7 @@ BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer,
 BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN;
 void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset,
         struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size) DECLSPEC_HIDDEN;
-void wined3d_buffer_upload_data(struct wined3d_buffer *buffer, struct wined3d_context *context,
+HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
         const struct wined3d_box *box, const void *data) DECLSPEC_HIDDEN;
 
 struct wined3d_rendertarget_view
-- 
2.13.1

