query.c revision fc50d11e45d83ecb4fbb2a6761d1adb5d6cc268f
/*
* IWineD3DQuery implementation
*
* Copyright 2005 Oliver Stieber
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
* Copyright 2009 Henri Verbeet for CodeWeavers.
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include "wined3d_private.h"
#define GLINFO_LOCATION (*gl_info)
{
return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
}
{
}
enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
{
struct wined3d_context *context;
const struct wined3d_gl_info *gl_info;
{
TRACE("Query not started\n");
return WINED3D_EVENT_QUERY_NOT_STARTED;
}
#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
{
WARN("Event query tested from wrong thread\n");
return WINED3D_EVENT_QUERY_WRONG_THREAD;
}
#endif
ENTER_GL();
{
checkGLcall("glClientWaitSync");
switch (gl_ret)
{
case GL_ALREADY_SIGNALED:
case GL_CONDITION_SATISFIED:
break;
case GL_TIMEOUT_EXPIRED:
break;
case GL_WAIT_FAILED:
default:
}
}
{
checkGLcall("glTestFenceAPPLE");
else ret = WINED3D_EVENT_QUERY_WAITING;
}
{
checkGLcall("glTestFenceNV");
else ret = WINED3D_EVENT_QUERY_WAITING;
}
else
{
#ifdef VBOX_WITH_WDDM
Assert(0);
/* doing Flush (rather than Finish) should be enough since we're serialized on the host in any way */
wglFlush();
#else
ERR("Event query created despite lack of GL support\n");
#endif
}
LEAVE_GL();
return ret;
}
enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
{
struct wined3d_context *context;
const struct wined3d_gl_info *gl_info;
{
TRACE("Query not started\n");
return WINED3D_EVENT_QUERY_NOT_STARTED;
}
{
/* 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
*/
ERR("Event query finished from wrong thread\n");
#else
WARN("Event query finished from wrong thread\n");
#endif
return WINED3D_EVENT_QUERY_WRONG_THREAD;
}
ENTER_GL();
{
checkGLcall("glClientWaitSync");
switch (gl_ret)
{
case GL_ALREADY_SIGNALED:
case GL_CONDITION_SATISFIED:
break;
/* We don't expect a timeout for a ~584 year wait */
default:
}
}
{
checkGLcall("glFinishFenceAPPLE");
}
{
checkGLcall("glFinishFenceNV");
}
else
{
ERR("Event query created without GL support\n");
}
LEAVE_GL();
return ret;
}
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
{
{
ERR("unexpected\n");
#endif
}
else
{
}
}
else
{
}
ENTER_GL();
{
checkGLcall("glDeleteSync");
checkGLcall("glFenceSync");
}
{
checkGLcall("glSetFenceAPPLE");
}
{
checkGLcall("glSetFenceNV");
}
LEAVE_GL();
}
/*
* Occlusion Queries:
*/
/* *******************************************
IWineD3DQuery IUnknown parts follow
******************************************* */
static HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
{
return S_OK;
}
return E_NOINTERFACE;
}
}
if (ref == 0) {
/* 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. */
{
}
{
}
}
return ref;
}
/* *******************************************
IWineD3DQuery IWineD3DQuery parts follow
******************************************* */
{
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
struct wined3d_context *context;
TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
{
/* 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");
return S_OK;
}
{
/* Msdn says this returns an error, but our tests show that S_FALSE is returned */
TRACE("Query is building, returning S_FALSE\n");
return S_FALSE;
}
{
*data = 1;
return S_OK;
}
{
*data = 1;
return S_OK;
}
ENTER_GL();
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
if (available)
{
if (data)
{
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
}
}
else
{
}
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:
break;
break;
break;
ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
return S_OK;
}
return sizeof(BOOL);
}
return sizeof(DWORD);
}
}
if (dwIssueFlags & WINED3DISSUE_END)
{
/* Faked event query support */
if (!query) return WINED3D_OK;
}
else if(dwIssueFlags & WINED3DISSUE_BEGIN)
{
/* Started implicitly at device creation */
ERR("Event query issued with START flag - what to do?\n");
}
if(dwIssueFlags & WINED3DISSUE_BEGIN) {
} else {
}
return WINED3D_OK;
}
{
struct wined3d_context *context;
/* This is allowed according to msdn and our tests. Reset the query and restart */
if (dwIssueFlags & WINED3DISSUE_BEGIN)
{
{
{
FIXME("Wrong thread, can't restart query.\n");
}
else
{
ENTER_GL();
checkGLcall("glEndQuery()");
LEAVE_GL();
}
}
else
{
}
ENTER_GL();
checkGLcall("glBeginQuery()");
LEAVE_GL();
}
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
*/
{
{
FIXME("Wrong thread, can't end query.\n");
}
else
{
ENTER_GL();
checkGLcall("glEndQuery()");
LEAVE_GL();
}
}
}
} else {
}
if(dwIssueFlags & WINED3DISSUE_BEGIN) {
} else {
}
return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
}
static const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
{
/*** IUnknown methods ***/
/*** IWineD3Dquery methods ***/
};
static const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
{
/*** IUnknown methods ***/
/*** IWineD3Dquery methods ***/
};
{
switch (type)
{
TRACE("Occlusion query.\n");
{
WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
return WINED3DERR_NOTAVAILABLE;
}
if (!query->extendedData)
{
ERR("Failed to allocate occlusion query extended data.\n");
return E_OUTOFMEMORY;
}
break;
case WINED3DQUERYTYPE_EVENT:
TRACE("Event query.\n");
{
/* 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->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_event_query));
if (!query->extendedData)
{
ERR("Failed to allocate event query memory.\n");
return E_OUTOFMEMORY;
}
break;
case WINED3DQUERYTYPE_VCACHE:
default:
return WINED3DERR_NOTAVAILABLE;
}
return WINED3D_OK;
}