[PATCH 6/6] wined3d: Introduce wined3d_texture_check_block_align().
Henri Verbeet
hverbeet at codeweavers.com
Wed Feb 17 11:35:35 CST 2016
From: Stefan Dösinger <stefan at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
dlls/wined3d/surface.c | 31 ++-----------------------------
dlls/wined3d/texture.c | 29 +++++++++++++++++++++++++++++
dlls/wined3d/volume.c | 31 ++-----------------------------
dlls/wined3d/wined3d_private.h | 2 ++
4 files changed, 35 insertions(+), 58 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index c1d7b18..7858d15 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1538,38 +1538,11 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
}
}
-static BOOL surface_check_block_align(struct wined3d_surface *surface, const struct wined3d_box *box)
-{
- UINT width_mask, height_mask;
-
- if (!box->left && !box->top
- && box->right == surface->resource.width
- && box->bottom == surface->resource.height)
- return TRUE;
-
- if ((box->left >= box->right)
- || (box->top >= box->bottom)
- || (box->right > surface->resource.width)
- || (box->bottom > surface->resource.height))
- return FALSE;
-
- /* This assumes power of two block sizes, but NPOT block sizes would be
- * silly anyway. */
- width_mask = surface->resource.format->block_width - 1;
- height_mask = surface->resource.format->block_height - 1;
-
- if (!(box->left & width_mask) && !(box->top & height_mask)
- && !(box->right & width_mask) && !(box->bottom & height_mask))
- return TRUE;
-
- return FALSE;
-}
-
static BOOL surface_check_block_align_rect(struct wined3d_surface *surface, const RECT *rect)
{
struct wined3d_box box = {rect->left, rect->top, rect->right, rect->bottom, 0, 1};
- return surface_check_block_align(surface, &box);
+ return wined3d_texture_check_block_align(surface->container, surface->texture_level, &box);
}
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
@@ -2301,7 +2274,7 @@ HRESULT wined3d_surface_map(struct wined3d_surface *surface, struct wined3d_map_
}
if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && box
- && !surface_check_block_align(surface, box))
+ && !wined3d_texture_check_block_align(surface->container, surface->texture_level, box))
{
WARN("Map box %s is misaligned for %ux%u blocks.\n",
debug_box(box), format->block_width, format->block_height);
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 7a24ff0..804856b 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1201,6 +1201,35 @@ static const struct wined3d_texture_ops texture3d_ops =
texture3d_prepare_texture,
};
+BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
+ unsigned int level, const struct wined3d_box *box)
+{
+ const struct wined3d_format *format = texture->resource.format;
+ unsigned int height = max(1, texture->resource.height >> level);
+ unsigned int width = max(1, texture->resource.width >> level);
+ unsigned int width_mask, height_mask;
+
+ if ((box->left >= box->right)
+ || (box->top >= box->bottom)
+ || (box->right > width)
+ || (box->bottom > height))
+ return FALSE;
+
+ /* This assumes power of two block sizes, but NPOT block sizes would be
+ * silly anyway.
+ *
+ * This also assumes that the format's block depth is 1. */
+ width_mask = format->block_width - 1;
+ height_mask = format->block_height - 1;
+
+ if ((box->left & width_mask) || (box->top & height_mask)
+ || (box->right & width_mask && box->right != width)
+ || (box->bottom & height_mask && box->bottom != height))
+ return FALSE;
+
+ return TRUE;
+}
+
static HRESULT texture3d_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
{
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 75585d8..6f5de73 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -433,34 +433,6 @@ static void volume_unload(struct wined3d_resource *resource)
resource_unload(resource);
}
-static BOOL volume_check_block_align(const struct wined3d_volume *volume,
- const struct wined3d_box *box)
-{
- UINT width_mask, height_mask;
- const struct wined3d_format *format = volume->resource.format;
-
- if (!box)
- return TRUE;
-
- /* This assumes power of two block sizes, but NPOT block sizes would be
- * silly anyway.
- *
- * This also assumes that the format's block depth is 1. */
- width_mask = format->block_width - 1;
- height_mask = format->block_height - 1;
-
- if (box->left & width_mask)
- return FALSE;
- if (box->top & height_mask)
- return FALSE;
- if (box->right & width_mask && box->right != volume->resource.width)
- return FALSE;
- if (box->bottom & height_mask && box->bottom != volume->resource.height)
- return FALSE;
-
- return TRUE;
-}
-
static BOOL wined3d_volume_check_box_dimensions(const struct wined3d_volume *volume,
const struct wined3d_box *box)
{
@@ -512,7 +484,8 @@ HRESULT wined3d_volume_map(struct wined3d_volume *volume,
WARN("Map box is invalid.\n");
return WINED3DERR_INVALIDCALL;
}
- if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !volume_check_block_align(volume, box))
+ if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && box
+ && !wined3d_texture_check_block_align(volume->container, volume->texture_level, box))
{
WARN("Map box %s is misaligned for %ux%u blocks.\n",
debug_box(box), format->block_width, format->block_height);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index a243727..a20bc65 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2405,6 +2405,8 @@ void wined3d_texture_bind(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
+BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
+ unsigned int level, const struct wined3d_box *box) DECLSPEC_HIDDEN;
void wined3d_texture_force_reload(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
void wined3d_texture_load(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
--
2.1.4
More information about the wine-patches
mailing list