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);
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 if(This->extendedData != NULL){
64 HeapFree(GetProcessHeap(), 0, This->extendedData);
66 HeapFree(GetProcessHeap(), 0, This);
71 /* *******************************************
72 IWineD3DQuery IWineD3DQuery parts follow
73 ******************************************* */
74 HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
75 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
77 *parent= (IUnknown*) parent;
78 IUnknown_AddRef(*parent);
79 TRACE("(%p) : returning %p\n", This, *parent);
83 HRESULT WINAPI IWineD3DQueryImpl_GetDevice(IWineD3DQuery* iface, IWineD3DDevice **pDevice){
84 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
85 IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
86 *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
87 TRACE("(%p) returning %p\n", This, *pDevice);
92 HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
93 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
95 /*you can use this method to poll the resource for the query status*/
96 /*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*/
103 case WINED3DQUERYTYPE_VCACHE:
106 WINED3DDEVINFO_VCACHE *data = (WINED3DDEVINFO_VCACHE *)pData;
107 data->Pattern = MAKEFOURCC('C','A','C','H');
108 data->OptMethod = 0; /*0 get longest strips, 1 optimize vertex cache*/
109 data->CacheSize = 0; /*cache size, only required if OptMethod == 1*/
110 data->MagicNumber = 0; /*only required if OptMethod == 1 (used internally)*/
114 case WINED3DQUERYTYPE_RESOURCEMANAGER:
116 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
118 for(i = 0; i < WINED3DRTYPECOUNT; i++){
119 /*I'm setting the default values to 1 so as to reduce the risk of a div/0 in the caller*/
120 /* isTextureResident could be used to get some of this infomration */
121 data->stats[i].bThrashing = FALSE;
122 data->stats[i].ApproxBytesDownloaded = 1;
123 data->stats[i].NumEvicts = 1;
124 data->stats[i].NumVidCreates = 1;
125 data->stats[i].LastPri = 1;
126 data->stats[i].NumUsed = 1;
127 data->stats[i].NumUsedInVidMem = 1;
128 data->stats[i].WorkingSet = 1;
129 data->stats[i].WorkingSetBytes = 1;
130 data->stats[i].TotalManaged = 1;
131 data->stats[i].TotalBytes = 1;
136 case WINED3DQUERYTYPE_VERTEXSTATS:
138 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
139 data->NumRenderedTriangles = 1;
140 data->NumExtraClippingTriangles = 1;
144 case WINED3DQUERYTYPE_EVENT:
147 *data = TRUE; /*Don't know what this is supposed to be*/
150 case WINED3DQUERYTYPE_OCCLUSION:
154 /* TODO: opengl occlusion queries
155 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
156 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
157 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
161 case WINED3DQUERYTYPE_TIMESTAMP:
163 UINT64* data = pData;
164 *data = 1; /*Don't know what this is supposed to be*/
167 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
170 *data = FALSE; /*Don't know what this is supposed to be*/
173 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
175 UINT64* data = pData;
176 *data = 1; /*Don't know what this is supposed to be*/
179 case WINED3DQUERYTYPE_PIPELINETIMINGS:
181 WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
183 data->VertexProcessingTimePercent = 1.0f;
184 data->PixelProcessingTimePercent = 1.0f;
185 data->OtherGPUProcessingTimePercent = 97.0f;
186 data->GPUIdleTimePercent = 1.0f;
189 case WINED3DQUERYTYPE_INTERFACETIMINGS:
191 WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
193 data->WaitingForGPUToUseApplicationResourceTimePercent = 1.0f;
194 data->WaitingForGPUToAcceptMoreCommandsTimePercent = 1.0f;
195 data->WaitingForGPUToStayWithinLatencyTimePercent = 1.0f;
196 data->WaitingForGPUExclusiveResourceTimePercent = 1.0f;
197 data->WaitingForGPUOtherTimePercent = 96.0f;
201 case WINED3DQUERYTYPE_VERTEXTIMINGS:
203 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
204 data->MemoryProcessingPercent = 50.0f;
205 data->ComputationProcessingPercent = 50.0f;
209 case WINED3DQUERYTYPE_PIXELTIMINGS:
211 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
212 data->MemoryProcessingPercent = 50.0f;
213 data->ComputationProcessingPercent = 50.0f;
216 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
218 WINED3DDEVINFO_BANDWIDTHTIMINGS *data = (WINED3DDEVINFO_BANDWIDTHTIMINGS *)pData;
219 data->MaxBandwidthUtilized = 1.0f;
220 data->FrontEndUploadMemoryUtilizedPercent = 1.0f;
221 data->VertexRateUtilizedPercent = 1.0f;
222 data->TriangleSetupRateUtilizedPercent = 1.0f;
223 data->FillRateUtilizedPercent = 97.0f;
226 case WINED3DQUERYTYPE_CACHEUTILIZATION:
228 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
230 data->TextureCacheHitRate = 1.0f;
231 data->PostTransformVertexCacheHitRate = 1.0f;
237 FIXME("(%p) Unhandled query type %d\n",This , This->type);
241 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
242 D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
244 FIXME("(%p) : stub\n", This);
245 return S_OK; /* S_OK if the query data is available*/
249 DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
250 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
252 FIXME("(%p) : stub\n", This);
254 case WINED3DQUERYTYPE_VCACHE:
255 dataSize = sizeof(WINED3DDEVINFO_VCACHE);
257 case WINED3DQUERYTYPE_RESOURCEMANAGER:
258 dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
260 case WINED3DQUERYTYPE_VERTEXSTATS:
261 dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
263 case WINED3DQUERYTYPE_EVENT:
264 dataSize = sizeof(BOOL);
266 case WINED3DQUERYTYPE_OCCLUSION:
267 dataSize = sizeof(DWORD);
269 http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
270 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
271 http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
274 case WINED3DQUERYTYPE_TIMESTAMP:
275 dataSize = sizeof(UINT64);
277 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
278 dataSize = sizeof(BOOL);
280 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
281 dataSize = sizeof(UINT64);
283 case WINED3DQUERYTYPE_PIPELINETIMINGS:
284 dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
286 case WINED3DQUERYTYPE_INTERFACETIMINGS:
287 dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
289 case WINED3DQUERYTYPE_VERTEXTIMINGS:
290 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
292 case WINED3DQUERYTYPE_PIXELTIMINGS:
293 dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
295 case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
296 dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
298 case WINED3DQUERYTYPE_CACHEUTILIZATION:
299 dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
302 FIXME("(%p) Unhandled query type %d\n",This , This->type);
309 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
310 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
315 HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
316 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
317 FIXME("(%p) : stub\n", This);
318 return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
322 /**********************************************************
323 * IWineD3DQuery VTbl follows
324 **********************************************************/
326 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
328 /*** IUnknown methods ***/
329 IWineD3DQueryImpl_QueryInterface,
330 IWineD3DQueryImpl_AddRef,
331 IWineD3DQueryImpl_Release,
332 /*** IWineD3Dquery methods ***/
333 IWineD3DQueryImpl_GetParent,
334 IWineD3DQueryImpl_GetDevice,
335 IWineD3DQueryImpl_GetData,
336 IWineD3DQueryImpl_GetDataSize,
337 IWineD3DQueryImpl_GetType,
338 IWineD3DQueryImpl_Issue