mcicda: Exclude unused headers.
[wine] / dlls / d3d9 / tests / query.c
1 /*
2  * Copyright (C) 2006-2007 Stefan Dösinger(For CodeWeavers)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #include <d3d9.h>
21 #include <dxerr9.h>
22 #include "wine/test.h"
23
24 static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT);
25
26 struct queryInfo
27 {
28     D3DQUERYTYPE type;      /* Query to test */
29     BOOL foundSupported;    /* If at least one windows driver has been found supporting this query */
30     BOOL foundUnsupported;  /* If at least one windows driver has been found which does not support this query */
31 };
32
33 /* When running running this test on windows reveals any differences regarding known supported / unsupported queries,
34  * change this table.
35  *
36  * When marking a query known supported or known unsupported please write one card which supports / does not support
37  * the query.
38  */
39 static struct queryInfo queries[] =
40 {
41     {D3DQUERYTYPE_VCACHE,               TRUE /* geforce 6600 */,    TRUE /* geforce 2 mx */ },
42     {D3DQUERYTYPE_RESOURCEMANAGER,      FALSE,                      TRUE /* geforce 2 mx */ },
43     {D3DQUERYTYPE_VERTEXSTATS,          FALSE,                      TRUE /* geforce 2 mx */ },
44     {D3DQUERYTYPE_EVENT,                TRUE /* geforce 2 mx */,    TRUE /* ati mach64 */   },
45     {D3DQUERYTYPE_OCCLUSION,            TRUE /* radeon M9 */,       TRUE /* geforce 2 mx */ },
46     {D3DQUERYTYPE_TIMESTAMP,            TRUE /* geforce 6600 */,    TRUE /* geforce 2 mx */ },
47     {D3DQUERYTYPE_TIMESTAMPDISJOINT,    TRUE /* geforce 6600 */,    TRUE /* geforce 2 mx */ },
48     {D3DQUERYTYPE_TIMESTAMPFREQ,        TRUE /* geforce 6600 */,    TRUE /* geforce 2 mx */ },
49     {D3DQUERYTYPE_PIPELINETIMINGS,      FALSE,                      TRUE /* geforce 2 mx */ },
50     {D3DQUERYTYPE_INTERFACETIMINGS,     FALSE,                      TRUE /* geforce 2 mx */ },
51     {D3DQUERYTYPE_VERTEXTIMINGS,        FALSE,                      TRUE /* geforce 2 mx */ },
52     {D3DQUERYTYPE_PIXELTIMINGS,         FALSE,                      TRUE /* geforce 2 mx */ },
53     {D3DQUERYTYPE_BANDWIDTHTIMINGS,     FALSE,                      TRUE /* geforce 2 mx */ },
54     {D3DQUERYTYPE_CACHEUTILIZATION,     FALSE,                      TRUE /* geforce 2 mx */ },
55 };
56
57 static const char *queryName(D3DQUERYTYPE type)
58 {
59     switch(type)
60     {
61         case D3DQUERYTYPE_VCACHE:               return "D3DQUERYTYPE_VCACHE";
62         case D3DQUERYTYPE_RESOURCEMANAGER:      return "D3DQUERYTYPE_RESOURCEMANAGER";
63         case D3DQUERYTYPE_VERTEXSTATS:          return "D3DQUERYTYPE_VERTEXSTATS";
64         case D3DQUERYTYPE_EVENT:                return "D3DQUERYTYPE_EVENT";
65         case D3DQUERYTYPE_OCCLUSION:            return "D3DQUERYTYPE_OCCLUSION";
66         case D3DQUERYTYPE_TIMESTAMP:            return "D3DQUERYTYPE_TIMESTAMP";
67         case D3DQUERYTYPE_TIMESTAMPDISJOINT:    return "D3DQUERYTYPE_TIMESTAMPDISJOINT";
68         case D3DQUERYTYPE_TIMESTAMPFREQ:        return "D3DQUERYTYPE_TIMESTAMPFREQ";
69         case D3DQUERYTYPE_PIPELINETIMINGS:      return "D3DQUERYTYPE_PIPELINETIMINGS";
70         case D3DQUERYTYPE_INTERFACETIMINGS:     return "D3DQUERYTYPE_INTERFACETIMINGS";
71         case D3DQUERYTYPE_VERTEXTIMINGS:        return "D3DQUERYTYPE_VERTEXTIMINGS";
72         case D3DQUERYTYPE_PIXELTIMINGS:         return "D3DQUERYTYPE_PIXELTIMINGS";
73         case D3DQUERYTYPE_BANDWIDTHTIMINGS:     return "D3DQUERYTYPE_BANDWIDTHTIMINGS";
74         case D3DQUERYTYPE_CACHEUTILIZATION:     return "D3DQUERYTYPE_CACHEUTILIZATION";
75         default: return "Unexpected query type";
76     }
77 }
78
79 static void test_query_support(IDirect3D9 *pD3d, HWND hwnd)
80 {
81
82     HRESULT               hr;
83
84     IDirect3DDevice9      *pDevice = NULL;
85     D3DPRESENT_PARAMETERS d3dpp;
86     D3DDISPLAYMODE        d3ddm;
87     int                   i;
88     IDirect3DQuery9       *pQuery = NULL;
89     BOOL supported;
90
91     IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
92     ZeroMemory( &d3dpp, sizeof(d3dpp) );
93     d3dpp.Windowed         = TRUE;
94     d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
95     d3dpp.BackBufferFormat = d3ddm.Format;
96
97     hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
98                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
99     ok(SUCCEEDED(hr), "Failed to create IDirect3D9Device (%s)\n", DXGetErrorString9(hr));
100     if (FAILED(hr)) goto cleanup;
101
102     for(i = 0; i < sizeof(queries) / sizeof(queries[0]); i++)
103     {
104         hr = IDirect3DDevice9_CreateQuery(pDevice, queries[i].type, NULL);
105         ok(hr == D3D_OK || D3DERR_NOTAVAILABLE,
106            "IDirect3DDevice9_CreateQuery returned unexpected return value %s for query %s\n", DXGetErrorString9(hr), queryName(queries[i].type));
107
108         supported = (hr == D3D_OK ? TRUE : FALSE);
109         trace("query %s is %s\n", queryName(queries[i].type), supported ? "supported" : "not supported");
110
111         ok(!(supported == TRUE && queries[i].foundSupported == FALSE),
112             "Query %s is supported on this system, but was not found supported before\n",
113             queryName(queries[i].type));
114         ok(!(supported == FALSE && queries[i].foundUnsupported == FALSE),
115             "Query %s is not supported on this system, but was found to be supported on all other systems tested before\n",
116             queryName(queries[i].type));
117
118         hr = IDirect3DDevice9_CreateQuery(pDevice, queries[i].type, &pQuery);
119         ok(hr == D3D_OK || D3DERR_NOTAVAILABLE,
120            "IDirect3DDevice9_CreateQuery returned unexpected return value %s for query %s\n", DXGetErrorString9(hr), queryName(queries[i].type));
121         ok(!(supported && !pQuery), "Query %s was claimed to be supported, but can't be created\n", queryName(queries[i].type));
122         ok(!(!supported && pQuery), "Query %s was claimed not to be supported, but can be created\n", queryName(queries[i].type));
123         if(pQuery)
124         {
125             IDirect3DQuery9_Release(pQuery);
126             pQuery = NULL;
127         }
128     }
129
130     cleanup:
131     if(pDevice) IDirect3DDevice9_Release(pDevice);
132 }
133
134 START_TEST(query)
135 {
136     HMODULE d3d9_handle = LoadLibraryA( "d3d9.dll" );
137     if (!d3d9_handle)
138     {
139         skip("Could not load d3d9.dll\n");
140         return;
141     }
142
143     pDirect3DCreate9 = (void *)GetProcAddress( d3d9_handle, "Direct3DCreate9" );
144     ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
145     if (pDirect3DCreate9)
146     {
147         IDirect3D9            *pD3d = NULL;
148         HWND                  hwnd = NULL;
149
150         pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
151         if(!pD3d)
152         {
153             skip("Failed to create Direct3D9 object, not running tests\n");
154             return;
155         }
156         hwnd = CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
157         if(!hwnd)
158         {
159             skip("Failed to create window\n");
160             IDirect3D9_Release(pD3d);
161             return;
162         }
163
164         test_query_support(pD3d, hwnd);
165
166         DestroyWindow(hwnd);
167         IDirect3D9_Release(pD3d);
168     }
169 }