d3d11: Implement d3d11_device_context_ClearUnorderedAccessViewFloat().
[wine.git] / dlls / d3d11 / device.c
blobd3e4987967618aeca64247cc12de91a26324e19c
1 /*
2 * Copyright 2008-2012 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 #define NONAMELESSUNION
21 #define WINE_NO_NAMELESS_EXTENSION
22 #include "d3d11_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
26 static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
28 SIZE_T max_capacity, new_capacity;
29 void *new_elements;
31 if (count <= *capacity)
32 return TRUE;
34 max_capacity = ~(SIZE_T)0 / size;
35 if (count > max_capacity)
36 return FALSE;
38 new_capacity = max(1, *capacity);
39 while (new_capacity < count && new_capacity <= max_capacity / 2)
40 new_capacity *= 2;
41 if (new_capacity < count)
42 new_capacity = count;
44 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
45 return FALSE;
47 *elements = new_elements;
48 *capacity = new_capacity;
49 return TRUE;
52 static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
54 static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
56 d3d_null_wined3d_object_destroyed,
59 static inline BOOL d3d_device_is_d3d10_active(struct d3d_device *device)
61 return !device->state
62 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device)
63 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device1);
66 static D3D_FEATURE_LEVEL d3d_feature_level_from_wined3d(enum wined3d_feature_level level)
68 return (D3D_FEATURE_LEVEL)level;
71 /* ID3DDeviceContextState methods */
73 static inline struct d3d_device_context_state *impl_from_ID3DDeviceContextState(ID3DDeviceContextState *iface)
75 return CONTAINING_RECORD(iface, struct d3d_device_context_state, ID3DDeviceContextState_iface);
78 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface,
79 REFIID iid, void **out)
81 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
83 if (IsEqualGUID(iid, &IID_ID3DDeviceContextState)
84 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
85 || IsEqualGUID(iid, &IID_IUnknown))
87 ID3DDeviceContextState_AddRef(iface);
88 *out = iface;
89 return S_OK;
92 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
93 *out = NULL;
95 return E_NOINTERFACE;
98 static ULONG d3d_device_context_state_private_addref(struct d3d_device_context_state *state)
100 ULONG refcount = InterlockedIncrement(&state->private_refcount);
102 TRACE("%p increasing private refcount to %u.\n", state, refcount);
104 return refcount;
107 static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface)
109 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
110 ULONG refcount = InterlockedIncrement(&state->refcount);
112 TRACE("%p increasing refcount to %u.\n", state, refcount);
114 if (refcount == 1)
116 d3d_device_context_state_private_addref(state);
117 ID3D11Device2_AddRef(state->device);
120 return refcount;
123 static void d3d_device_remove_context_state(struct d3d_device *device, struct d3d_device_context_state *state)
125 unsigned int i;
127 for (i = 0; i < device->context_state_count; ++i)
129 if (device->context_states[i] != state)
130 continue;
132 if (i != device->context_state_count - 1)
133 device->context_states[i] = device->context_states[device->context_state_count - 1];
134 --device->context_state_count;
135 break;
139 static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
141 ULONG refcount = InterlockedDecrement(&state->private_refcount);
142 struct d3d_device_context_state_entry *entry;
143 struct d3d_device *device;
144 unsigned int i;
146 TRACE("%p decreasing private refcount to %u.\n", state, refcount);
148 if (!refcount)
150 wined3d_private_store_cleanup(&state->private_store);
151 for (i = 0; i < state->entry_count; ++i)
153 entry = &state->entries[i];
154 device = entry->device;
156 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
157 wined3d_state_destroy(entry->wined3d_state);
159 d3d_device_remove_context_state(device, state);
161 heap_free(state->entries);
162 wined3d_device_decref(state->wined3d_device);
163 heap_free(state);
167 static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface)
169 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
170 ULONG refcount = InterlockedDecrement(&state->refcount);
172 TRACE("%p decreasing refcount to %u.\n", state, refcount);
174 if (!refcount)
176 ID3D11Device2_Release(state->device);
177 d3d_device_context_state_private_release(state);
180 return refcount;
183 static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device)
185 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
187 TRACE("iface %p, device %p.\n", iface, device);
189 *device = (ID3D11Device *)state->device;
190 ID3D11Device_AddRef(*device);
193 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_GetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
194 UINT *data_size, void *data)
196 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
198 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
200 return d3d_get_private_data(&state->private_store, guid, data_size, data);
203 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
204 UINT data_size, const void *data)
206 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
208 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
210 return d3d_set_private_data(&state->private_store, guid, data_size, data);
213 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateDataInterface(ID3DDeviceContextState *iface,
214 REFGUID guid, const IUnknown *data)
216 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
218 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
220 return d3d_set_private_data_interface(&state->private_store, guid, data);
223 static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
225 /* IUnknown methods */
226 d3d_device_context_state_QueryInterface,
227 d3d_device_context_state_AddRef,
228 d3d_device_context_state_Release,
229 /* ID3D11DeviceChild methods */
230 d3d_device_context_state_GetDevice,
231 d3d_device_context_state_GetPrivateData,
232 d3d_device_context_state_SetPrivateData,
233 d3d_device_context_state_SetPrivateDataInterface,
234 /* ID3DDeviceContextState methods */
237 static struct d3d_device_context_state_entry *d3d_device_context_state_get_entry(
238 struct d3d_device_context_state *state, struct d3d_device *device)
240 unsigned int i;
242 for (i = 0; i < state->entry_count; ++i)
244 if (state->entries[i].device == device)
245 return &state->entries[i];
248 return NULL;
251 static BOOL d3d_device_context_state_add_entry(struct d3d_device_context_state *state,
252 struct d3d_device *device, struct wined3d_state *wined3d_state)
254 struct d3d_device_context_state_entry *entry;
256 if (!d3d_array_reserve((void **)&state->entries, &state->entries_size,
257 state->entry_count + 1, sizeof(*state->entries)))
258 return FALSE;
260 if (!d3d_array_reserve((void **)&device->context_states, &device->context_states_size,
261 device->context_state_count + 1, sizeof(*device->context_states)))
262 return FALSE;
264 entry = &state->entries[state->entry_count++];
265 entry->device = device;
266 entry->wined3d_state = wined3d_state;
268 device->context_states[device->context_state_count++] = state;
270 return TRUE;
273 static void d3d_device_context_state_remove_entry(struct d3d_device_context_state *state, struct d3d_device *device)
275 struct d3d_device_context_state_entry *entry;
276 unsigned int i;
278 for (i = 0; i < state->entry_count; ++i)
280 entry = &state->entries[i];
281 if (entry->device != device)
282 continue;
284 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
285 wined3d_state_destroy(entry->wined3d_state);
287 if (i != state->entry_count)
288 state->entries[i] = state->entries[state->entry_count - 1];
289 --state->entry_count;
291 break;
295 static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d3d_device_context_state *state,
296 struct d3d_device *device)
298 struct d3d_device_context_state_entry *entry;
299 struct wined3d_state *wined3d_state;
301 if ((entry = d3d_device_context_state_get_entry(state, device)))
302 return entry->wined3d_state;
304 if (FAILED(wined3d_state_create(device->wined3d_device,
305 (enum wined3d_feature_level *)&state->feature_level, 1, &wined3d_state)))
306 return NULL;
308 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
310 wined3d_state_destroy(wined3d_state);
311 return NULL;
314 return wined3d_state;
317 static void d3d_device_context_state_init(struct d3d_device_context_state *state,
318 struct d3d_device *device, D3D_FEATURE_LEVEL feature_level, REFIID emulated_interface)
320 state->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl;
321 state->refcount = state->private_refcount = 0;
323 wined3d_private_store_init(&state->private_store);
325 state->feature_level = feature_level;
326 state->emulated_interface = *emulated_interface;
327 wined3d_device_incref(state->wined3d_device = device->wined3d_device);
328 state->device = &device->ID3D11Device2_iface;
330 d3d_device_context_state_AddRef(&state->ID3DDeviceContextState_iface);
333 /* ID3D11CommandList methods */
335 static inline struct d3d11_command_list *impl_from_ID3D11CommandList(ID3D11CommandList *iface)
337 return CONTAINING_RECORD(iface, struct d3d11_command_list, ID3D11CommandList_iface);
340 static HRESULT STDMETHODCALLTYPE d3d11_command_list_QueryInterface(ID3D11CommandList *iface, REFIID iid, void **out)
342 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
344 if (IsEqualGUID(iid, &IID_ID3D11CommandList)
345 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
346 || IsEqualGUID(iid, &IID_IUnknown))
348 ID3D11CommandList_AddRef(iface);
349 *out = iface;
350 return S_OK;
353 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
354 *out = NULL;
356 return E_NOINTERFACE;
359 static ULONG STDMETHODCALLTYPE d3d11_command_list_AddRef(ID3D11CommandList *iface)
361 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
362 ULONG refcount = InterlockedIncrement(&list->refcount);
364 TRACE("%p increasing refcount to %u.\n", list, refcount);
366 return refcount;
369 static ULONG STDMETHODCALLTYPE d3d11_command_list_Release(ID3D11CommandList *iface)
371 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
372 ULONG refcount = InterlockedDecrement(&list->refcount);
374 TRACE("%p decreasing refcount to %u.\n", list, refcount);
376 if (!refcount)
378 wined3d_mutex_lock();
379 wined3d_command_list_decref(list->wined3d_list);
380 wined3d_mutex_unlock();
381 wined3d_private_store_cleanup(&list->private_store);
382 ID3D11Device2_Release(list->device);
383 heap_free(list);
386 return refcount;
389 static void STDMETHODCALLTYPE d3d11_command_list_GetDevice(ID3D11CommandList *iface, ID3D11Device **device)
391 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
393 TRACE("iface %p, device %p.\n", iface, device);
395 *device = (ID3D11Device *)list->device;
396 ID3D11Device2_AddRef(list->device);
399 static HRESULT STDMETHODCALLTYPE d3d11_command_list_GetPrivateData(ID3D11CommandList *iface, REFGUID guid,
400 UINT *data_size, void *data)
402 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
404 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
406 return d3d_get_private_data(&list->private_store, guid, data_size, data);
409 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateData(ID3D11CommandList *iface, REFGUID guid,
410 UINT data_size, const void *data)
412 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
414 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
416 return d3d_set_private_data(&list->private_store, guid, data_size, data);
419 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateDataInterface(ID3D11CommandList *iface,
420 REFGUID guid, const IUnknown *data)
422 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
424 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
426 return d3d_set_private_data_interface(&list->private_store, guid, data);
429 static UINT STDMETHODCALLTYPE d3d11_command_list_GetContextFlags(ID3D11CommandList *iface)
431 TRACE("iface %p.\n", iface);
433 return 0;
436 static const struct ID3D11CommandListVtbl d3d11_command_list_vtbl =
438 /* IUnknown methods */
439 d3d11_command_list_QueryInterface,
440 d3d11_command_list_AddRef,
441 d3d11_command_list_Release,
442 /* ID3D11DeviceChild methods */
443 d3d11_command_list_GetDevice,
444 d3d11_command_list_GetPrivateData,
445 d3d11_command_list_SetPrivateData,
446 d3d11_command_list_SetPrivateDataInterface,
447 /* ID3D11CommandList methods */
448 d3d11_command_list_GetContextFlags,
451 static struct d3d11_command_list *unsafe_impl_from_ID3D11CommandList(ID3D11CommandList *iface)
453 if (!iface)
454 return NULL;
455 assert(iface->lpVtbl == &d3d11_command_list_vtbl);
456 return impl_from_ID3D11CommandList(iface);
459 static void d3d11_device_context_cleanup(struct d3d11_device_context *context)
461 wined3d_private_store_cleanup(&context->private_store);
464 /* ID3D11DeviceContext - immediate context methods */
466 static inline struct d3d11_device_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
468 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11DeviceContext1_iface);
471 static HRESULT STDMETHODCALLTYPE d3d11_device_context_QueryInterface(ID3D11DeviceContext1 *iface,
472 REFIID iid, void **out)
474 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
476 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
478 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
479 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
480 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
481 || IsEqualGUID(iid, &IID_IUnknown))
483 *out = &context->ID3D11DeviceContext1_iface;
485 else if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE && IsEqualGUID(iid, &IID_ID3D11Multithread))
487 *out = &context->ID3D11Multithread_iface;
489 else
491 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
492 *out = NULL;
493 return E_NOINTERFACE;
496 ID3D11DeviceContext1_AddRef(iface);
497 return S_OK;
500 static ULONG STDMETHODCALLTYPE d3d11_device_context_AddRef(ID3D11DeviceContext1 *iface)
502 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
503 ULONG refcount = InterlockedIncrement(&context->refcount);
505 TRACE("%p increasing refcount to %u.\n", context, refcount);
507 if (refcount == 1)
509 ID3D11Device2_AddRef(&context->device->ID3D11Device2_iface);
512 return refcount;
515 static ULONG STDMETHODCALLTYPE d3d11_device_context_Release(ID3D11DeviceContext1 *iface)
517 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
518 ULONG refcount = InterlockedDecrement(&context->refcount);
520 TRACE("%p decreasing refcount to %u.\n", context, refcount);
522 if (!refcount)
524 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
526 wined3d_deferred_context_destroy(context->wined3d_context);
527 d3d11_device_context_cleanup(context);
528 heap_free(context);
530 ID3D11Device2_Release(&context->device->ID3D11Device2_iface);
533 return refcount;
536 static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface,
537 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
539 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
540 unsigned int i;
542 wined3d_mutex_lock();
543 for (i = 0; i < buffer_count; ++i)
545 struct wined3d_buffer *wined3d_buffer;
546 struct d3d_buffer *buffer_impl;
548 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(context->wined3d_context,
549 type, start_slot + i)))
551 buffers[i] = NULL;
552 continue;
555 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
556 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
557 ID3D11Buffer_AddRef(buffers[i]);
559 wined3d_mutex_unlock();
562 static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface,
563 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
565 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
566 unsigned int i;
568 wined3d_mutex_lock();
569 for (i = 0; i < buffer_count; ++i)
571 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
573 wined3d_device_context_set_constant_buffer(context->wined3d_context, type, start_slot + i,
574 buffer ? buffer->wined3d_buffer : NULL);
576 wined3d_mutex_unlock();
579 static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
581 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
583 TRACE("iface %p, device %p.\n", iface, device);
585 *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
586 ID3D11Device_AddRef(*device);
589 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
590 UINT *data_size, void *data)
592 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
594 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
596 return d3d_get_private_data(&context->private_store, guid, data_size, data);
599 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
600 UINT data_size, const void *data)
602 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
604 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
606 return d3d_set_private_data(&context->private_store, guid, data_size, data);
609 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
610 REFGUID guid, const IUnknown *data)
612 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
614 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
616 return d3d_set_private_data_interface(&context->private_store, guid, data);
619 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
620 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
622 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
623 iface, start_slot, buffer_count, buffers);
625 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
626 buffer_count, buffers);
629 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
630 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
632 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
633 unsigned int i;
635 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
636 iface, start_slot, view_count, views);
638 wined3d_mutex_lock();
639 for (i = 0; i < view_count; ++i)
641 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
643 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
644 start_slot + i, view ? view->wined3d_view : NULL);
646 wined3d_mutex_unlock();
649 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
650 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
652 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
653 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
655 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
656 iface, shader, class_instances, class_instance_count);
658 if (class_instances)
659 FIXME("Dynamic linking is not implemented yet.\n");
661 wined3d_mutex_lock();
662 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
663 ps ? ps->wined3d_shader : NULL);
664 wined3d_mutex_unlock();
667 static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
668 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
670 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
671 unsigned int i;
673 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
674 iface, start_slot, sampler_count, samplers);
676 wined3d_mutex_lock();
677 for (i = 0; i < sampler_count; ++i)
679 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
681 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i,
682 sampler ? sampler->wined3d_sampler : NULL);
684 wined3d_mutex_unlock();
687 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
688 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
690 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
691 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
693 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
694 iface, shader, class_instances, class_instance_count);
696 if (class_instances)
697 FIXME("Dynamic linking is not implemented yet.\n");
699 wined3d_mutex_lock();
700 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
701 vs ? vs->wined3d_shader : NULL);
702 wined3d_mutex_unlock();
705 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
706 UINT index_count, UINT start_index_location, INT base_vertex_location)
708 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
710 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
711 iface, index_count, start_index_location, base_vertex_location);
713 wined3d_mutex_lock();
714 wined3d_device_context_draw_indexed(context->wined3d_context,
715 base_vertex_location, start_index_location, index_count, 0, 0);
716 wined3d_mutex_unlock();
719 static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
720 UINT vertex_count, UINT start_vertex_location)
722 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
724 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
725 iface, vertex_count, start_vertex_location);
727 wined3d_mutex_lock();
728 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
729 wined3d_mutex_unlock();
732 static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
733 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
735 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
736 struct wined3d_resource *wined3d_resource;
737 struct wined3d_map_desc map_desc;
738 HRESULT hr;
740 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
741 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
743 if (map_flags)
744 FIXME("Ignoring map_flags %#x.\n", map_flags);
746 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
748 wined3d_mutex_lock();
749 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
750 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
751 wined3d_mutex_unlock();
753 mapped_subresource->pData = map_desc.data;
754 mapped_subresource->RowPitch = map_desc.row_pitch;
755 mapped_subresource->DepthPitch = map_desc.slice_pitch;
757 return hr;
760 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
761 UINT subresource_idx)
763 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
764 struct wined3d_resource *wined3d_resource;
766 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
768 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
770 wined3d_mutex_lock();
771 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
772 wined3d_mutex_unlock();
775 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
776 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
778 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
779 iface, start_slot, buffer_count, buffers);
781 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
782 buffer_count, buffers);
785 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
786 ID3D11InputLayout *input_layout)
788 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
789 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
791 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
793 wined3d_mutex_lock();
794 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
795 wined3d_mutex_unlock();
798 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
799 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
801 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
802 unsigned int i;
804 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
805 iface, start_slot, buffer_count, buffers, strides, offsets);
807 wined3d_mutex_lock();
808 for (i = 0; i < buffer_count; ++i)
810 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
812 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
813 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
815 wined3d_mutex_unlock();
818 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
819 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
821 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
822 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
824 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
825 iface, buffer, debug_dxgi_format(format), offset);
827 wined3d_mutex_lock();
828 wined3d_device_context_set_index_buffer(context->wined3d_context,
829 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
830 wined3dformat_from_dxgi_format(format), offset);
831 wined3d_mutex_unlock();
834 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
835 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
836 UINT start_instance_location)
838 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
840 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
841 "base_vertex_location %d, start_instance_location %u.\n",
842 iface, instance_index_count, instance_count, start_index_location,
843 base_vertex_location, start_instance_location);
845 wined3d_mutex_lock();
846 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
847 start_index_location, instance_index_count, start_instance_location, instance_count);
848 wined3d_mutex_unlock();
851 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
852 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
854 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
856 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
857 "start_instance_location %u.\n",
858 iface, instance_vertex_count, instance_count, start_vertex_location,
859 start_instance_location);
861 wined3d_mutex_lock();
862 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
863 instance_vertex_count, start_instance_location, instance_count);
864 wined3d_mutex_unlock();
867 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
868 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
870 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
871 iface, start_slot, buffer_count, buffers);
873 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
874 buffer_count, buffers);
877 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
878 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
880 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
881 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
883 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
884 iface, shader, class_instances, class_instance_count);
886 if (class_instances)
887 FIXME("Dynamic linking is not implemented yet.\n");
889 wined3d_mutex_lock();
890 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
891 gs ? gs->wined3d_shader : NULL);
892 wined3d_mutex_unlock();
895 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
896 D3D11_PRIMITIVE_TOPOLOGY topology)
898 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
899 enum wined3d_primitive_type primitive_type;
900 unsigned int patch_vertex_count;
902 TRACE("iface %p, topology %#x.\n", iface, topology);
904 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
906 wined3d_mutex_lock();
907 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
908 wined3d_mutex_unlock();
911 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
912 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
914 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
915 unsigned int i;
917 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
919 wined3d_mutex_lock();
920 for (i = 0; i < view_count; ++i)
922 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
924 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
925 start_slot + i, view ? view->wined3d_view : NULL);
927 wined3d_mutex_unlock();
930 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
931 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
933 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
934 unsigned int i;
936 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
937 iface, start_slot, sampler_count, samplers);
939 wined3d_mutex_lock();
940 for (i = 0; i < sampler_count; ++i)
942 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
944 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i,
945 sampler ? sampler->wined3d_sampler : NULL);
947 wined3d_mutex_unlock();
950 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
951 ID3D11Asynchronous *asynchronous)
953 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
954 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
956 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
958 wined3d_mutex_lock();
959 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
960 wined3d_mutex_unlock();
963 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
964 ID3D11Asynchronous *asynchronous)
966 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
967 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
969 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
971 wined3d_mutex_lock();
972 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
973 wined3d_mutex_unlock();
976 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
977 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
979 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
980 unsigned int wined3d_flags;
981 HRESULT hr;
983 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
984 iface, asynchronous, data, data_size, data_flags);
986 if (!data && data_size)
987 return E_INVALIDARG;
989 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
991 wined3d_mutex_lock();
992 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
994 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
995 if (hr == WINED3DERR_INVALIDCALL)
996 hr = DXGI_ERROR_INVALID_CALL;
998 else
1000 WARN("Invalid data size %u.\n", data_size);
1001 hr = E_INVALIDARG;
1003 wined3d_mutex_unlock();
1005 return hr;
1008 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1009 ID3D11Predicate *predicate, BOOL value)
1011 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1012 struct d3d_query *query;
1014 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1016 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1018 wined3d_mutex_lock();
1019 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1020 wined3d_mutex_unlock();
1023 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1024 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1026 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1027 unsigned int i;
1029 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1031 wined3d_mutex_lock();
1032 for (i = 0; i < view_count; ++i)
1034 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1036 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
1037 start_slot + i, view ? view->wined3d_view : NULL);
1039 wined3d_mutex_unlock();
1042 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1043 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1045 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1046 unsigned int i;
1048 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1049 iface, start_slot, sampler_count, samplers);
1051 wined3d_mutex_lock();
1052 for (i = 0; i < sampler_count; ++i)
1054 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1056 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i,
1057 sampler ? sampler->wined3d_sampler : NULL);
1059 wined3d_mutex_unlock();
1062 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1063 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1064 ID3D11DepthStencilView *depth_stencil_view)
1066 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1067 struct d3d_depthstencil_view *dsv;
1068 unsigned int i;
1070 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1071 iface, render_target_view_count, render_target_views, depth_stencil_view);
1073 wined3d_mutex_lock();
1074 for (i = 0; i < render_target_view_count; ++i)
1076 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
1077 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
1078 rtv ? rtv->wined3d_view : NULL, FALSE);
1080 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1082 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
1085 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1086 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
1087 wined3d_mutex_unlock();
1090 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1091 ID3D11DeviceContext1 *iface, UINT render_target_view_count,
1092 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
1093 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1094 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
1096 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1097 unsigned int i;
1099 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1100 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
1101 "initial_counts %p.\n",
1102 iface, render_target_view_count, render_target_views, depth_stencil_view,
1103 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
1104 initial_counts);
1106 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1108 d3d11_device_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
1109 depth_stencil_view);
1112 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1114 wined3d_mutex_lock();
1115 for (i = 0; i < unordered_access_view_start_slot; ++i)
1117 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1118 WINED3D_PIPELINE_GRAPHICS, i, NULL, ~0u);
1120 for (i = 0; i < unordered_access_view_count; ++i)
1122 struct d3d11_unordered_access_view *view
1123 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
1125 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1126 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i,
1127 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1129 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
1131 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1132 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i, NULL, ~0u);
1134 wined3d_mutex_unlock();
1138 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1139 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1141 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1142 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1143 struct d3d_blend_state *blend_state_impl;
1145 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1146 iface, blend_state, debug_float4(blend_factor), sample_mask);
1148 if (!blend_factor)
1149 blend_factor = default_blend_factor;
1151 wined3d_mutex_lock();
1152 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1153 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1154 (const struct wined3d_color *)blend_factor, sample_mask);
1155 else
1156 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1157 (const struct wined3d_color *)blend_factor, sample_mask);
1158 wined3d_mutex_unlock();
1161 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1162 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1164 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1165 struct d3d_depthstencil_state *state_impl;
1167 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1168 iface, depth_stencil_state, stencil_ref);
1170 wined3d_mutex_lock();
1171 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1173 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1174 wined3d_mutex_unlock();
1175 return;
1178 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1179 wined3d_mutex_unlock();
1182 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1183 ID3D11Buffer *const *buffers, const UINT *offsets)
1185 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1186 unsigned int count, i;
1188 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1190 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
1191 wined3d_mutex_lock();
1192 for (i = 0; i < count; ++i)
1194 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1196 wined3d_device_context_set_stream_output(context->wined3d_context, i,
1197 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1199 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1201 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
1203 wined3d_mutex_unlock();
1206 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1208 FIXME("iface %p stub!\n", iface);
1211 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1212 ID3D11Buffer *buffer, UINT offset)
1214 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1215 struct d3d_buffer *d3d_buffer;
1217 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1219 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1221 wined3d_mutex_lock();
1222 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1223 wined3d_mutex_unlock();
1226 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1227 ID3D11Buffer *buffer, UINT offset)
1229 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1230 struct d3d_buffer *d3d_buffer;
1232 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1234 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1236 wined3d_mutex_lock();
1237 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1238 wined3d_mutex_unlock();
1241 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1242 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1244 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1246 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1247 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1249 wined3d_mutex_lock();
1250 wined3d_device_context_dispatch(context->wined3d_context,
1251 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1252 wined3d_mutex_unlock();
1255 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1256 ID3D11Buffer *buffer, UINT offset)
1258 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1259 struct d3d_buffer *buffer_impl;
1261 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1263 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1265 wined3d_mutex_lock();
1266 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1267 wined3d_mutex_unlock();
1270 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1271 ID3D11RasterizerState *rasterizer_state)
1273 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1274 struct d3d_rasterizer_state *rasterizer_state_impl;
1276 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1278 wined3d_mutex_lock();
1279 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1280 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1281 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1282 wined3d_mutex_unlock();
1285 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1286 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1288 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1289 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1290 unsigned int i;
1292 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1294 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1295 return;
1297 for (i = 0; i < viewport_count; ++i)
1299 wined3d_vp[i].x = viewports[i].TopLeftX;
1300 wined3d_vp[i].y = viewports[i].TopLeftY;
1301 wined3d_vp[i].width = viewports[i].Width;
1302 wined3d_vp[i].height = viewports[i].Height;
1303 wined3d_vp[i].min_z = viewports[i].MinDepth;
1304 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1307 wined3d_mutex_lock();
1308 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1309 wined3d_mutex_unlock();
1312 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1313 UINT rect_count, const D3D11_RECT *rects)
1315 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1317 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1319 if (rect_count > WINED3D_MAX_VIEWPORTS)
1320 return;
1322 wined3d_mutex_lock();
1323 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1324 wined3d_mutex_unlock();
1327 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1328 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1329 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1331 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1332 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1333 struct wined3d_box wined3d_src_box;
1335 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1336 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1337 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1338 src_resource, src_subresource_idx, src_box);
1340 if (!dst_resource || !src_resource)
1341 return;
1343 if (src_box)
1344 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1345 src_box->right, src_box->bottom, src_box->front, src_box->back);
1347 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1348 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1349 wined3d_mutex_lock();
1350 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1351 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1352 wined3d_mutex_unlock();
1355 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1356 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1358 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1359 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1361 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1363 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1364 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1365 wined3d_mutex_lock();
1366 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1367 wined3d_mutex_unlock();
1370 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1371 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1372 const void *data, UINT row_pitch, UINT depth_pitch)
1374 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1375 struct wined3d_resource *wined3d_resource;
1376 struct wined3d_box wined3d_box;
1378 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1379 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1381 if (box)
1382 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1384 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1385 wined3d_mutex_lock();
1386 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1387 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1388 wined3d_mutex_unlock();
1391 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1392 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1394 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1395 struct d3d11_unordered_access_view *uav;
1396 struct d3d_buffer *buffer_impl;
1398 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1399 iface, dst_buffer, dst_offset, src_view);
1401 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1402 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1404 wined3d_mutex_lock();
1405 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1406 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1407 wined3d_mutex_unlock();
1410 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1411 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1413 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1414 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1415 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1416 HRESULT hr;
1418 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1419 iface, render_target_view, debug_float4(color_rgba));
1421 if (!view)
1422 return;
1424 wined3d_mutex_lock();
1425 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1426 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1427 ERR("Failed to clear view, hr %#x.\n", hr);
1428 wined3d_mutex_unlock();
1431 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1432 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1434 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1435 struct d3d11_unordered_access_view *view;
1437 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1438 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1440 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1441 wined3d_mutex_lock();
1442 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1443 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1444 wined3d_mutex_unlock();
1447 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1448 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1450 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1451 struct d3d11_unordered_access_view *view;
1453 TRACE("iface %p, unordered_access_view %p, values %s.\n",
1454 iface, unordered_access_view, debug_float4(values));
1456 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1457 wined3d_mutex_lock();
1458 wined3d_device_context_clear_uav_float(context->wined3d_context,
1459 view->wined3d_view, (const struct wined3d_vec4 *)values);
1460 wined3d_mutex_unlock();
1463 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1464 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1466 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1467 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1468 DWORD wined3d_flags;
1469 HRESULT hr;
1471 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1472 iface, depth_stencil_view, flags, depth, stencil);
1474 if (!view)
1475 return;
1477 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1479 wined3d_mutex_lock();
1480 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1481 wined3d_flags, NULL, depth, stencil)))
1482 ERR("Failed to clear view, hr %#x.\n", hr);
1483 wined3d_mutex_unlock();
1486 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1487 ID3D11ShaderResourceView *view)
1489 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1490 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1492 TRACE("iface %p, view %p.\n", iface, view);
1494 wined3d_mutex_lock();
1495 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1496 wined3d_mutex_unlock();
1499 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1500 ID3D11Resource *resource, FLOAT min_lod)
1502 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1505 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1506 ID3D11Resource *resource)
1508 FIXME("iface %p, resource %p stub!\n", iface, resource);
1510 return 0.0f;
1513 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1514 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1515 ID3D11Resource *src_resource, UINT src_subresource_idx,
1516 DXGI_FORMAT format)
1518 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1519 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1520 enum wined3d_format_id wined3d_format;
1522 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1523 "src_resource %p, src_subresource_idx %u, format %s.\n",
1524 iface, dst_resource, dst_subresource_idx,
1525 src_resource, src_subresource_idx, debug_dxgi_format(format));
1527 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1528 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1529 wined3d_format = wined3dformat_from_dxgi_format(format);
1530 wined3d_mutex_lock();
1531 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1532 wined3d_dst_resource, dst_subresource_idx,
1533 wined3d_src_resource, src_subresource_idx, wined3d_format);
1534 wined3d_mutex_unlock();
1537 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1538 ID3D11CommandList *command_list, BOOL restore_state)
1540 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1541 struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);
1543 TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);
1545 wined3d_mutex_lock();
1546 wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
1547 wined3d_mutex_unlock();
1550 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1551 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1553 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1554 unsigned int i;
1556 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1557 iface, start_slot, view_count, views);
1559 wined3d_mutex_lock();
1560 for (i = 0; i < view_count; ++i)
1562 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1564 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1565 start_slot + i, view ? view->wined3d_view : NULL);
1567 wined3d_mutex_unlock();
1570 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1571 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1573 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1574 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1576 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1577 iface, shader, class_instances, class_instance_count);
1579 if (class_instances)
1580 FIXME("Dynamic linking is not implemented yet.\n");
1582 wined3d_mutex_lock();
1583 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1584 hs ? hs->wined3d_shader : NULL);
1585 wined3d_mutex_unlock();
1588 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1589 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1591 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1592 unsigned int i;
1594 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1595 iface, start_slot, sampler_count, samplers);
1597 wined3d_mutex_lock();
1598 for (i = 0; i < sampler_count; ++i)
1600 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1602 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1603 sampler ? sampler->wined3d_sampler : NULL);
1605 wined3d_mutex_unlock();
1608 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1609 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1611 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1612 iface, start_slot, buffer_count, buffers);
1614 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1615 buffer_count, buffers);
1618 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1619 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1621 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1622 unsigned int i;
1624 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1625 iface, start_slot, view_count, views);
1627 wined3d_mutex_lock();
1628 for (i = 0; i < view_count; ++i)
1630 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1632 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1633 start_slot + i, view ? view->wined3d_view : NULL);
1635 wined3d_mutex_unlock();
1638 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1639 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1641 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1642 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1644 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1645 iface, shader, class_instances, class_instance_count);
1647 if (class_instances)
1648 FIXME("Dynamic linking is not implemented yet.\n");
1650 wined3d_mutex_lock();
1651 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1652 ds ? ds->wined3d_shader : NULL);
1653 wined3d_mutex_unlock();
1656 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1657 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1659 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1660 unsigned int i;
1662 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1663 iface, start_slot, sampler_count, samplers);
1665 wined3d_mutex_lock();
1666 for (i = 0; i < sampler_count; ++i)
1668 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1670 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1671 sampler ? sampler->wined3d_sampler : NULL);
1673 wined3d_mutex_unlock();
1676 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1677 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1679 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1680 iface, start_slot, buffer_count, buffers);
1682 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1683 buffer_count, buffers);
1686 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1687 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1689 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1690 unsigned int i;
1692 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1693 iface, start_slot, view_count, views);
1695 wined3d_mutex_lock();
1696 for (i = 0; i < view_count; ++i)
1698 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1700 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1701 start_slot + i, view ? view->wined3d_view : NULL);
1703 wined3d_mutex_unlock();
1706 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1707 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1709 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1710 unsigned int i;
1712 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1713 iface, start_slot, view_count, views, initial_counts);
1715 wined3d_mutex_lock();
1716 for (i = 0; i < view_count; ++i)
1718 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1720 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1721 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1723 wined3d_mutex_unlock();
1726 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1727 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1729 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1730 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1732 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1733 iface, shader, class_instances, class_instance_count);
1735 if (class_instances)
1736 FIXME("Dynamic linking is not implemented yet.\n");
1738 wined3d_mutex_lock();
1739 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1740 cs ? cs->wined3d_shader : NULL);
1741 wined3d_mutex_unlock();
1744 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1745 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1747 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1748 unsigned int i;
1750 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1751 iface, start_slot, sampler_count, samplers);
1753 wined3d_mutex_lock();
1754 for (i = 0; i < sampler_count; ++i)
1756 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1758 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1759 sampler ? sampler->wined3d_sampler : NULL);
1761 wined3d_mutex_unlock();
1764 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1765 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1767 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1768 iface, start_slot, buffer_count, buffers);
1770 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1771 buffer_count, buffers);
1774 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1775 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1777 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1778 iface, start_slot, buffer_count, buffers);
1780 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1781 buffer_count, buffers);
1784 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1785 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1787 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1788 unsigned int i;
1790 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1791 iface, start_slot, view_count, views);
1793 wined3d_mutex_lock();
1794 for (i = 0; i < view_count; ++i)
1796 struct wined3d_shader_resource_view *wined3d_view;
1797 struct d3d_shader_resource_view *view_impl;
1799 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1800 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1802 views[i] = NULL;
1803 continue;
1806 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1807 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1808 ID3D11ShaderResourceView_AddRef(views[i]);
1810 wined3d_mutex_unlock();
1813 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1814 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1816 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1817 struct wined3d_shader *wined3d_shader;
1818 struct d3d_pixel_shader *shader_impl;
1820 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1821 iface, shader, class_instances, class_instance_count);
1823 if (class_instances || class_instance_count)
1824 FIXME("Dynamic linking not implemented yet.\n");
1825 if (class_instance_count)
1826 *class_instance_count = 0;
1828 wined3d_mutex_lock();
1829 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1831 wined3d_mutex_unlock();
1832 *shader = NULL;
1833 return;
1836 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1837 wined3d_mutex_unlock();
1838 *shader = &shader_impl->ID3D11PixelShader_iface;
1839 ID3D11PixelShader_AddRef(*shader);
1842 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1843 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1845 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1846 unsigned int i;
1848 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1849 iface, start_slot, sampler_count, samplers);
1851 wined3d_mutex_lock();
1852 for (i = 0; i < sampler_count; ++i)
1854 struct wined3d_sampler *wined3d_sampler;
1855 struct d3d_sampler_state *sampler_impl;
1857 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1858 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1860 samplers[i] = NULL;
1861 continue;
1864 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1865 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1866 ID3D11SamplerState_AddRef(samplers[i]);
1868 wined3d_mutex_unlock();
1871 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1872 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1874 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1875 struct d3d_vertex_shader *shader_impl;
1876 struct wined3d_shader *wined3d_shader;
1878 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1879 iface, shader, class_instances, class_instance_count);
1881 if (class_instances || class_instance_count)
1882 FIXME("Dynamic linking not implemented yet.\n");
1883 if (class_instance_count)
1884 *class_instance_count = 0;
1886 wined3d_mutex_lock();
1887 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1889 wined3d_mutex_unlock();
1890 *shader = NULL;
1891 return;
1894 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1895 wined3d_mutex_unlock();
1896 *shader = &shader_impl->ID3D11VertexShader_iface;
1897 ID3D11VertexShader_AddRef(*shader);
1900 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1901 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1903 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1904 iface, start_slot, buffer_count, buffers);
1906 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1907 buffer_count, buffers);
1910 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1911 ID3D11InputLayout **input_layout)
1913 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1914 struct wined3d_vertex_declaration *wined3d_declaration;
1915 struct d3d_input_layout *input_layout_impl;
1917 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1919 wined3d_mutex_lock();
1920 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1922 wined3d_mutex_unlock();
1923 *input_layout = NULL;
1924 return;
1927 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1928 wined3d_mutex_unlock();
1929 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1930 ID3D11InputLayout_AddRef(*input_layout);
1933 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1934 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1936 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1937 unsigned int i;
1939 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1940 iface, start_slot, buffer_count, buffers, strides, offsets);
1942 wined3d_mutex_lock();
1943 for (i = 0; i < buffer_count; ++i)
1945 struct wined3d_buffer *wined3d_buffer = NULL;
1946 struct d3d_buffer *buffer_impl;
1948 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1949 &wined3d_buffer, &offsets[i], &strides[i])))
1951 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1952 if (strides)
1953 strides[i] = 0;
1954 if (offsets)
1955 offsets[i] = 0;
1958 if (!wined3d_buffer)
1960 buffers[i] = NULL;
1961 continue;
1964 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1965 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1967 wined3d_mutex_unlock();
1970 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1971 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1973 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1974 enum wined3d_format_id wined3d_format;
1975 struct wined3d_buffer *wined3d_buffer;
1976 struct d3d_buffer *buffer_impl;
1978 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1980 wined3d_mutex_lock();
1981 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1982 *format = dxgi_format_from_wined3dformat(wined3d_format);
1983 if (!wined3d_buffer)
1985 wined3d_mutex_unlock();
1986 *buffer = NULL;
1987 return;
1990 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1991 wined3d_mutex_unlock();
1992 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1995 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1996 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1998 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1999 iface, start_slot, buffer_count, buffers);
2001 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2002 buffer_count, buffers);
2005 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
2006 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2008 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2009 struct d3d_geometry_shader *shader_impl;
2010 struct wined3d_shader *wined3d_shader;
2012 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2013 iface, shader, class_instances, class_instance_count);
2015 if (class_instances || class_instance_count)
2016 FIXME("Dynamic linking not implemented yet.\n");
2017 if (class_instance_count)
2018 *class_instance_count = 0;
2020 wined3d_mutex_lock();
2021 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
2023 wined3d_mutex_unlock();
2024 *shader = NULL;
2025 return;
2028 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2029 wined3d_mutex_unlock();
2030 *shader = &shader_impl->ID3D11GeometryShader_iface;
2031 ID3D11GeometryShader_AddRef(*shader);
2034 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
2035 D3D11_PRIMITIVE_TOPOLOGY *topology)
2037 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2038 enum wined3d_primitive_type primitive_type;
2039 unsigned int patch_vertex_count;
2041 TRACE("iface %p, topology %p.\n", iface, topology);
2043 wined3d_mutex_lock();
2044 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
2045 wined3d_mutex_unlock();
2047 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
2050 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
2051 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2053 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2054 unsigned int i;
2056 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2058 wined3d_mutex_lock();
2059 for (i = 0; i < view_count; ++i)
2061 struct wined3d_shader_resource_view *wined3d_view;
2062 struct d3d_shader_resource_view *view_impl;
2064 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2065 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2067 views[i] = NULL;
2068 continue;
2071 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2072 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2073 ID3D11ShaderResourceView_AddRef(views[i]);
2075 wined3d_mutex_unlock();
2078 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
2079 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2081 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2082 unsigned int i;
2084 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2085 iface, start_slot, sampler_count, samplers);
2087 wined3d_mutex_lock();
2088 for (i = 0; i < sampler_count; ++i)
2090 struct wined3d_sampler *wined3d_sampler;
2091 struct d3d_sampler_state *sampler_impl;
2093 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2094 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2096 samplers[i] = NULL;
2097 continue;
2100 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2101 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2102 ID3D11SamplerState_AddRef(samplers[i]);
2104 wined3d_mutex_unlock();
2107 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2108 ID3D11Predicate **predicate, BOOL *value)
2110 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2111 struct wined3d_query *wined3d_predicate;
2112 struct d3d_query *predicate_impl;
2114 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2116 wined3d_mutex_lock();
2117 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2119 wined3d_mutex_unlock();
2120 *predicate = NULL;
2121 return;
2124 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2125 wined3d_mutex_unlock();
2126 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2127 ID3D11Predicate_AddRef(*predicate);
2130 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2131 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2133 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2134 unsigned int i;
2136 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2138 wined3d_mutex_lock();
2139 for (i = 0; i < view_count; ++i)
2141 struct wined3d_shader_resource_view *wined3d_view;
2142 struct d3d_shader_resource_view *view_impl;
2144 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2145 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2147 views[i] = NULL;
2148 continue;
2151 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2152 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2153 ID3D11ShaderResourceView_AddRef(views[i]);
2155 wined3d_mutex_unlock();
2158 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2159 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2161 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2162 unsigned int i;
2164 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2165 iface, start_slot, sampler_count, samplers);
2167 wined3d_mutex_lock();
2168 for (i = 0; i < sampler_count; ++i)
2170 struct d3d_sampler_state *sampler_impl;
2171 struct wined3d_sampler *wined3d_sampler;
2173 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2174 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2176 samplers[i] = NULL;
2177 continue;
2180 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2181 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2182 ID3D11SamplerState_AddRef(samplers[i]);
2184 wined3d_mutex_unlock();
2187 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2188 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2189 ID3D11DepthStencilView **depth_stencil_view)
2191 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2192 struct wined3d_rendertarget_view *wined3d_view;
2194 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2195 iface, render_target_view_count, render_target_views, depth_stencil_view);
2197 wined3d_mutex_lock();
2198 if (render_target_views)
2200 struct d3d_rendertarget_view *view_impl;
2201 unsigned int i;
2203 for (i = 0; i < render_target_view_count; ++i)
2205 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2206 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2208 render_target_views[i] = NULL;
2209 continue;
2212 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2213 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2217 if (depth_stencil_view)
2219 struct d3d_depthstencil_view *view_impl;
2221 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2222 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2224 *depth_stencil_view = NULL;
2226 else
2228 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2229 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2232 wined3d_mutex_unlock();
2235 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2236 ID3D11DeviceContext1 *iface,
2237 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2238 ID3D11DepthStencilView **depth_stencil_view,
2239 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2240 ID3D11UnorderedAccessView **unordered_access_views)
2242 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2243 struct wined3d_unordered_access_view *wined3d_view;
2244 struct d3d11_unordered_access_view *view_impl;
2245 unsigned int i;
2247 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2248 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2249 "unordered_access_views %p.\n",
2250 iface, render_target_view_count, render_target_views, depth_stencil_view,
2251 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2253 if (render_target_views || depth_stencil_view)
2254 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2255 render_target_views, depth_stencil_view);
2257 if (unordered_access_views)
2259 wined3d_mutex_lock();
2260 for (i = 0; i < unordered_access_view_count; ++i)
2262 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2263 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2265 unordered_access_views[i] = NULL;
2266 continue;
2269 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2270 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2271 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2273 wined3d_mutex_unlock();
2277 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2278 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2280 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2281 struct wined3d_blend_state *wined3d_state;
2282 struct d3d_blend_state *blend_state_impl;
2284 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2285 iface, blend_state, blend_factor, sample_mask);
2287 wined3d_mutex_lock();
2288 if ((wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2289 (struct wined3d_color *)blend_factor, sample_mask)))
2291 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2292 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2294 else
2296 *blend_state = NULL;
2298 wined3d_mutex_unlock();
2301 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2302 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2304 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2305 struct wined3d_depth_stencil_state *wined3d_state;
2306 struct d3d_depthstencil_state *state_impl;
2308 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2309 iface, depth_stencil_state, stencil_ref);
2311 wined3d_mutex_lock();
2312 if ((wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref)))
2314 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2315 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2317 else
2319 *depth_stencil_state = NULL;
2321 wined3d_mutex_unlock();
2324 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2325 UINT buffer_count, ID3D11Buffer **buffers)
2327 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2328 unsigned int i;
2330 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2332 wined3d_mutex_lock();
2333 for (i = 0; i < buffer_count; ++i)
2335 struct wined3d_buffer *wined3d_buffer;
2336 struct d3d_buffer *buffer_impl;
2338 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2340 buffers[i] = NULL;
2341 continue;
2344 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2345 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2346 ID3D11Buffer_AddRef(buffers[i]);
2348 wined3d_mutex_unlock();
2351 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2352 ID3D11RasterizerState **rasterizer_state)
2354 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2355 struct d3d_rasterizer_state *rasterizer_state_impl;
2356 struct wined3d_rasterizer_state *wined3d_state;
2358 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2360 wined3d_mutex_lock();
2361 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2363 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2364 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2366 else
2368 *rasterizer_state = NULL;
2370 wined3d_mutex_unlock();
2373 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2374 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2376 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2377 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2378 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2380 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2382 if (!viewport_count)
2383 return;
2385 wined3d_mutex_lock();
2386 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2387 wined3d_mutex_unlock();
2389 if (!viewports)
2391 *viewport_count = actual_count;
2392 return;
2395 if (*viewport_count > actual_count)
2396 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2398 *viewport_count = min(actual_count, *viewport_count);
2399 for (i = 0; i < *viewport_count; ++i)
2401 viewports[i].TopLeftX = wined3d_vp[i].x;
2402 viewports[i].TopLeftY = wined3d_vp[i].y;
2403 viewports[i].Width = wined3d_vp[i].width;
2404 viewports[i].Height = wined3d_vp[i].height;
2405 viewports[i].MinDepth = wined3d_vp[i].min_z;
2406 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2410 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2411 UINT *rect_count, D3D11_RECT *rects)
2413 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2414 unsigned int actual_count;
2416 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2418 if (!rect_count)
2419 return;
2421 actual_count = *rect_count;
2423 wined3d_mutex_lock();
2424 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2425 wined3d_mutex_unlock();
2427 if (rects && *rect_count > actual_count)
2428 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2429 *rect_count = actual_count;
2432 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2433 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2435 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2436 unsigned int i;
2438 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2440 wined3d_mutex_lock();
2441 for (i = 0; i < view_count; ++i)
2443 struct wined3d_shader_resource_view *wined3d_view;
2444 struct d3d_shader_resource_view *view_impl;
2446 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2447 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2449 views[i] = NULL;
2450 continue;
2453 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2454 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2456 wined3d_mutex_unlock();
2459 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2460 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2462 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2463 struct d3d11_hull_shader *shader_impl;
2464 struct wined3d_shader *wined3d_shader;
2466 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2467 iface, shader, class_instances, class_instance_count);
2469 if (class_instances || class_instance_count)
2470 FIXME("Dynamic linking not implemented yet.\n");
2471 if (class_instance_count)
2472 *class_instance_count = 0;
2474 wined3d_mutex_lock();
2475 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2477 wined3d_mutex_unlock();
2478 *shader = NULL;
2479 return;
2482 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2483 wined3d_mutex_unlock();
2484 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2487 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2488 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2490 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2491 unsigned int i;
2493 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2494 iface, start_slot, sampler_count, samplers);
2496 wined3d_mutex_lock();
2497 for (i = 0; i < sampler_count; ++i)
2499 struct wined3d_sampler *wined3d_sampler;
2500 struct d3d_sampler_state *sampler_impl;
2502 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2503 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2505 samplers[i] = NULL;
2506 continue;
2509 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2510 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2512 wined3d_mutex_unlock();
2515 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2516 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2518 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2519 iface, start_slot, buffer_count, buffers);
2521 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2522 buffer_count, buffers);
2525 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2526 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2528 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2529 unsigned int i;
2531 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2532 iface, start_slot, view_count, views);
2534 wined3d_mutex_lock();
2535 for (i = 0; i < view_count; ++i)
2537 struct wined3d_shader_resource_view *wined3d_view;
2538 struct d3d_shader_resource_view *view_impl;
2540 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2541 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2543 views[i] = NULL;
2544 continue;
2547 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2548 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2550 wined3d_mutex_unlock();
2553 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2554 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2556 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2557 struct d3d11_domain_shader *shader_impl;
2558 struct wined3d_shader *wined3d_shader;
2560 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2561 iface, shader, class_instances, class_instance_count);
2563 if (class_instances || class_instance_count)
2564 FIXME("Dynamic linking not implemented yet.\n");
2565 if (class_instance_count)
2566 *class_instance_count = 0;
2568 wined3d_mutex_lock();
2569 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2571 wined3d_mutex_unlock();
2572 *shader = NULL;
2573 return;
2576 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2577 wined3d_mutex_unlock();
2578 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2581 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2582 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2584 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2585 unsigned int i;
2587 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2588 iface, start_slot, sampler_count, samplers);
2590 wined3d_mutex_lock();
2591 for (i = 0; i < sampler_count; ++i)
2593 struct wined3d_sampler *wined3d_sampler;
2594 struct d3d_sampler_state *sampler_impl;
2596 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2597 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2599 samplers[i] = NULL;
2600 continue;
2603 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2604 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2606 wined3d_mutex_unlock();
2609 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2610 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2612 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2613 iface, start_slot, buffer_count, buffers);
2615 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2616 buffer_count, buffers);
2619 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2620 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2622 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2623 unsigned int i;
2625 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2627 wined3d_mutex_lock();
2628 for (i = 0; i < view_count; ++i)
2630 struct wined3d_shader_resource_view *wined3d_view;
2631 struct d3d_shader_resource_view *view_impl;
2633 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2634 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2636 views[i] = NULL;
2637 continue;
2640 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2641 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2643 wined3d_mutex_unlock();
2646 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2647 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2649 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2650 unsigned int i;
2652 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2654 wined3d_mutex_lock();
2655 for (i = 0; i < view_count; ++i)
2657 struct wined3d_unordered_access_view *wined3d_view;
2658 struct d3d11_unordered_access_view *view_impl;
2660 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2661 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2663 views[i] = NULL;
2664 continue;
2667 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2668 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2670 wined3d_mutex_unlock();
2673 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2674 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2676 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2677 struct d3d11_compute_shader *shader_impl;
2678 struct wined3d_shader *wined3d_shader;
2680 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2681 iface, shader, class_instances, class_instance_count);
2683 if (class_instances || class_instance_count)
2684 FIXME("Dynamic linking not implemented yet.\n");
2685 if (class_instance_count)
2686 *class_instance_count = 0;
2688 wined3d_mutex_lock();
2689 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2691 wined3d_mutex_unlock();
2692 *shader = NULL;
2693 return;
2696 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2697 wined3d_mutex_unlock();
2698 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2701 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2702 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2704 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2705 unsigned int i;
2707 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2708 iface, start_slot, sampler_count, samplers);
2710 wined3d_mutex_lock();
2711 for (i = 0; i < sampler_count; ++i)
2713 struct wined3d_sampler *wined3d_sampler;
2714 struct d3d_sampler_state *sampler_impl;
2716 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2717 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2719 samplers[i] = NULL;
2720 continue;
2723 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2724 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2726 wined3d_mutex_unlock();
2729 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2730 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2732 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2733 iface, start_slot, buffer_count, buffers);
2735 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2736 buffer_count, buffers);
2739 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2741 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2743 TRACE("iface %p.\n", iface);
2745 wined3d_mutex_lock();
2746 wined3d_device_context_reset_state(context->wined3d_context);
2747 wined3d_mutex_unlock();
2750 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2752 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2754 TRACE("iface %p.\n", iface);
2756 wined3d_mutex_lock();
2757 wined3d_device_context_flush(context->wined3d_context);
2758 wined3d_mutex_unlock();
2761 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2763 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2765 TRACE("iface %p.\n", iface);
2767 return context->type;
2770 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2772 TRACE("iface %p.\n", iface);
2774 return 0;
2777 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2778 BOOL restore, ID3D11CommandList **command_list)
2780 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2781 struct d3d11_command_list *object;
2782 HRESULT hr;
2784 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2786 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2788 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2789 return DXGI_ERROR_INVALID_CALL;
2792 if (!(object = heap_alloc_zero(sizeof(*object))))
2793 return E_OUTOFMEMORY;
2795 wined3d_mutex_lock();
2797 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2798 !!restore, &object->wined3d_list)))
2800 WARN("Failed to record wined3d command list, hr %#x.\n", hr);
2801 heap_free(object);
2802 return hr;
2805 wined3d_mutex_unlock();
2807 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2808 object->refcount = 1;
2809 object->device = &context->device->ID3D11Device2_iface;
2810 wined3d_private_store_init(&object->private_store);
2812 ID3D11Device2_AddRef(object->device);
2814 TRACE("Created command list %p.\n", object);
2815 *command_list = &object->ID3D11CommandList_iface;
2817 return S_OK;
2820 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2821 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2822 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2824 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2825 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2826 struct wined3d_box wined3d_src_box;
2828 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2829 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2830 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2831 src_resource, src_subresource_idx, src_box, flags);
2833 if (!dst_resource || !src_resource)
2834 return;
2836 if (src_box)
2837 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2838 src_box->right, src_box->bottom, src_box->front, src_box->back);
2840 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2841 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2842 wined3d_mutex_lock();
2843 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2844 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2845 wined3d_mutex_unlock();
2848 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2849 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2850 UINT row_pitch, UINT depth_pitch, UINT flags)
2852 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2853 struct wined3d_resource *wined3d_resource;
2854 struct wined3d_box wined3d_box;
2856 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2857 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2859 if (box)
2860 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2861 box->front, box->back);
2863 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2864 wined3d_mutex_lock();
2865 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2866 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2867 wined3d_mutex_unlock();
2870 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2871 ID3D11Resource *resource)
2873 FIXME("iface %p, resource %p stub!\n", iface, resource);
2876 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2878 FIXME("iface %p, view %p stub!\n", iface, view);
2881 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2882 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2883 const UINT *num_constants)
2885 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2886 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2889 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2890 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2891 const UINT *num_constants)
2893 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2894 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2897 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2898 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2899 const UINT *num_constants)
2901 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2902 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2905 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2906 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2907 const UINT *num_constants)
2909 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2910 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2913 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2914 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2915 const UINT *num_constants)
2917 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2918 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2921 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2922 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2923 const UINT *num_constants)
2925 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2926 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2929 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2930 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2932 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2933 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2936 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2937 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2939 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2940 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2943 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2944 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2946 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2947 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2950 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2951 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2953 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2954 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2957 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2958 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2960 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2961 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2964 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2965 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2967 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2968 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2971 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2972 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2974 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2975 struct d3d_device_context_state *state_impl, *prev_impl;
2976 struct d3d_device *device = context->device;
2977 struct wined3d_state *wined3d_state;
2979 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2981 if (prev)
2982 *prev = NULL;
2984 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
2986 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
2987 return;
2990 if (!state)
2991 return;
2993 wined3d_mutex_lock();
2995 prev_impl = device->state;
2996 state_impl = impl_from_ID3DDeviceContextState(state);
2997 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2998 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2999 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
3001 if (prev)
3002 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
3004 d3d_device_context_state_private_addref(state_impl);
3005 device->state = state_impl;
3006 d3d_device_context_state_private_release(prev_impl);
3008 if (d3d_device_is_d3d10_active(device))
3009 FIXME("D3D10 interface emulation not fully implemented yet!\n");
3010 wined3d_mutex_unlock();
3013 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
3014 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
3016 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
3019 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
3020 const D3D11_RECT *rects, UINT num_rects)
3022 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
3025 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
3027 /* IUnknown methods */
3028 d3d11_device_context_QueryInterface,
3029 d3d11_device_context_AddRef,
3030 d3d11_device_context_Release,
3031 /* ID3D11DeviceChild methods */
3032 d3d11_device_context_GetDevice,
3033 d3d11_device_context_GetPrivateData,
3034 d3d11_device_context_SetPrivateData,
3035 d3d11_device_context_SetPrivateDataInterface,
3036 /* ID3D11DeviceContext methods */
3037 d3d11_device_context_VSSetConstantBuffers,
3038 d3d11_device_context_PSSetShaderResources,
3039 d3d11_device_context_PSSetShader,
3040 d3d11_device_context_PSSetSamplers,
3041 d3d11_device_context_VSSetShader,
3042 d3d11_device_context_DrawIndexed,
3043 d3d11_device_context_Draw,
3044 d3d11_device_context_Map,
3045 d3d11_device_context_Unmap,
3046 d3d11_device_context_PSSetConstantBuffers,
3047 d3d11_device_context_IASetInputLayout,
3048 d3d11_device_context_IASetVertexBuffers,
3049 d3d11_device_context_IASetIndexBuffer,
3050 d3d11_device_context_DrawIndexedInstanced,
3051 d3d11_device_context_DrawInstanced,
3052 d3d11_device_context_GSSetConstantBuffers,
3053 d3d11_device_context_GSSetShader,
3054 d3d11_device_context_IASetPrimitiveTopology,
3055 d3d11_device_context_VSSetShaderResources,
3056 d3d11_device_context_VSSetSamplers,
3057 d3d11_device_context_Begin,
3058 d3d11_device_context_End,
3059 d3d11_device_context_GetData,
3060 d3d11_device_context_SetPredication,
3061 d3d11_device_context_GSSetShaderResources,
3062 d3d11_device_context_GSSetSamplers,
3063 d3d11_device_context_OMSetRenderTargets,
3064 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3065 d3d11_device_context_OMSetBlendState,
3066 d3d11_device_context_OMSetDepthStencilState,
3067 d3d11_device_context_SOSetTargets,
3068 d3d11_device_context_DrawAuto,
3069 d3d11_device_context_DrawIndexedInstancedIndirect,
3070 d3d11_device_context_DrawInstancedIndirect,
3071 d3d11_device_context_Dispatch,
3072 d3d11_device_context_DispatchIndirect,
3073 d3d11_device_context_RSSetState,
3074 d3d11_device_context_RSSetViewports,
3075 d3d11_device_context_RSSetScissorRects,
3076 d3d11_device_context_CopySubresourceRegion,
3077 d3d11_device_context_CopyResource,
3078 d3d11_device_context_UpdateSubresource,
3079 d3d11_device_context_CopyStructureCount,
3080 d3d11_device_context_ClearRenderTargetView,
3081 d3d11_device_context_ClearUnorderedAccessViewUint,
3082 d3d11_device_context_ClearUnorderedAccessViewFloat,
3083 d3d11_device_context_ClearDepthStencilView,
3084 d3d11_device_context_GenerateMips,
3085 d3d11_device_context_SetResourceMinLOD,
3086 d3d11_device_context_GetResourceMinLOD,
3087 d3d11_device_context_ResolveSubresource,
3088 d3d11_device_context_ExecuteCommandList,
3089 d3d11_device_context_HSSetShaderResources,
3090 d3d11_device_context_HSSetShader,
3091 d3d11_device_context_HSSetSamplers,
3092 d3d11_device_context_HSSetConstantBuffers,
3093 d3d11_device_context_DSSetShaderResources,
3094 d3d11_device_context_DSSetShader,
3095 d3d11_device_context_DSSetSamplers,
3096 d3d11_device_context_DSSetConstantBuffers,
3097 d3d11_device_context_CSSetShaderResources,
3098 d3d11_device_context_CSSetUnorderedAccessViews,
3099 d3d11_device_context_CSSetShader,
3100 d3d11_device_context_CSSetSamplers,
3101 d3d11_device_context_CSSetConstantBuffers,
3102 d3d11_device_context_VSGetConstantBuffers,
3103 d3d11_device_context_PSGetShaderResources,
3104 d3d11_device_context_PSGetShader,
3105 d3d11_device_context_PSGetSamplers,
3106 d3d11_device_context_VSGetShader,
3107 d3d11_device_context_PSGetConstantBuffers,
3108 d3d11_device_context_IAGetInputLayout,
3109 d3d11_device_context_IAGetVertexBuffers,
3110 d3d11_device_context_IAGetIndexBuffer,
3111 d3d11_device_context_GSGetConstantBuffers,
3112 d3d11_device_context_GSGetShader,
3113 d3d11_device_context_IAGetPrimitiveTopology,
3114 d3d11_device_context_VSGetShaderResources,
3115 d3d11_device_context_VSGetSamplers,
3116 d3d11_device_context_GetPredication,
3117 d3d11_device_context_GSGetShaderResources,
3118 d3d11_device_context_GSGetSamplers,
3119 d3d11_device_context_OMGetRenderTargets,
3120 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3121 d3d11_device_context_OMGetBlendState,
3122 d3d11_device_context_OMGetDepthStencilState,
3123 d3d11_device_context_SOGetTargets,
3124 d3d11_device_context_RSGetState,
3125 d3d11_device_context_RSGetViewports,
3126 d3d11_device_context_RSGetScissorRects,
3127 d3d11_device_context_HSGetShaderResources,
3128 d3d11_device_context_HSGetShader,
3129 d3d11_device_context_HSGetSamplers,
3130 d3d11_device_context_HSGetConstantBuffers,
3131 d3d11_device_context_DSGetShaderResources,
3132 d3d11_device_context_DSGetShader,
3133 d3d11_device_context_DSGetSamplers,
3134 d3d11_device_context_DSGetConstantBuffers,
3135 d3d11_device_context_CSGetShaderResources,
3136 d3d11_device_context_CSGetUnorderedAccessViews,
3137 d3d11_device_context_CSGetShader,
3138 d3d11_device_context_CSGetSamplers,
3139 d3d11_device_context_CSGetConstantBuffers,
3140 d3d11_device_context_ClearState,
3141 d3d11_device_context_Flush,
3142 d3d11_device_context_GetType,
3143 d3d11_device_context_GetContextFlags,
3144 d3d11_device_context_FinishCommandList,
3145 /* ID3D11DeviceContext1 methods */
3146 d3d11_device_context_CopySubresourceRegion1,
3147 d3d11_device_context_UpdateSubresource1,
3148 d3d11_device_context_DiscardResource,
3149 d3d11_device_context_DiscardView,
3150 d3d11_device_context_VSSetConstantBuffers1,
3151 d3d11_device_context_HSSetConstantBuffers1,
3152 d3d11_device_context_DSSetConstantBuffers1,
3153 d3d11_device_context_GSSetConstantBuffers1,
3154 d3d11_device_context_PSSetConstantBuffers1,
3155 d3d11_device_context_CSSetConstantBuffers1,
3156 d3d11_device_context_VSGetConstantBuffers1,
3157 d3d11_device_context_HSGetConstantBuffers1,
3158 d3d11_device_context_DSGetConstantBuffers1,
3159 d3d11_device_context_GSGetConstantBuffers1,
3160 d3d11_device_context_PSGetConstantBuffers1,
3161 d3d11_device_context_CSGetConstantBuffers1,
3162 d3d11_device_context_SwapDeviceContextState,
3163 d3d11_device_context_ClearView,
3164 d3d11_device_context_DiscardView1,
3167 /* ID3D11Multithread methods */
3169 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3171 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3174 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3175 REFIID iid, void **out)
3177 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3179 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3181 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3184 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3186 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3188 TRACE("iface %p.\n", iface);
3190 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3193 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3195 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3197 TRACE("iface %p.\n", iface);
3199 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3202 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3204 TRACE("iface %p.\n", iface);
3206 wined3d_mutex_lock();
3209 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3211 TRACE("iface %p.\n", iface);
3213 wined3d_mutex_unlock();
3216 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3217 ID3D11Multithread *iface, BOOL enable)
3219 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3221 return TRUE;
3224 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3226 FIXME("iface %p stub!\n", iface);
3228 return TRUE;
3231 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3233 d3d11_multithread_QueryInterface,
3234 d3d11_multithread_AddRef,
3235 d3d11_multithread_Release,
3236 d3d11_multithread_Enter,
3237 d3d11_multithread_Leave,
3238 d3d11_multithread_SetMultithreadProtected,
3239 d3d11_multithread_GetMultithreadProtected,
3242 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3243 D3D11_DEVICE_CONTEXT_TYPE type)
3245 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3246 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3247 context->refcount = 1;
3248 context->type = type;
3250 context->device = device;
3251 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3253 wined3d_private_store_init(&context->private_store);
3256 /* ID3D11Device methods */
3258 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3260 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3261 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3264 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3266 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3267 return IUnknown_AddRef(device->outer_unk);
3270 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3272 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3273 return IUnknown_Release(device->outer_unk);
3276 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3277 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3279 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3280 struct d3d_buffer *object;
3281 HRESULT hr;
3283 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3285 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3286 return hr;
3288 *buffer = &object->ID3D11Buffer_iface;
3290 return S_OK;
3293 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3294 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3296 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3297 struct d3d_texture1d *object;
3298 HRESULT hr;
3300 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3302 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3303 return hr;
3305 *texture = &object->ID3D11Texture1D_iface;
3307 return S_OK;
3310 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3311 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3313 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3314 struct d3d_texture2d *object;
3315 HRESULT hr;
3317 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3319 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3320 return hr;
3322 *texture = &object->ID3D11Texture2D_iface;
3324 return S_OK;
3327 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3328 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3330 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3331 struct d3d_texture3d *object;
3332 HRESULT hr;
3334 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3336 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3337 return hr;
3339 *texture = &object->ID3D11Texture3D_iface;
3341 return S_OK;
3344 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3345 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3347 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3348 struct d3d_shader_resource_view *object;
3349 HRESULT hr;
3351 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3353 if (!resource)
3354 return E_INVALIDARG;
3356 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3357 return hr;
3359 *view = &object->ID3D11ShaderResourceView_iface;
3361 return S_OK;
3364 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3365 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3367 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3368 struct d3d11_unordered_access_view *object;
3369 HRESULT hr;
3371 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3373 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3374 return hr;
3376 *view = &object->ID3D11UnorderedAccessView_iface;
3378 return S_OK;
3381 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3382 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3384 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3385 struct d3d_rendertarget_view *object;
3386 HRESULT hr;
3388 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3390 if (!resource)
3391 return E_INVALIDARG;
3393 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3394 return hr;
3396 *view = &object->ID3D11RenderTargetView_iface;
3398 return S_OK;
3401 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3402 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3404 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3405 struct d3d_depthstencil_view *object;
3406 HRESULT hr;
3408 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3410 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3411 return hr;
3413 *view = &object->ID3D11DepthStencilView_iface;
3415 return S_OK;
3418 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3419 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3420 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3422 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3423 struct d3d_input_layout *object;
3424 HRESULT hr;
3426 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3427 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3428 shader_byte_code_length, input_layout);
3430 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3431 shader_byte_code, shader_byte_code_length, &object)))
3432 return hr;
3434 *input_layout = &object->ID3D11InputLayout_iface;
3436 return S_OK;
3439 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3440 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3442 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3443 struct d3d_vertex_shader *object;
3444 HRESULT hr;
3446 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3447 iface, byte_code, byte_code_length, class_linkage, shader);
3449 if (class_linkage)
3450 FIXME("Class linkage is not implemented yet.\n");
3452 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3453 return hr;
3455 *shader = &object->ID3D11VertexShader_iface;
3457 return S_OK;
3460 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3461 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3463 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3464 struct d3d_geometry_shader *object;
3465 HRESULT hr;
3467 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3468 iface, byte_code, byte_code_length, class_linkage, shader);
3470 if (class_linkage)
3471 FIXME("Class linkage is not implemented yet.\n");
3473 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3474 NULL, 0, NULL, 0, 0, &object)))
3475 return hr;
3477 *shader = &object->ID3D11GeometryShader_iface;
3479 return S_OK;
3482 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3483 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3484 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3485 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3487 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3488 struct d3d_geometry_shader *object;
3489 HRESULT hr;
3491 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3492 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3493 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3494 rasterizer_stream, class_linkage, shader);
3496 if (class_linkage)
3497 FIXME("Class linkage is not implemented yet.\n");
3499 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3500 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3502 *shader = NULL;
3503 return hr;
3506 *shader = &object->ID3D11GeometryShader_iface;
3508 return hr;
3511 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3512 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3514 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3515 struct d3d_pixel_shader *object;
3516 HRESULT hr;
3518 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3519 iface, byte_code, byte_code_length, class_linkage, shader);
3521 if (class_linkage)
3522 FIXME("Class linkage is not implemented yet.\n");
3524 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3525 return hr;
3527 *shader = &object->ID3D11PixelShader_iface;
3529 return S_OK;
3532 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3533 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3535 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3536 struct d3d11_hull_shader *object;
3537 HRESULT hr;
3539 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3540 iface, byte_code, byte_code_length, class_linkage, shader);
3542 if (class_linkage)
3543 FIXME("Class linkage is not implemented yet.\n");
3545 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3546 return hr;
3548 *shader = &object->ID3D11HullShader_iface;
3550 return S_OK;
3553 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3554 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3556 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3557 struct d3d11_domain_shader *object;
3558 HRESULT hr;
3560 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3561 iface, byte_code, byte_code_length, class_linkage, shader);
3563 if (class_linkage)
3564 FIXME("Class linkage is not implemented yet.\n");
3566 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3567 return hr;
3569 *shader = &object->ID3D11DomainShader_iface;
3571 return S_OK;
3574 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3575 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3577 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3578 struct d3d11_compute_shader *object;
3579 HRESULT hr;
3581 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3582 iface, byte_code, byte_code_length, class_linkage, shader);
3584 if (class_linkage)
3585 FIXME("Class linkage is not implemented yet.\n");
3587 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3588 return hr;
3590 *shader = &object->ID3D11ComputeShader_iface;
3592 return S_OK;
3595 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3596 ID3D11ClassLinkage **class_linkage)
3598 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3599 struct d3d11_class_linkage *object;
3600 HRESULT hr;
3602 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3604 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3605 return hr;
3607 *class_linkage = &object->ID3D11ClassLinkage_iface;
3609 return S_OK;
3612 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3613 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3615 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3616 struct d3d_blend_state *object;
3617 HRESULT hr;
3619 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3621 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3622 return hr;
3624 *blend_state = &object->ID3D11BlendState_iface;
3626 return S_OK;
3629 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3630 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3632 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3633 struct d3d_depthstencil_state *object;
3634 HRESULT hr;
3636 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3638 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3639 return hr;
3641 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3643 return S_OK;
3646 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3647 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3649 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3650 struct d3d_rasterizer_state *object;
3651 HRESULT hr;
3653 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3655 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3656 return hr;
3658 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3660 return S_OK;
3663 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3664 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3666 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3667 struct d3d_sampler_state *object;
3668 HRESULT hr;
3670 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3672 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3673 return hr;
3675 *sampler_state = &object->ID3D11SamplerState_iface;
3677 return S_OK;
3680 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3681 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3683 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3684 struct d3d_query *object;
3685 HRESULT hr;
3687 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3689 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3690 return hr;
3692 if (query)
3694 *query = &object->ID3D11Query_iface;
3695 return S_OK;
3698 ID3D11Query_Release(&object->ID3D11Query_iface);
3699 return S_FALSE;
3702 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3703 ID3D11Predicate **predicate)
3705 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3706 struct d3d_query *object;
3707 HRESULT hr;
3709 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3711 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3712 return hr;
3714 if (predicate)
3716 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3717 return S_OK;
3720 ID3D11Query_Release(&object->ID3D11Query_iface);
3721 return S_FALSE;
3724 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3725 ID3D11Counter **counter)
3727 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3729 return E_NOTIMPL;
3732 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3733 UINT flags, struct d3d11_device_context **context)
3735 struct d3d11_device_context *object;
3736 HRESULT hr;
3738 if (flags)
3739 FIXME("Ignoring flags %#x.\n", flags);
3741 if (!(object = heap_alloc_zero(sizeof(*object))))
3742 return E_OUTOFMEMORY;
3743 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3745 wined3d_mutex_lock();
3746 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3748 WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
3749 heap_free(object);
3750 wined3d_mutex_unlock();
3751 return hr;
3753 wined3d_mutex_unlock();
3755 TRACE("Created deferred context %p.\n", object);
3756 *context = object;
3758 return S_OK;
3761 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3762 ID3D11DeviceContext **context)
3764 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3765 struct d3d11_device_context *object;
3766 HRESULT hr;
3768 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3770 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3771 return hr;
3773 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3774 return S_OK;
3777 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3778 void **out)
3780 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3782 return E_NOTIMPL;
3785 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3786 UINT *format_support)
3788 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3789 struct wined3d_device_creation_parameters params;
3790 struct wined3d_adapter *wined3d_adapter;
3791 enum wined3d_format_id wined3d_format;
3792 D3D_FEATURE_LEVEL feature_level;
3793 struct wined3d *wined3d;
3794 unsigned int i;
3796 static const struct
3798 enum wined3d_resource_type rtype;
3799 unsigned int bind_flags;
3800 unsigned int usage;
3801 D3D11_FORMAT_SUPPORT flag;
3803 flag_mapping[] =
3805 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3806 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3807 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3808 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3809 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3810 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3811 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3812 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3813 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3814 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3816 HRESULT hr;
3818 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3820 wined3d_format = wined3dformat_from_dxgi_format(format);
3821 if (format && !wined3d_format)
3823 WARN("Invalid format %#x.\n", format);
3824 *format_support = 0;
3825 return E_FAIL;
3828 *format_support = 0;
3830 wined3d_mutex_lock();
3831 feature_level = device->state->feature_level;
3832 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3833 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3834 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3835 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3837 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3838 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3839 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3840 continue;
3841 if (hr != WINED3D_OK)
3843 WARN("Failed to check device format support, hr %#x.\n", hr);
3844 wined3d_mutex_unlock();
3845 return E_FAIL;
3848 *format_support |= flag_mapping[i].flag;
3850 wined3d_mutex_unlock();
3852 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3853 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3855 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3856 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3858 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3859 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3860 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3862 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3863 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3865 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3867 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3868 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3870 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3871 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3875 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3876 * support multisample. */
3877 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3878 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3879 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3880 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3882 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3883 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3884 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3887 return S_OK;
3890 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3891 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3893 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3894 struct wined3d_device_creation_parameters params;
3895 struct wined3d_adapter *wined3d_adapter;
3896 struct wined3d *wined3d;
3897 HRESULT hr;
3899 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3900 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3902 if (!quality_level_count)
3903 return E_INVALIDARG;
3905 *quality_level_count = 0;
3907 if (!sample_count)
3908 return E_FAIL;
3909 if (sample_count == 1)
3911 *quality_level_count = 1;
3912 return S_OK;
3914 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3915 return E_FAIL;
3917 wined3d_mutex_lock();
3918 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3919 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3920 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3921 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3922 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3923 wined3d_mutex_unlock();
3925 if (hr == WINED3DERR_INVALIDCALL)
3926 return E_INVALIDARG;
3927 if (hr == WINED3DERR_NOTAVAILABLE)
3928 return S_OK;
3929 return hr;
3932 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3934 FIXME("iface %p, info %p stub!\n", iface, info);
3937 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3938 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3939 char *units, UINT *units_length, char *description, UINT *description_length)
3941 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3942 "units %p, units_length %p, description %p, description_length %p stub!\n",
3943 iface, desc, type, active_counter_count, name, name_length,
3944 units, units_length, description, description_length);
3946 return E_NOTIMPL;
3949 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3950 void *feature_support_data, UINT feature_support_data_size)
3952 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3953 struct wined3d_caps wined3d_caps;
3954 HRESULT hr;
3956 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3957 iface, feature, feature_support_data, feature_support_data_size);
3959 switch (feature)
3961 case D3D11_FEATURE_THREADING:
3963 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3964 if (feature_support_data_size != sizeof(*threading_data))
3966 WARN("Invalid data size.\n");
3967 return E_INVALIDARG;
3970 /* We lie about the threading support to make Tomb Raider 2013 and
3971 * Deus Ex: Human Revolution happy. */
3972 FIXME("Returning fake threading support data.\n");
3973 threading_data->DriverConcurrentCreates = TRUE;
3974 threading_data->DriverCommandLists = TRUE;
3975 return S_OK;
3978 case D3D11_FEATURE_DOUBLES:
3980 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3981 if (feature_support_data_size != sizeof(*doubles_data))
3983 WARN("Invalid data size.\n");
3984 return E_INVALIDARG;
3987 wined3d_mutex_lock();
3988 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3989 wined3d_mutex_unlock();
3990 if (FAILED(hr))
3992 WARN("Failed to get device caps, hr %#x.\n", hr);
3993 return hr;
3996 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3997 return S_OK;
4000 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
4002 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
4003 if (feature_support_data_size != sizeof(*options))
4005 WARN("Invalid data size.\n");
4006 return E_INVALIDARG;
4009 wined3d_mutex_lock();
4010 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4011 wined3d_mutex_unlock();
4012 if (FAILED(hr))
4014 WARN("Failed to get device caps, hr %#x.\n", hr);
4015 return hr;
4018 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
4019 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4020 return S_OK;
4023 case D3D11_FEATURE_D3D11_OPTIONS:
4025 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4026 if (feature_support_data_size != sizeof(*options))
4028 WARN("Invalid data size.\n");
4029 return E_INVALIDARG;
4032 FIXME("Returning fake Options support data.\n");
4033 options->OutputMergerLogicOp = FALSE;
4034 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4035 options->DiscardAPIsSeenByDriver = FALSE;
4036 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4037 options->ClearView = FALSE;
4038 options->CopyWithOverlap = FALSE;
4039 options->ConstantBufferPartialUpdate = FALSE;
4040 options->ConstantBufferOffsetting = FALSE;
4041 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
4042 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
4043 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4044 options->SAD4ShaderInstructions = FALSE;
4045 options->ExtendedDoublesShaderInstructions = FALSE;
4046 options->ExtendedResourceSharing = FALSE;
4047 return S_OK;
4050 case D3D11_FEATURE_D3D11_OPTIONS1:
4052 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4053 if (feature_support_data_size != sizeof(*options))
4055 WARN("Invalid data size.\n");
4056 return E_INVALIDARG;
4059 FIXME("Returning fake Options1 support data.\n");
4060 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4061 options->MinMaxFiltering = FALSE;
4062 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4063 options->MapOnDefaultBuffers = FALSE;
4064 return S_OK;
4067 case D3D11_FEATURE_D3D11_OPTIONS3:
4069 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4070 if (feature_support_data_size != sizeof(*options))
4072 WARN("Invalid data size.\n");
4073 return E_INVALIDARG;
4076 wined3d_mutex_lock();
4077 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4078 wined3d_mutex_unlock();
4079 if (FAILED(hr))
4081 WARN("Failed to get device caps, hr %#x.\n", hr);
4082 return hr;
4085 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4086 = wined3d_caps.viewport_array_index_any_shader;
4087 return S_OK;
4090 case D3D11_FEATURE_ARCHITECTURE_INFO:
4092 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4093 if (feature_support_data_size != sizeof(*options))
4095 WARN("Invalid data size.\n");
4096 return E_INVALIDARG;
4099 FIXME("Returning fake data architecture info.\n");
4100 options->TileBasedDeferredRenderer = FALSE;
4101 return S_OK;
4104 default:
4105 FIXME("Unhandled feature %#x.\n", feature);
4106 return E_NOTIMPL;
4110 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4111 UINT *data_size, void *data)
4113 IDXGIDevice *dxgi_device;
4114 HRESULT hr;
4116 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4118 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4119 return hr;
4120 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4121 IDXGIDevice_Release(dxgi_device);
4123 return hr;
4126 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4127 UINT data_size, const void *data)
4129 IDXGIDevice *dxgi_device;
4130 HRESULT hr;
4132 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4134 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4135 return hr;
4136 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4137 IDXGIDevice_Release(dxgi_device);
4139 return hr;
4142 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4143 const IUnknown *data)
4145 IDXGIDevice *dxgi_device;
4146 HRESULT hr;
4148 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4150 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4151 return hr;
4152 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4153 IDXGIDevice_Release(dxgi_device);
4155 return hr;
4158 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4160 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4162 TRACE("iface %p.\n", iface);
4164 return device->state->feature_level;
4167 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4169 FIXME("iface %p stub!\n", iface);
4171 return 0;
4174 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4176 WARN("iface %p stub!\n", iface);
4178 return S_OK;
4181 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4182 ID3D11DeviceContext **immediate_context)
4184 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4186 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4188 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4189 ID3D11DeviceContext_AddRef(*immediate_context);
4192 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4194 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4196 return E_NOTIMPL;
4199 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4201 FIXME("iface %p stub!\n", iface);
4203 return 0;
4206 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4207 ID3D11DeviceContext1 **immediate_context)
4209 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4211 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4213 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4214 ID3D11DeviceContext1_AddRef(*immediate_context);
4217 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4218 ID3D11DeviceContext1 **context)
4220 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4221 struct d3d11_device_context *object;
4222 HRESULT hr;
4224 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4226 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4227 return hr;
4229 *context = &object->ID3D11DeviceContext1_iface;
4230 return S_OK;
4233 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4234 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4236 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4238 return E_NOTIMPL;
4241 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4242 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4244 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4246 return E_NOTIMPL;
4249 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4250 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4251 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4253 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4254 struct d3d_device_context_state *state_impl;
4255 struct wined3d_state *wined3d_state;
4256 D3D_FEATURE_LEVEL feature_level;
4257 HRESULT hr = E_INVALIDARG;
4259 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4260 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4261 iface, flags, feature_levels, feature_level_count,
4262 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4264 if (flags)
4265 FIXME("Ignoring flags %#x.\n", flags);
4267 wined3d_mutex_lock();
4269 if (!feature_level_count)
4270 goto fail;
4272 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4273 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4274 goto fail;
4275 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4277 if (chosen_feature_level)
4278 *chosen_feature_level = feature_level;
4280 if (!state)
4282 wined3d_state_destroy(wined3d_state);
4283 wined3d_mutex_unlock();
4284 return S_FALSE;
4287 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4289 wined3d_state_destroy(wined3d_state);
4290 hr = E_OUTOFMEMORY;
4291 goto fail;
4294 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4295 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4297 wined3d_state_destroy(wined3d_state);
4298 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4299 hr = E_FAIL;
4300 goto fail;
4303 *state = &state_impl->ID3DDeviceContextState_iface;
4304 device->d3d11_only = FALSE;
4305 wined3d_mutex_unlock();
4307 return S_OK;
4309 fail:
4310 wined3d_mutex_unlock();
4311 if (chosen_feature_level)
4312 *chosen_feature_level = 0;
4313 if (state)
4314 *state = NULL;
4315 return hr;
4318 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4319 REFIID iid, void **resource)
4321 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4323 return E_NOTIMPL;
4326 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4327 DWORD access, REFIID iid, void **resource)
4329 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4330 debugstr_guid(iid), resource);
4332 return E_NOTIMPL;
4335 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4336 ID3D11DeviceContext2 **context)
4338 FIXME("iface %p, context %p stub!\n", iface, context);
4341 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4342 UINT flags, ID3D11DeviceContext2 **context)
4344 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4346 return E_NOTIMPL;
4349 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4350 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4351 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4352 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4354 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4355 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4356 iface, resource, tile_count, mip_desc, tile_shape,
4357 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4360 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4361 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4363 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4364 iface, format, sample_count, flags, quality_level_count);
4366 return E_NOTIMPL;
4369 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4371 /* IUnknown methods */
4372 d3d11_device_QueryInterface,
4373 d3d11_device_AddRef,
4374 d3d11_device_Release,
4375 /* ID3D11Device methods */
4376 d3d11_device_CreateBuffer,
4377 d3d11_device_CreateTexture1D,
4378 d3d11_device_CreateTexture2D,
4379 d3d11_device_CreateTexture3D,
4380 d3d11_device_CreateShaderResourceView,
4381 d3d11_device_CreateUnorderedAccessView,
4382 d3d11_device_CreateRenderTargetView,
4383 d3d11_device_CreateDepthStencilView,
4384 d3d11_device_CreateInputLayout,
4385 d3d11_device_CreateVertexShader,
4386 d3d11_device_CreateGeometryShader,
4387 d3d11_device_CreateGeometryShaderWithStreamOutput,
4388 d3d11_device_CreatePixelShader,
4389 d3d11_device_CreateHullShader,
4390 d3d11_device_CreateDomainShader,
4391 d3d11_device_CreateComputeShader,
4392 d3d11_device_CreateClassLinkage,
4393 d3d11_device_CreateBlendState,
4394 d3d11_device_CreateDepthStencilState,
4395 d3d11_device_CreateRasterizerState,
4396 d3d11_device_CreateSamplerState,
4397 d3d11_device_CreateQuery,
4398 d3d11_device_CreatePredicate,
4399 d3d11_device_CreateCounter,
4400 d3d11_device_CreateDeferredContext,
4401 d3d11_device_OpenSharedResource,
4402 d3d11_device_CheckFormatSupport,
4403 d3d11_device_CheckMultisampleQualityLevels,
4404 d3d11_device_CheckCounterInfo,
4405 d3d11_device_CheckCounter,
4406 d3d11_device_CheckFeatureSupport,
4407 d3d11_device_GetPrivateData,
4408 d3d11_device_SetPrivateData,
4409 d3d11_device_SetPrivateDataInterface,
4410 d3d11_device_GetFeatureLevel,
4411 d3d11_device_GetCreationFlags,
4412 d3d11_device_GetDeviceRemovedReason,
4413 d3d11_device_GetImmediateContext,
4414 d3d11_device_SetExceptionMode,
4415 d3d11_device_GetExceptionMode,
4416 /* ID3D11Device1 methods */
4417 d3d11_device_GetImmediateContext1,
4418 d3d11_device_CreateDeferredContext1,
4419 d3d11_device_CreateBlendState1,
4420 d3d11_device_CreateRasterizerState1,
4421 d3d11_device_CreateDeviceContextState,
4422 d3d11_device_OpenSharedResource1,
4423 d3d11_device_OpenSharedResourceByName,
4424 /* ID3D11Device2 methods */
4425 d3d11_device_GetImmediateContext2,
4426 d3d11_device_CreateDeferredContext2,
4427 d3d11_device_GetResourceTiling,
4428 d3d11_device_CheckMultisampleQualityLevels1,
4431 /* Inner IUnknown methods */
4433 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4435 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4438 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4440 struct d3d_device *device = impl_from_IUnknown(iface);
4442 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4444 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4445 || IsEqualGUID(riid, &IID_ID3D11Device1)
4446 || IsEqualGUID(riid, &IID_ID3D11Device)
4447 || IsEqualGUID(riid, &IID_IUnknown))
4449 *out = &device->ID3D11Device2_iface;
4451 else if (!device->d3d11_only
4452 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4453 || IsEqualGUID(riid, &IID_ID3D10Device)))
4455 *out = &device->ID3D10Device1_iface;
4457 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4459 *out = &device->ID3D10Multithread_iface;
4461 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4463 *out = &device->IWineDXGIDeviceParent_iface;
4465 else
4467 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4468 *out = NULL;
4469 return E_NOINTERFACE;
4472 IUnknown_AddRef((IUnknown *)*out);
4473 return S_OK;
4476 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4478 struct d3d_device *device = impl_from_IUnknown(iface);
4479 ULONG refcount = InterlockedIncrement(&device->refcount);
4481 TRACE("%p increasing refcount to %u.\n", device, refcount);
4483 return refcount;
4486 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4488 struct d3d_device *device = impl_from_IUnknown(iface);
4489 ULONG refcount = InterlockedDecrement(&device->refcount);
4490 unsigned int i;
4492 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4494 if (!refcount)
4496 if (device->state)
4497 d3d_device_context_state_private_release(device->state);
4498 for (i = 0; i < device->context_state_count; ++i)
4500 d3d_device_context_state_remove_entry(device->context_states[i], device);
4502 heap_free(device->context_states);
4503 d3d11_device_context_cleanup(&device->immediate_context);
4504 if (device->wined3d_device)
4506 wined3d_mutex_lock();
4507 wined3d_device_decref(device->wined3d_device);
4508 wined3d_mutex_unlock();
4510 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4511 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4512 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4513 wine_rb_destroy(&device->blend_states, NULL, NULL);
4516 return refcount;
4519 /* IUnknown methods */
4521 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4522 void **out)
4524 struct d3d_device *device = impl_from_ID3D10Device(iface);
4525 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4528 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4530 struct d3d_device *device = impl_from_ID3D10Device(iface);
4531 return IUnknown_AddRef(device->outer_unk);
4534 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4536 struct d3d_device *device = impl_from_ID3D10Device(iface);
4537 return IUnknown_Release(device->outer_unk);
4540 /* ID3D10Device methods */
4542 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4543 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4545 struct d3d_device *device = impl_from_ID3D10Device(iface);
4546 unsigned int i;
4548 wined3d_mutex_lock();
4549 for (i = 0; i < buffer_count; ++i)
4551 struct wined3d_buffer *wined3d_buffer;
4552 struct d3d_buffer *buffer_impl;
4554 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4555 type, start_slot + i)))
4557 buffers[i] = NULL;
4558 continue;
4561 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4562 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4563 ID3D10Buffer_AddRef(buffers[i]);
4565 wined3d_mutex_unlock();
4568 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4569 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4571 struct d3d_device *device = impl_from_ID3D10Device(iface);
4572 unsigned int i;
4574 wined3d_mutex_lock();
4575 for (i = 0; i < buffer_count; ++i)
4577 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4579 wined3d_device_context_set_constant_buffer(device->immediate_context.wined3d_context, type, start_slot + i,
4580 buffer ? buffer->wined3d_buffer : NULL);
4582 wined3d_mutex_unlock();
4585 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4586 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4588 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4589 iface, start_slot, buffer_count, buffers);
4591 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4592 buffer_count, buffers);
4595 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4596 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4598 struct d3d_device *device = impl_from_ID3D10Device(iface);
4599 unsigned int i;
4601 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4602 iface, start_slot, view_count, views);
4604 wined3d_mutex_lock();
4605 for (i = 0; i < view_count; ++i)
4607 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4609 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4610 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, view ? view->wined3d_view : NULL);
4612 wined3d_mutex_unlock();
4615 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4616 ID3D10PixelShader *shader)
4618 struct d3d_device *device = impl_from_ID3D10Device(iface);
4619 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4621 TRACE("iface %p, shader %p\n", iface, shader);
4623 wined3d_mutex_lock();
4624 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4625 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4626 wined3d_mutex_unlock();
4629 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4630 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4632 struct d3d_device *device = impl_from_ID3D10Device(iface);
4633 unsigned int i;
4635 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4636 iface, start_slot, sampler_count, samplers);
4638 wined3d_mutex_lock();
4639 for (i = 0; i < sampler_count; ++i)
4641 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4643 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4644 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4646 wined3d_mutex_unlock();
4649 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4650 ID3D10VertexShader *shader)
4652 struct d3d_device *device = impl_from_ID3D10Device(iface);
4653 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4655 TRACE("iface %p, shader %p\n", iface, shader);
4657 wined3d_mutex_lock();
4658 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4659 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4660 wined3d_mutex_unlock();
4663 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4664 UINT start_index_location, INT base_vertex_location)
4666 struct d3d_device *device = impl_from_ID3D10Device(iface);
4668 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4669 iface, index_count, start_index_location, base_vertex_location);
4671 wined3d_mutex_lock();
4672 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4673 base_vertex_location, start_index_location, index_count, 0, 0);
4674 wined3d_mutex_unlock();
4677 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4678 UINT start_vertex_location)
4680 struct d3d_device *device = impl_from_ID3D10Device(iface);
4682 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4683 iface, vertex_count, start_vertex_location);
4685 wined3d_mutex_lock();
4686 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4687 wined3d_mutex_unlock();
4690 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4691 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4693 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4694 iface, start_slot, buffer_count, buffers);
4696 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4697 buffer_count, buffers);
4700 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4701 ID3D10InputLayout *input_layout)
4703 struct d3d_device *device = impl_from_ID3D10Device(iface);
4704 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4706 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4708 wined3d_mutex_lock();
4709 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4710 layout ? layout->wined3d_decl : NULL);
4711 wined3d_mutex_unlock();
4714 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4715 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4717 struct d3d_device *device = impl_from_ID3D10Device(iface);
4718 unsigned int i;
4720 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4721 iface, start_slot, buffer_count, buffers, strides, offsets);
4723 wined3d_mutex_lock();
4724 for (i = 0; i < buffer_count; ++i)
4726 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4728 wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
4729 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
4731 wined3d_mutex_unlock();
4734 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4735 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4737 struct d3d_device *device = impl_from_ID3D10Device(iface);
4738 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4740 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4741 iface, buffer, debug_dxgi_format(format), offset);
4743 wined3d_mutex_lock();
4744 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4745 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4746 wined3dformat_from_dxgi_format(format), offset);
4747 wined3d_mutex_unlock();
4750 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4751 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4752 INT base_vertex_location, UINT start_instance_location)
4754 struct d3d_device *device = impl_from_ID3D10Device(iface);
4756 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4757 "base_vertex_location %d, start_instance_location %u.\n",
4758 iface, instance_index_count, instance_count, start_index_location,
4759 base_vertex_location, start_instance_location);
4761 wined3d_mutex_lock();
4762 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4763 start_index_location, instance_index_count, start_instance_location, instance_count);
4764 wined3d_mutex_unlock();
4767 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4768 UINT instance_vertex_count, UINT instance_count,
4769 UINT start_vertex_location, UINT start_instance_location)
4771 struct d3d_device *device = impl_from_ID3D10Device(iface);
4773 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4774 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4775 start_vertex_location, start_instance_location);
4777 wined3d_mutex_lock();
4778 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4779 instance_vertex_count, start_instance_location, instance_count);
4780 wined3d_mutex_unlock();
4783 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4784 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4786 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4787 iface, start_slot, buffer_count, buffers);
4789 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4790 buffer_count, buffers);
4793 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4795 struct d3d_device *device = impl_from_ID3D10Device(iface);
4796 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4798 TRACE("iface %p, shader %p.\n", iface, shader);
4800 wined3d_mutex_lock();
4801 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4802 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4803 wined3d_mutex_unlock();
4806 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4807 D3D10_PRIMITIVE_TOPOLOGY topology)
4809 struct d3d_device *device = impl_from_ID3D10Device(iface);
4811 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4813 wined3d_mutex_lock();
4814 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4815 (enum wined3d_primitive_type)topology, 0);
4816 wined3d_mutex_unlock();
4819 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4820 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4822 struct d3d_device *device = impl_from_ID3D10Device(iface);
4823 unsigned int i;
4825 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4826 iface, start_slot, view_count, views);
4828 wined3d_mutex_lock();
4829 for (i = 0; i < view_count; ++i)
4831 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4833 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4834 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, view ? view->wined3d_view : NULL);
4836 wined3d_mutex_unlock();
4839 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4840 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4842 struct d3d_device *device = impl_from_ID3D10Device(iface);
4843 unsigned int i;
4845 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4846 iface, start_slot, sampler_count, samplers);
4848 wined3d_mutex_lock();
4849 for (i = 0; i < sampler_count; ++i)
4851 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4853 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4854 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4856 wined3d_mutex_unlock();
4859 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4861 struct d3d_device *device = impl_from_ID3D10Device(iface);
4862 struct d3d_query *query;
4864 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4866 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4867 wined3d_mutex_lock();
4868 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4869 query ? query->wined3d_query : NULL, value);
4870 wined3d_mutex_unlock();
4873 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4874 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4876 struct d3d_device *device = impl_from_ID3D10Device(iface);
4877 unsigned int i;
4879 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4880 iface, start_slot, view_count, views);
4882 wined3d_mutex_lock();
4883 for (i = 0; i < view_count; ++i)
4885 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4887 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4888 WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i, view ? view->wined3d_view : NULL);
4890 wined3d_mutex_unlock();
4893 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4894 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4896 struct d3d_device *device = impl_from_ID3D10Device(iface);
4897 unsigned int i;
4899 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4900 iface, start_slot, sampler_count, samplers);
4902 wined3d_mutex_lock();
4903 for (i = 0; i < sampler_count; ++i)
4905 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4907 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
4908 start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4910 wined3d_mutex_unlock();
4913 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4914 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4915 ID3D10DepthStencilView *depth_stencil_view)
4917 struct d3d_device *device = impl_from_ID3D10Device(iface);
4918 struct d3d_depthstencil_view *dsv;
4919 unsigned int i;
4921 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4922 iface, render_target_view_count, render_target_views, depth_stencil_view);
4924 wined3d_mutex_lock();
4925 for (i = 0; i < render_target_view_count; ++i)
4927 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4929 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
4930 rtv ? rtv->wined3d_view : NULL, FALSE);
4932 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4934 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
4937 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4938 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4939 dsv ? dsv->wined3d_view : NULL);
4940 wined3d_mutex_unlock();
4943 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4944 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4946 struct d3d_device *device = impl_from_ID3D10Device(iface);
4947 struct d3d_blend_state *blend_state_object;
4949 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4950 iface, blend_state, debug_float4(blend_factor), sample_mask);
4952 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4953 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4954 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4957 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4958 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4960 struct d3d_device *device = impl_from_ID3D10Device(iface);
4961 struct d3d_depthstencil_state *ds_state_object;
4963 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4964 iface, depth_stencil_state, stencil_ref);
4966 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4967 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4968 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4971 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4972 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4974 struct d3d_device *device = impl_from_ID3D10Device(iface);
4975 unsigned int count, i;
4977 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4979 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4980 wined3d_mutex_lock();
4981 for (i = 0; i < count; ++i)
4983 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4985 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i,
4986 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4989 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4991 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i, NULL, 0);
4993 wined3d_mutex_unlock();
4996 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4998 FIXME("iface %p stub!\n", iface);
5001 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
5003 struct d3d_device *device = impl_from_ID3D10Device(iface);
5004 struct d3d_rasterizer_state *rasterizer_state_object;
5006 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5008 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5009 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5010 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
5013 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
5014 UINT viewport_count, const D3D10_VIEWPORT *viewports)
5016 struct d3d_device *device = impl_from_ID3D10Device(iface);
5017 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5018 unsigned int i;
5020 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5022 if (viewport_count > ARRAY_SIZE(wined3d_vp))
5023 return;
5025 for (i = 0; i < viewport_count; ++i)
5027 wined3d_vp[i].x = viewports[i].TopLeftX;
5028 wined3d_vp[i].y = viewports[i].TopLeftY;
5029 wined3d_vp[i].width = viewports[i].Width;
5030 wined3d_vp[i].height = viewports[i].Height;
5031 wined3d_vp[i].min_z = viewports[i].MinDepth;
5032 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5035 wined3d_mutex_lock();
5036 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5037 wined3d_mutex_unlock();
5040 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
5041 UINT rect_count, const D3D10_RECT *rects)
5043 struct d3d_device *device = impl_from_ID3D10Device(iface);
5045 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5047 if (rect_count > WINED3D_MAX_VIEWPORTS)
5048 return;
5050 wined3d_mutex_lock();
5051 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5052 wined3d_mutex_unlock();
5055 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5056 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5057 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5059 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5060 struct d3d_device *device = impl_from_ID3D10Device(iface);
5061 struct wined3d_box wined3d_src_box;
5063 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5064 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5065 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5066 src_resource, src_subresource_idx, src_box);
5068 if (!dst_resource || !src_resource)
5069 return;
5071 if (src_box)
5072 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5073 src_box->right, src_box->bottom, src_box->front, src_box->back);
5075 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5076 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5077 wined3d_mutex_lock();
5078 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5079 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5080 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5081 wined3d_mutex_unlock();
5084 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5085 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5087 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5088 struct d3d_device *device = impl_from_ID3D10Device(iface);
5090 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5092 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5093 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5094 wined3d_mutex_lock();
5095 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5096 wined3d_dst_resource, wined3d_src_resource);
5097 wined3d_mutex_unlock();
5100 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5101 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5102 const void *data, UINT row_pitch, UINT depth_pitch)
5104 struct d3d_device *device = impl_from_ID3D10Device(iface);
5105 ID3D11Resource *d3d11_resource;
5107 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5108 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5110 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5111 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5112 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5113 ID3D11Resource_Release(d3d11_resource);
5116 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5117 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5119 struct d3d_device *device = impl_from_ID3D10Device(iface);
5120 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5121 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5122 HRESULT hr;
5124 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5125 iface, render_target_view, debug_float4(color_rgba));
5127 if (!view)
5128 return;
5130 wined3d_mutex_lock();
5131 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5132 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5133 ERR("Failed to clear view, hr %#x.\n", hr);
5134 wined3d_mutex_unlock();
5137 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5138 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5140 struct d3d_device *device = impl_from_ID3D10Device(iface);
5141 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5142 DWORD wined3d_flags;
5143 HRESULT hr;
5145 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5146 iface, depth_stencil_view, flags, depth, stencil);
5148 if (!view)
5149 return;
5151 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5153 wined3d_mutex_lock();
5154 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5155 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5156 ERR("Failed to clear view, hr %#x.\n", hr);
5157 wined3d_mutex_unlock();
5160 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5161 ID3D10ShaderResourceView *view)
5163 struct d3d_device *device = impl_from_ID3D10Device(iface);
5164 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5166 TRACE("iface %p, view %p.\n", iface, view);
5168 wined3d_mutex_lock();
5169 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5170 wined3d_mutex_unlock();
5173 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5174 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5175 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5177 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5178 struct d3d_device *device = impl_from_ID3D10Device(iface);
5179 enum wined3d_format_id wined3d_format;
5181 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5182 "src_resource %p, src_subresource_idx %u, format %s.\n",
5183 iface, dst_resource, dst_subresource_idx,
5184 src_resource, src_subresource_idx, debug_dxgi_format(format));
5186 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5187 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5188 wined3d_format = wined3dformat_from_dxgi_format(format);
5189 wined3d_mutex_lock();
5190 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5191 wined3d_dst_resource, dst_subresource_idx,
5192 wined3d_src_resource, src_subresource_idx, wined3d_format);
5193 wined3d_mutex_unlock();
5196 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5197 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5199 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5200 iface, start_slot, buffer_count, buffers);
5202 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5203 buffers);
5206 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5207 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5209 struct d3d_device *device = impl_from_ID3D10Device(iface);
5210 unsigned int i;
5212 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5213 iface, start_slot, view_count, views);
5215 wined3d_mutex_lock();
5216 for (i = 0; i < view_count; ++i)
5218 struct wined3d_shader_resource_view *wined3d_view;
5219 struct d3d_shader_resource_view *view_impl;
5221 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5222 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5224 views[i] = NULL;
5225 continue;
5228 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5229 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5230 ID3D10ShaderResourceView_AddRef(views[i]);
5232 wined3d_mutex_unlock();
5235 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5237 struct d3d_device *device = impl_from_ID3D10Device(iface);
5238 struct d3d_pixel_shader *shader_impl;
5239 struct wined3d_shader *wined3d_shader;
5241 TRACE("iface %p, shader %p.\n", iface, shader);
5243 wined3d_mutex_lock();
5244 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5245 WINED3D_SHADER_TYPE_PIXEL)))
5247 wined3d_mutex_unlock();
5248 *shader = NULL;
5249 return;
5252 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5253 wined3d_mutex_unlock();
5254 *shader = &shader_impl->ID3D10PixelShader_iface;
5255 ID3D10PixelShader_AddRef(*shader);
5258 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5259 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5261 struct d3d_device *device = impl_from_ID3D10Device(iface);
5262 unsigned int i;
5264 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5265 iface, start_slot, sampler_count, samplers);
5267 wined3d_mutex_lock();
5268 for (i = 0; i < sampler_count; ++i)
5270 struct d3d_sampler_state *sampler_impl;
5271 struct wined3d_sampler *wined3d_sampler;
5273 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5274 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5276 samplers[i] = NULL;
5277 continue;
5280 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5281 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5282 ID3D10SamplerState_AddRef(samplers[i]);
5284 wined3d_mutex_unlock();
5287 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5289 struct d3d_device *device = impl_from_ID3D10Device(iface);
5290 struct d3d_vertex_shader *shader_impl;
5291 struct wined3d_shader *wined3d_shader;
5293 TRACE("iface %p, shader %p.\n", iface, shader);
5295 wined3d_mutex_lock();
5296 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5297 WINED3D_SHADER_TYPE_VERTEX)))
5299 wined3d_mutex_unlock();
5300 *shader = NULL;
5301 return;
5304 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5305 wined3d_mutex_unlock();
5306 *shader = &shader_impl->ID3D10VertexShader_iface;
5307 ID3D10VertexShader_AddRef(*shader);
5310 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5311 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5313 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5314 iface, start_slot, buffer_count, buffers);
5316 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5317 buffers);
5320 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5322 struct d3d_device *device = impl_from_ID3D10Device(iface);
5323 struct wined3d_vertex_declaration *wined3d_declaration;
5324 struct d3d_input_layout *input_layout_impl;
5326 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5328 wined3d_mutex_lock();
5329 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5330 device->immediate_context.wined3d_context)))
5332 wined3d_mutex_unlock();
5333 *input_layout = NULL;
5334 return;
5337 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5338 wined3d_mutex_unlock();
5339 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5340 ID3D10InputLayout_AddRef(*input_layout);
5343 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5344 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5346 struct d3d_device *device = impl_from_ID3D10Device(iface);
5347 unsigned int i;
5349 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5350 iface, start_slot, buffer_count, buffers, strides, offsets);
5352 wined3d_mutex_lock();
5353 for (i = 0; i < buffer_count; ++i)
5355 struct wined3d_buffer *wined3d_buffer = NULL;
5356 struct d3d_buffer *buffer_impl;
5358 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5359 &wined3d_buffer, &offsets[i], &strides[i])))
5360 ERR("Failed to get vertex buffer.\n");
5362 if (!wined3d_buffer)
5364 buffers[i] = NULL;
5365 continue;
5368 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5369 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5370 ID3D10Buffer_AddRef(buffers[i]);
5372 wined3d_mutex_unlock();
5375 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5376 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5378 struct d3d_device *device = impl_from_ID3D10Device(iface);
5379 enum wined3d_format_id wined3d_format;
5380 struct wined3d_buffer *wined3d_buffer;
5381 struct d3d_buffer *buffer_impl;
5383 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5385 wined3d_mutex_lock();
5386 wined3d_buffer = wined3d_device_context_get_index_buffer(
5387 device->immediate_context.wined3d_context, &wined3d_format, offset);
5388 *format = dxgi_format_from_wined3dformat(wined3d_format);
5389 if (!wined3d_buffer)
5391 wined3d_mutex_unlock();
5392 *buffer = NULL;
5393 return;
5396 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5397 wined3d_mutex_unlock();
5398 *buffer = &buffer_impl->ID3D10Buffer_iface;
5399 ID3D10Buffer_AddRef(*buffer);
5402 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5403 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5405 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5406 iface, start_slot, buffer_count, buffers);
5408 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5409 buffers);
5412 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5414 struct d3d_device *device = impl_from_ID3D10Device(iface);
5415 struct d3d_geometry_shader *shader_impl;
5416 struct wined3d_shader *wined3d_shader;
5418 TRACE("iface %p, shader %p.\n", iface, shader);
5420 wined3d_mutex_lock();
5421 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5422 WINED3D_SHADER_TYPE_GEOMETRY)))
5424 wined3d_mutex_unlock();
5425 *shader = NULL;
5426 return;
5429 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5430 wined3d_mutex_unlock();
5431 *shader = &shader_impl->ID3D10GeometryShader_iface;
5432 ID3D10GeometryShader_AddRef(*shader);
5435 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5436 D3D10_PRIMITIVE_TOPOLOGY *topology)
5438 struct d3d_device *device = impl_from_ID3D10Device(iface);
5440 TRACE("iface %p, topology %p.\n", iface, topology);
5442 wined3d_mutex_lock();
5443 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5444 (enum wined3d_primitive_type *)topology, NULL);
5445 wined3d_mutex_unlock();
5448 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5449 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5451 struct d3d_device *device = impl_from_ID3D10Device(iface);
5452 unsigned int i;
5454 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5455 iface, start_slot, view_count, views);
5457 wined3d_mutex_lock();
5458 for (i = 0; i < view_count; ++i)
5460 struct wined3d_shader_resource_view *wined3d_view;
5461 struct d3d_shader_resource_view *view_impl;
5463 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5464 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5466 views[i] = NULL;
5467 continue;
5470 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5471 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5472 ID3D10ShaderResourceView_AddRef(views[i]);
5474 wined3d_mutex_unlock();
5477 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5478 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5480 struct d3d_device *device = impl_from_ID3D10Device(iface);
5481 unsigned int i;
5483 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5484 iface, start_slot, sampler_count, samplers);
5486 wined3d_mutex_lock();
5487 for (i = 0; i < sampler_count; ++i)
5489 struct d3d_sampler_state *sampler_impl;
5490 struct wined3d_sampler *wined3d_sampler;
5492 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5493 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5495 samplers[i] = NULL;
5496 continue;
5499 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5500 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5501 ID3D10SamplerState_AddRef(samplers[i]);
5503 wined3d_mutex_unlock();
5506 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5507 ID3D10Predicate **predicate, BOOL *value)
5509 struct d3d_device *device = impl_from_ID3D10Device(iface);
5510 struct wined3d_query *wined3d_predicate;
5511 struct d3d_query *predicate_impl;
5513 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5515 wined3d_mutex_lock();
5516 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5518 wined3d_mutex_unlock();
5519 *predicate = NULL;
5520 return;
5523 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5524 wined3d_mutex_unlock();
5525 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5526 ID3D10Predicate_AddRef(*predicate);
5529 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5530 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5532 struct d3d_device *device = impl_from_ID3D10Device(iface);
5533 unsigned int i;
5535 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5536 iface, start_slot, view_count, views);
5538 wined3d_mutex_lock();
5539 for (i = 0; i < view_count; ++i)
5541 struct wined3d_shader_resource_view *wined3d_view;
5542 struct d3d_shader_resource_view *view_impl;
5544 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5545 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5547 views[i] = NULL;
5548 continue;
5551 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5552 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5553 ID3D10ShaderResourceView_AddRef(views[i]);
5555 wined3d_mutex_unlock();
5558 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5559 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5561 struct d3d_device *device = impl_from_ID3D10Device(iface);
5562 unsigned int i;
5564 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5565 iface, start_slot, sampler_count, samplers);
5567 wined3d_mutex_lock();
5568 for (i = 0; i < sampler_count; ++i)
5570 struct d3d_sampler_state *sampler_impl;
5571 struct wined3d_sampler *wined3d_sampler;
5573 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5574 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5576 samplers[i] = NULL;
5577 continue;
5580 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5581 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5582 ID3D10SamplerState_AddRef(samplers[i]);
5584 wined3d_mutex_unlock();
5587 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5588 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5590 struct d3d_device *device = impl_from_ID3D10Device(iface);
5591 struct wined3d_rendertarget_view *wined3d_view;
5593 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5594 iface, view_count, render_target_views, depth_stencil_view);
5596 wined3d_mutex_lock();
5597 if (render_target_views)
5599 struct d3d_rendertarget_view *view_impl;
5600 unsigned int i;
5602 for (i = 0; i < view_count; ++i)
5604 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5605 device->immediate_context.wined3d_context, i))
5606 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5608 render_target_views[i] = NULL;
5609 continue;
5612 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5613 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5617 if (depth_stencil_view)
5619 struct d3d_depthstencil_view *view_impl;
5621 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5622 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5624 *depth_stencil_view = NULL;
5626 else
5628 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5629 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5632 wined3d_mutex_unlock();
5635 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5636 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5638 struct d3d_device *device = impl_from_ID3D10Device(iface);
5639 ID3D11BlendState *d3d11_blend_state;
5641 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5642 iface, blend_state, blend_factor, sample_mask);
5644 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5645 &d3d11_blend_state, blend_factor, sample_mask);
5647 if (d3d11_blend_state)
5648 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5649 else
5650 *blend_state = NULL;
5653 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5654 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5656 struct d3d_device *device = impl_from_ID3D10Device(iface);
5657 ID3D11DepthStencilState *d3d11_iface;
5659 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5660 iface, depth_stencil_state, stencil_ref);
5662 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5663 &d3d11_iface, stencil_ref);
5665 if (d3d11_iface)
5666 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5667 else
5668 *depth_stencil_state = NULL;
5671 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5672 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5674 struct d3d_device *device = impl_from_ID3D10Device(iface);
5675 unsigned int i;
5677 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5678 iface, buffer_count, buffers, offsets);
5680 wined3d_mutex_lock();
5681 for (i = 0; i < buffer_count; ++i)
5683 struct wined3d_buffer *wined3d_buffer;
5684 struct d3d_buffer *buffer_impl;
5686 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5687 device->immediate_context.wined3d_context, i, &offsets[i])))
5689 buffers[i] = NULL;
5690 continue;
5693 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5694 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5695 ID3D10Buffer_AddRef(buffers[i]);
5697 wined3d_mutex_unlock();
5700 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5702 struct d3d_device *device = impl_from_ID3D10Device(iface);
5703 struct d3d_rasterizer_state *rasterizer_state_impl;
5704 struct wined3d_rasterizer_state *wined3d_state;
5706 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5708 wined3d_mutex_lock();
5709 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5711 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5712 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5714 else
5716 *rasterizer_state = NULL;
5718 wined3d_mutex_unlock();
5721 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5722 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5724 struct d3d_device *device = impl_from_ID3D10Device(iface);
5725 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5726 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5728 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5730 if (!viewport_count)
5731 return;
5733 wined3d_mutex_lock();
5734 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5735 &actual_count, viewports ? wined3d_vp : NULL);
5736 wined3d_mutex_unlock();
5738 if (!viewports)
5740 *viewport_count = actual_count;
5741 return;
5744 if (*viewport_count > actual_count)
5745 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5747 *viewport_count = min(actual_count, *viewport_count);
5748 for (i = 0; i < *viewport_count; ++i)
5750 viewports[i].TopLeftX = wined3d_vp[i].x;
5751 viewports[i].TopLeftY = wined3d_vp[i].y;
5752 viewports[i].Width = wined3d_vp[i].width;
5753 viewports[i].Height = wined3d_vp[i].height;
5754 viewports[i].MinDepth = wined3d_vp[i].min_z;
5755 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5759 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5761 struct d3d_device *device = impl_from_ID3D10Device(iface);
5762 unsigned int actual_count;
5764 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5766 if (!rect_count)
5767 return;
5769 actual_count = *rect_count;
5771 wined3d_mutex_lock();
5772 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5773 wined3d_mutex_unlock();
5775 if (!rects)
5777 *rect_count = actual_count;
5778 return;
5781 if (*rect_count > actual_count)
5782 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5785 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5787 TRACE("iface %p.\n", iface);
5789 /* In the current implementation the device is never removed, so we can
5790 * just return S_OK here. */
5792 return S_OK;
5795 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5797 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5799 return E_NOTIMPL;
5802 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5804 FIXME("iface %p stub!\n", iface);
5806 return 0;
5809 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5810 REFGUID guid, UINT *data_size, void *data)
5812 struct d3d_device *device = impl_from_ID3D10Device(iface);
5814 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5816 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5819 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5820 REFGUID guid, UINT data_size, const void *data)
5822 struct d3d_device *device = impl_from_ID3D10Device(iface);
5824 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5826 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5829 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5830 REFGUID guid, const IUnknown *data)
5832 struct d3d_device *device = impl_from_ID3D10Device(iface);
5834 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5836 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5839 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5841 struct d3d_device *device = impl_from_ID3D10Device(iface);
5843 TRACE("iface %p.\n", iface);
5845 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5848 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5850 struct d3d_device *device = impl_from_ID3D10Device(iface);
5852 TRACE("iface %p.\n", iface);
5854 wined3d_mutex_lock();
5855 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5856 wined3d_mutex_unlock();
5859 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5860 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5862 struct d3d_device *device = impl_from_ID3D10Device(iface);
5863 D3D11_BUFFER_DESC d3d11_desc;
5864 struct d3d_buffer *object;
5865 HRESULT hr;
5867 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5869 d3d11_desc.ByteWidth = desc->ByteWidth;
5870 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5871 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5872 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5873 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5874 d3d11_desc.StructureByteStride = 0;
5876 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5877 return hr;
5879 *buffer = &object->ID3D10Buffer_iface;
5881 return S_OK;
5884 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5885 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5887 struct d3d_device *device = impl_from_ID3D10Device(iface);
5888 D3D11_TEXTURE1D_DESC d3d11_desc;
5889 struct d3d_texture1d *object;
5890 HRESULT hr;
5892 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5894 d3d11_desc.Width = desc->Width;
5895 d3d11_desc.MipLevels = desc->MipLevels;
5896 d3d11_desc.ArraySize = desc->ArraySize;
5897 d3d11_desc.Format = desc->Format;
5898 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5899 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5900 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5901 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5903 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5904 return hr;
5906 *texture = &object->ID3D10Texture1D_iface;
5908 return S_OK;
5911 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5912 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5913 ID3D10Texture2D **texture)
5915 struct d3d_device *device = impl_from_ID3D10Device(iface);
5916 D3D11_TEXTURE2D_DESC d3d11_desc;
5917 struct d3d_texture2d *object;
5918 HRESULT hr;
5920 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5922 d3d11_desc.Width = desc->Width;
5923 d3d11_desc.Height = desc->Height;
5924 d3d11_desc.MipLevels = desc->MipLevels;
5925 d3d11_desc.ArraySize = desc->ArraySize;
5926 d3d11_desc.Format = desc->Format;
5927 d3d11_desc.SampleDesc = desc->SampleDesc;
5928 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5929 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5930 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5931 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5933 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5934 return hr;
5936 *texture = &object->ID3D10Texture2D_iface;
5938 return S_OK;
5941 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5942 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5943 ID3D10Texture3D **texture)
5945 struct d3d_device *device = impl_from_ID3D10Device(iface);
5946 D3D11_TEXTURE3D_DESC d3d11_desc;
5947 struct d3d_texture3d *object;
5948 HRESULT hr;
5950 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5952 d3d11_desc.Width = desc->Width;
5953 d3d11_desc.Height = desc->Height;
5954 d3d11_desc.Depth = desc->Depth;
5955 d3d11_desc.MipLevels = desc->MipLevels;
5956 d3d11_desc.Format = desc->Format;
5957 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5958 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5959 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5960 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5962 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5963 return hr;
5965 *texture = &object->ID3D10Texture3D_iface;
5967 return S_OK;
5970 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5971 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5973 struct d3d_device *device = impl_from_ID3D10Device(iface);
5974 struct d3d_shader_resource_view *object;
5975 ID3D11Resource *d3d11_resource;
5976 HRESULT hr;
5978 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5980 if (!resource)
5981 return E_INVALIDARG;
5983 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5985 ERR("Resource does not implement ID3D11Resource.\n");
5986 return E_FAIL;
5989 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5990 &object);
5991 ID3D11Resource_Release(d3d11_resource);
5992 if (FAILED(hr))
5993 return hr;
5995 *view = &object->ID3D10ShaderResourceView1_iface;
5997 return S_OK;
6000 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
6001 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
6003 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6005 return d3d10_device_CreateShaderResourceView1(iface, resource,
6006 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
6009 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
6010 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6012 struct d3d_device *device = impl_from_ID3D10Device(iface);
6013 struct d3d_rendertarget_view *object;
6014 ID3D11Resource *d3d11_resource;
6015 HRESULT hr;
6017 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6019 if (!resource)
6020 return E_INVALIDARG;
6022 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6024 ERR("Resource does not implement ID3D11Resource.\n");
6025 return E_FAIL;
6028 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6029 ID3D11Resource_Release(d3d11_resource);
6030 if (FAILED(hr))
6031 return hr;
6033 *view = &object->ID3D10RenderTargetView_iface;
6035 return S_OK;
6038 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6040 return (D3D11_DSV_DIMENSION)dim;
6043 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6044 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6046 struct d3d_device *device = impl_from_ID3D10Device(iface);
6047 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6048 struct d3d_depthstencil_view *object;
6049 ID3D11Resource *d3d11_resource;
6050 HRESULT hr;
6052 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6054 if (desc)
6056 d3d11_desc.Format = desc->Format;
6057 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6058 d3d11_desc.Flags = 0;
6059 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6062 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6064 ERR("Resource does not implement ID3D11Resource.\n");
6065 return E_FAIL;
6068 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6069 ID3D11Resource_Release(d3d11_resource);
6070 if (FAILED(hr))
6071 return hr;
6073 *view = &object->ID3D10DepthStencilView_iface;
6075 return S_OK;
6078 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6079 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6080 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6081 ID3D10InputLayout **input_layout)
6083 struct d3d_device *device = impl_from_ID3D10Device(iface);
6084 struct d3d_input_layout *object;
6085 HRESULT hr;
6087 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6088 "shader_byte_code_length %lu, input_layout %p\n",
6089 iface, element_descs, element_count, shader_byte_code,
6090 shader_byte_code_length, input_layout);
6092 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6093 shader_byte_code, shader_byte_code_length, &object)))
6094 return hr;
6096 *input_layout = &object->ID3D10InputLayout_iface;
6098 return S_OK;
6101 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6102 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6104 struct d3d_device *device = impl_from_ID3D10Device(iface);
6105 struct d3d_vertex_shader *object;
6106 HRESULT hr;
6108 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6109 iface, byte_code, byte_code_length, shader);
6111 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6112 return hr;
6114 *shader = &object->ID3D10VertexShader_iface;
6116 return S_OK;
6119 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6120 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6122 struct d3d_device *device = impl_from_ID3D10Device(iface);
6123 struct d3d_geometry_shader *object;
6124 HRESULT hr;
6126 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6127 iface, byte_code, byte_code_length, shader);
6129 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6130 NULL, 0, NULL, 0, 0, &object)))
6131 return hr;
6133 *shader = &object->ID3D10GeometryShader_iface;
6135 return S_OK;
6138 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6139 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6140 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6142 struct d3d_device *device = impl_from_ID3D10Device(iface);
6143 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6144 struct d3d_geometry_shader *object;
6145 unsigned int i, stride_count = 1;
6146 HRESULT hr;
6148 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
6149 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6150 iface, byte_code, byte_code_length, output_stream_decls,
6151 output_stream_decl_count, output_stream_stride, shader);
6153 if (!output_stream_decl_count && output_stream_stride)
6155 WARN("Stride must be 0 when declaration entry count is 0.\n");
6156 *shader = NULL;
6157 return E_INVALIDARG;
6160 if (output_stream_decl_count
6161 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6163 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6164 *shader = NULL;
6165 return E_OUTOFMEMORY;
6168 for (i = 0; i < output_stream_decl_count; ++i)
6170 so_entries[i].Stream = 0;
6171 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6172 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6173 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6174 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6175 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6177 if (output_stream_decls[i].OutputSlot)
6179 stride_count = 0;
6180 if (output_stream_stride)
6182 WARN("Stride must be 0 when multiple output slots are used.\n");
6183 heap_free(so_entries);
6184 *shader = NULL;
6185 return E_INVALIDARG;
6190 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6191 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6192 heap_free(so_entries);
6193 if (FAILED(hr))
6195 *shader = NULL;
6196 return hr;
6199 *shader = &object->ID3D10GeometryShader_iface;
6201 return hr;
6204 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6205 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6207 struct d3d_device *device = impl_from_ID3D10Device(iface);
6208 struct d3d_pixel_shader *object;
6209 HRESULT hr;
6211 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6212 iface, byte_code, byte_code_length, shader);
6214 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6215 return hr;
6217 *shader = &object->ID3D10PixelShader_iface;
6219 return S_OK;
6222 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6223 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6225 struct d3d_device *device = impl_from_ID3D10Device(iface);
6226 struct d3d_blend_state *object;
6227 HRESULT hr;
6229 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6231 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6232 return hr;
6234 *blend_state = &object->ID3D10BlendState1_iface;
6236 return S_OK;
6239 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6240 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6242 D3D10_BLEND_DESC1 d3d10_1_desc;
6243 unsigned int i;
6245 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6247 if (!desc)
6248 return E_INVALIDARG;
6250 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6251 d3d10_1_desc.IndependentBlendEnable = FALSE;
6252 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6254 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6255 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6256 d3d10_1_desc.IndependentBlendEnable = TRUE;
6259 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6261 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6262 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6263 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6264 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6265 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6266 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6267 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6268 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6271 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6274 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6275 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6277 struct d3d_device *device = impl_from_ID3D10Device(iface);
6278 struct d3d_depthstencil_state *object;
6279 HRESULT hr;
6281 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6283 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6284 return hr;
6286 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6288 return S_OK;
6291 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6292 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6294 struct d3d_device *device = impl_from_ID3D10Device(iface);
6295 struct d3d_rasterizer_state *object;
6296 HRESULT hr;
6298 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6300 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6301 return hr;
6303 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6305 return S_OK;
6308 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6309 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6311 struct d3d_device *device = impl_from_ID3D10Device(iface);
6312 struct d3d_sampler_state *object;
6313 HRESULT hr;
6315 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6317 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6318 return hr;
6320 *sampler_state = &object->ID3D10SamplerState_iface;
6322 return S_OK;
6325 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6326 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6328 struct d3d_device *device = impl_from_ID3D10Device(iface);
6329 struct d3d_query *object;
6330 HRESULT hr;
6332 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6334 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6335 return hr;
6337 if (query)
6339 *query = &object->ID3D10Query_iface;
6340 return S_OK;
6343 ID3D10Query_Release(&object->ID3D10Query_iface);
6344 return S_FALSE;
6347 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6348 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6350 struct d3d_device *device = impl_from_ID3D10Device(iface);
6351 struct d3d_query *object;
6352 HRESULT hr;
6354 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6356 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6357 return hr;
6359 if (predicate)
6361 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6362 return S_OK;
6365 ID3D10Query_Release(&object->ID3D10Query_iface);
6366 return S_FALSE;
6369 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6370 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6372 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6374 return E_NOTIMPL;
6377 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6378 DXGI_FORMAT format, UINT *format_support)
6380 struct d3d_device *device = impl_from_ID3D10Device(iface);
6382 TRACE("iface %p, format %s, format_support %p.\n",
6383 iface, debug_dxgi_format(format), format_support);
6385 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6388 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6389 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6391 struct d3d_device *device = impl_from_ID3D10Device(iface);
6393 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6394 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6396 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6397 sample_count, quality_level_count);
6400 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6402 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6405 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6406 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6407 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6409 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6410 "units %p, units_length %p, description %p, description_length %p stub!\n",
6411 iface, desc, type, active_counters, name, name_length,
6412 units, units_length, description, description_length);
6414 return E_NOTIMPL;
6417 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6419 FIXME("iface %p stub!\n", iface);
6421 return 0;
6424 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6425 HANDLE resource_handle, REFIID guid, void **resource)
6427 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6428 iface, resource_handle, debugstr_guid(guid), resource);
6430 return E_NOTIMPL;
6433 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6435 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6438 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6440 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6443 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6445 return (D3D10_FEATURE_LEVEL1)level;
6448 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6450 struct d3d_device *device = impl_from_ID3D10Device(iface);
6452 TRACE("iface %p.\n", iface);
6454 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6457 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6459 /* IUnknown methods */
6460 d3d10_device_QueryInterface,
6461 d3d10_device_AddRef,
6462 d3d10_device_Release,
6463 /* ID3D10Device methods */
6464 d3d10_device_VSSetConstantBuffers,
6465 d3d10_device_PSSetShaderResources,
6466 d3d10_device_PSSetShader,
6467 d3d10_device_PSSetSamplers,
6468 d3d10_device_VSSetShader,
6469 d3d10_device_DrawIndexed,
6470 d3d10_device_Draw,
6471 d3d10_device_PSSetConstantBuffers,
6472 d3d10_device_IASetInputLayout,
6473 d3d10_device_IASetVertexBuffers,
6474 d3d10_device_IASetIndexBuffer,
6475 d3d10_device_DrawIndexedInstanced,
6476 d3d10_device_DrawInstanced,
6477 d3d10_device_GSSetConstantBuffers,
6478 d3d10_device_GSSetShader,
6479 d3d10_device_IASetPrimitiveTopology,
6480 d3d10_device_VSSetShaderResources,
6481 d3d10_device_VSSetSamplers,
6482 d3d10_device_SetPredication,
6483 d3d10_device_GSSetShaderResources,
6484 d3d10_device_GSSetSamplers,
6485 d3d10_device_OMSetRenderTargets,
6486 d3d10_device_OMSetBlendState,
6487 d3d10_device_OMSetDepthStencilState,
6488 d3d10_device_SOSetTargets,
6489 d3d10_device_DrawAuto,
6490 d3d10_device_RSSetState,
6491 d3d10_device_RSSetViewports,
6492 d3d10_device_RSSetScissorRects,
6493 d3d10_device_CopySubresourceRegion,
6494 d3d10_device_CopyResource,
6495 d3d10_device_UpdateSubresource,
6496 d3d10_device_ClearRenderTargetView,
6497 d3d10_device_ClearDepthStencilView,
6498 d3d10_device_GenerateMips,
6499 d3d10_device_ResolveSubresource,
6500 d3d10_device_VSGetConstantBuffers,
6501 d3d10_device_PSGetShaderResources,
6502 d3d10_device_PSGetShader,
6503 d3d10_device_PSGetSamplers,
6504 d3d10_device_VSGetShader,
6505 d3d10_device_PSGetConstantBuffers,
6506 d3d10_device_IAGetInputLayout,
6507 d3d10_device_IAGetVertexBuffers,
6508 d3d10_device_IAGetIndexBuffer,
6509 d3d10_device_GSGetConstantBuffers,
6510 d3d10_device_GSGetShader,
6511 d3d10_device_IAGetPrimitiveTopology,
6512 d3d10_device_VSGetShaderResources,
6513 d3d10_device_VSGetSamplers,
6514 d3d10_device_GetPredication,
6515 d3d10_device_GSGetShaderResources,
6516 d3d10_device_GSGetSamplers,
6517 d3d10_device_OMGetRenderTargets,
6518 d3d10_device_OMGetBlendState,
6519 d3d10_device_OMGetDepthStencilState,
6520 d3d10_device_SOGetTargets,
6521 d3d10_device_RSGetState,
6522 d3d10_device_RSGetViewports,
6523 d3d10_device_RSGetScissorRects,
6524 d3d10_device_GetDeviceRemovedReason,
6525 d3d10_device_SetExceptionMode,
6526 d3d10_device_GetExceptionMode,
6527 d3d10_device_GetPrivateData,
6528 d3d10_device_SetPrivateData,
6529 d3d10_device_SetPrivateDataInterface,
6530 d3d10_device_ClearState,
6531 d3d10_device_Flush,
6532 d3d10_device_CreateBuffer,
6533 d3d10_device_CreateTexture1D,
6534 d3d10_device_CreateTexture2D,
6535 d3d10_device_CreateTexture3D,
6536 d3d10_device_CreateShaderResourceView,
6537 d3d10_device_CreateRenderTargetView,
6538 d3d10_device_CreateDepthStencilView,
6539 d3d10_device_CreateInputLayout,
6540 d3d10_device_CreateVertexShader,
6541 d3d10_device_CreateGeometryShader,
6542 d3d10_device_CreateGeometryShaderWithStreamOutput,
6543 d3d10_device_CreatePixelShader,
6544 d3d10_device_CreateBlendState,
6545 d3d10_device_CreateDepthStencilState,
6546 d3d10_device_CreateRasterizerState,
6547 d3d10_device_CreateSamplerState,
6548 d3d10_device_CreateQuery,
6549 d3d10_device_CreatePredicate,
6550 d3d10_device_CreateCounter,
6551 d3d10_device_CheckFormatSupport,
6552 d3d10_device_CheckMultisampleQualityLevels,
6553 d3d10_device_CheckCounterInfo,
6554 d3d10_device_CheckCounter,
6555 d3d10_device_GetCreationFlags,
6556 d3d10_device_OpenSharedResource,
6557 d3d10_device_SetTextFilterSize,
6558 d3d10_device_GetTextFilterSize,
6559 d3d10_device_CreateShaderResourceView1,
6560 d3d10_device_CreateBlendState1,
6561 d3d10_device_GetFeatureLevel,
6564 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6566 /* IUnknown methods */
6567 d3d_device_inner_QueryInterface,
6568 d3d_device_inner_AddRef,
6569 d3d_device_inner_Release,
6572 /* ID3D10Multithread methods */
6574 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6576 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6579 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6581 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6583 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6585 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6588 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6590 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6592 TRACE("iface %p.\n", iface);
6594 return IUnknown_AddRef(device->outer_unk);
6597 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6599 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6601 TRACE("iface %p.\n", iface);
6603 return IUnknown_Release(device->outer_unk);
6606 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6608 TRACE("iface %p.\n", iface);
6610 wined3d_mutex_lock();
6613 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6615 TRACE("iface %p.\n", iface);
6617 wined3d_mutex_unlock();
6620 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6622 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6624 return TRUE;
6627 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6629 FIXME("iface %p stub!\n", iface);
6631 return TRUE;
6634 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6636 d3d10_multithread_QueryInterface,
6637 d3d10_multithread_AddRef,
6638 d3d10_multithread_Release,
6639 d3d10_multithread_Enter,
6640 d3d10_multithread_Leave,
6641 d3d10_multithread_SetMultithreadProtected,
6642 d3d10_multithread_GetMultithreadProtected,
6645 /* IWineDXGIDeviceParent IUnknown methods */
6647 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6649 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6652 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6653 REFIID iid, void **out)
6655 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6656 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6659 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6661 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6662 return IUnknown_AddRef(device->outer_unk);
6665 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6667 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6668 return IUnknown_Release(device->outer_unk);
6671 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6672 IWineDXGIDeviceParent *iface)
6674 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6675 return &device->device_parent;
6678 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6680 /* IUnknown methods */
6681 dxgi_device_parent_QueryInterface,
6682 dxgi_device_parent_AddRef,
6683 dxgi_device_parent_Release,
6684 /* IWineDXGIDeviceParent methods */
6685 dxgi_device_parent_get_wined3d_device_parent,
6688 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6690 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6693 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6694 struct wined3d_device *wined3d_device)
6696 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6697 struct d3d_device_context_state *state;
6698 struct wined3d_state *wined3d_state;
6699 D3D_FEATURE_LEVEL feature_level;
6701 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6703 wined3d_device_incref(wined3d_device);
6704 device->wined3d_device = wined3d_device;
6705 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6707 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6708 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6710 if (!(state = heap_alloc_zero(sizeof(*state))))
6712 ERR("Failed to create the initial device context state.\n");
6713 return;
6716 d3d_device_context_state_init(state, device, feature_level,
6717 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6719 device->state = state;
6720 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6721 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6723 d3d_device_context_state_private_addref(state);
6724 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6727 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6729 TRACE("device_parent %p.\n", device_parent);
6732 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6734 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6737 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6738 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6739 void **parent, const struct wined3d_parent_ops **parent_ops)
6741 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6742 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6744 *parent = NULL;
6745 *parent_ops = &d3d_null_wined3d_parent_ops;
6747 return S_OK;
6750 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6751 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6752 struct wined3d_texture **wined3d_texture)
6754 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6755 struct d3d_texture2d *texture;
6756 ID3D11Texture2D *texture_iface;
6757 D3D11_TEXTURE2D_DESC desc;
6758 HRESULT hr;
6760 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6761 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6763 desc.Width = wined3d_desc->width;
6764 desc.Height = wined3d_desc->height;
6765 desc.MipLevels = 1;
6766 desc.ArraySize = 1;
6767 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6768 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6769 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6770 desc.Usage = D3D11_USAGE_DEFAULT;
6771 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6772 desc.CPUAccessFlags = 0;
6773 desc.MiscFlags = 0;
6775 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6777 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6778 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6781 if (texture_flags)
6782 FIXME("Unhandled flags %#x.\n", texture_flags);
6784 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6785 &desc, NULL, &texture_iface)))
6787 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6788 return hr;
6791 texture = impl_from_ID3D11Texture2D(texture_iface);
6793 *wined3d_texture = texture->wined3d_texture;
6794 wined3d_texture_incref(*wined3d_texture);
6795 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6797 return S_OK;
6800 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6802 device_parent_wined3d_device_created,
6803 device_parent_mode_changed,
6804 device_parent_activate,
6805 device_parent_texture_sub_resource_created,
6806 device_parent_create_swapchain_texture,
6809 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6811 const D3D11_SAMPLER_DESC *ka = key;
6812 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6814 return memcmp(ka, kb, sizeof(*ka));
6817 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6819 const D3D11_BLEND_DESC *ka = key;
6820 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6822 return memcmp(ka, kb, sizeof(*ka));
6825 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6827 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6828 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6829 const struct d3d_depthstencil_state, entry)->desc;
6831 return memcmp(ka, kb, sizeof(*ka));
6834 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6836 const D3D11_RASTERIZER_DESC *ka = key;
6837 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6839 return memcmp(ka, kb, sizeof(*ka));
6842 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6844 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6845 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6846 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6847 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6848 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6849 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6850 device->refcount = 1;
6851 /* COM aggregation always takes place */
6852 device->outer_unk = outer_unknown;
6853 device->d3d11_only = FALSE;
6854 device->state = NULL;
6856 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6857 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6859 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6860 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6861 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6862 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);