d3d11: Implement ID3D11DeviceContext::FinishCommandList().
[wine.git] / dlls / d3d11 / device.c
blob6c42c55b26ed5d42f4f70c5d954964531c77df6f
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 void d3d11_device_context_cleanup(struct d3d11_device_context *context)
453 wined3d_private_store_cleanup(&context->private_store);
456 /* ID3D11DeviceContext - immediate context methods */
458 static inline struct d3d11_device_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
460 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11DeviceContext1_iface);
463 static HRESULT STDMETHODCALLTYPE d3d11_device_context_QueryInterface(ID3D11DeviceContext1 *iface,
464 REFIID iid, void **out)
466 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
468 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
470 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
471 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
472 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
473 || IsEqualGUID(iid, &IID_IUnknown))
475 *out = &context->ID3D11DeviceContext1_iface;
477 else if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE && IsEqualGUID(iid, &IID_ID3D11Multithread))
479 *out = &context->ID3D11Multithread_iface;
481 else
483 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
484 *out = NULL;
485 return E_NOINTERFACE;
488 ID3D11DeviceContext1_AddRef(iface);
489 return S_OK;
492 static ULONG STDMETHODCALLTYPE d3d11_device_context_AddRef(ID3D11DeviceContext1 *iface)
494 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
495 ULONG refcount = InterlockedIncrement(&context->refcount);
497 TRACE("%p increasing refcount to %u.\n", context, refcount);
499 if (refcount == 1)
501 ID3D11Device2_AddRef(&context->device->ID3D11Device2_iface);
504 return refcount;
507 static ULONG STDMETHODCALLTYPE d3d11_device_context_Release(ID3D11DeviceContext1 *iface)
509 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
510 ULONG refcount = InterlockedDecrement(&context->refcount);
512 TRACE("%p decreasing refcount to %u.\n", context, refcount);
514 if (!refcount)
516 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
518 wined3d_deferred_context_destroy(context->wined3d_context);
519 d3d11_device_context_cleanup(context);
520 heap_free(context);
522 ID3D11Device2_Release(&context->device->ID3D11Device2_iface);
525 return refcount;
528 static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface,
529 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
531 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
532 unsigned int i;
534 wined3d_mutex_lock();
535 for (i = 0; i < buffer_count; ++i)
537 struct wined3d_buffer *wined3d_buffer;
538 struct d3d_buffer *buffer_impl;
540 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(context->wined3d_context,
541 type, start_slot + i)))
543 buffers[i] = NULL;
544 continue;
547 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
548 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
549 ID3D11Buffer_AddRef(buffers[i]);
551 wined3d_mutex_unlock();
554 static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface,
555 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
557 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
558 unsigned int i;
560 wined3d_mutex_lock();
561 for (i = 0; i < buffer_count; ++i)
563 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
565 wined3d_device_context_set_constant_buffer(context->wined3d_context, type, start_slot + i,
566 buffer ? buffer->wined3d_buffer : NULL);
568 wined3d_mutex_unlock();
571 static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
573 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
575 TRACE("iface %p, device %p.\n", iface, device);
577 *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
578 ID3D11Device_AddRef(*device);
581 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
582 UINT *data_size, void *data)
584 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
586 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
588 return d3d_get_private_data(&context->private_store, guid, data_size, data);
591 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
592 UINT data_size, const void *data)
594 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
596 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
598 return d3d_set_private_data(&context->private_store, guid, data_size, data);
601 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
602 REFGUID guid, const IUnknown *data)
604 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
606 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
608 return d3d_set_private_data_interface(&context->private_store, guid, data);
611 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
612 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
614 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
615 iface, start_slot, buffer_count, buffers);
617 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
618 buffer_count, buffers);
621 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
622 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
624 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
625 unsigned int i;
627 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
628 iface, start_slot, view_count, views);
630 wined3d_mutex_lock();
631 for (i = 0; i < view_count; ++i)
633 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
635 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
636 start_slot + i, view ? view->wined3d_view : NULL);
638 wined3d_mutex_unlock();
641 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
642 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
644 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
645 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
647 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
648 iface, shader, class_instances, class_instance_count);
650 if (class_instances)
651 FIXME("Dynamic linking is not implemented yet.\n");
653 wined3d_mutex_lock();
654 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
655 ps ? ps->wined3d_shader : NULL);
656 wined3d_mutex_unlock();
659 static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
660 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
662 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
663 unsigned int i;
665 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
666 iface, start_slot, sampler_count, samplers);
668 wined3d_mutex_lock();
669 for (i = 0; i < sampler_count; ++i)
671 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
673 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i,
674 sampler ? sampler->wined3d_sampler : NULL);
676 wined3d_mutex_unlock();
679 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
680 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
682 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
683 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
685 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
686 iface, shader, class_instances, class_instance_count);
688 if (class_instances)
689 FIXME("Dynamic linking is not implemented yet.\n");
691 wined3d_mutex_lock();
692 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
693 vs ? vs->wined3d_shader : NULL);
694 wined3d_mutex_unlock();
697 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
698 UINT index_count, UINT start_index_location, INT base_vertex_location)
700 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
702 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
703 iface, index_count, start_index_location, base_vertex_location);
705 wined3d_mutex_lock();
706 wined3d_device_context_draw_indexed(context->wined3d_context,
707 base_vertex_location, start_index_location, index_count, 0, 0);
708 wined3d_mutex_unlock();
711 static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
712 UINT vertex_count, UINT start_vertex_location)
714 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
716 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
717 iface, vertex_count, start_vertex_location);
719 wined3d_mutex_lock();
720 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
721 wined3d_mutex_unlock();
724 static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
725 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
727 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
728 struct wined3d_resource *wined3d_resource;
729 struct wined3d_map_desc map_desc;
730 HRESULT hr;
732 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
733 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
735 if (map_flags)
736 FIXME("Ignoring map_flags %#x.\n", map_flags);
738 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
740 wined3d_mutex_lock();
741 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
742 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
743 wined3d_mutex_unlock();
745 mapped_subresource->pData = map_desc.data;
746 mapped_subresource->RowPitch = map_desc.row_pitch;
747 mapped_subresource->DepthPitch = map_desc.slice_pitch;
749 return hr;
752 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
753 UINT subresource_idx)
755 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
756 struct wined3d_resource *wined3d_resource;
758 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
760 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
762 wined3d_mutex_lock();
763 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
764 wined3d_mutex_unlock();
767 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
768 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
770 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
771 iface, start_slot, buffer_count, buffers);
773 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
774 buffer_count, buffers);
777 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
778 ID3D11InputLayout *input_layout)
780 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
781 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
783 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
785 wined3d_mutex_lock();
786 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
787 wined3d_mutex_unlock();
790 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
791 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
793 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
794 unsigned int i;
796 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
797 iface, start_slot, buffer_count, buffers, strides, offsets);
799 wined3d_mutex_lock();
800 for (i = 0; i < buffer_count; ++i)
802 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
804 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
805 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
807 wined3d_mutex_unlock();
810 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
811 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
813 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
814 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
816 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
817 iface, buffer, debug_dxgi_format(format), offset);
819 wined3d_mutex_lock();
820 wined3d_device_context_set_index_buffer(context->wined3d_context,
821 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
822 wined3dformat_from_dxgi_format(format), offset);
823 wined3d_mutex_unlock();
826 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
827 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
828 UINT start_instance_location)
830 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
832 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
833 "base_vertex_location %d, start_instance_location %u.\n",
834 iface, instance_index_count, instance_count, start_index_location,
835 base_vertex_location, start_instance_location);
837 wined3d_mutex_lock();
838 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
839 start_index_location, instance_index_count, start_instance_location, instance_count);
840 wined3d_mutex_unlock();
843 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
844 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
846 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
848 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
849 "start_instance_location %u.\n",
850 iface, instance_vertex_count, instance_count, start_vertex_location,
851 start_instance_location);
853 wined3d_mutex_lock();
854 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
855 instance_vertex_count, start_instance_location, instance_count);
856 wined3d_mutex_unlock();
859 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
860 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
862 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
863 iface, start_slot, buffer_count, buffers);
865 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
866 buffer_count, buffers);
869 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
870 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
872 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
873 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
875 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
876 iface, shader, class_instances, class_instance_count);
878 if (class_instances)
879 FIXME("Dynamic linking is not implemented yet.\n");
881 wined3d_mutex_lock();
882 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
883 gs ? gs->wined3d_shader : NULL);
884 wined3d_mutex_unlock();
887 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
888 D3D11_PRIMITIVE_TOPOLOGY topology)
890 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
891 enum wined3d_primitive_type primitive_type;
892 unsigned int patch_vertex_count;
894 TRACE("iface %p, topology %#x.\n", iface, topology);
896 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
898 wined3d_mutex_lock();
899 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
900 wined3d_mutex_unlock();
903 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
904 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
906 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
907 unsigned int i;
909 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
911 wined3d_mutex_lock();
912 for (i = 0; i < view_count; ++i)
914 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
916 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
917 start_slot + i, view ? view->wined3d_view : NULL);
919 wined3d_mutex_unlock();
922 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
923 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
925 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
926 unsigned int i;
928 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
929 iface, start_slot, sampler_count, samplers);
931 wined3d_mutex_lock();
932 for (i = 0; i < sampler_count; ++i)
934 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
936 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i,
937 sampler ? sampler->wined3d_sampler : NULL);
939 wined3d_mutex_unlock();
942 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
943 ID3D11Asynchronous *asynchronous)
945 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
946 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
948 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
950 wined3d_mutex_lock();
951 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
952 wined3d_mutex_unlock();
955 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
956 ID3D11Asynchronous *asynchronous)
958 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
959 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
961 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
963 wined3d_mutex_lock();
964 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
965 wined3d_mutex_unlock();
968 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
969 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
971 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
972 unsigned int wined3d_flags;
973 HRESULT hr;
975 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
976 iface, asynchronous, data, data_size, data_flags);
978 if (!data && data_size)
979 return E_INVALIDARG;
981 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
983 wined3d_mutex_lock();
984 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
986 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
987 if (hr == WINED3DERR_INVALIDCALL)
988 hr = DXGI_ERROR_INVALID_CALL;
990 else
992 WARN("Invalid data size %u.\n", data_size);
993 hr = E_INVALIDARG;
995 wined3d_mutex_unlock();
997 return hr;
1000 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1001 ID3D11Predicate *predicate, BOOL value)
1003 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1004 struct d3d_query *query;
1006 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1008 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1010 wined3d_mutex_lock();
1011 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1012 wined3d_mutex_unlock();
1015 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1016 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1018 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1019 unsigned int i;
1021 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1023 wined3d_mutex_lock();
1024 for (i = 0; i < view_count; ++i)
1026 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1028 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
1029 start_slot + i, view ? view->wined3d_view : NULL);
1031 wined3d_mutex_unlock();
1034 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1035 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1037 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1038 unsigned int i;
1040 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1041 iface, start_slot, sampler_count, samplers);
1043 wined3d_mutex_lock();
1044 for (i = 0; i < sampler_count; ++i)
1046 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1048 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i,
1049 sampler ? sampler->wined3d_sampler : NULL);
1051 wined3d_mutex_unlock();
1054 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1055 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1056 ID3D11DepthStencilView *depth_stencil_view)
1058 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1059 struct d3d_depthstencil_view *dsv;
1060 unsigned int i;
1062 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1063 iface, render_target_view_count, render_target_views, depth_stencil_view);
1065 wined3d_mutex_lock();
1066 for (i = 0; i < render_target_view_count; ++i)
1068 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
1069 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
1070 rtv ? rtv->wined3d_view : NULL, FALSE);
1072 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1074 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
1077 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1078 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
1079 wined3d_mutex_unlock();
1082 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1083 ID3D11DeviceContext1 *iface, UINT render_target_view_count,
1084 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
1085 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1086 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
1088 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1089 unsigned int i;
1091 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1092 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
1093 "initial_counts %p.\n",
1094 iface, render_target_view_count, render_target_views, depth_stencil_view,
1095 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
1096 initial_counts);
1098 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1100 d3d11_device_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
1101 depth_stencil_view);
1104 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1106 wined3d_mutex_lock();
1107 for (i = 0; i < unordered_access_view_start_slot; ++i)
1109 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1110 WINED3D_PIPELINE_GRAPHICS, i, NULL, ~0u);
1112 for (i = 0; i < unordered_access_view_count; ++i)
1114 struct d3d11_unordered_access_view *view
1115 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
1117 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1118 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i,
1119 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1121 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
1123 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1124 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i, NULL, ~0u);
1126 wined3d_mutex_unlock();
1130 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1131 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1133 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1134 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1135 struct d3d_blend_state *blend_state_impl;
1137 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1138 iface, blend_state, debug_float4(blend_factor), sample_mask);
1140 if (!blend_factor)
1141 blend_factor = default_blend_factor;
1143 wined3d_mutex_lock();
1144 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1145 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1146 (const struct wined3d_color *)blend_factor, sample_mask);
1147 else
1148 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1149 (const struct wined3d_color *)blend_factor, sample_mask);
1150 wined3d_mutex_unlock();
1153 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1154 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1156 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1157 struct d3d_depthstencil_state *state_impl;
1159 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1160 iface, depth_stencil_state, stencil_ref);
1162 wined3d_mutex_lock();
1163 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1165 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1166 wined3d_mutex_unlock();
1167 return;
1170 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1171 wined3d_mutex_unlock();
1174 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1175 ID3D11Buffer *const *buffers, const UINT *offsets)
1177 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1178 unsigned int count, i;
1180 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1182 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
1183 wined3d_mutex_lock();
1184 for (i = 0; i < count; ++i)
1186 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1188 wined3d_device_context_set_stream_output(context->wined3d_context, i,
1189 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1191 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1193 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
1195 wined3d_mutex_unlock();
1198 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1200 FIXME("iface %p stub!\n", iface);
1203 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1204 ID3D11Buffer *buffer, UINT offset)
1206 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1207 struct d3d_buffer *d3d_buffer;
1209 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1211 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1213 wined3d_mutex_lock();
1214 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1215 wined3d_mutex_unlock();
1218 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1219 ID3D11Buffer *buffer, UINT offset)
1221 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1222 struct d3d_buffer *d3d_buffer;
1224 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1226 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1228 wined3d_mutex_lock();
1229 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1230 wined3d_mutex_unlock();
1233 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1234 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1236 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1238 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1239 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1241 wined3d_mutex_lock();
1242 wined3d_device_context_dispatch(context->wined3d_context,
1243 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1244 wined3d_mutex_unlock();
1247 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1248 ID3D11Buffer *buffer, UINT offset)
1250 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1251 struct d3d_buffer *buffer_impl;
1253 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1255 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1257 wined3d_mutex_lock();
1258 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1259 wined3d_mutex_unlock();
1262 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1263 ID3D11RasterizerState *rasterizer_state)
1265 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1266 struct d3d_rasterizer_state *rasterizer_state_impl;
1268 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1270 wined3d_mutex_lock();
1271 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1272 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1273 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1274 wined3d_mutex_unlock();
1277 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1278 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1280 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1281 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1282 unsigned int i;
1284 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1286 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1287 return;
1289 for (i = 0; i < viewport_count; ++i)
1291 wined3d_vp[i].x = viewports[i].TopLeftX;
1292 wined3d_vp[i].y = viewports[i].TopLeftY;
1293 wined3d_vp[i].width = viewports[i].Width;
1294 wined3d_vp[i].height = viewports[i].Height;
1295 wined3d_vp[i].min_z = viewports[i].MinDepth;
1296 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1299 wined3d_mutex_lock();
1300 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1301 wined3d_mutex_unlock();
1304 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1305 UINT rect_count, const D3D11_RECT *rects)
1307 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1309 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1311 if (rect_count > WINED3D_MAX_VIEWPORTS)
1312 return;
1314 wined3d_mutex_lock();
1315 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1316 wined3d_mutex_unlock();
1319 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1320 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1321 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1323 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1324 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1325 struct wined3d_box wined3d_src_box;
1327 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1328 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1329 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1330 src_resource, src_subresource_idx, src_box);
1332 if (!dst_resource || !src_resource)
1333 return;
1335 if (src_box)
1336 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1337 src_box->right, src_box->bottom, src_box->front, src_box->back);
1339 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1340 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1341 wined3d_mutex_lock();
1342 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1343 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1344 wined3d_mutex_unlock();
1347 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1348 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1350 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1351 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1353 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1355 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1356 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1357 wined3d_mutex_lock();
1358 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1359 wined3d_mutex_unlock();
1362 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1363 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1364 const void *data, UINT row_pitch, UINT depth_pitch)
1366 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1367 struct wined3d_resource *wined3d_resource;
1368 struct wined3d_box wined3d_box;
1370 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1371 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1373 if (box)
1374 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1376 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1377 wined3d_mutex_lock();
1378 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1379 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1380 wined3d_mutex_unlock();
1383 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1384 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1386 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1387 struct d3d11_unordered_access_view *uav;
1388 struct d3d_buffer *buffer_impl;
1390 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1391 iface, dst_buffer, dst_offset, src_view);
1393 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1394 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1396 wined3d_mutex_lock();
1397 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1398 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1399 wined3d_mutex_unlock();
1402 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1403 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1405 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1406 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1407 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1408 HRESULT hr;
1410 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1411 iface, render_target_view, debug_float4(color_rgba));
1413 if (!view)
1414 return;
1416 wined3d_mutex_lock();
1417 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1418 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1419 ERR("Failed to clear view, hr %#x.\n", hr);
1420 wined3d_mutex_unlock();
1423 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1424 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1426 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1427 struct d3d11_unordered_access_view *view;
1429 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1430 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1432 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1433 wined3d_mutex_lock();
1434 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1435 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1436 wined3d_mutex_unlock();
1439 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1440 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1442 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1443 iface, unordered_access_view, debug_float4(values));
1446 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1447 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1449 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1450 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1451 DWORD wined3d_flags;
1452 HRESULT hr;
1454 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1455 iface, depth_stencil_view, flags, depth, stencil);
1457 if (!view)
1458 return;
1460 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1462 wined3d_mutex_lock();
1463 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1464 wined3d_flags, NULL, depth, stencil)))
1465 ERR("Failed to clear view, hr %#x.\n", hr);
1466 wined3d_mutex_unlock();
1469 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1470 ID3D11ShaderResourceView *view)
1472 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1473 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1475 TRACE("iface %p, view %p.\n", iface, view);
1477 wined3d_mutex_lock();
1478 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1479 wined3d_mutex_unlock();
1482 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1483 ID3D11Resource *resource, FLOAT min_lod)
1485 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1488 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1489 ID3D11Resource *resource)
1491 FIXME("iface %p, resource %p stub!\n", iface, resource);
1493 return 0.0f;
1496 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1497 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1498 ID3D11Resource *src_resource, UINT src_subresource_idx,
1499 DXGI_FORMAT format)
1501 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1502 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1503 enum wined3d_format_id wined3d_format;
1505 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1506 "src_resource %p, src_subresource_idx %u, format %s.\n",
1507 iface, dst_resource, dst_subresource_idx,
1508 src_resource, src_subresource_idx, debug_dxgi_format(format));
1510 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1511 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1512 wined3d_format = wined3dformat_from_dxgi_format(format);
1513 wined3d_mutex_lock();
1514 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1515 wined3d_dst_resource, dst_subresource_idx,
1516 wined3d_src_resource, src_subresource_idx, wined3d_format);
1517 wined3d_mutex_unlock();
1520 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1521 ID3D11CommandList *command_list, BOOL restore_state)
1523 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1526 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1527 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1529 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1530 unsigned int i;
1532 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1533 iface, start_slot, view_count, views);
1535 wined3d_mutex_lock();
1536 for (i = 0; i < view_count; ++i)
1538 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1540 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1541 start_slot + i, view ? view->wined3d_view : NULL);
1543 wined3d_mutex_unlock();
1546 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1547 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1549 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1550 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1552 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1553 iface, shader, class_instances, class_instance_count);
1555 if (class_instances)
1556 FIXME("Dynamic linking is not implemented yet.\n");
1558 wined3d_mutex_lock();
1559 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1560 hs ? hs->wined3d_shader : NULL);
1561 wined3d_mutex_unlock();
1564 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1565 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1567 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1568 unsigned int i;
1570 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1571 iface, start_slot, sampler_count, samplers);
1573 wined3d_mutex_lock();
1574 for (i = 0; i < sampler_count; ++i)
1576 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1578 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1579 sampler ? sampler->wined3d_sampler : NULL);
1581 wined3d_mutex_unlock();
1584 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1585 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1587 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1588 iface, start_slot, buffer_count, buffers);
1590 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1591 buffer_count, buffers);
1594 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1595 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1597 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1598 unsigned int i;
1600 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1601 iface, start_slot, view_count, views);
1603 wined3d_mutex_lock();
1604 for (i = 0; i < view_count; ++i)
1606 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1608 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1609 start_slot + i, view ? view->wined3d_view : NULL);
1611 wined3d_mutex_unlock();
1614 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1615 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1617 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1618 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1620 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1621 iface, shader, class_instances, class_instance_count);
1623 if (class_instances)
1624 FIXME("Dynamic linking is not implemented yet.\n");
1626 wined3d_mutex_lock();
1627 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1628 ds ? ds->wined3d_shader : NULL);
1629 wined3d_mutex_unlock();
1632 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1633 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1635 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1636 unsigned int i;
1638 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1639 iface, start_slot, sampler_count, samplers);
1641 wined3d_mutex_lock();
1642 for (i = 0; i < sampler_count; ++i)
1644 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1646 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1647 sampler ? sampler->wined3d_sampler : NULL);
1649 wined3d_mutex_unlock();
1652 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1653 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1655 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1656 iface, start_slot, buffer_count, buffers);
1658 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1659 buffer_count, buffers);
1662 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1663 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1665 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1666 unsigned int i;
1668 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1669 iface, start_slot, view_count, views);
1671 wined3d_mutex_lock();
1672 for (i = 0; i < view_count; ++i)
1674 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1676 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1677 start_slot + i, view ? view->wined3d_view : NULL);
1679 wined3d_mutex_unlock();
1682 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1683 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1685 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1686 unsigned int i;
1688 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1689 iface, start_slot, view_count, views, initial_counts);
1691 wined3d_mutex_lock();
1692 for (i = 0; i < view_count; ++i)
1694 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1696 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1697 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1699 wined3d_mutex_unlock();
1702 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1703 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1705 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1706 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1708 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1709 iface, shader, class_instances, class_instance_count);
1711 if (class_instances)
1712 FIXME("Dynamic linking is not implemented yet.\n");
1714 wined3d_mutex_lock();
1715 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1716 cs ? cs->wined3d_shader : NULL);
1717 wined3d_mutex_unlock();
1720 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1721 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1723 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1724 unsigned int i;
1726 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1727 iface, start_slot, sampler_count, samplers);
1729 wined3d_mutex_lock();
1730 for (i = 0; i < sampler_count; ++i)
1732 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1734 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1735 sampler ? sampler->wined3d_sampler : NULL);
1737 wined3d_mutex_unlock();
1740 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1741 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1743 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1744 iface, start_slot, buffer_count, buffers);
1746 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1747 buffer_count, buffers);
1750 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1751 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1753 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1754 iface, start_slot, buffer_count, buffers);
1756 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1757 buffer_count, buffers);
1760 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1761 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1763 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1764 unsigned int i;
1766 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1767 iface, start_slot, view_count, views);
1769 wined3d_mutex_lock();
1770 for (i = 0; i < view_count; ++i)
1772 struct wined3d_shader_resource_view *wined3d_view;
1773 struct d3d_shader_resource_view *view_impl;
1775 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1776 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1778 views[i] = NULL;
1779 continue;
1782 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1783 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1784 ID3D11ShaderResourceView_AddRef(views[i]);
1786 wined3d_mutex_unlock();
1789 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1790 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1792 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1793 struct wined3d_shader *wined3d_shader;
1794 struct d3d_pixel_shader *shader_impl;
1796 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1797 iface, shader, class_instances, class_instance_count);
1799 if (class_instances || class_instance_count)
1800 FIXME("Dynamic linking not implemented yet.\n");
1801 if (class_instance_count)
1802 *class_instance_count = 0;
1804 wined3d_mutex_lock();
1805 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1807 wined3d_mutex_unlock();
1808 *shader = NULL;
1809 return;
1812 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1813 wined3d_mutex_unlock();
1814 *shader = &shader_impl->ID3D11PixelShader_iface;
1815 ID3D11PixelShader_AddRef(*shader);
1818 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1819 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1821 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1822 unsigned int i;
1824 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1825 iface, start_slot, sampler_count, samplers);
1827 wined3d_mutex_lock();
1828 for (i = 0; i < sampler_count; ++i)
1830 struct wined3d_sampler *wined3d_sampler;
1831 struct d3d_sampler_state *sampler_impl;
1833 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1834 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1836 samplers[i] = NULL;
1837 continue;
1840 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1841 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1842 ID3D11SamplerState_AddRef(samplers[i]);
1844 wined3d_mutex_unlock();
1847 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1848 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1850 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1851 struct d3d_vertex_shader *shader_impl;
1852 struct wined3d_shader *wined3d_shader;
1854 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1855 iface, shader, class_instances, class_instance_count);
1857 if (class_instances || class_instance_count)
1858 FIXME("Dynamic linking not implemented yet.\n");
1859 if (class_instance_count)
1860 *class_instance_count = 0;
1862 wined3d_mutex_lock();
1863 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1865 wined3d_mutex_unlock();
1866 *shader = NULL;
1867 return;
1870 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1871 wined3d_mutex_unlock();
1872 *shader = &shader_impl->ID3D11VertexShader_iface;
1873 ID3D11VertexShader_AddRef(*shader);
1876 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1877 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1879 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1880 iface, start_slot, buffer_count, buffers);
1882 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1883 buffer_count, buffers);
1886 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1887 ID3D11InputLayout **input_layout)
1889 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1890 struct wined3d_vertex_declaration *wined3d_declaration;
1891 struct d3d_input_layout *input_layout_impl;
1893 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1895 wined3d_mutex_lock();
1896 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1898 wined3d_mutex_unlock();
1899 *input_layout = NULL;
1900 return;
1903 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1904 wined3d_mutex_unlock();
1905 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1906 ID3D11InputLayout_AddRef(*input_layout);
1909 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1910 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1912 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1913 unsigned int i;
1915 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1916 iface, start_slot, buffer_count, buffers, strides, offsets);
1918 wined3d_mutex_lock();
1919 for (i = 0; i < buffer_count; ++i)
1921 struct wined3d_buffer *wined3d_buffer = NULL;
1922 struct d3d_buffer *buffer_impl;
1924 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1925 &wined3d_buffer, &offsets[i], &strides[i])))
1927 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1928 if (strides)
1929 strides[i] = 0;
1930 if (offsets)
1931 offsets[i] = 0;
1934 if (!wined3d_buffer)
1936 buffers[i] = NULL;
1937 continue;
1940 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1941 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1943 wined3d_mutex_unlock();
1946 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1947 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1949 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1950 enum wined3d_format_id wined3d_format;
1951 struct wined3d_buffer *wined3d_buffer;
1952 struct d3d_buffer *buffer_impl;
1954 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1956 wined3d_mutex_lock();
1957 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1958 *format = dxgi_format_from_wined3dformat(wined3d_format);
1959 if (!wined3d_buffer)
1961 wined3d_mutex_unlock();
1962 *buffer = NULL;
1963 return;
1966 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1967 wined3d_mutex_unlock();
1968 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1971 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1972 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1974 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1975 iface, start_slot, buffer_count, buffers);
1977 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1978 buffer_count, buffers);
1981 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1982 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1984 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1985 struct d3d_geometry_shader *shader_impl;
1986 struct wined3d_shader *wined3d_shader;
1988 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1989 iface, shader, class_instances, class_instance_count);
1991 if (class_instances || class_instance_count)
1992 FIXME("Dynamic linking not implemented yet.\n");
1993 if (class_instance_count)
1994 *class_instance_count = 0;
1996 wined3d_mutex_lock();
1997 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
1999 wined3d_mutex_unlock();
2000 *shader = NULL;
2001 return;
2004 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2005 wined3d_mutex_unlock();
2006 *shader = &shader_impl->ID3D11GeometryShader_iface;
2007 ID3D11GeometryShader_AddRef(*shader);
2010 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
2011 D3D11_PRIMITIVE_TOPOLOGY *topology)
2013 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2014 enum wined3d_primitive_type primitive_type;
2015 unsigned int patch_vertex_count;
2017 TRACE("iface %p, topology %p.\n", iface, topology);
2019 wined3d_mutex_lock();
2020 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
2021 wined3d_mutex_unlock();
2023 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
2026 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
2027 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2029 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2030 unsigned int i;
2032 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2034 wined3d_mutex_lock();
2035 for (i = 0; i < view_count; ++i)
2037 struct wined3d_shader_resource_view *wined3d_view;
2038 struct d3d_shader_resource_view *view_impl;
2040 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2041 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2043 views[i] = NULL;
2044 continue;
2047 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2048 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2049 ID3D11ShaderResourceView_AddRef(views[i]);
2051 wined3d_mutex_unlock();
2054 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
2055 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2057 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2058 unsigned int i;
2060 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2061 iface, start_slot, sampler_count, samplers);
2063 wined3d_mutex_lock();
2064 for (i = 0; i < sampler_count; ++i)
2066 struct wined3d_sampler *wined3d_sampler;
2067 struct d3d_sampler_state *sampler_impl;
2069 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2070 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2072 samplers[i] = NULL;
2073 continue;
2076 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2077 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2078 ID3D11SamplerState_AddRef(samplers[i]);
2080 wined3d_mutex_unlock();
2083 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2084 ID3D11Predicate **predicate, BOOL *value)
2086 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2087 struct wined3d_query *wined3d_predicate;
2088 struct d3d_query *predicate_impl;
2090 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2092 wined3d_mutex_lock();
2093 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2095 wined3d_mutex_unlock();
2096 *predicate = NULL;
2097 return;
2100 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2101 wined3d_mutex_unlock();
2102 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2103 ID3D11Predicate_AddRef(*predicate);
2106 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2107 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2109 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2110 unsigned int i;
2112 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2114 wined3d_mutex_lock();
2115 for (i = 0; i < view_count; ++i)
2117 struct wined3d_shader_resource_view *wined3d_view;
2118 struct d3d_shader_resource_view *view_impl;
2120 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2121 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2123 views[i] = NULL;
2124 continue;
2127 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2128 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2129 ID3D11ShaderResourceView_AddRef(views[i]);
2131 wined3d_mutex_unlock();
2134 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2135 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2137 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2138 unsigned int i;
2140 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2141 iface, start_slot, sampler_count, samplers);
2143 wined3d_mutex_lock();
2144 for (i = 0; i < sampler_count; ++i)
2146 struct d3d_sampler_state *sampler_impl;
2147 struct wined3d_sampler *wined3d_sampler;
2149 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2150 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2152 samplers[i] = NULL;
2153 continue;
2156 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2157 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2158 ID3D11SamplerState_AddRef(samplers[i]);
2160 wined3d_mutex_unlock();
2163 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2164 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2165 ID3D11DepthStencilView **depth_stencil_view)
2167 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2168 struct wined3d_rendertarget_view *wined3d_view;
2170 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2171 iface, render_target_view_count, render_target_views, depth_stencil_view);
2173 wined3d_mutex_lock();
2174 if (render_target_views)
2176 struct d3d_rendertarget_view *view_impl;
2177 unsigned int i;
2179 for (i = 0; i < render_target_view_count; ++i)
2181 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2182 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2184 render_target_views[i] = NULL;
2185 continue;
2188 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2189 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2193 if (depth_stencil_view)
2195 struct d3d_depthstencil_view *view_impl;
2197 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2198 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2200 *depth_stencil_view = NULL;
2202 else
2204 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2205 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2208 wined3d_mutex_unlock();
2211 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2212 ID3D11DeviceContext1 *iface,
2213 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2214 ID3D11DepthStencilView **depth_stencil_view,
2215 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2216 ID3D11UnorderedAccessView **unordered_access_views)
2218 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2219 struct wined3d_unordered_access_view *wined3d_view;
2220 struct d3d11_unordered_access_view *view_impl;
2221 unsigned int i;
2223 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2224 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2225 "unordered_access_views %p.\n",
2226 iface, render_target_view_count, render_target_views, depth_stencil_view,
2227 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2229 if (render_target_views || depth_stencil_view)
2230 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2231 render_target_views, depth_stencil_view);
2233 if (unordered_access_views)
2235 wined3d_mutex_lock();
2236 for (i = 0; i < unordered_access_view_count; ++i)
2238 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2239 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2241 unordered_access_views[i] = NULL;
2242 continue;
2245 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2246 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2247 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2249 wined3d_mutex_unlock();
2253 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2254 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2256 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2257 struct wined3d_blend_state *wined3d_state;
2258 struct d3d_blend_state *blend_state_impl;
2260 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2261 iface, blend_state, blend_factor, sample_mask);
2263 wined3d_mutex_lock();
2264 if ((wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2265 (struct wined3d_color *)blend_factor, sample_mask)))
2267 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2268 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2270 else
2272 *blend_state = NULL;
2274 wined3d_mutex_unlock();
2277 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2278 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2280 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2281 struct wined3d_depth_stencil_state *wined3d_state;
2282 struct d3d_depthstencil_state *state_impl;
2284 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2285 iface, depth_stencil_state, stencil_ref);
2287 wined3d_mutex_lock();
2288 if ((wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref)))
2290 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2291 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2293 else
2295 *depth_stencil_state = NULL;
2297 wined3d_mutex_unlock();
2300 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2301 UINT buffer_count, ID3D11Buffer **buffers)
2303 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2304 unsigned int i;
2306 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2308 wined3d_mutex_lock();
2309 for (i = 0; i < buffer_count; ++i)
2311 struct wined3d_buffer *wined3d_buffer;
2312 struct d3d_buffer *buffer_impl;
2314 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2316 buffers[i] = NULL;
2317 continue;
2320 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2321 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2322 ID3D11Buffer_AddRef(buffers[i]);
2324 wined3d_mutex_unlock();
2327 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2328 ID3D11RasterizerState **rasterizer_state)
2330 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2331 struct d3d_rasterizer_state *rasterizer_state_impl;
2332 struct wined3d_rasterizer_state *wined3d_state;
2334 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2336 wined3d_mutex_lock();
2337 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2339 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2340 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2342 else
2344 *rasterizer_state = NULL;
2346 wined3d_mutex_unlock();
2349 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2350 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2352 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2353 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2354 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2356 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2358 if (!viewport_count)
2359 return;
2361 wined3d_mutex_lock();
2362 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2363 wined3d_mutex_unlock();
2365 if (!viewports)
2367 *viewport_count = actual_count;
2368 return;
2371 if (*viewport_count > actual_count)
2372 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2374 *viewport_count = min(actual_count, *viewport_count);
2375 for (i = 0; i < *viewport_count; ++i)
2377 viewports[i].TopLeftX = wined3d_vp[i].x;
2378 viewports[i].TopLeftY = wined3d_vp[i].y;
2379 viewports[i].Width = wined3d_vp[i].width;
2380 viewports[i].Height = wined3d_vp[i].height;
2381 viewports[i].MinDepth = wined3d_vp[i].min_z;
2382 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2386 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2387 UINT *rect_count, D3D11_RECT *rects)
2389 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2390 unsigned int actual_count;
2392 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2394 if (!rect_count)
2395 return;
2397 actual_count = *rect_count;
2399 wined3d_mutex_lock();
2400 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2401 wined3d_mutex_unlock();
2403 if (rects && *rect_count > actual_count)
2404 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2405 *rect_count = actual_count;
2408 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2409 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2411 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2412 unsigned int i;
2414 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2416 wined3d_mutex_lock();
2417 for (i = 0; i < view_count; ++i)
2419 struct wined3d_shader_resource_view *wined3d_view;
2420 struct d3d_shader_resource_view *view_impl;
2422 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2423 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2425 views[i] = NULL;
2426 continue;
2429 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2430 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2432 wined3d_mutex_unlock();
2435 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2436 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2438 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2439 struct d3d11_hull_shader *shader_impl;
2440 struct wined3d_shader *wined3d_shader;
2442 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2443 iface, shader, class_instances, class_instance_count);
2445 if (class_instances || class_instance_count)
2446 FIXME("Dynamic linking not implemented yet.\n");
2447 if (class_instance_count)
2448 *class_instance_count = 0;
2450 wined3d_mutex_lock();
2451 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2453 wined3d_mutex_unlock();
2454 *shader = NULL;
2455 return;
2458 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2459 wined3d_mutex_unlock();
2460 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2463 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2464 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2466 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2467 unsigned int i;
2469 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2470 iface, start_slot, sampler_count, samplers);
2472 wined3d_mutex_lock();
2473 for (i = 0; i < sampler_count; ++i)
2475 struct wined3d_sampler *wined3d_sampler;
2476 struct d3d_sampler_state *sampler_impl;
2478 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2479 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2481 samplers[i] = NULL;
2482 continue;
2485 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2486 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2488 wined3d_mutex_unlock();
2491 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2492 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2494 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2495 iface, start_slot, buffer_count, buffers);
2497 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2498 buffer_count, buffers);
2501 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2502 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2504 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2505 unsigned int i;
2507 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2508 iface, start_slot, view_count, views);
2510 wined3d_mutex_lock();
2511 for (i = 0; i < view_count; ++i)
2513 struct wined3d_shader_resource_view *wined3d_view;
2514 struct d3d_shader_resource_view *view_impl;
2516 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2517 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2519 views[i] = NULL;
2520 continue;
2523 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2524 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2526 wined3d_mutex_unlock();
2529 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2530 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2532 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2533 struct d3d11_domain_shader *shader_impl;
2534 struct wined3d_shader *wined3d_shader;
2536 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2537 iface, shader, class_instances, class_instance_count);
2539 if (class_instances || class_instance_count)
2540 FIXME("Dynamic linking not implemented yet.\n");
2541 if (class_instance_count)
2542 *class_instance_count = 0;
2544 wined3d_mutex_lock();
2545 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2547 wined3d_mutex_unlock();
2548 *shader = NULL;
2549 return;
2552 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2553 wined3d_mutex_unlock();
2554 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2557 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2558 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2560 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2561 unsigned int i;
2563 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2564 iface, start_slot, sampler_count, samplers);
2566 wined3d_mutex_lock();
2567 for (i = 0; i < sampler_count; ++i)
2569 struct wined3d_sampler *wined3d_sampler;
2570 struct d3d_sampler_state *sampler_impl;
2572 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2573 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2575 samplers[i] = NULL;
2576 continue;
2579 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2580 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2582 wined3d_mutex_unlock();
2585 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2586 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2588 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2589 iface, start_slot, buffer_count, buffers);
2591 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2592 buffer_count, buffers);
2595 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2596 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2598 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2599 unsigned int i;
2601 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2603 wined3d_mutex_lock();
2604 for (i = 0; i < view_count; ++i)
2606 struct wined3d_shader_resource_view *wined3d_view;
2607 struct d3d_shader_resource_view *view_impl;
2609 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2610 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2612 views[i] = NULL;
2613 continue;
2616 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2617 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2619 wined3d_mutex_unlock();
2622 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2623 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2625 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2626 unsigned int i;
2628 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2630 wined3d_mutex_lock();
2631 for (i = 0; i < view_count; ++i)
2633 struct wined3d_unordered_access_view *wined3d_view;
2634 struct d3d11_unordered_access_view *view_impl;
2636 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2637 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2639 views[i] = NULL;
2640 continue;
2643 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2644 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2646 wined3d_mutex_unlock();
2649 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2650 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2652 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2653 struct d3d11_compute_shader *shader_impl;
2654 struct wined3d_shader *wined3d_shader;
2656 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2657 iface, shader, class_instances, class_instance_count);
2659 if (class_instances || class_instance_count)
2660 FIXME("Dynamic linking not implemented yet.\n");
2661 if (class_instance_count)
2662 *class_instance_count = 0;
2664 wined3d_mutex_lock();
2665 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2667 wined3d_mutex_unlock();
2668 *shader = NULL;
2669 return;
2672 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2673 wined3d_mutex_unlock();
2674 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2677 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2678 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2680 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2681 unsigned int i;
2683 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2684 iface, start_slot, sampler_count, samplers);
2686 wined3d_mutex_lock();
2687 for (i = 0; i < sampler_count; ++i)
2689 struct wined3d_sampler *wined3d_sampler;
2690 struct d3d_sampler_state *sampler_impl;
2692 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2693 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2695 samplers[i] = NULL;
2696 continue;
2699 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2700 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2702 wined3d_mutex_unlock();
2705 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2706 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2708 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2709 iface, start_slot, buffer_count, buffers);
2711 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2712 buffer_count, buffers);
2715 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2717 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2719 TRACE("iface %p.\n", iface);
2721 wined3d_mutex_lock();
2722 wined3d_device_context_reset_state(context->wined3d_context);
2723 wined3d_mutex_unlock();
2726 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2728 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2730 TRACE("iface %p.\n", iface);
2732 wined3d_mutex_lock();
2733 wined3d_device_context_flush(context->wined3d_context);
2734 wined3d_mutex_unlock();
2737 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2739 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2741 TRACE("iface %p.\n", iface);
2743 return context->type;
2746 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2748 TRACE("iface %p.\n", iface);
2750 return 0;
2753 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2754 BOOL restore, ID3D11CommandList **command_list)
2756 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2757 struct d3d11_command_list *object;
2758 HRESULT hr;
2760 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2762 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2764 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2765 return DXGI_ERROR_INVALID_CALL;
2768 if (!(object = heap_alloc_zero(sizeof(*object))))
2769 return E_OUTOFMEMORY;
2771 wined3d_mutex_lock();
2773 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2774 !!restore, &object->wined3d_list)))
2776 WARN("Failed to record wined3d command list, hr %#x.\n", hr);
2777 heap_free(object);
2778 return hr;
2781 wined3d_mutex_unlock();
2783 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2784 object->refcount = 1;
2785 object->device = &context->device->ID3D11Device2_iface;
2786 wined3d_private_store_init(&object->private_store);
2788 ID3D11Device2_AddRef(object->device);
2790 TRACE("Created command list %p.\n", object);
2791 *command_list = &object->ID3D11CommandList_iface;
2793 return S_OK;
2796 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2797 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2798 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2800 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2801 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2802 struct wined3d_box wined3d_src_box;
2804 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2805 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2806 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2807 src_resource, src_subresource_idx, src_box, flags);
2809 if (!dst_resource || !src_resource)
2810 return;
2812 if (src_box)
2813 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2814 src_box->right, src_box->bottom, src_box->front, src_box->back);
2816 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2817 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2818 wined3d_mutex_lock();
2819 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2820 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2821 wined3d_mutex_unlock();
2824 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2825 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2826 UINT row_pitch, UINT depth_pitch, UINT flags)
2828 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2829 struct wined3d_resource *wined3d_resource;
2830 struct wined3d_box wined3d_box;
2832 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2833 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2835 if (box)
2836 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2837 box->front, box->back);
2839 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2840 wined3d_mutex_lock();
2841 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2842 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2843 wined3d_mutex_unlock();
2846 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2847 ID3D11Resource *resource)
2849 FIXME("iface %p, resource %p stub!\n", iface, resource);
2852 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2854 FIXME("iface %p, view %p stub!\n", iface, view);
2857 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2858 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2859 const UINT *num_constants)
2861 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2862 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2865 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2866 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2867 const UINT *num_constants)
2869 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2870 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2873 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2874 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2875 const UINT *num_constants)
2877 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2878 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2881 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(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_PSSetConstantBuffers1(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_CSSetConstantBuffers1(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_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2906 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2908 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2909 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2912 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2913 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2915 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2916 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2919 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2920 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2922 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2923 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2926 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2927 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2929 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2930 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2933 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2934 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2936 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2937 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2940 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2941 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2943 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2944 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2947 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2948 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2950 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2951 struct d3d_device_context_state *state_impl, *prev_impl;
2952 struct d3d_device *device = context->device;
2953 struct wined3d_state *wined3d_state;
2955 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2957 if (prev)
2958 *prev = NULL;
2960 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
2962 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
2963 return;
2966 if (!state)
2967 return;
2969 wined3d_mutex_lock();
2971 prev_impl = device->state;
2972 state_impl = impl_from_ID3DDeviceContextState(state);
2973 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2974 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2975 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
2977 if (prev)
2978 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2980 d3d_device_context_state_private_addref(state_impl);
2981 device->state = state_impl;
2982 d3d_device_context_state_private_release(prev_impl);
2984 if (d3d_device_is_d3d10_active(device))
2985 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2986 wined3d_mutex_unlock();
2989 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2990 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2992 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2995 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2996 const D3D11_RECT *rects, UINT num_rects)
2998 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
3001 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
3003 /* IUnknown methods */
3004 d3d11_device_context_QueryInterface,
3005 d3d11_device_context_AddRef,
3006 d3d11_device_context_Release,
3007 /* ID3D11DeviceChild methods */
3008 d3d11_device_context_GetDevice,
3009 d3d11_device_context_GetPrivateData,
3010 d3d11_device_context_SetPrivateData,
3011 d3d11_device_context_SetPrivateDataInterface,
3012 /* ID3D11DeviceContext methods */
3013 d3d11_device_context_VSSetConstantBuffers,
3014 d3d11_device_context_PSSetShaderResources,
3015 d3d11_device_context_PSSetShader,
3016 d3d11_device_context_PSSetSamplers,
3017 d3d11_device_context_VSSetShader,
3018 d3d11_device_context_DrawIndexed,
3019 d3d11_device_context_Draw,
3020 d3d11_device_context_Map,
3021 d3d11_device_context_Unmap,
3022 d3d11_device_context_PSSetConstantBuffers,
3023 d3d11_device_context_IASetInputLayout,
3024 d3d11_device_context_IASetVertexBuffers,
3025 d3d11_device_context_IASetIndexBuffer,
3026 d3d11_device_context_DrawIndexedInstanced,
3027 d3d11_device_context_DrawInstanced,
3028 d3d11_device_context_GSSetConstantBuffers,
3029 d3d11_device_context_GSSetShader,
3030 d3d11_device_context_IASetPrimitiveTopology,
3031 d3d11_device_context_VSSetShaderResources,
3032 d3d11_device_context_VSSetSamplers,
3033 d3d11_device_context_Begin,
3034 d3d11_device_context_End,
3035 d3d11_device_context_GetData,
3036 d3d11_device_context_SetPredication,
3037 d3d11_device_context_GSSetShaderResources,
3038 d3d11_device_context_GSSetSamplers,
3039 d3d11_device_context_OMSetRenderTargets,
3040 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3041 d3d11_device_context_OMSetBlendState,
3042 d3d11_device_context_OMSetDepthStencilState,
3043 d3d11_device_context_SOSetTargets,
3044 d3d11_device_context_DrawAuto,
3045 d3d11_device_context_DrawIndexedInstancedIndirect,
3046 d3d11_device_context_DrawInstancedIndirect,
3047 d3d11_device_context_Dispatch,
3048 d3d11_device_context_DispatchIndirect,
3049 d3d11_device_context_RSSetState,
3050 d3d11_device_context_RSSetViewports,
3051 d3d11_device_context_RSSetScissorRects,
3052 d3d11_device_context_CopySubresourceRegion,
3053 d3d11_device_context_CopyResource,
3054 d3d11_device_context_UpdateSubresource,
3055 d3d11_device_context_CopyStructureCount,
3056 d3d11_device_context_ClearRenderTargetView,
3057 d3d11_device_context_ClearUnorderedAccessViewUint,
3058 d3d11_device_context_ClearUnorderedAccessViewFloat,
3059 d3d11_device_context_ClearDepthStencilView,
3060 d3d11_device_context_GenerateMips,
3061 d3d11_device_context_SetResourceMinLOD,
3062 d3d11_device_context_GetResourceMinLOD,
3063 d3d11_device_context_ResolveSubresource,
3064 d3d11_device_context_ExecuteCommandList,
3065 d3d11_device_context_HSSetShaderResources,
3066 d3d11_device_context_HSSetShader,
3067 d3d11_device_context_HSSetSamplers,
3068 d3d11_device_context_HSSetConstantBuffers,
3069 d3d11_device_context_DSSetShaderResources,
3070 d3d11_device_context_DSSetShader,
3071 d3d11_device_context_DSSetSamplers,
3072 d3d11_device_context_DSSetConstantBuffers,
3073 d3d11_device_context_CSSetShaderResources,
3074 d3d11_device_context_CSSetUnorderedAccessViews,
3075 d3d11_device_context_CSSetShader,
3076 d3d11_device_context_CSSetSamplers,
3077 d3d11_device_context_CSSetConstantBuffers,
3078 d3d11_device_context_VSGetConstantBuffers,
3079 d3d11_device_context_PSGetShaderResources,
3080 d3d11_device_context_PSGetShader,
3081 d3d11_device_context_PSGetSamplers,
3082 d3d11_device_context_VSGetShader,
3083 d3d11_device_context_PSGetConstantBuffers,
3084 d3d11_device_context_IAGetInputLayout,
3085 d3d11_device_context_IAGetVertexBuffers,
3086 d3d11_device_context_IAGetIndexBuffer,
3087 d3d11_device_context_GSGetConstantBuffers,
3088 d3d11_device_context_GSGetShader,
3089 d3d11_device_context_IAGetPrimitiveTopology,
3090 d3d11_device_context_VSGetShaderResources,
3091 d3d11_device_context_VSGetSamplers,
3092 d3d11_device_context_GetPredication,
3093 d3d11_device_context_GSGetShaderResources,
3094 d3d11_device_context_GSGetSamplers,
3095 d3d11_device_context_OMGetRenderTargets,
3096 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3097 d3d11_device_context_OMGetBlendState,
3098 d3d11_device_context_OMGetDepthStencilState,
3099 d3d11_device_context_SOGetTargets,
3100 d3d11_device_context_RSGetState,
3101 d3d11_device_context_RSGetViewports,
3102 d3d11_device_context_RSGetScissorRects,
3103 d3d11_device_context_HSGetShaderResources,
3104 d3d11_device_context_HSGetShader,
3105 d3d11_device_context_HSGetSamplers,
3106 d3d11_device_context_HSGetConstantBuffers,
3107 d3d11_device_context_DSGetShaderResources,
3108 d3d11_device_context_DSGetShader,
3109 d3d11_device_context_DSGetSamplers,
3110 d3d11_device_context_DSGetConstantBuffers,
3111 d3d11_device_context_CSGetShaderResources,
3112 d3d11_device_context_CSGetUnorderedAccessViews,
3113 d3d11_device_context_CSGetShader,
3114 d3d11_device_context_CSGetSamplers,
3115 d3d11_device_context_CSGetConstantBuffers,
3116 d3d11_device_context_ClearState,
3117 d3d11_device_context_Flush,
3118 d3d11_device_context_GetType,
3119 d3d11_device_context_GetContextFlags,
3120 d3d11_device_context_FinishCommandList,
3121 /* ID3D11DeviceContext1 methods */
3122 d3d11_device_context_CopySubresourceRegion1,
3123 d3d11_device_context_UpdateSubresource1,
3124 d3d11_device_context_DiscardResource,
3125 d3d11_device_context_DiscardView,
3126 d3d11_device_context_VSSetConstantBuffers1,
3127 d3d11_device_context_HSSetConstantBuffers1,
3128 d3d11_device_context_DSSetConstantBuffers1,
3129 d3d11_device_context_GSSetConstantBuffers1,
3130 d3d11_device_context_PSSetConstantBuffers1,
3131 d3d11_device_context_CSSetConstantBuffers1,
3132 d3d11_device_context_VSGetConstantBuffers1,
3133 d3d11_device_context_HSGetConstantBuffers1,
3134 d3d11_device_context_DSGetConstantBuffers1,
3135 d3d11_device_context_GSGetConstantBuffers1,
3136 d3d11_device_context_PSGetConstantBuffers1,
3137 d3d11_device_context_CSGetConstantBuffers1,
3138 d3d11_device_context_SwapDeviceContextState,
3139 d3d11_device_context_ClearView,
3140 d3d11_device_context_DiscardView1,
3143 /* ID3D11Multithread methods */
3145 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3147 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3150 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3151 REFIID iid, void **out)
3153 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3155 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3157 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3160 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3162 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3164 TRACE("iface %p.\n", iface);
3166 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3169 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3171 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3173 TRACE("iface %p.\n", iface);
3175 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3178 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3180 TRACE("iface %p.\n", iface);
3182 wined3d_mutex_lock();
3185 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3187 TRACE("iface %p.\n", iface);
3189 wined3d_mutex_unlock();
3192 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3193 ID3D11Multithread *iface, BOOL enable)
3195 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3197 return TRUE;
3200 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3202 FIXME("iface %p stub!\n", iface);
3204 return TRUE;
3207 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3209 d3d11_multithread_QueryInterface,
3210 d3d11_multithread_AddRef,
3211 d3d11_multithread_Release,
3212 d3d11_multithread_Enter,
3213 d3d11_multithread_Leave,
3214 d3d11_multithread_SetMultithreadProtected,
3215 d3d11_multithread_GetMultithreadProtected,
3218 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3219 D3D11_DEVICE_CONTEXT_TYPE type)
3221 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3222 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3223 context->refcount = 1;
3224 context->type = type;
3226 context->device = device;
3227 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3229 wined3d_private_store_init(&context->private_store);
3232 /* ID3D11Device methods */
3234 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3236 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3237 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3240 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3242 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3243 return IUnknown_AddRef(device->outer_unk);
3246 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3248 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3249 return IUnknown_Release(device->outer_unk);
3252 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3253 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3255 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3256 struct d3d_buffer *object;
3257 HRESULT hr;
3259 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3261 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3262 return hr;
3264 *buffer = &object->ID3D11Buffer_iface;
3266 return S_OK;
3269 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3270 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3272 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3273 struct d3d_texture1d *object;
3274 HRESULT hr;
3276 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3278 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3279 return hr;
3281 *texture = &object->ID3D11Texture1D_iface;
3283 return S_OK;
3286 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3287 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3289 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3290 struct d3d_texture2d *object;
3291 HRESULT hr;
3293 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3295 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3296 return hr;
3298 *texture = &object->ID3D11Texture2D_iface;
3300 return S_OK;
3303 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3304 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3306 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3307 struct d3d_texture3d *object;
3308 HRESULT hr;
3310 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3312 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3313 return hr;
3315 *texture = &object->ID3D11Texture3D_iface;
3317 return S_OK;
3320 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3321 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3323 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3324 struct d3d_shader_resource_view *object;
3325 HRESULT hr;
3327 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3329 if (!resource)
3330 return E_INVALIDARG;
3332 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3333 return hr;
3335 *view = &object->ID3D11ShaderResourceView_iface;
3337 return S_OK;
3340 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3341 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3343 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3344 struct d3d11_unordered_access_view *object;
3345 HRESULT hr;
3347 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3349 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3350 return hr;
3352 *view = &object->ID3D11UnorderedAccessView_iface;
3354 return S_OK;
3357 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3358 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3360 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3361 struct d3d_rendertarget_view *object;
3362 HRESULT hr;
3364 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3366 if (!resource)
3367 return E_INVALIDARG;
3369 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3370 return hr;
3372 *view = &object->ID3D11RenderTargetView_iface;
3374 return S_OK;
3377 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3378 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3380 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3381 struct d3d_depthstencil_view *object;
3382 HRESULT hr;
3384 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3386 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3387 return hr;
3389 *view = &object->ID3D11DepthStencilView_iface;
3391 return S_OK;
3394 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3395 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3396 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3398 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3399 struct d3d_input_layout *object;
3400 HRESULT hr;
3402 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3403 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3404 shader_byte_code_length, input_layout);
3406 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3407 shader_byte_code, shader_byte_code_length, &object)))
3408 return hr;
3410 *input_layout = &object->ID3D11InputLayout_iface;
3412 return S_OK;
3415 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3416 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3418 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3419 struct d3d_vertex_shader *object;
3420 HRESULT hr;
3422 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3423 iface, byte_code, byte_code_length, class_linkage, shader);
3425 if (class_linkage)
3426 FIXME("Class linkage is not implemented yet.\n");
3428 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3429 return hr;
3431 *shader = &object->ID3D11VertexShader_iface;
3433 return S_OK;
3436 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3437 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3439 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3440 struct d3d_geometry_shader *object;
3441 HRESULT hr;
3443 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3444 iface, byte_code, byte_code_length, class_linkage, shader);
3446 if (class_linkage)
3447 FIXME("Class linkage is not implemented yet.\n");
3449 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3450 NULL, 0, NULL, 0, 0, &object)))
3451 return hr;
3453 *shader = &object->ID3D11GeometryShader_iface;
3455 return S_OK;
3458 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3459 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3460 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3461 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, so_entries %p, entry_count %u, "
3468 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3469 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3470 rasterizer_stream, class_linkage, shader);
3472 if (class_linkage)
3473 FIXME("Class linkage is not implemented yet.\n");
3475 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3476 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3478 *shader = NULL;
3479 return hr;
3482 *shader = &object->ID3D11GeometryShader_iface;
3484 return hr;
3487 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3488 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3490 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3491 struct d3d_pixel_shader *object;
3492 HRESULT hr;
3494 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3495 iface, byte_code, byte_code_length, class_linkage, shader);
3497 if (class_linkage)
3498 FIXME("Class linkage is not implemented yet.\n");
3500 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3501 return hr;
3503 *shader = &object->ID3D11PixelShader_iface;
3505 return S_OK;
3508 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3509 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3511 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3512 struct d3d11_hull_shader *object;
3513 HRESULT hr;
3515 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3516 iface, byte_code, byte_code_length, class_linkage, shader);
3518 if (class_linkage)
3519 FIXME("Class linkage is not implemented yet.\n");
3521 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3522 return hr;
3524 *shader = &object->ID3D11HullShader_iface;
3526 return S_OK;
3529 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3530 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3532 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3533 struct d3d11_domain_shader *object;
3534 HRESULT hr;
3536 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3537 iface, byte_code, byte_code_length, class_linkage, shader);
3539 if (class_linkage)
3540 FIXME("Class linkage is not implemented yet.\n");
3542 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3543 return hr;
3545 *shader = &object->ID3D11DomainShader_iface;
3547 return S_OK;
3550 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3551 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3553 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3554 struct d3d11_compute_shader *object;
3555 HRESULT hr;
3557 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3558 iface, byte_code, byte_code_length, class_linkage, shader);
3560 if (class_linkage)
3561 FIXME("Class linkage is not implemented yet.\n");
3563 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3564 return hr;
3566 *shader = &object->ID3D11ComputeShader_iface;
3568 return S_OK;
3571 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3572 ID3D11ClassLinkage **class_linkage)
3574 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3575 struct d3d11_class_linkage *object;
3576 HRESULT hr;
3578 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3580 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3581 return hr;
3583 *class_linkage = &object->ID3D11ClassLinkage_iface;
3585 return S_OK;
3588 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3589 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3591 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3592 struct d3d_blend_state *object;
3593 HRESULT hr;
3595 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3597 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3598 return hr;
3600 *blend_state = &object->ID3D11BlendState_iface;
3602 return S_OK;
3605 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3606 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3608 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3609 struct d3d_depthstencil_state *object;
3610 HRESULT hr;
3612 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3614 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3615 return hr;
3617 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3619 return S_OK;
3622 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3623 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3625 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3626 struct d3d_rasterizer_state *object;
3627 HRESULT hr;
3629 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3631 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3632 return hr;
3634 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3636 return S_OK;
3639 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3640 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3642 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3643 struct d3d_sampler_state *object;
3644 HRESULT hr;
3646 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3648 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3649 return hr;
3651 *sampler_state = &object->ID3D11SamplerState_iface;
3653 return S_OK;
3656 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3657 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3659 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3660 struct d3d_query *object;
3661 HRESULT hr;
3663 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3665 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3666 return hr;
3668 if (query)
3670 *query = &object->ID3D11Query_iface;
3671 return S_OK;
3674 ID3D11Query_Release(&object->ID3D11Query_iface);
3675 return S_FALSE;
3678 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3679 ID3D11Predicate **predicate)
3681 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3682 struct d3d_query *object;
3683 HRESULT hr;
3685 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3687 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3688 return hr;
3690 if (predicate)
3692 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3693 return S_OK;
3696 ID3D11Query_Release(&object->ID3D11Query_iface);
3697 return S_FALSE;
3700 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3701 ID3D11Counter **counter)
3703 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3705 return E_NOTIMPL;
3708 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3709 UINT flags, struct d3d11_device_context **context)
3711 struct d3d11_device_context *object;
3712 HRESULT hr;
3714 if (flags)
3715 FIXME("Ignoring flags %#x.\n", flags);
3717 if (!(object = heap_alloc_zero(sizeof(*object))))
3718 return E_OUTOFMEMORY;
3719 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3721 wined3d_mutex_lock();
3722 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3724 WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
3725 heap_free(object);
3726 wined3d_mutex_unlock();
3727 return hr;
3729 wined3d_mutex_unlock();
3731 TRACE("Created deferred context %p.\n", object);
3732 *context = object;
3734 return S_OK;
3737 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3738 ID3D11DeviceContext **context)
3740 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3741 struct d3d11_device_context *object;
3742 HRESULT hr;
3744 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3746 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3747 return hr;
3749 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3750 return S_OK;
3753 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3754 void **out)
3756 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3758 return E_NOTIMPL;
3761 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3762 UINT *format_support)
3764 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3765 struct wined3d_device_creation_parameters params;
3766 struct wined3d_adapter *wined3d_adapter;
3767 enum wined3d_format_id wined3d_format;
3768 D3D_FEATURE_LEVEL feature_level;
3769 struct wined3d *wined3d;
3770 unsigned int i;
3772 static const struct
3774 enum wined3d_resource_type rtype;
3775 unsigned int bind_flags;
3776 unsigned int usage;
3777 D3D11_FORMAT_SUPPORT flag;
3779 flag_mapping[] =
3781 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3782 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3783 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3784 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3785 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3786 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3787 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3788 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3789 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3790 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3792 HRESULT hr;
3794 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3796 wined3d_format = wined3dformat_from_dxgi_format(format);
3797 if (format && !wined3d_format)
3799 WARN("Invalid format %#x.\n", format);
3800 *format_support = 0;
3801 return E_FAIL;
3804 *format_support = 0;
3806 wined3d_mutex_lock();
3807 feature_level = device->state->feature_level;
3808 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3809 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3810 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3811 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3813 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3814 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3815 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3816 continue;
3817 if (hr != WINED3D_OK)
3819 WARN("Failed to check device format support, hr %#x.\n", hr);
3820 wined3d_mutex_unlock();
3821 return E_FAIL;
3824 *format_support |= flag_mapping[i].flag;
3826 wined3d_mutex_unlock();
3828 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3829 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3831 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3832 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3834 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3835 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3836 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3838 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3839 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3841 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3843 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3844 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3846 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3847 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3851 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3852 * support multisample. */
3853 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3854 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3855 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3856 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3858 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3859 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3860 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3863 return S_OK;
3866 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3867 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3869 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3870 struct wined3d_device_creation_parameters params;
3871 struct wined3d_adapter *wined3d_adapter;
3872 struct wined3d *wined3d;
3873 HRESULT hr;
3875 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3876 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3878 if (!quality_level_count)
3879 return E_INVALIDARG;
3881 *quality_level_count = 0;
3883 if (!sample_count)
3884 return E_FAIL;
3885 if (sample_count == 1)
3887 *quality_level_count = 1;
3888 return S_OK;
3890 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3891 return E_FAIL;
3893 wined3d_mutex_lock();
3894 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3895 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3896 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3897 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3898 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3899 wined3d_mutex_unlock();
3901 if (hr == WINED3DERR_INVALIDCALL)
3902 return E_INVALIDARG;
3903 if (hr == WINED3DERR_NOTAVAILABLE)
3904 return S_OK;
3905 return hr;
3908 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3910 FIXME("iface %p, info %p stub!\n", iface, info);
3913 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3914 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3915 char *units, UINT *units_length, char *description, UINT *description_length)
3917 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3918 "units %p, units_length %p, description %p, description_length %p stub!\n",
3919 iface, desc, type, active_counter_count, name, name_length,
3920 units, units_length, description, description_length);
3922 return E_NOTIMPL;
3925 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3926 void *feature_support_data, UINT feature_support_data_size)
3928 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3929 struct wined3d_caps wined3d_caps;
3930 HRESULT hr;
3932 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3933 iface, feature, feature_support_data, feature_support_data_size);
3935 switch (feature)
3937 case D3D11_FEATURE_THREADING:
3939 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3940 if (feature_support_data_size != sizeof(*threading_data))
3942 WARN("Invalid data size.\n");
3943 return E_INVALIDARG;
3946 /* We lie about the threading support to make Tomb Raider 2013 and
3947 * Deus Ex: Human Revolution happy. */
3948 FIXME("Returning fake threading support data.\n");
3949 threading_data->DriverConcurrentCreates = TRUE;
3950 threading_data->DriverCommandLists = TRUE;
3951 return S_OK;
3954 case D3D11_FEATURE_DOUBLES:
3956 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3957 if (feature_support_data_size != sizeof(*doubles_data))
3959 WARN("Invalid data size.\n");
3960 return E_INVALIDARG;
3963 wined3d_mutex_lock();
3964 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3965 wined3d_mutex_unlock();
3966 if (FAILED(hr))
3968 WARN("Failed to get device caps, hr %#x.\n", hr);
3969 return hr;
3972 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3973 return S_OK;
3976 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3978 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3979 if (feature_support_data_size != sizeof(*options))
3981 WARN("Invalid data size.\n");
3982 return E_INVALIDARG;
3985 wined3d_mutex_lock();
3986 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3987 wined3d_mutex_unlock();
3988 if (FAILED(hr))
3990 WARN("Failed to get device caps, hr %#x.\n", hr);
3991 return hr;
3994 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
3995 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
3996 return S_OK;
3999 case D3D11_FEATURE_D3D11_OPTIONS:
4001 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4002 if (feature_support_data_size != sizeof(*options))
4004 WARN("Invalid data size.\n");
4005 return E_INVALIDARG;
4008 FIXME("Returning fake Options support data.\n");
4009 options->OutputMergerLogicOp = FALSE;
4010 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4011 options->DiscardAPIsSeenByDriver = FALSE;
4012 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4013 options->ClearView = FALSE;
4014 options->CopyWithOverlap = FALSE;
4015 options->ConstantBufferPartialUpdate = FALSE;
4016 options->ConstantBufferOffsetting = FALSE;
4017 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
4018 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
4019 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4020 options->SAD4ShaderInstructions = FALSE;
4021 options->ExtendedDoublesShaderInstructions = FALSE;
4022 options->ExtendedResourceSharing = FALSE;
4023 return S_OK;
4026 case D3D11_FEATURE_D3D11_OPTIONS1:
4028 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4029 if (feature_support_data_size != sizeof(*options))
4031 WARN("Invalid data size.\n");
4032 return E_INVALIDARG;
4035 FIXME("Returning fake Options1 support data.\n");
4036 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4037 options->MinMaxFiltering = FALSE;
4038 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4039 options->MapOnDefaultBuffers = FALSE;
4040 return S_OK;
4043 case D3D11_FEATURE_D3D11_OPTIONS3:
4045 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4046 if (feature_support_data_size != sizeof(*options))
4048 WARN("Invalid data size.\n");
4049 return E_INVALIDARG;
4052 wined3d_mutex_lock();
4053 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4054 wined3d_mutex_unlock();
4055 if (FAILED(hr))
4057 WARN("Failed to get device caps, hr %#x.\n", hr);
4058 return hr;
4061 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4062 = wined3d_caps.viewport_array_index_any_shader;
4063 return S_OK;
4066 case D3D11_FEATURE_ARCHITECTURE_INFO:
4068 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4069 if (feature_support_data_size != sizeof(*options))
4071 WARN("Invalid data size.\n");
4072 return E_INVALIDARG;
4075 FIXME("Returning fake data architecture info.\n");
4076 options->TileBasedDeferredRenderer = FALSE;
4077 return S_OK;
4080 default:
4081 FIXME("Unhandled feature %#x.\n", feature);
4082 return E_NOTIMPL;
4086 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4087 UINT *data_size, void *data)
4089 IDXGIDevice *dxgi_device;
4090 HRESULT hr;
4092 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4094 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4095 return hr;
4096 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4097 IDXGIDevice_Release(dxgi_device);
4099 return hr;
4102 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4103 UINT data_size, const void *data)
4105 IDXGIDevice *dxgi_device;
4106 HRESULT hr;
4108 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4110 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4111 return hr;
4112 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4113 IDXGIDevice_Release(dxgi_device);
4115 return hr;
4118 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4119 const IUnknown *data)
4121 IDXGIDevice *dxgi_device;
4122 HRESULT hr;
4124 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4126 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4127 return hr;
4128 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4129 IDXGIDevice_Release(dxgi_device);
4131 return hr;
4134 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4136 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4138 TRACE("iface %p.\n", iface);
4140 return device->state->feature_level;
4143 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4145 FIXME("iface %p stub!\n", iface);
4147 return 0;
4150 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4152 WARN("iface %p stub!\n", iface);
4154 return S_OK;
4157 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4158 ID3D11DeviceContext **immediate_context)
4160 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4162 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4164 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4165 ID3D11DeviceContext_AddRef(*immediate_context);
4168 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4170 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4172 return E_NOTIMPL;
4175 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4177 FIXME("iface %p stub!\n", iface);
4179 return 0;
4182 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4183 ID3D11DeviceContext1 **immediate_context)
4185 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4187 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4189 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4190 ID3D11DeviceContext1_AddRef(*immediate_context);
4193 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4194 ID3D11DeviceContext1 **context)
4196 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4197 struct d3d11_device_context *object;
4198 HRESULT hr;
4200 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4202 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4203 return hr;
4205 *context = &object->ID3D11DeviceContext1_iface;
4206 return S_OK;
4209 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4210 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4212 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4214 return E_NOTIMPL;
4217 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4218 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4220 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4222 return E_NOTIMPL;
4225 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4226 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4227 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4229 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4230 struct d3d_device_context_state *state_impl;
4231 struct wined3d_state *wined3d_state;
4232 D3D_FEATURE_LEVEL feature_level;
4233 HRESULT hr = E_INVALIDARG;
4235 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4236 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4237 iface, flags, feature_levels, feature_level_count,
4238 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4240 if (flags)
4241 FIXME("Ignoring flags %#x.\n", flags);
4243 wined3d_mutex_lock();
4245 if (!feature_level_count)
4246 goto fail;
4248 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4249 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4250 goto fail;
4251 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4253 if (chosen_feature_level)
4254 *chosen_feature_level = feature_level;
4256 if (!state)
4258 wined3d_state_destroy(wined3d_state);
4259 wined3d_mutex_unlock();
4260 return S_FALSE;
4263 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4265 wined3d_state_destroy(wined3d_state);
4266 hr = E_OUTOFMEMORY;
4267 goto fail;
4270 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4271 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4273 wined3d_state_destroy(wined3d_state);
4274 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4275 hr = E_FAIL;
4276 goto fail;
4279 *state = &state_impl->ID3DDeviceContextState_iface;
4280 device->d3d11_only = FALSE;
4281 wined3d_mutex_unlock();
4283 return S_OK;
4285 fail:
4286 wined3d_mutex_unlock();
4287 if (chosen_feature_level)
4288 *chosen_feature_level = 0;
4289 if (state)
4290 *state = NULL;
4291 return hr;
4294 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4295 REFIID iid, void **resource)
4297 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4299 return E_NOTIMPL;
4302 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4303 DWORD access, REFIID iid, void **resource)
4305 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4306 debugstr_guid(iid), resource);
4308 return E_NOTIMPL;
4311 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4312 ID3D11DeviceContext2 **context)
4314 FIXME("iface %p, context %p stub!\n", iface, context);
4317 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4318 UINT flags, ID3D11DeviceContext2 **context)
4320 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4322 return E_NOTIMPL;
4325 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4326 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4327 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4328 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4330 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4331 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4332 iface, resource, tile_count, mip_desc, tile_shape,
4333 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4336 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4337 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4339 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4340 iface, format, sample_count, flags, quality_level_count);
4342 return E_NOTIMPL;
4345 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4347 /* IUnknown methods */
4348 d3d11_device_QueryInterface,
4349 d3d11_device_AddRef,
4350 d3d11_device_Release,
4351 /* ID3D11Device methods */
4352 d3d11_device_CreateBuffer,
4353 d3d11_device_CreateTexture1D,
4354 d3d11_device_CreateTexture2D,
4355 d3d11_device_CreateTexture3D,
4356 d3d11_device_CreateShaderResourceView,
4357 d3d11_device_CreateUnorderedAccessView,
4358 d3d11_device_CreateRenderTargetView,
4359 d3d11_device_CreateDepthStencilView,
4360 d3d11_device_CreateInputLayout,
4361 d3d11_device_CreateVertexShader,
4362 d3d11_device_CreateGeometryShader,
4363 d3d11_device_CreateGeometryShaderWithStreamOutput,
4364 d3d11_device_CreatePixelShader,
4365 d3d11_device_CreateHullShader,
4366 d3d11_device_CreateDomainShader,
4367 d3d11_device_CreateComputeShader,
4368 d3d11_device_CreateClassLinkage,
4369 d3d11_device_CreateBlendState,
4370 d3d11_device_CreateDepthStencilState,
4371 d3d11_device_CreateRasterizerState,
4372 d3d11_device_CreateSamplerState,
4373 d3d11_device_CreateQuery,
4374 d3d11_device_CreatePredicate,
4375 d3d11_device_CreateCounter,
4376 d3d11_device_CreateDeferredContext,
4377 d3d11_device_OpenSharedResource,
4378 d3d11_device_CheckFormatSupport,
4379 d3d11_device_CheckMultisampleQualityLevels,
4380 d3d11_device_CheckCounterInfo,
4381 d3d11_device_CheckCounter,
4382 d3d11_device_CheckFeatureSupport,
4383 d3d11_device_GetPrivateData,
4384 d3d11_device_SetPrivateData,
4385 d3d11_device_SetPrivateDataInterface,
4386 d3d11_device_GetFeatureLevel,
4387 d3d11_device_GetCreationFlags,
4388 d3d11_device_GetDeviceRemovedReason,
4389 d3d11_device_GetImmediateContext,
4390 d3d11_device_SetExceptionMode,
4391 d3d11_device_GetExceptionMode,
4392 /* ID3D11Device1 methods */
4393 d3d11_device_GetImmediateContext1,
4394 d3d11_device_CreateDeferredContext1,
4395 d3d11_device_CreateBlendState1,
4396 d3d11_device_CreateRasterizerState1,
4397 d3d11_device_CreateDeviceContextState,
4398 d3d11_device_OpenSharedResource1,
4399 d3d11_device_OpenSharedResourceByName,
4400 /* ID3D11Device2 methods */
4401 d3d11_device_GetImmediateContext2,
4402 d3d11_device_CreateDeferredContext2,
4403 d3d11_device_GetResourceTiling,
4404 d3d11_device_CheckMultisampleQualityLevels1,
4407 /* Inner IUnknown methods */
4409 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4411 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4414 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4416 struct d3d_device *device = impl_from_IUnknown(iface);
4418 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4420 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4421 || IsEqualGUID(riid, &IID_ID3D11Device1)
4422 || IsEqualGUID(riid, &IID_ID3D11Device)
4423 || IsEqualGUID(riid, &IID_IUnknown))
4425 *out = &device->ID3D11Device2_iface;
4427 else if (!device->d3d11_only
4428 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4429 || IsEqualGUID(riid, &IID_ID3D10Device)))
4431 *out = &device->ID3D10Device1_iface;
4433 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4435 *out = &device->ID3D10Multithread_iface;
4437 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4439 *out = &device->IWineDXGIDeviceParent_iface;
4441 else
4443 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4444 *out = NULL;
4445 return E_NOINTERFACE;
4448 IUnknown_AddRef((IUnknown *)*out);
4449 return S_OK;
4452 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4454 struct d3d_device *device = impl_from_IUnknown(iface);
4455 ULONG refcount = InterlockedIncrement(&device->refcount);
4457 TRACE("%p increasing refcount to %u.\n", device, refcount);
4459 return refcount;
4462 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4464 struct d3d_device *device = impl_from_IUnknown(iface);
4465 ULONG refcount = InterlockedDecrement(&device->refcount);
4466 unsigned int i;
4468 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4470 if (!refcount)
4472 if (device->state)
4473 d3d_device_context_state_private_release(device->state);
4474 for (i = 0; i < device->context_state_count; ++i)
4476 d3d_device_context_state_remove_entry(device->context_states[i], device);
4478 heap_free(device->context_states);
4479 d3d11_device_context_cleanup(&device->immediate_context);
4480 if (device->wined3d_device)
4482 wined3d_mutex_lock();
4483 wined3d_device_decref(device->wined3d_device);
4484 wined3d_mutex_unlock();
4486 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4487 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4488 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4489 wine_rb_destroy(&device->blend_states, NULL, NULL);
4492 return refcount;
4495 /* IUnknown methods */
4497 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4498 void **out)
4500 struct d3d_device *device = impl_from_ID3D10Device(iface);
4501 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4504 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4506 struct d3d_device *device = impl_from_ID3D10Device(iface);
4507 return IUnknown_AddRef(device->outer_unk);
4510 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4512 struct d3d_device *device = impl_from_ID3D10Device(iface);
4513 return IUnknown_Release(device->outer_unk);
4516 /* ID3D10Device methods */
4518 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4519 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4521 struct d3d_device *device = impl_from_ID3D10Device(iface);
4522 unsigned int i;
4524 wined3d_mutex_lock();
4525 for (i = 0; i < buffer_count; ++i)
4527 struct wined3d_buffer *wined3d_buffer;
4528 struct d3d_buffer *buffer_impl;
4530 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4531 type, start_slot + i)))
4533 buffers[i] = NULL;
4534 continue;
4537 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4538 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4539 ID3D10Buffer_AddRef(buffers[i]);
4541 wined3d_mutex_unlock();
4544 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4545 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4547 struct d3d_device *device = impl_from_ID3D10Device(iface);
4548 unsigned int i;
4550 wined3d_mutex_lock();
4551 for (i = 0; i < buffer_count; ++i)
4553 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4555 wined3d_device_context_set_constant_buffer(device->immediate_context.wined3d_context, type, start_slot + i,
4556 buffer ? buffer->wined3d_buffer : NULL);
4558 wined3d_mutex_unlock();
4561 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4562 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4564 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4565 iface, start_slot, buffer_count, buffers);
4567 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4568 buffer_count, buffers);
4571 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4572 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4574 struct d3d_device *device = impl_from_ID3D10Device(iface);
4575 unsigned int i;
4577 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4578 iface, start_slot, view_count, views);
4580 wined3d_mutex_lock();
4581 for (i = 0; i < view_count; ++i)
4583 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4585 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4586 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, view ? view->wined3d_view : NULL);
4588 wined3d_mutex_unlock();
4591 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4592 ID3D10PixelShader *shader)
4594 struct d3d_device *device = impl_from_ID3D10Device(iface);
4595 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4597 TRACE("iface %p, shader %p\n", iface, shader);
4599 wined3d_mutex_lock();
4600 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4601 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4602 wined3d_mutex_unlock();
4605 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4606 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4608 struct d3d_device *device = impl_from_ID3D10Device(iface);
4609 unsigned int i;
4611 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4612 iface, start_slot, sampler_count, samplers);
4614 wined3d_mutex_lock();
4615 for (i = 0; i < sampler_count; ++i)
4617 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4619 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4620 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4622 wined3d_mutex_unlock();
4625 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4626 ID3D10VertexShader *shader)
4628 struct d3d_device *device = impl_from_ID3D10Device(iface);
4629 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4631 TRACE("iface %p, shader %p\n", iface, shader);
4633 wined3d_mutex_lock();
4634 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4635 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4636 wined3d_mutex_unlock();
4639 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4640 UINT start_index_location, INT base_vertex_location)
4642 struct d3d_device *device = impl_from_ID3D10Device(iface);
4644 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4645 iface, index_count, start_index_location, base_vertex_location);
4647 wined3d_mutex_lock();
4648 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4649 base_vertex_location, start_index_location, index_count, 0, 0);
4650 wined3d_mutex_unlock();
4653 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4654 UINT start_vertex_location)
4656 struct d3d_device *device = impl_from_ID3D10Device(iface);
4658 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4659 iface, vertex_count, start_vertex_location);
4661 wined3d_mutex_lock();
4662 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4663 wined3d_mutex_unlock();
4666 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4667 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4669 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4670 iface, start_slot, buffer_count, buffers);
4672 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4673 buffer_count, buffers);
4676 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4677 ID3D10InputLayout *input_layout)
4679 struct d3d_device *device = impl_from_ID3D10Device(iface);
4680 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4682 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4684 wined3d_mutex_lock();
4685 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4686 layout ? layout->wined3d_decl : NULL);
4687 wined3d_mutex_unlock();
4690 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4691 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4693 struct d3d_device *device = impl_from_ID3D10Device(iface);
4694 unsigned int i;
4696 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4697 iface, start_slot, buffer_count, buffers, strides, offsets);
4699 wined3d_mutex_lock();
4700 for (i = 0; i < buffer_count; ++i)
4702 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4704 wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
4705 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
4707 wined3d_mutex_unlock();
4710 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4711 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4713 struct d3d_device *device = impl_from_ID3D10Device(iface);
4714 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4716 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4717 iface, buffer, debug_dxgi_format(format), offset);
4719 wined3d_mutex_lock();
4720 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4721 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4722 wined3dformat_from_dxgi_format(format), offset);
4723 wined3d_mutex_unlock();
4726 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4727 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4728 INT base_vertex_location, UINT start_instance_location)
4730 struct d3d_device *device = impl_from_ID3D10Device(iface);
4732 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4733 "base_vertex_location %d, start_instance_location %u.\n",
4734 iface, instance_index_count, instance_count, start_index_location,
4735 base_vertex_location, start_instance_location);
4737 wined3d_mutex_lock();
4738 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4739 start_index_location, instance_index_count, start_instance_location, instance_count);
4740 wined3d_mutex_unlock();
4743 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4744 UINT instance_vertex_count, UINT instance_count,
4745 UINT start_vertex_location, UINT start_instance_location)
4747 struct d3d_device *device = impl_from_ID3D10Device(iface);
4749 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4750 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4751 start_vertex_location, start_instance_location);
4753 wined3d_mutex_lock();
4754 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4755 instance_vertex_count, start_instance_location, instance_count);
4756 wined3d_mutex_unlock();
4759 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4760 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4762 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4763 iface, start_slot, buffer_count, buffers);
4765 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4766 buffer_count, buffers);
4769 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4771 struct d3d_device *device = impl_from_ID3D10Device(iface);
4772 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4774 TRACE("iface %p, shader %p.\n", iface, shader);
4776 wined3d_mutex_lock();
4777 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4778 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4779 wined3d_mutex_unlock();
4782 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4783 D3D10_PRIMITIVE_TOPOLOGY topology)
4785 struct d3d_device *device = impl_from_ID3D10Device(iface);
4787 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4789 wined3d_mutex_lock();
4790 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4791 (enum wined3d_primitive_type)topology, 0);
4792 wined3d_mutex_unlock();
4795 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4796 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4798 struct d3d_device *device = impl_from_ID3D10Device(iface);
4799 unsigned int i;
4801 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4802 iface, start_slot, view_count, views);
4804 wined3d_mutex_lock();
4805 for (i = 0; i < view_count; ++i)
4807 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4809 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4810 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, view ? view->wined3d_view : NULL);
4812 wined3d_mutex_unlock();
4815 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4816 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4818 struct d3d_device *device = impl_from_ID3D10Device(iface);
4819 unsigned int i;
4821 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4822 iface, start_slot, sampler_count, samplers);
4824 wined3d_mutex_lock();
4825 for (i = 0; i < sampler_count; ++i)
4827 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4829 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4830 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4832 wined3d_mutex_unlock();
4835 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4837 struct d3d_device *device = impl_from_ID3D10Device(iface);
4838 struct d3d_query *query;
4840 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4842 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4843 wined3d_mutex_lock();
4844 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4845 query ? query->wined3d_query : NULL, value);
4846 wined3d_mutex_unlock();
4849 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4850 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4852 struct d3d_device *device = impl_from_ID3D10Device(iface);
4853 unsigned int i;
4855 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4856 iface, start_slot, view_count, views);
4858 wined3d_mutex_lock();
4859 for (i = 0; i < view_count; ++i)
4861 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4863 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4864 WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i, view ? view->wined3d_view : NULL);
4866 wined3d_mutex_unlock();
4869 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4870 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4872 struct d3d_device *device = impl_from_ID3D10Device(iface);
4873 unsigned int i;
4875 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4876 iface, start_slot, sampler_count, samplers);
4878 wined3d_mutex_lock();
4879 for (i = 0; i < sampler_count; ++i)
4881 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4883 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
4884 start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4886 wined3d_mutex_unlock();
4889 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4890 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4891 ID3D10DepthStencilView *depth_stencil_view)
4893 struct d3d_device *device = impl_from_ID3D10Device(iface);
4894 struct d3d_depthstencil_view *dsv;
4895 unsigned int i;
4897 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4898 iface, render_target_view_count, render_target_views, depth_stencil_view);
4900 wined3d_mutex_lock();
4901 for (i = 0; i < render_target_view_count; ++i)
4903 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4905 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
4906 rtv ? rtv->wined3d_view : NULL, FALSE);
4908 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4910 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
4913 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4914 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4915 dsv ? dsv->wined3d_view : NULL);
4916 wined3d_mutex_unlock();
4919 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4920 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4922 struct d3d_device *device = impl_from_ID3D10Device(iface);
4923 struct d3d_blend_state *blend_state_object;
4925 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4926 iface, blend_state, debug_float4(blend_factor), sample_mask);
4928 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4929 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4930 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4933 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4934 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4936 struct d3d_device *device = impl_from_ID3D10Device(iface);
4937 struct d3d_depthstencil_state *ds_state_object;
4939 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4940 iface, depth_stencil_state, stencil_ref);
4942 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4943 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4944 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4947 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4948 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4950 struct d3d_device *device = impl_from_ID3D10Device(iface);
4951 unsigned int count, i;
4953 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4955 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4956 wined3d_mutex_lock();
4957 for (i = 0; i < count; ++i)
4959 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4961 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i,
4962 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4965 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4967 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i, NULL, 0);
4969 wined3d_mutex_unlock();
4972 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4974 FIXME("iface %p stub!\n", iface);
4977 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4979 struct d3d_device *device = impl_from_ID3D10Device(iface);
4980 struct d3d_rasterizer_state *rasterizer_state_object;
4982 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4984 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4985 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
4986 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4989 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4990 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4992 struct d3d_device *device = impl_from_ID3D10Device(iface);
4993 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
4994 unsigned int i;
4996 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4998 if (viewport_count > ARRAY_SIZE(wined3d_vp))
4999 return;
5001 for (i = 0; i < viewport_count; ++i)
5003 wined3d_vp[i].x = viewports[i].TopLeftX;
5004 wined3d_vp[i].y = viewports[i].TopLeftY;
5005 wined3d_vp[i].width = viewports[i].Width;
5006 wined3d_vp[i].height = viewports[i].Height;
5007 wined3d_vp[i].min_z = viewports[i].MinDepth;
5008 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5011 wined3d_mutex_lock();
5012 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5013 wined3d_mutex_unlock();
5016 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
5017 UINT rect_count, const D3D10_RECT *rects)
5019 struct d3d_device *device = impl_from_ID3D10Device(iface);
5021 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5023 if (rect_count > WINED3D_MAX_VIEWPORTS)
5024 return;
5026 wined3d_mutex_lock();
5027 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5028 wined3d_mutex_unlock();
5031 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5032 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5033 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5035 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5036 struct d3d_device *device = impl_from_ID3D10Device(iface);
5037 struct wined3d_box wined3d_src_box;
5039 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5040 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5041 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5042 src_resource, src_subresource_idx, src_box);
5044 if (!dst_resource || !src_resource)
5045 return;
5047 if (src_box)
5048 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5049 src_box->right, src_box->bottom, src_box->front, src_box->back);
5051 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5052 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5053 wined3d_mutex_lock();
5054 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5055 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5056 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5057 wined3d_mutex_unlock();
5060 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5061 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5063 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5064 struct d3d_device *device = impl_from_ID3D10Device(iface);
5066 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5068 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5069 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5070 wined3d_mutex_lock();
5071 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5072 wined3d_dst_resource, wined3d_src_resource);
5073 wined3d_mutex_unlock();
5076 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5077 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5078 const void *data, UINT row_pitch, UINT depth_pitch)
5080 struct d3d_device *device = impl_from_ID3D10Device(iface);
5081 ID3D11Resource *d3d11_resource;
5083 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5084 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5086 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5087 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5088 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5089 ID3D11Resource_Release(d3d11_resource);
5092 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5093 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5095 struct d3d_device *device = impl_from_ID3D10Device(iface);
5096 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5097 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5098 HRESULT hr;
5100 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5101 iface, render_target_view, debug_float4(color_rgba));
5103 if (!view)
5104 return;
5106 wined3d_mutex_lock();
5107 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5108 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5109 ERR("Failed to clear view, hr %#x.\n", hr);
5110 wined3d_mutex_unlock();
5113 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5114 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5116 struct d3d_device *device = impl_from_ID3D10Device(iface);
5117 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5118 DWORD wined3d_flags;
5119 HRESULT hr;
5121 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5122 iface, depth_stencil_view, flags, depth, stencil);
5124 if (!view)
5125 return;
5127 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5129 wined3d_mutex_lock();
5130 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5131 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5132 ERR("Failed to clear view, hr %#x.\n", hr);
5133 wined3d_mutex_unlock();
5136 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5137 ID3D10ShaderResourceView *view)
5139 struct d3d_device *device = impl_from_ID3D10Device(iface);
5140 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5142 TRACE("iface %p, view %p.\n", iface, view);
5144 wined3d_mutex_lock();
5145 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5146 wined3d_mutex_unlock();
5149 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5150 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5151 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5153 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5154 struct d3d_device *device = impl_from_ID3D10Device(iface);
5155 enum wined3d_format_id wined3d_format;
5157 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5158 "src_resource %p, src_subresource_idx %u, format %s.\n",
5159 iface, dst_resource, dst_subresource_idx,
5160 src_resource, src_subresource_idx, debug_dxgi_format(format));
5162 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5163 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5164 wined3d_format = wined3dformat_from_dxgi_format(format);
5165 wined3d_mutex_lock();
5166 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5167 wined3d_dst_resource, dst_subresource_idx,
5168 wined3d_src_resource, src_subresource_idx, wined3d_format);
5169 wined3d_mutex_unlock();
5172 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5173 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5175 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5176 iface, start_slot, buffer_count, buffers);
5178 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5179 buffers);
5182 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5183 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5185 struct d3d_device *device = impl_from_ID3D10Device(iface);
5186 unsigned int i;
5188 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5189 iface, start_slot, view_count, views);
5191 wined3d_mutex_lock();
5192 for (i = 0; i < view_count; ++i)
5194 struct wined3d_shader_resource_view *wined3d_view;
5195 struct d3d_shader_resource_view *view_impl;
5197 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5198 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5200 views[i] = NULL;
5201 continue;
5204 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5205 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5206 ID3D10ShaderResourceView_AddRef(views[i]);
5208 wined3d_mutex_unlock();
5211 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5213 struct d3d_device *device = impl_from_ID3D10Device(iface);
5214 struct d3d_pixel_shader *shader_impl;
5215 struct wined3d_shader *wined3d_shader;
5217 TRACE("iface %p, shader %p.\n", iface, shader);
5219 wined3d_mutex_lock();
5220 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5221 WINED3D_SHADER_TYPE_PIXEL)))
5223 wined3d_mutex_unlock();
5224 *shader = NULL;
5225 return;
5228 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5229 wined3d_mutex_unlock();
5230 *shader = &shader_impl->ID3D10PixelShader_iface;
5231 ID3D10PixelShader_AddRef(*shader);
5234 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5235 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5237 struct d3d_device *device = impl_from_ID3D10Device(iface);
5238 unsigned int i;
5240 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5241 iface, start_slot, sampler_count, samplers);
5243 wined3d_mutex_lock();
5244 for (i = 0; i < sampler_count; ++i)
5246 struct d3d_sampler_state *sampler_impl;
5247 struct wined3d_sampler *wined3d_sampler;
5249 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5250 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5252 samplers[i] = NULL;
5253 continue;
5256 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5257 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5258 ID3D10SamplerState_AddRef(samplers[i]);
5260 wined3d_mutex_unlock();
5263 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5265 struct d3d_device *device = impl_from_ID3D10Device(iface);
5266 struct d3d_vertex_shader *shader_impl;
5267 struct wined3d_shader *wined3d_shader;
5269 TRACE("iface %p, shader %p.\n", iface, shader);
5271 wined3d_mutex_lock();
5272 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5273 WINED3D_SHADER_TYPE_VERTEX)))
5275 wined3d_mutex_unlock();
5276 *shader = NULL;
5277 return;
5280 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5281 wined3d_mutex_unlock();
5282 *shader = &shader_impl->ID3D10VertexShader_iface;
5283 ID3D10VertexShader_AddRef(*shader);
5286 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5287 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5289 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5290 iface, start_slot, buffer_count, buffers);
5292 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5293 buffers);
5296 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5298 struct d3d_device *device = impl_from_ID3D10Device(iface);
5299 struct wined3d_vertex_declaration *wined3d_declaration;
5300 struct d3d_input_layout *input_layout_impl;
5302 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5304 wined3d_mutex_lock();
5305 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5306 device->immediate_context.wined3d_context)))
5308 wined3d_mutex_unlock();
5309 *input_layout = NULL;
5310 return;
5313 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5314 wined3d_mutex_unlock();
5315 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5316 ID3D10InputLayout_AddRef(*input_layout);
5319 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5320 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5322 struct d3d_device *device = impl_from_ID3D10Device(iface);
5323 unsigned int i;
5325 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5326 iface, start_slot, buffer_count, buffers, strides, offsets);
5328 wined3d_mutex_lock();
5329 for (i = 0; i < buffer_count; ++i)
5331 struct wined3d_buffer *wined3d_buffer = NULL;
5332 struct d3d_buffer *buffer_impl;
5334 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5335 &wined3d_buffer, &offsets[i], &strides[i])))
5336 ERR("Failed to get vertex buffer.\n");
5338 if (!wined3d_buffer)
5340 buffers[i] = NULL;
5341 continue;
5344 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5345 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5346 ID3D10Buffer_AddRef(buffers[i]);
5348 wined3d_mutex_unlock();
5351 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5352 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5354 struct d3d_device *device = impl_from_ID3D10Device(iface);
5355 enum wined3d_format_id wined3d_format;
5356 struct wined3d_buffer *wined3d_buffer;
5357 struct d3d_buffer *buffer_impl;
5359 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5361 wined3d_mutex_lock();
5362 wined3d_buffer = wined3d_device_context_get_index_buffer(
5363 device->immediate_context.wined3d_context, &wined3d_format, offset);
5364 *format = dxgi_format_from_wined3dformat(wined3d_format);
5365 if (!wined3d_buffer)
5367 wined3d_mutex_unlock();
5368 *buffer = NULL;
5369 return;
5372 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5373 wined3d_mutex_unlock();
5374 *buffer = &buffer_impl->ID3D10Buffer_iface;
5375 ID3D10Buffer_AddRef(*buffer);
5378 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5379 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5381 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5382 iface, start_slot, buffer_count, buffers);
5384 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5385 buffers);
5388 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5390 struct d3d_device *device = impl_from_ID3D10Device(iface);
5391 struct d3d_geometry_shader *shader_impl;
5392 struct wined3d_shader *wined3d_shader;
5394 TRACE("iface %p, shader %p.\n", iface, shader);
5396 wined3d_mutex_lock();
5397 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5398 WINED3D_SHADER_TYPE_GEOMETRY)))
5400 wined3d_mutex_unlock();
5401 *shader = NULL;
5402 return;
5405 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5406 wined3d_mutex_unlock();
5407 *shader = &shader_impl->ID3D10GeometryShader_iface;
5408 ID3D10GeometryShader_AddRef(*shader);
5411 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5412 D3D10_PRIMITIVE_TOPOLOGY *topology)
5414 struct d3d_device *device = impl_from_ID3D10Device(iface);
5416 TRACE("iface %p, topology %p.\n", iface, topology);
5418 wined3d_mutex_lock();
5419 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5420 (enum wined3d_primitive_type *)topology, NULL);
5421 wined3d_mutex_unlock();
5424 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5425 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5427 struct d3d_device *device = impl_from_ID3D10Device(iface);
5428 unsigned int i;
5430 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5431 iface, start_slot, view_count, views);
5433 wined3d_mutex_lock();
5434 for (i = 0; i < view_count; ++i)
5436 struct wined3d_shader_resource_view *wined3d_view;
5437 struct d3d_shader_resource_view *view_impl;
5439 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5440 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5442 views[i] = NULL;
5443 continue;
5446 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5447 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5448 ID3D10ShaderResourceView_AddRef(views[i]);
5450 wined3d_mutex_unlock();
5453 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5454 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5456 struct d3d_device *device = impl_from_ID3D10Device(iface);
5457 unsigned int i;
5459 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5460 iface, start_slot, sampler_count, samplers);
5462 wined3d_mutex_lock();
5463 for (i = 0; i < sampler_count; ++i)
5465 struct d3d_sampler_state *sampler_impl;
5466 struct wined3d_sampler *wined3d_sampler;
5468 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5469 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5471 samplers[i] = NULL;
5472 continue;
5475 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5476 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5477 ID3D10SamplerState_AddRef(samplers[i]);
5479 wined3d_mutex_unlock();
5482 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5483 ID3D10Predicate **predicate, BOOL *value)
5485 struct d3d_device *device = impl_from_ID3D10Device(iface);
5486 struct wined3d_query *wined3d_predicate;
5487 struct d3d_query *predicate_impl;
5489 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5491 wined3d_mutex_lock();
5492 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5494 wined3d_mutex_unlock();
5495 *predicate = NULL;
5496 return;
5499 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5500 wined3d_mutex_unlock();
5501 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5502 ID3D10Predicate_AddRef(*predicate);
5505 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5506 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5508 struct d3d_device *device = impl_from_ID3D10Device(iface);
5509 unsigned int i;
5511 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5512 iface, start_slot, view_count, views);
5514 wined3d_mutex_lock();
5515 for (i = 0; i < view_count; ++i)
5517 struct wined3d_shader_resource_view *wined3d_view;
5518 struct d3d_shader_resource_view *view_impl;
5520 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5521 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5523 views[i] = NULL;
5524 continue;
5527 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5528 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5529 ID3D10ShaderResourceView_AddRef(views[i]);
5531 wined3d_mutex_unlock();
5534 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5535 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5537 struct d3d_device *device = impl_from_ID3D10Device(iface);
5538 unsigned int i;
5540 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5541 iface, start_slot, sampler_count, samplers);
5543 wined3d_mutex_lock();
5544 for (i = 0; i < sampler_count; ++i)
5546 struct d3d_sampler_state *sampler_impl;
5547 struct wined3d_sampler *wined3d_sampler;
5549 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5550 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5552 samplers[i] = NULL;
5553 continue;
5556 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5557 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5558 ID3D10SamplerState_AddRef(samplers[i]);
5560 wined3d_mutex_unlock();
5563 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5564 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5566 struct d3d_device *device = impl_from_ID3D10Device(iface);
5567 struct wined3d_rendertarget_view *wined3d_view;
5569 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5570 iface, view_count, render_target_views, depth_stencil_view);
5572 wined3d_mutex_lock();
5573 if (render_target_views)
5575 struct d3d_rendertarget_view *view_impl;
5576 unsigned int i;
5578 for (i = 0; i < view_count; ++i)
5580 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5581 device->immediate_context.wined3d_context, i))
5582 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5584 render_target_views[i] = NULL;
5585 continue;
5588 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5589 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5593 if (depth_stencil_view)
5595 struct d3d_depthstencil_view *view_impl;
5597 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5598 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5600 *depth_stencil_view = NULL;
5602 else
5604 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5605 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5608 wined3d_mutex_unlock();
5611 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5612 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5614 struct d3d_device *device = impl_from_ID3D10Device(iface);
5615 ID3D11BlendState *d3d11_blend_state;
5617 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5618 iface, blend_state, blend_factor, sample_mask);
5620 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5621 &d3d11_blend_state, blend_factor, sample_mask);
5623 if (d3d11_blend_state)
5624 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5625 else
5626 *blend_state = NULL;
5629 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5630 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5632 struct d3d_device *device = impl_from_ID3D10Device(iface);
5633 ID3D11DepthStencilState *d3d11_iface;
5635 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5636 iface, depth_stencil_state, stencil_ref);
5638 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5639 &d3d11_iface, stencil_ref);
5641 if (d3d11_iface)
5642 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5643 else
5644 *depth_stencil_state = NULL;
5647 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5648 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5650 struct d3d_device *device = impl_from_ID3D10Device(iface);
5651 unsigned int i;
5653 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5654 iface, buffer_count, buffers, offsets);
5656 wined3d_mutex_lock();
5657 for (i = 0; i < buffer_count; ++i)
5659 struct wined3d_buffer *wined3d_buffer;
5660 struct d3d_buffer *buffer_impl;
5662 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5663 device->immediate_context.wined3d_context, i, &offsets[i])))
5665 buffers[i] = NULL;
5666 continue;
5669 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5670 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5671 ID3D10Buffer_AddRef(buffers[i]);
5673 wined3d_mutex_unlock();
5676 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5678 struct d3d_device *device = impl_from_ID3D10Device(iface);
5679 struct d3d_rasterizer_state *rasterizer_state_impl;
5680 struct wined3d_rasterizer_state *wined3d_state;
5682 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5684 wined3d_mutex_lock();
5685 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5687 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5688 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5690 else
5692 *rasterizer_state = NULL;
5694 wined3d_mutex_unlock();
5697 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5698 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5700 struct d3d_device *device = impl_from_ID3D10Device(iface);
5701 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5702 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5704 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5706 if (!viewport_count)
5707 return;
5709 wined3d_mutex_lock();
5710 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5711 &actual_count, viewports ? wined3d_vp : NULL);
5712 wined3d_mutex_unlock();
5714 if (!viewports)
5716 *viewport_count = actual_count;
5717 return;
5720 if (*viewport_count > actual_count)
5721 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5723 *viewport_count = min(actual_count, *viewport_count);
5724 for (i = 0; i < *viewport_count; ++i)
5726 viewports[i].TopLeftX = wined3d_vp[i].x;
5727 viewports[i].TopLeftY = wined3d_vp[i].y;
5728 viewports[i].Width = wined3d_vp[i].width;
5729 viewports[i].Height = wined3d_vp[i].height;
5730 viewports[i].MinDepth = wined3d_vp[i].min_z;
5731 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5735 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5737 struct d3d_device *device = impl_from_ID3D10Device(iface);
5738 unsigned int actual_count;
5740 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5742 if (!rect_count)
5743 return;
5745 actual_count = *rect_count;
5747 wined3d_mutex_lock();
5748 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5749 wined3d_mutex_unlock();
5751 if (!rects)
5753 *rect_count = actual_count;
5754 return;
5757 if (*rect_count > actual_count)
5758 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5761 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5763 TRACE("iface %p.\n", iface);
5765 /* In the current implementation the device is never removed, so we can
5766 * just return S_OK here. */
5768 return S_OK;
5771 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5773 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5775 return E_NOTIMPL;
5778 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5780 FIXME("iface %p stub!\n", iface);
5782 return 0;
5785 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5786 REFGUID guid, UINT *data_size, void *data)
5788 struct d3d_device *device = impl_from_ID3D10Device(iface);
5790 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5792 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5795 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5796 REFGUID guid, UINT data_size, const void *data)
5798 struct d3d_device *device = impl_from_ID3D10Device(iface);
5800 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5802 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5805 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5806 REFGUID guid, const IUnknown *data)
5808 struct d3d_device *device = impl_from_ID3D10Device(iface);
5810 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5812 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5815 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5817 struct d3d_device *device = impl_from_ID3D10Device(iface);
5819 TRACE("iface %p.\n", iface);
5821 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5824 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5826 struct d3d_device *device = impl_from_ID3D10Device(iface);
5828 TRACE("iface %p.\n", iface);
5830 wined3d_mutex_lock();
5831 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5832 wined3d_mutex_unlock();
5835 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5836 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5838 struct d3d_device *device = impl_from_ID3D10Device(iface);
5839 D3D11_BUFFER_DESC d3d11_desc;
5840 struct d3d_buffer *object;
5841 HRESULT hr;
5843 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5845 d3d11_desc.ByteWidth = desc->ByteWidth;
5846 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5847 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5848 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5849 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5850 d3d11_desc.StructureByteStride = 0;
5852 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5853 return hr;
5855 *buffer = &object->ID3D10Buffer_iface;
5857 return S_OK;
5860 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5861 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5863 struct d3d_device *device = impl_from_ID3D10Device(iface);
5864 D3D11_TEXTURE1D_DESC d3d11_desc;
5865 struct d3d_texture1d *object;
5866 HRESULT hr;
5868 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5870 d3d11_desc.Width = desc->Width;
5871 d3d11_desc.MipLevels = desc->MipLevels;
5872 d3d11_desc.ArraySize = desc->ArraySize;
5873 d3d11_desc.Format = desc->Format;
5874 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5875 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5876 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5877 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5879 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5880 return hr;
5882 *texture = &object->ID3D10Texture1D_iface;
5884 return S_OK;
5887 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5888 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5889 ID3D10Texture2D **texture)
5891 struct d3d_device *device = impl_from_ID3D10Device(iface);
5892 D3D11_TEXTURE2D_DESC d3d11_desc;
5893 struct d3d_texture2d *object;
5894 HRESULT hr;
5896 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5898 d3d11_desc.Width = desc->Width;
5899 d3d11_desc.Height = desc->Height;
5900 d3d11_desc.MipLevels = desc->MipLevels;
5901 d3d11_desc.ArraySize = desc->ArraySize;
5902 d3d11_desc.Format = desc->Format;
5903 d3d11_desc.SampleDesc = desc->SampleDesc;
5904 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5905 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5906 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5907 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5909 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5910 return hr;
5912 *texture = &object->ID3D10Texture2D_iface;
5914 return S_OK;
5917 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5918 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5919 ID3D10Texture3D **texture)
5921 struct d3d_device *device = impl_from_ID3D10Device(iface);
5922 D3D11_TEXTURE3D_DESC d3d11_desc;
5923 struct d3d_texture3d *object;
5924 HRESULT hr;
5926 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5928 d3d11_desc.Width = desc->Width;
5929 d3d11_desc.Height = desc->Height;
5930 d3d11_desc.Depth = desc->Depth;
5931 d3d11_desc.MipLevels = desc->MipLevels;
5932 d3d11_desc.Format = desc->Format;
5933 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5934 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5935 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5936 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5938 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5939 return hr;
5941 *texture = &object->ID3D10Texture3D_iface;
5943 return S_OK;
5946 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5947 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5949 struct d3d_device *device = impl_from_ID3D10Device(iface);
5950 struct d3d_shader_resource_view *object;
5951 ID3D11Resource *d3d11_resource;
5952 HRESULT hr;
5954 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5956 if (!resource)
5957 return E_INVALIDARG;
5959 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5961 ERR("Resource does not implement ID3D11Resource.\n");
5962 return E_FAIL;
5965 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5966 &object);
5967 ID3D11Resource_Release(d3d11_resource);
5968 if (FAILED(hr))
5969 return hr;
5971 *view = &object->ID3D10ShaderResourceView1_iface;
5973 return S_OK;
5976 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5977 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5979 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5981 return d3d10_device_CreateShaderResourceView1(iface, resource,
5982 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5985 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5986 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5988 struct d3d_device *device = impl_from_ID3D10Device(iface);
5989 struct d3d_rendertarget_view *object;
5990 ID3D11Resource *d3d11_resource;
5991 HRESULT hr;
5993 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5995 if (!resource)
5996 return E_INVALIDARG;
5998 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6000 ERR("Resource does not implement ID3D11Resource.\n");
6001 return E_FAIL;
6004 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6005 ID3D11Resource_Release(d3d11_resource);
6006 if (FAILED(hr))
6007 return hr;
6009 *view = &object->ID3D10RenderTargetView_iface;
6011 return S_OK;
6014 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6016 return (D3D11_DSV_DIMENSION)dim;
6019 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6020 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6022 struct d3d_device *device = impl_from_ID3D10Device(iface);
6023 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6024 struct d3d_depthstencil_view *object;
6025 ID3D11Resource *d3d11_resource;
6026 HRESULT hr;
6028 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6030 if (desc)
6032 d3d11_desc.Format = desc->Format;
6033 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6034 d3d11_desc.Flags = 0;
6035 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6038 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6040 ERR("Resource does not implement ID3D11Resource.\n");
6041 return E_FAIL;
6044 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6045 ID3D11Resource_Release(d3d11_resource);
6046 if (FAILED(hr))
6047 return hr;
6049 *view = &object->ID3D10DepthStencilView_iface;
6051 return S_OK;
6054 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6055 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6056 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6057 ID3D10InputLayout **input_layout)
6059 struct d3d_device *device = impl_from_ID3D10Device(iface);
6060 struct d3d_input_layout *object;
6061 HRESULT hr;
6063 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6064 "shader_byte_code_length %lu, input_layout %p\n",
6065 iface, element_descs, element_count, shader_byte_code,
6066 shader_byte_code_length, input_layout);
6068 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6069 shader_byte_code, shader_byte_code_length, &object)))
6070 return hr;
6072 *input_layout = &object->ID3D10InputLayout_iface;
6074 return S_OK;
6077 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6078 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6080 struct d3d_device *device = impl_from_ID3D10Device(iface);
6081 struct d3d_vertex_shader *object;
6082 HRESULT hr;
6084 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6085 iface, byte_code, byte_code_length, shader);
6087 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6088 return hr;
6090 *shader = &object->ID3D10VertexShader_iface;
6092 return S_OK;
6095 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6096 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6098 struct d3d_device *device = impl_from_ID3D10Device(iface);
6099 struct d3d_geometry_shader *object;
6100 HRESULT hr;
6102 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6103 iface, byte_code, byte_code_length, shader);
6105 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6106 NULL, 0, NULL, 0, 0, &object)))
6107 return hr;
6109 *shader = &object->ID3D10GeometryShader_iface;
6111 return S_OK;
6114 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6115 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6116 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6118 struct d3d_device *device = impl_from_ID3D10Device(iface);
6119 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6120 struct d3d_geometry_shader *object;
6121 unsigned int i, stride_count = 1;
6122 HRESULT hr;
6124 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
6125 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6126 iface, byte_code, byte_code_length, output_stream_decls,
6127 output_stream_decl_count, output_stream_stride, shader);
6129 if (!output_stream_decl_count && output_stream_stride)
6131 WARN("Stride must be 0 when declaration entry count is 0.\n");
6132 *shader = NULL;
6133 return E_INVALIDARG;
6136 if (output_stream_decl_count
6137 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6139 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6140 *shader = NULL;
6141 return E_OUTOFMEMORY;
6144 for (i = 0; i < output_stream_decl_count; ++i)
6146 so_entries[i].Stream = 0;
6147 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6148 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6149 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6150 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6151 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6153 if (output_stream_decls[i].OutputSlot)
6155 stride_count = 0;
6156 if (output_stream_stride)
6158 WARN("Stride must be 0 when multiple output slots are used.\n");
6159 heap_free(so_entries);
6160 *shader = NULL;
6161 return E_INVALIDARG;
6166 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6167 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6168 heap_free(so_entries);
6169 if (FAILED(hr))
6171 *shader = NULL;
6172 return hr;
6175 *shader = &object->ID3D10GeometryShader_iface;
6177 return hr;
6180 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6181 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6183 struct d3d_device *device = impl_from_ID3D10Device(iface);
6184 struct d3d_pixel_shader *object;
6185 HRESULT hr;
6187 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6188 iface, byte_code, byte_code_length, shader);
6190 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6191 return hr;
6193 *shader = &object->ID3D10PixelShader_iface;
6195 return S_OK;
6198 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6199 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6201 struct d3d_device *device = impl_from_ID3D10Device(iface);
6202 struct d3d_blend_state *object;
6203 HRESULT hr;
6205 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6207 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6208 return hr;
6210 *blend_state = &object->ID3D10BlendState1_iface;
6212 return S_OK;
6215 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6216 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6218 D3D10_BLEND_DESC1 d3d10_1_desc;
6219 unsigned int i;
6221 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6223 if (!desc)
6224 return E_INVALIDARG;
6226 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6227 d3d10_1_desc.IndependentBlendEnable = FALSE;
6228 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6230 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6231 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6232 d3d10_1_desc.IndependentBlendEnable = TRUE;
6235 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6237 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6238 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6239 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6240 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6241 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6242 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6243 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6244 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6247 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6250 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6251 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6253 struct d3d_device *device = impl_from_ID3D10Device(iface);
6254 struct d3d_depthstencil_state *object;
6255 HRESULT hr;
6257 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6259 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6260 return hr;
6262 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6264 return S_OK;
6267 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6268 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6270 struct d3d_device *device = impl_from_ID3D10Device(iface);
6271 struct d3d_rasterizer_state *object;
6272 HRESULT hr;
6274 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6276 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6277 return hr;
6279 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6281 return S_OK;
6284 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6285 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6287 struct d3d_device *device = impl_from_ID3D10Device(iface);
6288 struct d3d_sampler_state *object;
6289 HRESULT hr;
6291 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6293 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6294 return hr;
6296 *sampler_state = &object->ID3D10SamplerState_iface;
6298 return S_OK;
6301 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6302 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6304 struct d3d_device *device = impl_from_ID3D10Device(iface);
6305 struct d3d_query *object;
6306 HRESULT hr;
6308 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6310 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6311 return hr;
6313 if (query)
6315 *query = &object->ID3D10Query_iface;
6316 return S_OK;
6319 ID3D10Query_Release(&object->ID3D10Query_iface);
6320 return S_FALSE;
6323 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6324 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6326 struct d3d_device *device = impl_from_ID3D10Device(iface);
6327 struct d3d_query *object;
6328 HRESULT hr;
6330 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6332 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6333 return hr;
6335 if (predicate)
6337 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6338 return S_OK;
6341 ID3D10Query_Release(&object->ID3D10Query_iface);
6342 return S_FALSE;
6345 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6346 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6348 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6350 return E_NOTIMPL;
6353 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6354 DXGI_FORMAT format, UINT *format_support)
6356 struct d3d_device *device = impl_from_ID3D10Device(iface);
6358 TRACE("iface %p, format %s, format_support %p.\n",
6359 iface, debug_dxgi_format(format), format_support);
6361 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6364 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6365 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6367 struct d3d_device *device = impl_from_ID3D10Device(iface);
6369 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6370 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6372 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6373 sample_count, quality_level_count);
6376 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6378 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6381 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6382 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6383 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6385 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6386 "units %p, units_length %p, description %p, description_length %p stub!\n",
6387 iface, desc, type, active_counters, name, name_length,
6388 units, units_length, description, description_length);
6390 return E_NOTIMPL;
6393 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6395 FIXME("iface %p stub!\n", iface);
6397 return 0;
6400 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6401 HANDLE resource_handle, REFIID guid, void **resource)
6403 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6404 iface, resource_handle, debugstr_guid(guid), resource);
6406 return E_NOTIMPL;
6409 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6411 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6414 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6416 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6419 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6421 return (D3D10_FEATURE_LEVEL1)level;
6424 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6426 struct d3d_device *device = impl_from_ID3D10Device(iface);
6428 TRACE("iface %p.\n", iface);
6430 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6433 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6435 /* IUnknown methods */
6436 d3d10_device_QueryInterface,
6437 d3d10_device_AddRef,
6438 d3d10_device_Release,
6439 /* ID3D10Device methods */
6440 d3d10_device_VSSetConstantBuffers,
6441 d3d10_device_PSSetShaderResources,
6442 d3d10_device_PSSetShader,
6443 d3d10_device_PSSetSamplers,
6444 d3d10_device_VSSetShader,
6445 d3d10_device_DrawIndexed,
6446 d3d10_device_Draw,
6447 d3d10_device_PSSetConstantBuffers,
6448 d3d10_device_IASetInputLayout,
6449 d3d10_device_IASetVertexBuffers,
6450 d3d10_device_IASetIndexBuffer,
6451 d3d10_device_DrawIndexedInstanced,
6452 d3d10_device_DrawInstanced,
6453 d3d10_device_GSSetConstantBuffers,
6454 d3d10_device_GSSetShader,
6455 d3d10_device_IASetPrimitiveTopology,
6456 d3d10_device_VSSetShaderResources,
6457 d3d10_device_VSSetSamplers,
6458 d3d10_device_SetPredication,
6459 d3d10_device_GSSetShaderResources,
6460 d3d10_device_GSSetSamplers,
6461 d3d10_device_OMSetRenderTargets,
6462 d3d10_device_OMSetBlendState,
6463 d3d10_device_OMSetDepthStencilState,
6464 d3d10_device_SOSetTargets,
6465 d3d10_device_DrawAuto,
6466 d3d10_device_RSSetState,
6467 d3d10_device_RSSetViewports,
6468 d3d10_device_RSSetScissorRects,
6469 d3d10_device_CopySubresourceRegion,
6470 d3d10_device_CopyResource,
6471 d3d10_device_UpdateSubresource,
6472 d3d10_device_ClearRenderTargetView,
6473 d3d10_device_ClearDepthStencilView,
6474 d3d10_device_GenerateMips,
6475 d3d10_device_ResolveSubresource,
6476 d3d10_device_VSGetConstantBuffers,
6477 d3d10_device_PSGetShaderResources,
6478 d3d10_device_PSGetShader,
6479 d3d10_device_PSGetSamplers,
6480 d3d10_device_VSGetShader,
6481 d3d10_device_PSGetConstantBuffers,
6482 d3d10_device_IAGetInputLayout,
6483 d3d10_device_IAGetVertexBuffers,
6484 d3d10_device_IAGetIndexBuffer,
6485 d3d10_device_GSGetConstantBuffers,
6486 d3d10_device_GSGetShader,
6487 d3d10_device_IAGetPrimitiveTopology,
6488 d3d10_device_VSGetShaderResources,
6489 d3d10_device_VSGetSamplers,
6490 d3d10_device_GetPredication,
6491 d3d10_device_GSGetShaderResources,
6492 d3d10_device_GSGetSamplers,
6493 d3d10_device_OMGetRenderTargets,
6494 d3d10_device_OMGetBlendState,
6495 d3d10_device_OMGetDepthStencilState,
6496 d3d10_device_SOGetTargets,
6497 d3d10_device_RSGetState,
6498 d3d10_device_RSGetViewports,
6499 d3d10_device_RSGetScissorRects,
6500 d3d10_device_GetDeviceRemovedReason,
6501 d3d10_device_SetExceptionMode,
6502 d3d10_device_GetExceptionMode,
6503 d3d10_device_GetPrivateData,
6504 d3d10_device_SetPrivateData,
6505 d3d10_device_SetPrivateDataInterface,
6506 d3d10_device_ClearState,
6507 d3d10_device_Flush,
6508 d3d10_device_CreateBuffer,
6509 d3d10_device_CreateTexture1D,
6510 d3d10_device_CreateTexture2D,
6511 d3d10_device_CreateTexture3D,
6512 d3d10_device_CreateShaderResourceView,
6513 d3d10_device_CreateRenderTargetView,
6514 d3d10_device_CreateDepthStencilView,
6515 d3d10_device_CreateInputLayout,
6516 d3d10_device_CreateVertexShader,
6517 d3d10_device_CreateGeometryShader,
6518 d3d10_device_CreateGeometryShaderWithStreamOutput,
6519 d3d10_device_CreatePixelShader,
6520 d3d10_device_CreateBlendState,
6521 d3d10_device_CreateDepthStencilState,
6522 d3d10_device_CreateRasterizerState,
6523 d3d10_device_CreateSamplerState,
6524 d3d10_device_CreateQuery,
6525 d3d10_device_CreatePredicate,
6526 d3d10_device_CreateCounter,
6527 d3d10_device_CheckFormatSupport,
6528 d3d10_device_CheckMultisampleQualityLevels,
6529 d3d10_device_CheckCounterInfo,
6530 d3d10_device_CheckCounter,
6531 d3d10_device_GetCreationFlags,
6532 d3d10_device_OpenSharedResource,
6533 d3d10_device_SetTextFilterSize,
6534 d3d10_device_GetTextFilterSize,
6535 d3d10_device_CreateShaderResourceView1,
6536 d3d10_device_CreateBlendState1,
6537 d3d10_device_GetFeatureLevel,
6540 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6542 /* IUnknown methods */
6543 d3d_device_inner_QueryInterface,
6544 d3d_device_inner_AddRef,
6545 d3d_device_inner_Release,
6548 /* ID3D10Multithread methods */
6550 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6552 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6555 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6557 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6559 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6561 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6564 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6566 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6568 TRACE("iface %p.\n", iface);
6570 return IUnknown_AddRef(device->outer_unk);
6573 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6575 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6577 TRACE("iface %p.\n", iface);
6579 return IUnknown_Release(device->outer_unk);
6582 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6584 TRACE("iface %p.\n", iface);
6586 wined3d_mutex_lock();
6589 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6591 TRACE("iface %p.\n", iface);
6593 wined3d_mutex_unlock();
6596 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6598 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6600 return TRUE;
6603 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6605 FIXME("iface %p stub!\n", iface);
6607 return TRUE;
6610 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6612 d3d10_multithread_QueryInterface,
6613 d3d10_multithread_AddRef,
6614 d3d10_multithread_Release,
6615 d3d10_multithread_Enter,
6616 d3d10_multithread_Leave,
6617 d3d10_multithread_SetMultithreadProtected,
6618 d3d10_multithread_GetMultithreadProtected,
6621 /* IWineDXGIDeviceParent IUnknown methods */
6623 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6625 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6628 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6629 REFIID iid, void **out)
6631 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6632 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6635 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6637 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6638 return IUnknown_AddRef(device->outer_unk);
6641 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6643 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6644 return IUnknown_Release(device->outer_unk);
6647 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6648 IWineDXGIDeviceParent *iface)
6650 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6651 return &device->device_parent;
6654 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6656 /* IUnknown methods */
6657 dxgi_device_parent_QueryInterface,
6658 dxgi_device_parent_AddRef,
6659 dxgi_device_parent_Release,
6660 /* IWineDXGIDeviceParent methods */
6661 dxgi_device_parent_get_wined3d_device_parent,
6664 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6666 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6669 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6670 struct wined3d_device *wined3d_device)
6672 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6673 struct d3d_device_context_state *state;
6674 struct wined3d_state *wined3d_state;
6675 D3D_FEATURE_LEVEL feature_level;
6677 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6679 wined3d_device_incref(wined3d_device);
6680 device->wined3d_device = wined3d_device;
6681 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6683 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6684 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6686 if (!(state = heap_alloc_zero(sizeof(*state))))
6688 ERR("Failed to create the initial device context state.\n");
6689 return;
6692 d3d_device_context_state_init(state, device, feature_level,
6693 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6695 device->state = state;
6696 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6697 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6699 d3d_device_context_state_private_addref(state);
6700 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6703 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6705 TRACE("device_parent %p.\n", device_parent);
6708 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6710 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6713 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6714 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6715 void **parent, const struct wined3d_parent_ops **parent_ops)
6717 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6718 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6720 *parent = NULL;
6721 *parent_ops = &d3d_null_wined3d_parent_ops;
6723 return S_OK;
6726 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6727 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6728 struct wined3d_texture **wined3d_texture)
6730 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6731 struct d3d_texture2d *texture;
6732 ID3D11Texture2D *texture_iface;
6733 D3D11_TEXTURE2D_DESC desc;
6734 HRESULT hr;
6736 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6737 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6739 desc.Width = wined3d_desc->width;
6740 desc.Height = wined3d_desc->height;
6741 desc.MipLevels = 1;
6742 desc.ArraySize = 1;
6743 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6744 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6745 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6746 desc.Usage = D3D11_USAGE_DEFAULT;
6747 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6748 desc.CPUAccessFlags = 0;
6749 desc.MiscFlags = 0;
6751 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6753 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6754 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6757 if (texture_flags)
6758 FIXME("Unhandled flags %#x.\n", texture_flags);
6760 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6761 &desc, NULL, &texture_iface)))
6763 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6764 return hr;
6767 texture = impl_from_ID3D11Texture2D(texture_iface);
6769 *wined3d_texture = texture->wined3d_texture;
6770 wined3d_texture_incref(*wined3d_texture);
6771 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6773 return S_OK;
6776 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6778 device_parent_wined3d_device_created,
6779 device_parent_mode_changed,
6780 device_parent_activate,
6781 device_parent_texture_sub_resource_created,
6782 device_parent_create_swapchain_texture,
6785 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6787 const D3D11_SAMPLER_DESC *ka = key;
6788 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6790 return memcmp(ka, kb, sizeof(*ka));
6793 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6795 const D3D11_BLEND_DESC *ka = key;
6796 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6798 return memcmp(ka, kb, sizeof(*ka));
6801 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6803 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6804 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6805 const struct d3d_depthstencil_state, entry)->desc;
6807 return memcmp(ka, kb, sizeof(*ka));
6810 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6812 const D3D11_RASTERIZER_DESC *ka = key;
6813 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6815 return memcmp(ka, kb, sizeof(*ka));
6818 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6820 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6821 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6822 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6823 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6824 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6825 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6826 device->refcount = 1;
6827 /* COM aggregation always takes place */
6828 device->outer_unk = outer_unknown;
6829 device->d3d11_only = FALSE;
6830 device->state = NULL;
6832 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6833 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6835 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6836 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6837 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6838 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);