[PATCH 2/3] d3dx9: Correctly align texture dimensions to block size in D3DXCheckTextureRequirements().

Matteo Bruni mbruni at codeweavers.com
Wed Oct 2 13:22:09 CDT 2019


From: Christian Costa <titan.costa at gmail.com>

Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
>From staging. Do we know of any application affected by this?

 dlls/d3dx9_36/tests/texture.c |  9 +++++++++
 dlls/d3dx9_36/texture.c       | 15 +++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c
index 229c857ac2e..3416a3318b2 100644
--- a/dlls/d3dx9_36/tests/texture.c
+++ b/dlls/d3dx9_36/tests/texture.c
@@ -448,6 +448,15 @@ static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
         ok(width == 4, "Got unexpected width %d.\n", width);
         ok(height == 4, "Got unexpected height %d.\n", height);
         ok(format == D3DFMT_DXT5, "Got unexpected format %u.\n", format);
+
+        width = 9;
+        height = 9;
+        hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, &format, D3DPOOL_DEFAULT);
+        ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+        ok(width == 12, "Got unexpected width %u.\n", width);
+        ok(height == 12, "Got unexpected height %u.\n", height);
+        ok(mipmaps == 1, "Got unexpected level count %u.\n", mipmaps);
+        ok(format == D3DFMT_DXT5, "Got unexpected format %u.\n", format);
     }
     else
     {
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c
index 8708ed702fd..6ee7d72e38e 100644
--- a/dlls/d3dx9_36/texture.c
+++ b/dlls/d3dx9_36/texture.c
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-
+#include <assert.h>
 #include "d3dx9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -337,13 +337,12 @@ HRESULT WINAPI D3DXCheckTextureRequirements(struct IDirect3DDevice9 *device, UIN
     else if (h == D3DX_DEFAULT)
         h = (width ? w : 256);
 
-    if (fmt->block_width != 1 || fmt->block_height != 1)
-    {
-        if (w < fmt->block_width)
-            w = fmt->block_width;
-        if (h < fmt->block_height)
-            h = fmt->block_height;
-    }
+    assert(!(fmt->block_width & (fmt->block_width - 1)));
+    assert(!(fmt->block_height & (fmt->block_height - 1)));
+    if (w & (fmt->block_width - 1))
+        w = (w + fmt->block_width) & ~(fmt->block_width - 1);
+    if (h & (fmt->block_height - 1))
+        h = (h + fmt->block_height) & ~(fmt->block_height - 1);
 
     if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && (!is_pow2(w)))
         w = make_pow2(w);
-- 
2.21.0




More information about the wine-devel mailing list