Vitaliy Margolen : wined3d/d3d9: Pitch for DXTn textures can not be 0. With tests.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Dec 4 07:17:04 CST 2006


Module: wine
Branch: master
Commit: 81c7c00bb2f1675f853dc0fe5b6ca8178ac7a537
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=81c7c00bb2f1675f853dc0fe5b6ca8178ac7a537

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Sat Dec  2 20:27:36 2006 -0700

wined3d/d3d9: Pitch for DXTn textures can not be 0. With tests.

---

 dlls/d3d9/tests/surface.c |   30 ++++++++++++++++++++++++++++++
 dlls/wined3d/surface.c    |    4 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c
index b7a16a2..badfb3a 100644
--- a/dlls/d3d9/tests/surface.c
+++ b/dlls/d3d9/tests/surface.c
@@ -17,6 +17,7 @@
  */
 #define COBJMACROS
 #include <d3d9.h>
+#include <dxerr9.h>
 #include "wine/test.h"
 
 static HWND create_window(void)
@@ -117,6 +118,7 @@ static void test_surface_alignment(IDire
 {
     IDirect3DSurface9 *surface_ptr = 0;
     HRESULT hr;
+    int i;
 
     /* Test a sysmem surface as those aren't affected by the hardware's np2 restrictions */
     hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device_ptr, 5, 5, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface_ptr, 0);
@@ -137,6 +139,34 @@ static void test_surface_alignment(IDire
         hr = IDirect3DSurface9_UnlockRect(surface_ptr);
         IDirect3DSurface9_Release(surface_ptr);
     }
+
+    for (i = 0; i < 5; i++)
+    {
+        IDirect3DTexture9 *pTexture;
+        int j, pitch;
+
+        hr = IDirect3DDevice9_CreateTexture(device_ptr, 64, 64, 0, 0, MAKEFOURCC('D', 'X', 'T', '1'+i),
+                                            D3DPOOL_MANAGED, &pTexture, NULL);
+        ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture: %s\n", DXGetErrorString9(hr));
+        if (FAILED(hr)) continue;
+
+        for (j = IDirect3DBaseTexture9_GetLevelCount(pTexture) - 1; j >= 0; j--)
+        {
+            D3DLOCKED_RECT rc;
+            D3DSURFACE_DESC descr;
+
+            IDirect3DTexture9_GetLevelDesc(pTexture, j, &descr);
+            hr = IDirect3DTexture9_LockRect(pTexture, j, &rc, NULL, 0);
+            ok(SUCCEEDED(hr), "IDirect3DTexture9_LockRect: %s\n", DXGetErrorString9(hr));
+            IDirect3DTexture9_UnlockRect(pTexture, j);
+
+            pitch = ((descr.Width + 3) >> 2) << 3;
+            if (i > 0) pitch <<= 1;
+            ok(rc.Pitch == pitch, "Wrong pitch for DXT%d lvl[%d (%dx%d)]: expected %d got %d\n",
+               i + 1, j, descr.Width, descr.Height, pitch, rc.Pitch);
+        }
+        IUnknown_Release( pTexture );
+    }
 }
 
 START_TEST(surface)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 84a838f..abc35ee 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3023,10 +3023,10 @@ DWORD WINAPI IWineD3DSurfaceImpl_GetPitc
          where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5)
           ie pitch = (width/4) * bytes per block                                  */
     if (This->resource.format == WINED3DFMT_DXT1) /* DXT1 is 8 bytes per block */
-        ret = (This->currentDesc.Width >> 2) << 3;
+        ret = ((This->currentDesc.Width + 3) >> 2) << 3;
     else if (This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
              This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
-        ret = (This->currentDesc.Width >> 2) << 4;
+        ret = ((This->currentDesc.Width + 3) >> 2) << 4;
     else {
         if (NP2_REPACK == wined3d_settings.nonpower2_mode || This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
             /* Front and back buffers are always lockes/unlocked on currentDesc.Width */




More information about the wine-cvs mailing list