2 * IWineD3DQuery implementation
4 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wined3d_private.h"
28 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/Queries.asp
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 /* *******************************************
34 IWineD3DQuery IUnknown parts follow
35 ******************************************* */
36 HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
38 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
39 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IWineD3DBase)
42 || IsEqualGUID(riid, &IID_IWineD3DQuery)) {
43 IUnknown_AddRef(iface);
51 ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
52 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
53 TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
54 return InterlockedIncrement(&This->ref);
57 ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
58 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
60 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
61 ref = InterlockedDecrement(&This->ref);
63 HeapFree(GetProcessHeap(), 0, This->extendedData);
64 HeapFree(GetProcessHeap(), 0, This);
69 /* *******************************************
70 IWineD3DQuery IWineD3DQuery parts follow
71 ******************************************* */
72 HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
73 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
75 *parent= (IUnknown*) parent;
76 IUnknown_AddRef(*parent);
77 TRACE("(%p) : returning %p\n", This, *parent);
81 HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
82 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
83 IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
84 *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
85 TRACE("(%p) returning %p\n", This, *pDevice);
90 HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
91 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
93 /*you can use this method to poll the resource for the query status*/
94 /*We return success(S_OK) if we support a feature, and faikure(S_FALSE) if we don't, just return success and fluff it for now*/
101 case WINED3DQUERYTYPE_VCACHE:
104 WINED3DDEVINFO_VCACHE *data = (WINED3DDEVINFO_VCACHE *)pData;
105 data->Pattern = MAKEFOURCC('C','A','C','H');
106 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
107 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
108 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
112 case WINED3DQUERYTYPE_RESOURCEMANAGER:
114 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
116 for(i = 0; i < WINED3DRTYPECOUNT; i++){
117 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
118 /* isTextureResident could be used to get some of this infomration */
119 data->stats[i].bThrashing = FALSE;
120 data->stats[i].ApproxBytesDownloaded = 1;
121 data->stats[i].NumEvicts = 1;
122 data->stats[i].NumVidCreates = 1;
123 data->stats[i].LastPri = 1;
124 data->stats[i].NumUsed = 1;
125 data->stats[i].NumUsedInVidMem = 1;
126 data->stats[i].WorkingSet = 1;
127 data->stats[i].WorkingSetBytes = 1;
128 data->stats[i].TotalManaged = 1;
129 data->stats[i].TotalBytes = 1;
134 case WINED3DQUERYTYPE_VERTEXSTATS:
136 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
137 data->NumRenderedTriangles = 1;
138 data->NumExtraClippingTriangles = 1;
142 case WINED3DQUERYTYPE_EVENT:
145 *data = TRUE; /*Don't know what this is supposed to be*/
148 case WINED3DQUERYTYPE_OCCLUSION:
152 /* TODO: opengl occlusion queries
153 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
154 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
155 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
159 case WINED3DQUERYTYPE_TIMESTAMP:
161 UINT64* data = pData;
162 *data = 1; /*Don't know what this is supposed to be*/
165 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
168 *data = FALSE; /*Don't know what this is supposed to be*/
171 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
173 UINT64* data = pData;
174 *data = 1; /*Don't know what this is supposed to be*/
177 case WINED3DQUERYTYPE_PIPELINETIMINGS:
179 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
181 data->VertexProcessingTimePercent = 1.0f;
182 data->PixelProcessingTimePercent = 1.0f;
183 data->OtherGPUProcessingTimePercent = 97.0f;
184 data->GPUIdleTimePercent = 1.0f;
187 case WINED3DQUERYTYPE_INTERFACETIMINGS:
189 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
191 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
192 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
193 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
194 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
195 data->WaitingForGPUOtherTimePercent = 96.0f;
199 case WINED3DQUERYTYPE_VERTEXTIMINGS:
201 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
202 data->MemoryProcessingPercent = 50.0f;
203 data->ComputationProcessingPercent = 50.0f;
207 case WINED3DQUERYTYPE_PIXELTIMINGS:
209 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
210 data->MemoryProcessingPercent = 50.0f;
211 data->ComputationProcessingPercent = 50.0f;
214 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
216 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
217 data->MaxBandwidthUtilized = 1.0f;
218 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
219 data->VertexRateUtilizedPercent = 1.0f;
220 data->TriangleSetupRateUtilizedPercent = 1.0f;
221 data->FillRateUtilizedPercent = 97.0f;
224 case WINED3DQUERYTYPE_CACHEUTILIZATION:
226 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
228 data->TextureCacheHitRate = 1.0f;
229 data->PostTransformVertexCacheHitRate = 1.0f;
235 FIXME("(%p) Unhandled query type %d\n",This , This->type);
239 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
240 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
242 FIXME("(%p) : stub\n", This);
243 return S_OK; /* S_OK if the query data is available*/
247 DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
248 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
250 FIXME("(%p) : stub\n", This);
252 case WINED3DQUERYTYPE_VCACHE:
253 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
255 case WINED3DQUERYTYPE_RESOURCEMANAGER:
256 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
258 case WINED3DQUERYTYPE_VERTEXSTATS:
259 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
261 case WINED3DQUERYTYPE_EVENT:
262 dataSize = sizeof(BOOL);
264 case WINED3DQUERYTYPE_OCCLUSION:
265 dataSize = sizeof(DWORD);
267 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
268 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
269 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
272 case WINED3DQUERYTYPE_TIMESTAMP:
273 dataSize = sizeof(UINT64);
275 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
276 dataSize = sizeof(BOOL);
278 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
279 dataSize = sizeof(UINT64);
281 case WINED3DQUERYTYPE_PIPELINETIMINGS:
282 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
284 case WINED3DQUERYTYPE_INTERFACETIMINGS:
285 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
287 case WINED3DQUERYTYPE_VERTEXTIMINGS:
288 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
290 case WINED3DQUERYTYPE_PIXELTIMINGS:
291 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
293 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
294 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
296 case WINED3DQUERYTYPE_CACHEUTILIZATION:
297 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
300 FIXME("(%p) Unhandled query type %d\n",This , This->type);
307 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
308 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
313 HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
314 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
315 FIXME("(%p) : stub\n", This);
316 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
320 /**********************************************************
321 * IWineD3DQuery VTbl follows
322 **********************************************************/
324 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
326 /*** IUnknown methods ***/
327 IWineD3DQueryImpl_QueryInterface,
328 IWineD3DQueryImpl_AddRef,
329 IWineD3DQueryImpl_Release,
330 /*** IWineD3Dquery methods ***/
331 IWineD3DQueryImpl_GetParent,
332 IWineD3DQueryImpl_GetDevice,
333 IWineD3DQueryImpl_GetData,
334 IWineD3DQueryImpl_GetDataSize,
335 IWineD3DQueryImpl_GetType,
336 IWineD3DQueryImpl_Issue