[PATCH 1/9] wined3d: Separate mapping from data writing in surface_cpu_blt_colour_fill.

Stefan Dösinger stefan at codeweavers.com
Sun May 1 13:39:03 CDT 2022


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>
---
 dlls/wined3d/resource.c        | 90 ++++++++++++++++++++++++++++++++++
 dlls/wined3d/surface.c         | 76 +---------------------------
 dlls/wined3d/wined3d_private.h |  3 ++
 3 files changed, 95 insertions(+), 74 deletions(-)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 437f9c9da69..a21949e79fd 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -613,3 +613,93 @@ void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned in
                 + (box->left * format->byte_count);
     }
 }
+
+void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
+        unsigned int level, const struct wined3d_map_desc *map,
+        const struct wined3d_color *colour, const struct wined3d_box *box)
+{
+    const struct wined3d_format *format = resource->format;
+    unsigned int w, h, d, x, y, z, bpp;
+    struct wined3d_box level_box;
+    uint8_t *dst, *dst2;
+    DWORD c;
+
+    if (resource->type == WINED3D_RTYPE_BUFFER)
+    {
+        level_box.left = 0; level_box.top = 0; level_box.front = 0;
+        level_box.right = resource->width; level_box.bottom = 1; level_box.back = 1;
+    }
+    else
+    {
+        wined3d_texture_get_level_box(texture_from_resource(resource), level, &level_box);
+    }
+
+    w = min(box->right, level_box.right) - min(box->left, level_box.right);
+    h = min(box->bottom, level_box.bottom) - min(box->top, level_box.bottom);
+    if (resource->type != WINED3D_RTYPE_TEXTURE_3D)
+        d = 1;
+    else
+        d = min(box->back, level_box.back) - min(box->front, level_box.back);
+
+    dst = (BYTE *)map->data
+            + (box->front * map->slice_pitch)
+            + ((box->top / format->block_height) * map->row_pitch)
+            + ((box->left / format->block_width) * format->block_byte_count);
+
+    c = wined3d_format_convert_from_float(format, colour);
+    bpp = format->byte_count;
+
+    switch (bpp)
+    {
+        case 1:
+            for (x = 0; x < w; ++x)
+            {
+                dst[x] = c;
+            }
+            break;
+
+        case 2:
+            for (x = 0; x < w; ++x)
+            {
+                ((WORD *)dst)[x] = c;
+            }
+            break;
+
+        case 3:
+        {
+            dst2 = dst;
+            for (x = 0; x < w; ++x, dst += 3)
+            {
+                dst2[0] = (c      ) & 0xff;
+                dst2[1] = (c >>  8) & 0xff;
+                dst2[2] = (c >> 16) & 0xff;
+            }
+            break;
+        }
+        case 4:
+            for (x = 0; x < w; ++x)
+            {
+                ((DWORD *)dst)[x] = c;
+            }
+            break;
+
+        default:
+            FIXME("Not implemented for bpp %u.\n", bpp);
+            return;
+    }
+
+    dst2 = dst;
+    for (y = 1; y < h; ++y)
+    {
+        dst2 += map->row_pitch;
+        memcpy(dst2, dst, w * bpp);
+    }
+
+    dst2 = dst;
+    for (z = 1; z < d; ++z)
+    {
+        dst2 += map->slice_pitch;
+        memcpy(dst2, dst, w * h * bpp);
+    }
+
+}
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 5feeba3be2d..afe6ea6e5ba 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1241,15 +1241,13 @@ static void surface_cpu_blt_colour_fill(struct wined3d_rendertarget_view *view,
         const struct wined3d_box *box, const struct wined3d_color *colour)
 {
     struct wined3d_device *device = view->resource->device;
-    unsigned int x, y, z, w, h, d, bpp, level;
     struct wined3d_context *context;
     struct wined3d_texture *texture;
     struct wined3d_bo_address data;
     struct wined3d_map_desc map;
     struct wined3d_range range;
+    unsigned int level;
     DWORD map_binding;
-    uint8_t *dst;
-    DWORD c;
 
     TRACE("view %p, box %s, colour %s.\n", view, debug_box(box), debug_color(colour));
 
@@ -1274,20 +1272,6 @@ static void surface_cpu_blt_colour_fill(struct wined3d_rendertarget_view *view,
     texture = texture_from_resource(view->resource);
     level = view->sub_resource_idx % texture->level_count;
 
-    c = wined3d_format_convert_from_float(view->format, colour);
-    bpp = view->format->byte_count;
-    w = min(box->right, view->width) - min(box->left, view->width);
-    h = min(box->bottom, view->height) - min(box->top, view->height);
-    if (view->resource->type != WINED3D_RTYPE_TEXTURE_3D)
-    {
-        d = 1;
-    }
-    else
-    {
-        d = wined3d_texture_get_level_depth(texture, level);
-        d = min(box->back, d) - min(box->front, d);
-    }
-
     map_binding = texture->resource.map_binding;
     if (!wined3d_texture_load_location(texture, view->sub_resource_idx, context, map_binding))
         ERR("Failed to load the sub-resource into %s.\n", wined3d_debug_location(map_binding));
@@ -1296,66 +1280,10 @@ static void surface_cpu_blt_colour_fill(struct wined3d_rendertarget_view *view,
     wined3d_texture_get_bo_address(texture, view->sub_resource_idx, &data, map_binding);
     map.data = wined3d_context_map_bo_address(context, &data,
             texture->sub_resources[view->sub_resource_idx].size, WINED3D_MAP_WRITE);
-    map.data = (BYTE *)map.data
-            + (box->front * map.slice_pitch)
-            + ((box->top / view->format->block_height) * map.row_pitch)
-            + ((box->left / view->format->block_width) * view->format->block_byte_count);
     range.offset = 0;
     range.size = texture->sub_resources[view->sub_resource_idx].size;
 
-    switch (bpp)
-    {
-        case 1:
-            for (x = 0; x < w; ++x)
-            {
-                ((BYTE *)map.data)[x] = c;
-            }
-            break;
-
-        case 2:
-            for (x = 0; x < w; ++x)
-            {
-                ((WORD *)map.data)[x] = c;
-            }
-            break;
-
-        case 3:
-        {
-            dst = map.data;
-            for (x = 0; x < w; ++x, dst += 3)
-            {
-                dst[0] = (c      ) & 0xff;
-                dst[1] = (c >>  8) & 0xff;
-                dst[2] = (c >> 16) & 0xff;
-            }
-            break;
-        }
-        case 4:
-            for (x = 0; x < w; ++x)
-            {
-                ((DWORD *)map.data)[x] = c;
-            }
-            break;
-
-        default:
-            FIXME("Not implemented for bpp %u.\n", bpp);
-            wined3d_resource_unmap(view->resource, view->sub_resource_idx);
-            return;
-    }
-
-    dst = map.data;
-    for (y = 1; y < h; ++y)
-    {
-        dst += map.row_pitch;
-        memcpy(dst, map.data, w * bpp);
-    }
-
-    dst = map.data;
-    for (z = 1; z < d; ++z)
-    {
-        dst += map.slice_pitch;
-        memcpy(dst, map.data, w * h * bpp);
-    }
+    wined3d_resource_memory_colour_fill(view->resource, level, &map, colour, box);
 
     wined3d_context_unmap_bo_address(context, &data, 1, &range);
     context_release(context);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 3a12f5ef261..e19eb476153 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4366,6 +4366,9 @@ GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *reso
 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
+void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
+        unsigned int level, const struct wined3d_map_desc *map,
+        const struct wined3d_color *colour, const struct wined3d_box *box) DECLSPEC_HIDDEN;
 
 /* Tests show that the start address of resources is 32 byte aligned */
 #define RESOURCE_ALIGNMENT 16
-- 
2.35.1




More information about the wine-devel mailing list