Commit 58719f60 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Introduce wined3d_texture_check_block_align().

parent b162e29c
......@@ -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);
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment