wined3d: Implement SM5 deriv_rty_coarse instruction.
[wine.git] / dlls / d3d11 / async.c
blobfa384844a99900d6a4369ca0e8d650b63283c62f
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 /* ID3D11Query methods */
29 static inline struct d3d_query *impl_from_ID3D11Query(ID3D11Query *iface)
31 return CONTAINING_RECORD(iface, struct d3d_query, ID3D11Query_iface);
34 static HRESULT STDMETHODCALLTYPE d3d11_query_QueryInterface(ID3D11Query *iface, REFIID riid, void **object)
36 struct d3d_query *query = impl_from_ID3D11Query(iface);
38 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
40 if ((IsEqualGUID(riid, &IID_ID3D11Predicate) && query->predicate)
41 || IsEqualGUID(riid, &IID_ID3D11Query)
42 || IsEqualGUID(riid, &IID_ID3D11Asynchronous)
43 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
44 || IsEqualGUID(riid, &IID_IUnknown))
46 ID3D11Query_AddRef(iface);
47 *object = iface;
48 return S_OK;
51 if ((IsEqualGUID(riid, &IID_ID3D10Predicate) && query->predicate)
52 || IsEqualGUID(riid, &IID_ID3D10Query)
53 || IsEqualGUID(riid, &IID_ID3D10Asynchronous)
54 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
56 ID3D10Query_AddRef(&query->ID3D10Query_iface);
57 *object = &query->ID3D10Query_iface;
58 return S_OK;
61 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
63 *object = NULL;
64 return E_NOINTERFACE;
67 static ULONG STDMETHODCALLTYPE d3d11_query_AddRef(ID3D11Query *iface)
69 struct d3d_query *query = impl_from_ID3D11Query(iface);
70 ULONG refcount = InterlockedIncrement(&query->refcount);
72 TRACE("%p increasing refcount to %u.\n", query, refcount);
74 return refcount;
77 static ULONG STDMETHODCALLTYPE d3d11_query_Release(ID3D11Query *iface)
79 struct d3d_query *query = impl_from_ID3D11Query(iface);
80 ULONG refcount = InterlockedDecrement(&query->refcount);
82 TRACE("%p decreasing refcount to %u.\n", query, refcount);
84 if (!refcount)
86 ID3D11Device_Release(query->device);
87 wined3d_mutex_lock();
88 wined3d_query_decref(query->wined3d_query);
89 wined3d_private_store_cleanup(&query->private_store);
90 wined3d_mutex_unlock();
91 HeapFree(GetProcessHeap(), 0, query);
94 return refcount;
97 static void STDMETHODCALLTYPE d3d11_query_GetDevice(ID3D11Query *iface, ID3D11Device **device)
99 struct d3d_query *query = impl_from_ID3D11Query(iface);
101 TRACE("iface %p, device %p.\n", iface, device);
103 *device = query->device;
104 ID3D11Device_AddRef(*device);
107 static HRESULT STDMETHODCALLTYPE d3d11_query_GetPrivateData(ID3D11Query *iface,
108 REFGUID guid, UINT *data_size, void *data)
110 struct d3d_query *query = impl_from_ID3D11Query(iface);
112 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
114 return d3d_get_private_data(&query->private_store, guid, data_size, data);
117 static HRESULT STDMETHODCALLTYPE d3d11_query_SetPrivateData(ID3D11Query *iface,
118 REFGUID guid, UINT data_size, const void *data)
120 struct d3d_query *query = impl_from_ID3D11Query(iface);
122 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
124 return d3d_set_private_data(&query->private_store, guid, data_size, data);
127 static HRESULT STDMETHODCALLTYPE d3d11_query_SetPrivateDataInterface(ID3D11Query *iface,
128 REFGUID guid, const IUnknown *data)
130 struct d3d_query *query = impl_from_ID3D11Query(iface);
132 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
134 return d3d_set_private_data_interface(&query->private_store, guid, data);
137 static UINT STDMETHODCALLTYPE d3d11_query_GetDataSize(ID3D11Query *iface)
139 struct d3d_query *query = impl_from_ID3D11Query(iface);
140 unsigned int data_size;
142 TRACE("iface %p.\n", iface);
144 wined3d_mutex_lock();
145 data_size = wined3d_query_get_data_size(query->wined3d_query);
146 wined3d_mutex_unlock();
148 return data_size;
151 static void STDMETHODCALLTYPE d3d11_query_GetDesc(ID3D11Query *iface, D3D11_QUERY_DESC *desc)
153 FIXME("iface %p, desc %p stub!\n", iface, desc);
156 static const struct ID3D11QueryVtbl d3d11_query_vtbl =
158 /* IUnknown methods */
159 d3d11_query_QueryInterface,
160 d3d11_query_AddRef,
161 d3d11_query_Release,
162 /* ID3D11DeviceChild methods */
163 d3d11_query_GetDevice,
164 d3d11_query_GetPrivateData,
165 d3d11_query_SetPrivateData,
166 d3d11_query_SetPrivateDataInterface,
167 /* ID3D11Asynchronous methods */
168 d3d11_query_GetDataSize,
169 /* ID3D11Query methods */
170 d3d11_query_GetDesc,
173 struct d3d_query *unsafe_impl_from_ID3D11Query(ID3D11Query *iface)
175 if (!iface)
176 return NULL;
177 assert(iface->lpVtbl == &d3d11_query_vtbl);
178 return CONTAINING_RECORD(iface, struct d3d_query, ID3D11Query_iface);
181 struct d3d_query *unsafe_impl_from_ID3D11Asynchronous(ID3D11Asynchronous *iface)
183 return unsafe_impl_from_ID3D11Query((ID3D11Query *)iface);
186 /* ID3D10Query methods */
188 static inline struct d3d_query *impl_from_ID3D10Query(ID3D10Query *iface)
190 return CONTAINING_RECORD(iface, struct d3d_query, ID3D10Query_iface);
193 /* IUnknown methods */
195 static HRESULT STDMETHODCALLTYPE d3d10_query_QueryInterface(ID3D10Query *iface, REFIID riid, void **object)
197 struct d3d_query *query = impl_from_ID3D10Query(iface);
199 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
201 return d3d11_query_QueryInterface(&query->ID3D11Query_iface, riid, object);
204 static ULONG STDMETHODCALLTYPE d3d10_query_AddRef(ID3D10Query *iface)
206 struct d3d_query *query = impl_from_ID3D10Query(iface);
208 TRACE("iface %p.\n", iface);
210 return d3d11_query_AddRef(&query->ID3D11Query_iface);
213 static ULONG STDMETHODCALLTYPE d3d10_query_Release(ID3D10Query *iface)
215 struct d3d_query *query = impl_from_ID3D10Query(iface);
217 TRACE("iface %p.\n", iface);
219 return d3d11_query_Release(&query->ID3D11Query_iface);
222 /* ID3D10DeviceChild methods */
224 static void STDMETHODCALLTYPE d3d10_query_GetDevice(ID3D10Query *iface, ID3D10Device **device)
226 struct d3d_query *query = impl_from_ID3D10Query(iface);
228 TRACE("iface %p, device %p.\n", iface, device);
230 ID3D11Device_QueryInterface(query->device, &IID_ID3D10Device, (void **)device);
233 static HRESULT STDMETHODCALLTYPE d3d10_query_GetPrivateData(ID3D10Query *iface,
234 REFGUID guid, UINT *data_size, void *data)
236 struct d3d_query *query = impl_from_ID3D10Query(iface);
238 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
239 iface, debugstr_guid(guid), data_size, data);
241 return d3d_get_private_data(&query->private_store, guid, data_size, data);
244 static HRESULT STDMETHODCALLTYPE d3d10_query_SetPrivateData(ID3D10Query *iface,
245 REFGUID guid, UINT data_size, const void *data)
247 struct d3d_query *query = impl_from_ID3D10Query(iface);
249 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
250 iface, debugstr_guid(guid), data_size, data);
252 return d3d_set_private_data(&query->private_store, guid, data_size, data);
255 static HRESULT STDMETHODCALLTYPE d3d10_query_SetPrivateDataInterface(ID3D10Query *iface,
256 REFGUID guid, const IUnknown *data)
258 struct d3d_query *query = impl_from_ID3D10Query(iface);
260 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
262 return d3d_set_private_data_interface(&query->private_store, guid, data);
265 /* ID3D10Asynchronous methods */
267 static void STDMETHODCALLTYPE d3d10_query_Begin(ID3D10Query *iface)
269 struct d3d_query *query = impl_from_ID3D10Query(iface);
270 HRESULT hr;
272 TRACE("iface %p.\n", iface);
274 wined3d_mutex_lock();
275 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_BEGIN)))
276 ERR("Failed to issue query, hr %#x.\n", hr);
277 wined3d_mutex_unlock();
280 static void STDMETHODCALLTYPE d3d10_query_End(ID3D10Query *iface)
282 struct d3d_query *query = impl_from_ID3D10Query(iface);
283 HRESULT hr;
285 TRACE("iface %p.\n", iface);
287 wined3d_mutex_lock();
288 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_END)))
289 ERR("Failed to issue query, hr %#x.\n", hr);
290 wined3d_mutex_unlock();
293 static HRESULT STDMETHODCALLTYPE d3d10_query_GetData(ID3D10Query *iface, void *data, UINT data_size, UINT flags)
295 struct d3d_query *query = impl_from_ID3D10Query(iface);
296 unsigned int wined3d_flags;
297 HRESULT hr;
299 TRACE("iface %p, data %p, data_size %u, flags %#x.\n", iface, data, data_size, flags);
301 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(flags);
303 wined3d_mutex_lock();
304 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
306 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
308 else
310 WARN("Invalid data size %u.\n", data_size);
311 hr = E_INVALIDARG;
313 wined3d_mutex_unlock();
315 return hr;
318 static UINT STDMETHODCALLTYPE d3d10_query_GetDataSize(ID3D10Query *iface)
320 struct d3d_query *query = impl_from_ID3D10Query(iface);
321 unsigned int data_size;
323 TRACE("iface %p.\n", iface);
325 wined3d_mutex_lock();
326 data_size = wined3d_query_get_data_size(query->wined3d_query);
327 wined3d_mutex_unlock();
329 return data_size;
332 /* ID3D10Query methods */
334 static void STDMETHODCALLTYPE d3d10_query_GetDesc(ID3D10Query *iface, D3D10_QUERY_DESC *desc)
336 FIXME("iface %p, desc %p stub!\n", iface, desc);
339 static const struct ID3D10QueryVtbl d3d10_query_vtbl =
341 /* IUnknown methods */
342 d3d10_query_QueryInterface,
343 d3d10_query_AddRef,
344 d3d10_query_Release,
345 /* ID3D10DeviceChild methods */
346 d3d10_query_GetDevice,
347 d3d10_query_GetPrivateData,
348 d3d10_query_SetPrivateData,
349 d3d10_query_SetPrivateDataInterface,
350 /* ID3D10Asynchronous methods */
351 d3d10_query_Begin,
352 d3d10_query_End,
353 d3d10_query_GetData,
354 d3d10_query_GetDataSize,
355 /* ID3D10Query methods */
356 d3d10_query_GetDesc,
359 struct d3d_query *unsafe_impl_from_ID3D10Query(ID3D10Query *iface)
361 if (!iface)
362 return NULL;
363 assert(iface->lpVtbl == &d3d10_query_vtbl);
364 return CONTAINING_RECORD(iface, struct d3d_query, ID3D10Query_iface);
367 static HRESULT d3d_query_init(struct d3d_query *query, struct d3d_device *device,
368 const D3D11_QUERY_DESC *desc, BOOL predicate)
370 HRESULT hr;
372 static const enum wined3d_query_type query_type_map[] =
374 /* D3D11_QUERY_EVENT */ WINED3D_QUERY_TYPE_EVENT,
375 /* D3D11_QUERY_OCCLUSION */ WINED3D_QUERY_TYPE_OCCLUSION,
376 /* D3D11_QUERY_TIMESTAMP */ WINED3D_QUERY_TYPE_TIMESTAMP,
377 /* D3D11_QUERY_TIMESTAMP_DISJOINT */ WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT,
378 /* D3D11_QUERY_PIPELINE_STATISTICS */ WINED3D_QUERY_TYPE_PIPELINE_STATISTICS,
379 /* D3D11_QUERY_OCCLUSION_PREDICATE */ WINED3D_QUERY_TYPE_OCCLUSION,
380 /* D3D11_QUERY_SO_STATISTICS */ WINED3D_QUERY_TYPE_SO_STATISTICS,
381 /* D3D11_QUERY_SO_OVERFLOW_PREDICATE */ WINED3D_QUERY_TYPE_SO_OVERFLOW,
384 if (desc->Query >= sizeof(query_type_map) / sizeof(*query_type_map))
386 FIXME("Unhandled query type %#x.\n", desc->Query);
387 return E_INVALIDARG;
390 if (desc->MiscFlags)
391 FIXME("Ignoring MiscFlags %#x.\n", desc->MiscFlags);
393 query->ID3D11Query_iface.lpVtbl = &d3d11_query_vtbl;
394 query->ID3D10Query_iface.lpVtbl = &d3d10_query_vtbl;
395 query->refcount = 1;
396 wined3d_mutex_lock();
397 wined3d_private_store_init(&query->private_store);
399 if (FAILED(hr = wined3d_query_create(device->wined3d_device,
400 query_type_map[desc->Query], query, &query->wined3d_query)))
402 WARN("Failed to create wined3d query, hr %#x.\n", hr);
403 wined3d_private_store_cleanup(&query->private_store);
404 wined3d_mutex_unlock();
405 return hr;
407 wined3d_mutex_unlock();
409 query->predicate = predicate;
410 query->device = &device->ID3D11Device_iface;
411 ID3D11Device_AddRef(query->device);
413 return S_OK;
416 HRESULT d3d_query_create(struct d3d_device *device, const D3D11_QUERY_DESC *desc, BOOL predicate,
417 struct d3d_query **query)
419 struct d3d_query *object;
420 BOOL is_predicate_type;
421 HRESULT hr;
423 if (!desc)
424 return E_INVALIDARG;
426 is_predicate_type = desc->Query == D3D11_QUERY_OCCLUSION_PREDICATE
427 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE
428 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0
429 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1
430 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2
431 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3;
433 if (!is_predicate_type && predicate)
435 WARN("Query type %u is not a predicate.\n", desc->Query);
436 return E_INVALIDARG;
439 if (is_predicate_type)
440 predicate = TRUE;
442 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
443 return E_OUTOFMEMORY;
445 if (FAILED(hr = d3d_query_init(object, device, desc, predicate)))
447 WARN("Failed to initialize predicate, hr %#x.\n", hr);
448 HeapFree(GetProcessHeap(), 0, object);
449 return hr;
452 TRACE("Created predicate %p.\n", object);
453 *query = object;
455 return S_OK;