wined3d: Add function to print the infolog of a GLSL shader on errors.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 S_OK;
46     }
47     *ppobj = NULL;
48     return E_NOINTERFACE;
49 }
50
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);
55 }
56
57 ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
58     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
59     ULONG ref;
60     TRACE("(%p) : Releasing from %ld\n", This, This->ref);
61     ref = InterlockedDecrement(&This->ref);
62     if (ref == 0) {
63         HeapFree(GetProcessHeap(), 0, This->extendedData);
64         HeapFree(GetProcessHeap(), 0, This);
65     }
66     return ref;
67 }
68
69 /* *******************************************
70    IWineD3DQuery IWineD3DQuery parts follow
71    ******************************************* */
72 HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown** parent){
73     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
74
75     *parent= (IUnknown*) parent;
76     IUnknown_AddRef(*parent);
77     TRACE("(%p) : returning %p\n", This, *parent);
78     return WINED3D_OK;
79 }
80
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);
86     return WINED3D_OK;
87 }
88
89
90 HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags){
91     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
92     if(dwSize == 0){
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*/
95         return S_OK;
96     }else{
97     }
98
99     switch (This->type){
100
101     case WINED3DQUERYTYPE_VCACHE:
102     {
103
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)*/
109
110     }
111     break;
112     case WINED3DQUERYTYPE_RESOURCEMANAGER:
113     {
114         WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
115         int i;
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;
130         }
131
132     }
133     break;
134     case WINED3DQUERYTYPE_VERTEXSTATS:
135     {
136         WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
137         data->NumRenderedTriangles      = 1;
138         data->NumExtraClippingTriangles = 1;
139
140     }
141     break;
142     case WINED3DQUERYTYPE_EVENT:
143     {
144         BOOL* data = pData;
145         *data = TRUE; /*Don't know what this is supposed to be*/
146     }
147     break;
148     case WINED3DQUERYTYPE_OCCLUSION:
149     {
150         DWORD* data = pData;
151         *data = 1;
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
156         */
157     }
158     break;
159     case WINED3DQUERYTYPE_TIMESTAMP:
160     {
161         UINT64* data = pData;
162         *data = 1; /*Don't know what this is supposed to be*/
163     }
164     break;
165     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
166     {
167         BOOL* data = pData;
168         *data = FALSE; /*Don't know what this is supposed to be*/
169     }
170     break;
171     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
172     {
173         UINT64* data = pData;
174         *data = 1; /*Don't know what this is supposed to be*/
175     }
176     break;
177     case WINED3DQUERYTYPE_PIPELINETIMINGS:
178     {
179         WINED3DDEVINFO_PIPELINETIMINGS *data = (WINED3DDEVINFO_PIPELINETIMINGS *)pData;
180
181         data->VertexProcessingTimePercent    =   1.0f;
182         data->PixelProcessingTimePercent     =   1.0f;
183         data->OtherGPUProcessingTimePercent  =  97.0f;
184         data->GPUIdleTimePercent             =   1.0f;
185     }
186     break;
187     case WINED3DQUERYTYPE_INTERFACETIMINGS:
188     {
189         WINED3DDEVINFO_INTERFACETIMINGS *data = (WINED3DDEVINFO_INTERFACETIMINGS *)pData;
190
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;
196     }
197
198     break;
199     case WINED3DQUERYTYPE_VERTEXTIMINGS:
200     {
201         WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
202         data->MemoryProcessingPercent      = 50.0f;
203         data->ComputationProcessingPercent = 50.0f;
204
205     }
206     break;
207     case WINED3DQUERYTYPE_PIXELTIMINGS:
208     {
209         WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
210         data->MemoryProcessingPercent      = 50.0f;
211         data->ComputationProcessingPercent = 50.0f;
212     }
213     break;
214     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
215     {
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;
222     }
223     break;
224     case WINED3DQUERYTYPE_CACHEUTILIZATION:
225     {
226         WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
227
228         data->TextureCacheHitRate             = 1.0f;
229         data->PostTransformVertexCacheHitRate = 1.0f;
230     }
231
232
233     break;
234     default:
235         FIXME("(%p) Unhandled query type %d\n",This , This->type);
236
237     };
238
239     /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
240     D3DGETDATA_FLUSH may return WINED3DERR_DEVICELOST if the device is lost
241     */
242     FIXME("(%p) : stub\n", This);
243     return S_OK; /* S_OK if the query data is available*/
244 }
245
246
247 DWORD WINAPI IWineD3DQueryImpl_GetDataSize(IWineD3DQuery* iface){
248     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
249     int dataSize = 0;
250     FIXME("(%p) : stub\n", This);
251     switch(This->type){
252     case WINED3DQUERYTYPE_VCACHE:
253         dataSize = sizeof(WINED3DDEVINFO_VCACHE);
254         break;
255     case WINED3DQUERYTYPE_RESOURCEMANAGER:
256         dataSize = sizeof(WINED3DDEVINFO_RESOURCEMANAGER);
257         break;
258     case WINED3DQUERYTYPE_VERTEXSTATS:
259         dataSize = sizeof(WINED3DDEVINFO_VERTEXSTATS);
260         break;
261     case WINED3DQUERYTYPE_EVENT:
262         dataSize = sizeof(BOOL);
263         break;
264     case WINED3DQUERYTYPE_OCCLUSION:
265         dataSize = sizeof(DWORD);
266         /*
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
270         */
271         break;
272     case WINED3DQUERYTYPE_TIMESTAMP:
273         dataSize = sizeof(UINT64);
274         break;
275     case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
276         dataSize = sizeof(BOOL);
277         break;
278     case WINED3DQUERYTYPE_TIMESTAMPFREQ:
279         dataSize = sizeof(UINT64);
280         break;
281     case WINED3DQUERYTYPE_PIPELINETIMINGS:
282         dataSize = sizeof(WINED3DDEVINFO_PIPELINETIMINGS);
283         break;
284     case WINED3DQUERYTYPE_INTERFACETIMINGS:
285         dataSize = sizeof(WINED3DDEVINFO_INTERFACETIMINGS);
286         break;
287     case WINED3DQUERYTYPE_VERTEXTIMINGS:
288         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
289         break;
290     case WINED3DQUERYTYPE_PIXELTIMINGS:
291         dataSize = sizeof(WINED3DDEVINFO_STAGETIMINGS);
292         break;
293     case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
294         dataSize = sizeof(WINED3DQUERYTYPE_BANDWIDTHTIMINGS);
295         break;
296     case WINED3DQUERYTYPE_CACHEUTILIZATION:
297         dataSize = sizeof(WINED3DDEVINFO_CACHEUTILIZATION);
298         break;
299     default:
300        FIXME("(%p) Unhandled query type %d\n",This , This->type);
301        dataSize = 0;
302     }
303     return dataSize;
304 }
305
306
307 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
308     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
309     return This->type;
310 }
311
312
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.    */
317 }
318
319
320 /**********************************************************
321  * IWineD3DQuery VTbl follows
322  **********************************************************/
323
324 const IWineD3DQueryVtbl IWineD3DQuery_Vtbl =
325 {
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
337 };