wined3d: Get rid of redundant NULL checks for event query "extendedData".
[wine.git] / dlls / wined3d / query.c
blobc09fe8649d35367942d83cc467a665f3cd7cfc6e
1 /*
2 * Copyright 2005 Oliver Stieber
3 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
4 * Copyright 2009-2010 Henri Verbeet for CodeWeavers.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
28 BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info)
30 return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
33 void wined3d_event_query_destroy(struct wined3d_event_query *query)
35 if (query->context) context_free_event_query(query);
36 HeapFree(GetProcessHeap(), 0, query);
39 static enum wined3d_event_query_result wined3d_event_query_test(const struct wined3d_event_query *query,
40 const struct wined3d_device *device)
42 struct wined3d_context *context;
43 const struct wined3d_gl_info *gl_info;
44 enum wined3d_event_query_result ret;
45 BOOL fence_result;
47 TRACE("(%p) : device %p\n", query, device);
49 if (!query->context)
51 TRACE("Query not started\n");
52 return WINED3D_EVENT_QUERY_NOT_STARTED;
55 if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
57 WARN("Event query tested from wrong thread\n");
58 return WINED3D_EVENT_QUERY_WRONG_THREAD;
61 context = context_acquire(device, context_get_rt_surface(query->context));
62 gl_info = context->gl_info;
64 if (gl_info->supported[ARB_SYNC])
66 GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, 0));
67 checkGLcall("glClientWaitSync");
69 switch (gl_ret)
71 case GL_ALREADY_SIGNALED:
72 case GL_CONDITION_SATISFIED:
73 ret = WINED3D_EVENT_QUERY_OK;
74 break;
76 case GL_TIMEOUT_EXPIRED:
77 ret = WINED3D_EVENT_QUERY_WAITING;
78 break;
80 case GL_WAIT_FAILED:
81 default:
82 ERR("glClientWaitSync returned %#x.\n", gl_ret);
83 ret = WINED3D_EVENT_QUERY_ERROR;
86 else if (gl_info->supported[APPLE_FENCE])
88 fence_result = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
89 checkGLcall("glTestFenceAPPLE");
90 if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
91 else ret = WINED3D_EVENT_QUERY_WAITING;
93 else if (gl_info->supported[NV_FENCE])
95 fence_result = GL_EXTCALL(glTestFenceNV(query->object.id));
96 checkGLcall("glTestFenceNV");
97 if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
98 else ret = WINED3D_EVENT_QUERY_WAITING;
100 else
102 ERR("Event query created despite lack of GL support\n");
103 ret = WINED3D_EVENT_QUERY_ERROR;
106 context_release(context);
107 return ret;
110 enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query,
111 const struct wined3d_device *device)
113 struct wined3d_context *context;
114 const struct wined3d_gl_info *gl_info;
115 enum wined3d_event_query_result ret;
117 TRACE("query %p, device %p.\n", query, device);
119 if (!query->context)
121 TRACE("Query not started\n");
122 return WINED3D_EVENT_QUERY_NOT_STARTED;
124 gl_info = query->context->gl_info;
126 if (query->context->tid != GetCurrentThreadId() && !gl_info->supported[ARB_SYNC])
128 /* A glFinish does not reliably wait for draws in other contexts. The caller has
129 * to find its own way to cope with the thread switch
131 WARN("Event query finished from wrong thread\n");
132 return WINED3D_EVENT_QUERY_WRONG_THREAD;
135 context = context_acquire(device, context_get_rt_surface(query->context));
137 if (gl_info->supported[ARB_SYNC])
139 /* Apple seems to be into arbitrary limits, and timeouts larger than
140 * 0xfffffffffffffbff immediately return GL_TIMEOUT_EXPIRED. We don't
141 * really care and can live with waiting a few μs less. (OS X 10.7.4). */
142 GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, GL_SYNC_FLUSH_COMMANDS_BIT, ~(GLuint64)0xffff));
143 checkGLcall("glClientWaitSync");
145 switch (gl_ret)
147 case GL_ALREADY_SIGNALED:
148 case GL_CONDITION_SATISFIED:
149 ret = WINED3D_EVENT_QUERY_OK;
150 break;
152 /* We don't expect a timeout for a ~584 year wait */
153 default:
154 ERR("glClientWaitSync returned %#x.\n", gl_ret);
155 ret = WINED3D_EVENT_QUERY_ERROR;
158 else if (context->gl_info->supported[APPLE_FENCE])
160 GL_EXTCALL(glFinishFenceAPPLE(query->object.id));
161 checkGLcall("glFinishFenceAPPLE");
162 ret = WINED3D_EVENT_QUERY_OK;
164 else if (context->gl_info->supported[NV_FENCE])
166 GL_EXTCALL(glFinishFenceNV(query->object.id));
167 checkGLcall("glFinishFenceNV");
168 ret = WINED3D_EVENT_QUERY_OK;
170 else
172 ERR("Event query created without GL support\n");
173 ret = WINED3D_EVENT_QUERY_ERROR;
176 context_release(context);
177 return ret;
180 void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device)
182 const struct wined3d_gl_info *gl_info;
183 struct wined3d_context *context;
185 if (query->context)
187 if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
189 context_free_event_query(query);
190 context = context_acquire(device, NULL);
191 context_alloc_event_query(context, query);
193 else
195 context = context_acquire(device, context_get_rt_surface(query->context));
198 else
200 context = context_acquire(device, NULL);
201 context_alloc_event_query(context, query);
204 gl_info = context->gl_info;
206 if (gl_info->supported[ARB_SYNC])
208 if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
209 checkGLcall("glDeleteSync");
210 query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
211 checkGLcall("glFenceSync");
213 else if (gl_info->supported[APPLE_FENCE])
215 GL_EXTCALL(glSetFenceAPPLE(query->object.id));
216 checkGLcall("glSetFenceAPPLE");
218 else if (gl_info->supported[NV_FENCE])
220 GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
221 checkGLcall("glSetFenceNV");
224 context_release(context);
227 ULONG CDECL wined3d_query_incref(struct wined3d_query *query)
229 ULONG refcount = InterlockedIncrement(&query->ref);
231 TRACE("%p increasing refcount to %u.\n", query, refcount);
233 return refcount;
236 static void wined3d_query_destroy_object(void *object)
238 struct wined3d_query *query = object;
240 /* Queries are specific to the GL context that created them. Not
241 * deleting the query will obviously leak it, but that's still better
242 * than potentially deleting a different query with the same id in this
243 * context, and (still) leaking the actual query. */
244 if (query->type == WINED3D_QUERY_TYPE_EVENT)
246 struct wined3d_event_query *event_query = query->extendedData;
247 wined3d_event_query_destroy(event_query);
249 else if (query->type == WINED3D_QUERY_TYPE_OCCLUSION)
251 struct wined3d_occlusion_query *oq = query->extendedData;
253 if (oq->context) context_free_occlusion_query(oq);
254 HeapFree(GetProcessHeap(), 0, query->extendedData);
256 else if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP)
258 struct wined3d_timestamp_query *tq = query->extendedData;
260 if (tq->context)
261 context_free_timestamp_query(tq);
262 HeapFree(GetProcessHeap(), 0, query->extendedData);
265 HeapFree(GetProcessHeap(), 0, query);
268 ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
270 ULONG refcount = InterlockedDecrement(&query->ref);
272 TRACE("%p decreasing refcount to %u.\n", query, refcount);
274 if (!refcount)
275 wined3d_cs_emit_destroy_object(query->device->cs, wined3d_query_destroy_object, query);
277 return refcount;
280 HRESULT CDECL wined3d_query_get_data(struct wined3d_query *query,
281 void *data, UINT data_size, DWORD flags)
283 TRACE("query %p, data %p, data_size %u, flags %#x.\n",
284 query, data, data_size, flags);
286 return query->query_ops->query_get_data(query, data, data_size, flags);
289 UINT CDECL wined3d_query_get_data_size(const struct wined3d_query *query)
291 TRACE("query %p.\n", query);
293 return query->data_size;
296 HRESULT CDECL wined3d_query_issue(struct wined3d_query *query, DWORD flags)
298 TRACE("query %p, flags %#x.\n", query, flags);
300 return query->query_ops->query_issue(query, flags);
303 static void fill_query_data(void *out, unsigned int out_size, const void *result, unsigned int result_size)
305 memcpy(out, result, min(out_size, result_size));
308 static HRESULT wined3d_occlusion_query_ops_get_data(struct wined3d_query *query,
309 void *data, DWORD size, DWORD flags)
311 struct wined3d_occlusion_query *oq = query->extendedData;
312 struct wined3d_device *device = query->device;
313 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
314 struct wined3d_context *context;
315 GLuint available;
316 GLuint samples;
317 HRESULT res;
319 TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
321 if (!oq->context)
322 query->state = QUERY_CREATED;
324 if (query->state == QUERY_CREATED)
326 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
327 TRACE("Query wasn't yet started, returning S_OK\n");
328 samples = 0;
329 fill_query_data(data, size, &samples, sizeof(samples));
330 return S_OK;
333 if (query->state == QUERY_BUILDING)
335 /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
336 TRACE("Query is building, returning S_FALSE\n");
337 return S_FALSE;
340 if (!gl_info->supported[ARB_OCCLUSION_QUERY])
342 WARN("%p Occlusion queries not supported. Returning 1.\n", query);
343 samples = 1;
344 fill_query_data(data, size, &samples, sizeof(samples));
345 return S_OK;
348 if (oq->context->tid != GetCurrentThreadId())
350 FIXME("%p Wrong thread, returning 1.\n", query);
351 samples = 1;
352 fill_query_data(data, size, &samples, sizeof(samples));
353 return S_OK;
356 context = context_acquire(device, context_get_rt_surface(oq->context));
358 GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT_AVAILABLE, &available));
359 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
360 TRACE("available %#x.\n", available);
362 if (available)
364 if (size)
366 GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT, &samples));
367 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT)");
368 TRACE("Returning %d samples.\n", samples);
369 fill_query_data(data, size, &samples, sizeof(samples));
371 res = S_OK;
373 else
375 res = S_FALSE;
378 context_release(context);
380 return res;
383 static HRESULT wined3d_event_query_ops_get_data(struct wined3d_query *query,
384 void *data, DWORD size, DWORD flags)
386 struct wined3d_event_query *event_query = query->extendedData;
387 BOOL signaled;
388 enum wined3d_event_query_result ret;
390 TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
392 if (!data || !size)
393 return S_OK;
395 ret = wined3d_event_query_test(event_query, query->device);
396 switch(ret)
398 case WINED3D_EVENT_QUERY_OK:
399 case WINED3D_EVENT_QUERY_NOT_STARTED:
400 signaled = TRUE;
401 fill_query_data(data, size, &signaled, sizeof(signaled));
402 break;
404 case WINED3D_EVENT_QUERY_WAITING:
405 signaled = FALSE;
406 fill_query_data(data, size, &signaled, sizeof(signaled));
407 break;
409 case WINED3D_EVENT_QUERY_WRONG_THREAD:
410 FIXME("(%p) Wrong thread, reporting GPU idle.\n", query);
411 signaled = TRUE;
412 fill_query_data(data, size, &signaled, sizeof(signaled));
413 break;
415 case WINED3D_EVENT_QUERY_ERROR:
416 ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
417 return WINED3DERR_INVALIDCALL;
420 return S_OK;
423 void * CDECL wined3d_query_get_parent(const struct wined3d_query *query)
425 TRACE("query %p.\n", query);
427 return query->parent;
430 enum wined3d_query_type CDECL wined3d_query_get_type(const struct wined3d_query *query)
432 TRACE("query %p.\n", query);
434 return query->type;
437 static HRESULT wined3d_event_query_ops_issue(struct wined3d_query *query, DWORD flags)
439 TRACE("query %p, flags %#x.\n", query, flags);
441 TRACE("(%p) : flags %#x, type D3DQUERY_EVENT\n", query, flags);
442 if (flags & WINED3DISSUE_END)
444 struct wined3d_event_query *event_query = query->extendedData;
446 wined3d_event_query_issue(event_query, query->device);
448 else if (flags & WINED3DISSUE_BEGIN)
450 /* Started implicitly at device creation */
451 ERR("Event query issued with START flag - what to do?\n");
454 if (flags & WINED3DISSUE_BEGIN)
455 query->state = QUERY_BUILDING;
456 else
457 query->state = QUERY_SIGNALLED;
459 return WINED3D_OK;
462 static HRESULT wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DWORD flags)
464 struct wined3d_device *device = query->device;
465 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
467 TRACE("query %p, flags %#x.\n", query, flags);
469 if (gl_info->supported[ARB_OCCLUSION_QUERY])
471 struct wined3d_occlusion_query *oq = query->extendedData;
472 struct wined3d_context *context;
474 /* This is allowed according to msdn and our tests. Reset the query and restart */
475 if (flags & WINED3DISSUE_BEGIN)
477 if (query->state == QUERY_BUILDING)
479 if (oq->context->tid != GetCurrentThreadId())
481 FIXME("Wrong thread, can't restart query.\n");
483 context_free_occlusion_query(oq);
484 context = context_acquire(query->device, NULL);
485 context_alloc_occlusion_query(context, oq);
487 else
489 context = context_acquire(device, context_get_rt_surface(oq->context));
491 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
492 checkGLcall("glEndQuery()");
495 else
497 if (oq->context) context_free_occlusion_query(oq);
498 context = context_acquire(query->device, NULL);
499 context_alloc_occlusion_query(context, oq);
502 GL_EXTCALL(glBeginQuery(GL_SAMPLES_PASSED, oq->id));
503 checkGLcall("glBeginQuery()");
505 context_release(context);
507 if (flags & WINED3DISSUE_END)
509 /* Msdn says _END on a non-building occlusion query returns an error, but
510 * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
511 * generating an error
513 if (query->state == QUERY_BUILDING)
515 if (oq->context->tid != GetCurrentThreadId())
517 FIXME("Wrong thread, can't end query.\n");
519 else
521 context = context_acquire(device, context_get_rt_surface(oq->context));
523 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
524 checkGLcall("glEndQuery()");
526 context_release(context);
531 else
533 FIXME("%p Occlusion queries not supported.\n", query);
536 if (flags & WINED3DISSUE_BEGIN)
537 query->state = QUERY_BUILDING;
538 else
539 query->state = QUERY_SIGNALLED;
541 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
544 static HRESULT wined3d_timestamp_query_ops_get_data(struct wined3d_query *query,
545 void *data, DWORD size, DWORD flags)
547 struct wined3d_timestamp_query *tq = query->extendedData;
548 struct wined3d_device *device = query->device;
549 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
550 struct wined3d_context *context;
551 GLuint available;
552 GLuint64 timestamp;
553 HRESULT res;
555 TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
557 if (!tq->context)
558 query->state = QUERY_CREATED;
560 if (query->state == QUERY_CREATED)
562 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves. */
563 TRACE("Query wasn't yet started, returning S_OK.\n");
564 timestamp = 0;
565 fill_query_data(data, size, &timestamp, sizeof(timestamp));
566 return S_OK;
569 if (tq->context->tid != GetCurrentThreadId())
571 FIXME("%p Wrong thread, returning 1.\n", query);
572 timestamp = 1;
573 fill_query_data(data, size, &timestamp, sizeof(timestamp));
574 return S_OK;
577 context = context_acquire(device, context_get_rt_surface(tq->context));
579 GL_EXTCALL(glGetQueryObjectuiv(tq->id, GL_QUERY_RESULT_AVAILABLE, &available));
580 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
581 TRACE("available %#x.\n", available);
583 if (available)
585 if (size)
587 GL_EXTCALL(glGetQueryObjectui64v(tq->id, GL_QUERY_RESULT, &timestamp));
588 checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
589 TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp));
590 fill_query_data(data, size, &timestamp, sizeof(timestamp));
592 res = S_OK;
594 else
596 res = S_FALSE;
599 context_release(context);
601 return res;
604 static HRESULT wined3d_timestamp_query_ops_issue(struct wined3d_query *query, DWORD flags)
606 struct wined3d_device *device = query->device;
607 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
609 TRACE("query %p, flags %#x.\n", query, flags);
611 if (gl_info->supported[ARB_TIMER_QUERY])
613 struct wined3d_timestamp_query *tq = query->extendedData;
614 struct wined3d_context *context;
616 if (flags & WINED3DISSUE_BEGIN)
618 WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
620 if (flags & WINED3DISSUE_END)
622 if (tq->context)
623 context_free_timestamp_query(tq);
624 context = context_acquire(query->device, NULL);
625 context_alloc_timestamp_query(context, tq);
626 GL_EXTCALL(glQueryCounter(tq->id, GL_TIMESTAMP));
627 checkGLcall("glQueryCounter()");
628 context_release(context);
631 else
633 ERR("Timestamp queries not supported.\n");
636 if (flags & WINED3DISSUE_END)
637 query->state = QUERY_SIGNALLED;
639 return WINED3D_OK;
642 static HRESULT wined3d_timestamp_disjoint_query_ops_get_data(struct wined3d_query *query,
643 void *data, DWORD size, DWORD flags)
645 TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
647 if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
649 static const struct wined3d_query_data_timestamp_disjoint disjoint_data = {1000 * 1000 * 1000, FALSE};
651 if (query->state == QUERY_BUILDING)
653 TRACE("Query is building, returning S_FALSE.\n");
654 return S_FALSE;
657 fill_query_data(data, size, &disjoint_data, sizeof(disjoint_data));
659 else
661 static const UINT64 freq = 1000 * 1000 * 1000;
663 fill_query_data(data, size, &freq, sizeof(freq));
665 return S_OK;
668 static HRESULT wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query *query, DWORD flags)
670 TRACE("query %p, flags %#x.\n", query, flags);
672 if (flags & WINED3DISSUE_BEGIN)
673 query->state = QUERY_BUILDING;
674 if (flags & WINED3DISSUE_END)
675 query->state = QUERY_SIGNALLED;
677 return WINED3D_OK;
680 static const struct wined3d_query_ops event_query_ops =
682 wined3d_event_query_ops_get_data,
683 wined3d_event_query_ops_issue,
686 static const struct wined3d_query_ops occlusion_query_ops =
688 wined3d_occlusion_query_ops_get_data,
689 wined3d_occlusion_query_ops_issue,
692 static const struct wined3d_query_ops timestamp_query_ops =
694 wined3d_timestamp_query_ops_get_data,
695 wined3d_timestamp_query_ops_issue,
698 static const struct wined3d_query_ops timestamp_disjoint_query_ops =
700 wined3d_timestamp_disjoint_query_ops_get_data,
701 wined3d_timestamp_disjoint_query_ops_issue,
704 static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device,
705 enum wined3d_query_type type, void *parent)
707 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
709 query->parent = parent;
711 switch (type)
713 case WINED3D_QUERY_TYPE_OCCLUSION:
714 TRACE("Occlusion query.\n");
715 if (!gl_info->supported[ARB_OCCLUSION_QUERY])
717 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
718 return WINED3DERR_NOTAVAILABLE;
720 query->query_ops = &occlusion_query_ops;
721 query->data_size = sizeof(DWORD);
722 query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
723 if (!query->extendedData)
725 ERR("Failed to allocate occlusion query extended data.\n");
726 return E_OUTOFMEMORY;
728 ((struct wined3d_occlusion_query *)query->extendedData)->context = NULL;
729 break;
731 case WINED3D_QUERY_TYPE_EVENT:
732 TRACE("Event query.\n");
733 if (!wined3d_event_query_supported(gl_info))
735 /* Half-Life 2 needs this query. It does not render the main
736 * menu correctly otherwise. Pretend to support it, faking
737 * this query does not do much harm except potentially
738 * lowering performance. */
739 FIXME("Event query: Unimplemented, but pretending to be supported.\n");
741 query->query_ops = &event_query_ops;
742 query->data_size = sizeof(BOOL);
743 query->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_event_query));
744 if (!query->extendedData)
746 ERR("Failed to allocate event query memory.\n");
747 return E_OUTOFMEMORY;
749 break;
751 case WINED3D_QUERY_TYPE_TIMESTAMP:
752 TRACE("Timestamp query.\n");
753 if (!gl_info->supported[ARB_TIMER_QUERY])
755 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
756 return WINED3DERR_NOTAVAILABLE;
758 query->query_ops = &timestamp_query_ops;
759 query->data_size = sizeof(UINT64);
760 query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_timestamp_query));
761 if (!query->extendedData)
763 ERR("Failed to allocate timestamp query extended data.\n");
764 return E_OUTOFMEMORY;
766 ((struct wined3d_timestamp_query *)query->extendedData)->context = NULL;
767 break;
769 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT:
770 case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ:
771 TRACE("TIMESTAMP_DISJOINT query.\n");
772 if (!gl_info->supported[ARB_TIMER_QUERY])
774 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
775 return WINED3DERR_NOTAVAILABLE;
777 query->query_ops = &timestamp_disjoint_query_ops;
778 query->data_size = type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
779 ? sizeof(struct wined3d_query_data_timestamp_disjoint) : sizeof(UINT64);
780 query->extendedData = NULL;
781 break;
783 case WINED3D_QUERY_TYPE_VCACHE:
784 case WINED3D_QUERY_TYPE_RESOURCE_MANAGER:
785 case WINED3D_QUERY_TYPE_VERTEX_STATS:
786 case WINED3D_QUERY_TYPE_PIPELINE_TIMINGS:
787 case WINED3D_QUERY_TYPE_INTERFACE_TIMINGS:
788 case WINED3D_QUERY_TYPE_VERTEX_TIMINGS:
789 case WINED3D_QUERY_TYPE_PIXEL_TIMINGS:
790 case WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS:
791 case WINED3D_QUERY_TYPE_CACHE_UTILIZATION:
792 default:
793 FIXME("Unhandled query type %#x.\n", type);
794 return WINED3DERR_NOTAVAILABLE;
797 query->type = type;
798 query->state = QUERY_CREATED;
799 query->device = device;
800 query->ref = 1;
802 return WINED3D_OK;
805 HRESULT CDECL wined3d_query_create(struct wined3d_device *device,
806 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
808 struct wined3d_query *object;
809 HRESULT hr;
811 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
813 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
814 if (!object)
815 return E_OUTOFMEMORY;
817 if (FAILED(hr = query_init(object, device, type, parent)))
819 WARN("Failed to initialize query, hr %#x.\n", hr);
820 HeapFree(GetProcessHeap(), 0, object);
821 return hr;
824 TRACE("Created query %p.\n", object);
825 *query = object;
827 return WINED3D_OK;