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 if(This->type == WINED3DQUERYTYPE_EVENT && GL_SUPPORT(NV_FENCE)) {
69 GL_EXTCALL(glDeleteFencesNV(1, &((WineQueryEventData *)(This->extendedData))->fenceId));
70 checkGLcall("glDeleteFencesNV");
71 } else if(This->type == WINED3DQUERYTYPE_OCCLUSION && GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
72 GL_EXTCALL(glDeleteQueriesARB(1, &((WineQueryOcclusionData *)(This->extendedData))->queryId));
73 checkGLcall("glDeleteQueriesARB");
76 HeapFree(GetProcessHeap(), 0, This->extendedData);
77 HeapFree(GetProcessHeap(), 0, This);
82 /* *******************************************
83 IWineD3DQuery IWineD3DQuery parts follow
84 ******************************************* */
85 static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
86 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
88 *parent= (IUnknown*) parent;
89 IUnknown_AddRef(*parent);
90 TRACE("(%p) : returning %p\n", This, *parent);
94 static HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
95 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
96 IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
97 *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
98 TRACE("(%p) returning %p\n", This, *pDevice);
103 static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
104 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
107 TRACE("(%p) : type %#x, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, This->type, pData, dwSize, dwGetDataFlags);
110 /*you can use this method to poll the resource for the query status*/
111 /*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*/
118 case WINED3DQUERYTYPE_VCACHE:
121 WINED3DDEVINFO_VCACHE *data = (WINED3DDEVINFO_VCACHE *)pData;
122 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VCACHE\n", This);
123 data->Pattern = MAKEFOURCC('C','A','C','H');
124 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
125 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
126 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
130 case WINED3DQUERYTYPE_RESOURCEMANAGER:
132 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
134 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_RESOURCEMANAGER\n", This);
135 for(i = 0; i < WINED3DRTYPECOUNT; i++){
136 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
137 /* isTextureResident could be used to get some of this infomration */
138 data->stats[i].bThrashing = FALSE;
139 data->stats[i].ApproxBytesDownloaded = 1;
140 data->stats[i].NumEvicts = 1;
141 data->stats[i].NumVidCreates = 1;
142 data->stats[i].LastPri = 1;
143 data->stats[i].NumUsed = 1;
144 data->stats[i].NumUsedInVidMem = 1;
145 data->stats[i].WorkingSet = 1;
146 data->stats[i].WorkingSetBytes = 1;
147 data->stats[i].TotalManaged = 1;
148 data->stats[i].TotalBytes = 1;
153 case WINED3DQUERYTYPE_VERTEXSTATS:
155 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
156 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXSTATS\n", This);
157 data->NumRenderedTriangles = 1;
158 data->NumExtraClippingTriangles = 1;
162 case WINED3DQUERYTYPE_EVENT:
165 if(GL_SUPPORT(NV_FENCE)) {
166 *data = GL_EXTCALL(glTestFenceNV(((WineQueryEventData *)This->extendedData)->fenceId));
167 checkGLcall("glTestFenceNV");
169 WARN("(%p): reporting GPU idle\n", This);
174 case WINED3DQUERYTYPE_OCCLUSION:
177 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
180 GLuint queryId = ((WineQueryOcclusionData *)This->extendedData)->queryId;
182 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
183 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)\n");
184 TRACE("(%p) : available %d.\n", This, available);
187 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_ARB, &samples));
188 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)\n");
189 TRACE("(%p) : Returning %d samples.\n", This, samples);
196 FIXME("(%p) : Occlusion queries not supported. Returning 1.\n", This);
202 case WINED3DQUERYTYPE_TIMESTAMP:
204 UINT64* data = pData;
205 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMP\n", This);
206 *data = 1; /*Don't know what this is supposed to be*/
209 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
212 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPDISJOINT\n", This);
213 *data = FALSE; /*Don't know what this is supposed to be*/
216 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
218 UINT64* data = pData;
219 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPFREQ\n", This);
220 *data = 1; /*Don't know what this is supposed to be*/
223 case WINED3DQUERYTYPE_PIPELINETIMINGS:
225 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
226 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIPELINETIMINGS\n", This);
228 data->VertexProcessingTimePercent = 1.0f;
229 data->PixelProcessingTimePercent = 1.0f;
230 data->OtherGPUProcessingTimePercent = 97.0f;
231 data->GPUIdleTimePercent = 1.0f;
234 case WINED3DQUERYTYPE_INTERFACETIMINGS:
236 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
237 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_INTERFACETIMINGS\n", This);
239 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
240 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
241 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
242 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
243 data->WaitingForGPUOtherTimePercent = 96.0f;
247 case WINED3DQUERYTYPE_VERTEXTIMINGS:
249 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
250 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXTIMINGS\n", This);
252 data->MemoryProcessingPercent = 50.0f;
253 data->ComputationProcessingPercent = 50.0f;
257 case WINED3DQUERYTYPE_PIXELTIMINGS:
259 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
260 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIXELTIMINGS\n", This);
262 data->MemoryProcessingPercent = 50.0f;
263 data->ComputationProcessingPercent = 50.0f;
266 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
268 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
269 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_BANDWIDTHTIMINGS\n", This);
271 data->MaxBandwidthUtilized = 1.0f;
272 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
273 data->VertexRateUtilizedPercent = 1.0f;
274 data->TriangleSetupRateUtilizedPercent = 1.0f;
275 data->FillRateUtilizedPercent = 97.0f;
278 case WINED3DQUERYTYPE_CACHEUTILIZATION:
280 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
281 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_CACHEUTILIZATION\n", This);
283 data->TextureCacheHitRate = 1.0f;
284 data->PostTransformVertexCacheHitRate = 1.0f;
290 FIXME("(%p) Unhandled query type %d\n",This , This->type);
294 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
295 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
297 return res; /* S_OK if the query data is available*/
301 static DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
302 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
304 TRACE("(%p) : type %#x\n", This, This->type);
306 case WINED3DQUERYTYPE_VCACHE:
307 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
309 case WINED3DQUERYTYPE_RESOURCEMANAGER:
310 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
312 case WINED3DQUERYTYPE_VERTEXSTATS:
313 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
315 case WINED3DQUERYTYPE_EVENT:
316 dataSize = sizeof(BOOL);
318 case WINED3DQUERYTYPE_OCCLUSION:
319 dataSize = sizeof(DWORD);
321 case WINED3DQUERYTYPE_TIMESTAMP:
322 dataSize = sizeof(UINT64);
324 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
325 dataSize = sizeof(BOOL);
327 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
328 dataSize = sizeof(UINT64);
330 case WINED3DQUERYTYPE_PIPELINETIMINGS:
331 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
333 case WINED3DQUERYTYPE_INTERFACETIMINGS:
334 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
336 case WINED3DQUERYTYPE_VERTEXTIMINGS:
337 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
339 case WINED3DQUERYTYPE_PIXELTIMINGS:
340 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
342 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
343 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
345 case WINED3DQUERYTYPE_CACHEUTILIZATION:
346 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
349 FIXME("(%p) Unhandled query type %d\n",This , This->type);
356 static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
357 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
362 static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
363 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
365 TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
367 switch (This->type) {
368 case WINED3DQUERYTYPE_OCCLUSION:
369 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
370 if (dwIssueFlags & WINED3DISSUE_BEGIN) {
371 GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId));
372 checkGLcall("glBeginQuery()");
374 if (dwIssueFlags & WINED3DISSUE_END) {
375 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
376 checkGLcall("glEndQuery()");
379 FIXME("(%p) : Occlusion queries not supported\n", This);
383 case WINED3DQUERYTYPE_EVENT: {
384 if (GL_SUPPORT(GL_NV_fence)) {
385 if (dwIssueFlags & WINED3DISSUE_END) {
386 GL_EXTCALL(glSetFenceNV(((WineQueryEventData *)This->extendedData)->fenceId, GL_ALL_COMPLETED_NV));
387 } else if(dwIssueFlags & WINED3DISSUE_BEGIN) {
388 /* Started implicitly at device creation */
389 ERR("Event query issued with START flag - what to do?\n");
395 /* The fixme is printed when the app asks for the resulting data */
396 WARN("(%p) : Unhandled query type %#x\n", This, This->type);
400 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
404 /**********************************************************
405 * IWineD3DQuery VTbl follows
406 **********************************************************/
408 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
410 /*** IUnknown methods ***/
411 IWineD3DQueryImpl_QueryInterface,
412 IWineD3DQueryImpl_AddRef,
413 IWineD3DQueryImpl_Release,
414 /*** IWineD3Dquery methods ***/
415 IWineD3DQueryImpl_GetParent,
416 IWineD3DQueryImpl_GetDevice,
417 IWineD3DQueryImpl_GetData,
418 IWineD3DQueryImpl_GetDataSize,
419 IWineD3DQueryImpl_GetType,
420 IWineD3DQueryImpl_Issue