taskmgr: Fix some gcc 4.1 warnings.
[wine] / dlls / wined3d / query.c
1 /*
2  * IWineD3DQuery implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
6  *
7  *
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.
12  *
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.
17  *
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
21  */
22
23
24 #include "config.h"
25 #include "wined3d_private.h"
26
27 /*
28 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/Queries.asp
29 */
30
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32
33 /* *******************************************
34    IWineD3DQuery IUnknown parts follow
35    ******************************************* */
36 HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
37 {
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);
44         *ppobj = This;
45         return D3D_OK;
46     }
47     return E_NOINTERFACE;
48 }
49
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);
54 }
55
56 ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
57     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
58     ULONG ref;
59     TRACE("(%p) : Releasing from %ld\n", This, This->ref);
60     ref = InterlockedDecrement(&This->ref);
61     if (ref == 0) {
62         if(This->extendedData != NULL){
63             HeapFree(GetProcessHeap(), 0, This->extendedData);
64         }
65         HeapFree(GetProcessHeap(), 0, This);
66     }
67     return ref;
68 }
69
70 /* *******************************************
71    IWineD3DQuery IWineD3DQuery parts follow
72    ******************************************* */
73 HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
74     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
75
76     *parent= (IUnknown*) parent;
77     IUnknown_AddRef(*parent);
78     TRACE("(%p) : returning %p\n", This, *parent);
79     return D3D_OK;
80 }
81
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);
87     return D3D_OK;
88 }
89
90
91 HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
92     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
93     if(dwSize == 0){
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*/
96         return S_OK;
97     }else{
98     }
99
100     switch (This->type){
101
102     case WINED3DQUERYTYPE_VCACHE:
103     {
104
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)*/
110
111     }
112     break;
113     case WINED3DQUERYTYPE_RESOURCEMANAGER:
114     {
115         WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
116         int i;
117         for(i = 0; i < WINED3DRTYPECOUNT; 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;
131         }
132
133     }
134     break;
135     case WINED3DQUERYTYPE_VERTEXSTATS:
136     {
137         WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
138         data->NumRenderedTriangles      = 1;
139         data->NumExtraClippingTriangles = 1;
140
141     }
142     break;
143     case WINED3DQUERYTYPE_EVENT:
144     {
145         BOOL* data = pData;
146         *data = TRUE; /*Don't know what this is supposed to be*/
147     }
148     break;
149     case WINED3DQUERYTYPE_OCCLUSION:
150     {
151         DWORD* data = pData;
152         *data = 1;
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
157         */
158     }
159     break;
160     case WINED3DQUERYTYPE_TIMESTAMP:
161     {
162         UINT64* data = pData;
163         *data = 1; /*Don't know what this is supposed to be*/
164     }
165     break;
166     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
167     {
168         BOOL* data = pData;
169         *data = FALSE; /*Don't know what this is supposed to be*/
170     }
171     break;
172     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
173     {
174         UINT64* data = pData;
175         *data = 1; /*Don't know what this is supposed to be*/
176     }
177     break;
178     case WINED3DQUERYTYPE_PIPELINETIMINGS:
179     {
180         WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
181
182         data->VertexProcessingTimePercent    =   1.0f;
183         data->PixelProcessingTimePercent     =   1.0f;
184         data->OtherGPUProcessingTimePercent  =  97.0f;
185         data->GPUIdleTimePercent             =   1.0f;
186     }
187     break;
188     case WINED3DQUERYTYPE_INTERFACETIMINGS:
189     {
190         WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
191
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;
197     }
198
199     break;
200     case WINED3DQUERYTYPE_VERTEXTIMINGS:
201     {
202         WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
203         data->MemoryProcessingPercent      = 50.0f;
204         data->ComputationProcessingPercent = 50.0f;
205
206     }
207     break;
208     case WINED3DQUERYTYPE_PIXELTIMINGS:
209     {
210         WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
211         data->MemoryProcessingPercent      = 50.0f;
212         data->ComputationProcessingPercent = 50.0f;
213     }
214     break;
215     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
216     {
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;
223     }
224     break;
225     case WINED3DQUERYTYPE_CACHEUTILIZATION:
226     {
227         WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
228
229         data->TextureCacheHitRate             = 1.0f;
230         data->PostTransformVertexCacheHitRate = 1.0f;
231     }
232
233
234     break;
235     default:
236         FIXME("(%p) Unhandled query type %d\n",This , This->type);
237
238     };
239
240     /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
241     D3DGETDATA_FLUSH may return D3DERR_DEVICELOST if the device is lost
242     */
243     FIXME("(%p) : stub\n", This);
244     return S_OK; /* S_OK if the query data is available*/
245 }
246
247
248 DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
249     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
250     int dataSize = 0;
251     FIXME("(%p) : stub\n", This);
252     switch(This->type){
253     case WINED3DQUERYTYPE_VCACHE:
254         dataSize = sizeof(WINED3DDEVINFO_VCACHE);
255         break;
256     case WINED3DQUERYTYPE_RESOURCEMANAGER:
257         dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
258         break;
259     case WINED3DQUERYTYPE_VERTEXSTATS:
260         dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
261         break;
262     case WINED3DQUERYTYPE_EVENT:
263         dataSize = sizeof(BOOL);
264         break;
265     case WINED3DQUERYTYPE_OCCLUSION:
266         dataSize = sizeof(DWORD);
267         /*
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
271         */
272         break;
273     case WINED3DQUERYTYPE_TIMESTAMP:
274         dataSize = sizeof(UINT64);
275         break;
276     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
277         dataSize = sizeof(BOOL);
278         break;
279     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
280         dataSize = sizeof(UINT64);
281         break;
282     case WINED3DQUERYTYPE_PIPELINETIMINGS:
283         dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
284         break;
285     case WINED3DQUERYTYPE_INTERFACETIMINGS:
286         dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
287         break;
288     case WINED3DQUERYTYPE_VERTEXTIMINGS:
289         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
290         break;
291     case WINED3DQUERYTYPE_PIXELTIMINGS:
292         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
293         break;
294     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
295         dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
296         break;
297     case WINED3DQUERYTYPE_CACHEUTILIZATION:
298         dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
299         break;
300     default:
301        FIXME("(%p) Unhandled query type %d\n",This , This->type);
302        dataSize = 0;
303     }
304     return dataSize;
305 }
306
307
308 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
309     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
310     return This->type;
311 }
312
313
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.    */
318 }
319
320
321 /**********************************************************
322  * IWineD3DQuery VTbl follows
323  **********************************************************/
324
325 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
326 {
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
338 };