2005-03-03 14:57:15 +01:00
|
|
|
/*
|
|
|
|
* IWineD3DQuery implementation
|
|
|
|
*
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2009-10-28 11:00:11 +01:00
|
|
|
* Copyright 2009 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"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
/*
|
2006-07-25 00:51:33 +02:00
|
|
|
* Occlusion Queries:
|
|
|
|
* http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
|
|
|
|
* http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
|
|
|
|
*/
|
2005-03-03 14:57:15 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2010-01-19 23:52:26 +01:00
|
|
|
#define GLINFO_LOCATION (*gl_info)
|
2005-03-03 14:57:15 +01:00
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
IWineD3DQuery IUnknown parts follow
|
|
|
|
******************************************* */
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
|
2005-03-03 14:57:15 +01:00
|
|
|
{
|
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2006-02-06 11:32:41 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
2005-03-03 14:57:15 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DQuery)) {
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*ppobj = This;
|
2006-04-25 23:59:12 +02:00
|
|
|
return S_OK;
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
2006-04-25 23:59:12 +02:00
|
|
|
*ppobj = NULL;
|
2005-03-03 14:57:15 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
|
2005-03-03 14:57:15 +01:00
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
|
2005-03-03 14:57:15 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
|
2005-03-03 14:57:15 +01:00
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
|
|
|
ULONG ref;
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p) : Releasing from %d\n", This, This->ref);
|
2005-03-03 14:57:15 +01:00
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0) {
|
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. */
|
2009-07-01 09:46:17 +02:00
|
|
|
if (This->type == WINED3DQUERYTYPE_EVENT)
|
|
|
|
{
|
2009-07-24 10:44:14 +02:00
|
|
|
struct wined3d_event_query *query = This->extendedData;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
if (query->context) context_free_event_query(query);
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
2009-07-24 10:44:13 +02:00
|
|
|
else if (This->type == WINED3DQUERYTYPE_OCCLUSION)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2009-07-24 10:44:13 +02:00
|
|
|
struct wined3d_occlusion_query *query = This->extendedData;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
if (query->context) context_free_occlusion_query(query);
|
2007-03-01 00:34:33 +01:00
|
|
|
}
|
|
|
|
|
2006-05-10 00:33:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->extendedData);
|
2005-03-03 14:57:15 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *******************************************
|
|
|
|
IWineD3DQuery IWineD3DQuery parts follow
|
|
|
|
******************************************* */
|
2009-12-21 23:17:26 +01:00
|
|
|
static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown **parent)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, parent %p.\n", iface, parent);
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2009-12-21 23:17:26 +01:00
|
|
|
*parent = (IUnknown *)parent;
|
2005-03-03 14:57:15 +01:00
|
|
|
IUnknown_AddRef(*parent);
|
2009-12-21 23:17:26 +01:00
|
|
|
|
|
|
|
TRACE("Returning %p.\n", *parent);
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-03-03 14:57:15 +01:00
|
|
|
}
|
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
static HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
|
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
|
2009-07-24 10:44:13 +02:00
|
|
|
struct wined3d_occlusion_query *query = This->extendedData;
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->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;
|
2008-02-28 21:03:41 +01:00
|
|
|
DWORD* data = pData;
|
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
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
if (!query->context) This->state = QUERY_CREATED;
|
|
|
|
|
2009-01-07 09:00:55 +01:00
|
|
|
if (This->state == QUERY_CREATED)
|
|
|
|
{
|
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");
|
|
|
|
if(data) *data = 0;
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->state == QUERY_BUILDING)
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
|
2008-02-28 21:03:41 +01:00
|
|
|
*data = 1;
|
2009-01-07 09:00:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
if (query->context->tid != GetCurrentThreadId())
|
2009-01-07 09:00:55 +01:00
|
|
|
{
|
2009-07-01 09:46:17 +02:00
|
|
|
FIXME("%p Wrong thread, returning 1.\n", This);
|
2009-01-07 09:00:55 +01:00
|
|
|
*data = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2009-01-07 09:00:55 +01:00
|
|
|
ENTER_GL();
|
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
|
2009-01-07 09:00:55 +01:00
|
|
|
TRACE("(%p) : available %d.\n", This, available);
|
|
|
|
|
|
|
|
if (available)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
2009-07-24 10:44:13 +02:00
|
|
|
GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_ARB, &samples));
|
2009-07-07 11:08:02 +02:00
|
|
|
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
|
2009-01-07 09:00:55 +01:00
|
|
|
TRACE("(%p) : Returning %d samples.\n", This, samples);
|
|
|
|
*data = samples;
|
|
|
|
}
|
2008-02-28 21:03:41 +01:00
|
|
|
res = S_OK;
|
|
|
|
}
|
2009-01-07 09:00:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
res = S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
|
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
|
2009-07-24 10:44:14 +02:00
|
|
|
struct wined3d_event_query *query = This->extendedData;
|
2010-01-19 23:52:26 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
BOOL *data = pData;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
|
|
|
|
|
2009-07-01 09:46:17 +02:00
|
|
|
if (!pData || !dwSize) return S_OK;
|
2009-06-26 10:07:08 +02:00
|
|
|
|
2009-08-11 09:42:12 +02:00
|
|
|
if (!query->context)
|
|
|
|
{
|
2009-12-16 19:55:56 +01:00
|
|
|
TRACE("Query not started, returning TRUE.\n");
|
2009-08-11 09:42:12 +02:00
|
|
|
*data = TRUE;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2008-02-28 21:02:58 +01:00
|
|
|
/* See comment in IWineD3DQuery::Issue, event query codeblock */
|
2009-07-01 09:46:17 +02:00
|
|
|
FIXME("Wrong thread, reporting GPU idle.\n");
|
2008-02-28 21:02:58 +01:00
|
|
|
*data = TRUE;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
2010-01-19 23:52:26 +01:00
|
|
|
gl_info = context->gl_info;
|
2009-07-01 09:46:17 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
if (gl_info->supported[ARB_SYNC])
|
|
|
|
{
|
|
|
|
GLenum ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, 0));
|
|
|
|
checkGLcall("glClientWaitSync");
|
|
|
|
|
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case GL_ALREADY_SIGNALED:
|
|
|
|
case GL_CONDITION_SATISFIED:
|
|
|
|
*data = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_TIMEOUT_EXPIRED:
|
|
|
|
*data = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_WAIT_FAILED:
|
|
|
|
default:
|
|
|
|
ERR("glClientWaitSync returned %#x.\n", ret);
|
|
|
|
*data = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gl_info->supported[APPLE_FENCE])
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
*data = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
|
2008-02-28 21:02:58 +01:00
|
|
|
checkGLcall("glTestFenceAPPLE");
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
2010-01-19 23:52:26 +01:00
|
|
|
else if (gl_info->supported[NV_FENCE])
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
*data = GL_EXTCALL(glTestFenceNV(query->object.id));
|
2008-02-28 21:02:58 +01:00
|
|
|
checkGLcall("glTestFenceNV");
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-28 21:02:58 +01:00
|
|
|
WARN("(%p): reporting GPU idle\n", This);
|
|
|
|
*data = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-01 09:46:17 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
static DWORD WINAPI IWineD3DEventQueryImpl_GetDataSize(IWineD3DQuery* iface){
|
|
|
|
TRACE("(%p) : type D3DQUERY_EVENT\n", iface);
|
|
|
|
|
|
|
|
return sizeof(BOOL);
|
|
|
|
}
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
static DWORD WINAPI IWineD3DOcclusionQueryImpl_GetDataSize(IWineD3DQuery* iface){
|
|
|
|
TRACE("(%p) : type D3DQUERY_OCCLUSION\n", iface);
|
|
|
|
|
|
|
|
return sizeof(DWORD);
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
|
2005-03-03 14:57:15 +01:00
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
|
|
|
return This->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 21:02:58 +01:00
|
|
|
static HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
|
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
|
|
|
|
|
|
|
TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
|
2009-07-01 09:46:17 +02:00
|
|
|
if (dwIssueFlags & WINED3DISSUE_END)
|
|
|
|
{
|
2009-07-24 10:44:14 +02:00
|
|
|
struct wined3d_event_query *query = This->extendedData;
|
2010-01-19 23:52:26 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-08-03 08:06:51 +02:00
|
|
|
struct wined3d_context *context;
|
2009-06-26 10:07:08 +02:00
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
if (query->context)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2009-07-24 10:44:14 +02:00
|
|
|
context_free_event_query(query);
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:14 +02:00
|
|
|
context_alloc_event_query(context, query);
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
2009-07-24 10:44:14 +02:00
|
|
|
else
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
2009-07-01 09:46:17 +02:00
|
|
|
}
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:14 +02:00
|
|
|
context_alloc_event_query(context, query);
|
|
|
|
}
|
|
|
|
|
2010-01-19 23:52:26 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2009-07-24 10:44:14 +02:00
|
|
|
ENTER_GL();
|
2009-07-01 09:46:17 +02:00
|
|
|
|
2010-01-25 19:51:30 +01:00
|
|
|
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])
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
GL_EXTCALL(glSetFenceAPPLE(query->object.id));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glSetFenceAPPLE");
|
|
|
|
}
|
2010-01-19 23:52:26 +01:00
|
|
|
else if (gl_info->supported[NV_FENCE])
|
2009-07-24 10:44:14 +02:00
|
|
|
{
|
2010-01-25 19:51:30 +01:00
|
|
|
GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
|
2009-07-24 10:44:14 +02:00
|
|
|
checkGLcall("glSetFenceNV");
|
2008-02-28 21:02:58 +01:00
|
|
|
}
|
2009-07-24 10:44:14 +02:00
|
|
|
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2009-07-24 10:44:14 +02:00
|
|
|
}
|
|
|
|
else if(dwIssueFlags & WINED3DISSUE_BEGIN)
|
|
|
|
{
|
2008-02-28 21:02:58 +01:00
|
|
|
/* Started implicitly at device creation */
|
|
|
|
ERR("Event query issued with START flag - what to do?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dwIssueFlags & WINED3DISSUE_BEGIN) {
|
|
|
|
This->state = QUERY_BUILDING;
|
|
|
|
} else {
|
|
|
|
This->state = QUERY_SIGNALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
|
2005-03-03 14:57:15 +01:00
|
|
|
IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->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
|
|
|
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2009-07-24 10:44:13 +02:00
|
|
|
struct wined3d_occlusion_query *query = This->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 */
|
|
|
|
if (dwIssueFlags & WINED3DISSUE_BEGIN)
|
2009-07-01 09:46:17 +02:00
|
|
|
{
|
2009-07-24 10:44:13 +02:00
|
|
|
if (This->state == QUERY_BUILDING)
|
|
|
|
{
|
|
|
|
if (query->context->tid != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
FIXME("Wrong thread, can't restart query.\n");
|
2009-06-26 10:07:08 +02:00
|
|
|
|
2009-07-24 10:44:13 +02:00
|
|
|
context_free_occlusion_query(query);
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:13 +02:00
|
|
|
context_alloc_occlusion_query(context, query);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:13 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
2008-02-28 21:03:41 +01:00
|
|
|
GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
|
|
|
|
checkGLcall("glEndQuery()");
|
2009-07-24 10:44:13 +02:00
|
|
|
LEAVE_GL();
|
2008-02-28 21:03:41 +01:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 10:44:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (query->context) context_free_occlusion_query(query);
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:13 +02:00
|
|
|
context_alloc_occlusion_query(context, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query->id));
|
|
|
|
checkGLcall("glBeginQuery()");
|
|
|
|
LEAVE_GL();
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
context_release(context);
|
2009-07-24 10:44:13 +02:00
|
|
|
}
|
|
|
|
if (dwIssueFlags & WINED3DISSUE_END) {
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
if (This->state == QUERY_BUILDING)
|
|
|
|
{
|
|
|
|
if (query->context->tid != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
FIXME("Wrong thread, can't end query.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
2009-07-24 10:44:13 +02:00
|
|
|
|
|
|
|
ENTER_GL();
|
2008-02-28 21:03:41 +01:00
|
|
|
GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
|
|
|
|
checkGLcall("glEndQuery()");
|
2009-07-24 10:44:13 +02:00
|
|
|
LEAVE_GL();
|
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
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FIXME("(%p) : Occlusion queries not supported\n", This);
|
|
|
|
}
|
2006-07-25 00:51:33 +02:00
|
|
|
|
2008-02-28 21:03:41 +01:00
|
|
|
if(dwIssueFlags & WINED3DISSUE_BEGIN) {
|
|
|
|
This->state = QUERY_BUILDING;
|
|
|
|
} else {
|
|
|
|
This->state = QUERY_SIGNALLED;
|
2006-07-25 00:51:33 +02:00
|
|
|
}
|
2008-02-28 21:03:41 +01:00
|
|
|
return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
|
|
|
|
}
|
|
|
|
|
2010-01-17 21:31:30 +01:00
|
|
|
static const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
|
2008-02-28 21:02:58 +01:00
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
IWineD3DQueryImpl_QueryInterface,
|
|
|
|
IWineD3DQueryImpl_AddRef,
|
|
|
|
IWineD3DQueryImpl_Release,
|
|
|
|
/*** IWineD3Dquery methods ***/
|
|
|
|
IWineD3DQueryImpl_GetParent,
|
|
|
|
IWineD3DEventQueryImpl_GetData,
|
|
|
|
IWineD3DEventQueryImpl_GetDataSize,
|
|
|
|
IWineD3DQueryImpl_GetType,
|
|
|
|
IWineD3DEventQueryImpl_Issue
|
|
|
|
};
|
2008-02-28 21:03:41 +01:00
|
|
|
|
2010-01-17 21:31:30 +01:00
|
|
|
static const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
|
2008-02-28 21:03:41 +01:00
|
|
|
{
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
IWineD3DQueryImpl_QueryInterface,
|
|
|
|
IWineD3DQueryImpl_AddRef,
|
|
|
|
IWineD3DQueryImpl_Release,
|
|
|
|
/*** IWineD3Dquery methods ***/
|
|
|
|
IWineD3DQueryImpl_GetParent,
|
|
|
|
IWineD3DOcclusionQueryImpl_GetData,
|
|
|
|
IWineD3DOcclusionQueryImpl_GetDataSize,
|
|
|
|
IWineD3DQueryImpl_GetType,
|
|
|
|
IWineD3DOcclusionQueryImpl_Issue
|
|
|
|
};
|
2010-01-17 21:31:30 +01:00
|
|
|
|
|
|
|
HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
|
|
|
|
WINED3DQUERYTYPE type, IUnknown *parent)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case WINED3DQUERYTYPE_OCCLUSION:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
query->lpVtbl = &IWineD3DOcclusionQuery_Vtbl;
|
|
|
|
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;
|
|
|
|
|
|
|
|
case WINED3DQUERYTYPE_EVENT:
|
|
|
|
TRACE("Event query.\n");
|
2010-01-25 19:51:30 +01:00
|
|
|
if (!gl_info->supported[ARB_SYNC] && !gl_info->supported[NV_FENCE]
|
|
|
|
&& !gl_info->supported[APPLE_FENCE])
|
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");
|
|
|
|
}
|
|
|
|
query->lpVtbl = &IWineD3DEventQuery_Vtbl;
|
|
|
|
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_event_query));
|
|
|
|
if (!query->extendedData)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate event query extended data.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
((struct wined3d_event_query *)query->extendedData)->context = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DQUERYTYPE_VCACHE:
|
|
|
|
case WINED3DQUERYTYPE_RESOURCEMANAGER:
|
|
|
|
case WINED3DQUERYTYPE_VERTEXSTATS:
|
|
|
|
case WINED3DQUERYTYPE_TIMESTAMP:
|
|
|
|
case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
|
|
|
|
case WINED3DQUERYTYPE_TIMESTAMPFREQ:
|
|
|
|
case WINED3DQUERYTYPE_PIPELINETIMINGS:
|
|
|
|
case WINED3DQUERYTYPE_INTERFACETIMINGS:
|
|
|
|
case WINED3DQUERYTYPE_VERTEXTIMINGS:
|
|
|
|
case WINED3DQUERYTYPE_PIXELTIMINGS:
|
|
|
|
case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
|
|
|
|
case WINED3DQUERYTYPE_CACHEUTILIZATION:
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled query type %#x.\n", type);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
query->type = type;
|
|
|
|
query->state = QUERY_CREATED;
|
|
|
|
query->device = device;
|
|
|
|
query->parent = parent;
|
|
|
|
query->ref = 1;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|