query.c revision 3c5c04d7b0973be0757addef8ba44b9352b38386
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * IWineD3DQuery implementation
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Copyright 2005 Oliver Stieber
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Copyright 2009 Henri Verbeet for CodeWeavers.
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * This library is free software; you can redistribute it and/or
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * modify it under the terms of the GNU Lesser General Public
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * License as published by the Free Software Foundation; either
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * version 2.1 of the License, or (at your option) any later version.
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * This library is distributed in the hope that it will be useful,
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Lesser General Public License for more details.
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * You should have received a copy of the GNU Lesser General Public
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * License along with this library; if not, write to the Free Software
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync * a choice of LGPL license versions is made available with the language indicating
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * of the LGPL is applied is otherwise unspecified.
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncBOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncvoid wined3d_event_query_destroy(struct wined3d_event_query *query)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (query->context) context_free_event_query(query);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncenum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, 0));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync fence_result = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync fence_result = GL_EXTCALL(glTestFenceNV(query->object.id));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync ERR("Event query created despite lack of GL support\n");
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncenum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (query->context->tid != GetCurrentThreadId() && !gl_info->supported[ARB_SYNC])
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync /* A glFinish does not reliably wait for draws in other contexts. The caller has
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * to find its own way to cope with the thread switch
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, ~(GLuint64)0));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync /* We don't expect a timeout for a ~584 year wait */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncvoid wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * Occlusion Queries:
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync/* *******************************************
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQuery IUnknown parts follow
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync ******************************************* */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncstatic ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncstatic ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync TRACE("(%p) : Releasing from %d\n", This, This->ref);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (ref == 0) {
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync /* Queries are specific to the GL context that created them. Not
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * deleting the query will obviously leak it, but that's still better
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * than potentially deleting a different query with the same id in this
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync * context, and (still) leaking the actual query. */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync struct wined3d_event_query *query = This->extendedData;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync struct wined3d_occlusion_query *query = This->extendedData;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync if (query->context) context_free_occlusion_query(query);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync/* *******************************************
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQuery IWineD3DQuery parts follow
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync ******************************************* */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown **parent)
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsyncstatic HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync struct wined3d_occlusion_query *query = This->extendedData;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync TRACE("Query wasn't yet started, returning S_OK\n");
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
caa941f0c7e5e632e27efc23a253533dd72148a5vboxsync context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
if (available)
if (data)
LEAVE_GL();
return res;
static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
if (!query)
return S_OK;
switch(ret)
case WINED3D_EVENT_QUERY_OK:
return WINED3DERR_INVALIDCALL;
return S_OK;
return sizeof(BOOL);
return sizeof(DWORD);
return WINED3D_OK;
ENTER_GL();
LEAVE_GL();
ENTER_GL();
LEAVE_GL();
ENTER_GL();
LEAVE_GL();
switch (type)
return WINED3DERR_NOTAVAILABLE;
return E_OUTOFMEMORY;
case WINED3DQUERYTYPE_EVENT:
query->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_event_query));
return E_OUTOFMEMORY;
case WINED3DQUERYTYPE_VCACHE:
return WINED3DERR_NOTAVAILABLE;
return WINED3D_OK;