[PATCH 2/5] wined3d: Separate a resource_offset_map_pointer() helper.

Zebediah Figura zfigura at codeweavers.com
Wed Sep 29 17:15:21 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/wined3d/resource.c        | 26 ++++++++++++++++++++++++++
 dlls/wined3d/texture.c         | 22 +---------------------
 dlls/wined3d/wined3d_private.h |  2 ++
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 3d24d375bc8..8f31996595c 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -586,3 +586,29 @@ VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags)
 
     return flags;
 }
+
+void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
+        uint8_t *base_memory, const struct wined3d_box *box)
+{
+    const struct wined3d_format *format = resource->format;
+    unsigned int row_pitch, slice_pitch;
+
+    wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
+
+    if ((resource->format_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
+    {
+        /* Compressed textures are block based, so calculate the offset of
+         * the block that contains the top-left pixel of the mapped box. */
+        return base_memory
+                + (box->front * slice_pitch)
+                + ((box->top / format->block_height) * row_pitch)
+                + ((box->left / format->block_width) * format->block_byte_count);
+    }
+    else
+    {
+        return base_memory
+                + (box->front * slice_pitch)
+                + (box->top * row_pitch)
+                + (box->left * format->byte_count);
+    }
+}
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index f9babc6e28f..db32274960f 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -3466,11 +3466,8 @@ static void texture_resource_sub_resource_get_map_pitch(struct wined3d_resource
 static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
         void **map_ptr, const struct wined3d_box *box, DWORD flags)
 {
-    const struct wined3d_format *format = resource->format;
     struct wined3d_texture_sub_resource *sub_resource;
     struct wined3d_device *device = resource->device;
-    unsigned int fmt_flags = resource->format_flags;
-    unsigned int row_pitch, slice_pitch;
     struct wined3d_context *context;
     struct wined3d_texture *texture;
     struct wined3d_bo_address data;
@@ -3537,24 +3534,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
 
     context_release(context);
 
-    texture_resource_sub_resource_get_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
-
-    if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
-    {
-        /* Compressed textures are block based, so calculate the offset of
-         * the block that contains the top-left pixel of the mapped box. */
-        *map_ptr = base_memory
-                + (box->front * slice_pitch)
-                + ((box->top / format->block_height) * row_pitch)
-                + ((box->left / format->block_width) * format->block_byte_count);
-    }
-    else
-    {
-        *map_ptr = base_memory
-                + (box->front * slice_pitch)
-                + (box->top * row_pitch)
-                + (box->left * format->byte_count);
-    }
+    *map_ptr = resource_offset_map_pointer(resource, sub_resource_idx, base_memory, box);
 
     if (texture->swapchain && texture->swapchain->front_buffer == texture)
     {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 520eb968eb6..5a5c6c9c0a3 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4165,6 +4165,8 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
         unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
         unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
         const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
+void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
+        uint8_t *base_memory, const struct wined3d_box *box) DECLSPEC_HIDDEN;
 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource,
         unsigned int sub_resource_idx, const struct wined3d_box *box) DECLSPEC_HIDDEN;
-- 
2.33.0




More information about the wine-devel mailing list