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 data->Pattern = MAKEFOURCC('C','A','C','H');
115 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
116 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
117 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
121 case WINED3DQUERYTYPE_RESOURCEMANAGER:
123 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
125 for(i = 0; i < WINED3DRTYPECOUNT; i++){
126 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
127 /* isTextureResident could be used to get some of this infomration */
128 data->stats[i].bThrashing = FALSE;
129 data->stats[i].ApproxBytesDownloaded = 1;
130 data->stats[i].NumEvicts = 1;
131 data->stats[i].NumVidCreates = 1;
132 data->stats[i].LastPri = 1;
133 data->stats[i].NumUsed = 1;
134 data->stats[i].NumUsedInVidMem = 1;
135 data->stats[i].WorkingSet = 1;
136 data->stats[i].WorkingSetBytes = 1;
137 data->stats[i].TotalManaged = 1;
138 data->stats[i].TotalBytes = 1;
143 case WINED3DQUERYTYPE_VERTEXSTATS:
145 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
146 data->NumRenderedTriangles = 1;
147 data->NumExtraClippingTriangles = 1;
151 case WINED3DQUERYTYPE_EVENT:
154 *data = TRUE; /*Don't know what this is supposed to be*/
157 case WINED3DQUERYTYPE_OCCLUSION:
160 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
163 GLuint queryId = ((WineQueryOcclusionData *)This->extendedData)->queryId;
165 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
166 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)\n");
167 TRACE("(%p) : available %d.\n", This, available);
169 if (available || dwGetDataFlags & WINED3DGETDATA_FLUSH) {
170 GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_ARB, &samples));
171 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)\n");
172 TRACE("(%p) : Returning %d samples.\n", This, samples);
179 FIXME("(%p) : Occlusion queries not supported. Returning 1.\n", This);
185 case WINED3DQUERYTYPE_TIMESTAMP:
187 UINT64* data = pData;
188 *data = 1; /*Don't know what this is supposed to be*/
191 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
194 *data = FALSE; /*Don't know what this is supposed to be*/
197 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
199 UINT64* data = pData;
200 *data = 1; /*Don't know what this is supposed to be*/
203 case WINED3DQUERYTYPE_PIPELINETIMINGS:
205 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
207 data->VertexProcessingTimePercent = 1.0f;
208 data->PixelProcessingTimePercent = 1.0f;
209 data->OtherGPUProcessingTimePercent = 97.0f;
210 data->GPUIdleTimePercent = 1.0f;
213 case WINED3DQUERYTYPE_INTERFACETIMINGS:
215 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
217 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
218 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
219 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
220 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
221 data->WaitingForGPUOtherTimePercent = 96.0f;
225 case WINED3DQUERYTYPE_VERTEXTIMINGS:
227 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
228 data->MemoryProcessingPercent = 50.0f;
229 data->ComputationProcessingPercent = 50.0f;
233 case WINED3DQUERYTYPE_PIXELTIMINGS:
235 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
236 data->MemoryProcessingPercent = 50.0f;
237 data->ComputationProcessingPercent = 50.0f;
240 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
242 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
243 data->MaxBandwidthUtilized = 1.0f;
244 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
245 data->VertexRateUtilizedPercent = 1.0f;
246 data->TriangleSetupRateUtilizedPercent = 1.0f;
247 data->FillRateUtilizedPercent = 97.0f;
250 case WINED3DQUERYTYPE_CACHEUTILIZATION:
252 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
254 data->TextureCacheHitRate = 1.0f;
255 data->PostTransformVertexCacheHitRate = 1.0f;
261 FIXME("(%p) Unhandled query type %d\n",This , This->type);
265 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
266 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
268 FIXME("(%p) : type %#x, Partial stub\n", This, This->type);
269 return res; /* S_OK if the query data is available*/
273 static DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
274 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
276 TRACE("(%p) : type %#x\n", This, This->type);
278 case WINED3DQUERYTYPE_VCACHE:
279 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
281 case WINED3DQUERYTYPE_RESOURCEMANAGER:
282 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
284 case WINED3DQUERYTYPE_VERTEXSTATS:
285 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
287 case WINED3DQUERYTYPE_EVENT:
288 dataSize = sizeof(BOOL);
290 case WINED3DQUERYTYPE_OCCLUSION:
291 dataSize = sizeof(DWORD);
293 case WINED3DQUERYTYPE_TIMESTAMP:
294 dataSize = sizeof(UINT64);
296 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
297 dataSize = sizeof(BOOL);
299 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
300 dataSize = sizeof(UINT64);
302 case WINED3DQUERYTYPE_PIPELINETIMINGS:
303 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
305 case WINED3DQUERYTYPE_INTERFACETIMINGS:
306 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
308 case WINED3DQUERYTYPE_VERTEXTIMINGS:
309 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
311 case WINED3DQUERYTYPE_PIXELTIMINGS:
312 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
314 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
315 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
317 case WINED3DQUERYTYPE_CACHEUTILIZATION:
318 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
321 FIXME("(%p) Unhandled query type %d\n",This , This->type);
328 static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
329 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
334 static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
335 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
337 TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
339 switch (This->type) {
340 case WINED3DQUERYTYPE_OCCLUSION:
341 if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
342 if (dwIssueFlags & D3DISSUE_BEGIN) {
343 GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId));
344 checkGLcall("glBeginQuery()");
346 if (dwIssueFlags & D3DISSUE_END) {
347 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
348 checkGLcall("glEndQuery()");
351 FIXME("(%p) : Occlusion queries not supported\n", This);
356 FIXME("(%p) : Unhandled query type %#x\n", This, This->type);
360 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
364 /**********************************************************
365 * IWineD3DQuery VTbl follows
366 **********************************************************/
368 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
370 /*** IUnknown methods ***/
371 IWineD3DQueryImpl_QueryInterface,
372 IWineD3DQueryImpl_AddRef,
373 IWineD3DQueryImpl_Release,
374 /*** IWineD3Dquery methods ***/
375 IWineD3DQueryImpl_GetParent,
376 IWineD3DQueryImpl_GetDevice,
377 IWineD3DQueryImpl_GetData,
378 IWineD3DQueryImpl_GetDataSize,
379 IWineD3DQueryImpl_GetType,
380 IWineD3DQueryImpl_Issue