On Tuesday 18 October 2011 20:12:35 Stefan Dösinger wrote:
> On Tuesday 18 October 2011 19:36:33 Stefan Dösinger wrote:
> > I felt that merging the tests to test all format and pool combinations
> > would cause needlessly complicated
> 
> With a few simplifications like skipping all tests without dynamic textures
> it turns out okish. It's not too pretty. There are still a bunch of checks
> for caps and pools, but it should be readable.
This is a version of the patch with both tests merged into one that tests all 
format-pool combinations. I'll resend the patches tomorrow unless you have 
further suggestions.

I changed the d3d8 patch in a similar way.
From d49c0377ec20a5832e3eb0a76d64ac7690158b0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <ste...@codeweavers.com>
Date: Fri, 14 Oct 2011 12:54:37 +0200
Subject: [PATCH 03/13] d3d9/tests: Test more properties of block-based surfaces

---
 dlls/d3d9/tests/surface.c |  194 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 164 insertions(+), 30 deletions(-)

diff --git a/dlls/d3d9/tests/surface.c b/dlls/d3d9/tests/surface.c
index 572478e..b2e0fd4 100644
--- a/dlls/d3d9/tests/surface.c
+++ b/dlls/d3d9/tests/surface.c
@@ -187,26 +187,32 @@ static void test_surface_alignment(IDirect3DDevice9 *device_ptr)
 /* Since the DXT formats are based on 4x4 blocks, locking works slightly
  * different than with regular formats. This patch verifies we return the
  * correct memory offsets */
-static void test_lockrect_offset(IDirect3DDevice9 *device)
+static void test_format_blocks(IDirect3DDevice9 *device)
 {
-    IDirect3DSurface9 *surface = 0;
+    IDirect3DTexture9 *texture;
+    IDirect3DSurface9 *surface;
     IDirect3D9 *d3d;
     const RECT rect = {60, 60, 68, 68};
     D3DLOCKED_RECT locked_rect;
     int expected_pitch;
     unsigned int expected_offset;
     unsigned int offset;
-    unsigned int i;
+    unsigned int i, j;
     BYTE *base;
     HRESULT hr;
+    RECT partial_rect;
+    BOOL surface_only;
 
-    const struct {
+    const struct
+    {
         D3DFORMAT fmt;
         const char *name;
         unsigned int block_width;
         unsigned int block_height;
         unsigned int block_size;
-    } dxt_formats[] = {
+    }
+    formats[] =
+    {
         {D3DFMT_DXT1,                 "D3DFMT_DXT1", 4, 4, 8},
         {D3DFMT_DXT2,                 "D3DFMT_DXT2", 4, 4, 16},
         {D3DFMT_DXT3,                 "D3DFMT_DXT3", 4, 4, 16},
@@ -214,43 +220,171 @@ static void test_lockrect_offset(IDirect3DDevice9 *device)
         {D3DFMT_DXT5,                 "D3DFMT_DXT5", 4, 4, 16},
         {MAKEFOURCC('A','T','I','2'), "ATI2N",       1, 1,  1},
     };
+    static const struct
+    {
+        D3DPOOL pool;
+        const char *name;
+        HRESULT hr;
+    }
+    pools[] =
+    {
+        {D3DPOOL_DEFAULT,       "D3DPOOL_DEFAULT",  D3DERR_INVALIDCALL},
+        {D3DPOOL_SCRATCH,       "D3DPOOL_SCRATCH",  D3D_OK},
+        {D3DPOOL_SYSTEMMEM,     "D3DPOOL_SYSTEMMEM",D3D_OK},
+        {D3DPOOL_MANAGED,       "D3DPOOL_MANAGED",  D3D_OK},
+    };
+
     hr = IDirect3DDevice9_GetDirect3D(device, &d3d);
     ok(SUCCEEDED(hr), "IDirect3DDevice9_GetDirect3D failed (%08x)\n", hr);
 
-    for (i = 0; i < (sizeof(dxt_formats) / sizeof(*dxt_formats)); ++i) {
-        hr = IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, dxt_formats[i].fmt);
-        if(FAILED(hr))
+    for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i) {
+        surface_only = FALSE;
+        hr = IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC,
+                D3DRTYPE_TEXTURE, formats[i].fmt);
+        if (FAILED(hr))
         {
-            skip("Format %s not supported, skipping lockrect offset test\n", dxt_formats[i].name);
-            continue;
+            hr = IDirect3D9_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, formats[i].fmt);
+            if (FAILED(hr))
+            {
+                skip("Format %s not supported, skipping lockrect offset test\n", formats[i].name);
+                continue;
+            }
+            surface_only = TRUE;
         }
 
-        hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, dxt_formats[i].fmt, D3DPOOL_SCRATCH, &surface, 0);
-        ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (%08x)\n", hr);
+        for (j = 0; j < (sizeof(pools) / sizeof(*pools)); j++)
+        {
+            switch (pools[j].pool)
+            {
+                case D3DPOOL_MANAGED:
+                    if (surface_only) continue;
+                    /* Fall through */
+                case D3DPOOL_DEFAULT:
+                    if (surface_only)
+                    {
+                        hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, formats[i].fmt,
+                                pools[j].pool, &surface, 0);
+                        ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateOffscreenPlainSurface failed (%08x)\n", hr);
+                    }
+                    else
+                    {
+                        hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1,
+                                pools[j].pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0,
+                                formats[i].fmt, pools[j].pool, &texture, NULL);
+                        ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed (%08x)\n", hr);
+                        hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
+                        ok(SUCCEEDED(hr), "IDirect3DTexture9_GetSurfaceLevel failed (%08x)\n", hr);
+                        IDirect3DTexture9_Release(texture);
+                    }
+                    break;
+
+                case D3DPOOL_SCRATCH:
+                case D3DPOOL_SYSTEMMEM:
+                    hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, formats[i].fmt,
+                            D3DPOOL_SCRATCH, &surface, 0);
+                    ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (%08x)\n", hr);
+                    break;
+
+                default:
+                    break;
+            }
 
-        hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
-        ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
+            /* D3DPOOL_DEFAULT does not have reliable base addresses */
+            if (pools[j].pool != D3DPOOL_DEFAULT)
+            {
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
+                ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
 
-        base = locked_rect.pBits;
-        expected_pitch = (128 + dxt_formats[i].block_height - 1) / dxt_formats[i].block_width
-                         * dxt_formats[i].block_size;
-        ok(locked_rect.Pitch == expected_pitch, "Got pitch %d, expected pitch %d for format %s\n", locked_rect.Pitch, expected_pitch, dxt_formats[i].name);
+                base = locked_rect.pBits;
+                expected_pitch = (128 + formats[i].block_height - 1) / formats[i].block_width
+                                * formats[i].block_size;
+                ok(locked_rect.Pitch == expected_pitch, "Got pitch %d, expected pitch %d for format %s\n",
+                        locked_rect.Pitch, expected_pitch, formats[i].name);
 
-        hr = IDirect3DSurface9_UnlockRect(surface);
-        ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
+                hr = IDirect3DSurface9_UnlockRect(surface);
+                ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
 
-        hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &rect, 0);
-        ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &rect, 0);
+                ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
 
-        offset = (BYTE *)locked_rect.pBits - base;
-        expected_offset = (rect.top / dxt_formats[i].block_height) * expected_pitch
-                        + (rect.left / dxt_formats[i].block_width) * dxt_formats[i].block_size;
-        ok(offset == expected_offset, "Got offset %u, expected offset %u for format %s\n", offset, expected_offset, dxt_formats[i].name);
+                offset = (BYTE *)locked_rect.pBits - base;
+                expected_offset = (rect.top / formats[i].block_height) * expected_pitch
+                                + (rect.left / formats[i].block_width) * formats[i].block_size;
+                ok(offset == expected_offset, "Got offset %u, expected offset %u for format %s\n", offset,
+                        expected_offset, formats[i].name);
 
-        hr = IDirect3DSurface9_UnlockRect(surface);
-        ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
+                hr = IDirect3DSurface9_UnlockRect(surface);
+                ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
+            }
 
-        IDirect3DSurface9_Release(surface);
+            if (formats[i].block_width > 1)
+            {
+                SetRect(&partial_rect, 1, 0, formats[i].block_width, formats[i].block_height);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == pools[j].hr, "Partial block lock returned %08x, expected %08x, format %s\n",
+                        hr, pools[j].hr, formats[i].name);
+                if (SUCCEEDED(hr))
+                {
+                    hr = IDirect3DSurface9_UnlockRect(surface);
+                    ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+                }
+
+                SetRect(&partial_rect, 0, 0, formats[i].block_width - 1, formats[i].block_height);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == pools[j].hr, "Partial block lock returned %08x, expected %08x, format %s\n",
+                        hr, pools[j].hr, formats[i].name);
+                if (SUCCEEDED(hr))
+                {
+                    hr = IDirect3DSurface9_UnlockRect(surface);
+                    ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+                }
+            }
+            else
+            {
+                /* Verify that we can lock single columns */
+                SetRect(&partial_rect, 0, 0, 1, formats[i].block_height);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == D3D_OK, "Single column lock returned %08x, expected %08x, format %s\n",
+                        hr, D3D_OK, formats[i].name);
+                hr = IDirect3DSurface9_UnlockRect(surface);
+                ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+            }
+
+            if (formats[i].block_height > 1)
+            {
+                SetRect(&partial_rect, 0, 1, formats[i].block_width, formats[i].block_height);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == pools[j].hr, "Partial block lock returned %08x, expected %08x, format %s\n",
+                        hr, pools[j].hr, formats[i].name);
+                if (SUCCEEDED(hr))
+                {
+                    hr = IDirect3DSurface9_UnlockRect(surface);
+                    ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+                }
+
+                SetRect(&partial_rect, 0, 0, formats[i].block_width, formats[i].block_height - 1);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == pools[j].hr, "Partial block lock returned %08x, expected %08x, format %s\n",
+                        hr, pools[j].hr, formats[i].name);
+                if (SUCCEEDED(hr))
+                {
+                    hr = IDirect3DSurface9_UnlockRect(surface);
+                    ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+                }
+            }
+            else
+            {
+                /* Verify that we can lock single rows */
+                SetRect(&partial_rect, 0, 0, formats[i].block_width, 1);
+                hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &partial_rect, 0);
+                ok(hr == D3D_OK, "Single row lock returned %08x, expected %08x, format %s\n",
+                        hr, D3D_OK, formats[i].name);
+                hr = IDirect3DSurface9_UnlockRect(surface);
+                ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect failed (%08x)\n", hr);
+            }
+
+            IDirect3DSurface9_Release(surface);
+        }
     }
     IDirect3D9_Release(d3d);
 }
@@ -650,7 +784,7 @@ START_TEST(surface)
 
     test_surface_get_container(device_ptr);
     test_surface_alignment(device_ptr);
-    test_lockrect_offset(device_ptr);
+    test_format_blocks(device_ptr);
     test_lockrect_invalid(device_ptr);
     test_private_data(device_ptr);
     test_getdc(device_ptr);
-- 
1.7.3.4

Attachment: signature.asc
Description: This is a digitally signed message part.



Reply via email to