query.c revision 040b4a09341f574825386333398110f4db3e1e51
af062818b47340eef15700d2f0211576ba3506eevboxsync * IWineD3DQuery implementation
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2005 Oliver Stieber
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is free software; you can redistribute it and/or
af062818b47340eef15700d2f0211576ba3506eevboxsync * modify it under the terms of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License as published by the Free Software Foundation; either
af062818b47340eef15700d2f0211576ba3506eevboxsync * version 2.1 of the License, or (at your option) any later version.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This library is distributed in the hope that it will be useful,
af062818b47340eef15700d2f0211576ba3506eevboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
af062818b47340eef15700d2f0211576ba3506eevboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * Lesser General Public License for more details.
af062818b47340eef15700d2f0211576ba3506eevboxsync * You should have received a copy of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync * License along with this library; if not, write to the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * other than GPL or LGPL is available it will apply instead, Sun elects to use only
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * a choice of LGPL license versions is made available with the language indicating
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * of the LGPL is applied is otherwise unspecified.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Occlusion Queries:
af062818b47340eef15700d2f0211576ba3506eevboxsync * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
af062818b47340eef15700d2f0211576ba3506eevboxsync * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
af062818b47340eef15700d2f0211576ba3506eevboxsync#define GLINFO_LOCATION This->wineD3DDevice->adapter->gl_info
af062818b47340eef15700d2f0211576ba3506eevboxsync/* *******************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQuery IUnknown parts follow
af062818b47340eef15700d2f0211576ba3506eevboxsync ******************************************* */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : Releasing from %d\n", This, This->ref);
af062818b47340eef15700d2f0211576ba3506eevboxsync if (ref == 0) {
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync /* Queries are specific to the GL context that created them. Not
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * deleting the query will obviously leak it, but that's still better
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * than potentially deleting a different query with the same id in this
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * context, and (still) leaking the actual query. */
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
040b4a09341f574825386333398110f4db3e1e51vboxsync FIXME("Query was created in a different thread, skipping deletion.\n");
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glDeleteFencesAPPLE(1, &query_data->fenceId));
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glDeleteFencesNV(1, &query_data->fenceId));
040b4a09341f574825386333398110f4db3e1e51vboxsync else if (This->type == WINED3DQUERYTYPE_OCCLUSION && GL_SUPPORT(ARB_OCCLUSION_QUERY))
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
040b4a09341f574825386333398110f4db3e1e51vboxsync FIXME("Query was created in a different thread, skipping deletion.\n");
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glDeleteQueriesARB(1, &query_data->queryId));
af062818b47340eef15700d2f0211576ba3506eevboxsync/* *******************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQuery IWineD3DQuery parts follow
af062818b47340eef15700d2f0211576ba3506eevboxsync ******************************************* */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : type %#x, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, This->type, pData, dwSize, dwGetDataFlags);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VCACHE\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
af062818b47340eef15700d2f0211576ba3506eevboxsync data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
af062818b47340eef15700d2f0211576ba3506eevboxsync data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_RESOURCEMANAGER\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync for(i = 0; i < WINED3DRTYPECOUNT; i++){
af062818b47340eef15700d2f0211576ba3506eevboxsync /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
af062818b47340eef15700d2f0211576ba3506eevboxsync /* isTextureResident could be used to get some of this information */
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXSTATS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMP\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync *data = 1; /*Don't know what this is supposed to be*/
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPDISJOINT\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync *data = FALSE; /*Don't know what this is supposed to be*/
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_TIMESTAMPFREQ\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync *data = 1; /*Don't know what this is supposed to be*/
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIPELINETIMINGS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_INTERFACETIMINGS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
af062818b47340eef15700d2f0211576ba3506eevboxsync data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
af062818b47340eef15700d2f0211576ba3506eevboxsync data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
af062818b47340eef15700d2f0211576ba3506eevboxsync data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_VERTEXTIMINGS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_PIXELTIMINGS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_BANDWIDTHTIMINGS\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p): Unimplemented query WINED3DQUERYTYPE_CACHEUTILIZATION\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p) Unhandled query type %d\n",This , This->type);
af062818b47340eef15700d2f0211576ba3506eevboxsync /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
af062818b47340eef15700d2f0211576ba3506eevboxsync D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
af062818b47340eef15700d2f0211576ba3506eevboxsync return res; /* S_OK if the query data is available*/
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("Query wasn't yet started, returning S_OK\n");
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glGetQueryObjectuivARB(query_data->queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
040b4a09341f574825386333398110f4db3e1e51vboxsync checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glGetQueryObjectuivARB(query_data->queryId, GL_QUERY_RESULT_ARB, &samples));
040b4a09341f574825386333398110f4db3e1e51vboxsync checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync TRACE("(%p) : Returning %d samples.\n", This, samples);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* See comment in IWineD3DQuery::Issue, event query codeblock */
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
040b4a09341f574825386333398110f4db3e1e51vboxsync *data = GL_EXTCALL(glTestFenceAPPLE(query_data->fenceId));
040b4a09341f574825386333398110f4db3e1e51vboxsync *data = GL_EXTCALL(glTestFenceNV(query_data->fenceId));
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
af062818b47340eef15700d2f0211576ba3506eevboxsync dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
af062818b47340eef15700d2f0211576ba3506eevboxsync dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p) Unhandled query type %d\n",This , This->type);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic DWORD WINAPI IWineD3DEventQueryImpl_GetDataSize(IWineD3DQuery* iface){
af062818b47340eef15700d2f0211576ba3506eevboxsync return sizeof(BOOL);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic DWORD WINAPI IWineD3DOcclusionQueryImpl_GetDataSize(IWineD3DQuery* iface){
af062818b47340eef15700d2f0211576ba3506eevboxsync return sizeof(DWORD);
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* GL fences can be used only from the context that created them,
af062818b47340eef15700d2f0211576ba3506eevboxsync * so if a different context is active, don't bother setting the query. The penalty
af062818b47340eef15700d2f0211576ba3506eevboxsync * of a context switch is most likely higher than the gain of a correct query result
af062818b47340eef15700d2f0211576ba3506eevboxsync * If the query is used from a different thread, don't bother creating a multithread
af062818b47340eef15700d2f0211576ba3506eevboxsync * context - there's no point in doing that as the query would be unusable anyway
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glSetFenceNV(query_data->fenceId, GL_ALL_COMPLETED_NV));
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Started implicitly at device creation */
af062818b47340eef15700d2f0211576ba3506eevboxsync ERR("Event query issued with START flag - what to do?\n");
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
040b4a09341f574825386333398110f4db3e1e51vboxsync WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
040b4a09341f574825386333398110f4db3e1e51vboxsync FIXME("Not the owning context, can't start query.\n");
040b4a09341f574825386333398110f4db3e1e51vboxsync ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* This is allowed according to msdn and our tests. Reset the query and restart */
040b4a09341f574825386333398110f4db3e1e51vboxsync GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query_data->queryId));
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Msdn says _END on a non-building occlusion query returns an error, but
af062818b47340eef15700d2f0211576ba3506eevboxsync * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
af062818b47340eef15700d2f0211576ba3506eevboxsync * generating an error
af062818b47340eef15700d2f0211576ba3506eevboxsync FIXME("(%p) : Occlusion queries not supported\n", This);
af062818b47340eef15700d2f0211576ba3506eevboxsync return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
af062818b47340eef15700d2f0211576ba3506eevboxsync IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
af062818b47340eef15700d2f0211576ba3506eevboxsync TRACE("(%p) : dwIssueFlags %#x, type %#x\n", This, dwIssueFlags, This->type);
af062818b47340eef15700d2f0211576ba3506eevboxsync /* The fixme is printed when the app asks for the resulting data */
af062818b47340eef15700d2f0211576ba3506eevboxsync WARN("(%p) : Unhandled query type %#x\n", This, This->type);
af062818b47340eef15700d2f0211576ba3506eevboxsync return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
af062818b47340eef15700d2f0211576ba3506eevboxsync/**********************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync * IWineD3DQuery VTbl follows
af062818b47340eef15700d2f0211576ba3506eevboxsync **********************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IUnknown methods ***/
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IWineD3Dquery methods ***/
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IUnknown methods ***/
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IWineD3Dquery methods ***/
af062818b47340eef15700d2f0211576ba3506eevboxsyncconst IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IUnknown methods ***/
af062818b47340eef15700d2f0211576ba3506eevboxsync /*** IWineD3Dquery methods ***/