2 * IWineD3DQuery implementation
4 * Copyright 2005 Oliver Stieber
5 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
6 * Copyright 2009 Henri Verbeet for CodeWeavers.
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"
29 * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
30 * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34 #define GLINFO_LOCATION This->device->adapter->gl_info
36 /* *******************************************
37 IWineD3DQuery IUnknown parts follow
38 ******************************************* */
39 static HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
41 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
42 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
43 if (IsEqualGUID(riid, &IID_IUnknown)
44 || IsEqualGUID(riid, &IID_IWineD3DBase)
45 || IsEqualGUID(riid, &IID_IWineD3DQuery)) {
46 IUnknown_AddRef(iface);
54 static ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
55 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
56 TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
57 return InterlockedIncrement(&This->ref);
60 static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
61 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
63 TRACE("(%p) : Releasing from %d\n", This, This->ref);
64 ref = InterlockedDecrement(&This->ref);
66 /* Queries are specific to the GL context that created them. Not
67 * deleting the query will obviously leak it, but that's still better
68 * than potentially deleting a different query with the same id in this
69 * context, and (still) leaking the actual query. */
70 if (This->type == WINED3DQUERYTYPE_EVENT)
72 struct wined3d_event_query *query = This->extendedData;
74 if (query->context) context_free_event_query(query);
76 else if (This->type == WINED3DQUERYTYPE_OCCLUSION)
78 struct wined3d_occlusion_query *query = This->extendedData;
80 if (query->context) context_free_occlusion_query(query);
83 HeapFree(GetProcessHeap(), 0, This->extendedData);
84 HeapFree(GetProcessHeap(), 0, This);
89 /* *******************************************
90 IWineD3DQuery IWineD3DQuery parts follow
91 ******************************************* */
92 static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown **parent)
94 TRACE("iface %p, parent %p.\n", iface, parent);
96 *parent = (IUnknown *)parent;
97 IUnknown_AddRef(*parent);
99 TRACE("Returning %p.\n", *parent);
104 static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
105 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
108 TRACE("(%p) : type %#x, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, This->type, pData, dwSize, dwGetDataFlags);
112 case WINED3DQUERYTYPE_VCACHE:
115 WINED3DDEVINFO_VCACHE *data = pData;
116 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VCACHE\n", This);
117 if(pData == NULL || dwSize == 0) break;
118 data->Pattern = WINEMAKEFOURCC('C','A','C','H');
119 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
120 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
121 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
125 case WINED3DQUERYTYPE_RESOURCEMANAGER:
127 WINED3DDEVINFO_RESOURCEMANAGER *data = pData;
129 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_RESOURCEMANAGER\n", This);
130 if(pData == NULL || dwSize == 0) break;
131 for(i = 0; i < WINED3DRTYPECOUNT; i++){
132 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
133 /* isTextureResident could be used to get some of this information */
134 data->stats[i].bThrashing = FALSE;
135 data->stats[i].ApproxBytesDownloaded = 1;
136 data->stats[i].NumEvicts = 1;
137 data->stats[i].NumVidCreates = 1;
138 data->stats[i].LastPri = 1;
139 data->stats[i].NumUsed = 1;
140 data->stats[i].NumUsedInVidMem = 1;
141 data->stats[i].WorkingSet = 1;
142 data->stats[i].WorkingSetBytes = 1;
143 data->stats[i].TotalManaged = 1;
144 data->stats[i].TotalBytes = 1;
149 case WINED3DQUERYTYPE_VERTEXSTATS:
151 WINED3DDEVINFO_VERTEXSTATS *data = pData;
152 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXSTATS\n", This);
153 if(pData == NULL || dwSize == 0) break;
154 data->NumRenderedTriangles = 1;
155 data->NumExtraClippingTriangles = 1;
159 case WINED3DQUERYTYPE_TIMESTAMP:
161 UINT64* data = pData;
162 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMP\n", This);
163 if(pData == NULL || dwSize == 0) break;
164 *data = 1; /*Don't know what this is supposed to be*/
167 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
170 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPDISJOINT\n", This);
171 if(pData == NULL || dwSize == 0) break;
172 *data = FALSE; /*Don't know what this is supposed to be*/
175 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
177 UINT64* data = pData;
178 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPFREQ\n", This);
179 if(pData == NULL || dwSize == 0) break;
180 *data = 1; /*Don't know what this is supposed to be*/
183 case WINED3DQUERYTYPE_PIPELINETIMINGS:
185 WINED3DDEVINFO_PIPELINETIMINGS *data = pData;
186 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIPELINETIMINGS\n", This);
187 if(pData == NULL || dwSize == 0) break;
189 data->VertexProcessingTimePercent = 1.0f;
190 data->PixelProcessingTimePercent = 1.0f;
191 data->OtherGPUProcessingTimePercent = 97.0f;
192 data->GPUIdleTimePercent = 1.0f;
195 case WINED3DQUERYTYPE_INTERFACETIMINGS:
197 WINED3DDEVINFO_INTERFACETIMINGS *data = pData;
198 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_INTERFACETIMINGS\n", This);
200 if(pData == NULL || dwSize == 0) break;
201 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
202 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
203 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
204 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
205 data->WaitingForGPUOtherTimePercent = 96.0f;
209 case WINED3DQUERYTYPE_VERTEXTIMINGS:
211 WINED3DDEVINFO_STAGETIMINGS *data = pData;
212 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXTIMINGS\n", This);
214 if(pData == NULL || dwSize == 0) break;
215 data->MemoryProcessingPercent = 50.0f;
216 data->ComputationProcessingPercent = 50.0f;
220 case WINED3DQUERYTYPE_PIXELTIMINGS:
222 WINED3DDEVINFO_STAGETIMINGS *data = pData;
223 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIXELTIMINGS\n", This);
225 if(pData == NULL || dwSize == 0) break;
226 data->MemoryProcessingPercent = 50.0f;
227 data->ComputationProcessingPercent = 50.0f;
230 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
232 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = pData;
233 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_BANDWIDTHTIMINGS\n", This);
235 if(pData == NULL || dwSize == 0) break;
236 data->MaxBandwidthUtilized = 1.0f;
237 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
238 data->VertexRateUtilizedPercent = 1.0f;
239 data->TriangleSetupRateUtilizedPercent = 1.0f;
240 data->FillRateUtilizedPercent = 97.0f;
243 case WINED3DQUERYTYPE_CACHEUTILIZATION:
245 WINED3DDEVINFO_CACHEUTILIZATION *data = pData;
246 FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_CACHEUTILIZATION\n", This);
248 if(pData == NULL || dwSize == 0) break;
249 data->TextureCacheHitRate = 1.0f;
250 data->PostTransformVertexCacheHitRate = 1.0f;
256 FIXME("(%p) Unhandled query type %d\n",This , This->type);
260 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
261 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
263 return res; /* S_OK if the query data is available*/
266 static HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
267 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
268 struct wined3d_occlusion_query *query = This->extendedData;
269 IWineD3DDeviceImpl *device = This->device;
270 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
271 struct wined3d_context *context;
277 TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
279 if (!query->context) This->state = QUERY_CREATED;
281 if (This->state == QUERY_CREATED)
283 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
284 TRACE("Query wasn't yet started, returning S_OK\n");
289 if (This->state == QUERY_BUILDING)
291 /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
292 TRACE("Query is building, returning S_FALSE\n");
296 if (!gl_info->supported[ARB_OCCLUSION_QUERY])
298 WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
303 if (query->context->tid != GetCurrentThreadId())
305 FIXME("%p Wrong thread, returning 1.\n", This);
310 context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
314 GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
315 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
316 TRACE("(%p) : available %d.\n", This, available);
322 GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_ARB, &samples));
323 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
324 TRACE("(%p) : Returning %d samples.\n", This, samples);
336 context_release(context);
341 static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
342 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
343 struct wined3d_event_query *query = This->extendedData;
344 struct wined3d_context *context;
347 TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
349 if (!pData || !dwSize) return S_OK;
353 TRACE("Query not started, returning TRUE.\n");
359 if (query->context->tid != GetCurrentThreadId())
361 /* See comment in IWineD3DQuery::Issue, event query codeblock */
362 FIXME("Wrong thread, reporting GPU idle.\n");
368 context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
372 if (context->gl_info->supported[APPLE_FENCE])
374 *data = GL_EXTCALL(glTestFenceAPPLE(query->id));
375 checkGLcall("glTestFenceAPPLE");
377 else if (context->gl_info->supported[NV_FENCE])
379 *data = GL_EXTCALL(glTestFenceNV(query->id));
380 checkGLcall("glTestFenceNV");
384 WARN("(%p): reporting GPU idle\n", This);
390 context_release(context);
395 static DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
396 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
398 TRACE("(%p) : type %#x\n", This, This->type);
400 case WINED3DQUERYTYPE_VCACHE:
401 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
403 case WINED3DQUERYTYPE_RESOURCEMANAGER:
404 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
406 case WINED3DQUERYTYPE_VERTEXSTATS:
407 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
409 case WINED3DQUERYTYPE_EVENT:
410 dataSize = sizeof(BOOL);
412 case WINED3DQUERYTYPE_TIMESTAMP:
413 dataSize = sizeof(UINT64);
415 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
416 dataSize = sizeof(BOOL);
418 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
419 dataSize = sizeof(UINT64);
421 case WINED3DQUERYTYPE_PIPELINETIMINGS:
422 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
424 case WINED3DQUERYTYPE_INTERFACETIMINGS:
425 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
427 case WINED3DQUERYTYPE_VERTEXTIMINGS:
428 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
430 case WINED3DQUERYTYPE_PIXELTIMINGS:
431 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
433 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
434 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
436 case WINED3DQUERYTYPE_CACHEUTILIZATION:
437 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
440 FIXME("(%p) Unhandled query type %d\n",This , This->type);
446 static DWORD WINAPI IWineD3DEventQueryImpl_GetDataSize(IWineD3DQuery* iface){
447 TRACE("(%p) : type D3DQUERY_EVENT\n", iface);
452 static DWORD WINAPI IWineD3DOcclusionQueryImpl_GetDataSize(IWineD3DQuery* iface){
453 TRACE("(%p) : type D3DQUERY_OCCLUSION\n", iface);
455 return sizeof(DWORD);
458 static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
459 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
464 static HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
465 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
467 TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
468 if (dwIssueFlags & WINED3DISSUE_END)
470 struct wined3d_event_query *query = This->extendedData;
471 struct wined3d_context *context;
475 if (query->context->tid != GetCurrentThreadId())
477 context_free_event_query(query);
478 context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
479 context_alloc_event_query(context, query);
483 context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
488 context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
489 context_alloc_event_query(context, query);
494 if (context->gl_info->supported[APPLE_FENCE])
496 GL_EXTCALL(glSetFenceAPPLE(query->id));
497 checkGLcall("glSetFenceAPPLE");
499 else if (context->gl_info->supported[NV_FENCE])
501 GL_EXTCALL(glSetFenceNV(query->id, GL_ALL_COMPLETED_NV));
502 checkGLcall("glSetFenceNV");
507 context_release(context);
509 else if(dwIssueFlags & WINED3DISSUE_BEGIN)
511 /* Started implicitly at device creation */
512 ERR("Event query issued with START flag - what to do?\n");
515 if(dwIssueFlags & WINED3DISSUE_BEGIN) {
516 This->state = QUERY_BUILDING;
518 This->state = QUERY_SIGNALLED;
524 static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
525 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
526 IWineD3DDeviceImpl *device = This->device;
527 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
529 if (gl_info->supported[ARB_OCCLUSION_QUERY])
531 struct wined3d_occlusion_query *query = This->extendedData;
532 struct wined3d_context *context;
534 /* This is allowed according to msdn and our tests. Reset the query and restart */
535 if (dwIssueFlags & WINED3DISSUE_BEGIN)
537 if (This->state == QUERY_BUILDING)
539 if (query->context->tid != GetCurrentThreadId())
541 FIXME("Wrong thread, can't restart query.\n");
543 context_free_occlusion_query(query);
544 context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
545 context_alloc_occlusion_query(context, query);
549 context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
552 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
553 checkGLcall("glEndQuery()");
559 if (query->context) context_free_occlusion_query(query);
560 context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
561 context_alloc_occlusion_query(context, query);
565 GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query->id));
566 checkGLcall("glBeginQuery()");
569 context_release(context);
571 if (dwIssueFlags & WINED3DISSUE_END) {
572 /* Msdn says _END on a non-building occlusion query returns an error, but
573 * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
574 * generating an error
576 if (This->state == QUERY_BUILDING)
578 if (query->context->tid != GetCurrentThreadId())
580 FIXME("Wrong thread, can't end query.\n");
584 context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
587 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
588 checkGLcall("glEndQuery()");
591 context_release(context);
596 FIXME("(%p) : Occlusion queries not supported\n", This);
599 if(dwIssueFlags & WINED3DISSUE_BEGIN) {
600 This->state = QUERY_BUILDING;
602 This->state = QUERY_SIGNALLED;
604 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
607 static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
608 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
610 TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
612 /* The fixme is printed when the app asks for the resulting data */
613 WARN("(%p) : Unhandled query type %#x\n", This, This->type);
615 if(dwIssueFlags & WINED3DISSUE_BEGIN) {
616 This->state = QUERY_BUILDING;
618 This->state = QUERY_SIGNALLED;
621 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
625 /**********************************************************
626 * IWineD3DQuery VTbl follows
627 **********************************************************/
629 static const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
631 /*** IUnknown methods ***/
632 IWineD3DQueryImpl_QueryInterface,
633 IWineD3DQueryImpl_AddRef,
634 IWineD3DQueryImpl_Release,
635 /*** IWineD3Dquery methods ***/
636 IWineD3DQueryImpl_GetParent,
637 IWineD3DQueryImpl_GetData,
638 IWineD3DQueryImpl_GetDataSize,
639 IWineD3DQueryImpl_GetType,
640 IWineD3DQueryImpl_Issue
643 static const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
645 /*** IUnknown methods ***/
646 IWineD3DQueryImpl_QueryInterface,
647 IWineD3DQueryImpl_AddRef,
648 IWineD3DQueryImpl_Release,
649 /*** IWineD3Dquery methods ***/
650 IWineD3DQueryImpl_GetParent,
651 IWineD3DEventQueryImpl_GetData,
652 IWineD3DEventQueryImpl_GetDataSize,
653 IWineD3DQueryImpl_GetType,
654 IWineD3DEventQueryImpl_Issue
657 static const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
659 /*** IUnknown methods ***/
660 IWineD3DQueryImpl_QueryInterface,
661 IWineD3DQueryImpl_AddRef,
662 IWineD3DQueryImpl_Release,
663 /*** IWineD3Dquery methods ***/
664 IWineD3DQueryImpl_GetParent,
665 IWineD3DOcclusionQueryImpl_GetData,
666 IWineD3DOcclusionQueryImpl_GetDataSize,
667 IWineD3DQueryImpl_GetType,
668 IWineD3DOcclusionQueryImpl_Issue
671 HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
672 WINED3DQUERYTYPE type, IUnknown *parent)
674 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
678 case WINED3DQUERYTYPE_OCCLUSION:
679 TRACE("Occlusion query.\n");
680 if (!gl_info->supported[ARB_OCCLUSION_QUERY])
682 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY/NV_OCCLUSION_QUERY\n");
683 return WINED3DERR_NOTAVAILABLE;
685 query->lpVtbl = &IWineD3DOcclusionQuery_Vtbl;
686 query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
687 if (!query->extendedData)
689 ERR("Failed to allocate occlusion query extended data.\n");
690 return E_OUTOFMEMORY;
692 ((struct wined3d_occlusion_query *)query->extendedData)->context = NULL;
695 case WINED3DQUERYTYPE_EVENT:
696 TRACE("Event query.\n");
697 if (!gl_info->supported[NV_FENCE] && !gl_info->supported[APPLE_FENCE])
699 /* Half-Life 2 needs this query. It does not render the main
700 * menu correctly otherwise. Pretend to support it, faking
701 * this query does not do much harm except potentially
702 * lowering performance. */
703 FIXME("Event query: Unimplemented, but pretending to be supported.\n");
705 query->lpVtbl = &IWineD3DEventQuery_Vtbl;
706 query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_event_query));
707 if (!query->extendedData)
709 ERR("Failed to allocate event query extended data.\n");
710 return E_OUTOFMEMORY;
712 ((struct wined3d_event_query *)query->extendedData)->context = NULL;
715 case WINED3DQUERYTYPE_VCACHE:
716 case WINED3DQUERYTYPE_RESOURCEMANAGER:
717 case WINED3DQUERYTYPE_VERTEXSTATS:
718 case WINED3DQUERYTYPE_TIMESTAMP:
719 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
720 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
721 case WINED3DQUERYTYPE_PIPELINETIMINGS:
722 case WINED3DQUERYTYPE_INTERFACETIMINGS:
723 case WINED3DQUERYTYPE_VERTEXTIMINGS:
724 case WINED3DQUERYTYPE_PIXELTIMINGS:
725 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
726 case WINED3DQUERYTYPE_CACHEUTILIZATION:
728 /* Use the base query vtable until we have a special one for each query. */
729 query->lpVtbl = &IWineD3DQuery_Vtbl;
730 FIXME("Unhandled query type %#x.\n", type);
731 return WINED3DERR_NOTAVAILABLE;
735 query->state = QUERY_CREATED;
736 query->device = device;
737 query->parent = parent;