[PATCH 1/6] wined3d: Improve volume size calculation
Stefan Dösinger
stefan at codeweavers.com
Wed Aug 21 08:15:47 CDT 2013
The existing code does not work for compressed formats. This patch is
obviously not enough for s3tc volume texture support, but it fixes
memory corruption in the d3dx9_36 texture test.
---
dlls/wined3d/surface.c | 6 +++---
dlls/wined3d/utils.c | 5 ++++-
dlls/wined3d/volume.c | 6 ++++--
dlls/wined3d/wined3d_private.h | 2 +-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index c5dd301..c8fedd0 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2293,7 +2293,7 @@ static void surface_upload_data(struct wined3d_surface *surface, const struct wi
if (format->flags & WINED3DFMT_FLAG_COMPRESSED)
{
- UINT row_length = wined3d_format_calculate_size(format, 1, update_w, 1);
+ UINT row_length = wined3d_format_calculate_size(format, 1, update_w, 1, 1);
UINT row_count = (update_h + format->block_height - 1) / format->block_height;
const BYTE *addr = data->addr;
GLenum internal;
@@ -3437,7 +3437,7 @@ HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface,
struct wined3d_device *device = surface->resource.device;
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
- UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height);
+ UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, 1);
TRACE("surface %p, width %u, height %u, format %s, multisample_type %#x, multisample_quality %u.\n",
surface, width, height, debug_d3dformat(format_id), multisample_type, multisample_type);
@@ -7161,7 +7161,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
/* FIXME: Check that the format is supported by the device. */
- resource_size = wined3d_format_calculate_size(format, alignment, width, height);
+ resource_size = wined3d_format_calculate_size(format, alignment, width, height, 1);
if (!resource_size)
return WINED3DERR_INVALIDCALL;
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 7cb14d7..9462a3c 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -1942,7 +1942,8 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
return &gl_info->formats[idx];
}
-UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment, UINT width, UINT height)
+UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
+ UINT width, UINT height, UINT depth)
{
UINT size;
@@ -1968,6 +1969,8 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali
size /= format->height_scale.denominator;
}
+ size *= depth;
+
return size;
}
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index b4a8c64..50d9a75 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -265,6 +265,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
HRESULT hr;
+ UINT size;
if (!gl_info->supported[EXT_TEXTURE3D])
{
@@ -272,10 +273,11 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device
return WINED3DERR_INVALIDCALL;
}
+ size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, depth);
+
hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format,
WINED3D_MULTISAMPLE_NONE, 0, usage, pool, width, height, depth,
- width * height * depth * format->byte_count, parent, parent_ops,
- &volume_resource_ops);
+ size, parent, parent_ops, &volume_resource_ops);
if (FAILED(hr))
{
WARN("Failed to initialize resource, returning %#x.\n", hr);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 49aacc1..23c12aa 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2962,7 +2962,7 @@ 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_size(const struct wined3d_format *format,
- UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
+ UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
const struct wined3d_color *color) DECLSPEC_HIDDEN;
--
1.8.1.5
More information about the wine-patches
mailing list