2 * IWineD3DQuery implementation
4 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wined3d_private.h"
28 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/Queries.asp
31 * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
32 * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
35 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
36 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->wineD3DDevice)->wineD3D))->gl_info
38 /* *******************************************
39 IWineD3DQuery IUnknown parts follow
40 ******************************************* */
41 static HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
43 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
44 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
45 if (IsEqualGUID(riid, &IID_IUnknown)
46 || IsEqualGUID(riid, &IID_IWineD3DBase)
47 || IsEqualGUID(riid, &IID_IWineD3DQuery)) {
48 IUnknown_AddRef(iface);
56 static ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
57 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
58 TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
59 return InterlockedIncrement(&This->ref);
62 static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
63 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
65 TRACE("(%p) : Releasing from %d\n", This, This->ref);
66 ref = InterlockedDecrement(&This->ref);
68 HeapFree(GetProcessHeap(), 0, This->extendedData);
69 HeapFree(GetProcessHeap(), 0, This);
74 /* *******************************************
75 IWineD3DQuery IWineD3DQuery parts follow
76 ******************************************* */
77 static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
78 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
80 *parent= (IUnknown*) parent;
81 IUnknown_AddRef(*parent);
82 TRACE("(%p) : returning %p\n", This, *parent);
86 static HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
87 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
88 IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
89 *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
90 TRACE("(%p) returning %p\n", This, *pDevice);
95 static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
96 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
99 TRACE("(%p) : type %#x, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, This->type, pData, dwSize, dwGetDataFlags);
102 /*you can use this method to poll the resource for the query status*/
103 /*We return success(S_OK) if we support a feature, and faikure(S_FALSE) if we don't, just return success and fluff it for now*/
110 case WINED3DQUERYTYPE_VCACHE:
113 WINED3DDEVINFO_VCACHE *data = (WINED3DDEVINFO_VCACHE *)pData;
114 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VCACHE\n", This);
115 data->Pattern = MAKEFOURCC('C','A','C','H');
116 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
117 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
118 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
122 case WINED3DQUERYTYPE_RESOURCEMANAGER:
124 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
126 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_RESOURCEMANAGER\n", This);
127 for(i = 0; i < WINED3DRTYPECOUNT; i++){
128 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
129 /* isTextureResident could be used to get some of this infomration */
130 data->stats[i].bThrashing = FALSE;
131 data->stats[i].ApproxBytesDownloaded = 1;
132 data->stats[i].NumEvicts = 1;
133 data->stats[i].NumVidCreates = 1;
134 data->stats[i].LastPri = 1;
135 data->stats[i].NumUsed = 1;
136 data->stats[i].NumUsedInVidMem = 1;
137 data->stats[i].WorkingSet = 1;
138 data->stats[i].WorkingSetBytes = 1;
139 data->stats[i].TotalManaged = 1;
140 data->stats[i].TotalBytes = 1;
145 case WINED3DQUERYTYPE_VERTEXSTATS:
147 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
148 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXSTATS\n", This);
149 data->NumRenderedTriangles = 1;
150 data->NumExtraClippingTriangles = 1;
154 case WINED3DQUERYTYPE_EVENT:
157 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_EVENT\n", This);
158 *data = TRUE; /*Don't know what this is supposed to be*/
161 case WINED3DQUERYTYPE_OCCLUSION:
164 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
167 GLuint queryId = ((WineQueryOcclusionData *)This->extendedData)->queryId;
169 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
170 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)\n");
171 TRACE("(%p) : available %d.\n", This, available);
174 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_ARB, &samples));
175 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)\n");
176 TRACE("(%p) : Returning %d samples.\n", This, samples);
183 FIXME("(%p) : Occlusion queries not supported. Returning 1.\n", This);
189 case WINED3DQUERYTYPE_TIMESTAMP:
191 UINT64* data = pData;
192 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMP\n", This);
193 *data = 1; /*Don't know what this is supposed to be*/
196 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
199 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPDISJOINT\n", This);
200 *data = FALSE; /*Don't know what this is supposed to be*/
203 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
205 UINT64* data = pData;
206 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPFREQ\n", This);
207 *data = 1; /*Don't know what this is supposed to be*/
210 case WINED3DQUERYTYPE_PIPELINETIMINGS:
212 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
213 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIPELINETIMINGS\n", This);
215 data->VertexProcessingTimePercent = 1.0f;
216 data->PixelProcessingTimePercent = 1.0f;
217 data->OtherGPUProcessingTimePercent = 97.0f;
218 data->GPUIdleTimePercent = 1.0f;
221 case WINED3DQUERYTYPE_INTERFACETIMINGS:
223 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
224 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_INTERFACETIMINGS\n", This);
226 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
227 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
228 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
229 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
230 data->WaitingForGPUOtherTimePercent = 96.0f;
234 case WINED3DQUERYTYPE_VERTEXTIMINGS:
236 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
237 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXTIMINGS\n", This);
239 data->MemoryProcessingPercent = 50.0f;
240 data->ComputationProcessingPercent = 50.0f;
244 case WINED3DQUERYTYPE_PIXELTIMINGS:
246 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
247 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIXELTIMINGS\n", This);
249 data->MemoryProcessingPercent = 50.0f;
250 data->ComputationProcessingPercent = 50.0f;
253 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
255 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
256 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_BANDWIDTHTIMINGS\n", This);
258 data->MaxBandwidthUtilized = 1.0f;
259 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
260 data->VertexRateUtilizedPercent = 1.0f;
261 data->TriangleSetupRateUtilizedPercent = 1.0f;
262 data->FillRateUtilizedPercent = 97.0f;
265 case WINED3DQUERYTYPE_CACHEUTILIZATION:
267 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
268 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_CACHEUTILIZATION\n", This);
270 data->TextureCacheHitRate = 1.0f;
271 data->PostTransformVertexCacheHitRate = 1.0f;
277 FIXME("(%p) Unhandled query type %d\n",This , This->type);
281 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
282 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
284 return res; /* S_OK if the query data is available*/
288 static DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
289 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
291 TRACE("(%p) : type %#x\n", This, This->type);
293 case WINED3DQUERYTYPE_VCACHE:
294 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
296 case WINED3DQUERYTYPE_RESOURCEMANAGER:
297 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
299 case WINED3DQUERYTYPE_VERTEXSTATS:
300 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
302 case WINED3DQUERYTYPE_EVENT:
303 dataSize = sizeof(BOOL);
305 case WINED3DQUERYTYPE_OCCLUSION:
306 dataSize = sizeof(DWORD);
308 case WINED3DQUERYTYPE_TIMESTAMP:
309 dataSize = sizeof(UINT64);
311 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
312 dataSize = sizeof(BOOL);
314 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
315 dataSize = sizeof(UINT64);
317 case WINED3DQUERYTYPE_PIPELINETIMINGS:
318 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
320 case WINED3DQUERYTYPE_INTERFACETIMINGS:
321 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
323 case WINED3DQUERYTYPE_VERTEXTIMINGS:
324 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
326 case WINED3DQUERYTYPE_PIXELTIMINGS:
327 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
329 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
330 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
332 case WINED3DQUERYTYPE_CACHEUTILIZATION:
333 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
336 FIXME("(%p) Unhandled query type %d\n",This , This->type);
343 static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
344 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
349 static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
350 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
352 TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
354 switch (This->type) {
355 case WINED3DQUERYTYPE_OCCLUSION:
356 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
357 if (dwIssueFlags & D3DISSUE_BEGIN) {
358 GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId));
359 checkGLcall("glBeginQuery()");
361 if (dwIssueFlags & D3DISSUE_END) {
362 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
363 checkGLcall("glEndQuery()");
366 FIXME("(%p) : Occlusion queries not supported\n", This);
371 /* The fixme is printed when the app asks for the resulting data */
372 WARN("(%p) : Unhandled query type %#x\n", This, This->type);
376 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
380 /**********************************************************
381 * IWineD3DQuery VTbl follows
382 **********************************************************/
384 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
386 /*** IUnknown methods ***/
387 IWineD3DQueryImpl_QueryInterface,
388 IWineD3DQueryImpl_AddRef,
389 IWineD3DQueryImpl_Release,
390 /*** IWineD3Dquery methods ***/
391 IWineD3DQueryImpl_GetParent,
392 IWineD3DQueryImpl_GetDevice,
393 IWineD3DQueryImpl_GetData,
394 IWineD3DQueryImpl_GetDataSize,
395 IWineD3DQueryImpl_GetType,
396 IWineD3DQueryImpl_Issue