[PATCH 1/7] wined3d: Add support for buffers in wined3d_device_update_sub_resource(). (try 2)

Józef Kucia jkucia at codeweavers.com
Mon Jan 4 06:03:36 CST 2016


Try 2: Validate sub_resource_idx.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/wined3d/buffer.c          | 38 +++++++++++++++++++++++++++++---------
 dlls/wined3d/device.c          | 17 +++++++++++++++++
 dlls/wined3d/wined3d_private.h |  2 ++
 3 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index d20931b..444015f 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -1113,6 +1113,33 @@ void CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer)
     }
 }
 
+HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
+        const struct wined3d_box *box, const void *data)
+{
+    UINT offset, size;
+    HRESULT hr;
+    BYTE *ptr;
+
+    if (box)
+    {
+        offset = box->left;
+        size = box->right - box->left;
+    }
+    else
+    {
+        offset = 0;
+        size = buffer->resource.size;
+    }
+
+    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)
 {
     return wined3d_buffer_incref(buffer_from_resource(resource));
@@ -1240,20 +1267,13 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
 
     if (data)
     {
-        BYTE *ptr;
-
-        hr = wined3d_buffer_map(buffer, 0, size, &ptr, 0);
-        if (FAILED(hr))
+        if (FAILED(hr = wined3d_buffer_upload_data(buffer, NULL, data->data)))
         {
-            ERR("Failed to map buffer, hr %#x\n", hr);
+            ERR("Failed to upload data, hr %#x.\n", hr);
             buffer_unload(&buffer->resource);
             resource_cleanup(&buffer->resource);
             return hr;
         }
-
-        memcpy(ptr, data->data, size);
-
-        wined3d_buffer_unmap(buffer);
     }
 
     buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 76c4e7d..d8a6462 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3989,6 +3989,23 @@ void CDECL wined3d_device_update_sub_resource(struct wined3d_device *device, str
     TRACE("device %p, resource %p, sub_resource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
             device, resource, sub_resource_idx, box, data, row_pitch, depth_pitch);
 
+    if (resource->type == WINED3D_RTYPE_BUFFER)
+    {
+        struct wined3d_buffer *buffer = buffer_from_resource(resource);
+        HRESULT hr;
+
+        if (sub_resource_idx > 0)
+        {
+            WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
+            return;
+        }
+
+        if (FAILED(hr = wined3d_buffer_upload_data(buffer, box, data)))
+            WARN("Failed to update buffer data, hr %#x.\n", hr);
+
+        return;
+    }
+
     if (resource->type != WINED3D_RTYPE_TEXTURE)
     {
         FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 288d683..293e807 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2758,6 +2758,8 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, struct wined3d_context *con
 void buffer_internal_preload(struct wined3d_buffer *buffer, struct wined3d_context *context,
         const struct wined3d_state *state) DECLSPEC_HIDDEN;
 void buffer_mark_used(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
+HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
+        const struct wined3d_box *box, const void *data) DECLSPEC_HIDDEN;
 
 struct wined3d_rendertarget_view
 {
-- 
2.4.10




More information about the wine-patches mailing list