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

Zebediah Figura zfigura at codeweavers.com
Wed Oct 6 21:04:31 CDT 2021


Partially undoes 61024aa12f.

We want to be able to allocate a new upload BO for a given map, but it's a bit
structurally awkward to ask for a specific memory layout when
parepare_upload_bo() might return different ones depending on the flags and
other factors.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
This is kind of janky, though. It might not be all that unreasonable to ask
prepare_upload_bo() for a specific layout.

 dlls/wined3d/cs.c              | 21 ++++++++++++++++-----
 dlls/wined3d/device.c          |  7 +------
 dlls/wined3d/wined3d_private.h |  2 +-
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index a34aad060f9..cbe333fab95 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -2483,20 +2483,25 @@ 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,
+            && (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);
+        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;
     }
 
@@ -2511,7 +2516,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;
@@ -2519,6 +2524,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 (SUCCEEDED(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 71b1e3c3f88..8e84544e6af 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4841,7 +4841,6 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
 {
     struct wined3d_sub_resource_desc desc;
     struct wined3d_box b;
-    HRESULT hr;
 
     TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
             context, resource, sub_resource_idx, map_desc, debug_box(box), flags);
@@ -4885,11 +4884,7 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
             return WINED3DERR_INVALIDCALL;
     }
 
-    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);
-    return hr;
+    return wined3d_device_context_emit_map(context, resource, sub_resource_idx, map_desc, box, flags);
 }
 
 HRESULT CDECL wined3d_device_context_unmap(struct wined3d_device_context *context,
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 0c169ec344b..acd3ded7a24 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4868,7 +4868,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