[D3D9 5/8] State test for textures

Ivan Gyurdiev ivg231 at gmail.com
Mon Oct 2 19:16:10 CDT 2006


This tests regular textures, VTF textures, and the DMAP sampler.

Note: The final release of the VTF textures will cause a hang on native. 
I don't understand why this happens - refcounting seems correct. It may 
be the case the vertex textures aren't supposed to work due to caps... 
but they *do* work - the get and set calls all pass, and the correct 
data is returned. Perhaps this is triggering some kind of a bug in the 
native dll.

I think the test should be merged nevertheless, because the vtf set/get 
calls pass, and the test reports 184 failures on wine (those are really 
caused by about 3-4 bugs). If we determine the cause of this problem 
later, we can easily fix the memory leak.

-------------- next part --------------
>From 169787e9b42f5ad75f753e64167b0f2881dc612c Mon Sep 17 00:00:00 2001
From: Ivan Gyurdiev <ivg2 at cornell.edu>
Date: Mon, 2 Oct 2006 19:38:55 -0400
Subject: [PATCH] State test for textures.

This tests regular textures, VTF textures, and the DMAP sampler.

Note: The final release of the VTF textures will cause a hang on native. I don't understand why this happens - refcounting seems correct. It may be the case the vertex textures aren't supposed to work due to caps... but they *do* work - the get and set calls all pass, and the correct data is returned. Perhaps this is triggering some kind of a bug in the native dll.

I think the test should be merged nevertheless, because the vtf set/get calls pass, and the test reports 184 failures on wine (those are really caused by about 3-4 bugs). If we determine the cause later, we can easily fix it.
---
 dlls/d3d9/tests/stateblock.c |  235 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 233 insertions(+), 2 deletions(-)

diff --git a/dlls/d3d9/tests/stateblock.c b/dlls/d3d9/tests/stateblock.c
index 6c300ae..5349cbd 100644
--- a/dlls/d3d9/tests/stateblock.c
+++ b/dlls/d3d9/tests/stateblock.c
@@ -1370,6 +1370,231 @@ static void render_states_queue_test(
     test->test_arg = test_arg;
 }
 
+/* =================== State test: Textures  ==================================== */
+
+#define MAX_SAMPLERS 16
+#define MAX_VERTEX_SAMPLERS 4
+
+typedef struct texture_data {
+    IDirect3DBaseTexture9* tex[16];
+    IDirect3DBaseTexture9* tex_dmap;
+    IDirect3DBaseTexture9* tex_vertex[4];
+} texture_data;
+
+typedef struct texture_arg {
+    IDirect3DDevice9* device;
+} texture_arg;
+
+static void texture_default_data_init(
+    texture_data* data) {
+
+    unsigned int i;
+
+    for (i = 0; i < MAX_SAMPLERS; i++)
+        data->tex[i] = NULL;
+
+    data->tex_dmap = NULL;
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++)
+        data->tex_vertex[i] = NULL;
+}
+
+static void texture_poison_data_init(
+    texture_data* data) {
+
+    unsigned int i;
+   
+    for (i = 0; i < MAX_SAMPLERS; i++)
+        data->tex[i] = (void*) 0x1337c0de;
+
+    data->tex_dmap = (void*) 0x1337c0de;
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++)
+        data->tex_vertex[i] = (void*) 0x1337c0de;
+}
+
+static IDirect3DBaseTexture9* texture_make_default(
+    IDirect3DDevice9* device) {
+
+    HRESULT hret;
+    IDirect3DTexture9* texture = NULL;
+
+    UINT default_width = 8;
+    UINT default_height = 8;
+    UINT default_levels = 1;
+    DWORD default_usage = 0;
+    D3DFORMAT default_fmt = D3DFMT_A8R8G8B8;
+    D3DPOOL default_pool = D3DPOOL_DEFAULT;
+    
+    hret = IDirect3DDevice9_CreateTexture(device, default_width, default_height, default_levels,
+       default_usage, default_fmt, default_pool, &texture, NULL);
+    ok (hret == D3D_OK, "CreateTexture returned %#lx.\n", hret);  
+
+    return (IDirect3DBaseTexture9*) texture;
+}
+
+static void texture_test_data_init(
+    IDirect3DDevice9* device,
+    texture_data* data) {
+
+    unsigned int i;
+    for (i = 0; i < MAX_SAMPLERS; i++)
+        data->tex[i] = texture_make_default(device);
+
+    data->tex_dmap = texture_make_default(device);
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++)
+        data->tex_vertex[i] = texture_make_default(device);
+}
+
+static void texture_test_data_release(
+    texture_data* data) {
+
+    unsigned int i;
+
+    for (i = 0; i < MAX_SAMPLERS; i++) {
+        if (data->tex[i])
+            IUnknown_Release(data->tex[i]);
+    }
+
+    if (data->tex_dmap)
+        IUnknown_Release(data->tex_dmap);
+
+#if 0
+   
+    /* This is disabled, because it hangs on native.
+     * The reason is unknown - refcounting appears to work properly,
+     * and the Set/Get on vertex textures succeed.
+     * For now, we'll leak memory to workaround the issue */
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++) {
+        if (data->tex_vertex[i])
+            IUnknown_Release(data->tex_vertex[i]);
+    }
+
+#endif
+}
+
+static void texture_set_handler(
+    IDirect3DDevice9* device, const state_test* test, const void* data) {
+
+    HRESULT hret;
+    unsigned int i;
+    texture_data* tdata = (texture_data*) data;
+
+    for (i = 0; i < MAX_SAMPLERS; i++) {
+        hret = IDirect3DDevice9_SetTexture(device, i, tdata->tex[i]);
+        ok(hret == D3D_OK, "SetTexture returned %#lx for sampler %u.\n", hret, i);
+    }
+
+    hret = IDirect3DDevice9_SetTexture(device, D3DDMAPSAMPLER, tdata->tex_dmap);
+    ok(hret == D3D_OK, "SetTexture returned %#lx for sampler %u.\n", hret, D3DDMAPSAMPLER);
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++) {
+        hret = IDirect3DDevice9_SetTexture(device, D3DVERTEXTEXTURESAMPLER0 + i, tdata->tex_vertex[i]);
+        ok(hret == D3D_OK, "SetTexture returned %#lx for sampler %u.\n", hret, D3DVERTEXTEXTURESAMPLER0 + i);
+    }
+}
+
+static void texture_get_handler(
+    IDirect3DDevice9* device, const state_test* test, const void* data) {
+
+    HRESULT hret;
+    unsigned int i;
+    texture_data* tdata = (texture_data*) data;
+
+    for (i = 0; i < MAX_SAMPLERS; i++) {
+        hret = IDirect3DDevice9_GetTexture(device, i, &tdata->tex[i]);
+        ok(hret == D3D_OK, "GetTexture returned %#lx for sampler %u.\n", hret, i);
+        if (hret == D3D_OK && tdata->tex[i])
+            IUnknown_Release(tdata->tex[i]);
+    }
+
+    hret = IDirect3DDevice9_GetTexture(device, D3DDMAPSAMPLER, &tdata->tex_dmap);
+    ok(hret == D3D_OK, "GetTexture returned %#lx for sampler %u.\n", hret, D3DDMAPSAMPLER);
+    if (hret == D3D_OK && tdata->tex_dmap)
+        IUnknown_Release(tdata->tex_dmap);
+        
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++) {
+        hret = IDirect3DDevice9_GetTexture(device, D3DVERTEXTEXTURESAMPLER0 + i, &tdata->tex_vertex[i]);
+        ok(hret == D3D_OK, "GetTexture returned %#lx for sampler %u.\n", hret, D3DVERTEXTEXTURESAMPLER0 + i);
+        if (hret == D3D_OK && tdata->tex_vertex[i])
+            IUnknown_Release(tdata->tex_vertex[i]);
+    }
+}
+
+static void texture_print_handler(
+    const void* data) {
+
+    unsigned int i;
+    texture_data* tdata = (texture_data*) data;
+
+    for (i = 0; i < MAX_SAMPLERS; i++)
+        trace("Sampler = %u, Texture = %p\n", i, tdata->tex[i]);
+
+    trace("Sampler = %u, Texture = %p\n", D3DDMAPSAMPLER, tdata->tex_dmap);
+
+    for (i = 0; i < MAX_VERTEX_SAMPLERS; i++)
+        trace("Sampler = %u, Texture = %p\n", D3DVERTEXTEXTURESAMPLER0 + i, tdata->tex_vertex[i]);
+}
+
+static HRESULT texture_setup_handler(
+    state_test* test) {
+
+    texture_arg* targ = (texture_arg*) test->test_arg;
+
+    test->return_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(texture_data));
+    if (test->return_data == NULL)
+        return E_FAIL;
+
+    test->default_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(texture_data));
+    if (test->default_data == NULL)
+        return E_FAIL;
+
+    test->test_data_in = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(texture_data));
+    if (test->test_data_in == NULL)
+        return E_FAIL;
+
+    test->poison_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(texture_data));
+    if (test->poison_data == NULL)
+        return E_FAIL;
+
+    texture_default_data_init(test->default_data);
+    texture_test_data_init(targ->device, test->test_data_in);
+    texture_poison_data_init(test->poison_data);
+
+    test->initial_data = test->default_data;
+    test->test_data_out = test->test_data_in;
+
+    test->data_size = sizeof(texture_data);
+
+    return D3D_OK;
+}
+
+static void texture_teardown_handler(
+    state_test* test) {
+
+    texture_test_data_release(test->test_data_in);
+ 
+    HeapFree(GetProcessHeap(), 0, test->return_data);
+    HeapFree(GetProcessHeap(), 0, test->default_data);
+    HeapFree(GetProcessHeap(), 0, test->test_data_in);
+    HeapFree(GetProcessHeap(), 0, test->poison_data);
+}
+
+static void textures_queue_test(
+    state_test* test,
+    texture_arg* test_arg) {
+
+    test->setup_handler = texture_setup_handler;
+    test->teardown_handler = texture_teardown_handler;
+    test->set_handler = texture_set_handler;
+    test->get_handler = texture_get_handler;
+    test->print_handler = texture_print_handler;
+    test->test_name = "set_get_texture";
+    test->test_arg = test_arg;
+}
+
 /* =================== Main state tests function =============================== */
 
 static void test_state_management(
@@ -1383,15 +1608,17 @@ static void test_state_management(
                    1 for lights
                    1 for transforms
                    1 for render states
+                   1 for textures
      */
-    const int max_tests = 5;
-    state_test tests[5];
+    const int max_tests = 6;
+    state_test tests[6];
     unsigned int tcount = 0;
 
     shader_constant_arg pshader_constant_arg;
     shader_constant_arg vshader_constant_arg;
     render_state_arg render_state_arg;
     light_arg light_arg;
+    texture_arg texture_arg;
 
     hret = IDirect3DDevice9_GetDeviceCaps(device, &caps);
     ok(hret == D3D_OK, "GetDeviceCaps returned %#lx.\n", hret);
@@ -1427,6 +1654,10 @@ static void test_state_management(
     render_states_queue_test(&tests[tcount], &render_state_arg);
     tcount++;
 
+    texture_arg.device = device;
+    textures_queue_test(&tests[tcount], &texture_arg);
+    tcount++;
+
     execute_test_chain_all(device, tests, tcount);
 }
 
-- 
1.4.2.1



More information about the wine-patches mailing list