Commit bd0641d3 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Add wined3d_event_query_create and destroy.

This also moves the event query faking code back to the external interface and removes the temporary WINED3D_EVENT_QUERY_UNSUPPORTED return value since wined3d_event_query_create properly fails if no event query GL extension is supported.
parent 6863af3e
...@@ -27,6 +27,30 @@ ...@@ -27,6 +27,30 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DEFAULT_DEBUG_CHANNEL(d3d);
#define GLINFO_LOCATION (*gl_info) #define GLINFO_LOCATION (*gl_info)
static HRESULT wined3d_event_query_init(const struct wined3d_gl_info *gl_info, struct wined3d_event_query **query)
{
struct wined3d_event_query *ret;
*query = NULL;
if (!gl_info->supported[ARB_SYNC] && !gl_info->supported[NV_FENCE]
&& !gl_info->supported[APPLE_FENCE]) return E_NOTIMPL;
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(*ret));
if (!ret)
{
ERR("Failed to allocate a wined3d event query structure.\n");
return E_OUTOFMEMORY;
}
ret->context = NULL;
*query = ret;
return WINED3D_OK;
}
static void wined3d_event_query_destroy(struct wined3d_event_query *query)
{
if (query->context) context_free_event_query(query);
HeapFree(GetProcessHeap(), 0, query);
}
static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
{ {
struct wined3d_context *context; struct wined3d_context *context;
...@@ -91,7 +115,8 @@ static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_e ...@@ -91,7 +115,8 @@ static enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_e
} }
else else
{ {
ret = WINED3D_EVENT_QUERY_UNSUPPORTED; ERR("Event query created despite lack of GL support\n");
ret = WINED3D_EVENT_QUERY_ERROR;
} }
LEAVE_GL(); LEAVE_GL();
...@@ -194,17 +219,16 @@ static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) { ...@@ -194,17 +219,16 @@ static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
if (This->type == WINED3DQUERYTYPE_EVENT) if (This->type == WINED3DQUERYTYPE_EVENT)
{ {
struct wined3d_event_query *query = This->extendedData; struct wined3d_event_query *query = This->extendedData;
if (query) wined3d_event_query_destroy(query);
if (query->context) context_free_event_query(query);
} }
else if (This->type == WINED3DQUERYTYPE_OCCLUSION) else if (This->type == WINED3DQUERYTYPE_OCCLUSION)
{ {
struct wined3d_occlusion_query *query = This->extendedData; struct wined3d_occlusion_query *query = This->extendedData;
if (query->context) context_free_occlusion_query(query); if (query->context) context_free_occlusion_query(query);
HeapFree(GetProcessHeap(), 0, This->extendedData);
} }
HeapFree(GetProcessHeap(), 0, This->extendedData);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
return ref; return ref;
...@@ -309,6 +333,12 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void ...@@ -309,6 +333,12 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void
TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags); TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
if (!pData || !dwSize) return S_OK; if (!pData || !dwSize) return S_OK;
if (!query)
{
WARN("(%p): Event query not supported by GL, reporting GPU idle\n", This);
*data = TRUE;
return S_OK;
}
ret = wined3d_event_query_test(query, This->device); ret = wined3d_event_query_test(query, This->device);
switch(ret) switch(ret)
...@@ -327,11 +357,6 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void ...@@ -327,11 +357,6 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void
*data = TRUE; *data = TRUE;
break; break;
case WINED3D_EVENT_QUERY_UNSUPPORTED:
WARN("(%p): Event query not supported by GL, reporting GPU idle\n", This);
*data = TRUE;
break;
case WINED3D_EVENT_QUERY_ERROR: case WINED3D_EVENT_QUERY_ERROR:
ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n"); ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
...@@ -364,6 +389,10 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD ...@@ -364,6 +389,10 @@ static HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD
if (dwIssueFlags & WINED3DISSUE_END) if (dwIssueFlags & WINED3DISSUE_END)
{ {
struct wined3d_event_query *query = This->extendedData; struct wined3d_event_query *query = This->extendedData;
/* Faked event query support */
if (!query) return WINED3D_OK;
wined3d_event_query_issue(query, This->device); wined3d_event_query_issue(query, This->device);
} }
else if(dwIssueFlags & WINED3DISSUE_BEGIN) else if(dwIssueFlags & WINED3DISSUE_BEGIN)
...@@ -496,6 +525,7 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device, ...@@ -496,6 +525,7 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
WINED3DQUERYTYPE type, IUnknown *parent) WINED3DQUERYTYPE type, IUnknown *parent)
{ {
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
HRESULT hr;
switch (type) switch (type)
{ {
...@@ -518,8 +548,9 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device, ...@@ -518,8 +548,9 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
case WINED3DQUERYTYPE_EVENT: case WINED3DQUERYTYPE_EVENT:
TRACE("Event query.\n"); TRACE("Event query.\n");
if (!gl_info->supported[ARB_SYNC] && !gl_info->supported[NV_FENCE] query->lpVtbl = &IWineD3DEventQuery_Vtbl;
&& !gl_info->supported[APPLE_FENCE]) hr = wined3d_event_query_init(gl_info, (struct wined3d_event_query **) &query->extendedData);
if (hr == E_NOTIMPL)
{ {
/* Half-Life 2 needs this query. It does not render the main /* Half-Life 2 needs this query. It does not render the main
* menu correctly otherwise. Pretend to support it, faking * menu correctly otherwise. Pretend to support it, faking
...@@ -527,14 +558,10 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device, ...@@ -527,14 +558,10 @@ HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
* lowering performance. */ * lowering performance. */
FIXME("Event query: Unimplemented, but pretending to be supported.\n"); FIXME("Event query: Unimplemented, but pretending to be supported.\n");
} }
query->lpVtbl = &IWineD3DEventQuery_Vtbl; else if(FAILED(hr))
query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_event_query));
if (!query->extendedData)
{ {
ERR("Failed to allocate event query extended data.\n"); return hr;
return E_OUTOFMEMORY;
} }
((struct wined3d_event_query *)query->extendedData)->context = NULL;
break; break;
case WINED3DQUERYTYPE_VCACHE: case WINED3DQUERYTYPE_VCACHE:
......
...@@ -1036,8 +1036,7 @@ enum wined3d_event_query_result ...@@ -1036,8 +1036,7 @@ enum wined3d_event_query_result
WINED3D_EVENT_QUERY_WAITING, WINED3D_EVENT_QUERY_WAITING,
WINED3D_EVENT_QUERY_NOT_STARTED, WINED3D_EVENT_QUERY_NOT_STARTED,
WINED3D_EVENT_QUERY_WRONG_THREAD, WINED3D_EVENT_QUERY_WRONG_THREAD,
WINED3D_EVENT_QUERY_ERROR, WINED3D_EVENT_QUERY_ERROR
WINED3D_EVENT_QUERY_UNSUPPORTED
}; };
struct wined3d_context struct wined3d_context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment