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
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
;
47 TRACE("(%p) : device %p\n", query
, device
);
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");
71 case GL_ALREADY_SIGNALED
:
72 case GL_CONDITION_SATISFIED
:
73 ret
= WINED3D_EVENT_QUERY_OK
;
76 case GL_TIMEOUT_EXPIRED
:
77 ret
= WINED3D_EVENT_QUERY_WAITING
;
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
;
102 ERR("Event query created despite lack of GL support\n");
103 ret
= WINED3D_EVENT_QUERY_ERROR
;
106 context_release(context
);
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
);
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");
147 case GL_ALREADY_SIGNALED
:
148 case GL_CONDITION_SATISFIED
:
149 ret
= WINED3D_EVENT_QUERY_OK
;
152 /* We don't expect a timeout for a ~584 year wait */
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
;
172 ERR("Event query created without GL support\n");
173 ret
= WINED3D_EVENT_QUERY_ERROR
;
176 context_release(context
);
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
;
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
);
195 context
= context_acquire(device
, context_get_rt_surface(query
->context
));
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
);
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
;
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
);
275 wined3d_cs_emit_destroy_object(query
->device
->cs
, wined3d_query_destroy_object
, query
);
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
;
319 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
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");
329 fill_query_data(data
, size
, &samples
, sizeof(samples
));
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");
340 if (oq
->context
->tid
!= GetCurrentThreadId())
342 FIXME("%p Wrong thread, returning 1.\n", query
);
344 fill_query_data(data
, size
, &samples
, sizeof(samples
));
348 context
= context_acquire(device
, context_get_rt_surface(oq
->context
));
350 GL_EXTCALL(glGetQueryObjectuiv(oq
->id
, GL_QUERY_RESULT_AVAILABLE
, &available
));
351 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
352 TRACE("available %#x.\n", available
);
358 GL_EXTCALL(glGetQueryObjectuiv(oq
->id
, GL_QUERY_RESULT
, &samples
));
359 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT)");
360 TRACE("Returning %d samples.\n", samples
);
361 fill_query_data(data
, size
, &samples
, sizeof(samples
));
370 context_release(context
);
375 static HRESULT
wined3d_event_query_ops_get_data(struct wined3d_query
*query
,
376 void *data
, DWORD size
, DWORD flags
)
378 struct wined3d_event_query
*event_query
= query
->extendedData
;
380 enum wined3d_event_query_result ret
;
382 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
387 ret
= wined3d_event_query_test(event_query
, query
->device
);
390 case WINED3D_EVENT_QUERY_OK
:
391 case WINED3D_EVENT_QUERY_NOT_STARTED
:
393 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
396 case WINED3D_EVENT_QUERY_WAITING
:
398 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
401 case WINED3D_EVENT_QUERY_WRONG_THREAD
:
402 FIXME("(%p) Wrong thread, reporting GPU idle.\n", query
);
404 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
407 case WINED3D_EVENT_QUERY_ERROR
:
408 ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
409 return WINED3DERR_INVALIDCALL
;
415 void * CDECL
wined3d_query_get_parent(const struct wined3d_query
*query
)
417 TRACE("query %p.\n", query
);
419 return query
->parent
;
422 enum wined3d_query_type CDECL
wined3d_query_get_type(const struct wined3d_query
*query
)
424 TRACE("query %p.\n", query
);
429 static HRESULT
wined3d_event_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
431 TRACE("query %p, flags %#x.\n", query
, flags
);
433 TRACE("(%p) : flags %#x, type D3DQUERY_EVENT\n", query
, flags
);
434 if (flags
& WINED3DISSUE_END
)
436 struct wined3d_event_query
*event_query
= query
->extendedData
;
438 wined3d_event_query_issue(event_query
, query
->device
);
440 else if (flags
& WINED3DISSUE_BEGIN
)
442 /* Started implicitly at device creation */
443 ERR("Event query issued with START flag - what to do?\n");
446 if (flags
& WINED3DISSUE_BEGIN
)
447 query
->state
= QUERY_BUILDING
;
449 query
->state
= QUERY_SIGNALLED
;
454 static HRESULT
wined3d_occlusion_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
456 struct wined3d_occlusion_query
*oq
= query
->extendedData
;
457 struct wined3d_device
*device
= query
->device
;
458 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
459 struct wined3d_context
*context
;
461 TRACE("query %p, flags %#x.\n", query
, flags
);
463 /* This is allowed according to MSDN and our tests. Reset the query and
465 if (flags
& WINED3DISSUE_BEGIN
)
467 if (query
->state
== QUERY_BUILDING
)
469 if (oq
->context
->tid
!= GetCurrentThreadId())
471 FIXME("Wrong thread, can't restart query.\n");
473 context_free_occlusion_query(oq
);
474 context
= context_acquire(query
->device
, NULL
);
475 context_alloc_occlusion_query(context
, oq
);
479 context
= context_acquire(device
, context_get_rt_surface(oq
->context
));
481 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED
));
482 checkGLcall("glEndQuery()");
488 context_free_occlusion_query(oq
);
489 context
= context_acquire(query
->device
, NULL
);
490 context_alloc_occlusion_query(context
, oq
);
493 GL_EXTCALL(glBeginQuery(GL_SAMPLES_PASSED
, oq
->id
));
494 checkGLcall("glBeginQuery()");
496 context_release(context
);
498 if (flags
& WINED3DISSUE_END
)
500 /* MSDN says END on a non-building occlusion query returns an error,
501 * but our tests show that it returns OK. But OpenGL doesn't like it,
502 * so avoid generating an error. */
503 if (query
->state
== QUERY_BUILDING
)
505 if (oq
->context
->tid
!= GetCurrentThreadId())
507 FIXME("Wrong thread, can't end query.\n");
511 context
= context_acquire(device
, context_get_rt_surface(oq
->context
));
513 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED
));
514 checkGLcall("glEndQuery()");
516 context_release(context
);
521 if (flags
& WINED3DISSUE_BEGIN
)
522 query
->state
= QUERY_BUILDING
;
524 query
->state
= QUERY_SIGNALLED
;
526 return WINED3D_OK
; /* can be WINED3DERR_INVALIDCALL. */
529 static HRESULT
wined3d_timestamp_query_ops_get_data(struct wined3d_query
*query
,
530 void *data
, DWORD size
, DWORD flags
)
532 struct wined3d_timestamp_query
*tq
= query
->extendedData
;
533 struct wined3d_device
*device
= query
->device
;
534 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
535 struct wined3d_context
*context
;
540 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
543 query
->state
= QUERY_CREATED
;
545 if (query
->state
== QUERY_CREATED
)
547 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves. */
548 TRACE("Query wasn't yet started, returning S_OK.\n");
550 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
554 if (tq
->context
->tid
!= GetCurrentThreadId())
556 FIXME("%p Wrong thread, returning 1.\n", query
);
558 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
562 context
= context_acquire(device
, context_get_rt_surface(tq
->context
));
564 GL_EXTCALL(glGetQueryObjectuiv(tq
->id
, GL_QUERY_RESULT_AVAILABLE
, &available
));
565 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
566 TRACE("available %#x.\n", available
);
572 GL_EXTCALL(glGetQueryObjectui64v(tq
->id
, GL_QUERY_RESULT
, ×tamp
));
573 checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
574 TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp
));
575 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
584 context_release(context
);
589 static HRESULT
wined3d_timestamp_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
591 struct wined3d_device
*device
= query
->device
;
592 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
594 TRACE("query %p, flags %#x.\n", query
, flags
);
596 if (gl_info
->supported
[ARB_TIMER_QUERY
])
598 struct wined3d_timestamp_query
*tq
= query
->extendedData
;
599 struct wined3d_context
*context
;
601 if (flags
& WINED3DISSUE_BEGIN
)
603 WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
605 if (flags
& WINED3DISSUE_END
)
608 context_free_timestamp_query(tq
);
609 context
= context_acquire(query
->device
, NULL
);
610 context_alloc_timestamp_query(context
, tq
);
611 GL_EXTCALL(glQueryCounter(tq
->id
, GL_TIMESTAMP
));
612 checkGLcall("glQueryCounter()");
613 context_release(context
);
618 ERR("Timestamp queries not supported.\n");
621 if (flags
& WINED3DISSUE_END
)
622 query
->state
= QUERY_SIGNALLED
;
627 static HRESULT
wined3d_timestamp_disjoint_query_ops_get_data(struct wined3d_query
*query
,
628 void *data
, DWORD size
, DWORD flags
)
630 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
632 if (query
->type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
)
634 static const struct wined3d_query_data_timestamp_disjoint disjoint_data
= {1000 * 1000 * 1000, FALSE
};
636 if (query
->state
== QUERY_BUILDING
)
638 TRACE("Query is building, returning S_FALSE.\n");
642 fill_query_data(data
, size
, &disjoint_data
, sizeof(disjoint_data
));
646 static const UINT64 freq
= 1000 * 1000 * 1000;
648 fill_query_data(data
, size
, &freq
, sizeof(freq
));
653 static HRESULT
wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
655 TRACE("query %p, flags %#x.\n", query
, flags
);
657 if (flags
& WINED3DISSUE_BEGIN
)
658 query
->state
= QUERY_BUILDING
;
659 if (flags
& WINED3DISSUE_END
)
660 query
->state
= QUERY_SIGNALLED
;
665 static const struct wined3d_query_ops event_query_ops
=
667 wined3d_event_query_ops_get_data
,
668 wined3d_event_query_ops_issue
,
671 static const struct wined3d_query_ops occlusion_query_ops
=
673 wined3d_occlusion_query_ops_get_data
,
674 wined3d_occlusion_query_ops_issue
,
677 static const struct wined3d_query_ops timestamp_query_ops
=
679 wined3d_timestamp_query_ops_get_data
,
680 wined3d_timestamp_query_ops_issue
,
683 static const struct wined3d_query_ops timestamp_disjoint_query_ops
=
685 wined3d_timestamp_disjoint_query_ops_get_data
,
686 wined3d_timestamp_disjoint_query_ops_issue
,
689 static HRESULT
query_init(struct wined3d_query
*query
, struct wined3d_device
*device
,
690 enum wined3d_query_type type
, void *parent
)
692 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
694 query
->parent
= parent
;
698 case WINED3D_QUERY_TYPE_OCCLUSION
:
699 TRACE("Occlusion query.\n");
700 if (!gl_info
->supported
[ARB_OCCLUSION_QUERY
])
702 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
703 return WINED3DERR_NOTAVAILABLE
;
705 query
->query_ops
= &occlusion_query_ops
;
706 query
->data_size
= sizeof(DWORD
);
707 query
->extendedData
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query
));
708 if (!query
->extendedData
)
710 ERR("Failed to allocate occlusion query extended data.\n");
711 return E_OUTOFMEMORY
;
713 ((struct wined3d_occlusion_query
*)query
->extendedData
)->context
= NULL
;
716 case WINED3D_QUERY_TYPE_EVENT
:
717 TRACE("Event query.\n");
718 if (!wined3d_event_query_supported(gl_info
))
720 WARN("Event queries not supported.\n");
721 return WINED3DERR_NOTAVAILABLE
;
723 query
->query_ops
= &event_query_ops
;
724 query
->data_size
= sizeof(BOOL
);
725 query
->extendedData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct wined3d_event_query
));
726 if (!query
->extendedData
)
728 ERR("Failed to allocate event query memory.\n");
729 return E_OUTOFMEMORY
;
733 case WINED3D_QUERY_TYPE_TIMESTAMP
:
734 TRACE("Timestamp query.\n");
735 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
737 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
738 return WINED3DERR_NOTAVAILABLE
;
740 query
->query_ops
= ×tamp_query_ops
;
741 query
->data_size
= sizeof(UINT64
);
742 query
->extendedData
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_timestamp_query
));
743 if (!query
->extendedData
)
745 ERR("Failed to allocate timestamp query extended data.\n");
746 return E_OUTOFMEMORY
;
748 ((struct wined3d_timestamp_query
*)query
->extendedData
)->context
= NULL
;
751 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
:
752 case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ
:
753 TRACE("TIMESTAMP_DISJOINT query.\n");
754 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
756 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
757 return WINED3DERR_NOTAVAILABLE
;
759 query
->query_ops
= ×tamp_disjoint_query_ops
;
760 query
->data_size
= type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
761 ? sizeof(struct wined3d_query_data_timestamp_disjoint
) : sizeof(UINT64
);
762 query
->extendedData
= NULL
;
765 case WINED3D_QUERY_TYPE_VCACHE
:
766 case WINED3D_QUERY_TYPE_RESOURCE_MANAGER
:
767 case WINED3D_QUERY_TYPE_VERTEX_STATS
:
768 case WINED3D_QUERY_TYPE_PIPELINE_TIMINGS
:
769 case WINED3D_QUERY_TYPE_INTERFACE_TIMINGS
:
770 case WINED3D_QUERY_TYPE_VERTEX_TIMINGS
:
771 case WINED3D_QUERY_TYPE_PIXEL_TIMINGS
:
772 case WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS
:
773 case WINED3D_QUERY_TYPE_CACHE_UTILIZATION
:
775 FIXME("Unhandled query type %#x.\n", type
);
776 return WINED3DERR_NOTAVAILABLE
;
780 query
->state
= QUERY_CREATED
;
781 query
->device
= device
;
787 HRESULT CDECL
wined3d_query_create(struct wined3d_device
*device
,
788 enum wined3d_query_type type
, void *parent
, struct wined3d_query
**query
)
790 struct wined3d_query
*object
;
793 TRACE("device %p, type %#x, parent %p, query %p.\n", device
, type
, parent
, query
);
795 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
797 return E_OUTOFMEMORY
;
799 if (FAILED(hr
= query_init(object
, device
, type
, parent
)))
801 WARN("Failed to initialize query, hr %#x.\n", hr
);
802 HeapFree(GetProcessHeap(), 0, object
);
806 TRACE("Created query %p.\n", object
);