query.c revision 4237d5a79f48789aacc67dc43378d2d7813a39f4
/*
* Copyright 2005 Oliver Stieber
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
* Copyright 2009-2010 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"
{
return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
}
{
}
static enum wined3d_event_query_result wined3d_event_query_test(const struct wined3d_event_query *query,
const struct wined3d_device *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
{
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
/* doing Flush (rather than Finish) should be enough since we're serialized on the host in any way */
#else
ERR("Event query created despite lack of GL support\n");
#endif
}
return ret;
}
const struct wined3d_device *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)
{
/* 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;
}
#endif
{
/* 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));
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");
}
return ret;
}
void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device)
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
{
#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
{
}
else
#endif
{
}
}
else
{
}
{
checkGLcall("glDeleteSync");
checkGLcall("glFenceSync");
}
{
checkGLcall("glSetFenceAPPLE");
}
{
checkGLcall("glSetFenceNV");
}
}
{
return refcount;
}
{
if (!refcount)
{
/* 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 refcount;
}
{
TRACE("query %p, data %p, data_size %u, flags %#x.\n",
}
{
}
{
}
{
struct wined3d_context *context;
TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, flags %#x.\n", query, pData, dwSize, flags);
{
/* 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;
}
#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
{
*data = 1;
return S_OK;
}
#endif
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
if (available)
{
if (data)
{
checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
}
}
else
{
}
return res;
}
{
if (!event_query)
{
WARN("Event query not supported by GL, reporting GPU idle.\n");
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;
}
{
}
{
if (flags & WINED3DISSUE_END)
{
/* Faked event query support */
if (!event_query) return WINED3D_OK;
}
else if (flags & WINED3DISSUE_BEGIN)
{
/* Started implicitly at device creation */
ERR("Event query issued with START flag - what to do?\n");
}
if (flags & 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 (flags & WINED3DISSUE_BEGIN)
{
{
#if !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
{
FIXME("Wrong thread, can't restart query.\n");
}
else
#endif
{
checkGLcall("glEndQuery()");
}
}
else
{
}
checkGLcall("glBeginQuery()");
}
if (flags & 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 !defined(VBOX_WINE_WITH_SINGLE_CONTEXT) && !defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
{
FIXME("Wrong thread, can't end query.\n");
}
else
#endif
{
checkGLcall("glEndQuery()");
}
}
}
}
else
{
}
if (flags & WINED3DISSUE_BEGIN)
else
return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
}
static const struct wined3d_query_ops event_query_ops =
{
};
static const struct wined3d_query_ops occlusion_query_ops =
{
};
static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device, enum wined3d_query_type type)
{
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 WINED3D_QUERY_TYPE_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;
default:
return WINED3DERR_NOTAVAILABLE;
}
return WINED3D_OK;
}
{
struct wined3d_query *object;
if (!object)
return E_OUTOFMEMORY;
{
return hr;
}
return WINED3D_OK;
}