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
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
);
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
;
61 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
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
);
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
);
86 ID3D11Device_Release(query
->device
);
88 wined3d_query_decref(query
->wined3d_query
);
89 wined3d_private_store_cleanup(&query
->private_store
);
90 wined3d_mutex_unlock();
91 HeapFree(GetProcessHeap(), 0, query
);
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 FIXME("iface %p stub!\n", iface
);
144 static void STDMETHODCALLTYPE
d3d11_query_GetDesc(ID3D11Query
*iface
, D3D11_QUERY_DESC
*desc
)
146 FIXME("iface %p, desc %p stub!\n", iface
, desc
);
149 static const struct ID3D11QueryVtbl d3d11_query_vtbl
=
151 /* IUnknown methods */
152 d3d11_query_QueryInterface
,
155 /* ID3D11DeviceChild methods */
156 d3d11_query_GetDevice
,
157 d3d11_query_GetPrivateData
,
158 d3d11_query_SetPrivateData
,
159 d3d11_query_SetPrivateDataInterface
,
160 /* ID3D11Asynchronous methods */
161 d3d11_query_GetDataSize
,
162 /* ID3D11Query methods */
166 struct d3d_query
*unsafe_impl_from_ID3D11Query(ID3D11Query
*iface
)
170 assert(iface
->lpVtbl
== &d3d11_query_vtbl
);
171 return CONTAINING_RECORD(iface
, struct d3d_query
, ID3D11Query_iface
);
174 /* ID3D10Query methods */
176 static inline struct d3d_query
*impl_from_ID3D10Query(ID3D10Query
*iface
)
178 return CONTAINING_RECORD(iface
, struct d3d_query
, ID3D10Query_iface
);
181 /* IUnknown methods */
183 static HRESULT STDMETHODCALLTYPE
d3d10_query_QueryInterface(ID3D10Query
*iface
, REFIID riid
, void **object
)
185 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
187 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
189 return d3d11_query_QueryInterface(&query
->ID3D11Query_iface
, riid
, object
);
192 static ULONG STDMETHODCALLTYPE
d3d10_query_AddRef(ID3D10Query
*iface
)
194 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
196 TRACE("iface %p.\n", iface
);
198 return d3d11_query_AddRef(&query
->ID3D11Query_iface
);
201 static ULONG STDMETHODCALLTYPE
d3d10_query_Release(ID3D10Query
*iface
)
203 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
205 TRACE("iface %p.\n", iface
);
207 return d3d11_query_Release(&query
->ID3D11Query_iface
);
210 /* ID3D10DeviceChild methods */
212 static void STDMETHODCALLTYPE
d3d10_query_GetDevice(ID3D10Query
*iface
, ID3D10Device
**device
)
214 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
216 TRACE("iface %p, device %p.\n", iface
, device
);
218 ID3D11Device_QueryInterface(query
->device
, &IID_ID3D10Device
, (void **)device
);
221 static HRESULT STDMETHODCALLTYPE
d3d10_query_GetPrivateData(ID3D10Query
*iface
,
222 REFGUID guid
, UINT
*data_size
, void *data
)
224 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
226 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
227 iface
, debugstr_guid(guid
), data_size
, data
);
229 return d3d_get_private_data(&query
->private_store
, guid
, data_size
, data
);
232 static HRESULT STDMETHODCALLTYPE
d3d10_query_SetPrivateData(ID3D10Query
*iface
,
233 REFGUID guid
, UINT data_size
, const void *data
)
235 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
237 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
238 iface
, debugstr_guid(guid
), data_size
, data
);
240 return d3d_set_private_data(&query
->private_store
, guid
, data_size
, data
);
243 static HRESULT STDMETHODCALLTYPE
d3d10_query_SetPrivateDataInterface(ID3D10Query
*iface
,
244 REFGUID guid
, const IUnknown
*data
)
246 struct d3d_query
*query
= impl_from_ID3D10Query(iface
);
248 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
250 return d3d_set_private_data_interface(&query
->private_store
, guid
, data
);
253 /* ID3D10Asynchronous methods */
255 static void STDMETHODCALLTYPE
d3d10_query_Begin(ID3D10Query
*iface
)
257 FIXME("iface %p stub!\n", iface
);
260 static void STDMETHODCALLTYPE
d3d10_query_End(ID3D10Query
*iface
)
262 FIXME("iface %p stub!\n", iface
);
265 static HRESULT STDMETHODCALLTYPE
d3d10_query_GetData(ID3D10Query
*iface
, void *data
, UINT data_size
, UINT flags
)
267 FIXME("iface %p, data %p, data_size %u, flags %#x stub!\n", iface
, data
, data_size
, flags
);
272 static UINT STDMETHODCALLTYPE
d3d10_query_GetDataSize(ID3D10Query
*iface
)
274 FIXME("iface %p stub!\n", iface
);
279 /* ID3D10Query methods */
281 static void STDMETHODCALLTYPE
d3d10_query_GetDesc(ID3D10Query
*iface
, D3D10_QUERY_DESC
*desc
)
283 FIXME("iface %p, desc %p stub!\n", iface
, desc
);
286 static const struct ID3D10QueryVtbl d3d10_query_vtbl
=
288 /* IUnknown methods */
289 d3d10_query_QueryInterface
,
292 /* ID3D10DeviceChild methods */
293 d3d10_query_GetDevice
,
294 d3d10_query_GetPrivateData
,
295 d3d10_query_SetPrivateData
,
296 d3d10_query_SetPrivateDataInterface
,
297 /* ID3D10Asynchronous methods */
301 d3d10_query_GetDataSize
,
302 /* ID3D10Query methods */
306 struct d3d_query
*unsafe_impl_from_ID3D10Query(ID3D10Query
*iface
)
310 assert(iface
->lpVtbl
== &d3d10_query_vtbl
);
311 return CONTAINING_RECORD(iface
, struct d3d_query
, ID3D10Query_iface
);
314 static HRESULT
d3d_query_init(struct d3d_query
*query
, struct d3d_device
*device
,
315 const D3D11_QUERY_DESC
*desc
, BOOL predicate
)
319 static const enum wined3d_query_type query_type_map
[] =
321 /* D3D11_QUERY_EVENT */ WINED3D_QUERY_TYPE_EVENT
,
322 /* D3D11_QUERY_OCCLUSION */ WINED3D_QUERY_TYPE_OCCLUSION
,
323 /* D3D11_QUERY_TIMESTAMP */ WINED3D_QUERY_TYPE_TIMESTAMP
,
324 /* D3D11_QUERY_TIMESTAMP_DISJOINT */ WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
,
325 /* D3D11_QUERY_PIPELINE_STATISTICS */ WINED3D_QUERY_TYPE_PIPELINE_STATISTICS
,
326 /* D3D11_QUERY_OCCLUSION_PREDICATE */ WINED3D_QUERY_TYPE_OCCLUSION
,
327 /* D3D11_QUERY_SO_STATISTICS */ WINED3D_QUERY_TYPE_SO_STATISTICS
,
328 /* D3D11_QUERY_SO_OVERFLOW_PREDICATE */ WINED3D_QUERY_TYPE_SO_OVERFLOW
,
331 if (desc
->Query
>= sizeof(query_type_map
) / sizeof(*query_type_map
))
333 FIXME("Unhandled query type %#x.\n", desc
->Query
);
338 FIXME("Ignoring MiscFlags %#x.\n", desc
->MiscFlags
);
340 query
->ID3D11Query_iface
.lpVtbl
= &d3d11_query_vtbl
;
341 query
->ID3D10Query_iface
.lpVtbl
= &d3d10_query_vtbl
;
343 wined3d_mutex_lock();
344 wined3d_private_store_init(&query
->private_store
);
346 if (FAILED(hr
= wined3d_query_create(device
->wined3d_device
,
347 query_type_map
[desc
->Query
], query
, &query
->wined3d_query
)))
349 WARN("Failed to create wined3d query, hr %#x.\n", hr
);
350 wined3d_private_store_cleanup(&query
->private_store
);
351 wined3d_mutex_unlock();
354 wined3d_mutex_unlock();
356 query
->predicate
= predicate
;
357 query
->device
= &device
->ID3D11Device_iface
;
358 ID3D11Device_AddRef(query
->device
);
363 HRESULT
d3d_query_create(struct d3d_device
*device
, const D3D11_QUERY_DESC
*desc
, BOOL predicate
,
364 struct d3d_query
**query
)
366 struct d3d_query
*object
;
367 BOOL is_predicate_type
;
373 is_predicate_type
= desc
->Query
== D3D11_QUERY_OCCLUSION_PREDICATE
374 || desc
->Query
== D3D11_QUERY_SO_OVERFLOW_PREDICATE
375 || desc
->Query
== D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0
376 || desc
->Query
== D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1
377 || desc
->Query
== D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2
378 || desc
->Query
== D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3
;
380 if (!is_predicate_type
&& predicate
)
382 WARN("Query type %u is not a predicate.\n", desc
->Query
);
386 if (is_predicate_type
)
389 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
390 return E_OUTOFMEMORY
;
392 if (FAILED(hr
= d3d_query_init(object
, device
, desc
, predicate
)))
394 WARN("Failed to initialize predicate, hr %#x.\n", hr
);
395 HeapFree(GetProcessHeap(), 0, object
);
399 TRACE("Created predicate %p.\n", object
);