[PATCH v2 1/7] wined3d: Return the map pitch from wined3d_device_context_emit_map().

Zebediah Figura zfigura at codeweavers.com
Tue Oct 12 16:15:42 CDT 2021


Partially undoes 61024aa12f.

We may want to be able to return an existing BO from
context->ops->map_upload_bo(), in which case it is structurally awkward to
request a specific memory layout. We may also want to give map_upload_bo() the
freedom to allocate either a new (smaller) BO, or use an existing (larger) one,
for partial uploads.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/wined3d/cs.c              | 37 ++++++++++++++++++++++------------
 dlls/wined3d/device.c          |  5 +----
 dlls/wined3d/wined3d_private.h |  2 +-
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 51718a8a4d0..ce9e6fca214 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -2491,27 +2491,32 @@ static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data)
             op->sub_resource_idx, op->map_ptr, op->box, op->flags);
 }
 
-HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context, struct wined3d_resource *resource,
-        unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags)
+HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
+        struct wined3d_resource *resource, unsigned int sub_resource_idx,
+        struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags)
 {
     unsigned int row_pitch, slice_pitch;
     struct wined3d_cs_map *op;
+    void *map_ptr;
     HRESULT hr;
 
-    wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
-
-    if ((flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
-            && (*map_ptr = context->ops->map_upload_bo(context, resource,
-            sub_resource_idx, box, row_pitch, slice_pitch, flags)))
-    {
-        TRACE("Returning map pointer %p, row pitch %u, slice pitch %u.\n", *map_ptr, row_pitch, slice_pitch);
-        return WINED3D_OK;
-    }
-
     /* Mapping resources from the worker thread isn't an issue by itself, but
      * increasing the map count would be visible to applications. */
     wined3d_not_from_cs(context->device->cs);
 
+    wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
+
+    if ((flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
+            && (map_ptr = context->ops->map_upload_bo(context, resource,
+            sub_resource_idx, box, row_pitch, slice_pitch, flags)))
+    {
+        TRACE("Returning map pointer %p, row pitch %u, slice pitch %u.\n", map_ptr, row_pitch, slice_pitch);
+        map_desc->data = map_ptr;
+        map_desc->row_pitch = row_pitch;
+        map_desc->slice_pitch = slice_pitch;
+        return WINED3D_OK;
+    }
+
     wined3d_resource_wait_idle(resource);
 
     if (!(op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_MAP)))
@@ -2519,7 +2524,7 @@ HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
     op->opcode = WINED3D_CS_OP_MAP;
     op->resource = resource;
     op->sub_resource_idx = sub_resource_idx;
-    op->map_ptr = map_ptr;
+    op->map_ptr = &map_ptr;
     op->box = box;
     op->flags = flags;
     op->hr = &hr;
@@ -2527,6 +2532,12 @@ HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
     wined3d_device_context_submit(context, WINED3D_CS_QUEUE_MAP);
     wined3d_device_context_finish(context, WINED3D_CS_QUEUE_MAP);
 
+    if (FAILED(hr))
+        return hr;
+
+    map_desc->data = map_ptr;
+    map_desc->row_pitch = row_pitch;
+    map_desc->slice_pitch = slice_pitch;
     return hr;
 }
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 436c4dfe854..b8c1630ee25 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4957,10 +4957,7 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
     }
 
     wined3d_mutex_lock();
-    if (SUCCEEDED(hr = wined3d_device_context_emit_map(context, resource,
-            sub_resource_idx, &map_desc->data, box, flags)))
-        wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx,
-                &map_desc->row_pitch, &map_desc->slice_pitch);
+    hr = wined3d_device_context_emit_map(context, resource, sub_resource_idx, map_desc, box, flags);
     wined3d_mutex_unlock();
     return hr;
 }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 56c90ba6606..a2899e6a778 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4867,7 +4867,7 @@ void wined3d_device_context_emit_execute_command_list(struct wined3d_device_cont
 void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context *context,
         struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
 HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
-        struct wined3d_resource *resource, unsigned int sub_resource_idx, void **map_ptr,
+        struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
         const struct wined3d_box *box, unsigned int flags) DECLSPEC_HIDDEN;
 void wined3d_device_context_emit_reset_state(struct wined3d_device_context *context, bool invalidate) DECLSPEC_HIDDEN;
 void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context *context,
-- 
2.33.0




More information about the wine-devel mailing list