[PATCH 1/5] d3d9/tests: Test GetData behavior with various size values. (try 3)

Matteo Bruni mbruni at codeweavers.com
Mon May 12 10:45:15 CDT 2014


---
 dlls/d3d9/tests/device.c | 119 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 96 insertions(+), 23 deletions(-)

diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 894e566..441c692 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -4517,7 +4517,13 @@ static void test_query_support(void)
 
 static void test_occlusion_query_states(void)
 {
-    static const float point[3] = {0.0, 0.0, 0.0};
+    static const float quad[] =
+    {
+        -1.0f, -1.0f, 0.0f,
+        -1.0f,  1.0f, 0.0f,
+         1.0f,  1.0f, 0.0f,
+         1.0f, -1.0f, 0.0f,
+    };
     IDirect3DQuery9 *query = NULL;
     unsigned int data_size, i;
     IDirect3DDevice9 *device;
@@ -4525,7 +4531,12 @@ static void test_occlusion_query_states(void)
     ULONG refcount;
     HWND window;
     HRESULT hr;
-    BYTE *data;
+    union
+    {
+        WORD word[4];
+        DWORD dword[2];
+    } data;
+    BOOL broken_occlusion = FALSE;
 
     window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
@@ -4551,11 +4562,11 @@ static void test_occlusion_query_states(void)
     }
 
     data_size = IDirect3DQuery9_GetDataSize(query);
-    data = HeapAlloc(GetProcessHeap(), 0, data_size);
+    ok(data_size == sizeof(DWORD), "Unexpected data size %u.\n", data_size);
 
     hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, data, data_size, D3DGETDATA_FLUSH);
+    hr = IDirect3DQuery9_GetData(query, &data, data_size, D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
 
     hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
@@ -4565,19 +4576,19 @@ static void test_occlusion_query_states(void)
     hr = IDirect3DQuery9_Issue(query, D3DISSUE_BEGIN);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
 
-    *((DWORD *)data) = 0x12345678;
+    data.dword[0] = 0x12345678;
     hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH);
     ok(hr == S_FALSE || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, data, data_size, D3DGETDATA_FLUSH);
+    hr = IDirect3DQuery9_GetData(query, &data, data_size, D3DGETDATA_FLUSH);
     ok(hr == S_FALSE || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
     if (hr == D3D_OK)
-        ok(!*(DWORD *)data, "Got unexpected query result %u.\n", *(DWORD *)data);
+        ok(!data.dword[0], "Got unexpected query result %u.\n", data.dword[0]);
 
     hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
     ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
     hr = IDirect3DDevice9_BeginScene(device);
     ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
-    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
+    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, 3 * sizeof(float));
     ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
     hr = IDirect3DDevice9_EndScene(device);
     ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
@@ -4592,10 +4603,50 @@ static void test_occlusion_query_states(void)
     }
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
 
-    hr = IDirect3DQuery9_GetData(query, data, data_size, D3DGETDATA_FLUSH);
+    memset(&data, 0xff, sizeof(data));
+    hr = IDirect3DQuery9_GetData(query, &data, sizeof(WORD), D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, data, data_size, D3DGETDATA_FLUSH);
+    ok(data.word[0] == 0xd7a0 || broken(!data.word[0]),
+            "Occlusion query returned an unexpected result (0x%.8x).\n", data.dword[0]);
+    if (!data.word[0])
+    {
+        skip("Occlusion query result looks broken, ignoring returned count.\n");
+        broken_occlusion = TRUE;
+    }
+    todo_wine ok(data.word[1] == 0xffff,
+            "data was modified outside of the expected size (0x%.8x).\n", data.dword[0]);
+    hr = IDirect3DQuery9_GetData(query, &data, data_size, D3DGETDATA_FLUSH);
+    ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    if (!broken_occlusion)
+        ok(data.dword[0] == 0xfd7a0,
+                "Occlusion query returned an unexpected result (0x%.8x).\n", data.dword[0]);
+
+    memset(&data, 0xf0, sizeof(data));
+    hr = IDirect3DQuery9_GetData(query, &data, sizeof(data), D3DGETDATA_FLUSH);
+    ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    if (!broken_occlusion)
+        ok(data.dword[0] == 0xfd7a0,
+                "Occlusion query returned an unexpected result (0x%.8x).\n", data.dword[0]);
+    /* Different drivers seem to return different data in those high bytes on Windows, but they all
+       write something there and the extra data is consistent (I've seen 0x00000000 and 0xdddddddd
+       on AMD and Nvidia respectively). */
+    if (0)
+    {
+        ok(data.dword[1] != 0xf0f0f0f0, "high bytes of data were not modified (0x%.8x).\n",
+                data.dword[1]);
+    }
+
+    memset(&data, 0xff, sizeof(data));
+    hr = IDirect3DQuery9_GetData(query, &data, 0, D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    todo_wine ok(data.dword[0] == 0xffffffff, "Occlusion query returned an unexpected result (0x%.8x).\n", data.dword[0]);
+
+    /* This crashes on Windows. */
+    if (0)
+    {
+        hr = IDirect3DQuery9_GetData(query, NULL, data_size, D3DGETDATA_FLUSH);
+        ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    }
 
     hr = IDirect3DQuery9_Issue(query, D3DISSUE_BEGIN);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
@@ -4604,7 +4655,6 @@ static void test_occlusion_query_states(void)
     hr = IDirect3DQuery9_Issue(query, D3DISSUE_END);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
 
-    HeapFree(GetProcessHeap(), 0, data);
     IDirect3DQuery9_Release(query);
     refcount = IDirect3DDevice9_Release(device);
     ok(!refcount, "Device has %u references left.\n", refcount);
@@ -4614,7 +4664,13 @@ static void test_occlusion_query_states(void)
 
 static void test_timestamp_query(void)
 {
-    static const float point[3] = {0.0, 0.0, 0.0};
+    static const float quad[] =
+    {
+        -1.0f, -1.0f, 0.0f,
+        -1.0f,  1.0f, 0.0f,
+         1.0f,  1.0f, 0.0f,
+         1.0f, -1.0f, 0.0f,
+    };
     IDirect3DQuery9 *query, *disjoint_query, *freq_query;
     unsigned int data_size, i;
     IDirect3DDevice9 *device;
@@ -4622,8 +4678,8 @@ static void test_timestamp_query(void)
     ULONG refcount;
     HWND window;
     HRESULT hr;
-    UINT64 timestamp, freq;
-    BOOL disjoint;
+    DWORD timestamp[2], freq[2];
+    WORD disjoint[2];
 
     window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
             0, 0, 640, 480, 0, 0, 0, 0);
@@ -4669,12 +4725,20 @@ static void test_timestamp_query(void)
         Sleep(10);
     }
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+    memset(freq, 0xff, sizeof(freq));
+    hr = IDirect3DQuery9_GetData(freq_query, freq, sizeof(DWORD), D3DGETDATA_FLUSH);
+    ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    todo_wine ok(freq[1] == 0xffffffff,
+            "freq was modified outside of the expected size (0x%.8x).\n", freq[1]);
     hr = IDirect3DQuery9_GetData(freq_query, &freq, sizeof(freq), D3DGETDATA_FLUSH);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+    ok(freq[1] != 0xffffffff, "high bytes of freq were not modified (0x%.8x).\n",
+            freq[1]);
 
     hr = IDirect3DQuery9_GetData(query, NULL, 0, D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
+    hr = IDirect3DQuery9_GetData(query, timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
 
     hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_END);
@@ -4684,14 +4748,14 @@ static void test_timestamp_query(void)
     hr = IDirect3DQuery9_Issue(disjoint_query, D3DISSUE_BEGIN);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
 
-    hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
+    hr = IDirect3DQuery9_GetData(query, timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
     ok(hr == S_FALSE || hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
 
     hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ);
     ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
     hr = IDirect3DDevice9_BeginScene(device);
     ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
-    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
+    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, 3 * sizeof(float));
     ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
     hr = IDirect3DDevice9_EndScene(device);
     ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
@@ -4706,10 +4770,12 @@ static void test_timestamp_query(void)
     }
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
 
-    hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
-    ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
+    memset(timestamp, 0xff, sizeof(timestamp));
+    hr = IDirect3DQuery9_GetData(query, timestamp, sizeof(DWORD), D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    todo_wine ok(timestamp[1] == 0xffffffff,
+            "timestamp was modified outside of the expected size (0x%.8x).\n",
+            timestamp[1]);
 
     hr = IDirect3DQuery9_Issue(query, D3DISSUE_BEGIN);
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
@@ -4727,14 +4793,21 @@ static void test_timestamp_query(void)
         Sleep(10);
     }
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(disjoint_query, &disjoint, sizeof(disjoint), D3DGETDATA_FLUSH);
+
+    memset(disjoint, 0xff, sizeof(disjoint));
+    hr = IDirect3DQuery9_GetData(disjoint_query, disjoint, sizeof(WORD), D3DGETDATA_FLUSH);
+    ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    todo_wine ok(disjoint[1] == 0xffff,
+            "disjoint was modified outside of the expected size (0x%.4hx).\n", disjoint[1]);
+    hr = IDirect3DQuery9_GetData(disjoint_query, disjoint, sizeof(disjoint), D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    ok(disjoint[1] != 0xffff, "high bytes of disjoint were not modified (0x%.4hx).\n", disjoint[1]);
 
     /* It's not strictly necessary for the TIMESTAMP query to be inside
      * a TIMESTAMP_DISJOINT query. */
     hr = IDirect3DDevice9_BeginScene(device);
     ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
-    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
+    hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, 3 * sizeof(float));
     ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
     hr = IDirect3DDevice9_EndScene(device);
     ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
@@ -4748,7 +4821,7 @@ static void test_timestamp_query(void)
         Sleep(10);
     }
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    hr = IDirect3DQuery9_GetData(query, &timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
+    hr = IDirect3DQuery9_GetData(query, timestamp, sizeof(timestamp), D3DGETDATA_FLUSH);
     ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
 
     IDirect3DQuery9_Release(query);
-- 
1.8.5.5




More information about the wine-patches mailing list