Henri Verbeet : wined3d: Ensure the last mip-level is at least large enough to hold a single compressed block.

Alexandre Julliard julliard at winehq.org
Wed Dec 9 15:38:58 CST 2020


Module: wine
Branch: master
Commit: 97558b65502935cbd0cbd8492f473b9c87cf3720
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=97558b65502935cbd0cbd8492f473b9c87cf3720

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Wed Dec  9 15:22:55 2020 +0330

wined3d: Ensure the last mip-level is at least large enough to hold a single compressed block.

This fixes a regression exposed by commit
ca0c3f770ae4fe4d535f59f2d54b4c0a531e800f, but probably originally introduced
by commit 3f7e5d647e40ce09292e7164eb5cc49ac77914cc.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48362
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wined3d/texture.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 6c9627d21f8..69f948c5fd2 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -3683,6 +3683,20 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc
     if (!offset)
         return WINED3DERR_INVALIDCALL;
 
+    /* Ensure the last mip-level is at least large enough to hold a single
+     * compressed block. It is questionable how useful these mip-levels are to
+     * the application with "broken pitch" formats, but we want to avoid
+     * memory corruption when loading textures into WINED3D_LOCATION_SYSMEM. */
+    if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BROKEN_PITCH)
+    {
+        unsigned int min_size;
+
+        min_size = texture->sub_resources[level_count * layer_count - 1].offset + format->block_byte_count;
+        min_size = (min_size + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1);
+        if (min_size > offset)
+            offset = min_size;
+    }
+
     if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
             desc->multisample_type, desc->multisample_quality, desc->usage, desc->bind_flags, desc->access,
             desc->width, desc->height, desc->depth, offset, parent, parent_ops, &texture_resource_ops)))




More information about the wine-cvs mailing list