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
, query
->context
->current_rt
);
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("(%p)\n", query
);
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
, query
->context
->current_rt
);
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
, query
->context
->current_rt
);
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 ULONG CDECL
wined3d_query_decref(struct wined3d_query
*query
)
238 ULONG refcount
= InterlockedDecrement(&query
->ref
);
240 TRACE("%p decreasing refcount to %u.\n", query
, refcount
);
244 /* Queries are specific to the GL context that created them. Not
245 * deleting the query will obviously leak it, but that's still better
246 * than potentially deleting a different query with the same id in this
247 * context, and (still) leaking the actual query. */
248 if (query
->type
== WINED3D_QUERY_TYPE_EVENT
)
250 struct wined3d_event_query
*event_query
= query
->extendedData
;
251 if (event_query
) wined3d_event_query_destroy(event_query
);
253 else if (query
->type
== WINED3D_QUERY_TYPE_OCCLUSION
)
255 struct wined3d_occlusion_query
*oq
= query
->extendedData
;
257 if (oq
->context
) context_free_occlusion_query(oq
);
258 HeapFree(GetProcessHeap(), 0, query
->extendedData
);
260 else if (query
->type
== WINED3D_QUERY_TYPE_TIMESTAMP
)
262 struct wined3d_timestamp_query
*tq
= query
->extendedData
;
265 context_free_timestamp_query(tq
);
266 HeapFree(GetProcessHeap(), 0, query
->extendedData
);
269 HeapFree(GetProcessHeap(), 0, query
);
275 HRESULT CDECL
wined3d_query_get_data(struct wined3d_query
*query
,
276 void *data
, UINT data_size
, DWORD flags
)
278 TRACE("query %p, data %p, data_size %u, flags %#x.\n",
279 query
, data
, data_size
, flags
);
281 return query
->query_ops
->query_get_data(query
, data
, data_size
, flags
);
284 UINT CDECL
wined3d_query_get_data_size(const struct wined3d_query
*query
)
286 TRACE("query %p.\n", query
);
288 return query
->data_size
;
291 HRESULT CDECL
wined3d_query_issue(struct wined3d_query
*query
, DWORD flags
)
293 TRACE("query %p, flags %#x.\n", query
, flags
);
295 return query
->query_ops
->query_issue(query
, flags
);
298 static void fill_query_data(void *out
, unsigned int out_size
, const void *result
, unsigned int result_size
)
300 memcpy(out
, result
, min(out_size
, result_size
));
303 static HRESULT
wined3d_occlusion_query_ops_get_data(struct wined3d_query
*query
,
304 void *data
, DWORD size
, DWORD flags
)
306 struct wined3d_occlusion_query
*oq
= query
->extendedData
;
307 struct wined3d_device
*device
= query
->device
;
308 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
309 struct wined3d_context
*context
;
314 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
317 query
->state
= QUERY_CREATED
;
319 if (query
->state
== QUERY_CREATED
)
321 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
322 TRACE("Query wasn't yet started, returning S_OK\n");
324 fill_query_data(data
, size
, &samples
, sizeof(samples
));
328 if (query
->state
== QUERY_BUILDING
)
330 /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
331 TRACE("Query is building, returning S_FALSE\n");
335 if (!gl_info
->supported
[ARB_OCCLUSION_QUERY
])
337 WARN("%p Occlusion queries not supported. Returning 1.\n", query
);
339 fill_query_data(data
, size
, &samples
, sizeof(samples
));
343 if (oq
->context
->tid
!= GetCurrentThreadId())
345 FIXME("%p Wrong thread, returning 1.\n", query
);
347 fill_query_data(data
, size
, &samples
, sizeof(samples
));
351 context
= context_acquire(query
->device
, oq
->context
->current_rt
);
353 GL_EXTCALL(glGetQueryObjectuivARB(oq
->id
, GL_QUERY_RESULT_AVAILABLE_ARB
, &available
));
354 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
355 TRACE("available %#x.\n", available
);
361 GL_EXTCALL(glGetQueryObjectuivARB(oq
->id
, GL_QUERY_RESULT_ARB
, &samples
));
362 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
363 TRACE("Returning %d samples.\n", samples
);
364 fill_query_data(data
, size
, &samples
, sizeof(samples
));
373 context_release(context
);
378 static HRESULT
wined3d_event_query_ops_get_data(struct wined3d_query
*query
,
379 void *data
, DWORD size
, DWORD flags
)
381 struct wined3d_event_query
*event_query
= query
->extendedData
;
383 enum wined3d_event_query_result ret
;
385 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
387 if (!data
|| !size
) return S_OK
;
390 WARN("Event query not supported by GL, reporting GPU idle.\n");
392 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
396 ret
= wined3d_event_query_test(event_query
, query
->device
);
399 case WINED3D_EVENT_QUERY_OK
:
400 case WINED3D_EVENT_QUERY_NOT_STARTED
:
402 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
405 case WINED3D_EVENT_QUERY_WAITING
:
407 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
410 case WINED3D_EVENT_QUERY_WRONG_THREAD
:
411 FIXME("(%p) Wrong thread, reporting GPU idle.\n", query
);
413 fill_query_data(data
, size
, &signaled
, sizeof(signaled
));
416 case WINED3D_EVENT_QUERY_ERROR
:
417 ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
418 return WINED3DERR_INVALIDCALL
;
424 enum wined3d_query_type CDECL
wined3d_query_get_type(const struct wined3d_query
*query
)
426 TRACE("query %p.\n", query
);
431 static HRESULT
wined3d_event_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
433 TRACE("query %p, flags %#x.\n", query
, flags
);
435 TRACE("(%p) : flags %#x, type D3DQUERY_EVENT\n", query
, flags
);
436 if (flags
& WINED3DISSUE_END
)
438 struct wined3d_event_query
*event_query
= query
->extendedData
;
440 /* Faked event query support */
441 if (!event_query
) return WINED3D_OK
;
443 wined3d_event_query_issue(event_query
, query
->device
);
445 else if (flags
& WINED3DISSUE_BEGIN
)
447 /* Started implicitly at device creation */
448 ERR("Event query issued with START flag - what to do?\n");
451 if (flags
& WINED3DISSUE_BEGIN
)
452 query
->state
= QUERY_BUILDING
;
454 query
->state
= QUERY_SIGNALLED
;
459 static HRESULT
wined3d_occlusion_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
461 struct wined3d_device
*device
= query
->device
;
462 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
464 TRACE("query %p, flags %#x.\n", query
, flags
);
466 if (gl_info
->supported
[ARB_OCCLUSION_QUERY
])
468 struct wined3d_occlusion_query
*oq
= query
->extendedData
;
469 struct wined3d_context
*context
;
471 /* This is allowed according to msdn and our tests. Reset the query and restart */
472 if (flags
& WINED3DISSUE_BEGIN
)
474 if (query
->state
== QUERY_BUILDING
)
476 if (oq
->context
->tid
!= GetCurrentThreadId())
478 FIXME("Wrong thread, can't restart query.\n");
480 context_free_occlusion_query(oq
);
481 context
= context_acquire(query
->device
, NULL
);
482 context_alloc_occlusion_query(context
, oq
);
486 context
= context_acquire(query
->device
, oq
->context
->current_rt
);
488 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB
));
489 checkGLcall("glEndQuery()");
494 if (oq
->context
) context_free_occlusion_query(oq
);
495 context
= context_acquire(query
->device
, NULL
);
496 context_alloc_occlusion_query(context
, oq
);
499 GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB
, oq
->id
));
500 checkGLcall("glBeginQuery()");
502 context_release(context
);
504 if (flags
& WINED3DISSUE_END
)
506 /* Msdn says _END on a non-building occlusion query returns an error, but
507 * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
508 * generating an error
510 if (query
->state
== QUERY_BUILDING
)
512 if (oq
->context
->tid
!= GetCurrentThreadId())
514 FIXME("Wrong thread, can't end query.\n");
518 context
= context_acquire(query
->device
, oq
->context
->current_rt
);
520 GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB
));
521 checkGLcall("glEndQuery()");
523 context_release(context
);
530 FIXME("%p Occlusion queries not supported.\n", query
);
533 if (flags
& WINED3DISSUE_BEGIN
)
534 query
->state
= QUERY_BUILDING
;
536 query
->state
= QUERY_SIGNALLED
;
538 return WINED3D_OK
; /* can be WINED3DERR_INVALIDCALL. */
541 static HRESULT
wined3d_timestamp_query_ops_get_data(struct wined3d_query
*query
,
542 void *data
, DWORD size
, DWORD flags
)
544 struct wined3d_timestamp_query
*tq
= query
->extendedData
;
545 struct wined3d_device
*device
= query
->device
;
546 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
547 struct wined3d_context
*context
;
552 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
555 query
->state
= QUERY_CREATED
;
557 if (query
->state
== QUERY_CREATED
)
559 /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves. */
560 TRACE("Query wasn't yet started, returning S_OK.\n");
562 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
566 if (tq
->context
->tid
!= GetCurrentThreadId())
568 FIXME("%p Wrong thread, returning 1.\n", query
);
570 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
574 context
= context_acquire(query
->device
, tq
->context
->current_rt
);
576 GL_EXTCALL(glGetQueryObjectuivARB(tq
->id
, GL_QUERY_RESULT_AVAILABLE_ARB
, &available
));
577 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
578 TRACE("available %#x.\n", available
);
584 GL_EXTCALL(glGetQueryObjectui64v(tq
->id
, GL_QUERY_RESULT_ARB
, ×tamp
));
585 checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
586 TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp
));
587 fill_query_data(data
, size
, ×tamp
, sizeof(timestamp
));
596 context_release(context
);
601 static HRESULT
wined3d_timestamp_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
603 struct wined3d_device
*device
= query
->device
;
604 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
606 TRACE("query %p, flags %#x.\n", query
, flags
);
608 if (gl_info
->supported
[ARB_TIMER_QUERY
])
610 struct wined3d_timestamp_query
*tq
= query
->extendedData
;
611 struct wined3d_context
*context
;
613 if (flags
& WINED3DISSUE_BEGIN
)
615 WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
617 if (flags
& WINED3DISSUE_END
)
620 context_free_timestamp_query(tq
);
621 context
= context_acquire(query
->device
, NULL
);
622 context_alloc_timestamp_query(context
, tq
);
623 GL_EXTCALL(glQueryCounter(tq
->id
, GL_TIMESTAMP
));
624 checkGLcall("glQueryCounter()");
625 context_release(context
);
630 ERR("Timestamp queries not supported.\n");
633 if (flags
& WINED3DISSUE_END
)
634 query
->state
= QUERY_SIGNALLED
;
639 static HRESULT
wined3d_timestamp_disjoint_query_ops_get_data(struct wined3d_query
*query
,
640 void *data
, DWORD size
, DWORD flags
)
642 TRACE("query %p, data %p, size %#x, flags %#x.\n", query
, data
, size
, flags
);
644 if (query
->type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
)
646 static const struct wined3d_query_data_timestamp_disjoint disjoint_data
= {FALSE
, 1000 * 1000 * 1000};
648 if (query
->state
== QUERY_BUILDING
)
650 TRACE("Query is building, returning S_FALSE.\n");
654 fill_query_data(data
, size
, &disjoint_data
, sizeof(disjoint_data
));
658 static const UINT64 freq
= 1000 * 1000 * 1000;
660 fill_query_data(data
, size
, &freq
, sizeof(freq
));
665 static HRESULT
wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
667 TRACE("query %p, flags %#x.\n", query
, flags
);
669 if (flags
& WINED3DISSUE_BEGIN
)
670 query
->state
= QUERY_BUILDING
;
671 if (flags
& WINED3DISSUE_END
)
672 query
->state
= QUERY_SIGNALLED
;
677 static const struct wined3d_query_ops event_query_ops
=
679 wined3d_event_query_ops_get_data
,
680 wined3d_event_query_ops_issue
,
683 static const struct wined3d_query_ops occlusion_query_ops
=
685 wined3d_occlusion_query_ops_get_data
,
686 wined3d_occlusion_query_ops_issue
,
689 static const struct wined3d_query_ops timestamp_query_ops
=
691 wined3d_timestamp_query_ops_get_data
,
692 wined3d_timestamp_query_ops_issue
,
695 static const struct wined3d_query_ops timestamp_disjoint_query_ops
=
697 wined3d_timestamp_disjoint_query_ops_get_data
,
698 wined3d_timestamp_disjoint_query_ops_issue
,
701 static HRESULT
query_init(struct wined3d_query
*query
, struct wined3d_device
*device
, enum wined3d_query_type type
)
703 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
707 case WINED3D_QUERY_TYPE_OCCLUSION
:
708 TRACE("Occlusion query.\n");
709 if (!gl_info
->supported
[ARB_OCCLUSION_QUERY
])
711 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
712 return WINED3DERR_NOTAVAILABLE
;
714 query
->query_ops
= &occlusion_query_ops
;
715 query
->data_size
= sizeof(DWORD
);
716 query
->extendedData
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query
));
717 if (!query
->extendedData
)
719 ERR("Failed to allocate occlusion query extended data.\n");
720 return E_OUTOFMEMORY
;
722 ((struct wined3d_occlusion_query
*)query
->extendedData
)->context
= NULL
;
725 case WINED3D_QUERY_TYPE_EVENT
:
726 TRACE("Event query.\n");
727 if (!wined3d_event_query_supported(gl_info
))
729 /* Half-Life 2 needs this query. It does not render the main
730 * menu correctly otherwise. Pretend to support it, faking
731 * this query does not do much harm except potentially
732 * lowering performance. */
733 FIXME("Event query: Unimplemented, but pretending to be supported.\n");
735 query
->query_ops
= &event_query_ops
;
736 query
->data_size
= sizeof(BOOL
);
737 query
->extendedData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct wined3d_event_query
));
738 if (!query
->extendedData
)
740 ERR("Failed to allocate event query memory.\n");
741 return E_OUTOFMEMORY
;
745 case WINED3D_QUERY_TYPE_TIMESTAMP
:
746 TRACE("Timestamp query.\n");
747 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
749 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
750 return WINED3DERR_NOTAVAILABLE
;
752 query
->query_ops
= ×tamp_query_ops
;
753 query
->data_size
= sizeof(UINT64
);
754 query
->extendedData
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_timestamp_query
));
755 if (!query
->extendedData
)
757 ERR("Failed to allocate timestamp query extended data.\n");
758 return E_OUTOFMEMORY
;
760 ((struct wined3d_timestamp_query
*)query
->extendedData
)->context
= NULL
;
763 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
:
764 case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ
:
765 TRACE("TIMESTAMP_DISJOINT query.\n");
766 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
768 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
769 return WINED3DERR_NOTAVAILABLE
;
771 query
->query_ops
= ×tamp_disjoint_query_ops
;
772 query
->data_size
= type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
773 ? sizeof(struct wined3d_query_data_timestamp_disjoint
) : sizeof(UINT64
);
774 query
->extendedData
= NULL
;
777 case WINED3D_QUERY_TYPE_VCACHE
:
778 case WINED3D_QUERY_TYPE_RESOURCE_MANAGER
:
779 case WINED3D_QUERY_TYPE_VERTEX_STATS
:
780 case WINED3D_QUERY_TYPE_PIPELINE_TIMINGS
:
781 case WINED3D_QUERY_TYPE_INTERFACE_TIMINGS
:
782 case WINED3D_QUERY_TYPE_VERTEX_TIMINGS
:
783 case WINED3D_QUERY_TYPE_PIXEL_TIMINGS
:
784 case WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS
:
785 case WINED3D_QUERY_TYPE_CACHE_UTILIZATION
:
787 FIXME("Unhandled query type %#x.\n", type
);
788 return WINED3DERR_NOTAVAILABLE
;
792 query
->state
= QUERY_CREATED
;
793 query
->device
= device
;
799 HRESULT CDECL
wined3d_query_create(struct wined3d_device
*device
,
800 enum wined3d_query_type type
, struct wined3d_query
**query
)
802 struct wined3d_query
*object
;
805 TRACE("device %p, type %#x, query %p.\n", device
, type
, query
);
807 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
809 return E_OUTOFMEMORY
;
811 hr
= query_init(object
, device
, type
);
814 WARN("Failed to initialize query, hr %#x.\n", hr
);
815 HeapFree(GetProcessHeap(), 0, object
);
819 TRACE("Created query %p.\n", object
);