2005-03-03 14:57:15 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2010-11-18 20:50:40 +01:00
|
|
|
* Copyright 2009-2010 Henri Verbeet for CodeWeavers.
|
2005-03-03 14:57:15 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-03 14:57:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2005-03-03 14:57:15 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2010-03-03 22:45:34 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2010-03-30 11:24:43 +02:00
|
|
|
BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info)
|
2010-03-03 23:48:50 +01:00
|
|
|
{
|
2010-03-30 11:24:43 +02:00
|
|
|
return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
|
2010-03-03 23:48:50 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 13:26:36 +01:00
|
|
|
void wined3d_event_query_destroy(struct wined3d_event_query *query)
|
2010-03-03 23:48:50 +01:00
|
|
|
{
|
|
|
|
if (query->context) context_free_event_query(query);
|
|
|
|
HeapFree(GetProcessHeap(), 0, query);
|
|
|
|
}
|
|
|
|
|
2011-07-19 12:56:14 +02:00
|
|
|
static enum wined3d_event_query_result wined3d_event_query_test(const struct wined3d_event_query *query,
|
2011-10-27 17:06:27 +02:00
|
|
|
const struct wined3d_device *device)
|
2010-03-03 22:45:34 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
enum wined3d_event_query_result ret;
|
|
|
|
BOOL fence_result;
|
|
|
|
|
|
|
|
TRACE("(%p) : device %p\n", query, device);
|
|
|
|
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!query->context)
|
2010-03-03 22:45:34 +01:00
|
|
|
{
|
|
|
|
TRACE("Query not started\n");
|
|
|
|
return WINED3D_EVENT_QUERY_NOT_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
WARN("Event query tested from wrong thread\n");
|
|
|
|
return WINED3D_EVENT_QUERY_WRONG_THREAD;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(query->context));
|
2010-03-03 22:45:34 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, 0));
|
|
|
|
checkGLcall("glClientWaitSync");
|
|
|
|
|
|
|
|
switch (gl_ret)
|
|
|
|
{
|
|
|
|
case GL_ALREADY_SIGNALED:
|
|
|
|
case GL_CONDITION_SATISFIED:
|
|
|
|
ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TIMEOUT_EXPIRED:
|
|
|
|
ret = WINED3D_EVENT_QUERY_WAITING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_WAIT_FAILED:
|
|
|
|
default:
|
|
|
|
ERR("glClientWaitSync returned %#x.\n", gl_ret);
|
|
|
|
ret = WINED3D_EVENT_QUERY_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
fence_result = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
|
|
|
|
checkGLcall("glTestFenceAPPLE");
|
|
|
|
if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
else ret = WINED3D_EVENT_QUERY_WAITING;
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_FENCE])
|
|
|
|
{
|
|
|
|
fence_result = GL_EXTCALL(glTestFenceNV(query->object.id));
|
|
|
|
checkGLcall("glTestFenceNV");
|
|
|
|
if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
else ret = WINED3D_EVENT_QUERY_WAITING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-03 23:48:50 +01:00
|
|
|
ERR("Event query created despite lack of GL support\n");
|
|
|
|
ret = WINED3D_EVENT_QUERY_ERROR;
|
2010-03-03 22:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-19 12:56:15 +02:00
|
|
|
enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query,
|
2011-10-30 18:06:35 +01:00
|
|
|
const struct wined3d_device *device)
|
2010-03-21 13:26:36 +01:00
|
|
|
{
|
|
|
|
struct wined3d_context *context;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
enum wined3d_event_query_result ret;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("query %p, device %p.\n", query, device);
|
2010-03-21 13:26:36 +01:00
|
|
|
|
|
|
|
if (!query->context)
|
|
|
|
{
|
|
|
|
TRACE("Query not started\n");
|
|
|
|
return WINED3D_EVENT_QUERY_NOT_STARTED;
|
|
|
|
}
|
|
|
|
gl_info = query->context->gl_info;
|
|
|
|
|
|
|
|
if (query->context->tid != GetCurrentThreadId() && !gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
/* A glFinish does not reliably wait for draws in other contexts. The caller has
|
|
|
|
* to find its own way to cope with the thread switch
|
|
|
|
*/
|
|
|
|
WARN("Event query finished from wrong thread\n");
|
|
|
|
return WINED3D_EVENT_QUERY_WRONG_THREAD;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(query->context));
|
2010-03-21 13:26:36 +01:00
|
|
|
|
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
2012-08-20 08:12:08 +02:00
|
|
|
/* Apple seems to be into arbitrary limits, and timeouts larger than
|
|
|
|
* 0xfffffffffffffbff immediately return GL_TIMEOUT_EXPIRED. We don't
|
|
|
|
* really care and can live with waiting a few μs less. (OS X 10.7.4). */
|
|
|
|
GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, GL_SYNC_FLUSH_COMMANDS_BIT, ~(GLuint64)0xffff));
|
2010-03-21 13:26:36 +01:00
|
|
|
checkGLcall("glClientWaitSync");
|
|
|
|
|
|
|
|
switch (gl_ret)
|
|
|
|
{
|
|
|
|
case GL_ALREADY_SIGNALED:
|
|
|
|
case GL_CONDITION_SATISFIED:
|
|
|
|
ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* We don't expect a timeout for a ~584 year wait */
|
|
|
|
default:
|
|
|
|
ERR("glClientWaitSync returned %#x.\n", gl_ret);
|
|
|
|
ret = WINED3D_EVENT_QUERY_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (context->gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glFinishFenceAPPLE(query->object.id));
|
|
|
|
checkGLcall("glFinishFenceAPPLE");
|
|
|
|
ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
}
|
|
|
|
else if (context->gl_info->supported[NV_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glFinishFenceNV(query->object.id));
|
|
|
|
checkGLcall("glFinishFenceNV");
|
|
|
|
ret = WINED3D_EVENT_QUERY_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Event query created without GL support\n");
|
|
|
|
ret = WINED3D_EVENT_QUERY_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-30 18:06:36 +01:00
|
|
|
void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device)
|
2010-03-03 23:18:37 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
if (query->context)
|
|
|
|
{
|
|
|
|
if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
context_free_event_query(query);
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-03-03 23:18:37 +01:00
|
|
|
context_alloc_event_query(context, query);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(query->context));
|
2010-03-03 23:18:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2010-03-03 23:18:37 +01:00
|
|
|
context_alloc_event_query(context, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
|
|
|
|
checkGLcall("glDeleteSync");
|
|
|
|
query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
|
|
|
|
checkGLcall("glFenceSync");
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glSetFenceAPPLE(query->object.id));
|
|
|
|
checkGLcall("glSetFenceAPPLE");
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[NV_FENCE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
|
|
|
|
checkGLcall("glSetFenceNV");
|
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
ULONG CDECL wined3d_query_incref(struct wined3d_query *query)
|
2005-03-03 14:57:15 +01:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&query->ref);
|
2010-08-31 18:41:38 +02:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", query, refcount);
|
2010-08-31 18:41:38 +02:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
return refcount;
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
|
|
|
|
{
|
2011-04-13 19:14:34 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&query->ref);
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", query, refcount);
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
if (!refcount)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2009-01-07 09:00:55 +01:00
|
|
|
/* Queries are specific to the GL context that created them. Not
|
|
|
|
* deleting the query will obviously leak it, but that's still better
|
|
|
|
* than potentially deleting a different query with the same id in this
|
|
|
|
* context, and (still) leaking the actual query. */
|
2012-01-17 21:13:38 +01:00
|
|
|
if (query->type == WINED3D_QUERY_TYPE_EVENT)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
struct wined3d_event_query *event_query = query->extendedData;
|
|
|
|
if (event_query) wined3d_event_query_destroy(event_query);
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
2012-01-17 21:13:38 +01:00
|
|
|
else if (query->type == WINED3D_QUERY_TYPE_OCCLUSION)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
struct wined3d_occlusion_query *oq = query->extendedData;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
if (oq->context) context_free_occlusion_query(oq);
|
|
|
|
HeapFree(GetProcessHeap(), 0, query->extendedData);
|
2007-03-01 00:34:33 +01:00
|
|
|
}
|
2014-04-16 18:14:48 +02:00
|
|
|
else if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP)
|
|
|
|
{
|
|
|
|
struct wined3d_timestamp_query *tq = query->extendedData;
|
|
|
|
|
|
|
|
if (tq->context)
|
|
|
|
context_free_timestamp_query(tq);
|
|
|
|
HeapFree(GetProcessHeap(), 0, query->extendedData);
|
|
|
|
}
|
2007-03-01 00:34:33 +01:00
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, query);
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
2011-02-03 20:14:06 +01:00
|
|
|
|
|
|
|
return refcount;
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
HRESULT CDECL wined3d_query_get_data(struct wined3d_query *query,
|
|
|
|
void *data, UINT data_size, DWORD flags)
|
2011-02-03 20:14:05 +01:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
TRACE("query %p, data %p, data_size %u, flags %#x.\n",
|
|
|
|
query, data, data_size, flags);
|
2011-02-03 20:14:05 +01:00
|
|
|
|
|
|
|
return query->query_ops->query_get_data(query, data, data_size, flags);
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
UINT CDECL wined3d_query_get_data_size(const struct wined3d_query *query)
|
2011-02-03 20:14:05 +01:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
TRACE("query %p.\n", query);
|
2011-02-03 20:14:05 +01:00
|
|
|
|
|
|
|
return query->data_size;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
HRESULT CDECL wined3d_query_issue(struct wined3d_query *query, DWORD flags)
|
2011-02-03 20:14:05 +01:00
|
|
|
{
|
2011-02-03 20:14:06 +01:00
|
|
|
TRACE("query %p, flags %#x.\n", query, flags);
|
2011-02-03 20:14:05 +01:00
|
|
|
|
|
|
|
return query->query_ops->query_issue(query, flags);
|
|
|
|
}
|
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
static void fill_query_data(void *out, unsigned int out_size, const void *result, unsigned int result_size)
|
|
|
|
{
|
|
|
|
memcpy(out, result, min(out_size, result_size));
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
static HRESULT wined3d_occlusion_query_ops_get_data(struct wined3d_query *query,
|
2014-06-13 15:08:51 +02:00
|
|
|
void *data, DWORD size, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
struct wined3d_occlusion_query *oq = query->extendedData;
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = query->device;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2009-01-07 09:00:55 +01:00
|
|
|
GLuint available;
|
|
|
|
GLuint samples;
|
2008-02-28 21:03:41 +01:00
|
|
|
HRESULT res;
|
2009-01-07 09:00:55 +01:00
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
|
2008-02-28 21:03:41 +01:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
if (!oq->context)
|
|
|
|
query->state = QUERY_CREATED;
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
if (query->state == QUERY_CREATED)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2008-02-28 21:03:41 +01:00
|
|
|
/* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
|
|
|
|
TRACE("Query wasn't yet started, returning S_OK\n");
|
2014-06-13 15:08:51 +02:00
|
|
|
samples = 0;
|
|
|
|
fill_query_data(data, size, &samples, sizeof(samples));
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
if (query->state == QUERY_BUILDING)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2008-02-28 21:03:41 +01:00
|
|
|
/* Msdn says this returns an error, but our tests show that S_FALSE is returned */
|
|
|
|
TRACE("Query is building, returning S_FALSE\n");
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_FALSE;
|
2009-01-07 09:00:55 +01:00
|
|
|
}
|
2009-01-07 09:00:55 +01:00
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (!gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
WARN("%p Occlusion queries not supported. Returning 1.\n", query);
|
2014-06-13 15:08:51 +02:00
|
|
|
samples = 1;
|
|
|
|
fill_query_data(data, size, &samples, sizeof(samples));
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
if (oq->context->tid != GetCurrentThreadId())
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
FIXME("%p Wrong thread, returning 1.\n", query);
|
2014-06-13 15:08:51 +02:00
|
|
|
samples = 1;
|
|
|
|
fill_query_data(data, size, &samples, sizeof(samples));
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(oq->context));
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT_AVAILABLE, &available));
|
|
|
|
checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
|
2011-02-03 20:14:05 +01:00
|
|
|
TRACE("available %#x.\n", available);
|
2009-01-07 09:00:55 +01:00
|
|
|
|
|
|
|
if (available)
|
|
|
|
{
|
2014-06-13 15:08:51 +02:00
|
|
|
if (size)
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGetQueryObjectuiv(oq->id, GL_QUERY_RESULT, &samples));
|
|
|
|
checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT)");
|
2011-02-03 20:14:05 +01:00
|
|
|
TRACE("Returning %d samples.\n", samples);
|
2014-06-13 15:08:51 +02:00
|
|
|
fill_query_data(data, size, &samples, sizeof(samples));
|
2009-01-07 09:00:55 +01:00
|
|
|
}
|
2008-02-28 21:03:41 +01:00
|
|
|
res = S_OK;
|
|
|
|
}
|
2009-01-07 09:00:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
res = S_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:07 +01:00
|
|
|
static HRESULT wined3d_event_query_ops_get_data(struct wined3d_query *query,
|
2014-06-13 15:08:51 +02:00
|
|
|
void *data, DWORD size, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
struct wined3d_event_query *event_query = query->extendedData;
|
2014-06-13 15:08:51 +02:00
|
|
|
BOOL signaled;
|
2010-03-03 22:45:34 +01:00
|
|
|
enum wined3d_event_query_result ret;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
|
2008-02-28 21:02:58 +01:00
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
if (!data || !size) return S_OK;
|
2011-02-03 20:14:05 +01:00
|
|
|
if (!event_query)
|
2010-03-03 23:48:50 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
WARN("Event query not supported by GL, reporting GPU idle.\n");
|
2014-06-13 15:08:51 +02:00
|
|
|
signaled = TRUE;
|
|
|
|
fill_query_data(data, size, &signaled, sizeof(signaled));
|
2010-03-03 23:48:50 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2009-06-26 10:07:08 +02:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
ret = wined3d_event_query_test(event_query, query->device);
|
2010-03-03 22:45:34 +01:00
|
|
|
switch(ret)
|
2009-08-11 09:42:12 +02:00
|
|
|
{
|
2010-03-03 22:45:34 +01:00
|
|
|
case WINED3D_EVENT_QUERY_OK:
|
|
|
|
case WINED3D_EVENT_QUERY_NOT_STARTED:
|
2014-06-13 15:08:51 +02:00
|
|
|
signaled = TRUE;
|
|
|
|
fill_query_data(data, size, &signaled, sizeof(signaled));
|
2010-03-03 22:45:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_EVENT_QUERY_WAITING:
|
2014-06-13 15:08:51 +02:00
|
|
|
signaled = FALSE;
|
|
|
|
fill_query_data(data, size, &signaled, sizeof(signaled));
|
2010-03-03 22:45:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_EVENT_QUERY_WRONG_THREAD:
|
2011-02-03 20:14:05 +01:00
|
|
|
FIXME("(%p) Wrong thread, reporting GPU idle.\n", query);
|
2014-06-13 15:08:51 +02:00
|
|
|
signaled = TRUE;
|
|
|
|
fill_query_data(data, size, &signaled, sizeof(signaled));
|
2010-03-03 22:45:34 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_EVENT_QUERY_ERROR:
|
|
|
|
ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2014-09-19 10:41:47 +02:00
|
|
|
void * CDECL wined3d_query_get_parent(const struct wined3d_query *query)
|
|
|
|
{
|
|
|
|
TRACE("query %p.\n", query);
|
|
|
|
|
|
|
|
return query->parent;
|
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:38 +01:00
|
|
|
enum wined3d_query_type CDECL wined3d_query_get_type(const struct wined3d_query *query)
|
2011-02-03 20:14:06 +01:00
|
|
|
{
|
|
|
|
TRACE("query %p.\n", query);
|
|
|
|
|
|
|
|
return query->type;
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
static HRESULT wined3d_event_query_ops_issue(struct wined3d_query *query, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
TRACE("query %p, flags %#x.\n", query, flags);
|
2008-02-28 21:02:58 +01:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
TRACE("(%p) : flags %#x, type D3DQUERY_EVENT\n", query, flags);
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DISSUE_END)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
struct wined3d_event_query *event_query = query->extendedData;
|
2010-03-03 23:48:50 +01:00
|
|
|
|
|
|
|
/* Faked event query support */
|
2011-02-03 20:14:05 +01:00
|
|
|
if (!event_query) return WINED3D_OK;
|
2010-03-03 23:48:50 +01:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
wined3d_event_query_issue(event_query, query->device);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
2010-11-18 20:50:40 +01:00
|
|
|
else if (flags & WINED3DISSUE_BEGIN)
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2008-02-28 21:02:58 +01:00
|
|
|
/* Started implicitly at device creation */
|
|
|
|
ERR("Event query issued with START flag - what to do?\n");
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DISSUE_BEGIN)
|
2011-02-03 20:14:05 +01:00
|
|
|
query->state = QUERY_BUILDING;
|
2010-11-18 20:50:40 +01:00
|
|
|
else
|
2011-02-03 20:14:05 +01:00
|
|
|
query->state = QUERY_SIGNALLED;
|
2008-02-28 21:02:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:06 +01:00
|
|
|
static HRESULT wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = query->device;
|
2009-10-29 10:37:11 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2006-07-25 00:51:33 +02:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
TRACE("query %p, flags %#x.\n", query, flags);
|
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
struct wined3d_occlusion_query *oq = query->extendedData;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2008-02-28 21:03:41 +01:00
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
/* This is allowed according to msdn and our tests. Reset the query and restart */
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DISSUE_BEGIN)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
if (query->state == QUERY_BUILDING)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
if (oq->context->tid != GetCurrentThreadId())
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
|
|
|
FIXME("Wrong thread, can't restart query.\n");
|
2009-06-26 10:07:08 +02:00
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
context_free_occlusion_query(oq);
|
|
|
|
context = context_acquire(query->device, NULL);
|
|
|
|
context_alloc_occlusion_query(context, oq);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(oq->context));
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
|
2008-02-28 21:03:41 +01:00
|
|
|
checkGLcall("glEndQuery()");
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 10:44:13 +02:00
|
|
|
else
|
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
if (oq->context) context_free_occlusion_query(oq);
|
|
|
|
context = context_acquire(query->device, NULL);
|
|
|
|
context_alloc_occlusion_query(context, oq);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glBeginQuery(GL_SAMPLES_PASSED, oq->id));
|
2009-07-24 10:44:13 +02:00
|
|
|
checkGLcall("glBeginQuery()");
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DISSUE_END)
|
|
|
|
{
|
2009-07-24 10:44:13 +02:00
|
|
|
/* Msdn says _END on a non-building occlusion query returns an error, but
|
|
|
|
* our tests show that it returns OK. But OpenGL doesn't like it, so avoid
|
|
|
|
* generating an error
|
|
|
|
*/
|
2011-02-03 20:14:05 +01:00
|
|
|
if (query->state == QUERY_BUILDING)
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
if (oq->context->tid != GetCurrentThreadId())
|
2009-07-24 10:44:13 +02:00
|
|
|
{
|
|
|
|
FIXME("Wrong thread, can't end query.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(oq->context));
|
2009-07-24 10:44:13 +02:00
|
|
|
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glEndQuery(GL_SAMPLES_PASSED));
|
2008-02-28 21:03:41 +01:00
|
|
|
checkGLcall("glEndQuery()");
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2006-07-25 00:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-28 21:03:41 +01:00
|
|
|
}
|
2011-02-03 20:14:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("%p Occlusion queries not supported.\n", query);
|
2008-02-28 21:03:41 +01:00
|
|
|
}
|
2006-07-25 00:51:33 +02:00
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DISSUE_BEGIN)
|
2011-02-03 20:14:05 +01:00
|
|
|
query->state = QUERY_BUILDING;
|
2010-11-18 20:50:40 +01:00
|
|
|
else
|
2011-02-03 20:14:05 +01:00
|
|
|
query->state = QUERY_SIGNALLED;
|
2010-11-18 20:50:40 +01:00
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
|
|
|
|
}
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
static HRESULT wined3d_timestamp_query_ops_get_data(struct wined3d_query *query,
|
|
|
|
void *data, DWORD size, DWORD flags)
|
|
|
|
{
|
|
|
|
struct wined3d_timestamp_query *tq = query->extendedData;
|
|
|
|
struct wined3d_device *device = query->device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
GLuint available;
|
|
|
|
GLuint64 timestamp;
|
|
|
|
HRESULT res;
|
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
|
2014-04-16 18:14:48 +02:00
|
|
|
|
|
|
|
if (!tq->context)
|
|
|
|
query->state = QUERY_CREATED;
|
|
|
|
|
|
|
|
if (query->state == QUERY_CREATED)
|
|
|
|
{
|
|
|
|
/* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves. */
|
|
|
|
TRACE("Query wasn't yet started, returning S_OK.\n");
|
2014-06-13 15:08:51 +02:00
|
|
|
timestamp = 0;
|
|
|
|
fill_query_data(data, size, ×tamp, sizeof(timestamp));
|
2014-04-16 18:14:48 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tq->context->tid != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
FIXME("%p Wrong thread, returning 1.\n", query);
|
2014-06-13 15:08:51 +02:00
|
|
|
timestamp = 1;
|
|
|
|
fill_query_data(data, size, ×tamp, sizeof(timestamp));
|
2014-04-16 18:14:48 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:32 +02:00
|
|
|
context = context_acquire(device, context_get_rt_surface(tq->context));
|
2014-04-16 18:14:48 +02:00
|
|
|
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGetQueryObjectuiv(tq->id, GL_QUERY_RESULT_AVAILABLE, &available));
|
|
|
|
checkGLcall("glGetQueryObjectuiv(GL_QUERY_RESULT_AVAILABLE)");
|
2014-04-16 18:14:48 +02:00
|
|
|
TRACE("available %#x.\n", available);
|
|
|
|
|
|
|
|
if (available)
|
|
|
|
{
|
2014-06-13 15:08:51 +02:00
|
|
|
if (size)
|
2014-04-16 18:14:48 +02:00
|
|
|
{
|
2015-01-29 18:45:04 +01:00
|
|
|
GL_EXTCALL(glGetQueryObjectui64v(tq->id, GL_QUERY_RESULT, ×tamp));
|
|
|
|
checkGLcall("glGetQueryObjectui64v(GL_QUERY_RESULT)");
|
2014-04-16 18:14:48 +02:00
|
|
|
TRACE("Returning timestamp %s.\n", wine_dbgstr_longlong(timestamp));
|
2014-06-13 15:08:51 +02:00
|
|
|
fill_query_data(data, size, ×tamp, sizeof(timestamp));
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
res = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT wined3d_timestamp_query_ops_issue(struct wined3d_query *query, DWORD flags)
|
|
|
|
{
|
|
|
|
struct wined3d_device *device = query->device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
|
|
|
TRACE("query %p, flags %#x.\n", query, flags);
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_TIMER_QUERY])
|
|
|
|
{
|
|
|
|
struct wined3d_timestamp_query *tq = query->extendedData;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
if (flags & WINED3DISSUE_BEGIN)
|
|
|
|
{
|
|
|
|
WARN("Ignoring WINED3DISSUE_BEGIN with a TIMESTAMP query.\n");
|
|
|
|
}
|
|
|
|
if (flags & WINED3DISSUE_END)
|
|
|
|
{
|
|
|
|
if (tq->context)
|
|
|
|
context_free_timestamp_query(tq);
|
|
|
|
context = context_acquire(query->device, NULL);
|
|
|
|
context_alloc_timestamp_query(context, tq);
|
|
|
|
GL_EXTCALL(glQueryCounter(tq->id, GL_TIMESTAMP));
|
|
|
|
checkGLcall("glQueryCounter()");
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Timestamp queries not supported.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3DISSUE_END)
|
|
|
|
query->state = QUERY_SIGNALLED;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT wined3d_timestamp_disjoint_query_ops_get_data(struct wined3d_query *query,
|
|
|
|
void *data, DWORD size, DWORD flags)
|
|
|
|
{
|
2014-06-13 15:08:51 +02:00
|
|
|
TRACE("query %p, data %p, size %#x, flags %#x.\n", query, data, size, flags);
|
2014-04-16 18:14:48 +02:00
|
|
|
|
|
|
|
if (query->type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
|
|
|
|
{
|
2015-05-04 23:16:15 +02:00
|
|
|
static const struct wined3d_query_data_timestamp_disjoint disjoint_data = {1000 * 1000 * 1000, FALSE};
|
2014-04-16 18:14:48 +02:00
|
|
|
|
|
|
|
if (query->state == QUERY_BUILDING)
|
|
|
|
{
|
|
|
|
TRACE("Query is building, returning S_FALSE.\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
fill_query_data(data, size, &disjoint_data, sizeof(disjoint_data));
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-13 15:08:51 +02:00
|
|
|
static const UINT64 freq = 1000 * 1000 * 1000;
|
2014-04-16 18:14:48 +02:00
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
fill_query_data(data, size, &freq, sizeof(freq));
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT wined3d_timestamp_disjoint_query_ops_issue(struct wined3d_query *query, DWORD flags)
|
|
|
|
{
|
|
|
|
TRACE("query %p, flags %#x.\n", query, flags);
|
|
|
|
|
|
|
|
if (flags & WINED3DISSUE_BEGIN)
|
|
|
|
query->state = QUERY_BUILDING;
|
|
|
|
if (flags & WINED3DISSUE_END)
|
|
|
|
query->state = QUERY_SIGNALLED;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-02-03 20:14:05 +01:00
|
|
|
static const struct wined3d_query_ops event_query_ops =
|
2008-02-28 21:02:58 +01:00
|
|
|
{
|
2011-02-03 20:14:05 +01:00
|
|
|
wined3d_event_query_ops_get_data,
|
|
|
|
wined3d_event_query_ops_issue,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct wined3d_query_ops occlusion_query_ops =
|
|
|
|
{
|
|
|
|
wined3d_occlusion_query_ops_get_data,
|
|
|
|
wined3d_occlusion_query_ops_issue,
|
2008-02-28 21:02:58 +01:00
|
|
|
};
|
2008-02-28 21:03:41 +01:00
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
static const struct wined3d_query_ops timestamp_query_ops =
|
|
|
|
{
|
|
|
|
wined3d_timestamp_query_ops_get_data,
|
|
|
|
wined3d_timestamp_query_ops_issue,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct wined3d_query_ops timestamp_disjoint_query_ops =
|
|
|
|
{
|
|
|
|
wined3d_timestamp_disjoint_query_ops_get_data,
|
|
|
|
wined3d_timestamp_disjoint_query_ops_issue,
|
|
|
|
};
|
|
|
|
|
2014-09-19 10:41:47 +02:00
|
|
|
static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device,
|
|
|
|
enum wined3d_query_type type, void *parent)
|
2010-01-17 21:31:30 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
2014-09-19 10:41:47 +02:00
|
|
|
query->parent = parent;
|
|
|
|
|
2010-01-17 21:31:30 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
2012-01-17 21:13:38 +01:00
|
|
|
case WINED3D_QUERY_TYPE_OCCLUSION:
|
2010-01-17 21:31:30 +01:00
|
|
|
TRACE("Occlusion query.\n");
|
|
|
|
if (!gl_info->supported[ARB_OCCLUSION_QUERY])
|
|
|
|
{
|
2010-01-21 10:38:31 +01:00
|
|
|
WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
|
2010-01-17 21:31:30 +01:00
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
2011-02-03 20:14:05 +01:00
|
|
|
query->query_ops = &occlusion_query_ops;
|
|
|
|
query->data_size = sizeof(DWORD);
|
2010-01-17 21:31:30 +01:00
|
|
|
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
|
|
|
|
if (!query->extendedData)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate occlusion query extended data.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
((struct wined3d_occlusion_query *)query->extendedData)->context = NULL;
|
|
|
|
break;
|
|
|
|
|
2012-01-17 21:13:38 +01:00
|
|
|
case WINED3D_QUERY_TYPE_EVENT:
|
2010-01-17 21:31:30 +01:00
|
|
|
TRACE("Event query.\n");
|
2010-03-30 11:24:43 +02:00
|
|
|
if (!wined3d_event_query_supported(gl_info))
|
2010-01-17 21:31:30 +01:00
|
|
|
{
|
|
|
|
/* Half-Life 2 needs this query. It does not render the main
|
|
|
|
* menu correctly otherwise. Pretend to support it, faking
|
|
|
|
* this query does not do much harm except potentially
|
|
|
|
* lowering performance. */
|
|
|
|
FIXME("Event query: Unimplemented, but pretending to be supported.\n");
|
|
|
|
}
|
2011-02-03 20:14:05 +01:00
|
|
|
query->query_ops = &event_query_ops;
|
|
|
|
query->data_size = sizeof(BOOL);
|
2010-03-30 11:24:43 +02:00
|
|
|
query->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_event_query));
|
|
|
|
if (!query->extendedData)
|
2010-01-17 21:31:30 +01:00
|
|
|
{
|
2010-03-30 11:24:43 +02:00
|
|
|
ERR("Failed to allocate event query memory.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2010-01-17 21:31:30 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-17 21:13:38 +01:00
|
|
|
case WINED3D_QUERY_TYPE_TIMESTAMP:
|
2014-04-16 18:14:48 +02:00
|
|
|
TRACE("Timestamp query.\n");
|
|
|
|
if (!gl_info->supported[ARB_TIMER_QUERY])
|
|
|
|
{
|
|
|
|
WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
query->query_ops = ×tamp_query_ops;
|
|
|
|
query->data_size = sizeof(UINT64);
|
|
|
|
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_timestamp_query));
|
|
|
|
if (!query->extendedData)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate timestamp query extended data.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
((struct wined3d_timestamp_query *)query->extendedData)->context = NULL;
|
|
|
|
break;
|
|
|
|
|
2012-01-17 21:13:38 +01:00
|
|
|
case WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT:
|
|
|
|
case WINED3D_QUERY_TYPE_TIMESTAMP_FREQ:
|
2014-04-16 18:14:48 +02:00
|
|
|
TRACE("TIMESTAMP_DISJOINT query.\n");
|
|
|
|
if (!gl_info->supported[ARB_TIMER_QUERY])
|
|
|
|
{
|
|
|
|
WARN("Unsupported in local OpenGL implementation: ARB_TIMER_QUERY.\n");
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
query->query_ops = ×tamp_disjoint_query_ops;
|
|
|
|
query->data_size = type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
|
|
|
|
? sizeof(struct wined3d_query_data_timestamp_disjoint) : sizeof(UINT64);
|
|
|
|
query->extendedData = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_QUERY_TYPE_VCACHE:
|
|
|
|
case WINED3D_QUERY_TYPE_RESOURCE_MANAGER:
|
|
|
|
case WINED3D_QUERY_TYPE_VERTEX_STATS:
|
2012-01-17 21:13:38 +01:00
|
|
|
case WINED3D_QUERY_TYPE_PIPELINE_TIMINGS:
|
|
|
|
case WINED3D_QUERY_TYPE_INTERFACE_TIMINGS:
|
|
|
|
case WINED3D_QUERY_TYPE_VERTEX_TIMINGS:
|
|
|
|
case WINED3D_QUERY_TYPE_PIXEL_TIMINGS:
|
|
|
|
case WINED3D_QUERY_TYPE_BANDWIDTH_TIMINGS:
|
|
|
|
case WINED3D_QUERY_TYPE_CACHE_UTILIZATION:
|
2010-01-17 21:31:30 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled query type %#x.\n", type);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
query->type = type;
|
|
|
|
query->state = QUERY_CREATED;
|
|
|
|
query->device = device;
|
|
|
|
query->ref = 1;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_query_create(struct wined3d_device *device,
|
2014-09-19 10:41:47 +02:00
|
|
|
enum wined3d_query_type type, void *parent, struct wined3d_query **query)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_query *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("device %p, type %#x, parent %p, query %p.\n", device, type, parent, query);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2014-09-19 10:41:47 +02:00
|
|
|
if (FAILED(hr = query_init(object, device, type, parent)))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize query, hr %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created query %p.\n", object);
|
|
|
|
*query = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|