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 static void wined3d_query_buffer_invalidate(struct wined3d_query
*query
)
30 /* map[0] != map[1]: exact values do not have any significance. */
31 query
->map_ptr
[0] = 0;
32 query
->map_ptr
[1] = ~(UINT64
)0;
35 static BOOL
wined3d_query_buffer_is_valid(struct wined3d_query
*query
)
37 return query
->map_ptr
[0] == query
->map_ptr
[1];
40 static void wined3d_query_create_buffer_object(struct wined3d_context_gl
*context_gl
, struct wined3d_query
*query
)
42 const GLuint map_flags
= GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
| GL_MAP_PERSISTENT_BIT
| GL_MAP_COHERENT_BIT
;
43 const struct wined3d_gl_info
*gl_info
= context_gl
->gl_info
;
46 GL_EXTCALL(glGenBuffers(1, &buffer_object
));
47 GL_EXTCALL(glBindBuffer(GL_QUERY_BUFFER
, buffer_object
));
48 GL_EXTCALL(glBufferStorage(GL_QUERY_BUFFER
, sizeof(query
->map_ptr
[0]) * 2, NULL
, map_flags
));
49 query
->map_ptr
= GL_EXTCALL(glMapBufferRange(GL_QUERY_BUFFER
, 0, sizeof(query
->map_ptr
[0]) * 2, map_flags
));
50 GL_EXTCALL(glBindBuffer(GL_QUERY_BUFFER
, 0));
51 checkGLcall("query buffer object creation");
53 wined3d_query_buffer_invalidate(query
);
54 query
->buffer_object
= buffer_object
;
57 void wined3d_query_gl_destroy_buffer_object(struct wined3d_context_gl
*context_gl
, struct wined3d_query
*query
)
59 const struct wined3d_gl_info
*gl_info
= context_gl
->gl_info
;
61 GL_EXTCALL(glDeleteBuffers(1, &query
->buffer_object
));
62 checkGLcall("query buffer object destruction");
64 query
->buffer_object
= 0;
65 query
->map_ptr
= NULL
;
68 /* From ARB_occlusion_query: "Querying the state for a given occlusion query
69 * forces that occlusion query to complete within a finite amount of time."
70 * In practice, that means drivers flush when retrieving
71 * GL_QUERY_RESULT_AVAILABLE, which can be undesirable when applications use a
72 * significant number of queries. Using a persistently mapped query buffer
73 * object allows us to avoid these implicit flushes. An additional benefit is
74 * that it allows us to poll the query status from the application-thread
75 * instead of from the csmt-thread. */
76 static BOOL
wined3d_query_buffer_queue_result(struct wined3d_context_gl
*context_gl
,
77 struct wined3d_query
*query
, GLuint id
)
79 const struct wined3d_gl_info
*gl_info
= context_gl
->gl_info
;
82 if (!gl_info
->supported
[ARB_QUERY_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_BUFFER_STORAGE
])
84 /* Don't use query buffers without CSMT, mainly for simplicity. */
85 if (!context_gl
->c
.device
->cs
->thread
)
88 if (query
->buffer_object
)
90 /* If there's still a query result in-flight for the existing buffer
91 * object (i.e., the query was restarted before we received its
92 * result), we can't reuse the existing buffer object. */
93 if (wined3d_query_buffer_is_valid(query
))
94 wined3d_query_buffer_invalidate(query
);
96 wined3d_query_gl_destroy_buffer_object(context_gl
, query
);
99 if (!query
->buffer_object
)
100 wined3d_query_create_buffer_object(context_gl
, query
);
102 GL_EXTCALL(glBindBuffer(GL_QUERY_BUFFER
, query
->buffer_object
));
103 /* Read the same value twice. We know we have the result if map_ptr[0] == map_ptr[1]. */
104 GL_EXTCALL(glGetQueryObjectui64v(id
, GL_QUERY_RESULT
, (void *)0));
105 GL_EXTCALL(glGetQueryObjectui64v(id
, GL_QUERY_RESULT
, (void *)sizeof(query
->map_ptr
[0])));
106 GL_EXTCALL(glBindBuffer(GL_QUERY_BUFFER
, 0));
107 checkGLcall("queue query result");
109 /* ARB_buffer_storage requires the client to call FenceSync with
110 * SYNC_GPU_COMMANDS_COMPLETE after the server does a write. This behavior
111 * is not enforced by Mesa.
113 tmp_sync
= GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0));
114 GL_EXTCALL(glDeleteSync(tmp_sync
));
115 checkGLcall("query buffer sync");
120 static UINT64
get_query_result64(GLuint id
, const struct wined3d_gl_info
*gl_info
)
122 if (gl_info
->supported
[ARB_TIMER_QUERY
])
125 GL_EXTCALL(glGetQueryObjectui64v(id
, GL_QUERY_RESULT
, &result
));
131 GL_EXTCALL(glGetQueryObjectuiv(id
, GL_QUERY_RESULT
, &result
));
136 static void wined3d_query_init(struct wined3d_query
*query
, struct wined3d_device
*device
,
137 enum wined3d_query_type type
, const void *data
, DWORD data_size
,
138 const struct wined3d_query_ops
*query_ops
, void *parent
, const struct wined3d_parent_ops
*parent_ops
)
141 query
->parent
= parent
;
142 query
->parent_ops
= parent_ops
;
143 query
->device
= device
;
144 query
->state
= QUERY_CREATED
;
147 query
->data_size
= data_size
;
148 query
->query_ops
= query_ops
;
149 list_init(&query
->poll_list_entry
);
152 static struct wined3d_event_query
*wined3d_event_query_from_query(struct wined3d_query
*query
)
154 return CONTAINING_RECORD(query
, struct wined3d_event_query
, query
);
157 static struct wined3d_occlusion_query
*wined3d_occlusion_query_from_query(struct wined3d_query
*query
)
159 return CONTAINING_RECORD(query
, struct wined3d_occlusion_query
, query
);
162 static struct wined3d_timestamp_query
*wined3d_timestamp_query_from_query(struct wined3d_query
*query
)
164 return CONTAINING_RECORD(query
, struct wined3d_timestamp_query
, query
);
167 static struct wined3d_so_statistics_query
*wined3d_so_statistics_query_from_query(struct wined3d_query
*query
)
169 return CONTAINING_RECORD(query
, struct wined3d_so_statistics_query
, query
);
172 static struct wined3d_pipeline_statistics_query
*wined3d_pipeline_statistics_query_from_query(
173 struct wined3d_query
*query
)
175 return CONTAINING_RECORD(query
, struct wined3d_pipeline_statistics_query
, query
);
178 static BOOL
wined3d_fence_supported(const struct wined3d_gl_info
*gl_info
)
180 return gl_info
->supported
[ARB_SYNC
] || gl_info
->supported
[NV_FENCE
] || gl_info
->supported
[APPLE_FENCE
];
183 enum wined3d_fence_result
wined3d_fence_test(const struct wined3d_fence
*fence
,
184 struct wined3d_device
*device
, DWORD flags
)
186 const struct wined3d_gl_info
*gl_info
;
187 struct wined3d_context_gl
*context_gl
;
188 enum wined3d_fence_result ret
;
191 TRACE("fence %p, device %p, flags %#x.\n", fence
, device
, flags
);
193 if (!fence
->context_gl
)
195 TRACE("Fence not issued.\n");
196 return WINED3D_FENCE_NOT_STARTED
;
199 if (!(context_gl
= wined3d_context_gl_reacquire(fence
->context_gl
)))
201 if (!fence
->context_gl
->gl_info
->supported
[ARB_SYNC
])
203 WARN("Fence tested from wrong thread.\n");
204 return WINED3D_FENCE_WRONG_THREAD
;
206 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
208 gl_info
= context_gl
->gl_info
;
210 if (gl_info
->supported
[ARB_SYNC
])
212 GLenum gl_ret
= GL_EXTCALL(glClientWaitSync(fence
->object
.sync
,
213 (flags
& WINED3DGETDATA_FLUSH
) ? GL_SYNC_FLUSH_COMMANDS_BIT
: 0, 0));
214 checkGLcall("glClientWaitSync");
218 case GL_ALREADY_SIGNALED
:
219 case GL_CONDITION_SATISFIED
:
220 ret
= WINED3D_FENCE_OK
;
223 case GL_TIMEOUT_EXPIRED
:
224 ret
= WINED3D_FENCE_WAITING
;
229 ERR("glClientWaitSync returned %#x.\n", gl_ret
);
230 ret
= WINED3D_FENCE_ERROR
;
233 else if (gl_info
->supported
[APPLE_FENCE
])
235 fence_result
= GL_EXTCALL(glTestFenceAPPLE(fence
->object
.id
));
236 checkGLcall("glTestFenceAPPLE");
238 ret
= WINED3D_FENCE_OK
;
240 ret
= WINED3D_FENCE_WAITING
;
242 else if (gl_info
->supported
[NV_FENCE
])
244 fence_result
= GL_EXTCALL(glTestFenceNV(fence
->object
.id
));
245 checkGLcall("glTestFenceNV");
247 ret
= WINED3D_FENCE_OK
;
249 ret
= WINED3D_FENCE_WAITING
;
253 ERR("Fence created despite lack of GL support.\n");
254 ret
= WINED3D_FENCE_ERROR
;
257 context_release(&context_gl
->c
);
261 enum wined3d_fence_result
wined3d_fence_wait(const struct wined3d_fence
*fence
,
262 struct wined3d_device
*device
)
264 const struct wined3d_gl_info
*gl_info
;
265 struct wined3d_context_gl
*context_gl
;
266 enum wined3d_fence_result ret
;
268 TRACE("fence %p, device %p.\n", fence
, device
);
270 if (!fence
->context_gl
)
272 TRACE("Fence not issued.\n");
273 return WINED3D_FENCE_NOT_STARTED
;
275 gl_info
= fence
->context_gl
->gl_info
;
277 if (!(context_gl
= wined3d_context_gl_reacquire(fence
->context_gl
)))
279 /* A glFinish does not reliably wait for draws in other contexts. The caller has
280 * to find its own way to cope with the thread switch
282 if (!gl_info
->supported
[ARB_SYNC
])
284 WARN("Fence finished from wrong thread.\n");
285 return WINED3D_FENCE_WRONG_THREAD
;
287 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
289 gl_info
= context_gl
->gl_info
;
291 if (gl_info
->supported
[ARB_SYNC
])
293 /* Timeouts near 0xffffffffffffffff may immediately return GL_TIMEOUT_EXPIRED,
294 * possibly because macOS internally adds some slop to the timer. To avoid this,
295 * we use a large number that isn't near the point of overflow (macOS 10.12.5).
297 GLenum gl_ret
= GL_EXTCALL(glClientWaitSync(fence
->object
.sync
,
298 GL_SYNC_FLUSH_COMMANDS_BIT
, ~(GLuint64
)0 >> 1));
299 checkGLcall("glClientWaitSync");
303 case GL_ALREADY_SIGNALED
:
304 case GL_CONDITION_SATISFIED
:
305 ret
= WINED3D_FENCE_OK
;
308 /* We don't expect a timeout for a ~292 year wait */
310 ERR("glClientWaitSync returned %#x.\n", gl_ret
);
311 ret
= WINED3D_FENCE_ERROR
;
314 else if (gl_info
->supported
[APPLE_FENCE
])
316 GL_EXTCALL(glFinishFenceAPPLE(fence
->object
.id
));
317 checkGLcall("glFinishFenceAPPLE");
318 ret
= WINED3D_FENCE_OK
;
320 else if (gl_info
->supported
[NV_FENCE
])
322 GL_EXTCALL(glFinishFenceNV(fence
->object
.id
));
323 checkGLcall("glFinishFenceNV");
324 ret
= WINED3D_FENCE_OK
;
328 ERR("Fence created without GL support.\n");
329 ret
= WINED3D_FENCE_ERROR
;
332 context_release(&context_gl
->c
);
336 void wined3d_fence_issue(struct wined3d_fence
*fence
, struct wined3d_device
*device
)
338 struct wined3d_context_gl
*context_gl
= NULL
;
339 const struct wined3d_gl_info
*gl_info
;
341 if (fence
->context_gl
&& !(context_gl
= wined3d_context_gl_reacquire(fence
->context_gl
))
342 && !fence
->context_gl
->gl_info
->supported
[ARB_SYNC
])
343 wined3d_context_gl_free_fence(fence
);
345 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
346 gl_info
= context_gl
->gl_info
;
347 if (!fence
->context_gl
)
348 wined3d_context_gl_alloc_fence(context_gl
, fence
);
350 if (gl_info
->supported
[ARB_SYNC
])
352 if (fence
->object
.sync
)
353 GL_EXTCALL(glDeleteSync(fence
->object
.sync
));
354 checkGLcall("glDeleteSync");
355 fence
->object
.sync
= GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0));
356 checkGLcall("glFenceSync");
358 else if (gl_info
->supported
[APPLE_FENCE
])
360 GL_EXTCALL(glSetFenceAPPLE(fence
->object
.id
));
361 checkGLcall("glSetFenceAPPLE");
363 else if (gl_info
->supported
[NV_FENCE
])
365 GL_EXTCALL(glSetFenceNV(fence
->object
.id
, GL_ALL_COMPLETED_NV
));
366 checkGLcall("glSetFenceNV");
369 context_release(&context_gl
->c
);
372 static void wined3d_fence_free(struct wined3d_fence
*fence
)
374 if (fence
->context_gl
)
375 wined3d_context_gl_free_fence(fence
);
378 void wined3d_fence_destroy(struct wined3d_fence
*fence
)
380 wined3d_fence_free(fence
);
384 static HRESULT
wined3d_fence_init(struct wined3d_fence
*fence
, const struct wined3d_gl_info
*gl_info
)
386 if (!wined3d_fence_supported(gl_info
))
388 WARN("Fences not supported.\n");
389 return WINED3DERR_NOTAVAILABLE
;
395 HRESULT
wined3d_fence_create(struct wined3d_device
*device
, struct wined3d_fence
**fence
)
397 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
398 struct wined3d_fence
*object
;
401 TRACE("device %p, fence %p.\n", device
, fence
);
403 if (!(object
= heap_alloc_zero(sizeof(*object
))))
404 return E_OUTOFMEMORY
;
406 if (FAILED(hr
= wined3d_fence_init(object
, gl_info
)))
412 TRACE("Created fence %p.\n", object
);
418 ULONG CDECL
wined3d_query_incref(struct wined3d_query
*query
)
420 ULONG refcount
= InterlockedIncrement(&query
->ref
);
422 TRACE("%p increasing refcount to %u.\n", query
, refcount
);
427 static void wined3d_query_destroy_object(void *object
)
429 struct wined3d_query
*query
= object
;
431 TRACE("query %p.\n", query
);
433 if (!list_empty(&query
->poll_list_entry
))
434 list_remove(&query
->poll_list_entry
);
437 ULONG CDECL
wined3d_query_decref(struct wined3d_query
*query
)
439 ULONG refcount
= InterlockedDecrement(&query
->ref
);
441 TRACE("%p decreasing refcount to %u.\n", query
, refcount
);
445 struct wined3d_device
*device
= query
->device
;
447 query
->parent_ops
->wined3d_object_destroyed(query
->parent
);
448 wined3d_cs_destroy_object(device
->cs
, wined3d_query_destroy_object
, query
);
449 device
->adapter
->adapter_ops
->adapter_destroy_query(query
);
455 HRESULT CDECL
wined3d_query_get_data(struct wined3d_query
*query
,
456 void *data
, UINT data_size
, DWORD flags
)
458 TRACE("query %p, data %p, data_size %u, flags %#x.\n",
459 query
, data
, data_size
, flags
);
461 if (query
->state
== QUERY_BUILDING
)
463 WARN("Query is building, returning S_FALSE.\n");
467 if (query
->state
== QUERY_CREATED
)
469 WARN("Query wasn't started yet.\n");
470 return WINED3DERR_INVALIDCALL
;
473 if (query
->device
->cs
->thread
)
475 if (query
->counter_main
!= query
->counter_retrieved
476 || (query
->buffer_object
&& !wined3d_query_buffer_is_valid(query
)))
478 if (flags
& WINED3DGETDATA_FLUSH
&& !query
->device
->cs
->queries_flushed
)
479 wined3d_cs_emit_flush(query
->device
->cs
);
482 if (query
->buffer_object
)
483 query
->data
= query
->map_ptr
;
485 else if (!query
->query_ops
->query_poll(query
, flags
))
491 memcpy(data
, query
->data
, min(data_size
, query
->data_size
));
496 UINT CDECL
wined3d_query_get_data_size(const struct wined3d_query
*query
)
498 TRACE("query %p.\n", query
);
500 return query
->data_size
;
503 HRESULT CDECL
wined3d_query_issue(struct wined3d_query
*query
, DWORD flags
)
505 TRACE("query %p, flags %#x.\n", query
, flags
);
507 if (flags
& WINED3DISSUE_END
)
508 ++query
->counter_main
;
510 wined3d_cs_emit_query_issue(query
->device
->cs
, query
, flags
);
512 if (flags
& WINED3DISSUE_BEGIN
)
513 query
->state
= QUERY_BUILDING
;
515 query
->state
= QUERY_SIGNALLED
;
520 static BOOL
wined3d_occlusion_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
522 struct wined3d_occlusion_query
*oq
= wined3d_occlusion_query_from_query(query
);
523 const struct wined3d_gl_info
*gl_info
;
524 struct wined3d_context_gl
*context_gl
;
527 TRACE("query %p, flags %#x.\n", query
, flags
);
529 if (!(context_gl
= wined3d_context_gl_reacquire(oq
->context_gl
)))
531 FIXME("%p Wrong thread, returning 1.\n", query
);
535 gl_info
= context_gl
->gl_info
;
537 GL_EXTCALL(glGetQueryObjectuiv(oq
->id
, GL_QUERY_RESULT_AVAILABLE
, &available
));
538 TRACE("Available %#x.\n", available
);
542 oq
->samples
= get_query_result64(oq
->id
, gl_info
);
543 TRACE("Returning 0x%s samples.\n", wine_dbgstr_longlong(oq
->samples
));
546 checkGLcall("poll occlusion query");
547 context_release(&context_gl
->c
);
552 static BOOL
wined3d_event_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
554 struct wined3d_event_query
*event_query
= wined3d_event_query_from_query(query
);
555 enum wined3d_fence_result ret
;
557 TRACE("query %p, flags %#x.\n", query
, flags
);
559 ret
= wined3d_fence_test(&event_query
->fence
, query
->device
, flags
);
562 case WINED3D_FENCE_OK
:
563 case WINED3D_FENCE_NOT_STARTED
:
564 return event_query
->signalled
= TRUE
;
566 case WINED3D_FENCE_WAITING
:
567 return event_query
->signalled
= FALSE
;
569 case WINED3D_FENCE_WRONG_THREAD
:
570 FIXME("(%p) Wrong thread, reporting GPU idle.\n", query
);
571 return event_query
->signalled
= TRUE
;
573 case WINED3D_FENCE_ERROR
:
574 ERR("The GL event query failed.\n");
575 return event_query
->signalled
= TRUE
;
578 ERR("Unexpected wined3d_event_query_test result %#x.\n", ret
);
579 return event_query
->signalled
= TRUE
;
583 void * CDECL
wined3d_query_get_parent(const struct wined3d_query
*query
)
585 TRACE("query %p.\n", query
);
587 return query
->parent
;
590 enum wined3d_query_type CDECL
wined3d_query_get_type(const struct wined3d_query
*query
)
592 TRACE("query %p.\n", query
);
597 static BOOL
wined3d_event_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
599 TRACE("query %p, flags %#x.\n", query
, flags
);
601 if (flags
& WINED3DISSUE_END
)
603 struct wined3d_event_query
*event_query
= wined3d_event_query_from_query(query
);
605 wined3d_fence_issue(&event_query
->fence
, query
->device
);
608 else if (flags
& WINED3DISSUE_BEGIN
)
610 /* Started implicitly at query creation. */
611 ERR("Event query issued with START flag - what to do?\n");
617 static BOOL
wined3d_occlusion_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
619 struct wined3d_occlusion_query
*oq
= wined3d_occlusion_query_from_query(query
);
620 struct wined3d_device
*device
= query
->device
;
621 const struct wined3d_gl_info
*gl_info
;
622 struct wined3d_context_gl
*context_gl
;
625 TRACE("query %p, flags %#x.\n", query
, flags
);
627 /* This is allowed according to MSDN and our tests. Reset the query and
629 if (flags
& WINED3DISSUE_BEGIN
)
633 if ((context_gl
= wined3d_context_gl_reacquire(oq
->context_gl
)))
635 gl_info
= context_gl
->gl_info
;
636 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED
));
637 checkGLcall("glEndQuery()");
641 FIXME("Wrong thread, can't restart query.\n");
642 wined3d_context_gl_free_occlusion_query(oq
);
643 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
644 wined3d_context_gl_alloc_occlusion_query(context_gl
, oq
);
650 wined3d_context_gl_free_occlusion_query(oq
);
651 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
652 wined3d_context_gl_alloc_occlusion_query(context_gl
, oq
);
654 gl_info
= context_gl
->gl_info
;
656 GL_EXTCALL(glBeginQuery(GL_SAMPLES_PASSED
, oq
->id
));
657 checkGLcall("glBeginQuery()");
659 context_release(&context_gl
->c
);
662 if (flags
& WINED3DISSUE_END
)
664 /* MSDN says END on a non-building occlusion query returns an error,
665 * but our tests show that it returns OK. But OpenGL doesn't like it,
666 * so avoid generating an error. */
669 if ((context_gl
= wined3d_context_gl_reacquire(oq
->context_gl
)))
671 gl_info
= context_gl
->gl_info
;
672 GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED
));
673 checkGLcall("glEndQuery()");
674 wined3d_query_buffer_queue_result(context_gl
, query
, oq
->id
);
676 context_release(&context_gl
->c
);
681 FIXME("Wrong thread, can't end query.\n");
690 static BOOL
wined3d_timestamp_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
692 struct wined3d_timestamp_query
*tq
= wined3d_timestamp_query_from_query(query
);
693 const struct wined3d_gl_info
*gl_info
;
694 struct wined3d_context_gl
*context_gl
;
698 TRACE("query %p, flags %#x.\n", query
, flags
);
700 if (!(context_gl
= wined3d_context_gl_reacquire(tq
->context_gl
)))
702 FIXME("%p Wrong thread, returning 1.\n", query
);
706 gl_info
= context_gl
->gl_info
;
708 GL_EXTCALL(glGetQueryObjectuiv(tq
->id
, GL_QUERY_RESULT_AVAILABLE
, &available
));
709 checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
710 TRACE("available %#x.\n", available
);
714 GL_EXTCALL(glGetQueryObjectui64v(tq
->id
, GL_QUERY_RESULT
, ×tamp
));
715 checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
716 TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp
));
717 tq
->timestamp
= timestamp
;
720 context_release(&context_gl
->c
);
725 static BOOL
wined3d_timestamp_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
727 struct wined3d_timestamp_query
*tq
= wined3d_timestamp_query_from_query(query
);
728 const struct wined3d_gl_info
*gl_info
;
729 struct wined3d_context_gl
*context_gl
;
731 TRACE("query %p, flags %#x.\n", query
, flags
);
733 if (flags
& WINED3DISSUE_BEGIN
)
735 WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
737 if (flags
& WINED3DISSUE_END
)
740 wined3d_context_gl_free_timestamp_query(tq
);
741 context_gl
= wined3d_context_gl(context_acquire(query
->device
, NULL
, 0));
742 gl_info
= context_gl
->gl_info
;
743 wined3d_context_gl_alloc_timestamp_query(context_gl
, tq
);
744 GL_EXTCALL(glQueryCounter(tq
->id
, GL_TIMESTAMP
));
745 checkGLcall("glQueryCounter()");
746 context_release(&context_gl
->c
);
754 static BOOL
wined3d_timestamp_disjoint_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
756 TRACE("query %p, flags %#x.\n", query
, flags
);
761 static BOOL
wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
763 TRACE("query %p, flags %#x.\n", query
, flags
);
768 static BOOL
wined3d_so_statistics_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
770 struct wined3d_so_statistics_query
*pq
= wined3d_so_statistics_query_from_query(query
);
771 GLuint written_available
, generated_available
;
772 const struct wined3d_gl_info
*gl_info
;
773 struct wined3d_context_gl
*context_gl
;
775 TRACE("query %p, flags %#x.\n", query
, flags
);
777 if (!(context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
779 FIXME("%p Wrong thread, returning 0 primitives.\n", query
);
780 memset(&pq
->statistics
, 0, sizeof(pq
->statistics
));
783 gl_info
= context_gl
->gl_info
;
785 GL_EXTCALL(glGetQueryObjectuiv(pq
->u
.query
.written
,
786 GL_QUERY_RESULT_AVAILABLE
, &written_available
));
787 GL_EXTCALL(glGetQueryObjectuiv(pq
->u
.query
.generated
,
788 GL_QUERY_RESULT_AVAILABLE
, &generated_available
));
789 TRACE("Available %#x, %#x.\n", written_available
, generated_available
);
791 if (written_available
&& generated_available
)
793 pq
->statistics
.primitives_written
= get_query_result64(pq
->u
.query
.written
, gl_info
);
794 pq
->statistics
.primitives_generated
= get_query_result64(pq
->u
.query
.generated
, gl_info
);
795 TRACE("Returning %s, %s primitives.\n",
796 wine_dbgstr_longlong(pq
->statistics
.primitives_written
),
797 wine_dbgstr_longlong(pq
->statistics
.primitives_generated
));
800 checkGLcall("poll SO statistics query");
801 context_release(&context_gl
->c
);
803 return written_available
&& generated_available
;
806 static void wined3d_so_statistics_query_end(struct wined3d_so_statistics_query
*query
,
807 struct wined3d_context_gl
*context_gl
)
809 const struct wined3d_gl_info
*gl_info
= context_gl
->gl_info
;
811 if (gl_info
->supported
[ARB_TRANSFORM_FEEDBACK3
])
813 GL_EXTCALL(glEndQueryIndexed(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
, query
->stream_idx
));
814 GL_EXTCALL(glEndQueryIndexed(GL_PRIMITIVES_GENERATED
, query
->stream_idx
));
818 GL_EXTCALL(glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
));
819 GL_EXTCALL(glEndQuery(GL_PRIMITIVES_GENERATED
));
821 checkGLcall("end query");
824 static BOOL
wined3d_so_statistics_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
826 struct wined3d_so_statistics_query
*pq
= wined3d_so_statistics_query_from_query(query
);
827 struct wined3d_device
*device
= query
->device
;
828 const struct wined3d_gl_info
*gl_info
;
829 struct wined3d_context_gl
*context_gl
;
832 TRACE("query %p, flags %#x.\n", query
, flags
);
834 if (flags
& WINED3DISSUE_BEGIN
)
838 if ((context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
840 wined3d_so_statistics_query_end(pq
, context_gl
);
844 FIXME("Wrong thread, can't restart query.\n");
845 wined3d_context_gl_free_so_statistics_query(pq
);
846 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
847 wined3d_context_gl_alloc_so_statistics_query(context_gl
, pq
);
853 wined3d_context_gl_free_so_statistics_query(pq
);
854 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
855 wined3d_context_gl_alloc_so_statistics_query(context_gl
, pq
);
857 gl_info
= context_gl
->gl_info
;
859 if (gl_info
->supported
[ARB_TRANSFORM_FEEDBACK3
])
861 GL_EXTCALL(glBeginQueryIndexed(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
,
862 pq
->stream_idx
, pq
->u
.query
.written
));
863 GL_EXTCALL(glBeginQueryIndexed(GL_PRIMITIVES_GENERATED
,
864 pq
->stream_idx
, pq
->u
.query
.generated
));
868 GL_EXTCALL(glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
,
869 pq
->u
.query
.written
));
870 GL_EXTCALL(glBeginQuery(GL_PRIMITIVES_GENERATED
,
871 pq
->u
.query
.generated
));
873 checkGLcall("begin query");
875 context_release(&context_gl
->c
);
878 if (flags
& WINED3DISSUE_END
)
882 if ((context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
884 wined3d_so_statistics_query_end(pq
, context_gl
);
886 context_release(&context_gl
->c
);
891 FIXME("Wrong thread, can't end query.\n");
900 static BOOL
wined3d_pipeline_query_ops_poll(struct wined3d_query
*query
, DWORD flags
)
902 struct wined3d_pipeline_statistics_query
*pq
= wined3d_pipeline_statistics_query_from_query(query
);
903 const struct wined3d_gl_info
*gl_info
;
904 struct wined3d_context_gl
*context_gl
;
908 TRACE("query %p, flags %#x.\n", query
, flags
);
910 if (!(context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
912 FIXME("%p Wrong thread.\n", query
);
913 memset(&pq
->statistics
, 0, sizeof(pq
->statistics
));
916 gl_info
= context_gl
->gl_info
;
918 for (i
= 0; i
< ARRAY_SIZE(pq
->u
.id
); ++i
)
920 GL_EXTCALL(glGetQueryObjectuiv(pq
->u
.id
[i
], GL_QUERY_RESULT_AVAILABLE
, &available
));
927 pq
->statistics
.vertices_submitted
= get_query_result64(pq
->u
.query
.vertices
, gl_info
);
928 pq
->statistics
.primitives_submitted
= get_query_result64(pq
->u
.query
.primitives
, gl_info
);
929 pq
->statistics
.vs_invocations
= get_query_result64(pq
->u
.query
.vertex_shader
, gl_info
);
930 pq
->statistics
.hs_invocations
= get_query_result64(pq
->u
.query
.tess_control_shader
, gl_info
);
931 pq
->statistics
.ds_invocations
= get_query_result64(pq
->u
.query
.tess_eval_shader
, gl_info
);
932 pq
->statistics
.gs_invocations
= get_query_result64(pq
->u
.query
.geometry_shader
, gl_info
);
933 pq
->statistics
.gs_primitives
= get_query_result64(pq
->u
.query
.geometry_primitives
, gl_info
);
934 pq
->statistics
.ps_invocations
= get_query_result64(pq
->u
.query
.fragment_shader
, gl_info
);
935 pq
->statistics
.cs_invocations
= get_query_result64(pq
->u
.query
.compute_shader
, gl_info
);
936 pq
->statistics
.clipping_input_primitives
= get_query_result64(pq
->u
.query
.clipping_input
, gl_info
);
937 pq
->statistics
.clipping_output_primitives
= get_query_result64(pq
->u
.query
.clipping_output
, gl_info
);
940 checkGLcall("poll pipeline statistics query");
941 context_release(&context_gl
->c
);
945 static void wined3d_pipeline_statistics_query_end(struct wined3d_pipeline_statistics_query
*query
,
946 struct wined3d_context_gl
*context_gl
)
948 const struct wined3d_gl_info
*gl_info
= context_gl
->gl_info
;
950 GL_EXTCALL(glEndQuery(GL_VERTICES_SUBMITTED_ARB
));
951 GL_EXTCALL(glEndQuery(GL_PRIMITIVES_SUBMITTED_ARB
));
952 GL_EXTCALL(glEndQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB
));
953 GL_EXTCALL(glEndQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB
));
954 GL_EXTCALL(glEndQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
));
955 GL_EXTCALL(glEndQuery(GL_GEOMETRY_SHADER_INVOCATIONS
));
956 GL_EXTCALL(glEndQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
));
957 GL_EXTCALL(glEndQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB
));
958 GL_EXTCALL(glEndQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB
));
959 GL_EXTCALL(glEndQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB
));
960 GL_EXTCALL(glEndQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
));
961 checkGLcall("end query");
964 static BOOL
wined3d_pipeline_query_ops_issue(struct wined3d_query
*query
, DWORD flags
)
966 struct wined3d_pipeline_statistics_query
*pq
= wined3d_pipeline_statistics_query_from_query(query
);
967 struct wined3d_device
*device
= query
->device
;
968 const struct wined3d_gl_info
*gl_info
;
969 struct wined3d_context_gl
*context_gl
;
972 TRACE("query %p, flags %#x.\n", query
, flags
);
974 if (flags
& WINED3DISSUE_BEGIN
)
978 if ((context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
980 wined3d_pipeline_statistics_query_end(pq
, context_gl
);
984 FIXME("Wrong thread, can't restart query.\n");
985 wined3d_context_gl_free_pipeline_statistics_query(pq
);
986 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
987 wined3d_context_gl_alloc_pipeline_statistics_query(context_gl
, pq
);
993 wined3d_context_gl_free_pipeline_statistics_query(pq
);
994 context_gl
= wined3d_context_gl(context_acquire(device
, NULL
, 0));
995 wined3d_context_gl_alloc_pipeline_statistics_query(context_gl
, pq
);
997 gl_info
= context_gl
->gl_info
;
999 GL_EXTCALL(glBeginQuery(GL_VERTICES_SUBMITTED_ARB
, pq
->u
.query
.vertices
));
1000 GL_EXTCALL(glBeginQuery(GL_PRIMITIVES_SUBMITTED_ARB
, pq
->u
.query
.primitives
));
1001 GL_EXTCALL(glBeginQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB
, pq
->u
.query
.vertex_shader
));
1002 GL_EXTCALL(glBeginQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB
, pq
->u
.query
.tess_control_shader
));
1003 GL_EXTCALL(glBeginQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
, pq
->u
.query
.tess_eval_shader
));
1004 GL_EXTCALL(glBeginQuery(GL_GEOMETRY_SHADER_INVOCATIONS
, pq
->u
.query
.geometry_shader
));
1005 GL_EXTCALL(glBeginQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
, pq
->u
.query
.geometry_primitives
));
1006 GL_EXTCALL(glBeginQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB
, pq
->u
.query
.fragment_shader
));
1007 GL_EXTCALL(glBeginQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB
, pq
->u
.query
.compute_shader
));
1008 GL_EXTCALL(glBeginQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB
, pq
->u
.query
.clipping_input
));
1009 GL_EXTCALL(glBeginQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
, pq
->u
.query
.clipping_output
));
1010 checkGLcall("begin query");
1012 context_release(&context_gl
->c
);
1015 if (flags
& WINED3DISSUE_END
)
1019 if ((context_gl
= wined3d_context_gl_reacquire(pq
->context_gl
)))
1021 wined3d_pipeline_statistics_query_end(pq
, context_gl
);
1022 context_release(&context_gl
->c
);
1027 FIXME("Wrong thread, can't end query.\n");
1030 pq
->started
= FALSE
;
1036 static void wined3d_event_query_ops_destroy(struct wined3d_query
*query
)
1038 struct wined3d_event_query
*event_query
= wined3d_event_query_from_query(query
);
1040 wined3d_fence_free(&event_query
->fence
);
1041 heap_free(event_query
);
1044 static const struct wined3d_query_ops event_query_ops
=
1046 wined3d_event_query_ops_poll
,
1047 wined3d_event_query_ops_issue
,
1048 wined3d_event_query_ops_destroy
,
1051 static HRESULT
wined3d_event_query_create(struct wined3d_device
*device
,
1052 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1053 struct wined3d_query
**query
)
1055 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1056 struct wined3d_event_query
*object
;
1059 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1060 device
, type
, parent
, parent_ops
, query
);
1062 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1063 return E_OUTOFMEMORY
;
1065 if (FAILED(hr
= wined3d_fence_init(&object
->fence
, gl_info
)))
1067 WARN("Event queries not supported.\n");
1072 wined3d_query_init(&object
->query
, device
, type
, &object
->signalled
,
1073 sizeof(object
->signalled
), &event_query_ops
, parent
, parent_ops
);
1075 TRACE("Created query %p.\n", object
);
1076 *query
= &object
->query
;
1081 static void wined3d_occlusion_query_ops_destroy(struct wined3d_query
*query
)
1083 struct wined3d_occlusion_query
*oq
= wined3d_occlusion_query_from_query(query
);
1086 wined3d_context_gl_free_occlusion_query(oq
);
1090 static const struct wined3d_query_ops occlusion_query_ops
=
1092 wined3d_occlusion_query_ops_poll
,
1093 wined3d_occlusion_query_ops_issue
,
1094 wined3d_occlusion_query_ops_destroy
,
1097 static HRESULT
wined3d_occlusion_query_create(struct wined3d_device
*device
,
1098 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1099 struct wined3d_query
**query
)
1101 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1102 struct wined3d_occlusion_query
*object
;
1104 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1105 device
, type
, parent
, parent_ops
, query
);
1107 if (!gl_info
->supported
[ARB_OCCLUSION_QUERY
])
1109 WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
1110 return WINED3DERR_NOTAVAILABLE
;
1113 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1114 return E_OUTOFMEMORY
;
1116 wined3d_query_init(&object
->query
, device
, type
, &object
->samples
,
1117 sizeof(object
->samples
), &occlusion_query_ops
, parent
, parent_ops
);
1119 TRACE("Created query %p.\n", object
);
1120 *query
= &object
->query
;
1125 static void wined3d_timestamp_query_ops_destroy(struct wined3d_query
*query
)
1127 struct wined3d_timestamp_query
*tq
= wined3d_timestamp_query_from_query(query
);
1130 wined3d_context_gl_free_timestamp_query(tq
);
1134 static const struct wined3d_query_ops timestamp_query_ops
=
1136 wined3d_timestamp_query_ops_poll
,
1137 wined3d_timestamp_query_ops_issue
,
1138 wined3d_timestamp_query_ops_destroy
,
1141 static HRESULT
wined3d_timestamp_query_create(struct wined3d_device
*device
,
1142 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1143 struct wined3d_query
**query
)
1145 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1146 struct wined3d_timestamp_query
*object
;
1148 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1149 device
, type
, parent
, parent_ops
, query
);
1151 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
1153 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
1154 return WINED3DERR_NOTAVAILABLE
;
1157 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1158 return E_OUTOFMEMORY
;
1160 wined3d_query_init(&object
->query
, device
, type
, &object
->timestamp
,
1161 sizeof(object
->timestamp
), ×tamp_query_ops
, parent
, parent_ops
);
1163 TRACE("Created query %p.\n", object
);
1164 *query
= &object
->query
;
1169 static void wined3d_timestamp_disjoint_query_ops_destroy(struct wined3d_query
*query
)
1174 static const struct wined3d_query_ops timestamp_disjoint_query_ops
=
1176 wined3d_timestamp_disjoint_query_ops_poll
,
1177 wined3d_timestamp_disjoint_query_ops_issue
,
1178 wined3d_timestamp_disjoint_query_ops_destroy
,
1181 static HRESULT
wined3d_timestamp_disjoint_query_create(struct wined3d_device
*device
,
1182 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1183 struct wined3d_query
**query
)
1185 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1186 struct wined3d_query
*object
;
1188 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1189 device
, type
, parent
, parent_ops
, query
);
1191 if (!gl_info
->supported
[ARB_TIMER_QUERY
])
1193 WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
1194 return WINED3DERR_NOTAVAILABLE
;
1197 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1198 return E_OUTOFMEMORY
;
1200 if (type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
)
1202 static const struct wined3d_query_data_timestamp_disjoint disjoint_data
= {1000 * 1000 * 1000, FALSE
};
1204 wined3d_query_init(object
, device
, type
, &disjoint_data
,
1205 sizeof(disjoint_data
), ×tamp_disjoint_query_ops
, parent
, parent_ops
);
1209 static const UINT64 freq
= 1000 * 1000 * 1000;
1211 wined3d_query_init(object
, device
, type
, &freq
,
1212 sizeof(freq
), ×tamp_disjoint_query_ops
, parent
, parent_ops
);
1215 TRACE("Created query %p.\n", object
);
1221 static void wined3d_so_statistics_query_ops_destroy(struct wined3d_query
*query
)
1223 struct wined3d_so_statistics_query
*pq
= wined3d_so_statistics_query_from_query(query
);
1226 wined3d_context_gl_free_so_statistics_query(pq
);
1230 static const struct wined3d_query_ops so_statistics_query_ops
=
1232 wined3d_so_statistics_query_ops_poll
,
1233 wined3d_so_statistics_query_ops_issue
,
1234 wined3d_so_statistics_query_ops_destroy
,
1237 static HRESULT
wined3d_so_statistics_query_create(struct wined3d_device
*device
,
1238 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1239 struct wined3d_query
**query
)
1241 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1242 struct wined3d_so_statistics_query
*object
;
1243 unsigned int stream_idx
;
1245 if (WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
<= type
&& type
<= WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
)
1246 stream_idx
= type
- WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
;
1247 else if (type
== WINED3D_QUERY_TYPE_SO_STATISTICS
)
1250 return WINED3DERR_NOTAVAILABLE
;
1252 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1253 device
, type
, parent
, parent_ops
, query
);
1255 if (!gl_info
->supported
[WINED3D_GL_PRIMITIVE_QUERY
])
1257 WARN("OpenGL implementation does not support primitive queries.\n");
1258 return WINED3DERR_NOTAVAILABLE
;
1260 if (stream_idx
&& !gl_info
->supported
[ARB_TRANSFORM_FEEDBACK3
])
1262 WARN("OpenGL implementation does not support indexed queries.\n");
1263 return WINED3DERR_NOTAVAILABLE
;
1266 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1267 return E_OUTOFMEMORY
;
1269 wined3d_query_init(&object
->query
, device
, type
, &object
->statistics
,
1270 sizeof(object
->statistics
), &so_statistics_query_ops
, parent
, parent_ops
);
1271 object
->stream_idx
= stream_idx
;
1273 TRACE("Created query %p.\n", object
);
1274 *query
= &object
->query
;
1279 static void wined3d_pipeline_query_ops_destroy(struct wined3d_query
*query
)
1281 struct wined3d_pipeline_statistics_query
*pq
= wined3d_pipeline_statistics_query_from_query(query
);
1283 wined3d_context_gl_free_pipeline_statistics_query(pq
);
1287 static const struct wined3d_query_ops pipeline_query_ops
=
1289 wined3d_pipeline_query_ops_poll
,
1290 wined3d_pipeline_query_ops_issue
,
1291 wined3d_pipeline_query_ops_destroy
,
1294 static HRESULT
wined3d_pipeline_query_create(struct wined3d_device
*device
,
1295 enum wined3d_query_type type
, void *parent
, const struct wined3d_parent_ops
*parent_ops
,
1296 struct wined3d_query
**query
)
1298 const struct wined3d_gl_info
*gl_info
= &device
->adapter
->gl_info
;
1299 struct wined3d_pipeline_statistics_query
*object
;
1301 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1302 device
, type
, parent
, parent_ops
, query
);
1304 if (!gl_info
->supported
[ARB_PIPELINE_STATISTICS_QUERY
])
1306 WARN("OpenGL implementation does not support pipeline statistics queries.\n");
1307 return WINED3DERR_NOTAVAILABLE
;
1310 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1311 return E_OUTOFMEMORY
;
1313 wined3d_query_init(&object
->query
, device
, type
, &object
->statistics
,
1314 sizeof(object
->statistics
), &pipeline_query_ops
, parent
, parent_ops
);
1316 TRACE("Created query %p.\n", object
);
1317 *query
= &object
->query
;
1322 HRESULT
wined3d_query_gl_create(struct wined3d_device
*device
, enum wined3d_query_type type
,
1323 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_query
**query
)
1325 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1326 device
, type
, parent
, parent_ops
, query
);
1330 case WINED3D_QUERY_TYPE_EVENT
:
1331 return wined3d_event_query_create(device
, type
, parent
, parent_ops
, query
);
1333 case WINED3D_QUERY_TYPE_OCCLUSION
:
1334 return wined3d_occlusion_query_create(device
, type
, parent
, parent_ops
, query
);
1336 case WINED3D_QUERY_TYPE_TIMESTAMP
:
1337 return wined3d_timestamp_query_create(device
, type
, parent
, parent_ops
, query
);
1339 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
:
1340 case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ
:
1341 return wined3d_timestamp_disjoint_query_create(device
, type
, parent
, parent_ops
, query
);
1343 case WINED3D_QUERY_TYPE_SO_STATISTICS
:
1344 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
:
1345 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
:
1346 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM2
:
1347 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
:
1348 return wined3d_so_statistics_query_create(device
, type
, parent
, parent_ops
, query
);
1350 case WINED3D_QUERY_TYPE_PIPELINE_STATISTICS
:
1351 return wined3d_pipeline_query_create(device
, type
, parent
, parent_ops
, query
);
1354 FIXME("Unhandled query type %#x.\n", type
);
1355 return WINED3DERR_NOTAVAILABLE
;
1359 void wined3d_query_pool_vk_free_query(struct wined3d_query_pool_vk
*pool_vk
, size_t idx
)
1361 wined3d_bitmap_clear(pool_vk
->allocated
, idx
);
1363 if (list_empty(&pool_vk
->entry
))
1364 list_add_tail(pool_vk
->free_list
, &pool_vk
->entry
);
1367 bool wined3d_query_pool_vk_allocate_query(struct wined3d_query_pool_vk
*pool_vk
, size_t *idx
)
1369 if ((*idx
= wined3d_bitmap_ffz(pool_vk
->allocated
, WINED3D_QUERY_POOL_SIZE
, 0)) > WINED3D_QUERY_POOL_SIZE
)
1371 wined3d_bitmap_set(pool_vk
->allocated
, *idx
);
1376 void wined3d_query_pool_vk_cleanup(struct wined3d_query_pool_vk
*pool_vk
, struct wined3d_context_vk
*context_vk
)
1378 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(context_vk
->c
.device
);
1379 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1381 VK_CALL(vkDestroyQueryPool(device_vk
->vk_device
, pool_vk
->vk_query_pool
, NULL
));
1382 list_remove(&pool_vk
->entry
);
1385 bool wined3d_query_pool_vk_init(struct wined3d_query_pool_vk
*pool_vk
,
1386 struct wined3d_context_vk
*context_vk
, enum wined3d_query_type type
, struct list
*free_pools
)
1388 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(context_vk
->c
.device
);
1389 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1390 VkQueryPoolCreateInfo pool_info
;
1393 list_init(&pool_vk
->entry
);
1394 pool_vk
->free_list
= free_pools
;
1396 pool_info
.sType
= VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
;
1397 pool_info
.pNext
= NULL
;
1398 pool_info
.flags
= 0;
1399 pool_info
.queryCount
= WINED3D_QUERY_POOL_SIZE
;
1403 case WINED3D_QUERY_TYPE_OCCLUSION
:
1404 pool_info
.queryType
= VK_QUERY_TYPE_OCCLUSION
;
1405 pool_info
.pipelineStatistics
= 0;
1408 case WINED3D_QUERY_TYPE_TIMESTAMP
:
1409 pool_info
.queryType
= VK_QUERY_TYPE_TIMESTAMP
;
1410 pool_info
.pipelineStatistics
= 0;
1413 case WINED3D_QUERY_TYPE_PIPELINE_STATISTICS
:
1414 pool_info
.queryType
= VK_QUERY_TYPE_PIPELINE_STATISTICS
;
1415 pool_info
.pipelineStatistics
= VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT
1416 | VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT
1417 | VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT
1418 | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT
1419 | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT
1420 | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT
1421 | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT
1422 | VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT
1423 | VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT
1424 | VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT
1425 | VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT
;
1428 case WINED3D_QUERY_TYPE_SO_STATISTICS
:
1429 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
:
1430 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
:
1431 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM2
:
1432 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
:
1433 pool_info
.queryType
= VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT
;
1434 pool_info
.pipelineStatistics
= 0;
1438 FIXME("Unhandled query type %#x.\n", type
);
1442 if ((vr
= VK_CALL(vkCreateQueryPool(device_vk
->vk_device
, &pool_info
, NULL
, &pool_vk
->vk_query_pool
))) < 0)
1444 ERR("Failed to create Vulkan query pool, vr %s.\n", wined3d_debug_vkresult(vr
));
1448 list_add_head(free_pools
, &pool_vk
->entry
);
1453 bool wined3d_query_vk_accumulate_data(struct wined3d_query_vk
*query_vk
,
1454 struct wined3d_context_vk
*context_vk
, const struct wined3d_query_pool_idx_vk
*pool_idx
)
1456 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(context_vk
->c
.device
);
1457 const struct wined3d_query_data_pipeline_statistics
*ps_tmp
;
1458 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1459 struct wined3d_query_data_pipeline_statistics
*ps_result
;
1465 struct wined3d_query_data_pipeline_statistics pipeline_statistics
;
1466 struct wined3d_query_data_so_statistics so_statistics
;
1469 if ((vr
= VK_CALL(vkGetQueryPoolResults(device_vk
->vk_device
, pool_idx
->pool_vk
->vk_query_pool
,
1470 pool_idx
->idx
, 1, sizeof(tmp
), &tmp
, sizeof(tmp
), VK_QUERY_RESULT_64_BIT
))) < 0)
1472 ERR("Failed to get query results, vr %s.\n", wined3d_debug_vkresult(vr
));
1476 if (vr
== VK_NOT_READY
)
1479 result
= (void *)query_vk
->q
.data
;
1480 switch (query_vk
->q
.type
)
1482 case WINED3D_QUERY_TYPE_OCCLUSION
:
1483 result
->occlusion
+= tmp
.occlusion
;
1486 case WINED3D_QUERY_TYPE_TIMESTAMP
:
1487 result
->timestamp
= tmp
.timestamp
;
1490 case WINED3D_QUERY_TYPE_PIPELINE_STATISTICS
:
1491 ps_result
= &result
->pipeline_statistics
;
1492 ps_tmp
= &tmp
.pipeline_statistics
;
1493 ps_result
->vertices_submitted
+= ps_tmp
->vertices_submitted
;
1494 ps_result
->primitives_submitted
+= ps_tmp
->primitives_submitted
;
1495 ps_result
->vs_invocations
+= ps_tmp
->vs_invocations
;
1496 ps_result
->gs_invocations
+= ps_tmp
->gs_invocations
;
1497 ps_result
->gs_primitives
+= ps_tmp
->gs_primitives
;
1498 ps_result
->clipping_input_primitives
+= ps_tmp
->clipping_input_primitives
;
1499 ps_result
->clipping_output_primitives
+= ps_tmp
->clipping_output_primitives
;
1500 ps_result
->ps_invocations
+= ps_tmp
->ps_invocations
;
1501 ps_result
->hs_invocations
+= ps_tmp
->hs_invocations
;
1502 ps_result
->ds_invocations
+= ps_tmp
->ds_invocations
;
1503 ps_result
->cs_invocations
+= ps_tmp
->cs_invocations
;
1506 case WINED3D_QUERY_TYPE_SO_STATISTICS
:
1507 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
:
1508 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
:
1509 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM2
:
1510 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
:
1511 result
->so_statistics
.primitives_written
+= tmp
.so_statistics
.primitives_written
;
1512 result
->so_statistics
.primitives_generated
+= tmp
.so_statistics
.primitives_generated
;
1516 FIXME("Unhandled query type %#x.\n", query_vk
->q
.type
);
1523 static void wined3d_query_vk_begin(struct wined3d_query_vk
*query_vk
,
1524 struct wined3d_context_vk
*context_vk
, VkCommandBuffer vk_command_buffer
)
1526 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1527 struct wined3d_query_pool_vk
*pool_vk
;
1530 if (!query_vk
->pool_idx
.pool_vk
1531 && !wined3d_context_vk_allocate_query(context_vk
, query_vk
->q
.type
, &query_vk
->pool_idx
))
1533 ERR("Failed to allocate new query.\n");
1536 pool_vk
= query_vk
->pool_idx
.pool_vk
;
1537 idx
= query_vk
->pool_idx
.idx
;
1539 VK_CALL(vkCmdResetQueryPool(vk_command_buffer
, pool_vk
->vk_query_pool
, idx
, 1));
1540 if (query_vk
->q
.type
>= WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
1541 && query_vk
->q
.type
<= WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
)
1542 VK_CALL(vkCmdBeginQueryIndexedEXT(vk_command_buffer
, pool_vk
->vk_query_pool
, idx
,
1543 query_vk
->control_flags
, query_vk
->q
.type
- WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
));
1545 VK_CALL(vkCmdBeginQuery(vk_command_buffer
, pool_vk
->vk_query_pool
, idx
, query_vk
->control_flags
));
1546 wined3d_context_vk_reference_query(context_vk
, query_vk
);
1549 static void wined3d_query_vk_end(struct wined3d_query_vk
*query_vk
,
1550 struct wined3d_context_vk
*context_vk
, VkCommandBuffer vk_command_buffer
)
1552 const struct wined3d_vk_info
*vk_info
= context_vk
->vk_info
;
1553 struct wined3d_query_pool_vk
*pool_vk
;
1556 pool_vk
= query_vk
->pool_idx
.pool_vk
;
1557 idx
= query_vk
->pool_idx
.idx
;
1559 if (query_vk
->q
.type
>= WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
1560 && query_vk
->q
.type
<= WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
)
1561 VK_CALL(vkCmdEndQueryIndexedEXT(vk_command_buffer
, pool_vk
->vk_query_pool
,
1562 idx
, query_vk
->q
.type
- WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
));
1564 VK_CALL(vkCmdEndQuery(vk_command_buffer
, pool_vk
->vk_query_pool
, idx
));
1567 void wined3d_query_vk_resume(struct wined3d_query_vk
*query_vk
, struct wined3d_context_vk
*context_vk
)
1569 VkCommandBuffer vk_command_buffer
= context_vk
->current_command_buffer
.vk_command_buffer
;
1571 wined3d_query_vk_begin(query_vk
, context_vk
, vk_command_buffer
);
1574 void wined3d_query_vk_suspend(struct wined3d_query_vk
*query_vk
, struct wined3d_context_vk
*context_vk
)
1576 VkCommandBuffer vk_command_buffer
= context_vk
->current_command_buffer
.vk_command_buffer
;
1578 wined3d_query_vk_end(query_vk
, context_vk
, vk_command_buffer
);
1579 wined3d_context_vk_add_pending_query(context_vk
, query_vk
);
1580 query_vk
->pool_idx
.pool_vk
= NULL
;
1583 static BOOL
wined3d_query_vk_poll(struct wined3d_query
*query
, uint32_t flags
)
1585 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1586 struct wined3d_context_vk
*context_vk
;
1588 context_vk
= wined3d_context_vk(context_acquire(query
->device
, NULL
, 0));
1590 if (flags
& WINED3DGETDATA_FLUSH
)
1591 wined3d_context_vk_submit_command_buffer(context_vk
, 0, NULL
, NULL
, 0, NULL
);
1592 if (query_vk
->command_buffer_id
== context_vk
->current_command_buffer
.id
)
1595 if (query_vk
->command_buffer_id
> context_vk
->completed_command_buffer_id
)
1596 wined3d_context_vk_poll_command_buffers(context_vk
);
1597 if (query_vk
->command_buffer_id
> context_vk
->completed_command_buffer_id
)
1600 if (query_vk
->pending_count
)
1601 wined3d_context_vk_accumulate_pending_queries(context_vk
);
1602 if (query_vk
->pending_count
)
1605 /* If the query was suspended, and then ended before it was resumed,
1606 * there's no data to accumulate here. */
1607 if (query_vk
->pool_idx
.pool_vk
&& !wined3d_query_vk_accumulate_data(query_vk
, context_vk
, &query_vk
->pool_idx
))
1610 context_release(&context_vk
->c
);
1615 context_release(&context_vk
->c
);
1619 static BOOL
wined3d_query_vk_issue(struct wined3d_query
*query
, uint32_t flags
)
1621 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(query
->device
);
1622 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1623 struct wined3d_context_vk
*context_vk
;
1624 VkCommandBuffer vk_command_buffer
;
1627 TRACE("query %p, flags %#x.\n", query
, flags
);
1629 if (flags
& WINED3DISSUE_BEGIN
)
1631 context_vk
= wined3d_context_vk(context_acquire(&device_vk
->d
, NULL
, 0));
1633 wined3d_context_vk_end_current_render_pass(context_vk
);
1634 list_remove(&query_vk
->entry
);
1635 if (query_vk
->pending_count
)
1636 wined3d_context_vk_remove_pending_queries(context_vk
, query_vk
);
1637 memset((void *)query
->data
, 0, query
->data_size
);
1638 vk_command_buffer
= wined3d_context_vk_get_command_buffer(context_vk
);
1639 if (query_vk
->started
)
1641 wined3d_query_vk_end(query_vk
, context_vk
, vk_command_buffer
);
1642 list_remove(&query_vk
->entry
);
1644 wined3d_query_vk_begin(query_vk
, context_vk
, vk_command_buffer
);
1645 list_add_head(&context_vk
->active_queries
, &query_vk
->entry
);
1646 query_vk
->started
= true;
1648 context_release(&context_vk
->c
);
1650 if (flags
& WINED3DISSUE_END
&& query_vk
->started
)
1652 context_vk
= wined3d_context_vk(context_acquire(&device_vk
->d
, NULL
, 0));
1654 /* If the query was already ended because the command buffer was
1655 * flushed, we don't need to end it here. */
1656 if ((vk_command_buffer
= context_vk
->current_command_buffer
.vk_command_buffer
))
1657 wined3d_query_vk_end(query_vk
, context_vk
, vk_command_buffer
);
1658 list_remove(&query_vk
->entry
);
1659 query_vk
->started
= false;
1662 context_release(&context_vk
->c
);
1668 static void wined3d_query_vk_destroy(struct wined3d_query
*query
)
1670 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1671 struct wined3d_context_vk
*context_vk
;
1673 list_remove(&query_vk
->entry
);
1674 if (query_vk
->pending_count
)
1676 context_vk
= wined3d_context_vk(context_acquire(query_vk
->q
.device
, NULL
, 0));
1677 wined3d_context_vk_remove_pending_queries(context_vk
, query_vk
);
1678 context_release(&context_vk
->c
);
1680 if (query_vk
->pool_idx
.pool_vk
)
1681 wined3d_query_pool_vk_free_query(query_vk
->pool_idx
.pool_vk
, query_vk
->pool_idx
.idx
);
1682 heap_free(query_vk
);
1685 static const struct wined3d_query_ops wined3d_query_vk_ops
=
1687 .query_poll
= wined3d_query_vk_poll
,
1688 .query_issue
= wined3d_query_vk_issue
,
1689 .query_destroy
= wined3d_query_vk_destroy
,
1692 static BOOL
wined3d_query_event_vk_poll(struct wined3d_query
*query
, uint32_t flags
)
1694 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1695 struct wined3d_context_vk
*context_vk
;
1698 context_vk
= wined3d_context_vk(context_acquire(query
->device
, NULL
, 0));
1700 signalled
= (BOOL
*)query
->data
;
1701 if (flags
& WINED3DGETDATA_FLUSH
)
1702 wined3d_context_vk_submit_command_buffer(context_vk
, 0, NULL
, NULL
, 0, NULL
);
1703 if (query_vk
->command_buffer_id
== context_vk
->current_command_buffer
.id
)
1705 context_release(&context_vk
->c
);
1706 return *signalled
= FALSE
;
1709 if (query_vk
->command_buffer_id
> context_vk
->completed_command_buffer_id
)
1710 wined3d_context_vk_poll_command_buffers(context_vk
);
1711 *signalled
= context_vk
->completed_command_buffer_id
>= query_vk
->command_buffer_id
;
1713 context_release(&context_vk
->c
);
1718 static BOOL
wined3d_query_event_vk_issue(struct wined3d_query
*query
, uint32_t flags
)
1720 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(query
->device
);
1721 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1722 struct wined3d_context_vk
*context_vk
;
1724 TRACE("query %p, flags %#x.\n", query
, flags
);
1726 if (flags
& WINED3DISSUE_END
)
1728 context_vk
= wined3d_context_vk(context_acquire(&device_vk
->d
, NULL
, 0));
1729 wined3d_context_vk_reference_query(context_vk
, query_vk
);
1730 /* Because we don't actually submit any commands to the command buffer
1731 * for event queries, the context's current command buffer may still
1732 * be empty, and we should wait on the preceding command buffer
1733 * instead. That's not merely an optimisation; if the command buffer
1734 * referenced by the query is still empty by the time the application
1735 * waits for it, that wait will never complete. */
1736 if (!context_vk
->current_command_buffer
.vk_command_buffer
)
1737 --query_vk
->command_buffer_id
;
1738 context_release(&context_vk
->c
);
1746 static const struct wined3d_query_ops wined3d_query_event_vk_ops
=
1748 .query_poll
= wined3d_query_event_vk_poll
,
1749 .query_issue
= wined3d_query_event_vk_issue
,
1750 .query_destroy
= wined3d_query_vk_destroy
,
1753 static BOOL
wined3d_query_timestamp_vk_issue(struct wined3d_query
*query
, uint32_t flags
)
1755 struct wined3d_device_vk
*device_vk
= wined3d_device_vk(query
->device
);
1756 struct wined3d_query_vk
*query_vk
= wined3d_query_vk(query
);
1757 const struct wined3d_vk_info
*vk_info
;
1758 struct wined3d_context_vk
*context_vk
;
1759 VkCommandBuffer command_buffer
;
1761 TRACE("query %p, flags %#x.\n", query
, flags
);
1763 if (flags
& WINED3DISSUE_BEGIN
)
1764 TRACE("Ignoring WINED3DISSUE_BEGIN.\n");
1766 if (flags
& WINED3DISSUE_END
)
1768 context_vk
= wined3d_context_vk(context_acquire(&device_vk
->d
, NULL
, 0));
1769 vk_info
= context_vk
->vk_info
;
1771 wined3d_context_vk_end_current_render_pass(context_vk
);
1772 command_buffer
= wined3d_context_vk_get_command_buffer(context_vk
);
1773 if (!query_vk
->pool_idx
.pool_vk
)
1774 wined3d_context_vk_allocate_query(context_vk
, query_vk
->q
.type
, &query_vk
->pool_idx
);
1775 VK_CALL(vkCmdResetQueryPool(command_buffer
, query_vk
->pool_idx
.pool_vk
->vk_query_pool
,
1776 query_vk
->pool_idx
.idx
, 1));
1777 VK_CALL(vkCmdWriteTimestamp(command_buffer
, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
,
1778 query_vk
->pool_idx
.pool_vk
->vk_query_pool
, query_vk
->pool_idx
.idx
));
1779 wined3d_context_vk_reference_query(context_vk
, query_vk
);
1781 context_release(&context_vk
->c
);
1789 static const struct wined3d_query_ops wined3d_query_timestamp_vk_ops
=
1791 .query_poll
= wined3d_query_vk_poll
,
1792 .query_issue
= wined3d_query_timestamp_vk_issue
,
1793 .query_destroy
= wined3d_query_vk_destroy
,
1796 static const struct wined3d_query_ops wined3d_query_timestamp_disjoint_vk_ops
=
1798 .query_poll
= wined3d_timestamp_disjoint_query_ops_poll
,
1799 .query_issue
= wined3d_timestamp_disjoint_query_ops_issue
,
1800 .query_destroy
= wined3d_query_vk_destroy
,
1803 HRESULT
wined3d_query_vk_create(struct wined3d_device
*device
, enum wined3d_query_type type
,
1804 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_query
**query
)
1806 struct wined3d_query_data_timestamp_disjoint
*disjoint_data
;
1807 const struct wined3d_query_ops
*ops
= &wined3d_query_vk_ops
;
1808 struct wined3d_query_vk
*query_vk
;
1809 unsigned int data_size
;
1812 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1813 device
, type
, parent
, parent_ops
, query
);
1817 case WINED3D_QUERY_TYPE_EVENT
:
1818 ops
= &wined3d_query_event_vk_ops
;
1819 data_size
= sizeof(BOOL
);
1822 case WINED3D_QUERY_TYPE_OCCLUSION
:
1823 data_size
= sizeof(uint64_t);
1826 case WINED3D_QUERY_TYPE_TIMESTAMP
:
1827 if (!wined3d_device_vk(device
)->timestamp_bits
)
1829 WARN("Timestamp queries not supported.\n");
1830 return WINED3DERR_NOTAVAILABLE
;
1832 ops
= &wined3d_query_timestamp_vk_ops
;
1833 data_size
= sizeof(uint64_t);
1836 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
:
1837 if (!wined3d_device_vk(device
)->timestamp_bits
)
1839 WARN("Timestamp queries not supported.\n");
1840 return WINED3DERR_NOTAVAILABLE
;
1842 ops
= &wined3d_query_timestamp_disjoint_vk_ops
;
1843 data_size
= sizeof(struct wined3d_query_data_timestamp_disjoint
);
1846 case WINED3D_QUERY_TYPE_PIPELINE_STATISTICS
:
1847 data_size
= sizeof(struct wined3d_query_data_pipeline_statistics
);
1850 case WINED3D_QUERY_TYPE_SO_STATISTICS
:
1851 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM0
:
1852 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM1
:
1853 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM2
:
1854 case WINED3D_QUERY_TYPE_SO_STATISTICS_STREAM3
:
1855 if (!wined3d_adapter_vk(device
->adapter
)->vk_info
.supported
[WINED3D_VK_EXT_TRANSFORM_FEEDBACK
])
1857 WARN("Stream output queries not supported.\n");
1858 return WINED3DERR_NOTAVAILABLE
;
1860 data_size
= sizeof(struct wined3d_query_data_so_statistics
);
1864 FIXME("Unhandled query type %#x.\n", type
);
1865 return WINED3DERR_NOTAVAILABLE
;
1868 if (!(query_vk
= heap_alloc_zero(sizeof(*query_vk
) + data_size
)))
1869 return E_OUTOFMEMORY
;
1870 data
= query_vk
+ 1;
1872 wined3d_query_init(&query_vk
->q
, device
, type
, data
, data_size
, ops
, parent
, parent_ops
);
1873 list_init(&query_vk
->entry
);
1877 case WINED3D_QUERY_TYPE_OCCLUSION
:
1878 query_vk
->control_flags
= VK_QUERY_CONTROL_PRECISE_BIT
;
1881 case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
:
1882 disjoint_data
= data
;
1883 disjoint_data
->frequency
= 1000000000 / wined3d_adapter_vk(device
->adapter
)->device_limits
.timestampPeriod
;
1884 disjoint_data
->disjoint
= FALSE
;
1891 TRACE("Created query %p.\n", query_vk
);
1892 *query
= &query_vk
->q
;
1897 HRESULT CDECL
wined3d_query_create(struct wined3d_device
*device
, enum wined3d_query_type type
,
1898 void *parent
, const struct wined3d_parent_ops
*parent_ops
, struct wined3d_query
**query
)
1900 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
1901 device
, type
, parent
, parent_ops
, query
);
1903 return device
->adapter
->adapter_ops
->adapter_create_query(device
, type
, parent
, parent_ops
, query
);