reg/tests: Test import with non-standard registry file headers.
[wine.git] / dlls / wined3d / query.c
blob371f7d32c4ece251c1d063bf2fcffa4b1b0dff58
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 static void wined3d_query_init(struct wined3d_query *query, struct wined3d_device *device,
29 enum wined3d_query_type type, const void *data, DWORD data_size,
30 const struct wined3d_query_ops *query_ops, void *parent)
32 query->ref = 1;
33 query->parent = parent;
34 query->device = device;
35 query->state = QUERY_CREATED;
36 query->type = type;
37 query->data = data;
38 query->data_size = data_size;
39 query->query_ops = query_ops;
42 static struct wined3d_event_query *wined3d_event_query_from_query(struct wined3d_query *query)
44 return CONTAINING_RECORD(query, struct wined3d_event_query, query);
47 static struct wined3d_occlusion_query *wined3d_occlusion_query_from_query(struct wined3d_query *query)
49 return CONTAINING_RECORD(query, struct wined3d_occlusion_query, query);
52 static struct wined3d_timestamp_query *wined3d_timestamp_query_from_query(struct wined3d_query *query)
54 return CONTAINING_RECORD(query, struct wined3d_timestamp_query, query);
57 BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info)
59 return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
62 void wined3d_event_query_destroy(struct wined3d_event_query *query)
64 if (query->context) context_free_event_query(query);
65 HeapFree(GetProcessHeap(), 0, query);
68 static enum wined3d_event_query_result wined3d_event_query_test(const struct wined3d_event_query *query,
69 const struct wined3d_device *device, DWORD flags)
71 struct wined3d_context *context;
72 const struct wined3d_gl_info *gl_info;
73 enum wined3d_event_query_result ret;
74 BOOL fence_result;
76 TRACE("query %p, device %p, flags %#x.\n", query, device, flags);
78 if (!query->context)
80 TRACE("Query not started\n");
81 return WINED3D_EVENT_QUERY_NOT_STARTED;
84 if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
86 WARN("Event query tested from wrong thread\n");
87 return WINED3D_EVENT_QUERY_WRONG_THREAD;
90 context = context_acquire(device, query->context->current_rt.texture,
91 query->context->current_rt.sub_resource_idx);
92 gl_info = context->gl_info;
94 if (gl_info->supported[ARB_SYNC])
96 GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync,
97 (flags & WINED3DGETDATA_FLUSH) ? GL_SYNC_FLUSH_COMMANDS_BIT : 0, 0));
98 checkGLcall("glClientWaitSync");
100 switch (gl_ret)
102 case GL_ALREADY_SIGNALED:
103 case GL_CONDITION_SATISFIED:
104 ret = WINED3D_EVENT_QUERY_OK;
105 break;
107 case GL_TIMEOUT_EXPIRED:
108 ret = WINED3D_EVENT_QUERY_WAITING;
109 break;
111 case GL_WAIT_FAILED:
112 default:
113 ERR("glClientWaitSync returned %#x.\n", gl_ret);
114 ret = WINED3D_EVENT_QUERY_ERROR;
117 else if (gl_info->supported[APPLE_FENCE])
119 fence_result = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
120 checkGLcall("glTestFenceAPPLE");
121 if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
122 else ret = WINED3D_EVENT_QUERY_WAITING;
124 else if (gl_info->supported[NV_FENCE])
126 fence_result = GL_EXTCALL(glTestFenceNV(query->object.id));
127 checkGLcall("glTestFenceNV");
128 if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
129 else ret = WINED3D_EVENT_QUERY_WAITING;
131 else
133 ERR("Event query created despite lack of GL support\n");
134 ret = WINED3D_EVENT_QUERY_ERROR;
137 context_release(context);
138 return ret;
141 enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query,
142 const struct wined3d_device *device)
144 struct wined3d_context *context;
145 const struct wined3d_gl_info *gl_info;
146 enum wined3d_event_query_result ret;
148 TRACE("query %p, device %p.\n", query, device);
150 if (!query->context)
152 TRACE("Query not started\n");
153 return WINED3D_EVENT_QUERY_NOT_STARTED;
155 gl_info = query->context->gl_info;
157 if (query->context->tid != GetCurrentThreadId() && !gl_info->supported[ARB_SYNC])
159 /* A glFinish does not reliably wait for draws in other contexts. The caller has
160 * to find its own way to cope with the thread switch
162 WARN("Event query finished from wrong thread\n");
163 return WINED3D_EVENT_QUERY_WRONG_THREAD;
166 context = context_acquire(device, query->context->current_rt.texture,
167 query->context->current_rt.sub_resource_idx);
169 if (gl_info->supported[ARB_SYNC])
171 /* Apple seems to be into arbitrary limits, and timeouts larger than
172 * 0xfffffffffffffbff immediately return GL_TIMEOUT_EXPIRED. We don't
173 * really care and can live with waiting a few μs less. (OS X 10.7.4). */
174 GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, GL_SYNC_FLUSH_COMMANDS_BIT, ~(GLuint64)0xffff));
175 checkGLcall("glClientWaitSync");
177 switch (gl_ret)
179 case GL_ALREADY_SIGNALED:
180 case GL_CONDITION_SATISFIED:
181 ret = WINED3D_EVENT_QUERY_OK;
182 break;
184 /* We don't expect a timeout for a ~584 year wait */
185 default:
186 ERR("glClientWaitSync returned %#x.\n", gl_ret);
187 ret = WINED3D_EVENT_QUERY_ERROR;
190 else if (context->gl_info->supported[APPLE_FENCE])
192 GL_EXTCALL(glFinishFenceAPPLE(query->object.id));
193 checkGLcall("glFinishFenceAPPLE");
194 ret = WINED3D_EVENT_QUERY_OK;
196 else if (context->gl_info->supported[NV_FENCE])
198 GL_EXTCALL(glFinishFenceNV(query->object.id));
199 checkGLcall("glFinishFenceNV");
200 ret = WINED3D_EVENT_QUERY_OK;
202 else
204 ERR("Event query created without GL support\n");
205 ret = WINED3D_EVENT_QUERY_ERROR;
208 context_release(context);
209 return ret;
212 void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device)
214 const struct wined3d_gl_info *gl_info;
215 struct wined3d_context *context;
217 if (query->context)
219 if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
221 context_free_event_query(query);
222 context = context_acquire(device, NULL, 0);
223 context_alloc_event_query(context, query);
225 else
227 context = context_acquire(device, query->context->current_rt.texture,
228 query->context->current_rt.sub_resource_idx);
231 else
233 context = context_acquire(device, NULL, 0);
234 context_alloc_event_query(context, query);
237 gl_info = context->gl_info;
239 if (gl_info->supported[ARB_SYNC])
241 if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
242 checkGLcall("glDeleteSync");
243 query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
244 checkGLcall("glFenceSync");
246 else if (gl_info->supported[APPLE_FENCE])
248 GL_EXTCALL(glSetFenceAPPLE(query->object.id));
249 checkGLcall("glSetFenceAPPLE");
251 else if (gl_info->supported[NV_FENCE])
253 GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
254 checkGLcall("glSetFenceNV");
257 context_release(context);
260 ULONG CDECL wined3d_query_incref(struct wined3d_query *query)
262 ULONG refcount = InterlockedIncrement(&query->ref);
264 TRACE("%p increasing refcount to %u.\n", query, refcount);
266 return refcount;
269 static void wined3d_query_destroy_object(void *object)
271 struct wined3d_query *query = object;
273 /* Queries are specific to the GL context that created them. Not
274 * deleting the query will obviously leak it, but that's still better
275 * than potentially deleting a different query with the same id in this
276 * context, and (still) leaking the actual query. */
277 if (query->type == WINED3D_QUERY_TYPE_EVENT)
279 wined3d_event_query_destroy(wined3d_event_query_from_query(query));
281 else if (query->type == WINED3D_QUERY_TYPE_OCCLUSION)
283 struct wined3d_occlusion_query *oq = wined3d_occlusion_query_from_query(query);
285 if (oq->context)
286 context_free_occlusion_query(oq);
287 HeapFree(GetProcessHeap(), 0, oq);
289 else if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP)
291 struct wined3d_timestamp_query *tq = wined3d_timestamp_query_from_query(query);
293 if (tq->context)
294 context_free_timestamp_query(tq);
295 HeapFree(GetProcessHeap(), 0, tq);
297 else if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
298 || query->type == WINED3D_QUERY_TYPE_TIMESTAMP_FREQ)
300 HeapFree(GetProcessHeap(), 0, query);
302 else
304 ERR("Query %p has invalid type %#x.\n", query, query->type);
308 ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
310 ULONG refcount = InterlockedDecrement(&query->ref);
312 TRACE("%p decreasing refcount to %u.\n", query, refcount);
314 if (!refcount)
315 wined3d_cs_destroy_object(query->device->cs, wined3d_query_destroy_object, query);
317 return refcount;
320 HRESULT CDECL wined3d_query_get_data(struct wined3d_query *query,
321 void *data, UINT data_size, DWORD flags)
323 TRACE("query %p, data %p, data_size %u, flags %#x.\n",
324 query, data, data_size, flags);
326 if (flags)
327 WARN("Ignoring flags %#x.\n", flags);
329 if (query->state == QUERY_BUILDING)
331 WARN("Query is building, returning S_FALSE.\n");
332 return S_FALSE;
335 if (query->state == QUERY_CREATED)
337 WARN("Query wasn't started yet.\n");
338 return WINED3DERR_INVALIDCALL;
341 if (!query->query_ops->query_poll(query, flags))
342 return S_FALSE;
344 if (data)
345 memcpy(data, query->data, min(data_size, query->data_size));
347 return S_OK;
350 UINT CDECL wined3d_query_get_data_size(const struct wined3d_query *query)
352 TRACE("query %p.\n", query);
354 return query->data_size;
357 HRESULT CDECL wined3d_query_issue(struct wined3d_query *query, DWORD flags)
359 TRACE("query %p, flags %#x.\n", query, flags);
361 wined3d_cs_emit_query_issue(query->device->cs, query, flags);
363 if (flags & WINED3DISSUE_BEGIN)
364 query->state = QUERY_BUILDING;
365 else
366 query->state = QUERY_SIGNALLED;
368 return WINED3D_OK;
371 static BOOL wined3d_occlusion_query_ops_poll(struct wined3d_query *query, DWORD flags)
373 struct wined3d_occlusion_query *oq = wined3d_occlusion_query_from_query(query);
374 struct wined3d_device *device = query->device;
375 const struct wined3d_gl_info *gl_info;
376 struct wined3d_context *context;
377 GLuint available;
379 TRACE("query %p, flags %#x.\n", query, flags);
381 if (oq->context->tid != GetCurrentThreadId())
383 FIXME("%p Wrong thread, returning 1.\n", query);
384 oq->samples = 1;
385 return TRUE;
388 context = context_acquire(device, oq->context->current_rt.texture,
389 oq->context->current_rt.sub_resource_idx);
390 gl_info = context->gl_info;
392 GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT_AVAILABLE, &available));
393 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
394 TRACE("available %#x.\n", available);
396 if (available)
398 if (gl_info->supported[ARB_TIMER_QUERY])
400 GLuint64 result;
401 GL_EXTCALL(glGetQueryObjectui64v(oq->id, GL_QUERY_RESULT, &result));
402 checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
403 oq->samples = result;
405 else
407 GLuint result;
408 GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT, &result));
409 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT)");
410 oq->samples = result;
412 TRACE("Returning 0x%s samples.\n", wine_dbgstr_longlong(oq->samples));
415 context_release(context);
417 return available;
420 static BOOL wined3d_event_query_ops_poll(struct wined3d_query *query, DWORD flags)
422 struct wined3d_event_query *event_query = wined3d_event_query_from_query(query);
423 enum wined3d_event_query_result ret;
425 TRACE("query %p, flags %#x.\n", query, flags);
427 ret = wined3d_event_query_test(event_query, query->device, flags);
428 switch (ret)
430 case WINED3D_EVENT_QUERY_OK:
431 case WINED3D_EVENT_QUERY_NOT_STARTED:
432 return event_query->signalled = TRUE;
434 case WINED3D_EVENT_QUERY_WAITING:
435 return event_query->signalled = FALSE;
437 case WINED3D_EVENT_QUERY_WRONG_THREAD:
438 FIXME("(%p) Wrong thread, reporting GPU idle.\n", query);
439 return event_query->signalled = TRUE;
441 case WINED3D_EVENT_QUERY_ERROR:
442 ERR("The GL event query failed.\n");
443 return event_query->signalled = TRUE;
445 default:
446 ERR("Unexpected wined3d_event_query_test result %#x.\n", ret);
447 return event_query->signalled = TRUE;
451 void * CDECL wined3d_query_get_parent(const struct wined3d_query *query)
453 TRACE("query %p.\n", query);
455 return query->parent;
458 enum wined3d_query_type CDECL wined3d_query_get_type(const struct wined3d_query *query)
460 TRACE("query %p.\n", query);
462 return query->type;
465 static void wined3d_event_query_ops_issue(struct wined3d_query *query, DWORD flags)
467 TRACE("query %p, flags %#x.\n", query, flags);
469 if (flags & WINED3DISSUE_END)
471 struct wined3d_event_query *event_query = wined3d_event_query_from_query(query);
473 wined3d_event_query_issue(event_query, query->device);
475 else if (flags & WINED3DISSUE_BEGIN)
477 /* Started implicitly at query creation. */
478 ERR("Event query issued with START flag - what to do?\n");
482 static void wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DWORD flags)
484 struct wined3d_occlusion_query *oq = wined3d_occlusion_query_from_query(query);
485 struct wined3d_device *device = query->device;
486 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
487 struct wined3d_context *context;
489 TRACE("query %p, flags %#x.\n", query, flags);
491 /* This is allowed according to MSDN and our tests. Reset the query and
492 * restart. */
493 if (flags & WINED3DISSUE_BEGIN)
495 if (query->state == QUERY_BUILDING)
497 if (oq->context->tid != GetCurrentThreadId())
499 FIXME("Wrong thread, can't restart query.\n");
501 context_free_occlusion_query(oq);
502 context = context_acquire(query->device, NULL, 0);
503 context_alloc_occlusion_query(context, oq);
505 else
507 context = context_acquire(device, oq->context->current_rt.texture,
508 oq->context->current_rt.sub_resource_idx);
510 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
511 checkGLcall("glEndQuery()");
514 else
516 if (oq->context)
517 context_free_occlusion_query(oq);
518 context = context_acquire(query->device, NULL, 0);
519 context_alloc_occlusion_query(context, oq);
522 GL_EXTCALL(glBeginQuery(GL_SAMPLES_PASSED, oq->id));
523 checkGLcall("glBeginQuery()");
525 context_release(context);
527 if (flags & WINED3DISSUE_END)
529 /* MSDN says END on a non-building occlusion query returns an error,
530 * but our tests show that it returns OK. But OpenGL doesn't like it,
531 * so avoid generating an error. */
532 if (query->state == QUERY_BUILDING)
534 if (oq->context->tid != GetCurrentThreadId())
536 FIXME("Wrong thread, can't end query.\n");
538 else
540 context = context_acquire(device, oq->context->current_rt.texture,
541 oq->context->current_rt.sub_resource_idx);
543 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
544 checkGLcall("glEndQuery()");
546 context_release(context);
552 static BOOL wined3d_timestamp_query_ops_poll(struct wined3d_query *query, DWORD flags)
554 struct wined3d_timestamp_query *tq = wined3d_timestamp_query_from_query(query);
555 struct wined3d_device *device = query->device;
556 const struct wined3d_gl_info *gl_info;
557 struct wined3d_context *context;
558 GLuint64 timestamp;
559 GLuint available;
561 TRACE("query %p, flags %#x.\n", query, flags);
563 if (tq->context->tid != GetCurrentThreadId())
565 FIXME("%p Wrong thread, returning 1.\n", query);
566 tq->timestamp = 1;
567 return TRUE;
570 context = context_acquire(device, tq->context->current_rt.texture,
571 tq->context->current_rt.sub_resource_idx);
572 gl_info = context->gl_info;
574 GL_EXTCALL(glGetQueryObjectuiv(tq->id, GL_QUERY_RESULT_AVAILABLE, &available));
575 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
576 TRACE("available %#x.\n", available);
578 if (available)
580 GL_EXTCALL(glGetQueryObjectui64v(tq->id, GL_QUERY_RESULT, &timestamp));
581 checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
582 TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp));
583 tq->timestamp = timestamp;
586 context_release(context);
588 return available;
591 static void wined3d_timestamp_query_ops_issue(struct wined3d_query *query, DWORD flags)
593 struct wined3d_timestamp_query *tq = wined3d_timestamp_query_from_query(query);
594 const struct wined3d_gl_info *gl_info;
595 struct wined3d_context *context;
597 TRACE("query %p, flags %#x.\n", query, flags);
599 if (flags & WINED3DISSUE_BEGIN)
601 WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
603 if (flags & WINED3DISSUE_END)
605 if (tq->context)
606 context_free_timestamp_query(tq);
607 context = context_acquire(query->device, NULL, 0);
608 gl_info = context->gl_info;
609 context_alloc_timestamp_query(context, tq);
610 GL_EXTCALL(glQueryCounter(tq->id, GL_TIMESTAMP));
611 checkGLcall("glQueryCounter()");
612 context_release(context);
616 static BOOL wined3d_timestamp_disjoint_query_ops_poll(struct wined3d_query *query, DWORD flags)
618 TRACE("query %p, flags %#x.\n", query, flags);
620 return TRUE;
623 static void wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query *query, DWORD flags)
625 TRACE("query %p, flags %#x.\n", query, flags);
628 static const struct wined3d_query_ops event_query_ops =
630 wined3d_event_query_ops_poll,
631 wined3d_event_query_ops_issue,
634 static HRESULT wined3d_event_query_create(struct wined3d_device *device,
635 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
637 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
638 struct wined3d_event_query *object;
640 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
642 if (!wined3d_event_query_supported(gl_info))
644 WARN("Event queries not supported.\n");
645 return WINED3DERR_NOTAVAILABLE;
648 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
649 return E_OUTOFMEMORY;
651 wined3d_query_init(&object->query, device, type, &object->signalled,
652 sizeof(object->signalled), &event_query_ops, parent);
654 TRACE("Created query %p.\n", object);
655 *query = &object->query;
657 return WINED3D_OK;
660 static const struct wined3d_query_ops occlusion_query_ops =
662 wined3d_occlusion_query_ops_poll,
663 wined3d_occlusion_query_ops_issue,
666 static HRESULT wined3d_occlusion_query_create(struct wined3d_device *device,
667 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
669 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
670 struct wined3d_occlusion_query *object;
672 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
674 if (!gl_info->supported[ARB_OCCLUSION_QUERY])
676 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
677 return WINED3DERR_NOTAVAILABLE;
680 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
681 return E_OUTOFMEMORY;
683 wined3d_query_init(&object->query, device, type, &object->samples,
684 sizeof(object->samples), &occlusion_query_ops, parent);
686 TRACE("Created query %p.\n", object);
687 *query = &object->query;
689 return WINED3D_OK;
692 static const struct wined3d_query_ops timestamp_query_ops =
694 wined3d_timestamp_query_ops_poll,
695 wined3d_timestamp_query_ops_issue,
698 static HRESULT wined3d_timestamp_query_create(struct wined3d_device *device,
699 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
701 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
702 struct wined3d_timestamp_query *object;
704 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
706 if (!gl_info->supported[ARB_TIMER_QUERY])
708 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
709 return WINED3DERR_NOTAVAILABLE;
712 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
713 return E_OUTOFMEMORY;
715 wined3d_query_init(&object->query, device, type, &object->timestamp,
716 sizeof(object->timestamp), &timestamp_query_ops, parent);
718 TRACE("Created query %p.\n", object);
719 *query = &object->query;
721 return WINED3D_OK;
724 static const struct wined3d_query_ops timestamp_disjoint_query_ops =
726 wined3d_timestamp_disjoint_query_ops_poll,
727 wined3d_timestamp_disjoint_query_ops_issue,
730 static HRESULT wined3d_timestamp_disjoint_query_create(struct wined3d_device *device,
731 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
733 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
734 struct wined3d_query *object;
736 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
738 if (!gl_info->supported[ARB_TIMER_QUERY])
740 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
741 return WINED3DERR_NOTAVAILABLE;
744 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
745 return E_OUTOFMEMORY;
747 if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
749 static const struct wined3d_query_data_timestamp_disjoint disjoint_data = {1000 * 1000 * 1000, FALSE};
751 wined3d_query_init(object, device, type, &disjoint_data,
752 sizeof(disjoint_data), &timestamp_disjoint_query_ops, parent);
754 else
756 static const UINT64 freq = 1000 * 1000 * 1000;
758 wined3d_query_init(object, device, type, &freq,
759 sizeof(freq), &timestamp_disjoint_query_ops, parent);
762 TRACE("Created query %p.\n", object);
763 *query = object;
765 return WINED3D_OK;
768 HRESULT CDECL wined3d_query_create(struct wined3d_device *device,
769 enum wined3d_query_type type, void *parent, struct wined3d_query **query)
771 TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
773 switch (type)
775 case WINED3D_QUERY_TYPE_EVENT:
776 return wined3d_event_query_create(device, type, parent, query);
778 case WINED3D_QUERY_TYPE_OCCLUSION:
779 return wined3d_occlusion_query_create(device, type, parent, query);
781 case WINED3D_QUERY_TYPE_TIMESTAMP:
782 return wined3d_timestamp_query_create(device, type, parent, query);
784 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT:
785 case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ:
786 return wined3d_timestamp_disjoint_query_create(device, type, parent, query);
788 default:
789 FIXME("Unhandled query type %#x.\n", type);
790 return WINED3DERR_NOTAVAILABLE;