1 | /*
|
---|
2 | * IWineD3DQuery implementation
|
---|
3 | *
|
---|
4 | * Copyright 2005 Oliver Stieber
|
---|
5 | * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
6 | * Copyright 2009 Henri Verbeet for CodeWeavers.
|
---|
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 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
25 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
26 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
27 | * a choice of LGPL license versions is made available with the language indicating
|
---|
28 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
29 | * of the LGPL is applied is otherwise unspecified.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "config.h"
|
---|
33 | #include "wined3d_private.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
36 | #define GLINFO_LOCATION (*gl_info)
|
---|
37 |
|
---|
38 | BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info)
|
---|
39 | {
|
---|
40 | return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
|
---|
41 | }
|
---|
42 |
|
---|
43 | void wined3d_event_query_destroy(struct wined3d_event_query *query)
|
---|
44 | {
|
---|
45 | if (query->context) context_free_event_query(query);
|
---|
46 | HeapFree(GetProcessHeap(), 0, query);
|
---|
47 | }
|
---|
48 |
|
---|
49 | enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
|
---|
50 | {
|
---|
51 | struct wined3d_context *context;
|
---|
52 | const struct wined3d_gl_info *gl_info;
|
---|
53 | enum wined3d_event_query_result ret;
|
---|
54 | BOOL fence_result;
|
---|
55 |
|
---|
56 | TRACE("(%p) : device %p\n", query, device);
|
---|
57 |
|
---|
58 | if (query->context == NULL)
|
---|
59 | {
|
---|
60 | TRACE("Query not started\n");
|
---|
61 | return WINED3D_EVENT_QUERY_NOT_STARTED;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
---|
65 | {
|
---|
66 | #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
|
---|
67 | ERR("Event query tested from wrong thread\n");
|
---|
68 | #else
|
---|
69 | WARN("Event query tested from wrong thread\n");
|
---|
70 | #endif
|
---|
71 | return WINED3D_EVENT_QUERY_WRONG_THREAD;
|
---|
72 | }
|
---|
73 |
|
---|
74 | context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
75 | gl_info = context->gl_info;
|
---|
76 |
|
---|
77 | ENTER_GL();
|
---|
78 |
|
---|
79 | if (gl_info->supported[ARB_SYNC])
|
---|
80 | {
|
---|
81 | GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, 0));
|
---|
82 | checkGLcall("glClientWaitSync");
|
---|
83 |
|
---|
84 | switch (gl_ret)
|
---|
85 | {
|
---|
86 | case GL_ALREADY_SIGNALED:
|
---|
87 | case GL_CONDITION_SATISFIED:
|
---|
88 | ret = WINED3D_EVENT_QUERY_OK;
|
---|
89 | break;
|
---|
90 |
|
---|
91 | case GL_TIMEOUT_EXPIRED:
|
---|
92 | ret = WINED3D_EVENT_QUERY_WAITING;
|
---|
93 | break;
|
---|
94 |
|
---|
95 | case GL_WAIT_FAILED:
|
---|
96 | default:
|
---|
97 | ERR("glClientWaitSync returned %#x.\n", gl_ret);
|
---|
98 | ret = WINED3D_EVENT_QUERY_ERROR;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | else if (gl_info->supported[APPLE_FENCE])
|
---|
102 | {
|
---|
103 | fence_result = GL_EXTCALL(glTestFenceAPPLE(query->object.id));
|
---|
104 | checkGLcall("glTestFenceAPPLE");
|
---|
105 | if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
|
---|
106 | else ret = WINED3D_EVENT_QUERY_WAITING;
|
---|
107 | }
|
---|
108 | else if (gl_info->supported[NV_FENCE])
|
---|
109 | {
|
---|
110 | fence_result = GL_EXTCALL(glTestFenceNV(query->object.id));
|
---|
111 | checkGLcall("glTestFenceNV");
|
---|
112 | if (fence_result) ret = WINED3D_EVENT_QUERY_OK;
|
---|
113 | else ret = WINED3D_EVENT_QUERY_WAITING;
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | ERR("Event query created despite lack of GL support\n");
|
---|
118 | ret = WINED3D_EVENT_QUERY_ERROR;
|
---|
119 | }
|
---|
120 |
|
---|
121 | LEAVE_GL();
|
---|
122 |
|
---|
123 | context_release(context);
|
---|
124 | return ret;
|
---|
125 | }
|
---|
126 |
|
---|
127 | enum wined3d_event_query_result wined3d_event_query_finish(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
|
---|
128 | {
|
---|
129 | struct wined3d_context *context;
|
---|
130 | const struct wined3d_gl_info *gl_info;
|
---|
131 | enum wined3d_event_query_result ret;
|
---|
132 |
|
---|
133 | TRACE("(%p)\n", query);
|
---|
134 |
|
---|
135 | if (!query->context)
|
---|
136 | {
|
---|
137 | TRACE("Query not started\n");
|
---|
138 | return WINED3D_EVENT_QUERY_NOT_STARTED;
|
---|
139 | }
|
---|
140 | gl_info = query->context->gl_info;
|
---|
141 |
|
---|
142 | if (query->context->tid != GetCurrentThreadId() && !gl_info->supported[ARB_SYNC])
|
---|
143 | {
|
---|
144 | /* A glFinish does not reliably wait for draws in other contexts. The caller has
|
---|
145 | * to find its own way to cope with the thread switch
|
---|
146 | */
|
---|
147 | #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
|
---|
148 | ERR("Event query finished from wrong thread\n");
|
---|
149 | #else
|
---|
150 | WARN("Event query finished from wrong thread\n");
|
---|
151 | #endif
|
---|
152 | return WINED3D_EVENT_QUERY_WRONG_THREAD;
|
---|
153 | }
|
---|
154 |
|
---|
155 | context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
156 |
|
---|
157 | ENTER_GL();
|
---|
158 | if (gl_info->supported[ARB_SYNC])
|
---|
159 | {
|
---|
160 | GLenum gl_ret = GL_EXTCALL(glClientWaitSync(query->object.sync, 0, ~(GLuint64)0));
|
---|
161 | checkGLcall("glClientWaitSync");
|
---|
162 |
|
---|
163 | switch (gl_ret)
|
---|
164 | {
|
---|
165 | case GL_ALREADY_SIGNALED:
|
---|
166 | case GL_CONDITION_SATISFIED:
|
---|
167 | ret = WINED3D_EVENT_QUERY_OK;
|
---|
168 | break;
|
---|
169 |
|
---|
170 | /* We don't expect a timeout for a ~584 year wait */
|
---|
171 | default:
|
---|
172 | ERR("glClientWaitSync returned %#x.\n", gl_ret);
|
---|
173 | ret = WINED3D_EVENT_QUERY_ERROR;
|
---|
174 | }
|
---|
175 | }
|
---|
176 | else if (context->gl_info->supported[APPLE_FENCE])
|
---|
177 | {
|
---|
178 | GL_EXTCALL(glFinishFenceAPPLE(query->object.id));
|
---|
179 | checkGLcall("glFinishFenceAPPLE");
|
---|
180 | ret = WINED3D_EVENT_QUERY_OK;
|
---|
181 | }
|
---|
182 | else if (context->gl_info->supported[NV_FENCE])
|
---|
183 | {
|
---|
184 | GL_EXTCALL(glFinishFenceNV(query->object.id));
|
---|
185 | checkGLcall("glFinishFenceNV");
|
---|
186 | ret = WINED3D_EVENT_QUERY_OK;
|
---|
187 | }
|
---|
188 | else
|
---|
189 | {
|
---|
190 | ERR("Event query created without GL support\n");
|
---|
191 | ret = WINED3D_EVENT_QUERY_ERROR;
|
---|
192 | }
|
---|
193 | LEAVE_GL();
|
---|
194 |
|
---|
195 | context_release(context);
|
---|
196 | return ret;
|
---|
197 | }
|
---|
198 |
|
---|
199 | void wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
|
---|
200 | {
|
---|
201 | const struct wined3d_gl_info *gl_info;
|
---|
202 | struct wined3d_context *context;
|
---|
203 |
|
---|
204 | if (query->context)
|
---|
205 | {
|
---|
206 | if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
|
---|
207 | {
|
---|
208 | #ifdef VBOX_WINE_WITH_SINGLE_CONTEXT
|
---|
209 | ERR("unexpected\n");
|
---|
210 | #endif
|
---|
211 | context_free_event_query(query);
|
---|
212 | context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
213 | context_alloc_event_query(context, query);
|
---|
214 | }
|
---|
215 | else
|
---|
216 | {
|
---|
217 | context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
218 | }
|
---|
219 | }
|
---|
220 | else
|
---|
221 | {
|
---|
222 | context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
223 | context_alloc_event_query(context, query);
|
---|
224 | }
|
---|
225 |
|
---|
226 | gl_info = context->gl_info;
|
---|
227 |
|
---|
228 | ENTER_GL();
|
---|
229 |
|
---|
230 | if (gl_info->supported[ARB_SYNC])
|
---|
231 | {
|
---|
232 | if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
|
---|
233 | checkGLcall("glDeleteSync");
|
---|
234 | query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
|
---|
235 | checkGLcall("glFenceSync");
|
---|
236 | }
|
---|
237 | else if (gl_info->supported[APPLE_FENCE])
|
---|
238 | {
|
---|
239 | GL_EXTCALL(glSetFenceAPPLE(query->object.id));
|
---|
240 | checkGLcall("glSetFenceAPPLE");
|
---|
241 | }
|
---|
242 | else if (gl_info->supported[NV_FENCE])
|
---|
243 | {
|
---|
244 | GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
|
---|
245 | checkGLcall("glSetFenceNV");
|
---|
246 | }
|
---|
247 |
|
---|
248 | LEAVE_GL();
|
---|
249 |
|
---|
250 | context_release(context);
|
---|
251 | }
|
---|
252 |
|
---|
253 | /*
|
---|
254 | * Occlusion Queries:
|
---|
255 | * http://www.gris.uni-tuebingen.de/~bartz/Publications/paper/hww98.pdf
|
---|
256 | * http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
|
---|
257 | */
|
---|
258 |
|
---|
259 | /* *******************************************
|
---|
260 | IWineD3DQuery IUnknown parts follow
|
---|
261 | ******************************************* */
|
---|
262 | static HRESULT WINAPI IWineD3DQueryImpl_QueryInterface(IWineD3DQuery *iface, REFIID riid, LPVOID *ppobj)
|
---|
263 | {
|
---|
264 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
265 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
---|
266 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
267 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
268 | || IsEqualGUID(riid, &IID_IWineD3DQuery)) {
|
---|
269 | IUnknown_AddRef(iface);
|
---|
270 | *ppobj = This;
|
---|
271 | return S_OK;
|
---|
272 | }
|
---|
273 | *ppobj = NULL;
|
---|
274 | return E_NOINTERFACE;
|
---|
275 | }
|
---|
276 |
|
---|
277 | static ULONG WINAPI IWineD3DQueryImpl_AddRef(IWineD3DQuery *iface) {
|
---|
278 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
279 | TRACE("(%p) : AddRef increasing from %d\n", This, This->ref);
|
---|
280 | return InterlockedIncrement(&This->ref);
|
---|
281 | }
|
---|
282 |
|
---|
283 | static ULONG WINAPI IWineD3DQueryImpl_Release(IWineD3DQuery *iface) {
|
---|
284 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
285 | ULONG ref;
|
---|
286 | TRACE("(%p) : Releasing from %d\n", This, This->ref);
|
---|
287 | ref = InterlockedDecrement(&This->ref);
|
---|
288 | if (ref == 0) {
|
---|
289 | /* Queries are specific to the GL context that created them. Not
|
---|
290 | * deleting the query will obviously leak it, but that's still better
|
---|
291 | * than potentially deleting a different query with the same id in this
|
---|
292 | * context, and (still) leaking the actual query. */
|
---|
293 | if (This->type == WINED3DQUERYTYPE_EVENT)
|
---|
294 | {
|
---|
295 | struct wined3d_event_query *query = This->extendedData;
|
---|
296 | if (query) wined3d_event_query_destroy(query);
|
---|
297 | }
|
---|
298 | else if (This->type == WINED3DQUERYTYPE_OCCLUSION)
|
---|
299 | {
|
---|
300 | struct wined3d_occlusion_query *query = This->extendedData;
|
---|
301 |
|
---|
302 | if (query->context) context_free_occlusion_query(query);
|
---|
303 | HeapFree(GetProcessHeap(), 0, This->extendedData);
|
---|
304 | }
|
---|
305 |
|
---|
306 | HeapFree(GetProcessHeap(), 0, This);
|
---|
307 | }
|
---|
308 | return ref;
|
---|
309 | }
|
---|
310 |
|
---|
311 | /* *******************************************
|
---|
312 | IWineD3DQuery IWineD3DQuery parts follow
|
---|
313 | ******************************************* */
|
---|
314 | static HRESULT WINAPI IWineD3DQueryImpl_GetParent(IWineD3DQuery *iface, IUnknown **parent)
|
---|
315 | {
|
---|
316 | TRACE("iface %p, parent %p.\n", iface, parent);
|
---|
317 |
|
---|
318 | *parent = (IUnknown *)parent;
|
---|
319 | IUnknown_AddRef(*parent);
|
---|
320 |
|
---|
321 | TRACE("Returning %p.\n", *parent);
|
---|
322 |
|
---|
323 | return WINED3D_OK;
|
---|
324 | }
|
---|
325 |
|
---|
326 | static HRESULT WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
|
---|
327 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
|
---|
328 | struct wined3d_occlusion_query *query = This->extendedData;
|
---|
329 | IWineD3DDeviceImpl *device = This->device;
|
---|
330 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
331 | struct wined3d_context *context;
|
---|
332 | DWORD* data = pData;
|
---|
333 | GLuint available;
|
---|
334 | GLuint samples;
|
---|
335 | HRESULT res;
|
---|
336 |
|
---|
337 | TRACE("(%p) : type D3DQUERY_OCCLUSION, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
|
---|
338 |
|
---|
339 | if (!query->context) This->state = QUERY_CREATED;
|
---|
340 |
|
---|
341 | if (This->state == QUERY_CREATED)
|
---|
342 | {
|
---|
343 | /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
|
---|
344 | TRACE("Query wasn't yet started, returning S_OK\n");
|
---|
345 | if(data) *data = 0;
|
---|
346 | return S_OK;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (This->state == QUERY_BUILDING)
|
---|
350 | {
|
---|
351 | /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
|
---|
352 | TRACE("Query is building, returning S_FALSE\n");
|
---|
353 | return S_FALSE;
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (!gl_info->supported[ARB_OCCLUSION_QUERY])
|
---|
357 | {
|
---|
358 | WARN("(%p) : Occlusion queries not supported. Returning 1.\n", This);
|
---|
359 | *data = 1;
|
---|
360 | return S_OK;
|
---|
361 | }
|
---|
362 |
|
---|
363 | if (query->context->tid != GetCurrentThreadId())
|
---|
364 | {
|
---|
365 | FIXME("%p Wrong thread, returning 1.\n", This);
|
---|
366 | *data = 1;
|
---|
367 | return S_OK;
|
---|
368 | }
|
---|
369 |
|
---|
370 | context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
371 |
|
---|
372 | ENTER_GL();
|
---|
373 |
|
---|
374 | GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
|
---|
375 | checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
|
---|
376 | TRACE("(%p) : available %d.\n", This, available);
|
---|
377 |
|
---|
378 | if (available)
|
---|
379 | {
|
---|
380 | if (data)
|
---|
381 | {
|
---|
382 | GL_EXTCALL(glGetQueryObjectuivARB(query->id, GL_QUERY_RESULT_ARB, &samples));
|
---|
383 | checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
|
---|
384 | TRACE("(%p) : Returning %d samples.\n", This, samples);
|
---|
385 | *data = samples;
|
---|
386 | }
|
---|
387 | res = S_OK;
|
---|
388 | }
|
---|
389 | else
|
---|
390 | {
|
---|
391 | res = S_FALSE;
|
---|
392 | }
|
---|
393 |
|
---|
394 | LEAVE_GL();
|
---|
395 |
|
---|
396 | context_release(context);
|
---|
397 |
|
---|
398 | return res;
|
---|
399 | }
|
---|
400 |
|
---|
401 | static HRESULT WINAPI IWineD3DEventQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
|
---|
402 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
|
---|
403 | struct wined3d_event_query *query = This->extendedData;
|
---|
404 | BOOL *data = pData;
|
---|
405 | enum wined3d_event_query_result ret;
|
---|
406 |
|
---|
407 | TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
|
---|
408 |
|
---|
409 | if (!pData || !dwSize) return S_OK;
|
---|
410 | if (!query)
|
---|
411 | {
|
---|
412 | WARN("(%p): Event query not supported by GL, reporting GPU idle\n", This);
|
---|
413 | *data = TRUE;
|
---|
414 | return S_OK;
|
---|
415 | }
|
---|
416 |
|
---|
417 | ret = wined3d_event_query_test(query, This->device);
|
---|
418 | switch(ret)
|
---|
419 | {
|
---|
420 | case WINED3D_EVENT_QUERY_OK:
|
---|
421 | case WINED3D_EVENT_QUERY_NOT_STARTED:
|
---|
422 | *data = TRUE;
|
---|
423 | break;
|
---|
424 |
|
---|
425 | case WINED3D_EVENT_QUERY_WAITING:
|
---|
426 | *data = FALSE;
|
---|
427 | break;
|
---|
428 |
|
---|
429 | case WINED3D_EVENT_QUERY_WRONG_THREAD:
|
---|
430 | FIXME("(%p) Wrong thread, reporting GPU idle.\n", This);
|
---|
431 | *data = TRUE;
|
---|
432 | break;
|
---|
433 |
|
---|
434 | case WINED3D_EVENT_QUERY_ERROR:
|
---|
435 | ERR("The GL event query failed, returning D3DERR_INVALIDCALL\n");
|
---|
436 | return WINED3DERR_INVALIDCALL;
|
---|
437 | }
|
---|
438 |
|
---|
439 | return S_OK;
|
---|
440 | }
|
---|
441 |
|
---|
442 | static DWORD WINAPI IWineD3DEventQueryImpl_GetDataSize(IWineD3DQuery* iface){
|
---|
443 | TRACE("(%p) : type D3DQUERY_EVENT\n", iface);
|
---|
444 |
|
---|
445 | return sizeof(BOOL);
|
---|
446 | }
|
---|
447 |
|
---|
448 | static DWORD WINAPI IWineD3DOcclusionQueryImpl_GetDataSize(IWineD3DQuery* iface){
|
---|
449 | TRACE("(%p) : type D3DQUERY_OCCLUSION\n", iface);
|
---|
450 |
|
---|
451 | return sizeof(DWORD);
|
---|
452 | }
|
---|
453 |
|
---|
454 | static WINED3DQUERYTYPE WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
|
---|
455 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
456 | return This->type;
|
---|
457 | }
|
---|
458 |
|
---|
459 | static HRESULT WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
|
---|
460 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
461 |
|
---|
462 | TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
|
---|
463 | if (dwIssueFlags & WINED3DISSUE_END)
|
---|
464 | {
|
---|
465 | struct wined3d_event_query *query = This->extendedData;
|
---|
466 |
|
---|
467 | /* Faked event query support */
|
---|
468 | if (!query) return WINED3D_OK;
|
---|
469 |
|
---|
470 | wined3d_event_query_issue(query, This->device);
|
---|
471 | }
|
---|
472 | else if(dwIssueFlags & WINED3DISSUE_BEGIN)
|
---|
473 | {
|
---|
474 | /* Started implicitly at device creation */
|
---|
475 | ERR("Event query issued with START flag - what to do?\n");
|
---|
476 | }
|
---|
477 |
|
---|
478 | if(dwIssueFlags & WINED3DISSUE_BEGIN) {
|
---|
479 | This->state = QUERY_BUILDING;
|
---|
480 | } else {
|
---|
481 | This->state = QUERY_SIGNALLED;
|
---|
482 | }
|
---|
483 |
|
---|
484 | return WINED3D_OK;
|
---|
485 | }
|
---|
486 |
|
---|
487 | static HRESULT WINAPI IWineD3DOcclusionQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIssueFlags) {
|
---|
488 | IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
|
---|
489 | IWineD3DDeviceImpl *device = This->device;
|
---|
490 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
491 |
|
---|
492 | if (gl_info->supported[ARB_OCCLUSION_QUERY])
|
---|
493 | {
|
---|
494 | struct wined3d_occlusion_query *query = This->extendedData;
|
---|
495 | struct wined3d_context *context;
|
---|
496 |
|
---|
497 | /* This is allowed according to msdn and our tests. Reset the query and restart */
|
---|
498 | if (dwIssueFlags & WINED3DISSUE_BEGIN)
|
---|
499 | {
|
---|
500 | if (This->state == QUERY_BUILDING)
|
---|
501 | {
|
---|
502 | if (query->context->tid != GetCurrentThreadId())
|
---|
503 | {
|
---|
504 | FIXME("Wrong thread, can't restart query.\n");
|
---|
505 |
|
---|
506 | context_free_occlusion_query(query);
|
---|
507 | context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
508 | context_alloc_occlusion_query(context, query);
|
---|
509 | }
|
---|
510 | else
|
---|
511 | {
|
---|
512 | context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
513 |
|
---|
514 | ENTER_GL();
|
---|
515 | GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
|
---|
516 | checkGLcall("glEndQuery()");
|
---|
517 | LEAVE_GL();
|
---|
518 | }
|
---|
519 | }
|
---|
520 | else
|
---|
521 | {
|
---|
522 | if (query->context) context_free_occlusion_query(query);
|
---|
523 | context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
524 | context_alloc_occlusion_query(context, query);
|
---|
525 | }
|
---|
526 |
|
---|
527 | ENTER_GL();
|
---|
528 | GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query->id));
|
---|
529 | checkGLcall("glBeginQuery()");
|
---|
530 | LEAVE_GL();
|
---|
531 |
|
---|
532 | context_release(context);
|
---|
533 | }
|
---|
534 | if (dwIssueFlags & WINED3DISSUE_END) {
|
---|
535 | /* Msdn says _END on a non-building occlusion query returns an error, but
|
---|
536 | * our tests show that it returns OK. But OpenGL doesn't like it, so avoid
|
---|
537 | * generating an error
|
---|
538 | */
|
---|
539 | if (This->state == QUERY_BUILDING)
|
---|
540 | {
|
---|
541 | if (query->context->tid != GetCurrentThreadId())
|
---|
542 | {
|
---|
543 | FIXME("Wrong thread, can't end query.\n");
|
---|
544 | }
|
---|
545 | else
|
---|
546 | {
|
---|
547 | context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
|
---|
548 |
|
---|
549 | ENTER_GL();
|
---|
550 | GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB));
|
---|
551 | checkGLcall("glEndQuery()");
|
---|
552 | LEAVE_GL();
|
---|
553 |
|
---|
554 | context_release(context);
|
---|
555 | }
|
---|
556 | }
|
---|
557 | }
|
---|
558 | } else {
|
---|
559 | FIXME("(%p) : Occlusion queries not supported\n", This);
|
---|
560 | }
|
---|
561 |
|
---|
562 | if(dwIssueFlags & WINED3DISSUE_BEGIN) {
|
---|
563 | This->state = QUERY_BUILDING;
|
---|
564 | } else {
|
---|
565 | This->state = QUERY_SIGNALLED;
|
---|
566 | }
|
---|
567 | return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL. */
|
---|
568 | }
|
---|
569 |
|
---|
570 | static const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl =
|
---|
571 | {
|
---|
572 | /*** IUnknown methods ***/
|
---|
573 | IWineD3DQueryImpl_QueryInterface,
|
---|
574 | IWineD3DQueryImpl_AddRef,
|
---|
575 | IWineD3DQueryImpl_Release,
|
---|
576 | /*** IWineD3Dquery methods ***/
|
---|
577 | IWineD3DQueryImpl_GetParent,
|
---|
578 | IWineD3DEventQueryImpl_GetData,
|
---|
579 | IWineD3DEventQueryImpl_GetDataSize,
|
---|
580 | IWineD3DQueryImpl_GetType,
|
---|
581 | IWineD3DEventQueryImpl_Issue
|
---|
582 | };
|
---|
583 |
|
---|
584 | static const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl =
|
---|
585 | {
|
---|
586 | /*** IUnknown methods ***/
|
---|
587 | IWineD3DQueryImpl_QueryInterface,
|
---|
588 | IWineD3DQueryImpl_AddRef,
|
---|
589 | IWineD3DQueryImpl_Release,
|
---|
590 | /*** IWineD3Dquery methods ***/
|
---|
591 | IWineD3DQueryImpl_GetParent,
|
---|
592 | IWineD3DOcclusionQueryImpl_GetData,
|
---|
593 | IWineD3DOcclusionQueryImpl_GetDataSize,
|
---|
594 | IWineD3DQueryImpl_GetType,
|
---|
595 | IWineD3DOcclusionQueryImpl_Issue
|
---|
596 | };
|
---|
597 |
|
---|
598 | HRESULT query_init(IWineD3DQueryImpl *query, IWineD3DDeviceImpl *device,
|
---|
599 | WINED3DQUERYTYPE type, IUnknown *parent)
|
---|
600 | {
|
---|
601 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
602 |
|
---|
603 | switch (type)
|
---|
604 | {
|
---|
605 | case WINED3DQUERYTYPE_OCCLUSION:
|
---|
606 | TRACE("Occlusion query.\n");
|
---|
607 | if (!gl_info->supported[ARB_OCCLUSION_QUERY])
|
---|
608 | {
|
---|
609 | WARN("Unsupported in local OpenGL implementation: ARB_OCCLUSION_QUERY.\n");
|
---|
610 | return WINED3DERR_NOTAVAILABLE;
|
---|
611 | }
|
---|
612 | query->lpVtbl = &IWineD3DOcclusionQuery_Vtbl;
|
---|
613 | query->extendedData = HeapAlloc(GetProcessHeap(), 0, sizeof(struct wined3d_occlusion_query));
|
---|
614 | if (!query->extendedData)
|
---|
615 | {
|
---|
616 | ERR("Failed to allocate occlusion query extended data.\n");
|
---|
617 | return E_OUTOFMEMORY;
|
---|
618 | }
|
---|
619 | ((struct wined3d_occlusion_query *)query->extendedData)->context = NULL;
|
---|
620 | break;
|
---|
621 |
|
---|
622 | case WINED3DQUERYTYPE_EVENT:
|
---|
623 | TRACE("Event query.\n");
|
---|
624 | if (!wined3d_event_query_supported(gl_info))
|
---|
625 | {
|
---|
626 | /* Half-Life 2 needs this query. It does not render the main
|
---|
627 | * menu correctly otherwise. Pretend to support it, faking
|
---|
628 | * this query does not do much harm except potentially
|
---|
629 | * lowering performance. */
|
---|
630 | FIXME("Event query: Unimplemented, but pretending to be supported.\n");
|
---|
631 | }
|
---|
632 | query->lpVtbl = &IWineD3DEventQuery_Vtbl;
|
---|
633 | query->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_event_query));
|
---|
634 | if (!query->extendedData)
|
---|
635 | {
|
---|
636 | ERR("Failed to allocate event query memory.\n");
|
---|
637 | return E_OUTOFMEMORY;
|
---|
638 | }
|
---|
639 | break;
|
---|
640 |
|
---|
641 | case WINED3DQUERYTYPE_VCACHE:
|
---|
642 | case WINED3DQUERYTYPE_RESOURCEMANAGER:
|
---|
643 | case WINED3DQUERYTYPE_VERTEXSTATS:
|
---|
644 | case WINED3DQUERYTYPE_TIMESTAMP:
|
---|
645 | case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
|
---|
646 | case WINED3DQUERYTYPE_TIMESTAMPFREQ:
|
---|
647 | case WINED3DQUERYTYPE_PIPELINETIMINGS:
|
---|
648 | case WINED3DQUERYTYPE_INTERFACETIMINGS:
|
---|
649 | case WINED3DQUERYTYPE_VERTEXTIMINGS:
|
---|
650 | case WINED3DQUERYTYPE_PIXELTIMINGS:
|
---|
651 | case WINED3DQUERYTYPE_BANDWIDTHTIMINGS:
|
---|
652 | case WINED3DQUERYTYPE_CACHEUTILIZATION:
|
---|
653 | default:
|
---|
654 | FIXME("Unhandled query type %#x.\n", type);
|
---|
655 | return WINED3DERR_NOTAVAILABLE;
|
---|
656 | }
|
---|
657 |
|
---|
658 | query->type = type;
|
---|
659 | query->state = QUERY_CREATED;
|
---|
660 | query->device = device;
|
---|
661 | query->parent = parent;
|
---|
662 | query->ref = 1;
|
---|
663 |
|
---|
664 | return WINED3D_OK;
|
---|
665 | }
|
---|