If the meta/clip intersection (Rao) region doesn't exist, return
[wine/hacks.git] / dlls / wined3d / query.c
blobbe998f25039e561bf45cf9e197330d7c0657fda7
1 /*
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
24 #include "config.h"
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_IWineD3DQuery)) {
42 IUnknown_AddRef(iface);
43 *ppobj = This;
44 return D3D_OK;
46 return E_NOINTERFACE;
49 ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
50 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
51 TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
52 return InterlockedIncrement(&This->ref);
55 ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
56 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
57 ULONG ref;
58 TRACE("(%p) : Releasing from %ld\n", This, This->ref);
59 ref = InterlockedDecrement(&This->ref);
60 if (ref == 0) {
61 if(This->extendedData != NULL){
62 HeapFree(GetProcessHeap(), 0, This->extendedData);
64 HeapFree(GetProcessHeap(), 0, This);
66 return ref;
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);
78 return D3D_OK;
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 D3D_OK;
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{
99 switch (This->type){
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)*/
111 break;
112 case WINED3DQUERYTYPE_RESOURCEMANAGER:
114 WINED3DDEVINFO_RESOURCEMANAGER *data = (WINED3DDEVINFO_RESOURCEMANAGER *)pData;
115 int i;
116 for(i = 0; i < D3DRTYPECOUNT; 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;
133 break;
134 case WINED3DQUERYTYPE_VERTEXSTATS:
136 WINED3DDEVINFO_VERTEXSTATS *data = (WINED3DDEVINFO_VERTEXSTATS *)pData;
137 data->NumRenderedTriangles = 1;
138 data->NumExtraClippingTriangles = 1;
141 break;
142 case WINED3DQUERYTYPE_EVENT:
144 BOOL* data = pData;
145 *data = TRUE; /*Don't know what this is supposed to be*/
147 break;
148 case WINED3DQUERYTYPE_OCCLUSION:
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
158 break;
159 case WINED3DQUERYTYPE_TIMESTAMP:
161 UINT64* data = pData;
162 *data = 1; /*Don't know what this is supposed to be*/
164 break;
165 case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
167 BOOL* data = pData;
168 *data = FALSE; /*Don't know what this is supposed to be*/
170 break;
171 case WINED3DQUERYTYPE_TIMESTAMPFREQ:
173 UINT64* data = pData;
174 *data = 1; /*Don't know what this is supposed to be*/
176 break;
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;
186 break;
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;
198 break;
199 case WINED3DQUERYTYPE_VERTEXTIMINGS:
201 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
202 data->MemoryProcessingPercent = 50.0f;
203 data->ComputationProcessingPercent = 50.0f;
206 break;
207 case WINED3DQUERYTYPE_PIXELTIMINGS:
209 WINED3DDEVINFO_STAGETIMINGS *data = (WINED3DDEVINFO_STAGETIMINGS *)pData;
210 data->MemoryProcessingPercent = 50.0f;
211 data->ComputationProcessingPercent = 50.0f;
213 break;
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;
223 break;
224 case WINED3DQUERYTYPE_CACHEUTILIZATION:
226 WINED3DDEVINFO_CACHEUTILIZATION *data = (WINED3DDEVINFO_CACHEUTILIZATION *)pData;
228 data->TextureCacheHitRate = 1.0f;
229 data->PostTransformVertexCacheHitRate = 1.0f;
233 break;
234 default:
235 FIXME("(%p) Unhandled query type %d\n",This , This->type);
239 /*dwGetDataFlags = 0 || D3DGETDATA_FLUSH
240 D3DGETDATA_FLUSH may return D3DERR_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;
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);
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
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;
303 return dataSize;
307 WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
308 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
309 return This->type;
313 HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags){
314 IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
315 FIXME("(%p) : stub \n", This);
316 return D3D_OK; /* can be D3DERR_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