mf/samplegrabber: Handle paused state.
[wine.git] / dlls / d3d11 / device.c
blob7994da70591fb906fca1b221fb0eeedf6b0dbb8a
1 /*
2 * Copyright 2008-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
21 #define WINE_NO_NAMELESS_EXTENSION
22 #include "d3d11_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
26 static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
28 SIZE_T max_capacity, new_capacity;
29 void *new_elements;
31 if (count <= *capacity)
32 return TRUE;
34 max_capacity = ~(SIZE_T)0 / size;
35 if (count > max_capacity)
36 return FALSE;
38 new_capacity = max(1, *capacity);
39 while (new_capacity < count && new_capacity <= max_capacity / 2)
40 new_capacity *= 2;
41 if (new_capacity < count)
42 new_capacity = count;
44 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
45 return FALSE;
47 *elements = new_elements;
48 *capacity = new_capacity;
49 return TRUE;
52 static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
54 static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
56 d3d_null_wined3d_object_destroyed,
59 static inline BOOL d3d_device_is_d3d10_active(struct d3d_device *device)
61 return !device->state
62 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device)
63 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device1);
66 static D3D_FEATURE_LEVEL d3d_feature_level_from_wined3d(enum wined3d_feature_level level)
68 return (D3D_FEATURE_LEVEL)level;
71 /* ID3DDeviceContextState methods */
73 static inline struct d3d_device_context_state *impl_from_ID3DDeviceContextState(ID3DDeviceContextState *iface)
75 return CONTAINING_RECORD(iface, struct d3d_device_context_state, ID3DDeviceContextState_iface);
78 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface,
79 REFIID iid, void **out)
81 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
83 if (IsEqualGUID(iid, &IID_ID3DDeviceContextState)
84 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
85 || IsEqualGUID(iid, &IID_IUnknown))
87 ID3DDeviceContextState_AddRef(iface);
88 *out = iface;
89 return S_OK;
92 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
93 *out = NULL;
95 return E_NOINTERFACE;
98 static ULONG d3d_device_context_state_private_addref(struct d3d_device_context_state *state)
100 ULONG refcount = InterlockedIncrement(&state->private_refcount);
102 TRACE("%p increasing private refcount to %u.\n", state, refcount);
104 return refcount;
107 static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface)
109 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
110 ULONG refcount = InterlockedIncrement(&state->refcount);
112 TRACE("%p increasing refcount to %u.\n", state, refcount);
114 if (refcount == 1)
116 d3d_device_context_state_private_addref(state);
117 ID3D11Device2_AddRef(state->device);
120 return refcount;
123 static void d3d_device_remove_context_state(struct d3d_device *device, struct d3d_device_context_state *state)
125 unsigned int i;
127 for (i = 0; i < device->context_state_count; ++i)
129 if (device->context_states[i] != state)
130 continue;
132 if (i != device->context_state_count - 1)
133 device->context_states[i] = device->context_states[device->context_state_count - 1];
134 --device->context_state_count;
135 break;
139 static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
141 ULONG refcount = InterlockedDecrement(&state->private_refcount);
142 struct d3d_device_context_state_entry *entry;
143 struct d3d_device *device;
144 unsigned int i;
146 TRACE("%p decreasing private refcount to %u.\n", state, refcount);
148 if (!refcount)
150 wined3d_private_store_cleanup(&state->private_store);
151 for (i = 0; i < state->entry_count; ++i)
153 entry = &state->entries[i];
154 device = entry->device;
156 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
157 wined3d_state_destroy(entry->wined3d_state);
159 d3d_device_remove_context_state(device, state);
161 heap_free(state->entries);
162 wined3d_device_decref(state->wined3d_device);
163 heap_free(state);
167 static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface)
169 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
170 ULONG refcount = InterlockedDecrement(&state->refcount);
172 TRACE("%p decreasing refcount to %u.\n", state, refcount);
174 if (!refcount)
176 ID3D11Device2_Release(state->device);
177 d3d_device_context_state_private_release(state);
180 return refcount;
183 static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device)
185 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
187 TRACE("iface %p, device %p.\n", iface, device);
189 *device = (ID3D11Device *)state->device;
190 ID3D11Device_AddRef(*device);
193 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_GetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
194 UINT *data_size, void *data)
196 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
198 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
200 return d3d_get_private_data(&state->private_store, guid, data_size, data);
203 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
204 UINT data_size, const void *data)
206 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
208 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
210 return d3d_set_private_data(&state->private_store, guid, data_size, data);
213 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateDataInterface(ID3DDeviceContextState *iface,
214 REFGUID guid, const IUnknown *data)
216 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
218 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
220 return d3d_set_private_data_interface(&state->private_store, guid, data);
223 static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
225 /* IUnknown methods */
226 d3d_device_context_state_QueryInterface,
227 d3d_device_context_state_AddRef,
228 d3d_device_context_state_Release,
229 /* ID3D11DeviceChild methods */
230 d3d_device_context_state_GetDevice,
231 d3d_device_context_state_GetPrivateData,
232 d3d_device_context_state_SetPrivateData,
233 d3d_device_context_state_SetPrivateDataInterface,
234 /* ID3DDeviceContextState methods */
237 static struct d3d_device_context_state_entry *d3d_device_context_state_get_entry(
238 struct d3d_device_context_state *state, struct d3d_device *device)
240 unsigned int i;
242 for (i = 0; i < state->entry_count; ++i)
244 if (state->entries[i].device == device)
245 return &state->entries[i];
248 return NULL;
251 static BOOL d3d_device_context_state_add_entry(struct d3d_device_context_state *state,
252 struct d3d_device *device, struct wined3d_state *wined3d_state)
254 struct d3d_device_context_state_entry *entry;
256 if (!d3d_array_reserve((void **)&state->entries, &state->entries_size,
257 state->entry_count + 1, sizeof(*state->entries)))
258 return FALSE;
260 if (!d3d_array_reserve((void **)&device->context_states, &device->context_states_size,
261 device->context_state_count + 1, sizeof(*device->context_states)))
262 return FALSE;
264 entry = &state->entries[state->entry_count++];
265 entry->device = device;
266 entry->wined3d_state = wined3d_state;
268 device->context_states[device->context_state_count++] = state;
270 return TRUE;
273 static void d3d_device_context_state_remove_entry(struct d3d_device_context_state *state, struct d3d_device *device)
275 struct d3d_device_context_state_entry *entry;
276 unsigned int i;
278 for (i = 0; i < state->entry_count; ++i)
280 entry = &state->entries[i];
281 if (entry->device != device)
282 continue;
284 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
285 wined3d_state_destroy(entry->wined3d_state);
287 if (i != state->entry_count)
288 state->entries[i] = state->entries[state->entry_count - 1];
289 --state->entry_count;
291 break;
295 static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d3d_device_context_state *state,
296 struct d3d_device *device)
298 struct d3d_device_context_state_entry *entry;
299 struct wined3d_state *wined3d_state;
301 if ((entry = d3d_device_context_state_get_entry(state, device)))
302 return entry->wined3d_state;
304 if (FAILED(wined3d_state_create(device->wined3d_device,
305 (enum wined3d_feature_level *)&state->feature_level, 1, &wined3d_state)))
306 return NULL;
308 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
310 wined3d_state_destroy(wined3d_state);
311 return NULL;
314 return wined3d_state;
317 static void d3d_device_context_state_init(struct d3d_device_context_state *state,
318 struct d3d_device *device, D3D_FEATURE_LEVEL feature_level, REFIID emulated_interface)
320 state->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl;
321 state->refcount = state->private_refcount = 0;
323 wined3d_private_store_init(&state->private_store);
325 state->feature_level = feature_level;
326 state->emulated_interface = *emulated_interface;
327 wined3d_device_incref(state->wined3d_device = device->wined3d_device);
328 state->device = &device->ID3D11Device2_iface;
330 d3d_device_context_state_AddRef(&state->ID3DDeviceContextState_iface);
333 /* ID3D11CommandList methods */
335 static inline struct d3d11_command_list *impl_from_ID3D11CommandList(ID3D11CommandList *iface)
337 return CONTAINING_RECORD(iface, struct d3d11_command_list, ID3D11CommandList_iface);
340 static HRESULT STDMETHODCALLTYPE d3d11_command_list_QueryInterface(ID3D11CommandList *iface, REFIID iid, void **out)
342 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
344 if (IsEqualGUID(iid, &IID_ID3D11CommandList)
345 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
346 || IsEqualGUID(iid, &IID_IUnknown))
348 ID3D11CommandList_AddRef(iface);
349 *out = iface;
350 return S_OK;
353 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
354 *out = NULL;
356 return E_NOINTERFACE;
359 static ULONG STDMETHODCALLTYPE d3d11_command_list_AddRef(ID3D11CommandList *iface)
361 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
362 ULONG refcount = InterlockedIncrement(&list->refcount);
364 TRACE("%p increasing refcount to %u.\n", list, refcount);
366 return refcount;
369 static ULONG STDMETHODCALLTYPE d3d11_command_list_Release(ID3D11CommandList *iface)
371 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
372 ULONG refcount = InterlockedDecrement(&list->refcount);
374 TRACE("%p decreasing refcount to %u.\n", list, refcount);
376 if (!refcount)
378 wined3d_mutex_lock();
379 wined3d_command_list_decref(list->wined3d_list);
380 wined3d_mutex_unlock();
381 wined3d_private_store_cleanup(&list->private_store);
382 ID3D11Device2_Release(list->device);
383 heap_free(list);
386 return refcount;
389 static void STDMETHODCALLTYPE d3d11_command_list_GetDevice(ID3D11CommandList *iface, ID3D11Device **device)
391 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
393 TRACE("iface %p, device %p.\n", iface, device);
395 *device = (ID3D11Device *)list->device;
396 ID3D11Device2_AddRef(list->device);
399 static HRESULT STDMETHODCALLTYPE d3d11_command_list_GetPrivateData(ID3D11CommandList *iface, REFGUID guid,
400 UINT *data_size, void *data)
402 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
404 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
406 return d3d_get_private_data(&list->private_store, guid, data_size, data);
409 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateData(ID3D11CommandList *iface, REFGUID guid,
410 UINT data_size, const void *data)
412 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
414 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
416 return d3d_set_private_data(&list->private_store, guid, data_size, data);
419 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateDataInterface(ID3D11CommandList *iface,
420 REFGUID guid, const IUnknown *data)
422 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
424 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
426 return d3d_set_private_data_interface(&list->private_store, guid, data);
429 static UINT STDMETHODCALLTYPE d3d11_command_list_GetContextFlags(ID3D11CommandList *iface)
431 TRACE("iface %p.\n", iface);
433 return 0;
436 static const struct ID3D11CommandListVtbl d3d11_command_list_vtbl =
438 /* IUnknown methods */
439 d3d11_command_list_QueryInterface,
440 d3d11_command_list_AddRef,
441 d3d11_command_list_Release,
442 /* ID3D11DeviceChild methods */
443 d3d11_command_list_GetDevice,
444 d3d11_command_list_GetPrivateData,
445 d3d11_command_list_SetPrivateData,
446 d3d11_command_list_SetPrivateDataInterface,
447 /* ID3D11CommandList methods */
448 d3d11_command_list_GetContextFlags,
451 static struct d3d11_command_list *unsafe_impl_from_ID3D11CommandList(ID3D11CommandList *iface)
453 if (!iface)
454 return NULL;
455 assert(iface->lpVtbl == &d3d11_command_list_vtbl);
456 return impl_from_ID3D11CommandList(iface);
459 static void d3d11_device_context_cleanup(struct d3d11_device_context *context)
461 wined3d_private_store_cleanup(&context->private_store);
464 /* ID3D11DeviceContext - immediate context methods */
466 static inline struct d3d11_device_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
468 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11DeviceContext1_iface);
471 static HRESULT STDMETHODCALLTYPE d3d11_device_context_QueryInterface(ID3D11DeviceContext1 *iface,
472 REFIID iid, void **out)
474 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
476 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
478 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
479 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
480 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
481 || IsEqualGUID(iid, &IID_IUnknown))
483 *out = &context->ID3D11DeviceContext1_iface;
485 else if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE && IsEqualGUID(iid, &IID_ID3D11Multithread))
487 *out = &context->ID3D11Multithread_iface;
489 else
491 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
492 *out = NULL;
493 return E_NOINTERFACE;
496 ID3D11DeviceContext1_AddRef(iface);
497 return S_OK;
500 static ULONG STDMETHODCALLTYPE d3d11_device_context_AddRef(ID3D11DeviceContext1 *iface)
502 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
503 ULONG refcount = InterlockedIncrement(&context->refcount);
505 TRACE("%p increasing refcount to %u.\n", context, refcount);
507 if (refcount == 1)
509 ID3D11Device2_AddRef(&context->device->ID3D11Device2_iface);
512 return refcount;
515 static ULONG STDMETHODCALLTYPE d3d11_device_context_Release(ID3D11DeviceContext1 *iface)
517 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
518 ULONG refcount = InterlockedDecrement(&context->refcount);
520 TRACE("%p decreasing refcount to %u.\n", context, refcount);
522 if (!refcount)
524 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
526 wined3d_deferred_context_destroy(context->wined3d_context);
527 d3d11_device_context_cleanup(context);
528 heap_free(context);
530 ID3D11Device2_Release(&context->device->ID3D11Device2_iface);
533 return refcount;
536 static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface,
537 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
539 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
540 unsigned int i;
542 wined3d_mutex_lock();
543 for (i = 0; i < buffer_count; ++i)
545 struct wined3d_buffer *wined3d_buffer;
546 struct d3d_buffer *buffer_impl;
548 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(context->wined3d_context,
549 type, start_slot + i)))
551 buffers[i] = NULL;
552 continue;
555 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
556 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
557 ID3D11Buffer_AddRef(buffers[i]);
559 wined3d_mutex_unlock();
562 static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface,
563 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
565 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
566 unsigned int i;
568 wined3d_mutex_lock();
569 for (i = 0; i < buffer_count; ++i)
571 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
573 wined3d_device_context_set_constant_buffer(context->wined3d_context, type, start_slot + i,
574 buffer ? buffer->wined3d_buffer : NULL);
576 wined3d_mutex_unlock();
579 static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
581 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
583 TRACE("iface %p, device %p.\n", iface, device);
585 *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
586 ID3D11Device_AddRef(*device);
589 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
590 UINT *data_size, void *data)
592 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
594 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
596 return d3d_get_private_data(&context->private_store, guid, data_size, data);
599 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
600 UINT data_size, const void *data)
602 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
604 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
606 return d3d_set_private_data(&context->private_store, guid, data_size, data);
609 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
610 REFGUID guid, const IUnknown *data)
612 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
614 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
616 return d3d_set_private_data_interface(&context->private_store, guid, data);
619 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
620 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
622 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
623 iface, start_slot, buffer_count, buffers);
625 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
626 buffer_count, buffers);
629 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
630 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
632 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
633 unsigned int i;
635 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
636 iface, start_slot, view_count, views);
638 wined3d_mutex_lock();
639 for (i = 0; i < view_count; ++i)
641 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
643 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
644 start_slot + i, view ? view->wined3d_view : NULL);
646 wined3d_mutex_unlock();
649 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
650 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
652 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
653 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
655 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
656 iface, shader, class_instances, class_instance_count);
658 if (class_instances)
659 FIXME("Dynamic linking is not implemented yet.\n");
661 wined3d_mutex_lock();
662 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
663 ps ? ps->wined3d_shader : NULL);
664 wined3d_mutex_unlock();
667 static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
668 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
670 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
671 unsigned int i;
673 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
674 iface, start_slot, sampler_count, samplers);
676 wined3d_mutex_lock();
677 for (i = 0; i < sampler_count; ++i)
679 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
681 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i,
682 sampler ? sampler->wined3d_sampler : NULL);
684 wined3d_mutex_unlock();
687 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
688 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
690 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
691 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
693 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
694 iface, shader, class_instances, class_instance_count);
696 if (class_instances)
697 FIXME("Dynamic linking is not implemented yet.\n");
699 wined3d_mutex_lock();
700 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
701 vs ? vs->wined3d_shader : NULL);
702 wined3d_mutex_unlock();
705 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
706 UINT index_count, UINT start_index_location, INT base_vertex_location)
708 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
710 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
711 iface, index_count, start_index_location, base_vertex_location);
713 wined3d_mutex_lock();
714 wined3d_device_context_draw_indexed(context->wined3d_context,
715 base_vertex_location, start_index_location, index_count, 0, 0);
716 wined3d_mutex_unlock();
719 static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
720 UINT vertex_count, UINT start_vertex_location)
722 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
724 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
725 iface, vertex_count, start_vertex_location);
727 wined3d_mutex_lock();
728 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
729 wined3d_mutex_unlock();
732 static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
733 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
735 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
736 struct wined3d_resource *wined3d_resource;
737 struct wined3d_map_desc map_desc;
738 HRESULT hr;
740 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
741 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
743 if (map_flags)
744 FIXME("Ignoring map_flags %#x.\n", map_flags);
746 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
748 wined3d_mutex_lock();
749 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
750 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
751 wined3d_mutex_unlock();
753 mapped_subresource->pData = map_desc.data;
754 mapped_subresource->RowPitch = map_desc.row_pitch;
755 mapped_subresource->DepthPitch = map_desc.slice_pitch;
757 return hr;
760 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
761 UINT subresource_idx)
763 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
764 struct wined3d_resource *wined3d_resource;
766 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
768 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
770 wined3d_mutex_lock();
771 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
772 wined3d_mutex_unlock();
775 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
776 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
778 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
779 iface, start_slot, buffer_count, buffers);
781 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
782 buffer_count, buffers);
785 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
786 ID3D11InputLayout *input_layout)
788 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
789 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
791 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
793 wined3d_mutex_lock();
794 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
795 wined3d_mutex_unlock();
798 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
799 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
801 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
802 unsigned int i;
804 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
805 iface, start_slot, buffer_count, buffers, strides, offsets);
807 wined3d_mutex_lock();
808 for (i = 0; i < buffer_count; ++i)
810 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
812 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
813 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
815 wined3d_mutex_unlock();
818 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
819 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
821 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
822 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
824 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
825 iface, buffer, debug_dxgi_format(format), offset);
827 wined3d_mutex_lock();
828 wined3d_device_context_set_index_buffer(context->wined3d_context,
829 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
830 wined3dformat_from_dxgi_format(format), offset);
831 wined3d_mutex_unlock();
834 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
835 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
836 UINT start_instance_location)
838 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
840 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
841 "base_vertex_location %d, start_instance_location %u.\n",
842 iface, instance_index_count, instance_count, start_index_location,
843 base_vertex_location, start_instance_location);
845 wined3d_mutex_lock();
846 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
847 start_index_location, instance_index_count, start_instance_location, instance_count);
848 wined3d_mutex_unlock();
851 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
852 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
854 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
856 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
857 "start_instance_location %u.\n",
858 iface, instance_vertex_count, instance_count, start_vertex_location,
859 start_instance_location);
861 wined3d_mutex_lock();
862 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
863 instance_vertex_count, start_instance_location, instance_count);
864 wined3d_mutex_unlock();
867 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
868 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
870 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
871 iface, start_slot, buffer_count, buffers);
873 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
874 buffer_count, buffers);
877 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
878 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
880 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
881 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
883 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
884 iface, shader, class_instances, class_instance_count);
886 if (class_instances)
887 FIXME("Dynamic linking is not implemented yet.\n");
889 wined3d_mutex_lock();
890 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
891 gs ? gs->wined3d_shader : NULL);
892 wined3d_mutex_unlock();
895 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
896 D3D11_PRIMITIVE_TOPOLOGY topology)
898 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
899 enum wined3d_primitive_type primitive_type;
900 unsigned int patch_vertex_count;
902 TRACE("iface %p, topology %#x.\n", iface, topology);
904 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
906 wined3d_mutex_lock();
907 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
908 wined3d_mutex_unlock();
911 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
912 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
914 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
915 unsigned int i;
917 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
919 wined3d_mutex_lock();
920 for (i = 0; i < view_count; ++i)
922 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
924 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
925 start_slot + i, view ? view->wined3d_view : NULL);
927 wined3d_mutex_unlock();
930 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
931 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
933 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
934 unsigned int i;
936 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
937 iface, start_slot, sampler_count, samplers);
939 wined3d_mutex_lock();
940 for (i = 0; i < sampler_count; ++i)
942 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
944 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i,
945 sampler ? sampler->wined3d_sampler : NULL);
947 wined3d_mutex_unlock();
950 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
951 ID3D11Asynchronous *asynchronous)
953 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
954 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
956 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
958 wined3d_mutex_lock();
959 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
960 wined3d_mutex_unlock();
963 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
964 ID3D11Asynchronous *asynchronous)
966 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
967 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
969 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
971 wined3d_mutex_lock();
972 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
973 wined3d_mutex_unlock();
976 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
977 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
979 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
980 unsigned int wined3d_flags;
981 HRESULT hr;
983 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
984 iface, asynchronous, data, data_size, data_flags);
986 if (!data && data_size)
987 return E_INVALIDARG;
989 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
991 wined3d_mutex_lock();
992 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
994 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
995 if (hr == WINED3DERR_INVALIDCALL)
996 hr = DXGI_ERROR_INVALID_CALL;
998 else
1000 WARN("Invalid data size %u.\n", data_size);
1001 hr = E_INVALIDARG;
1003 wined3d_mutex_unlock();
1005 return hr;
1008 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1009 ID3D11Predicate *predicate, BOOL value)
1011 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1012 struct d3d_query *query;
1014 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1016 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1018 wined3d_mutex_lock();
1019 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1020 wined3d_mutex_unlock();
1023 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1024 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1026 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1027 unsigned int i;
1029 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1031 wined3d_mutex_lock();
1032 for (i = 0; i < view_count; ++i)
1034 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1036 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
1037 start_slot + i, view ? view->wined3d_view : NULL);
1039 wined3d_mutex_unlock();
1042 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1043 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1045 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1046 unsigned int i;
1048 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1049 iface, start_slot, sampler_count, samplers);
1051 wined3d_mutex_lock();
1052 for (i = 0; i < sampler_count; ++i)
1054 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1056 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i,
1057 sampler ? sampler->wined3d_sampler : NULL);
1059 wined3d_mutex_unlock();
1062 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1063 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1064 ID3D11DepthStencilView *depth_stencil_view)
1066 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1067 struct d3d_depthstencil_view *dsv;
1068 unsigned int i;
1070 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1071 iface, render_target_view_count, render_target_views, depth_stencil_view);
1073 wined3d_mutex_lock();
1074 for (i = 0; i < render_target_view_count; ++i)
1076 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
1077 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
1078 rtv ? rtv->wined3d_view : NULL, FALSE);
1080 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1082 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
1085 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1086 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
1087 wined3d_mutex_unlock();
1090 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1091 ID3D11DeviceContext1 *iface, UINT render_target_view_count,
1092 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
1093 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1094 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
1096 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1097 unsigned int i;
1099 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1100 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
1101 "initial_counts %p.\n",
1102 iface, render_target_view_count, render_target_views, depth_stencil_view,
1103 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
1104 initial_counts);
1106 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1108 d3d11_device_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
1109 depth_stencil_view);
1112 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1114 wined3d_mutex_lock();
1115 for (i = 0; i < unordered_access_view_start_slot; ++i)
1117 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1118 WINED3D_PIPELINE_GRAPHICS, i, NULL, ~0u);
1120 for (i = 0; i < unordered_access_view_count; ++i)
1122 struct d3d11_unordered_access_view *view
1123 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
1125 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1126 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i,
1127 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1129 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
1131 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1132 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i, NULL, ~0u);
1134 wined3d_mutex_unlock();
1138 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1139 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1141 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1142 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1143 struct d3d_blend_state *blend_state_impl;
1145 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1146 iface, blend_state, debug_float4(blend_factor), sample_mask);
1148 if (!blend_factor)
1149 blend_factor = default_blend_factor;
1151 wined3d_mutex_lock();
1152 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1153 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1154 (const struct wined3d_color *)blend_factor, sample_mask);
1155 else
1156 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1157 (const struct wined3d_color *)blend_factor, sample_mask);
1158 wined3d_mutex_unlock();
1161 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1162 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1164 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1165 struct d3d_depthstencil_state *state_impl;
1167 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1168 iface, depth_stencil_state, stencil_ref);
1170 wined3d_mutex_lock();
1171 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1173 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1174 wined3d_mutex_unlock();
1175 return;
1178 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1179 wined3d_mutex_unlock();
1182 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1183 ID3D11Buffer *const *buffers, const UINT *offsets)
1185 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1186 unsigned int count, i;
1188 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1190 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
1191 wined3d_mutex_lock();
1192 for (i = 0; i < count; ++i)
1194 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1196 wined3d_device_context_set_stream_output(context->wined3d_context, i,
1197 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1199 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1201 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
1203 wined3d_mutex_unlock();
1206 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1208 FIXME("iface %p stub!\n", iface);
1211 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1212 ID3D11Buffer *buffer, UINT offset)
1214 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1215 struct d3d_buffer *d3d_buffer;
1217 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1219 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1221 wined3d_mutex_lock();
1222 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1223 wined3d_mutex_unlock();
1226 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1227 ID3D11Buffer *buffer, UINT offset)
1229 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1230 struct d3d_buffer *d3d_buffer;
1232 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1234 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1236 wined3d_mutex_lock();
1237 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1238 wined3d_mutex_unlock();
1241 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1242 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1244 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1246 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1247 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1249 wined3d_mutex_lock();
1250 wined3d_device_context_dispatch(context->wined3d_context,
1251 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1252 wined3d_mutex_unlock();
1255 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1256 ID3D11Buffer *buffer, UINT offset)
1258 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1259 struct d3d_buffer *buffer_impl;
1261 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1263 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1265 wined3d_mutex_lock();
1266 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1267 wined3d_mutex_unlock();
1270 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1271 ID3D11RasterizerState *rasterizer_state)
1273 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1274 struct d3d_rasterizer_state *rasterizer_state_impl;
1276 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1278 wined3d_mutex_lock();
1279 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1280 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1281 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1282 wined3d_mutex_unlock();
1285 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1286 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1288 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1289 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1290 unsigned int i;
1292 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1294 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1295 return;
1297 for (i = 0; i < viewport_count; ++i)
1299 wined3d_vp[i].x = viewports[i].TopLeftX;
1300 wined3d_vp[i].y = viewports[i].TopLeftY;
1301 wined3d_vp[i].width = viewports[i].Width;
1302 wined3d_vp[i].height = viewports[i].Height;
1303 wined3d_vp[i].min_z = viewports[i].MinDepth;
1304 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1307 wined3d_mutex_lock();
1308 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1309 wined3d_mutex_unlock();
1312 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1313 UINT rect_count, const D3D11_RECT *rects)
1315 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1317 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1319 if (rect_count > WINED3D_MAX_VIEWPORTS)
1320 return;
1322 wined3d_mutex_lock();
1323 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1324 wined3d_mutex_unlock();
1327 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1328 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1329 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1331 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1332 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1333 struct wined3d_box wined3d_src_box;
1335 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1336 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1337 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1338 src_resource, src_subresource_idx, src_box);
1340 if (!dst_resource || !src_resource)
1341 return;
1343 if (src_box)
1344 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1345 src_box->right, src_box->bottom, src_box->front, src_box->back);
1347 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1348 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1349 wined3d_mutex_lock();
1350 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1351 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1352 wined3d_mutex_unlock();
1355 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1356 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1358 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1359 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1361 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1363 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1364 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1365 wined3d_mutex_lock();
1366 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1367 wined3d_mutex_unlock();
1370 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1371 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1372 const void *data, UINT row_pitch, UINT depth_pitch)
1374 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1375 struct wined3d_resource *wined3d_resource;
1376 struct wined3d_box wined3d_box;
1378 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1379 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1381 if (box)
1382 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1384 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1385 wined3d_mutex_lock();
1386 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1387 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1388 wined3d_mutex_unlock();
1391 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1392 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1394 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1395 struct d3d11_unordered_access_view *uav;
1396 struct d3d_buffer *buffer_impl;
1398 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1399 iface, dst_buffer, dst_offset, src_view);
1401 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1402 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1404 wined3d_mutex_lock();
1405 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1406 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1407 wined3d_mutex_unlock();
1410 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1411 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1413 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1414 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1415 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1416 HRESULT hr;
1418 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1419 iface, render_target_view, debug_float4(color_rgba));
1421 if (!view)
1422 return;
1424 wined3d_mutex_lock();
1425 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1426 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1427 ERR("Failed to clear view, hr %#x.\n", hr);
1428 wined3d_mutex_unlock();
1431 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1432 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1434 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1435 struct d3d11_unordered_access_view *view;
1437 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1438 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1440 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1441 wined3d_mutex_lock();
1442 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1443 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1444 wined3d_mutex_unlock();
1447 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1448 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1450 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1451 iface, unordered_access_view, debug_float4(values));
1454 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1455 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1457 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1458 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1459 DWORD wined3d_flags;
1460 HRESULT hr;
1462 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1463 iface, depth_stencil_view, flags, depth, stencil);
1465 if (!view)
1466 return;
1468 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1470 wined3d_mutex_lock();
1471 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1472 wined3d_flags, NULL, depth, stencil)))
1473 ERR("Failed to clear view, hr %#x.\n", hr);
1474 wined3d_mutex_unlock();
1477 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1478 ID3D11ShaderResourceView *view)
1480 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1481 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1483 TRACE("iface %p, view %p.\n", iface, view);
1485 wined3d_mutex_lock();
1486 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1487 wined3d_mutex_unlock();
1490 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1491 ID3D11Resource *resource, FLOAT min_lod)
1493 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1496 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1497 ID3D11Resource *resource)
1499 FIXME("iface %p, resource %p stub!\n", iface, resource);
1501 return 0.0f;
1504 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1505 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1506 ID3D11Resource *src_resource, UINT src_subresource_idx,
1507 DXGI_FORMAT format)
1509 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1510 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1511 enum wined3d_format_id wined3d_format;
1513 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1514 "src_resource %p, src_subresource_idx %u, format %s.\n",
1515 iface, dst_resource, dst_subresource_idx,
1516 src_resource, src_subresource_idx, debug_dxgi_format(format));
1518 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1519 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1520 wined3d_format = wined3dformat_from_dxgi_format(format);
1521 wined3d_mutex_lock();
1522 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1523 wined3d_dst_resource, dst_subresource_idx,
1524 wined3d_src_resource, src_subresource_idx, wined3d_format);
1525 wined3d_mutex_unlock();
1528 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1529 ID3D11CommandList *command_list, BOOL restore_state)
1531 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1532 struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);
1534 TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);
1536 wined3d_mutex_lock();
1537 wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
1538 wined3d_mutex_unlock();
1541 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1542 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1544 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1545 unsigned int i;
1547 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1548 iface, start_slot, view_count, views);
1550 wined3d_mutex_lock();
1551 for (i = 0; i < view_count; ++i)
1553 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1555 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1556 start_slot + i, view ? view->wined3d_view : NULL);
1558 wined3d_mutex_unlock();
1561 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1562 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1564 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1565 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1567 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1568 iface, shader, class_instances, class_instance_count);
1570 if (class_instances)
1571 FIXME("Dynamic linking is not implemented yet.\n");
1573 wined3d_mutex_lock();
1574 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1575 hs ? hs->wined3d_shader : NULL);
1576 wined3d_mutex_unlock();
1579 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1580 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1582 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1583 unsigned int i;
1585 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1586 iface, start_slot, sampler_count, samplers);
1588 wined3d_mutex_lock();
1589 for (i = 0; i < sampler_count; ++i)
1591 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1593 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1594 sampler ? sampler->wined3d_sampler : NULL);
1596 wined3d_mutex_unlock();
1599 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1600 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1602 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1603 iface, start_slot, buffer_count, buffers);
1605 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1606 buffer_count, buffers);
1609 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1610 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1612 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1613 unsigned int i;
1615 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1616 iface, start_slot, view_count, views);
1618 wined3d_mutex_lock();
1619 for (i = 0; i < view_count; ++i)
1621 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1623 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1624 start_slot + i, view ? view->wined3d_view : NULL);
1626 wined3d_mutex_unlock();
1629 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1630 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1632 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1633 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1635 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1636 iface, shader, class_instances, class_instance_count);
1638 if (class_instances)
1639 FIXME("Dynamic linking is not implemented yet.\n");
1641 wined3d_mutex_lock();
1642 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1643 ds ? ds->wined3d_shader : NULL);
1644 wined3d_mutex_unlock();
1647 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1648 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1650 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1651 unsigned int i;
1653 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1654 iface, start_slot, sampler_count, samplers);
1656 wined3d_mutex_lock();
1657 for (i = 0; i < sampler_count; ++i)
1659 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1661 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1662 sampler ? sampler->wined3d_sampler : NULL);
1664 wined3d_mutex_unlock();
1667 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1668 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1670 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1671 iface, start_slot, buffer_count, buffers);
1673 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1674 buffer_count, buffers);
1677 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1678 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1680 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1681 unsigned int i;
1683 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1684 iface, start_slot, view_count, views);
1686 wined3d_mutex_lock();
1687 for (i = 0; i < view_count; ++i)
1689 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1691 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1692 start_slot + i, view ? view->wined3d_view : NULL);
1694 wined3d_mutex_unlock();
1697 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1698 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1700 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1701 unsigned int i;
1703 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1704 iface, start_slot, view_count, views, initial_counts);
1706 wined3d_mutex_lock();
1707 for (i = 0; i < view_count; ++i)
1709 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1711 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1712 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1714 wined3d_mutex_unlock();
1717 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1718 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1720 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1721 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1723 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1724 iface, shader, class_instances, class_instance_count);
1726 if (class_instances)
1727 FIXME("Dynamic linking is not implemented yet.\n");
1729 wined3d_mutex_lock();
1730 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1731 cs ? cs->wined3d_shader : NULL);
1732 wined3d_mutex_unlock();
1735 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1736 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1738 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1739 unsigned int i;
1741 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1742 iface, start_slot, sampler_count, samplers);
1744 wined3d_mutex_lock();
1745 for (i = 0; i < sampler_count; ++i)
1747 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1749 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1750 sampler ? sampler->wined3d_sampler : NULL);
1752 wined3d_mutex_unlock();
1755 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1756 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1758 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1759 iface, start_slot, buffer_count, buffers);
1761 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1762 buffer_count, buffers);
1765 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1766 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1768 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1769 iface, start_slot, buffer_count, buffers);
1771 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1772 buffer_count, buffers);
1775 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1776 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1778 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1779 unsigned int i;
1781 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1782 iface, start_slot, view_count, views);
1784 wined3d_mutex_lock();
1785 for (i = 0; i < view_count; ++i)
1787 struct wined3d_shader_resource_view *wined3d_view;
1788 struct d3d_shader_resource_view *view_impl;
1790 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1791 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1793 views[i] = NULL;
1794 continue;
1797 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1798 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1799 ID3D11ShaderResourceView_AddRef(views[i]);
1801 wined3d_mutex_unlock();
1804 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1805 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1807 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1808 struct wined3d_shader *wined3d_shader;
1809 struct d3d_pixel_shader *shader_impl;
1811 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1812 iface, shader, class_instances, class_instance_count);
1814 if (class_instances || class_instance_count)
1815 FIXME("Dynamic linking not implemented yet.\n");
1816 if (class_instance_count)
1817 *class_instance_count = 0;
1819 wined3d_mutex_lock();
1820 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1822 wined3d_mutex_unlock();
1823 *shader = NULL;
1824 return;
1827 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1828 wined3d_mutex_unlock();
1829 *shader = &shader_impl->ID3D11PixelShader_iface;
1830 ID3D11PixelShader_AddRef(*shader);
1833 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1834 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1836 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1837 unsigned int i;
1839 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1840 iface, start_slot, sampler_count, samplers);
1842 wined3d_mutex_lock();
1843 for (i = 0; i < sampler_count; ++i)
1845 struct wined3d_sampler *wined3d_sampler;
1846 struct d3d_sampler_state *sampler_impl;
1848 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1849 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1851 samplers[i] = NULL;
1852 continue;
1855 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1856 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1857 ID3D11SamplerState_AddRef(samplers[i]);
1859 wined3d_mutex_unlock();
1862 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1863 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1865 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1866 struct d3d_vertex_shader *shader_impl;
1867 struct wined3d_shader *wined3d_shader;
1869 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1870 iface, shader, class_instances, class_instance_count);
1872 if (class_instances || class_instance_count)
1873 FIXME("Dynamic linking not implemented yet.\n");
1874 if (class_instance_count)
1875 *class_instance_count = 0;
1877 wined3d_mutex_lock();
1878 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1880 wined3d_mutex_unlock();
1881 *shader = NULL;
1882 return;
1885 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1886 wined3d_mutex_unlock();
1887 *shader = &shader_impl->ID3D11VertexShader_iface;
1888 ID3D11VertexShader_AddRef(*shader);
1891 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1892 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1894 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1895 iface, start_slot, buffer_count, buffers);
1897 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1898 buffer_count, buffers);
1901 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1902 ID3D11InputLayout **input_layout)
1904 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1905 struct wined3d_vertex_declaration *wined3d_declaration;
1906 struct d3d_input_layout *input_layout_impl;
1908 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1910 wined3d_mutex_lock();
1911 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1913 wined3d_mutex_unlock();
1914 *input_layout = NULL;
1915 return;
1918 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1919 wined3d_mutex_unlock();
1920 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1921 ID3D11InputLayout_AddRef(*input_layout);
1924 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1925 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1927 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1928 unsigned int i;
1930 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1931 iface, start_slot, buffer_count, buffers, strides, offsets);
1933 wined3d_mutex_lock();
1934 for (i = 0; i < buffer_count; ++i)
1936 struct wined3d_buffer *wined3d_buffer = NULL;
1937 struct d3d_buffer *buffer_impl;
1939 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1940 &wined3d_buffer, &offsets[i], &strides[i])))
1942 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1943 if (strides)
1944 strides[i] = 0;
1945 if (offsets)
1946 offsets[i] = 0;
1949 if (!wined3d_buffer)
1951 buffers[i] = NULL;
1952 continue;
1955 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1956 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1958 wined3d_mutex_unlock();
1961 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1962 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1964 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1965 enum wined3d_format_id wined3d_format;
1966 struct wined3d_buffer *wined3d_buffer;
1967 struct d3d_buffer *buffer_impl;
1969 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1971 wined3d_mutex_lock();
1972 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1973 *format = dxgi_format_from_wined3dformat(wined3d_format);
1974 if (!wined3d_buffer)
1976 wined3d_mutex_unlock();
1977 *buffer = NULL;
1978 return;
1981 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1982 wined3d_mutex_unlock();
1983 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1986 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1987 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1989 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1990 iface, start_slot, buffer_count, buffers);
1992 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1993 buffer_count, buffers);
1996 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1997 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1999 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2000 struct d3d_geometry_shader *shader_impl;
2001 struct wined3d_shader *wined3d_shader;
2003 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2004 iface, shader, class_instances, class_instance_count);
2006 if (class_instances || class_instance_count)
2007 FIXME("Dynamic linking not implemented yet.\n");
2008 if (class_instance_count)
2009 *class_instance_count = 0;
2011 wined3d_mutex_lock();
2012 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
2014 wined3d_mutex_unlock();
2015 *shader = NULL;
2016 return;
2019 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2020 wined3d_mutex_unlock();
2021 *shader = &shader_impl->ID3D11GeometryShader_iface;
2022 ID3D11GeometryShader_AddRef(*shader);
2025 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
2026 D3D11_PRIMITIVE_TOPOLOGY *topology)
2028 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2029 enum wined3d_primitive_type primitive_type;
2030 unsigned int patch_vertex_count;
2032 TRACE("iface %p, topology %p.\n", iface, topology);
2034 wined3d_mutex_lock();
2035 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
2036 wined3d_mutex_unlock();
2038 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
2041 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
2042 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2044 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2045 unsigned int i;
2047 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2049 wined3d_mutex_lock();
2050 for (i = 0; i < view_count; ++i)
2052 struct wined3d_shader_resource_view *wined3d_view;
2053 struct d3d_shader_resource_view *view_impl;
2055 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2056 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2058 views[i] = NULL;
2059 continue;
2062 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2063 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2064 ID3D11ShaderResourceView_AddRef(views[i]);
2066 wined3d_mutex_unlock();
2069 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
2070 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2072 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2073 unsigned int i;
2075 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2076 iface, start_slot, sampler_count, samplers);
2078 wined3d_mutex_lock();
2079 for (i = 0; i < sampler_count; ++i)
2081 struct wined3d_sampler *wined3d_sampler;
2082 struct d3d_sampler_state *sampler_impl;
2084 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2085 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2087 samplers[i] = NULL;
2088 continue;
2091 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2092 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2093 ID3D11SamplerState_AddRef(samplers[i]);
2095 wined3d_mutex_unlock();
2098 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2099 ID3D11Predicate **predicate, BOOL *value)
2101 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2102 struct wined3d_query *wined3d_predicate;
2103 struct d3d_query *predicate_impl;
2105 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2107 wined3d_mutex_lock();
2108 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2110 wined3d_mutex_unlock();
2111 *predicate = NULL;
2112 return;
2115 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2116 wined3d_mutex_unlock();
2117 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2118 ID3D11Predicate_AddRef(*predicate);
2121 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2122 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2124 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2125 unsigned int i;
2127 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2129 wined3d_mutex_lock();
2130 for (i = 0; i < view_count; ++i)
2132 struct wined3d_shader_resource_view *wined3d_view;
2133 struct d3d_shader_resource_view *view_impl;
2135 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2136 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2138 views[i] = NULL;
2139 continue;
2142 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2143 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2144 ID3D11ShaderResourceView_AddRef(views[i]);
2146 wined3d_mutex_unlock();
2149 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2150 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2152 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2153 unsigned int i;
2155 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2156 iface, start_slot, sampler_count, samplers);
2158 wined3d_mutex_lock();
2159 for (i = 0; i < sampler_count; ++i)
2161 struct d3d_sampler_state *sampler_impl;
2162 struct wined3d_sampler *wined3d_sampler;
2164 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2165 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2167 samplers[i] = NULL;
2168 continue;
2171 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2172 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2173 ID3D11SamplerState_AddRef(samplers[i]);
2175 wined3d_mutex_unlock();
2178 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2179 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2180 ID3D11DepthStencilView **depth_stencil_view)
2182 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2183 struct wined3d_rendertarget_view *wined3d_view;
2185 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2186 iface, render_target_view_count, render_target_views, depth_stencil_view);
2188 wined3d_mutex_lock();
2189 if (render_target_views)
2191 struct d3d_rendertarget_view *view_impl;
2192 unsigned int i;
2194 for (i = 0; i < render_target_view_count; ++i)
2196 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2197 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2199 render_target_views[i] = NULL;
2200 continue;
2203 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2204 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2208 if (depth_stencil_view)
2210 struct d3d_depthstencil_view *view_impl;
2212 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2213 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2215 *depth_stencil_view = NULL;
2217 else
2219 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2220 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2223 wined3d_mutex_unlock();
2226 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2227 ID3D11DeviceContext1 *iface,
2228 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2229 ID3D11DepthStencilView **depth_stencil_view,
2230 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2231 ID3D11UnorderedAccessView **unordered_access_views)
2233 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2234 struct wined3d_unordered_access_view *wined3d_view;
2235 struct d3d11_unordered_access_view *view_impl;
2236 unsigned int i;
2238 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2239 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2240 "unordered_access_views %p.\n",
2241 iface, render_target_view_count, render_target_views, depth_stencil_view,
2242 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2244 if (render_target_views || depth_stencil_view)
2245 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2246 render_target_views, depth_stencil_view);
2248 if (unordered_access_views)
2250 wined3d_mutex_lock();
2251 for (i = 0; i < unordered_access_view_count; ++i)
2253 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2254 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2256 unordered_access_views[i] = NULL;
2257 continue;
2260 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2261 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2262 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2264 wined3d_mutex_unlock();
2268 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2269 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2271 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2272 struct wined3d_blend_state *wined3d_state;
2273 struct d3d_blend_state *blend_state_impl;
2275 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2276 iface, blend_state, blend_factor, sample_mask);
2278 wined3d_mutex_lock();
2279 if ((wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2280 (struct wined3d_color *)blend_factor, sample_mask)))
2282 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2283 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2285 else
2287 *blend_state = NULL;
2289 wined3d_mutex_unlock();
2292 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2293 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2295 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2296 struct wined3d_depth_stencil_state *wined3d_state;
2297 struct d3d_depthstencil_state *state_impl;
2299 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2300 iface, depth_stencil_state, stencil_ref);
2302 wined3d_mutex_lock();
2303 if ((wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref)))
2305 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2306 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2308 else
2310 *depth_stencil_state = NULL;
2312 wined3d_mutex_unlock();
2315 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2316 UINT buffer_count, ID3D11Buffer **buffers)
2318 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2319 unsigned int i;
2321 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2323 wined3d_mutex_lock();
2324 for (i = 0; i < buffer_count; ++i)
2326 struct wined3d_buffer *wined3d_buffer;
2327 struct d3d_buffer *buffer_impl;
2329 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2331 buffers[i] = NULL;
2332 continue;
2335 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2336 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2337 ID3D11Buffer_AddRef(buffers[i]);
2339 wined3d_mutex_unlock();
2342 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2343 ID3D11RasterizerState **rasterizer_state)
2345 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2346 struct d3d_rasterizer_state *rasterizer_state_impl;
2347 struct wined3d_rasterizer_state *wined3d_state;
2349 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2351 wined3d_mutex_lock();
2352 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2354 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2355 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2357 else
2359 *rasterizer_state = NULL;
2361 wined3d_mutex_unlock();
2364 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2365 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2367 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2368 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2369 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2371 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2373 if (!viewport_count)
2374 return;
2376 wined3d_mutex_lock();
2377 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2378 wined3d_mutex_unlock();
2380 if (!viewports)
2382 *viewport_count = actual_count;
2383 return;
2386 if (*viewport_count > actual_count)
2387 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2389 *viewport_count = min(actual_count, *viewport_count);
2390 for (i = 0; i < *viewport_count; ++i)
2392 viewports[i].TopLeftX = wined3d_vp[i].x;
2393 viewports[i].TopLeftY = wined3d_vp[i].y;
2394 viewports[i].Width = wined3d_vp[i].width;
2395 viewports[i].Height = wined3d_vp[i].height;
2396 viewports[i].MinDepth = wined3d_vp[i].min_z;
2397 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2401 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2402 UINT *rect_count, D3D11_RECT *rects)
2404 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2405 unsigned int actual_count;
2407 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2409 if (!rect_count)
2410 return;
2412 actual_count = *rect_count;
2414 wined3d_mutex_lock();
2415 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2416 wined3d_mutex_unlock();
2418 if (rects && *rect_count > actual_count)
2419 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2420 *rect_count = actual_count;
2423 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2424 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2426 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2427 unsigned int i;
2429 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2431 wined3d_mutex_lock();
2432 for (i = 0; i < view_count; ++i)
2434 struct wined3d_shader_resource_view *wined3d_view;
2435 struct d3d_shader_resource_view *view_impl;
2437 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2438 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2440 views[i] = NULL;
2441 continue;
2444 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2445 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2447 wined3d_mutex_unlock();
2450 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2451 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2453 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2454 struct d3d11_hull_shader *shader_impl;
2455 struct wined3d_shader *wined3d_shader;
2457 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2458 iface, shader, class_instances, class_instance_count);
2460 if (class_instances || class_instance_count)
2461 FIXME("Dynamic linking not implemented yet.\n");
2462 if (class_instance_count)
2463 *class_instance_count = 0;
2465 wined3d_mutex_lock();
2466 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2468 wined3d_mutex_unlock();
2469 *shader = NULL;
2470 return;
2473 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2474 wined3d_mutex_unlock();
2475 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2478 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2479 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2481 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2482 unsigned int i;
2484 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2485 iface, start_slot, sampler_count, samplers);
2487 wined3d_mutex_lock();
2488 for (i = 0; i < sampler_count; ++i)
2490 struct wined3d_sampler *wined3d_sampler;
2491 struct d3d_sampler_state *sampler_impl;
2493 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2494 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2496 samplers[i] = NULL;
2497 continue;
2500 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2501 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2503 wined3d_mutex_unlock();
2506 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2507 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2509 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2510 iface, start_slot, buffer_count, buffers);
2512 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2513 buffer_count, buffers);
2516 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2517 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2519 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2520 unsigned int i;
2522 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2523 iface, start_slot, view_count, views);
2525 wined3d_mutex_lock();
2526 for (i = 0; i < view_count; ++i)
2528 struct wined3d_shader_resource_view *wined3d_view;
2529 struct d3d_shader_resource_view *view_impl;
2531 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2532 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2534 views[i] = NULL;
2535 continue;
2538 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2539 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2541 wined3d_mutex_unlock();
2544 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2545 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2547 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2548 struct d3d11_domain_shader *shader_impl;
2549 struct wined3d_shader *wined3d_shader;
2551 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2552 iface, shader, class_instances, class_instance_count);
2554 if (class_instances || class_instance_count)
2555 FIXME("Dynamic linking not implemented yet.\n");
2556 if (class_instance_count)
2557 *class_instance_count = 0;
2559 wined3d_mutex_lock();
2560 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2562 wined3d_mutex_unlock();
2563 *shader = NULL;
2564 return;
2567 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2568 wined3d_mutex_unlock();
2569 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2572 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2573 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2575 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2576 unsigned int i;
2578 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2579 iface, start_slot, sampler_count, samplers);
2581 wined3d_mutex_lock();
2582 for (i = 0; i < sampler_count; ++i)
2584 struct wined3d_sampler *wined3d_sampler;
2585 struct d3d_sampler_state *sampler_impl;
2587 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2588 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2590 samplers[i] = NULL;
2591 continue;
2594 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2595 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2597 wined3d_mutex_unlock();
2600 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2601 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2603 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2604 iface, start_slot, buffer_count, buffers);
2606 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2607 buffer_count, buffers);
2610 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2611 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2613 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2614 unsigned int i;
2616 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2618 wined3d_mutex_lock();
2619 for (i = 0; i < view_count; ++i)
2621 struct wined3d_shader_resource_view *wined3d_view;
2622 struct d3d_shader_resource_view *view_impl;
2624 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2625 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2627 views[i] = NULL;
2628 continue;
2631 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2632 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2634 wined3d_mutex_unlock();
2637 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2638 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2640 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2641 unsigned int i;
2643 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2645 wined3d_mutex_lock();
2646 for (i = 0; i < view_count; ++i)
2648 struct wined3d_unordered_access_view *wined3d_view;
2649 struct d3d11_unordered_access_view *view_impl;
2651 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2652 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2654 views[i] = NULL;
2655 continue;
2658 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2659 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2661 wined3d_mutex_unlock();
2664 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2665 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2667 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2668 struct d3d11_compute_shader *shader_impl;
2669 struct wined3d_shader *wined3d_shader;
2671 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2672 iface, shader, class_instances, class_instance_count);
2674 if (class_instances || class_instance_count)
2675 FIXME("Dynamic linking not implemented yet.\n");
2676 if (class_instance_count)
2677 *class_instance_count = 0;
2679 wined3d_mutex_lock();
2680 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2682 wined3d_mutex_unlock();
2683 *shader = NULL;
2684 return;
2687 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2688 wined3d_mutex_unlock();
2689 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2692 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2693 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2695 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2696 unsigned int i;
2698 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2699 iface, start_slot, sampler_count, samplers);
2701 wined3d_mutex_lock();
2702 for (i = 0; i < sampler_count; ++i)
2704 struct wined3d_sampler *wined3d_sampler;
2705 struct d3d_sampler_state *sampler_impl;
2707 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2708 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2710 samplers[i] = NULL;
2711 continue;
2714 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2715 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2717 wined3d_mutex_unlock();
2720 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2721 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2723 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2724 iface, start_slot, buffer_count, buffers);
2726 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2727 buffer_count, buffers);
2730 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2732 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2734 TRACE("iface %p.\n", iface);
2736 wined3d_mutex_lock();
2737 wined3d_device_context_reset_state(context->wined3d_context);
2738 wined3d_mutex_unlock();
2741 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2743 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2745 TRACE("iface %p.\n", iface);
2747 wined3d_mutex_lock();
2748 wined3d_device_context_flush(context->wined3d_context);
2749 wined3d_mutex_unlock();
2752 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2754 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2756 TRACE("iface %p.\n", iface);
2758 return context->type;
2761 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2763 TRACE("iface %p.\n", iface);
2765 return 0;
2768 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2769 BOOL restore, ID3D11CommandList **command_list)
2771 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2772 struct d3d11_command_list *object;
2773 HRESULT hr;
2775 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2777 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2779 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2780 return DXGI_ERROR_INVALID_CALL;
2783 if (!(object = heap_alloc_zero(sizeof(*object))))
2784 return E_OUTOFMEMORY;
2786 wined3d_mutex_lock();
2788 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2789 !!restore, &object->wined3d_list)))
2791 WARN("Failed to record wined3d command list, hr %#x.\n", hr);
2792 heap_free(object);
2793 return hr;
2796 wined3d_mutex_unlock();
2798 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2799 object->refcount = 1;
2800 object->device = &context->device->ID3D11Device2_iface;
2801 wined3d_private_store_init(&object->private_store);
2803 ID3D11Device2_AddRef(object->device);
2805 TRACE("Created command list %p.\n", object);
2806 *command_list = &object->ID3D11CommandList_iface;
2808 return S_OK;
2811 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2812 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2813 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2815 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2816 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2817 struct wined3d_box wined3d_src_box;
2819 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2820 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2821 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2822 src_resource, src_subresource_idx, src_box, flags);
2824 if (!dst_resource || !src_resource)
2825 return;
2827 if (src_box)
2828 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2829 src_box->right, src_box->bottom, src_box->front, src_box->back);
2831 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2832 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2833 wined3d_mutex_lock();
2834 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2835 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2836 wined3d_mutex_unlock();
2839 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2840 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2841 UINT row_pitch, UINT depth_pitch, UINT flags)
2843 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2844 struct wined3d_resource *wined3d_resource;
2845 struct wined3d_box wined3d_box;
2847 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2848 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2850 if (box)
2851 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2852 box->front, box->back);
2854 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2855 wined3d_mutex_lock();
2856 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2857 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2858 wined3d_mutex_unlock();
2861 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2862 ID3D11Resource *resource)
2864 FIXME("iface %p, resource %p stub!\n", iface, resource);
2867 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2869 FIXME("iface %p, view %p stub!\n", iface, view);
2872 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2873 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2874 const UINT *num_constants)
2876 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2877 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2880 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2881 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2882 const UINT *num_constants)
2884 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2885 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2888 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2889 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2890 const UINT *num_constants)
2892 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2893 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2896 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2897 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2898 const UINT *num_constants)
2900 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2901 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2904 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2905 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2906 const 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_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2913 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2914 const UINT *num_constants)
2916 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2917 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2920 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2921 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2923 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2924 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2927 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2928 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2930 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2931 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2934 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2935 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2937 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2938 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2941 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2942 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2944 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2945 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2948 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2949 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2951 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2952 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2955 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2956 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2958 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2959 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2962 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2963 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2965 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2966 struct d3d_device_context_state *state_impl, *prev_impl;
2967 struct d3d_device *device = context->device;
2968 struct wined3d_state *wined3d_state;
2970 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2972 if (prev)
2973 *prev = NULL;
2975 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
2977 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
2978 return;
2981 if (!state)
2982 return;
2984 wined3d_mutex_lock();
2986 prev_impl = device->state;
2987 state_impl = impl_from_ID3DDeviceContextState(state);
2988 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2989 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2990 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
2992 if (prev)
2993 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2995 d3d_device_context_state_private_addref(state_impl);
2996 device->state = state_impl;
2997 d3d_device_context_state_private_release(prev_impl);
2999 if (d3d_device_is_d3d10_active(device))
3000 FIXME("D3D10 interface emulation not fully implemented yet!\n");
3001 wined3d_mutex_unlock();
3004 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
3005 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
3007 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
3010 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
3011 const D3D11_RECT *rects, UINT num_rects)
3013 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
3016 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
3018 /* IUnknown methods */
3019 d3d11_device_context_QueryInterface,
3020 d3d11_device_context_AddRef,
3021 d3d11_device_context_Release,
3022 /* ID3D11DeviceChild methods */
3023 d3d11_device_context_GetDevice,
3024 d3d11_device_context_GetPrivateData,
3025 d3d11_device_context_SetPrivateData,
3026 d3d11_device_context_SetPrivateDataInterface,
3027 /* ID3D11DeviceContext methods */
3028 d3d11_device_context_VSSetConstantBuffers,
3029 d3d11_device_context_PSSetShaderResources,
3030 d3d11_device_context_PSSetShader,
3031 d3d11_device_context_PSSetSamplers,
3032 d3d11_device_context_VSSetShader,
3033 d3d11_device_context_DrawIndexed,
3034 d3d11_device_context_Draw,
3035 d3d11_device_context_Map,
3036 d3d11_device_context_Unmap,
3037 d3d11_device_context_PSSetConstantBuffers,
3038 d3d11_device_context_IASetInputLayout,
3039 d3d11_device_context_IASetVertexBuffers,
3040 d3d11_device_context_IASetIndexBuffer,
3041 d3d11_device_context_DrawIndexedInstanced,
3042 d3d11_device_context_DrawInstanced,
3043 d3d11_device_context_GSSetConstantBuffers,
3044 d3d11_device_context_GSSetShader,
3045 d3d11_device_context_IASetPrimitiveTopology,
3046 d3d11_device_context_VSSetShaderResources,
3047 d3d11_device_context_VSSetSamplers,
3048 d3d11_device_context_Begin,
3049 d3d11_device_context_End,
3050 d3d11_device_context_GetData,
3051 d3d11_device_context_SetPredication,
3052 d3d11_device_context_GSSetShaderResources,
3053 d3d11_device_context_GSSetSamplers,
3054 d3d11_device_context_OMSetRenderTargets,
3055 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3056 d3d11_device_context_OMSetBlendState,
3057 d3d11_device_context_OMSetDepthStencilState,
3058 d3d11_device_context_SOSetTargets,
3059 d3d11_device_context_DrawAuto,
3060 d3d11_device_context_DrawIndexedInstancedIndirect,
3061 d3d11_device_context_DrawInstancedIndirect,
3062 d3d11_device_context_Dispatch,
3063 d3d11_device_context_DispatchIndirect,
3064 d3d11_device_context_RSSetState,
3065 d3d11_device_context_RSSetViewports,
3066 d3d11_device_context_RSSetScissorRects,
3067 d3d11_device_context_CopySubresourceRegion,
3068 d3d11_device_context_CopyResource,
3069 d3d11_device_context_UpdateSubresource,
3070 d3d11_device_context_CopyStructureCount,
3071 d3d11_device_context_ClearRenderTargetView,
3072 d3d11_device_context_ClearUnorderedAccessViewUint,
3073 d3d11_device_context_ClearUnorderedAccessViewFloat,
3074 d3d11_device_context_ClearDepthStencilView,
3075 d3d11_device_context_GenerateMips,
3076 d3d11_device_context_SetResourceMinLOD,
3077 d3d11_device_context_GetResourceMinLOD,
3078 d3d11_device_context_ResolveSubresource,
3079 d3d11_device_context_ExecuteCommandList,
3080 d3d11_device_context_HSSetShaderResources,
3081 d3d11_device_context_HSSetShader,
3082 d3d11_device_context_HSSetSamplers,
3083 d3d11_device_context_HSSetConstantBuffers,
3084 d3d11_device_context_DSSetShaderResources,
3085 d3d11_device_context_DSSetShader,
3086 d3d11_device_context_DSSetSamplers,
3087 d3d11_device_context_DSSetConstantBuffers,
3088 d3d11_device_context_CSSetShaderResources,
3089 d3d11_device_context_CSSetUnorderedAccessViews,
3090 d3d11_device_context_CSSetShader,
3091 d3d11_device_context_CSSetSamplers,
3092 d3d11_device_context_CSSetConstantBuffers,
3093 d3d11_device_context_VSGetConstantBuffers,
3094 d3d11_device_context_PSGetShaderResources,
3095 d3d11_device_context_PSGetShader,
3096 d3d11_device_context_PSGetSamplers,
3097 d3d11_device_context_VSGetShader,
3098 d3d11_device_context_PSGetConstantBuffers,
3099 d3d11_device_context_IAGetInputLayout,
3100 d3d11_device_context_IAGetVertexBuffers,
3101 d3d11_device_context_IAGetIndexBuffer,
3102 d3d11_device_context_GSGetConstantBuffers,
3103 d3d11_device_context_GSGetShader,
3104 d3d11_device_context_IAGetPrimitiveTopology,
3105 d3d11_device_context_VSGetShaderResources,
3106 d3d11_device_context_VSGetSamplers,
3107 d3d11_device_context_GetPredication,
3108 d3d11_device_context_GSGetShaderResources,
3109 d3d11_device_context_GSGetSamplers,
3110 d3d11_device_context_OMGetRenderTargets,
3111 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3112 d3d11_device_context_OMGetBlendState,
3113 d3d11_device_context_OMGetDepthStencilState,
3114 d3d11_device_context_SOGetTargets,
3115 d3d11_device_context_RSGetState,
3116 d3d11_device_context_RSGetViewports,
3117 d3d11_device_context_RSGetScissorRects,
3118 d3d11_device_context_HSGetShaderResources,
3119 d3d11_device_context_HSGetShader,
3120 d3d11_device_context_HSGetSamplers,
3121 d3d11_device_context_HSGetConstantBuffers,
3122 d3d11_device_context_DSGetShaderResources,
3123 d3d11_device_context_DSGetShader,
3124 d3d11_device_context_DSGetSamplers,
3125 d3d11_device_context_DSGetConstantBuffers,
3126 d3d11_device_context_CSGetShaderResources,
3127 d3d11_device_context_CSGetUnorderedAccessViews,
3128 d3d11_device_context_CSGetShader,
3129 d3d11_device_context_CSGetSamplers,
3130 d3d11_device_context_CSGetConstantBuffers,
3131 d3d11_device_context_ClearState,
3132 d3d11_device_context_Flush,
3133 d3d11_device_context_GetType,
3134 d3d11_device_context_GetContextFlags,
3135 d3d11_device_context_FinishCommandList,
3136 /* ID3D11DeviceContext1 methods */
3137 d3d11_device_context_CopySubresourceRegion1,
3138 d3d11_device_context_UpdateSubresource1,
3139 d3d11_device_context_DiscardResource,
3140 d3d11_device_context_DiscardView,
3141 d3d11_device_context_VSSetConstantBuffers1,
3142 d3d11_device_context_HSSetConstantBuffers1,
3143 d3d11_device_context_DSSetConstantBuffers1,
3144 d3d11_device_context_GSSetConstantBuffers1,
3145 d3d11_device_context_PSSetConstantBuffers1,
3146 d3d11_device_context_CSSetConstantBuffers1,
3147 d3d11_device_context_VSGetConstantBuffers1,
3148 d3d11_device_context_HSGetConstantBuffers1,
3149 d3d11_device_context_DSGetConstantBuffers1,
3150 d3d11_device_context_GSGetConstantBuffers1,
3151 d3d11_device_context_PSGetConstantBuffers1,
3152 d3d11_device_context_CSGetConstantBuffers1,
3153 d3d11_device_context_SwapDeviceContextState,
3154 d3d11_device_context_ClearView,
3155 d3d11_device_context_DiscardView1,
3158 /* ID3D11Multithread methods */
3160 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3162 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3165 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3166 REFIID iid, void **out)
3168 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3170 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3172 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3175 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3177 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3179 TRACE("iface %p.\n", iface);
3181 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3184 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3186 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3188 TRACE("iface %p.\n", iface);
3190 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3193 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3195 TRACE("iface %p.\n", iface);
3197 wined3d_mutex_lock();
3200 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3202 TRACE("iface %p.\n", iface);
3204 wined3d_mutex_unlock();
3207 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3208 ID3D11Multithread *iface, BOOL enable)
3210 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3212 return TRUE;
3215 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3217 FIXME("iface %p stub!\n", iface);
3219 return TRUE;
3222 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3224 d3d11_multithread_QueryInterface,
3225 d3d11_multithread_AddRef,
3226 d3d11_multithread_Release,
3227 d3d11_multithread_Enter,
3228 d3d11_multithread_Leave,
3229 d3d11_multithread_SetMultithreadProtected,
3230 d3d11_multithread_GetMultithreadProtected,
3233 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3234 D3D11_DEVICE_CONTEXT_TYPE type)
3236 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3237 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3238 context->refcount = 1;
3239 context->type = type;
3241 context->device = device;
3242 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3244 wined3d_private_store_init(&context->private_store);
3247 /* ID3D11Device methods */
3249 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3251 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3252 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3255 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3257 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3258 return IUnknown_AddRef(device->outer_unk);
3261 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3263 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3264 return IUnknown_Release(device->outer_unk);
3267 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3268 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3270 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3271 struct d3d_buffer *object;
3272 HRESULT hr;
3274 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3276 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3277 return hr;
3279 *buffer = &object->ID3D11Buffer_iface;
3281 return S_OK;
3284 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3285 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3287 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3288 struct d3d_texture1d *object;
3289 HRESULT hr;
3291 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3293 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3294 return hr;
3296 *texture = &object->ID3D11Texture1D_iface;
3298 return S_OK;
3301 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3302 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3304 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3305 struct d3d_texture2d *object;
3306 HRESULT hr;
3308 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3310 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3311 return hr;
3313 *texture = &object->ID3D11Texture2D_iface;
3315 return S_OK;
3318 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3319 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3321 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3322 struct d3d_texture3d *object;
3323 HRESULT hr;
3325 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3327 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3328 return hr;
3330 *texture = &object->ID3D11Texture3D_iface;
3332 return S_OK;
3335 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3336 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3338 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3339 struct d3d_shader_resource_view *object;
3340 HRESULT hr;
3342 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3344 if (!resource)
3345 return E_INVALIDARG;
3347 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3348 return hr;
3350 *view = &object->ID3D11ShaderResourceView_iface;
3352 return S_OK;
3355 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3356 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3358 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3359 struct d3d11_unordered_access_view *object;
3360 HRESULT hr;
3362 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3364 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3365 return hr;
3367 *view = &object->ID3D11UnorderedAccessView_iface;
3369 return S_OK;
3372 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3373 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3375 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3376 struct d3d_rendertarget_view *object;
3377 HRESULT hr;
3379 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3381 if (!resource)
3382 return E_INVALIDARG;
3384 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3385 return hr;
3387 *view = &object->ID3D11RenderTargetView_iface;
3389 return S_OK;
3392 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3393 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3395 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3396 struct d3d_depthstencil_view *object;
3397 HRESULT hr;
3399 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3401 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3402 return hr;
3404 *view = &object->ID3D11DepthStencilView_iface;
3406 return S_OK;
3409 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3410 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3411 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3413 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3414 struct d3d_input_layout *object;
3415 HRESULT hr;
3417 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3418 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3419 shader_byte_code_length, input_layout);
3421 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3422 shader_byte_code, shader_byte_code_length, &object)))
3423 return hr;
3425 *input_layout = &object->ID3D11InputLayout_iface;
3427 return S_OK;
3430 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3431 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3433 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3434 struct d3d_vertex_shader *object;
3435 HRESULT hr;
3437 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3438 iface, byte_code, byte_code_length, class_linkage, shader);
3440 if (class_linkage)
3441 FIXME("Class linkage is not implemented yet.\n");
3443 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3444 return hr;
3446 *shader = &object->ID3D11VertexShader_iface;
3448 return S_OK;
3451 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3452 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3454 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3455 struct d3d_geometry_shader *object;
3456 HRESULT hr;
3458 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3459 iface, byte_code, byte_code_length, class_linkage, shader);
3461 if (class_linkage)
3462 FIXME("Class linkage is not implemented yet.\n");
3464 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3465 NULL, 0, NULL, 0, 0, &object)))
3466 return hr;
3468 *shader = &object->ID3D11GeometryShader_iface;
3470 return S_OK;
3473 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3474 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3475 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3476 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3478 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3479 struct d3d_geometry_shader *object;
3480 HRESULT hr;
3482 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3483 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3484 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3485 rasterizer_stream, class_linkage, shader);
3487 if (class_linkage)
3488 FIXME("Class linkage is not implemented yet.\n");
3490 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3491 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3493 *shader = NULL;
3494 return hr;
3497 *shader = &object->ID3D11GeometryShader_iface;
3499 return hr;
3502 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3503 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3505 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3506 struct d3d_pixel_shader *object;
3507 HRESULT hr;
3509 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3510 iface, byte_code, byte_code_length, class_linkage, shader);
3512 if (class_linkage)
3513 FIXME("Class linkage is not implemented yet.\n");
3515 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3516 return hr;
3518 *shader = &object->ID3D11PixelShader_iface;
3520 return S_OK;
3523 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3524 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3526 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3527 struct d3d11_hull_shader *object;
3528 HRESULT hr;
3530 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3531 iface, byte_code, byte_code_length, class_linkage, shader);
3533 if (class_linkage)
3534 FIXME("Class linkage is not implemented yet.\n");
3536 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3537 return hr;
3539 *shader = &object->ID3D11HullShader_iface;
3541 return S_OK;
3544 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3545 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3547 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3548 struct d3d11_domain_shader *object;
3549 HRESULT hr;
3551 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3552 iface, byte_code, byte_code_length, class_linkage, shader);
3554 if (class_linkage)
3555 FIXME("Class linkage is not implemented yet.\n");
3557 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3558 return hr;
3560 *shader = &object->ID3D11DomainShader_iface;
3562 return S_OK;
3565 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3566 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3568 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3569 struct d3d11_compute_shader *object;
3570 HRESULT hr;
3572 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3573 iface, byte_code, byte_code_length, class_linkage, shader);
3575 if (class_linkage)
3576 FIXME("Class linkage is not implemented yet.\n");
3578 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3579 return hr;
3581 *shader = &object->ID3D11ComputeShader_iface;
3583 return S_OK;
3586 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3587 ID3D11ClassLinkage **class_linkage)
3589 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3590 struct d3d11_class_linkage *object;
3591 HRESULT hr;
3593 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3595 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3596 return hr;
3598 *class_linkage = &object->ID3D11ClassLinkage_iface;
3600 return S_OK;
3603 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3604 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3606 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3607 struct d3d_blend_state *object;
3608 HRESULT hr;
3610 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3612 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3613 return hr;
3615 *blend_state = &object->ID3D11BlendState_iface;
3617 return S_OK;
3620 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3621 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3623 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3624 struct d3d_depthstencil_state *object;
3625 HRESULT hr;
3627 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3629 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3630 return hr;
3632 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3634 return S_OK;
3637 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3638 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3640 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3641 struct d3d_rasterizer_state *object;
3642 HRESULT hr;
3644 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3646 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3647 return hr;
3649 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3651 return S_OK;
3654 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3655 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3657 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3658 struct d3d_sampler_state *object;
3659 HRESULT hr;
3661 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3663 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3664 return hr;
3666 *sampler_state = &object->ID3D11SamplerState_iface;
3668 return S_OK;
3671 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3672 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3674 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3675 struct d3d_query *object;
3676 HRESULT hr;
3678 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3680 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3681 return hr;
3683 if (query)
3685 *query = &object->ID3D11Query_iface;
3686 return S_OK;
3689 ID3D11Query_Release(&object->ID3D11Query_iface);
3690 return S_FALSE;
3693 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3694 ID3D11Predicate **predicate)
3696 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3697 struct d3d_query *object;
3698 HRESULT hr;
3700 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3702 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3703 return hr;
3705 if (predicate)
3707 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3708 return S_OK;
3711 ID3D11Query_Release(&object->ID3D11Query_iface);
3712 return S_FALSE;
3715 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3716 ID3D11Counter **counter)
3718 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3720 return E_NOTIMPL;
3723 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3724 UINT flags, struct d3d11_device_context **context)
3726 struct d3d11_device_context *object;
3727 HRESULT hr;
3729 if (flags)
3730 FIXME("Ignoring flags %#x.\n", flags);
3732 if (!(object = heap_alloc_zero(sizeof(*object))))
3733 return E_OUTOFMEMORY;
3734 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3736 wined3d_mutex_lock();
3737 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3739 WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
3740 heap_free(object);
3741 wined3d_mutex_unlock();
3742 return hr;
3744 wined3d_mutex_unlock();
3746 TRACE("Created deferred context %p.\n", object);
3747 *context = object;
3749 return S_OK;
3752 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3753 ID3D11DeviceContext **context)
3755 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3756 struct d3d11_device_context *object;
3757 HRESULT hr;
3759 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3761 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3762 return hr;
3764 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3765 return S_OK;
3768 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3769 void **out)
3771 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3773 return E_NOTIMPL;
3776 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3777 UINT *format_support)
3779 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3780 struct wined3d_device_creation_parameters params;
3781 struct wined3d_adapter *wined3d_adapter;
3782 enum wined3d_format_id wined3d_format;
3783 D3D_FEATURE_LEVEL feature_level;
3784 struct wined3d *wined3d;
3785 unsigned int i;
3787 static const struct
3789 enum wined3d_resource_type rtype;
3790 unsigned int bind_flags;
3791 unsigned int usage;
3792 D3D11_FORMAT_SUPPORT flag;
3794 flag_mapping[] =
3796 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3797 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3798 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3799 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3800 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3801 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3802 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3803 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3804 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3805 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3807 HRESULT hr;
3809 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3811 wined3d_format = wined3dformat_from_dxgi_format(format);
3812 if (format && !wined3d_format)
3814 WARN("Invalid format %#x.\n", format);
3815 *format_support = 0;
3816 return E_FAIL;
3819 *format_support = 0;
3821 wined3d_mutex_lock();
3822 feature_level = device->state->feature_level;
3823 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3824 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3825 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3826 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3828 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3829 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3830 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3831 continue;
3832 if (hr != WINED3D_OK)
3834 WARN("Failed to check device format support, hr %#x.\n", hr);
3835 wined3d_mutex_unlock();
3836 return E_FAIL;
3839 *format_support |= flag_mapping[i].flag;
3841 wined3d_mutex_unlock();
3843 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3844 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3846 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3847 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3849 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3850 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3851 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3853 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3854 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3856 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3858 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3859 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3861 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3862 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3866 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3867 * support multisample. */
3868 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3869 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3870 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3871 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3873 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3874 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3875 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3878 return S_OK;
3881 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3882 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3884 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3885 struct wined3d_device_creation_parameters params;
3886 struct wined3d_adapter *wined3d_adapter;
3887 struct wined3d *wined3d;
3888 HRESULT hr;
3890 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3891 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3893 if (!quality_level_count)
3894 return E_INVALIDARG;
3896 *quality_level_count = 0;
3898 if (!sample_count)
3899 return E_FAIL;
3900 if (sample_count == 1)
3902 *quality_level_count = 1;
3903 return S_OK;
3905 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3906 return E_FAIL;
3908 wined3d_mutex_lock();
3909 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3910 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3911 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3912 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3913 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3914 wined3d_mutex_unlock();
3916 if (hr == WINED3DERR_INVALIDCALL)
3917 return E_INVALIDARG;
3918 if (hr == WINED3DERR_NOTAVAILABLE)
3919 return S_OK;
3920 return hr;
3923 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3925 FIXME("iface %p, info %p stub!\n", iface, info);
3928 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3929 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3930 char *units, UINT *units_length, char *description, UINT *description_length)
3932 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3933 "units %p, units_length %p, description %p, description_length %p stub!\n",
3934 iface, desc, type, active_counter_count, name, name_length,
3935 units, units_length, description, description_length);
3937 return E_NOTIMPL;
3940 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3941 void *feature_support_data, UINT feature_support_data_size)
3943 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3944 struct wined3d_caps wined3d_caps;
3945 HRESULT hr;
3947 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3948 iface, feature, feature_support_data, feature_support_data_size);
3950 switch (feature)
3952 case D3D11_FEATURE_THREADING:
3954 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3955 if (feature_support_data_size != sizeof(*threading_data))
3957 WARN("Invalid data size.\n");
3958 return E_INVALIDARG;
3961 /* We lie about the threading support to make Tomb Raider 2013 and
3962 * Deus Ex: Human Revolution happy. */
3963 FIXME("Returning fake threading support data.\n");
3964 threading_data->DriverConcurrentCreates = TRUE;
3965 threading_data->DriverCommandLists = TRUE;
3966 return S_OK;
3969 case D3D11_FEATURE_DOUBLES:
3971 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3972 if (feature_support_data_size != sizeof(*doubles_data))
3974 WARN("Invalid data size.\n");
3975 return E_INVALIDARG;
3978 wined3d_mutex_lock();
3979 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3980 wined3d_mutex_unlock();
3981 if (FAILED(hr))
3983 WARN("Failed to get device caps, hr %#x.\n", hr);
3984 return hr;
3987 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3988 return S_OK;
3991 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3993 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3994 if (feature_support_data_size != sizeof(*options))
3996 WARN("Invalid data size.\n");
3997 return E_INVALIDARG;
4000 wined3d_mutex_lock();
4001 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4002 wined3d_mutex_unlock();
4003 if (FAILED(hr))
4005 WARN("Failed to get device caps, hr %#x.\n", hr);
4006 return hr;
4009 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
4010 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4011 return S_OK;
4014 case D3D11_FEATURE_D3D11_OPTIONS:
4016 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4017 if (feature_support_data_size != sizeof(*options))
4019 WARN("Invalid data size.\n");
4020 return E_INVALIDARG;
4023 FIXME("Returning fake Options support data.\n");
4024 options->OutputMergerLogicOp = FALSE;
4025 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4026 options->DiscardAPIsSeenByDriver = FALSE;
4027 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4028 options->ClearView = FALSE;
4029 options->CopyWithOverlap = FALSE;
4030 options->ConstantBufferPartialUpdate = FALSE;
4031 options->ConstantBufferOffsetting = FALSE;
4032 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
4033 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
4034 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4035 options->SAD4ShaderInstructions = FALSE;
4036 options->ExtendedDoublesShaderInstructions = FALSE;
4037 options->ExtendedResourceSharing = FALSE;
4038 return S_OK;
4041 case D3D11_FEATURE_D3D11_OPTIONS1:
4043 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4044 if (feature_support_data_size != sizeof(*options))
4046 WARN("Invalid data size.\n");
4047 return E_INVALIDARG;
4050 FIXME("Returning fake Options1 support data.\n");
4051 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4052 options->MinMaxFiltering = FALSE;
4053 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4054 options->MapOnDefaultBuffers = FALSE;
4055 return S_OK;
4058 case D3D11_FEATURE_D3D11_OPTIONS3:
4060 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4061 if (feature_support_data_size != sizeof(*options))
4063 WARN("Invalid data size.\n");
4064 return E_INVALIDARG;
4067 wined3d_mutex_lock();
4068 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4069 wined3d_mutex_unlock();
4070 if (FAILED(hr))
4072 WARN("Failed to get device caps, hr %#x.\n", hr);
4073 return hr;
4076 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4077 = wined3d_caps.viewport_array_index_any_shader;
4078 return S_OK;
4081 case D3D11_FEATURE_ARCHITECTURE_INFO:
4083 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4084 if (feature_support_data_size != sizeof(*options))
4086 WARN("Invalid data size.\n");
4087 return E_INVALIDARG;
4090 FIXME("Returning fake data architecture info.\n");
4091 options->TileBasedDeferredRenderer = FALSE;
4092 return S_OK;
4095 default:
4096 FIXME("Unhandled feature %#x.\n", feature);
4097 return E_NOTIMPL;
4101 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4102 UINT *data_size, void *data)
4104 IDXGIDevice *dxgi_device;
4105 HRESULT hr;
4107 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4109 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4110 return hr;
4111 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4112 IDXGIDevice_Release(dxgi_device);
4114 return hr;
4117 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4118 UINT data_size, const void *data)
4120 IDXGIDevice *dxgi_device;
4121 HRESULT hr;
4123 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4125 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4126 return hr;
4127 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4128 IDXGIDevice_Release(dxgi_device);
4130 return hr;
4133 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4134 const IUnknown *data)
4136 IDXGIDevice *dxgi_device;
4137 HRESULT hr;
4139 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4141 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4142 return hr;
4143 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4144 IDXGIDevice_Release(dxgi_device);
4146 return hr;
4149 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4151 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4153 TRACE("iface %p.\n", iface);
4155 return device->state->feature_level;
4158 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4160 FIXME("iface %p stub!\n", iface);
4162 return 0;
4165 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4167 WARN("iface %p stub!\n", iface);
4169 return S_OK;
4172 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4173 ID3D11DeviceContext **immediate_context)
4175 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4177 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4179 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4180 ID3D11DeviceContext_AddRef(*immediate_context);
4183 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4185 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4187 return E_NOTIMPL;
4190 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4192 FIXME("iface %p stub!\n", iface);
4194 return 0;
4197 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4198 ID3D11DeviceContext1 **immediate_context)
4200 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4202 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4204 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4205 ID3D11DeviceContext1_AddRef(*immediate_context);
4208 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4209 ID3D11DeviceContext1 **context)
4211 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4212 struct d3d11_device_context *object;
4213 HRESULT hr;
4215 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4217 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4218 return hr;
4220 *context = &object->ID3D11DeviceContext1_iface;
4221 return S_OK;
4224 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4225 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4227 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4229 return E_NOTIMPL;
4232 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4233 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4235 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4237 return E_NOTIMPL;
4240 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4241 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4242 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4244 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4245 struct d3d_device_context_state *state_impl;
4246 struct wined3d_state *wined3d_state;
4247 D3D_FEATURE_LEVEL feature_level;
4248 HRESULT hr = E_INVALIDARG;
4250 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4251 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4252 iface, flags, feature_levels, feature_level_count,
4253 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4255 if (flags)
4256 FIXME("Ignoring flags %#x.\n", flags);
4258 wined3d_mutex_lock();
4260 if (!feature_level_count)
4261 goto fail;
4263 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4264 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4265 goto fail;
4266 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4268 if (chosen_feature_level)
4269 *chosen_feature_level = feature_level;
4271 if (!state)
4273 wined3d_state_destroy(wined3d_state);
4274 wined3d_mutex_unlock();
4275 return S_FALSE;
4278 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4280 wined3d_state_destroy(wined3d_state);
4281 hr = E_OUTOFMEMORY;
4282 goto fail;
4285 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4286 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4288 wined3d_state_destroy(wined3d_state);
4289 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4290 hr = E_FAIL;
4291 goto fail;
4294 *state = &state_impl->ID3DDeviceContextState_iface;
4295 device->d3d11_only = FALSE;
4296 wined3d_mutex_unlock();
4298 return S_OK;
4300 fail:
4301 wined3d_mutex_unlock();
4302 if (chosen_feature_level)
4303 *chosen_feature_level = 0;
4304 if (state)
4305 *state = NULL;
4306 return hr;
4309 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4310 REFIID iid, void **resource)
4312 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4314 return E_NOTIMPL;
4317 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4318 DWORD access, REFIID iid, void **resource)
4320 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4321 debugstr_guid(iid), resource);
4323 return E_NOTIMPL;
4326 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4327 ID3D11DeviceContext2 **context)
4329 FIXME("iface %p, context %p stub!\n", iface, context);
4332 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4333 UINT flags, ID3D11DeviceContext2 **context)
4335 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4337 return E_NOTIMPL;
4340 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4341 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4342 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4343 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4345 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4346 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4347 iface, resource, tile_count, mip_desc, tile_shape,
4348 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4351 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4352 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4354 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4355 iface, format, sample_count, flags, quality_level_count);
4357 return E_NOTIMPL;
4360 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4362 /* IUnknown methods */
4363 d3d11_device_QueryInterface,
4364 d3d11_device_AddRef,
4365 d3d11_device_Release,
4366 /* ID3D11Device methods */
4367 d3d11_device_CreateBuffer,
4368 d3d11_device_CreateTexture1D,
4369 d3d11_device_CreateTexture2D,
4370 d3d11_device_CreateTexture3D,
4371 d3d11_device_CreateShaderResourceView,
4372 d3d11_device_CreateUnorderedAccessView,
4373 d3d11_device_CreateRenderTargetView,
4374 d3d11_device_CreateDepthStencilView,
4375 d3d11_device_CreateInputLayout,
4376 d3d11_device_CreateVertexShader,
4377 d3d11_device_CreateGeometryShader,
4378 d3d11_device_CreateGeometryShaderWithStreamOutput,
4379 d3d11_device_CreatePixelShader,
4380 d3d11_device_CreateHullShader,
4381 d3d11_device_CreateDomainShader,
4382 d3d11_device_CreateComputeShader,
4383 d3d11_device_CreateClassLinkage,
4384 d3d11_device_CreateBlendState,
4385 d3d11_device_CreateDepthStencilState,
4386 d3d11_device_CreateRasterizerState,
4387 d3d11_device_CreateSamplerState,
4388 d3d11_device_CreateQuery,
4389 d3d11_device_CreatePredicate,
4390 d3d11_device_CreateCounter,
4391 d3d11_device_CreateDeferredContext,
4392 d3d11_device_OpenSharedResource,
4393 d3d11_device_CheckFormatSupport,
4394 d3d11_device_CheckMultisampleQualityLevels,
4395 d3d11_device_CheckCounterInfo,
4396 d3d11_device_CheckCounter,
4397 d3d11_device_CheckFeatureSupport,
4398 d3d11_device_GetPrivateData,
4399 d3d11_device_SetPrivateData,
4400 d3d11_device_SetPrivateDataInterface,
4401 d3d11_device_GetFeatureLevel,
4402 d3d11_device_GetCreationFlags,
4403 d3d11_device_GetDeviceRemovedReason,
4404 d3d11_device_GetImmediateContext,
4405 d3d11_device_SetExceptionMode,
4406 d3d11_device_GetExceptionMode,
4407 /* ID3D11Device1 methods */
4408 d3d11_device_GetImmediateContext1,
4409 d3d11_device_CreateDeferredContext1,
4410 d3d11_device_CreateBlendState1,
4411 d3d11_device_CreateRasterizerState1,
4412 d3d11_device_CreateDeviceContextState,
4413 d3d11_device_OpenSharedResource1,
4414 d3d11_device_OpenSharedResourceByName,
4415 /* ID3D11Device2 methods */
4416 d3d11_device_GetImmediateContext2,
4417 d3d11_device_CreateDeferredContext2,
4418 d3d11_device_GetResourceTiling,
4419 d3d11_device_CheckMultisampleQualityLevels1,
4422 /* Inner IUnknown methods */
4424 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4426 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4429 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4431 struct d3d_device *device = impl_from_IUnknown(iface);
4433 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4435 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4436 || IsEqualGUID(riid, &IID_ID3D11Device1)
4437 || IsEqualGUID(riid, &IID_ID3D11Device)
4438 || IsEqualGUID(riid, &IID_IUnknown))
4440 *out = &device->ID3D11Device2_iface;
4442 else if (!device->d3d11_only
4443 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4444 || IsEqualGUID(riid, &IID_ID3D10Device)))
4446 *out = &device->ID3D10Device1_iface;
4448 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4450 *out = &device->ID3D10Multithread_iface;
4452 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4454 *out = &device->IWineDXGIDeviceParent_iface;
4456 else
4458 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4459 *out = NULL;
4460 return E_NOINTERFACE;
4463 IUnknown_AddRef((IUnknown *)*out);
4464 return S_OK;
4467 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4469 struct d3d_device *device = impl_from_IUnknown(iface);
4470 ULONG refcount = InterlockedIncrement(&device->refcount);
4472 TRACE("%p increasing refcount to %u.\n", device, refcount);
4474 return refcount;
4477 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4479 struct d3d_device *device = impl_from_IUnknown(iface);
4480 ULONG refcount = InterlockedDecrement(&device->refcount);
4481 unsigned int i;
4483 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4485 if (!refcount)
4487 if (device->state)
4488 d3d_device_context_state_private_release(device->state);
4489 for (i = 0; i < device->context_state_count; ++i)
4491 d3d_device_context_state_remove_entry(device->context_states[i], device);
4493 heap_free(device->context_states);
4494 d3d11_device_context_cleanup(&device->immediate_context);
4495 if (device->wined3d_device)
4497 wined3d_mutex_lock();
4498 wined3d_device_decref(device->wined3d_device);
4499 wined3d_mutex_unlock();
4501 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4502 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4503 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4504 wine_rb_destroy(&device->blend_states, NULL, NULL);
4507 return refcount;
4510 /* IUnknown methods */
4512 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4513 void **out)
4515 struct d3d_device *device = impl_from_ID3D10Device(iface);
4516 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4519 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4521 struct d3d_device *device = impl_from_ID3D10Device(iface);
4522 return IUnknown_AddRef(device->outer_unk);
4525 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4527 struct d3d_device *device = impl_from_ID3D10Device(iface);
4528 return IUnknown_Release(device->outer_unk);
4531 /* ID3D10Device methods */
4533 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4534 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4536 struct d3d_device *device = impl_from_ID3D10Device(iface);
4537 unsigned int i;
4539 wined3d_mutex_lock();
4540 for (i = 0; i < buffer_count; ++i)
4542 struct wined3d_buffer *wined3d_buffer;
4543 struct d3d_buffer *buffer_impl;
4545 if (!(wined3d_buffer = wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4546 type, start_slot + i)))
4548 buffers[i] = NULL;
4549 continue;
4552 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4553 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4554 ID3D10Buffer_AddRef(buffers[i]);
4556 wined3d_mutex_unlock();
4559 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4560 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4562 struct d3d_device *device = impl_from_ID3D10Device(iface);
4563 unsigned int i;
4565 wined3d_mutex_lock();
4566 for (i = 0; i < buffer_count; ++i)
4568 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4570 wined3d_device_context_set_constant_buffer(device->immediate_context.wined3d_context, type, start_slot + i,
4571 buffer ? buffer->wined3d_buffer : NULL);
4573 wined3d_mutex_unlock();
4576 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4577 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4579 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4580 iface, start_slot, buffer_count, buffers);
4582 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4583 buffer_count, buffers);
4586 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4587 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4589 struct d3d_device *device = impl_from_ID3D10Device(iface);
4590 unsigned int i;
4592 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4593 iface, start_slot, view_count, views);
4595 wined3d_mutex_lock();
4596 for (i = 0; i < view_count; ++i)
4598 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4600 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4601 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, view ? view->wined3d_view : NULL);
4603 wined3d_mutex_unlock();
4606 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4607 ID3D10PixelShader *shader)
4609 struct d3d_device *device = impl_from_ID3D10Device(iface);
4610 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4612 TRACE("iface %p, shader %p\n", iface, shader);
4614 wined3d_mutex_lock();
4615 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4616 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4617 wined3d_mutex_unlock();
4620 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4621 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4623 struct d3d_device *device = impl_from_ID3D10Device(iface);
4624 unsigned int i;
4626 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4627 iface, start_slot, sampler_count, samplers);
4629 wined3d_mutex_lock();
4630 for (i = 0; i < sampler_count; ++i)
4632 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4634 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4635 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4637 wined3d_mutex_unlock();
4640 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4641 ID3D10VertexShader *shader)
4643 struct d3d_device *device = impl_from_ID3D10Device(iface);
4644 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4646 TRACE("iface %p, shader %p\n", iface, shader);
4648 wined3d_mutex_lock();
4649 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4650 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4651 wined3d_mutex_unlock();
4654 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4655 UINT start_index_location, INT base_vertex_location)
4657 struct d3d_device *device = impl_from_ID3D10Device(iface);
4659 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4660 iface, index_count, start_index_location, base_vertex_location);
4662 wined3d_mutex_lock();
4663 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4664 base_vertex_location, start_index_location, index_count, 0, 0);
4665 wined3d_mutex_unlock();
4668 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4669 UINT start_vertex_location)
4671 struct d3d_device *device = impl_from_ID3D10Device(iface);
4673 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4674 iface, vertex_count, start_vertex_location);
4676 wined3d_mutex_lock();
4677 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4678 wined3d_mutex_unlock();
4681 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4682 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4684 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4685 iface, start_slot, buffer_count, buffers);
4687 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4688 buffer_count, buffers);
4691 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4692 ID3D10InputLayout *input_layout)
4694 struct d3d_device *device = impl_from_ID3D10Device(iface);
4695 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4697 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4699 wined3d_mutex_lock();
4700 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4701 layout ? layout->wined3d_decl : NULL);
4702 wined3d_mutex_unlock();
4705 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4706 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4708 struct d3d_device *device = impl_from_ID3D10Device(iface);
4709 unsigned int i;
4711 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4712 iface, start_slot, buffer_count, buffers, strides, offsets);
4714 wined3d_mutex_lock();
4715 for (i = 0; i < buffer_count; ++i)
4717 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4719 wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
4720 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
4722 wined3d_mutex_unlock();
4725 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4726 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4728 struct d3d_device *device = impl_from_ID3D10Device(iface);
4729 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4731 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4732 iface, buffer, debug_dxgi_format(format), offset);
4734 wined3d_mutex_lock();
4735 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4736 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4737 wined3dformat_from_dxgi_format(format), offset);
4738 wined3d_mutex_unlock();
4741 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4742 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4743 INT base_vertex_location, UINT start_instance_location)
4745 struct d3d_device *device = impl_from_ID3D10Device(iface);
4747 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4748 "base_vertex_location %d, start_instance_location %u.\n",
4749 iface, instance_index_count, instance_count, start_index_location,
4750 base_vertex_location, start_instance_location);
4752 wined3d_mutex_lock();
4753 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4754 start_index_location, instance_index_count, start_instance_location, instance_count);
4755 wined3d_mutex_unlock();
4758 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4759 UINT instance_vertex_count, UINT instance_count,
4760 UINT start_vertex_location, UINT start_instance_location)
4762 struct d3d_device *device = impl_from_ID3D10Device(iface);
4764 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4765 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4766 start_vertex_location, start_instance_location);
4768 wined3d_mutex_lock();
4769 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4770 instance_vertex_count, start_instance_location, instance_count);
4771 wined3d_mutex_unlock();
4774 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4775 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4777 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4778 iface, start_slot, buffer_count, buffers);
4780 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4781 buffer_count, buffers);
4784 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4786 struct d3d_device *device = impl_from_ID3D10Device(iface);
4787 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4789 TRACE("iface %p, shader %p.\n", iface, shader);
4791 wined3d_mutex_lock();
4792 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4793 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4794 wined3d_mutex_unlock();
4797 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4798 D3D10_PRIMITIVE_TOPOLOGY topology)
4800 struct d3d_device *device = impl_from_ID3D10Device(iface);
4802 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4804 wined3d_mutex_lock();
4805 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4806 (enum wined3d_primitive_type)topology, 0);
4807 wined3d_mutex_unlock();
4810 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4811 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4813 struct d3d_device *device = impl_from_ID3D10Device(iface);
4814 unsigned int i;
4816 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4817 iface, start_slot, view_count, views);
4819 wined3d_mutex_lock();
4820 for (i = 0; i < view_count; ++i)
4822 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4824 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4825 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, view ? view->wined3d_view : NULL);
4827 wined3d_mutex_unlock();
4830 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4831 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4833 struct d3d_device *device = impl_from_ID3D10Device(iface);
4834 unsigned int i;
4836 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4837 iface, start_slot, sampler_count, samplers);
4839 wined3d_mutex_lock();
4840 for (i = 0; i < sampler_count; ++i)
4842 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4844 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4845 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4847 wined3d_mutex_unlock();
4850 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4852 struct d3d_device *device = impl_from_ID3D10Device(iface);
4853 struct d3d_query *query;
4855 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4857 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4858 wined3d_mutex_lock();
4859 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4860 query ? query->wined3d_query : NULL, value);
4861 wined3d_mutex_unlock();
4864 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4865 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4867 struct d3d_device *device = impl_from_ID3D10Device(iface);
4868 unsigned int i;
4870 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4871 iface, start_slot, view_count, views);
4873 wined3d_mutex_lock();
4874 for (i = 0; i < view_count; ++i)
4876 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4878 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4879 WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i, view ? view->wined3d_view : NULL);
4881 wined3d_mutex_unlock();
4884 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4885 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4887 struct d3d_device *device = impl_from_ID3D10Device(iface);
4888 unsigned int i;
4890 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4891 iface, start_slot, sampler_count, samplers);
4893 wined3d_mutex_lock();
4894 for (i = 0; i < sampler_count; ++i)
4896 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4898 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
4899 start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4901 wined3d_mutex_unlock();
4904 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4905 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4906 ID3D10DepthStencilView *depth_stencil_view)
4908 struct d3d_device *device = impl_from_ID3D10Device(iface);
4909 struct d3d_depthstencil_view *dsv;
4910 unsigned int i;
4912 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4913 iface, render_target_view_count, render_target_views, depth_stencil_view);
4915 wined3d_mutex_lock();
4916 for (i = 0; i < render_target_view_count; ++i)
4918 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4920 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
4921 rtv ? rtv->wined3d_view : NULL, FALSE);
4923 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4925 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
4928 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4929 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4930 dsv ? dsv->wined3d_view : NULL);
4931 wined3d_mutex_unlock();
4934 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4935 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4937 struct d3d_device *device = impl_from_ID3D10Device(iface);
4938 struct d3d_blend_state *blend_state_object;
4940 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4941 iface, blend_state, debug_float4(blend_factor), sample_mask);
4943 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4944 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4945 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4948 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4949 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4951 struct d3d_device *device = impl_from_ID3D10Device(iface);
4952 struct d3d_depthstencil_state *ds_state_object;
4954 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4955 iface, depth_stencil_state, stencil_ref);
4957 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4958 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4959 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4962 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4963 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4965 struct d3d_device *device = impl_from_ID3D10Device(iface);
4966 unsigned int count, i;
4968 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4970 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4971 wined3d_mutex_lock();
4972 for (i = 0; i < count; ++i)
4974 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4976 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i,
4977 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4980 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4982 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i, NULL, 0);
4984 wined3d_mutex_unlock();
4987 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4989 FIXME("iface %p stub!\n", iface);
4992 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4994 struct d3d_device *device = impl_from_ID3D10Device(iface);
4995 struct d3d_rasterizer_state *rasterizer_state_object;
4997 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4999 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5000 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5001 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
5004 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
5005 UINT viewport_count, const D3D10_VIEWPORT *viewports)
5007 struct d3d_device *device = impl_from_ID3D10Device(iface);
5008 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5009 unsigned int i;
5011 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5013 if (viewport_count > ARRAY_SIZE(wined3d_vp))
5014 return;
5016 for (i = 0; i < viewport_count; ++i)
5018 wined3d_vp[i].x = viewports[i].TopLeftX;
5019 wined3d_vp[i].y = viewports[i].TopLeftY;
5020 wined3d_vp[i].width = viewports[i].Width;
5021 wined3d_vp[i].height = viewports[i].Height;
5022 wined3d_vp[i].min_z = viewports[i].MinDepth;
5023 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5026 wined3d_mutex_lock();
5027 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5028 wined3d_mutex_unlock();
5031 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
5032 UINT rect_count, const D3D10_RECT *rects)
5034 struct d3d_device *device = impl_from_ID3D10Device(iface);
5036 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5038 if (rect_count > WINED3D_MAX_VIEWPORTS)
5039 return;
5041 wined3d_mutex_lock();
5042 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5043 wined3d_mutex_unlock();
5046 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5047 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5048 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5050 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5051 struct d3d_device *device = impl_from_ID3D10Device(iface);
5052 struct wined3d_box wined3d_src_box;
5054 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5055 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5056 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5057 src_resource, src_subresource_idx, src_box);
5059 if (!dst_resource || !src_resource)
5060 return;
5062 if (src_box)
5063 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5064 src_box->right, src_box->bottom, src_box->front, src_box->back);
5066 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5067 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5068 wined3d_mutex_lock();
5069 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5070 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5071 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5072 wined3d_mutex_unlock();
5075 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5076 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5078 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5079 struct d3d_device *device = impl_from_ID3D10Device(iface);
5081 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5083 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5084 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5085 wined3d_mutex_lock();
5086 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5087 wined3d_dst_resource, wined3d_src_resource);
5088 wined3d_mutex_unlock();
5091 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5092 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5093 const void *data, UINT row_pitch, UINT depth_pitch)
5095 struct d3d_device *device = impl_from_ID3D10Device(iface);
5096 ID3D11Resource *d3d11_resource;
5098 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5099 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5101 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5102 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5103 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5104 ID3D11Resource_Release(d3d11_resource);
5107 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5108 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5110 struct d3d_device *device = impl_from_ID3D10Device(iface);
5111 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5112 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5113 HRESULT hr;
5115 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5116 iface, render_target_view, debug_float4(color_rgba));
5118 if (!view)
5119 return;
5121 wined3d_mutex_lock();
5122 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5123 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5124 ERR("Failed to clear view, hr %#x.\n", hr);
5125 wined3d_mutex_unlock();
5128 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5129 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5131 struct d3d_device *device = impl_from_ID3D10Device(iface);
5132 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5133 DWORD wined3d_flags;
5134 HRESULT hr;
5136 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5137 iface, depth_stencil_view, flags, depth, stencil);
5139 if (!view)
5140 return;
5142 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5144 wined3d_mutex_lock();
5145 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5146 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5147 ERR("Failed to clear view, hr %#x.\n", hr);
5148 wined3d_mutex_unlock();
5151 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5152 ID3D10ShaderResourceView *view)
5154 struct d3d_device *device = impl_from_ID3D10Device(iface);
5155 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5157 TRACE("iface %p, view %p.\n", iface, view);
5159 wined3d_mutex_lock();
5160 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5161 wined3d_mutex_unlock();
5164 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5165 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5166 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5168 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5169 struct d3d_device *device = impl_from_ID3D10Device(iface);
5170 enum wined3d_format_id wined3d_format;
5172 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5173 "src_resource %p, src_subresource_idx %u, format %s.\n",
5174 iface, dst_resource, dst_subresource_idx,
5175 src_resource, src_subresource_idx, debug_dxgi_format(format));
5177 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5178 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5179 wined3d_format = wined3dformat_from_dxgi_format(format);
5180 wined3d_mutex_lock();
5181 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5182 wined3d_dst_resource, dst_subresource_idx,
5183 wined3d_src_resource, src_subresource_idx, wined3d_format);
5184 wined3d_mutex_unlock();
5187 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5188 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5190 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5191 iface, start_slot, buffer_count, buffers);
5193 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5194 buffers);
5197 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5198 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5200 struct d3d_device *device = impl_from_ID3D10Device(iface);
5201 unsigned int i;
5203 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5204 iface, start_slot, view_count, views);
5206 wined3d_mutex_lock();
5207 for (i = 0; i < view_count; ++i)
5209 struct wined3d_shader_resource_view *wined3d_view;
5210 struct d3d_shader_resource_view *view_impl;
5212 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5213 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5215 views[i] = NULL;
5216 continue;
5219 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5220 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5221 ID3D10ShaderResourceView_AddRef(views[i]);
5223 wined3d_mutex_unlock();
5226 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5228 struct d3d_device *device = impl_from_ID3D10Device(iface);
5229 struct d3d_pixel_shader *shader_impl;
5230 struct wined3d_shader *wined3d_shader;
5232 TRACE("iface %p, shader %p.\n", iface, shader);
5234 wined3d_mutex_lock();
5235 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5236 WINED3D_SHADER_TYPE_PIXEL)))
5238 wined3d_mutex_unlock();
5239 *shader = NULL;
5240 return;
5243 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5244 wined3d_mutex_unlock();
5245 *shader = &shader_impl->ID3D10PixelShader_iface;
5246 ID3D10PixelShader_AddRef(*shader);
5249 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5250 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5252 struct d3d_device *device = impl_from_ID3D10Device(iface);
5253 unsigned int i;
5255 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5256 iface, start_slot, sampler_count, samplers);
5258 wined3d_mutex_lock();
5259 for (i = 0; i < sampler_count; ++i)
5261 struct d3d_sampler_state *sampler_impl;
5262 struct wined3d_sampler *wined3d_sampler;
5264 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5265 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5267 samplers[i] = NULL;
5268 continue;
5271 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5272 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5273 ID3D10SamplerState_AddRef(samplers[i]);
5275 wined3d_mutex_unlock();
5278 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5280 struct d3d_device *device = impl_from_ID3D10Device(iface);
5281 struct d3d_vertex_shader *shader_impl;
5282 struct wined3d_shader *wined3d_shader;
5284 TRACE("iface %p, shader %p.\n", iface, shader);
5286 wined3d_mutex_lock();
5287 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5288 WINED3D_SHADER_TYPE_VERTEX)))
5290 wined3d_mutex_unlock();
5291 *shader = NULL;
5292 return;
5295 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5296 wined3d_mutex_unlock();
5297 *shader = &shader_impl->ID3D10VertexShader_iface;
5298 ID3D10VertexShader_AddRef(*shader);
5301 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5302 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5304 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5305 iface, start_slot, buffer_count, buffers);
5307 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5308 buffers);
5311 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5313 struct d3d_device *device = impl_from_ID3D10Device(iface);
5314 struct wined3d_vertex_declaration *wined3d_declaration;
5315 struct d3d_input_layout *input_layout_impl;
5317 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5319 wined3d_mutex_lock();
5320 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5321 device->immediate_context.wined3d_context)))
5323 wined3d_mutex_unlock();
5324 *input_layout = NULL;
5325 return;
5328 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5329 wined3d_mutex_unlock();
5330 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5331 ID3D10InputLayout_AddRef(*input_layout);
5334 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5335 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5337 struct d3d_device *device = impl_from_ID3D10Device(iface);
5338 unsigned int i;
5340 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5341 iface, start_slot, buffer_count, buffers, strides, offsets);
5343 wined3d_mutex_lock();
5344 for (i = 0; i < buffer_count; ++i)
5346 struct wined3d_buffer *wined3d_buffer = NULL;
5347 struct d3d_buffer *buffer_impl;
5349 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5350 &wined3d_buffer, &offsets[i], &strides[i])))
5351 ERR("Failed to get vertex buffer.\n");
5353 if (!wined3d_buffer)
5355 buffers[i] = NULL;
5356 continue;
5359 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5360 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5361 ID3D10Buffer_AddRef(buffers[i]);
5363 wined3d_mutex_unlock();
5366 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5367 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5369 struct d3d_device *device = impl_from_ID3D10Device(iface);
5370 enum wined3d_format_id wined3d_format;
5371 struct wined3d_buffer *wined3d_buffer;
5372 struct d3d_buffer *buffer_impl;
5374 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5376 wined3d_mutex_lock();
5377 wined3d_buffer = wined3d_device_context_get_index_buffer(
5378 device->immediate_context.wined3d_context, &wined3d_format, offset);
5379 *format = dxgi_format_from_wined3dformat(wined3d_format);
5380 if (!wined3d_buffer)
5382 wined3d_mutex_unlock();
5383 *buffer = NULL;
5384 return;
5387 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5388 wined3d_mutex_unlock();
5389 *buffer = &buffer_impl->ID3D10Buffer_iface;
5390 ID3D10Buffer_AddRef(*buffer);
5393 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5394 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5396 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5397 iface, start_slot, buffer_count, buffers);
5399 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5400 buffers);
5403 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5405 struct d3d_device *device = impl_from_ID3D10Device(iface);
5406 struct d3d_geometry_shader *shader_impl;
5407 struct wined3d_shader *wined3d_shader;
5409 TRACE("iface %p, shader %p.\n", iface, shader);
5411 wined3d_mutex_lock();
5412 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5413 WINED3D_SHADER_TYPE_GEOMETRY)))
5415 wined3d_mutex_unlock();
5416 *shader = NULL;
5417 return;
5420 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5421 wined3d_mutex_unlock();
5422 *shader = &shader_impl->ID3D10GeometryShader_iface;
5423 ID3D10GeometryShader_AddRef(*shader);
5426 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5427 D3D10_PRIMITIVE_TOPOLOGY *topology)
5429 struct d3d_device *device = impl_from_ID3D10Device(iface);
5431 TRACE("iface %p, topology %p.\n", iface, topology);
5433 wined3d_mutex_lock();
5434 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5435 (enum wined3d_primitive_type *)topology, NULL);
5436 wined3d_mutex_unlock();
5439 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5440 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5442 struct d3d_device *device = impl_from_ID3D10Device(iface);
5443 unsigned int i;
5445 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5446 iface, start_slot, view_count, views);
5448 wined3d_mutex_lock();
5449 for (i = 0; i < view_count; ++i)
5451 struct wined3d_shader_resource_view *wined3d_view;
5452 struct d3d_shader_resource_view *view_impl;
5454 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5455 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5457 views[i] = NULL;
5458 continue;
5461 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5462 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5463 ID3D10ShaderResourceView_AddRef(views[i]);
5465 wined3d_mutex_unlock();
5468 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5469 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5471 struct d3d_device *device = impl_from_ID3D10Device(iface);
5472 unsigned int i;
5474 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5475 iface, start_slot, sampler_count, samplers);
5477 wined3d_mutex_lock();
5478 for (i = 0; i < sampler_count; ++i)
5480 struct d3d_sampler_state *sampler_impl;
5481 struct wined3d_sampler *wined3d_sampler;
5483 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5484 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5486 samplers[i] = NULL;
5487 continue;
5490 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5491 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5492 ID3D10SamplerState_AddRef(samplers[i]);
5494 wined3d_mutex_unlock();
5497 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5498 ID3D10Predicate **predicate, BOOL *value)
5500 struct d3d_device *device = impl_from_ID3D10Device(iface);
5501 struct wined3d_query *wined3d_predicate;
5502 struct d3d_query *predicate_impl;
5504 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5506 wined3d_mutex_lock();
5507 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5509 wined3d_mutex_unlock();
5510 *predicate = NULL;
5511 return;
5514 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5515 wined3d_mutex_unlock();
5516 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5517 ID3D10Predicate_AddRef(*predicate);
5520 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5521 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5523 struct d3d_device *device = impl_from_ID3D10Device(iface);
5524 unsigned int i;
5526 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5527 iface, start_slot, view_count, views);
5529 wined3d_mutex_lock();
5530 for (i = 0; i < view_count; ++i)
5532 struct wined3d_shader_resource_view *wined3d_view;
5533 struct d3d_shader_resource_view *view_impl;
5535 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5536 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5538 views[i] = NULL;
5539 continue;
5542 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5543 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5544 ID3D10ShaderResourceView_AddRef(views[i]);
5546 wined3d_mutex_unlock();
5549 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5550 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5552 struct d3d_device *device = impl_from_ID3D10Device(iface);
5553 unsigned int i;
5555 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5556 iface, start_slot, sampler_count, samplers);
5558 wined3d_mutex_lock();
5559 for (i = 0; i < sampler_count; ++i)
5561 struct d3d_sampler_state *sampler_impl;
5562 struct wined3d_sampler *wined3d_sampler;
5564 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5565 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5567 samplers[i] = NULL;
5568 continue;
5571 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5572 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5573 ID3D10SamplerState_AddRef(samplers[i]);
5575 wined3d_mutex_unlock();
5578 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5579 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5581 struct d3d_device *device = impl_from_ID3D10Device(iface);
5582 struct wined3d_rendertarget_view *wined3d_view;
5584 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5585 iface, view_count, render_target_views, depth_stencil_view);
5587 wined3d_mutex_lock();
5588 if (render_target_views)
5590 struct d3d_rendertarget_view *view_impl;
5591 unsigned int i;
5593 for (i = 0; i < view_count; ++i)
5595 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5596 device->immediate_context.wined3d_context, i))
5597 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5599 render_target_views[i] = NULL;
5600 continue;
5603 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5604 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5608 if (depth_stencil_view)
5610 struct d3d_depthstencil_view *view_impl;
5612 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5613 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5615 *depth_stencil_view = NULL;
5617 else
5619 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5620 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5623 wined3d_mutex_unlock();
5626 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5627 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5629 struct d3d_device *device = impl_from_ID3D10Device(iface);
5630 ID3D11BlendState *d3d11_blend_state;
5632 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5633 iface, blend_state, blend_factor, sample_mask);
5635 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5636 &d3d11_blend_state, blend_factor, sample_mask);
5638 if (d3d11_blend_state)
5639 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5640 else
5641 *blend_state = NULL;
5644 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5645 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5647 struct d3d_device *device = impl_from_ID3D10Device(iface);
5648 ID3D11DepthStencilState *d3d11_iface;
5650 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5651 iface, depth_stencil_state, stencil_ref);
5653 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5654 &d3d11_iface, stencil_ref);
5656 if (d3d11_iface)
5657 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5658 else
5659 *depth_stencil_state = NULL;
5662 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5663 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5665 struct d3d_device *device = impl_from_ID3D10Device(iface);
5666 unsigned int i;
5668 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5669 iface, buffer_count, buffers, offsets);
5671 wined3d_mutex_lock();
5672 for (i = 0; i < buffer_count; ++i)
5674 struct wined3d_buffer *wined3d_buffer;
5675 struct d3d_buffer *buffer_impl;
5677 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5678 device->immediate_context.wined3d_context, i, &offsets[i])))
5680 buffers[i] = NULL;
5681 continue;
5684 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5685 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5686 ID3D10Buffer_AddRef(buffers[i]);
5688 wined3d_mutex_unlock();
5691 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5693 struct d3d_device *device = impl_from_ID3D10Device(iface);
5694 struct d3d_rasterizer_state *rasterizer_state_impl;
5695 struct wined3d_rasterizer_state *wined3d_state;
5697 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5699 wined3d_mutex_lock();
5700 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5702 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5703 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5705 else
5707 *rasterizer_state = NULL;
5709 wined3d_mutex_unlock();
5712 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5713 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5715 struct d3d_device *device = impl_from_ID3D10Device(iface);
5716 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5717 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5719 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5721 if (!viewport_count)
5722 return;
5724 wined3d_mutex_lock();
5725 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5726 &actual_count, viewports ? wined3d_vp : NULL);
5727 wined3d_mutex_unlock();
5729 if (!viewports)
5731 *viewport_count = actual_count;
5732 return;
5735 if (*viewport_count > actual_count)
5736 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5738 *viewport_count = min(actual_count, *viewport_count);
5739 for (i = 0; i < *viewport_count; ++i)
5741 viewports[i].TopLeftX = wined3d_vp[i].x;
5742 viewports[i].TopLeftY = wined3d_vp[i].y;
5743 viewports[i].Width = wined3d_vp[i].width;
5744 viewports[i].Height = wined3d_vp[i].height;
5745 viewports[i].MinDepth = wined3d_vp[i].min_z;
5746 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5750 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5752 struct d3d_device *device = impl_from_ID3D10Device(iface);
5753 unsigned int actual_count;
5755 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5757 if (!rect_count)
5758 return;
5760 actual_count = *rect_count;
5762 wined3d_mutex_lock();
5763 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5764 wined3d_mutex_unlock();
5766 if (!rects)
5768 *rect_count = actual_count;
5769 return;
5772 if (*rect_count > actual_count)
5773 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5776 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5778 TRACE("iface %p.\n", iface);
5780 /* In the current implementation the device is never removed, so we can
5781 * just return S_OK here. */
5783 return S_OK;
5786 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5788 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5790 return E_NOTIMPL;
5793 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5795 FIXME("iface %p stub!\n", iface);
5797 return 0;
5800 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5801 REFGUID guid, UINT *data_size, void *data)
5803 struct d3d_device *device = impl_from_ID3D10Device(iface);
5805 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5807 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5810 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5811 REFGUID guid, UINT data_size, const void *data)
5813 struct d3d_device *device = impl_from_ID3D10Device(iface);
5815 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5817 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5820 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5821 REFGUID guid, const IUnknown *data)
5823 struct d3d_device *device = impl_from_ID3D10Device(iface);
5825 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5827 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5830 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5832 struct d3d_device *device = impl_from_ID3D10Device(iface);
5834 TRACE("iface %p.\n", iface);
5836 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5839 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5841 struct d3d_device *device = impl_from_ID3D10Device(iface);
5843 TRACE("iface %p.\n", iface);
5845 wined3d_mutex_lock();
5846 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5847 wined3d_mutex_unlock();
5850 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5851 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5853 struct d3d_device *device = impl_from_ID3D10Device(iface);
5854 D3D11_BUFFER_DESC d3d11_desc;
5855 struct d3d_buffer *object;
5856 HRESULT hr;
5858 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5860 d3d11_desc.ByteWidth = desc->ByteWidth;
5861 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5862 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5863 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5864 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5865 d3d11_desc.StructureByteStride = 0;
5867 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5868 return hr;
5870 *buffer = &object->ID3D10Buffer_iface;
5872 return S_OK;
5875 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5876 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5878 struct d3d_device *device = impl_from_ID3D10Device(iface);
5879 D3D11_TEXTURE1D_DESC d3d11_desc;
5880 struct d3d_texture1d *object;
5881 HRESULT hr;
5883 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5885 d3d11_desc.Width = desc->Width;
5886 d3d11_desc.MipLevels = desc->MipLevels;
5887 d3d11_desc.ArraySize = desc->ArraySize;
5888 d3d11_desc.Format = desc->Format;
5889 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5890 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5891 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5892 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5894 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5895 return hr;
5897 *texture = &object->ID3D10Texture1D_iface;
5899 return S_OK;
5902 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5903 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5904 ID3D10Texture2D **texture)
5906 struct d3d_device *device = impl_from_ID3D10Device(iface);
5907 D3D11_TEXTURE2D_DESC d3d11_desc;
5908 struct d3d_texture2d *object;
5909 HRESULT hr;
5911 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5913 d3d11_desc.Width = desc->Width;
5914 d3d11_desc.Height = desc->Height;
5915 d3d11_desc.MipLevels = desc->MipLevels;
5916 d3d11_desc.ArraySize = desc->ArraySize;
5917 d3d11_desc.Format = desc->Format;
5918 d3d11_desc.SampleDesc = desc->SampleDesc;
5919 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5920 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5921 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5922 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5924 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5925 return hr;
5927 *texture = &object->ID3D10Texture2D_iface;
5929 return S_OK;
5932 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5933 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5934 ID3D10Texture3D **texture)
5936 struct d3d_device *device = impl_from_ID3D10Device(iface);
5937 D3D11_TEXTURE3D_DESC d3d11_desc;
5938 struct d3d_texture3d *object;
5939 HRESULT hr;
5941 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5943 d3d11_desc.Width = desc->Width;
5944 d3d11_desc.Height = desc->Height;
5945 d3d11_desc.Depth = desc->Depth;
5946 d3d11_desc.MipLevels = desc->MipLevels;
5947 d3d11_desc.Format = desc->Format;
5948 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5949 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5950 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5951 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5953 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5954 return hr;
5956 *texture = &object->ID3D10Texture3D_iface;
5958 return S_OK;
5961 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5962 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5964 struct d3d_device *device = impl_from_ID3D10Device(iface);
5965 struct d3d_shader_resource_view *object;
5966 ID3D11Resource *d3d11_resource;
5967 HRESULT hr;
5969 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5971 if (!resource)
5972 return E_INVALIDARG;
5974 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5976 ERR("Resource does not implement ID3D11Resource.\n");
5977 return E_FAIL;
5980 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5981 &object);
5982 ID3D11Resource_Release(d3d11_resource);
5983 if (FAILED(hr))
5984 return hr;
5986 *view = &object->ID3D10ShaderResourceView1_iface;
5988 return S_OK;
5991 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5992 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5994 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5996 return d3d10_device_CreateShaderResourceView1(iface, resource,
5997 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
6000 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
6001 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6003 struct d3d_device *device = impl_from_ID3D10Device(iface);
6004 struct d3d_rendertarget_view *object;
6005 ID3D11Resource *d3d11_resource;
6006 HRESULT hr;
6008 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6010 if (!resource)
6011 return E_INVALIDARG;
6013 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6015 ERR("Resource does not implement ID3D11Resource.\n");
6016 return E_FAIL;
6019 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6020 ID3D11Resource_Release(d3d11_resource);
6021 if (FAILED(hr))
6022 return hr;
6024 *view = &object->ID3D10RenderTargetView_iface;
6026 return S_OK;
6029 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6031 return (D3D11_DSV_DIMENSION)dim;
6034 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6035 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6037 struct d3d_device *device = impl_from_ID3D10Device(iface);
6038 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6039 struct d3d_depthstencil_view *object;
6040 ID3D11Resource *d3d11_resource;
6041 HRESULT hr;
6043 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6045 if (desc)
6047 d3d11_desc.Format = desc->Format;
6048 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6049 d3d11_desc.Flags = 0;
6050 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6053 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6055 ERR("Resource does not implement ID3D11Resource.\n");
6056 return E_FAIL;
6059 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6060 ID3D11Resource_Release(d3d11_resource);
6061 if (FAILED(hr))
6062 return hr;
6064 *view = &object->ID3D10DepthStencilView_iface;
6066 return S_OK;
6069 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6070 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6071 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6072 ID3D10InputLayout **input_layout)
6074 struct d3d_device *device = impl_from_ID3D10Device(iface);
6075 struct d3d_input_layout *object;
6076 HRESULT hr;
6078 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6079 "shader_byte_code_length %lu, input_layout %p\n",
6080 iface, element_descs, element_count, shader_byte_code,
6081 shader_byte_code_length, input_layout);
6083 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6084 shader_byte_code, shader_byte_code_length, &object)))
6085 return hr;
6087 *input_layout = &object->ID3D10InputLayout_iface;
6089 return S_OK;
6092 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6093 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6095 struct d3d_device *device = impl_from_ID3D10Device(iface);
6096 struct d3d_vertex_shader *object;
6097 HRESULT hr;
6099 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6100 iface, byte_code, byte_code_length, shader);
6102 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6103 return hr;
6105 *shader = &object->ID3D10VertexShader_iface;
6107 return S_OK;
6110 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6111 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6113 struct d3d_device *device = impl_from_ID3D10Device(iface);
6114 struct d3d_geometry_shader *object;
6115 HRESULT hr;
6117 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6118 iface, byte_code, byte_code_length, shader);
6120 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6121 NULL, 0, NULL, 0, 0, &object)))
6122 return hr;
6124 *shader = &object->ID3D10GeometryShader_iface;
6126 return S_OK;
6129 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6130 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6131 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6133 struct d3d_device *device = impl_from_ID3D10Device(iface);
6134 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6135 struct d3d_geometry_shader *object;
6136 unsigned int i, stride_count = 1;
6137 HRESULT hr;
6139 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
6140 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6141 iface, byte_code, byte_code_length, output_stream_decls,
6142 output_stream_decl_count, output_stream_stride, shader);
6144 if (!output_stream_decl_count && output_stream_stride)
6146 WARN("Stride must be 0 when declaration entry count is 0.\n");
6147 *shader = NULL;
6148 return E_INVALIDARG;
6151 if (output_stream_decl_count
6152 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6154 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6155 *shader = NULL;
6156 return E_OUTOFMEMORY;
6159 for (i = 0; i < output_stream_decl_count; ++i)
6161 so_entries[i].Stream = 0;
6162 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6163 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6164 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6165 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6166 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6168 if (output_stream_decls[i].OutputSlot)
6170 stride_count = 0;
6171 if (output_stream_stride)
6173 WARN("Stride must be 0 when multiple output slots are used.\n");
6174 heap_free(so_entries);
6175 *shader = NULL;
6176 return E_INVALIDARG;
6181 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6182 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6183 heap_free(so_entries);
6184 if (FAILED(hr))
6186 *shader = NULL;
6187 return hr;
6190 *shader = &object->ID3D10GeometryShader_iface;
6192 return hr;
6195 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6196 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6198 struct d3d_device *device = impl_from_ID3D10Device(iface);
6199 struct d3d_pixel_shader *object;
6200 HRESULT hr;
6202 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6203 iface, byte_code, byte_code_length, shader);
6205 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6206 return hr;
6208 *shader = &object->ID3D10PixelShader_iface;
6210 return S_OK;
6213 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6214 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6216 struct d3d_device *device = impl_from_ID3D10Device(iface);
6217 struct d3d_blend_state *object;
6218 HRESULT hr;
6220 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6222 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6223 return hr;
6225 *blend_state = &object->ID3D10BlendState1_iface;
6227 return S_OK;
6230 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6231 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6233 D3D10_BLEND_DESC1 d3d10_1_desc;
6234 unsigned int i;
6236 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6238 if (!desc)
6239 return E_INVALIDARG;
6241 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6242 d3d10_1_desc.IndependentBlendEnable = FALSE;
6243 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6245 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6246 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6247 d3d10_1_desc.IndependentBlendEnable = TRUE;
6250 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6252 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6253 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6254 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6255 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6256 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6257 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6258 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6259 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6262 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6265 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6266 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6268 struct d3d_device *device = impl_from_ID3D10Device(iface);
6269 struct d3d_depthstencil_state *object;
6270 HRESULT hr;
6272 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6274 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6275 return hr;
6277 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6279 return S_OK;
6282 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6283 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6285 struct d3d_device *device = impl_from_ID3D10Device(iface);
6286 struct d3d_rasterizer_state *object;
6287 HRESULT hr;
6289 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6291 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6292 return hr;
6294 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6296 return S_OK;
6299 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6300 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6302 struct d3d_device *device = impl_from_ID3D10Device(iface);
6303 struct d3d_sampler_state *object;
6304 HRESULT hr;
6306 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6308 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6309 return hr;
6311 *sampler_state = &object->ID3D10SamplerState_iface;
6313 return S_OK;
6316 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6317 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6319 struct d3d_device *device = impl_from_ID3D10Device(iface);
6320 struct d3d_query *object;
6321 HRESULT hr;
6323 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6325 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6326 return hr;
6328 if (query)
6330 *query = &object->ID3D10Query_iface;
6331 return S_OK;
6334 ID3D10Query_Release(&object->ID3D10Query_iface);
6335 return S_FALSE;
6338 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6339 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6341 struct d3d_device *device = impl_from_ID3D10Device(iface);
6342 struct d3d_query *object;
6343 HRESULT hr;
6345 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6347 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6348 return hr;
6350 if (predicate)
6352 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6353 return S_OK;
6356 ID3D10Query_Release(&object->ID3D10Query_iface);
6357 return S_FALSE;
6360 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6361 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6363 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6365 return E_NOTIMPL;
6368 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6369 DXGI_FORMAT format, UINT *format_support)
6371 struct d3d_device *device = impl_from_ID3D10Device(iface);
6373 TRACE("iface %p, format %s, format_support %p.\n",
6374 iface, debug_dxgi_format(format), format_support);
6376 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6379 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6380 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6382 struct d3d_device *device = impl_from_ID3D10Device(iface);
6384 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6385 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6387 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6388 sample_count, quality_level_count);
6391 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6393 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6396 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6397 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6398 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6400 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6401 "units %p, units_length %p, description %p, description_length %p stub!\n",
6402 iface, desc, type, active_counters, name, name_length,
6403 units, units_length, description, description_length);
6405 return E_NOTIMPL;
6408 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6410 FIXME("iface %p stub!\n", iface);
6412 return 0;
6415 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6416 HANDLE resource_handle, REFIID guid, void **resource)
6418 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6419 iface, resource_handle, debugstr_guid(guid), resource);
6421 return E_NOTIMPL;
6424 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6426 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6429 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6431 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6434 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6436 return (D3D10_FEATURE_LEVEL1)level;
6439 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6441 struct d3d_device *device = impl_from_ID3D10Device(iface);
6443 TRACE("iface %p.\n", iface);
6445 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6448 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6450 /* IUnknown methods */
6451 d3d10_device_QueryInterface,
6452 d3d10_device_AddRef,
6453 d3d10_device_Release,
6454 /* ID3D10Device methods */
6455 d3d10_device_VSSetConstantBuffers,
6456 d3d10_device_PSSetShaderResources,
6457 d3d10_device_PSSetShader,
6458 d3d10_device_PSSetSamplers,
6459 d3d10_device_VSSetShader,
6460 d3d10_device_DrawIndexed,
6461 d3d10_device_Draw,
6462 d3d10_device_PSSetConstantBuffers,
6463 d3d10_device_IASetInputLayout,
6464 d3d10_device_IASetVertexBuffers,
6465 d3d10_device_IASetIndexBuffer,
6466 d3d10_device_DrawIndexedInstanced,
6467 d3d10_device_DrawInstanced,
6468 d3d10_device_GSSetConstantBuffers,
6469 d3d10_device_GSSetShader,
6470 d3d10_device_IASetPrimitiveTopology,
6471 d3d10_device_VSSetShaderResources,
6472 d3d10_device_VSSetSamplers,
6473 d3d10_device_SetPredication,
6474 d3d10_device_GSSetShaderResources,
6475 d3d10_device_GSSetSamplers,
6476 d3d10_device_OMSetRenderTargets,
6477 d3d10_device_OMSetBlendState,
6478 d3d10_device_OMSetDepthStencilState,
6479 d3d10_device_SOSetTargets,
6480 d3d10_device_DrawAuto,
6481 d3d10_device_RSSetState,
6482 d3d10_device_RSSetViewports,
6483 d3d10_device_RSSetScissorRects,
6484 d3d10_device_CopySubresourceRegion,
6485 d3d10_device_CopyResource,
6486 d3d10_device_UpdateSubresource,
6487 d3d10_device_ClearRenderTargetView,
6488 d3d10_device_ClearDepthStencilView,
6489 d3d10_device_GenerateMips,
6490 d3d10_device_ResolveSubresource,
6491 d3d10_device_VSGetConstantBuffers,
6492 d3d10_device_PSGetShaderResources,
6493 d3d10_device_PSGetShader,
6494 d3d10_device_PSGetSamplers,
6495 d3d10_device_VSGetShader,
6496 d3d10_device_PSGetConstantBuffers,
6497 d3d10_device_IAGetInputLayout,
6498 d3d10_device_IAGetVertexBuffers,
6499 d3d10_device_IAGetIndexBuffer,
6500 d3d10_device_GSGetConstantBuffers,
6501 d3d10_device_GSGetShader,
6502 d3d10_device_IAGetPrimitiveTopology,
6503 d3d10_device_VSGetShaderResources,
6504 d3d10_device_VSGetSamplers,
6505 d3d10_device_GetPredication,
6506 d3d10_device_GSGetShaderResources,
6507 d3d10_device_GSGetSamplers,
6508 d3d10_device_OMGetRenderTargets,
6509 d3d10_device_OMGetBlendState,
6510 d3d10_device_OMGetDepthStencilState,
6511 d3d10_device_SOGetTargets,
6512 d3d10_device_RSGetState,
6513 d3d10_device_RSGetViewports,
6514 d3d10_device_RSGetScissorRects,
6515 d3d10_device_GetDeviceRemovedReason,
6516 d3d10_device_SetExceptionMode,
6517 d3d10_device_GetExceptionMode,
6518 d3d10_device_GetPrivateData,
6519 d3d10_device_SetPrivateData,
6520 d3d10_device_SetPrivateDataInterface,
6521 d3d10_device_ClearState,
6522 d3d10_device_Flush,
6523 d3d10_device_CreateBuffer,
6524 d3d10_device_CreateTexture1D,
6525 d3d10_device_CreateTexture2D,
6526 d3d10_device_CreateTexture3D,
6527 d3d10_device_CreateShaderResourceView,
6528 d3d10_device_CreateRenderTargetView,
6529 d3d10_device_CreateDepthStencilView,
6530 d3d10_device_CreateInputLayout,
6531 d3d10_device_CreateVertexShader,
6532 d3d10_device_CreateGeometryShader,
6533 d3d10_device_CreateGeometryShaderWithStreamOutput,
6534 d3d10_device_CreatePixelShader,
6535 d3d10_device_CreateBlendState,
6536 d3d10_device_CreateDepthStencilState,
6537 d3d10_device_CreateRasterizerState,
6538 d3d10_device_CreateSamplerState,
6539 d3d10_device_CreateQuery,
6540 d3d10_device_CreatePredicate,
6541 d3d10_device_CreateCounter,
6542 d3d10_device_CheckFormatSupport,
6543 d3d10_device_CheckMultisampleQualityLevels,
6544 d3d10_device_CheckCounterInfo,
6545 d3d10_device_CheckCounter,
6546 d3d10_device_GetCreationFlags,
6547 d3d10_device_OpenSharedResource,
6548 d3d10_device_SetTextFilterSize,
6549 d3d10_device_GetTextFilterSize,
6550 d3d10_device_CreateShaderResourceView1,
6551 d3d10_device_CreateBlendState1,
6552 d3d10_device_GetFeatureLevel,
6555 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6557 /* IUnknown methods */
6558 d3d_device_inner_QueryInterface,
6559 d3d_device_inner_AddRef,
6560 d3d_device_inner_Release,
6563 /* ID3D10Multithread methods */
6565 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6567 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6570 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6572 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6574 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6576 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6579 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6581 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6583 TRACE("iface %p.\n", iface);
6585 return IUnknown_AddRef(device->outer_unk);
6588 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6590 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6592 TRACE("iface %p.\n", iface);
6594 return IUnknown_Release(device->outer_unk);
6597 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6599 TRACE("iface %p.\n", iface);
6601 wined3d_mutex_lock();
6604 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6606 TRACE("iface %p.\n", iface);
6608 wined3d_mutex_unlock();
6611 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6613 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6615 return TRUE;
6618 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6620 FIXME("iface %p stub!\n", iface);
6622 return TRUE;
6625 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6627 d3d10_multithread_QueryInterface,
6628 d3d10_multithread_AddRef,
6629 d3d10_multithread_Release,
6630 d3d10_multithread_Enter,
6631 d3d10_multithread_Leave,
6632 d3d10_multithread_SetMultithreadProtected,
6633 d3d10_multithread_GetMultithreadProtected,
6636 /* IWineDXGIDeviceParent IUnknown methods */
6638 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6640 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6643 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6644 REFIID iid, void **out)
6646 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6647 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6650 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6652 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6653 return IUnknown_AddRef(device->outer_unk);
6656 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6658 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6659 return IUnknown_Release(device->outer_unk);
6662 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6663 IWineDXGIDeviceParent *iface)
6665 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6666 return &device->device_parent;
6669 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6671 /* IUnknown methods */
6672 dxgi_device_parent_QueryInterface,
6673 dxgi_device_parent_AddRef,
6674 dxgi_device_parent_Release,
6675 /* IWineDXGIDeviceParent methods */
6676 dxgi_device_parent_get_wined3d_device_parent,
6679 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6681 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6684 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6685 struct wined3d_device *wined3d_device)
6687 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6688 struct d3d_device_context_state *state;
6689 struct wined3d_state *wined3d_state;
6690 D3D_FEATURE_LEVEL feature_level;
6692 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6694 wined3d_device_incref(wined3d_device);
6695 device->wined3d_device = wined3d_device;
6696 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6698 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6699 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6701 if (!(state = heap_alloc_zero(sizeof(*state))))
6703 ERR("Failed to create the initial device context state.\n");
6704 return;
6707 d3d_device_context_state_init(state, device, feature_level,
6708 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6710 device->state = state;
6711 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6712 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6714 d3d_device_context_state_private_addref(state);
6715 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6718 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6720 TRACE("device_parent %p.\n", device_parent);
6723 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6725 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6728 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6729 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6730 void **parent, const struct wined3d_parent_ops **parent_ops)
6732 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6733 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6735 *parent = NULL;
6736 *parent_ops = &d3d_null_wined3d_parent_ops;
6738 return S_OK;
6741 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6742 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6743 struct wined3d_texture **wined3d_texture)
6745 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6746 struct d3d_texture2d *texture;
6747 ID3D11Texture2D *texture_iface;
6748 D3D11_TEXTURE2D_DESC desc;
6749 HRESULT hr;
6751 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6752 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6754 desc.Width = wined3d_desc->width;
6755 desc.Height = wined3d_desc->height;
6756 desc.MipLevels = 1;
6757 desc.ArraySize = 1;
6758 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6759 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6760 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6761 desc.Usage = D3D11_USAGE_DEFAULT;
6762 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6763 desc.CPUAccessFlags = 0;
6764 desc.MiscFlags = 0;
6766 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6768 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6769 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6772 if (texture_flags)
6773 FIXME("Unhandled flags %#x.\n", texture_flags);
6775 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6776 &desc, NULL, &texture_iface)))
6778 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6779 return hr;
6782 texture = impl_from_ID3D11Texture2D(texture_iface);
6784 *wined3d_texture = texture->wined3d_texture;
6785 wined3d_texture_incref(*wined3d_texture);
6786 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6788 return S_OK;
6791 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6793 device_parent_wined3d_device_created,
6794 device_parent_mode_changed,
6795 device_parent_activate,
6796 device_parent_texture_sub_resource_created,
6797 device_parent_create_swapchain_texture,
6800 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6802 const D3D11_SAMPLER_DESC *ka = key;
6803 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6805 return memcmp(ka, kb, sizeof(*ka));
6808 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6810 const D3D11_BLEND_DESC *ka = key;
6811 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6813 return memcmp(ka, kb, sizeof(*ka));
6816 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6818 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6819 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6820 const struct d3d_depthstencil_state, entry)->desc;
6822 return memcmp(ka, kb, sizeof(*ka));
6825 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6827 const D3D11_RASTERIZER_DESC *ka = key;
6828 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6830 return memcmp(ka, kb, sizeof(*ka));
6833 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6835 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6836 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6837 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6838 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6839 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6840 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6841 device->refcount = 1;
6842 /* COM aggregation always takes place */
6843 device->outer_unk = outer_unknown;
6844 device->d3d11_only = FALSE;
6845 device->state = NULL;
6847 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6848 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6850 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6851 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6852 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6853 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);