[PATCH 2/6] wined3d: Handle slice pitch and alignment as well in wined3d_format_calculate_pitch().
Henri Verbeet
hverbeet at codeweavers.com
Tue Feb 9 14:29:56 CST 2016
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
dlls/wined3d/directx.c | 6 +++++-
dlls/wined3d/surface.c | 41 ++++++++++++++++-------------------
dlls/wined3d/utils.c | 49 +++++++++++++++++++++---------------------
dlls/wined3d/volume.c | 22 ++-----------------
dlls/wined3d/wined3d_private.h | 3 ++-
5 files changed, 53 insertions(+), 68 deletions(-)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 329da15..5f995ce 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -4756,6 +4756,7 @@ UINT CDECL wined3d_calculate_format_pitch(const struct wined3d *wined3d, UINT ad
enum wined3d_format_id format_id, UINT width)
{
const struct wined3d_gl_info *gl_info;
+ unsigned int row_pitch, slice_pitch;
TRACE("wined3d %p, adapter_idx %u, format_id %s, width %u.\n",
wined3d, adapter_idx, debug_d3dformat(format_id), width);
@@ -4764,7 +4765,10 @@ UINT CDECL wined3d_calculate_format_pitch(const struct wined3d *wined3d, UINT ad
return ~0u;
gl_info = &wined3d->adapters[adapter_idx].gl_info;
- return wined3d_format_calculate_pitch(wined3d_get_format(gl_info, format_id), width);
+ wined3d_format_calculate_pitch(wined3d_get_format(gl_info, format_id),
+ 1, width, 1, &row_pitch, &slice_pitch);
+
+ return row_pitch;
}
HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 8597404..1860258 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1885,21 +1885,19 @@ static inline unsigned short float_32_to_16(const float *in)
DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
{
- unsigned int alignment;
- DWORD pitch;
+ unsigned int row_pitch, slice_pitch;
TRACE("surface %p.\n", surface);
if (surface->container->row_pitch)
return surface->container->row_pitch;
- alignment = surface->resource.device->surface_alignment;
- pitch = wined3d_format_calculate_pitch(surface->resource.format, surface->resource.width);
- pitch = (pitch + alignment - 1) & ~(alignment - 1);
+ wined3d_format_calculate_pitch(surface->resource.format, surface->resource.device->surface_alignment,
+ surface->resource.width, surface->resource.height, &row_pitch, &slice_pitch);
- TRACE("Returning %u.\n", pitch);
+ TRACE("Returning %u.\n", row_pitch);
- return pitch;
+ return row_pitch;
}
HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info)
@@ -1961,9 +1959,8 @@ HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface, const struc
else
{
/* User memory surfaces don't have the regular surface alignment. */
- surface->resource.size = wined3d_format_calculate_size(texture_resource->format,
- 1, width, height, 1);
- surface->container->row_pitch = wined3d_format_calculate_pitch(texture_resource->format, width);
+ wined3d_format_calculate_pitch(texture_resource->format, 1, width, height,
+ &surface->container->row_pitch, &surface->resource.size);
}
/* The format might be changed to a format that needs conversion.
@@ -3694,10 +3691,10 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
{
const struct wined3d_gl_info *gl_info = context->gl_info;
RECT src_rect = {0, 0, surface->resource.width, surface->resource.height};
+ unsigned int width, src_pitch, dst_row_pitch, dst_slice_pitch;
struct wined3d_device *device = surface->resource.device;
const struct wined3d_color_key_conversion *conversion;
struct wined3d_texture *texture = surface->container;
- UINT width, src_pitch, dst_pitch;
struct wined3d_bo_address data;
struct wined3d_format format;
POINT dst_point = {0, 0};
@@ -3812,17 +3809,17 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
UINT height = surface->resource.height;
format.byte_count = format.conv_byte_count;
- dst_pitch = wined3d_format_calculate_pitch(&format, width);
+ wined3d_format_calculate_pitch(&format, 1, width, height, &dst_row_pitch, &dst_slice_pitch);
- if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height)))
+ if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
{
- ERR("Out of memory (%u).\n", dst_pitch * height);
+ ERR("Out of memory (%u).\n", dst_slice_pitch);
context_release(context);
return E_OUTOFMEMORY;
}
format.convert(data.addr, mem, src_pitch, src_pitch * height,
- dst_pitch, dst_pitch * height, width, height, 1);
- src_pitch = dst_pitch;
+ dst_row_pitch, dst_slice_pitch, width, height, 1);
+ src_pitch = dst_row_pitch;
data.addr = mem;
}
else if (conversion)
@@ -3831,20 +3828,20 @@ static HRESULT surface_load_texture(struct wined3d_surface *surface,
struct wined3d_palette *palette = NULL;
UINT height = surface->resource.height;
- dst_pitch = wined3d_format_calculate_pitch(&format, width);
- dst_pitch = (dst_pitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
+ wined3d_format_calculate_pitch(&format, device->surface_alignment,
+ width, height, &dst_row_pitch, &dst_slice_pitch);
- if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height)))
+ if (!(mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
{
- ERR("Out of memory (%u).\n", dst_pitch * height);
+ ERR("Out of memory (%u).\n", dst_slice_pitch);
context_release(context);
return E_OUTOFMEMORY;
}
if (texture->swapchain && texture->swapchain->palette)
palette = texture->swapchain->palette;
- conversion->convert(data.addr, src_pitch, mem, dst_pitch,
+ conversion->convert(data.addr, src_pitch, mem, dst_row_pitch,
width, height, palette, &texture->async.gl_color_key);
- src_pitch = dst_pitch;
+ src_pitch = dst_row_pitch;
data.addr = mem;
}
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 340cd87..beb104a 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3083,46 +3083,47 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
return &gl_info->formats[idx];
}
-UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width)
+void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
+ unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch)
{
/* For block based formats, pitch means the amount of bytes to the next
* row of blocks rather than the next row of pixels. */
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BLOCKS)
- return format->block_byte_count * ((width + format->block_width - 1) / format->block_width);
-
- return format->byte_count * width;
-}
-
-UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
- UINT width, UINT height, UINT depth)
-{
- UINT pitch = wined3d_format_calculate_pitch(format, width);
- UINT size;
-
- if (format->id == WINED3DFMT_UNKNOWN)
- {
- size = 0;
- }
- else if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BLOCKS)
{
- UINT row_count = (height + format->block_height - 1) / format->block_height;
- size = row_count * ((pitch + alignment - 1) & ~(alignment - 1));
+ unsigned int row_block_count = (width + format->block_width - 1) / format->block_width;
+ unsigned int slice_block_count = (height + format->block_height - 1) / format->block_height;
+ *row_pitch = row_block_count * format->block_byte_count;
+ *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
+ *slice_pitch = *row_pitch * slice_block_count;
}
else
{
- size = height * ((pitch + alignment - 1) & ~(alignment - 1));
+ *row_pitch = format->byte_count * width; /* Bytes / row */
+ *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
+ *slice_pitch = *row_pitch * height;
}
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_HEIGHT_SCALE)
{
/* The D3D format requirements make sure that the resulting format is an integer again */
- size *= format->height_scale.numerator;
- size /= format->height_scale.denominator;
+ *slice_pitch *= format->height_scale.numerator;
+ *slice_pitch /= format->height_scale.denominator;
}
- size *= depth;
+ TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch, *slice_pitch);
+}
- return size;
+UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
+ UINT width, UINT height, UINT depth)
+{
+ unsigned int row_pitch, slice_pitch;
+
+ if (format->id == WINED3DFMT_UNKNOWN)
+ return 0;
+
+ wined3d_format_calculate_pitch(format, alignment, width, height, &row_pitch, &slice_pitch);
+
+ return slice_pitch * depth;
}
/*****************************************************************************
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 3ac7f98..733b468 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -42,26 +42,8 @@ BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pitch, UINT *slice_pitch)
{
- const struct wined3d_format *format = volume->resource.format;
-
- if (volume->container->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
- {
- /* Since compressed formats are block based, pitch means the amount of
- * bytes to the next row of block rather than the next row of pixels. */
- UINT row_block_count = (volume->resource.width + format->block_width - 1) / format->block_width;
- UINT slice_block_count = (volume->resource.height + format->block_height - 1) / format->block_height;
- *row_pitch = row_block_count * format->block_byte_count;
- *slice_pitch = *row_pitch * slice_block_count;
- }
- else
- {
- unsigned char alignment = volume->resource.device->surface_alignment;
- *row_pitch = format->byte_count * volume->resource.width; /* Bytes / row */
- *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
- *slice_pitch = *row_pitch * volume->resource.height;
- }
-
- TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch, *slice_pitch);
+ wined3d_format_calculate_pitch(volume->resource.format, volume->resource.device->surface_alignment,
+ volume->resource.width, volume->resource.height, row_pitch, slice_pitch);
}
/* This call just uploads data, the caller is responsible for binding the
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 142cb93..443f763 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3347,7 +3347,8 @@ struct wined3d_format
const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
-UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width) DECLSPEC_HIDDEN;
+void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
+ unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) DECLSPEC_HIDDEN;
UINT wined3d_format_calculate_size(const struct wined3d_format *format,
UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
--
2.1.4
More information about the wine-patches
mailing list