[PATCH 2/4] d3dx9/tests: Test D3DXCheckTextureRequirements.

Philip Nilsson pnilsson at nullref.se
Fri Apr 18 12:07:44 CDT 2008


I'm not too good at DirectX, so some things might be wrong.  I haven't
run the tests on a machine other than my own, so some things might fail
if I'm doing something driver-specific.
---
 dlls/d3dx9_36/tests/Makefile.in |    5 +-
 dlls/d3dx9_36/tests/texture.c   |  251 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 254 insertions(+), 2 deletions(-)
 create mode 100644 dlls/d3dx9_36/tests/texture.c

diff --git a/dlls/d3dx9_36/tests/Makefile.in b/dlls/d3dx9_36/tests/Makefile.in
index 5d72504..45b24a7 100644
--- a/dlls/d3dx9_36/tests/Makefile.in
+++ b/dlls/d3dx9_36/tests/Makefile.in
@@ -3,10 +3,11 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = d3dx9_36.dll
-IMPORTS   = d3dx9 kernel32
+IMPORTS   = d3dx9 user32 kernel32
 
 CTESTS = \
-	math.c
+	math.c \
+	texture.c
 
 @MAKE_TEST_RULES@
 
diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c
new file mode 100644
index 0000000..3b634a8
--- /dev/null
+++ b/dlls/d3dx9_36/tests/texture.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2008 Philip Nilsson
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/test.h"
+#include "d3dx9.h"
+
+/* TODO: Test format replacement, such as D32 -> D16. */
+static void test_D3DXCheckTextureRequirements(IDirect3DDevice9* device)
+{
+    /* These prev- variables are used to check that nothing is unexpectedly
+     * changed. */
+    UINT width = 64,
+         prevwidth = width,
+         height = 64,
+         prevheight = height,
+         miplevels = 0,
+         prevmiplevels = miplevels,
+         i = 0;
+    D3DFORMAT format = D3DFMT_A8R8G8B8,
+              prevformat = format;
+    HRESULT ret;
+
+    /* Verify that D3DERR_INVALIDCALL is returned on NULL device. */
+    ret = D3DXCheckTextureRequirements(NULL, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that some parameters can be NULL.
+     * format can be NULL as well, but with annoying results. */
+    ret = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify what happens if format is NULL. */
+    miplevels = prevmiplevels = 7;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, NULL, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+
+    /* Verify that mipmap level count calculations are correct. */
+    for (i = 1; i < 4096; i *= 2) {
+        UINT expected = 0;
+        UINT tempwidth;
+        prevwidth = prevheight = width = height = i;
+        tempwidth = width;
+        while (tempwidth) {
+            tempwidth = tempwidth >> 1;
+            ++expected;
+        }
+
+        miplevels = 0;
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+        ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+        ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+        ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+        ok(miplevels == expected, "Expected %u, got %u.\n", expected, miplevels);
+        ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    }
+
+    /* Verify that miplevels is set to 9 on NULL width and height. */
+    miplevels = 0;
+    ret = D3DXCheckTextureRequirements(device, NULL, NULL, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(miplevels == 9, "Expected %u, got %u.\n", 9, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that miplevels is correctly set on NULL height and non-NULL width. */
+    prevwidth = width = 64;
+    miplevels = 0;
+    ret = D3DXCheckTextureRequirements(device, &width, NULL, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(miplevels == 7, "Expected %u, got %u.\n", 7, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that miplevels is correctly set on NULL width and non-NULL height. */
+    prevheight = height = 128;
+    miplevels = 0;
+    ret = D3DXCheckTextureRequirements(device, NULL, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(miplevels == 8, "Expected %u, got %u.\n", 8, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that texture sizes are set to 1 if they are 0. */
+    prevmiplevels = miplevels = 1;
+    width = height = 0;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(width == 1, "1 expected, got %u.\n", width);
+    ok(height == 1, "1 expected, got %u.\n", height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that pool is rangechecked, and that the check comes before the 0->1 size replacement. */
+    width = height = 0;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, 0xdeadbeef);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(width == 0, "0 expected, got %u.\n", width);
+    ok(height == 0, "0 expected, got %u.\n", height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that D3DX_DEFAULT is properly replaced. */
+    width = D3DX_DEFAULT;
+    ret = D3DXCheckTextureRequirements(device, &width, NULL, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(width == 256, "256 expected, got %u.\n", width);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    height = D3DX_DEFAULT;
+    ret = D3DXCheckTextureRequirements(device, NULL, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(height == 256, "256 expected, got %u.\n", height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    width = height = D3DX_DEFAULT;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(width == 256, "256 expected, got %u.\n", width);
+    ok(height == 256, "256 expected, got %u.\n", height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that D3DUSAGE_RENDERTARGET can be used. */
+    prevwidth = prevheight = width = height = 64;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that you cannot create a depth stencil using an incompatible format. */
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_DEPTHSTENCIL, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_NOTAVAILABLE, "D3DERR_NOTAVAILABLE expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that depth stencils can be created. */
+    prevformat = format = D3DFMT_D16;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_DEPTHSTENCIL, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+
+    /* Verify that the non-query non-texture usages fail. */
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_WRITEONLY, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_DONOTCLIP, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_POINTS, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_RTPATCHES, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_NPATCHES, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x.\n", ret);
+    ok(prevwidth == width, "Width changed from %u to %u.\n", prevwidth, width);
+    ok(prevheight == height, "Height changed from %u to %u.\n", prevheight, height);
+    ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u.\n", prevmiplevels, miplevels);
+    ok(prevformat == format, "Format changed from %#x to %#x.\n", prevformat, format);
+}
+
+START_TEST(texture)
+{
+    HMODULE d3d9_handle;
+    IDirect3DDevice9* device = NULL;
+    IDirect3D9* (__stdcall *d3d9_create)(UINT SDKVersion) = 0;
+    IDirect3D9* d3d9_ptr = 0;
+    D3DPRESENT_PARAMETERS present_parameters;
+    HRESULT hr;
+    WNDCLASS wc = {0};
+
+    wc.lpfnWndProc = &DefWindowProc;
+    wc.lpszClassName = "d3dx9_test_wc";
+    RegisterClass(&wc);
+
+    d3d9_handle = LoadLibraryA("d3d9.dll");
+    if (!d3d9_handle) {
+        skip("Could not load d3d9.dll.\n");
+        return;
+    }
+
+    d3d9_create = (void*)GetProcAddress(d3d9_handle, "Direct3DCreate9");
+    if (!d3d9_create) {
+        skip("GetProcAddress failed for Direct3DCreate9.\n");
+        return;
+    }
+
+    d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
+    if (!d3d9_ptr) {
+        skip("Direct3DCreate9 failed for argument %#x.\n", D3D_SDK_VERSION);
+        return;
+    }
+
+    ZeroMemory(&present_parameters, sizeof(present_parameters));
+    present_parameters.Windowed = TRUE;
+    present_parameters.hDeviceWindow = CreateWindow("d3dx9_test_wc", "d3dx9_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
+    present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+
+    hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+            NULL, 0, &present_parameters, &device);
+
+    if (FAILED(hr) || !device) {
+        skip("Could not create device, CreateDevice returned %#x.\n", hr);
+        return;
+    }
+
+    test_D3DXCheckTextureRequirements(device);
+}
-- 
1.5.5




More information about the wine-patches mailing list