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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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);
50 ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
51 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
52 TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
53 return InterlockedIncrement(&This->ref);
56 ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
57 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
59 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
60 ref = InterlockedDecrement(&This->ref);
62 if(This->extendedData != NULL){
63 HeapFree(GetProcessHeap(), 0, This->extendedData);
65 HeapFree(GetProcessHeap(), 0, This);
70 /* *******************************************
71 IWineD3DQuery IWineD3DQuery parts follow
72 ******************************************* */
73 HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
74 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
76 *parent= (IUnknown*) parent;
77 IUnknown_AddRef(*parent);
78 TRACE("(%p) : returning %p\n", This, *parent);
82 HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
83 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
84 IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
85 *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
86 TRACE("(%p) returning %p\n", This, *pDevice);
91 HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
92 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
94 /*you can use this method to poll the resource for the query status*/
95 /*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*/
102 case WINED3DQUERYTYPE_VCACHE:
105 WINED3DDEVINFO_VCACHE *data = (WINED3DDEVINFO_VCACHE *)pData;
106 data->Pattern = MAKEFOURCC('C','A','C','H');
107 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
108 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
109 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
113 case WINED3DQUERYTYPE_RESOURCEMANAGER:
115 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
117 for(i = 0; i < D3DRTYPECOUNT; i++){
118 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
119 /* isTextureResident could be used to get some of this infomration */
120 data->stats[i].bThrashing = FALSE;
121 data->stats[i].ApproxBytesDownloaded = 1;
122 data->stats[i].NumEvicts = 1;
123 data->stats[i].NumVidCreates = 1;
124 data->stats[i].LastPri = 1;
125 data->stats[i].NumUsed = 1;
126 data->stats[i].NumUsedInVidMem = 1;
127 data->stats[i].WorkingSet = 1;
128 data->stats[i].WorkingSetBytes = 1;
129 data->stats[i].TotalManaged = 1;
130 data->stats[i].TotalBytes = 1;
135 case WINED3DQUERYTYPE_VERTEXSTATS:
137 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
138 data->NumRenderedTriangles = 1;
139 data->NumExtraClippingTriangles = 1;
143 case WINED3DQUERYTYPE_EVENT:
146 *data = TRUE; /*Don't know what this is supposed to be*/
149 case WINED3DQUERYTYPE_OCCLUSION:
153 /* TODO: opengl occlusion queries
154 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
155 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
156 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
160 case WINED3DQUERYTYPE_TIMESTAMP:
162 UINT64* data = pData;
163 *data = 1; /*Don't know what this is supposed to be*/
166 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
169 *data = FALSE; /*Don't know what this is supposed to be*/
172 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
174 UINT64* data = pData;
175 *data = 1; /*Don't know what this is supposed to be*/
178 case WINED3DQUERYTYPE_PIPELINETIMINGS:
180 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
182 data->VertexProcessingTimePercent = 1.0f;
183 data->PixelProcessingTimePercent = 1.0f;
184 data->OtherGPUProcessingTimePercent = 97.0f;
185 data->GPUIdleTimePercent = 1.0f;
188 case WINED3DQUERYTYPE_INTERFACETIMINGS:
190 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
192 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
193 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
194 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
195 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
196 data->WaitingForGPUOtherTimePercent = 96.0f;
200 case WINED3DQUERYTYPE_VERTEXTIMINGS:
202 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
203 data->MemoryProcessingPercent = 50.0f;
204 data->ComputationProcessingPercent = 50.0f;
208 case WINED3DQUERYTYPE_PIXELTIMINGS:
210 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
211 data->MemoryProcessingPercent = 50.0f;
212 data->ComputationProcessingPercent = 50.0f;
215 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
217 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
218 data->MaxBandwidthUtilized = 1.0f;
219 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
220 data->VertexRateUtilizedPercent = 1.0f;
221 data->TriangleSetupRateUtilizedPercent = 1.0f;
222 data->FillRateUtilizedPercent = 97.0f;
225 case WINED3DQUERYTYPE_CACHEUTILIZATION:
227 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
229 data->TextureCacheHitRate = 1.0f;
230 data->PostTransformVertexCacheHitRate = 1.0f;
236 FIXME("(%p) Unhandled query type %d\n",This , This->type);
240 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
241 D3DGETDATA_FLUSH may return D3DERR_DEVICELOST if the device is lost
243 FIXME("(%p) : stub\n", This);
244 return S_OK; /* S_OK if the query data is available*/
248 DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
249 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
251 FIXME("(%p) : stub\n", This);
253 case WINED3DQUERYTYPE_VCACHE:
254 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
256 case WINED3DQUERYTYPE_RESOURCEMANAGER:
257 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
259 case WINED3DQUERYTYPE_VERTEXSTATS:
260 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
262 case WINED3DQUERYTYPE_EVENT:
263 dataSize = sizeof(BOOL);
265 case WINED3DQUERYTYPE_OCCLUSION:
266 dataSize = sizeof(DWORD);
268 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
269 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
270 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
273 case WINED3DQUERYTYPE_TIMESTAMP:
274 dataSize = sizeof(UINT64);
276 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
277 dataSize = sizeof(BOOL);
279 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
280 dataSize = sizeof(UINT64);
282 case WINED3DQUERYTYPE_PIPELINETIMINGS:
283 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
285 case WINED3DQUERYTYPE_INTERFACETIMINGS:
286 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
288 case WINED3DQUERYTYPE_VERTEXTIMINGS:
289 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
291 case WINED3DQUERYTYPE_PIXELTIMINGS:
292 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
294 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
295 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
297 case WINED3DQUERYTYPE_CACHEUTILIZATION:
298 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
301 FIXME("(%p) Unhandled query type %d\n",This , This->type);
308 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
309 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
314 HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
315 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
316 FIXME("(%p) : stub\n", This);
317 return D3D_OK; /* can be D3DERR_INVALIDCALL. */
321 /**********************************************************
322 * IWineD3DQuery VTbl follows
323 **********************************************************/
325 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
327 /*** IUnknown methods ***/
328 IWineD3DQueryImpl_QueryInterface,
329 IWineD3DQueryImpl_AddRef,
330 IWineD3DQueryImpl_Release,
331 /*** IWineD3Dquery methods ***/
332 IWineD3DQueryImpl_GetParent,
333 IWineD3DQueryImpl_GetDevice,
334 IWineD3DQueryImpl_GetData,
335 IWineD3DQueryImpl_GetDataSize,
336 IWineD3DQueryImpl_GetType,
337 IWineD3DQueryImpl_Issue