[PATCH 6/7] d3dx9/tests: Test D3DXCheckTextureRequirements.

Philip Nilsson pnilsson at nullref.se
Mon Aug 25 10:15:18 CDT 2008


---
 dlls/d3dx9_36/tests/Makefile.in |    5 +-
 dlls/d3dx9_36/tests/texture.c   |  314 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 317 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 40500e2..d32aef9 100644
--- a/dlls/d3dx9_36/tests/Makefile.in
+++ b/dlls/d3dx9_36/tests/Makefile.in
@@ -3,11 +3,12 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = d3dx9_36.dll
-IMPORTS   = d3dx9 kernel32
+IMPORTS   = d3dx9 user32 kernel32
 
 CTESTS = \
 	math.c \
-	shader.c
+	shader.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..6e2599c
--- /dev/null
+++ b/dlls/d3dx9_36/tests/texture.c
@@ -0,0 +1,314 @@
+/*
+ * 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"
+
+IDirect3D9* d3d9_ptr = 0;
+
+static void test_D3DXCheckTextureRequirements(IDirect3DDevice9* device)
+{
+    /* All standard formats with a depth channel. */
+    static const D3DFORMAT format_depth[] = {
+        D3DFMT_D16_LOCKABLE, D3DFMT_D32, D3DFMT_D15S1, D3DFMT_D24S8,
+        D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D16, D3DFMT_D32F_LOCKABLE,
+        D3DFMT_D24FS8
+    };
+    /* 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 %u to %u.\n", prevformat, format);
+
+    /* Verify that some parameters can be NULL. */
+    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 %u to %u.\n", prevformat, format);
+
+    /* Verify that nothing happens when 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(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 %u to %u.\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 %u to %u.\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 %u to %u.\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 %u to %u.\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 %u to %u.\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 %u to %u.\n", prevformat, format);
+
+    /* Verify that D3DX_DEFAULT is replaced when the other parameter has a value. */
+    width = D3DX_DEFAULT;
+    height = 256;
+    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 %u to %u.\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 %u to %u.\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 %u to %u.\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 %u to %u.\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 %u to %u.\n", prevformat, format);
+
+    /* Verify that you cannot create a depth buffer using an incompatible
+     * format and that invalid depth buffer formats are not replaced. */
+    prevformat = format = D3DFMT_A8R8G8B8;
+    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 %u to %u.\n", prevformat, format);
+
+    /* Verify that depth buffers can be used. */
+    /* TODO: Check that the device supports this first. */
+    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 %u to %u.\n", prevformat, format);
+
+    /* Verify that the non-query non-texture usages fail. */
+    prevformat = format = D3DFMT_A8R8G8B8;
+    for (i = 0; i < 5; ++i) {
+        static const DWORD usages[] = { D3DUSAGE_WRITEONLY, D3DUSAGE_DONOTCLIP, D3DUSAGE_POINTS, D3DUSAGE_RTPATCHES, D3DUSAGE_NPATCHES };
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, usages[i], &format, D3DPOOL_DEFAULT);
+        ok(ret == D3DERR_INVALIDCALL, "D3DERR_INVALIDCALL expected, got %#x. (%u)\n", ret, i);
+        ok(prevwidth == width, "Width changed from %u to %u. (%u)\n", prevwidth, width, i);
+        ok(prevheight == height, "Height changed from %u to %u. (%u)\n", prevheight, height, i);
+        ok(prevmiplevels == miplevels, "Miplevels changed from %u to %u. (%u)\n", prevmiplevels, miplevels, i);
+        ok(prevformat == format, "Format changed from %u to %u. (%u)\n", prevformat, format, i);
+    }
+
+    /* Verify that invalid formats are replaced by D3DFMT_A8R8G8B8. */
+    format = 0xdeadbeef;
+    ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+    ok(ret == D3D_OK, "D3D_OK expected, got %#x.\n", ret);
+    ok(format == D3DFMT_A8R8G8B8, "Format %u expected for %u, got %u.\n", D3DFMT_A8R8G8B8, 0xdeadbeef, 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 invalid depth buffer formats are not replaced. */
+    prevformat = format = 0xdeadbeef;
+    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 %u to %u.\n", prevformat, format);
+
+    /* Verify that D3DUSAGE_RENDERTARGET and D3DUSAGE_DEPTHSTENCIL will return
+     * no formats when used together.
+     * 118 is the highest standard texture format index plus one. */
+    for (i = 0; i < 118; ++i) {
+        format = i;
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL, &format, D3DPOOL_DEFAULT);
+        ok(ret == D3DERR_NOTAVAILABLE, "D3DERR_NOTAVAILABLE expected, got %#x.\n", ret);
+        ok(format == i, "Format changed from %u to %u.\n", i, 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 a valid format is always returned. */
+    for (i = 0; i < 118; ++i) {
+        format = i;
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, 0, &format, D3DPOOL_DEFAULT);
+        ok(ret == D3D_OK, "D3D_OK expected, got %#x. (%u)\n", ret, i);
+        if (ret == D3D_OK) {
+            ret = IDirect3D9_CheckDeviceFormat(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, format);
+            ok(ret == D3D_OK, "D3D_OK expected, got %#x. (%u -> %u)\n", ret, i, format);
+        }
+
+        format = i;
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
+        if (ret == D3D_OK) {
+            ret = IDirect3D9_CheckDeviceFormat(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, format);
+            ok(ret == D3D_OK, "D3D_OK expected, got %#x. (%u -> %u)\n", ret, i, format);
+        }
+    }
+
+    /* Verify that a valid format is always returned. */
+    for (i = 0; i < sizeof(format_depth) / sizeof(D3DFORMAT); ++i) {
+        format = format_depth[i];
+        ret = D3DXCheckTextureRequirements(device, &width, &height, &miplevels, D3DUSAGE_DEPTHSTENCIL, &format, D3DPOOL_DEFAULT);
+        ok(ret == D3D_OK, "D3D_OK expected, got %#x. (%u)\n", ret, format_depth[i]);
+        if (ret == D3D_OK) {
+            ret = IDirect3D9_CheckDeviceFormat(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
+            ok(ret == D3D_OK, "D3D_OK expected, got %u. (%u -> %u)\n", ret, format_depth[i], format);
+            printf("%u -> %u\n", format_depth[i], 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);
+}
+
+START_TEST(texture)
+{
+    HMODULE d3d9_handle;
+    IDirect3DDevice9* device = NULL;
+    IDirect3D9* (__stdcall *d3d9_create)(UINT SDKVersion) = 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, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
+
+    if (FAILED(hr) || !device) {
+        skip("Could not create device, CreateDevice returned %#x.\n", hr);
+        return;
+    }
+
+    test_D3DXCheckTextureRequirements(device);
+}
-- 
1.6.0.2


--uQr8t48UFsdbeI+V--



More information about the wine-patches mailing list