kernelbase/tests: Fix the Sleep() test for non-default timer resolutions.
[wine.git] / dlls / d3d11 / device.c
blobc47b52083605d5bee2e7225caf68a2ed9d62881d
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 ID3D11Device2 *device = &context->device->ID3D11Device2_iface;
525 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
527 wined3d_deferred_context_destroy(context->wined3d_context);
528 d3d11_device_context_cleanup(context);
529 heap_free(context);
531 ID3D11Device2_Release(device);
534 return refcount;
537 static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
538 unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer **buffers,
539 unsigned int *offsets, unsigned int *counts)
541 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
542 unsigned int i;
544 wined3d_mutex_lock();
545 for (i = 0; i < buffer_count; ++i)
547 struct wined3d_constant_buffer_state state;
548 struct d3d_buffer *buffer_impl;
550 wined3d_device_context_get_constant_buffer(context->wined3d_context, type, start_slot + i, &state);
552 if (offsets)
553 offsets[i] = state.offset / sizeof(struct wined3d_vec4);
554 if (counts)
555 counts[i] = state.size / sizeof(struct wined3d_vec4);
557 if (!state.buffer)
559 buffers[i] = NULL;
560 continue;
563 buffer_impl = wined3d_buffer_get_parent(state.buffer);
564 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
565 ID3D11Buffer_AddRef(buffers[i]);
567 wined3d_mutex_unlock();
570 static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
571 unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer *const *buffers,
572 const unsigned int *offsets, const unsigned int *counts)
574 static const unsigned int alignment = D3D11_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT;
575 struct wined3d_constant_buffer_state wined3d_buffers[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
576 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
577 unsigned int i;
579 if (buffer_count > ARRAY_SIZE(wined3d_buffers))
581 WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
582 return;
585 if (!offsets != !counts)
587 WARN("Got offsets pointer %p but counts pointer %p; ignoring call.\n", offsets, counts);
588 return;
591 for (i = 0; i < buffer_count; ++i)
593 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
595 if (offsets && (offsets[i] & (alignment - 1)))
597 WARN("Offset %u is not aligned.\n", offsets[i]);
598 return;
601 if (counts && (counts[i] & (alignment - 1)))
603 WARN("Count %u is not aligned.\n", counts[i]);
604 return;
607 wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
608 wined3d_buffers[i].offset = (offsets ? offsets[i] : 0) * sizeof(struct wined3d_vec4);
609 wined3d_buffers[i].size = (counts ? counts[i] : WINED3D_MAX_CONSTANT_BUFFER_SIZE) * sizeof(struct wined3d_vec4);
612 wined3d_mutex_lock();
613 wined3d_device_context_set_constant_buffers(context->wined3d_context,
614 type, start_slot, buffer_count, wined3d_buffers);
615 wined3d_mutex_unlock();
618 static void d3d11_device_context_set_shader_resource_views(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
619 unsigned int start_slot, unsigned int count, ID3D11ShaderResourceView *const *views)
621 struct wined3d_shader_resource_view *wined3d_views[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
622 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
623 unsigned int i;
625 if (count > ARRAY_SIZE(wined3d_views))
627 WARN("View count %u exceeds limit; ignoring call.\n", count);
628 return;
631 for (i = 0; i < count; ++i)
633 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
635 wined3d_views[i] = view ? view->wined3d_view : NULL;
638 wined3d_mutex_lock();
639 wined3d_device_context_set_shader_resource_views(context->wined3d_context,
640 type, start_slot, count, wined3d_views);
641 wined3d_mutex_unlock();
644 static void d3d11_device_context_set_samplers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
645 unsigned int start_slot, unsigned int count, ID3D11SamplerState *const *samplers)
647 struct wined3d_sampler *wined3d_samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
648 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
649 unsigned int i;
651 if (count > ARRAY_SIZE(wined3d_samplers))
653 WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
654 return;
657 for (i = 0; i < count; ++i)
659 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
661 wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
664 wined3d_mutex_lock();
665 wined3d_device_context_set_samplers(context->wined3d_context, type, start_slot, count, wined3d_samplers);
666 wined3d_mutex_unlock();
669 static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
671 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
673 TRACE("iface %p, device %p.\n", iface, device);
675 *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
676 ID3D11Device_AddRef(*device);
679 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
680 UINT *data_size, void *data)
682 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
684 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
686 return d3d_get_private_data(&context->private_store, guid, data_size, data);
689 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
690 UINT data_size, const void *data)
692 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
694 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
696 return d3d_set_private_data(&context->private_store, guid, data_size, data);
699 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
700 REFGUID guid, const IUnknown *data)
702 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
704 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
706 return d3d_set_private_data_interface(&context->private_store, guid, data);
709 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
710 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
712 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
713 iface, start_slot, buffer_count, buffers);
715 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
716 buffer_count, buffers, NULL, NULL);
719 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
720 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
722 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
723 iface, start_slot, view_count, views);
725 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
728 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
729 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
731 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
732 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
734 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
735 iface, shader, class_instances, class_instance_count);
737 if (class_instances)
738 FIXME("Dynamic linking is not implemented yet.\n");
740 wined3d_mutex_lock();
741 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
742 ps ? ps->wined3d_shader : NULL);
743 wined3d_mutex_unlock();
746 static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
747 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
749 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
750 iface, start_slot, sampler_count, samplers);
752 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
755 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
756 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
758 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
759 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
761 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
762 iface, shader, class_instances, class_instance_count);
764 if (class_instances)
765 FIXME("Dynamic linking is not implemented yet.\n");
767 wined3d_mutex_lock();
768 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
769 vs ? vs->wined3d_shader : NULL);
770 wined3d_mutex_unlock();
773 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
774 UINT index_count, UINT start_index_location, INT base_vertex_location)
776 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
778 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
779 iface, index_count, start_index_location, base_vertex_location);
781 wined3d_mutex_lock();
782 wined3d_device_context_draw_indexed(context->wined3d_context,
783 base_vertex_location, start_index_location, index_count, 0, 0);
784 wined3d_mutex_unlock();
787 static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
788 UINT vertex_count, UINT start_vertex_location)
790 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
792 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
793 iface, vertex_count, start_vertex_location);
795 wined3d_mutex_lock();
796 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
797 wined3d_mutex_unlock();
800 static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
801 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
803 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
804 struct wined3d_resource *wined3d_resource;
805 struct wined3d_map_desc map_desc;
806 HRESULT hr;
808 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
809 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
811 if (map_flags)
812 FIXME("Ignoring map_flags %#x.\n", map_flags);
814 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE
815 && map_type != D3D11_MAP_WRITE_DISCARD && map_type != D3D11_MAP_WRITE_NO_OVERWRITE)
816 return E_INVALIDARG;
818 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
820 wined3d_mutex_lock();
821 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
822 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
823 wined3d_mutex_unlock();
825 mapped_subresource->pData = map_desc.data;
826 mapped_subresource->RowPitch = map_desc.row_pitch;
827 mapped_subresource->DepthPitch = map_desc.slice_pitch;
829 return hr;
832 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
833 UINT subresource_idx)
835 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
836 struct wined3d_resource *wined3d_resource;
838 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
840 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
842 wined3d_mutex_lock();
843 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
844 wined3d_mutex_unlock();
847 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
848 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
850 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
851 iface, start_slot, buffer_count, buffers);
853 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
854 buffer_count, buffers, NULL, NULL);
857 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
858 ID3D11InputLayout *input_layout)
860 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
861 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
863 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
865 wined3d_mutex_lock();
866 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
867 wined3d_mutex_unlock();
870 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
871 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
873 struct wined3d_stream_state streams[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
874 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
875 unsigned int i;
877 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
878 iface, start_slot, buffer_count, buffers, strides, offsets);
880 if (buffer_count > ARRAY_SIZE(streams))
882 WARN("Buffer count %u exceeds limit.\n", buffer_count);
883 buffer_count = ARRAY_SIZE(streams);
886 for (i = 0; i < buffer_count; ++i)
888 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
890 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
891 streams[i].offset = offsets[i];
892 streams[i].stride = strides[i];
893 streams[i].frequency = 1;
894 streams[i].flags = 0;
897 wined3d_mutex_lock();
898 wined3d_device_context_set_stream_sources(context->wined3d_context, start_slot, buffer_count, streams);
899 wined3d_mutex_unlock();
902 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
903 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
905 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
906 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
908 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
909 iface, buffer, debug_dxgi_format(format), offset);
911 wined3d_mutex_lock();
912 wined3d_device_context_set_index_buffer(context->wined3d_context,
913 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
914 wined3dformat_from_dxgi_format(format), offset);
915 wined3d_mutex_unlock();
918 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
919 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
920 UINT start_instance_location)
922 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
924 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
925 "base_vertex_location %d, start_instance_location %u.\n",
926 iface, instance_index_count, instance_count, start_index_location,
927 base_vertex_location, start_instance_location);
929 wined3d_mutex_lock();
930 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
931 start_index_location, instance_index_count, start_instance_location, instance_count);
932 wined3d_mutex_unlock();
935 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
936 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
938 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
940 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
941 "start_instance_location %u.\n",
942 iface, instance_vertex_count, instance_count, start_vertex_location,
943 start_instance_location);
945 wined3d_mutex_lock();
946 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
947 instance_vertex_count, start_instance_location, instance_count);
948 wined3d_mutex_unlock();
951 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
952 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
954 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
955 iface, start_slot, buffer_count, buffers);
957 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
958 buffer_count, buffers, NULL, NULL);
961 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
962 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
964 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
965 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
967 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
968 iface, shader, class_instances, class_instance_count);
970 if (class_instances)
971 FIXME("Dynamic linking is not implemented yet.\n");
973 wined3d_mutex_lock();
974 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
975 gs ? gs->wined3d_shader : NULL);
976 wined3d_mutex_unlock();
979 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
980 D3D11_PRIMITIVE_TOPOLOGY topology)
982 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
983 enum wined3d_primitive_type primitive_type;
984 unsigned int patch_vertex_count;
986 TRACE("iface %p, topology %#x.\n", iface, topology);
988 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
990 wined3d_mutex_lock();
991 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
992 wined3d_mutex_unlock();
995 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
996 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
998 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1000 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
1003 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
1004 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1006 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1007 iface, start_slot, sampler_count, samplers);
1009 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
1012 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
1013 ID3D11Asynchronous *asynchronous)
1015 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1016 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1018 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
1020 wined3d_mutex_lock();
1021 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
1022 wined3d_mutex_unlock();
1025 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
1026 ID3D11Asynchronous *asynchronous)
1028 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1029 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1031 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
1033 wined3d_mutex_lock();
1034 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
1035 wined3d_mutex_unlock();
1038 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
1039 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
1041 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1042 unsigned int wined3d_flags;
1043 HRESULT hr;
1045 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
1046 iface, asynchronous, data, data_size, data_flags);
1048 if (!data && data_size)
1049 return E_INVALIDARG;
1051 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
1053 wined3d_mutex_lock();
1054 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
1056 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
1057 if (hr == WINED3DERR_INVALIDCALL)
1058 hr = DXGI_ERROR_INVALID_CALL;
1060 else
1062 WARN("Invalid data size %u.\n", data_size);
1063 hr = E_INVALIDARG;
1065 wined3d_mutex_unlock();
1067 return hr;
1070 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1071 ID3D11Predicate *predicate, BOOL value)
1073 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1074 struct d3d_query *query;
1076 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1078 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1080 wined3d_mutex_lock();
1081 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1082 wined3d_mutex_unlock();
1085 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1086 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1088 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1090 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
1093 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1094 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1096 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1097 iface, start_slot, sampler_count, samplers);
1099 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
1102 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1103 UINT rtv_count, ID3D11RenderTargetView *const *rtvs, ID3D11DepthStencilView *depth_stencil_view)
1105 struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1106 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1107 struct d3d_depthstencil_view *dsv;
1108 unsigned int i;
1110 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
1112 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
1114 WARN("View count %u exceeds limit.\n", rtv_count);
1115 rtv_count = ARRAY_SIZE(wined3d_rtvs);
1118 for (i = 0; i < rtv_count; ++i)
1120 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(rtvs[i]);
1122 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1125 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1127 wined3d_mutex_lock();
1128 wined3d_device_context_set_rendertarget_views(context->wined3d_context, 0,
1129 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
1130 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
1131 wined3d_mutex_unlock();
1134 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1135 ID3D11DeviceContext1 *iface, UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1136 ID3D11DepthStencilView *depth_stencil_view, UINT uav_start_idx, UINT uav_count,
1137 ID3D11UnorderedAccessView *const *uavs, const UINT *initial_counts)
1139 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1140 unsigned int i;
1142 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1143 "uav_start_idx %u, uav_count %u, uavs %p, initial_counts %p.\n",
1144 iface, render_target_view_count, render_target_views, depth_stencil_view,
1145 uav_start_idx, uav_count, uavs, initial_counts);
1147 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1149 d3d11_device_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
1150 depth_stencil_view);
1153 if (uav_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1155 struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0};
1156 unsigned int wined3d_initial_counts[D3D11_PS_CS_UAV_REGISTER_COUNT];
1158 if (!wined3d_bound_range(uav_start_idx, uav_count, ARRAY_SIZE(wined3d_views)))
1160 WARN("View count %u exceeds limit; ignoring call.\n", uav_count);
1161 return;
1164 memset(wined3d_initial_counts, 0xff, sizeof(wined3d_initial_counts));
1166 for (i = 0; i < uav_count; ++i)
1168 struct d3d11_unordered_access_view *view =
1169 unsafe_impl_from_ID3D11UnorderedAccessView(uavs[i]);
1171 wined3d_views[uav_start_idx + i] = view ? view->wined3d_view : NULL;
1172 wined3d_initial_counts[uav_start_idx + i] = initial_counts ? initial_counts[i] : ~0u;
1175 wined3d_mutex_lock();
1176 wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_GRAPHICS,
1177 0, ARRAY_SIZE(wined3d_views), wined3d_views, wined3d_initial_counts);
1178 wined3d_mutex_unlock();
1182 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1183 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1185 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1186 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1187 struct d3d_blend_state *blend_state_impl;
1189 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1190 iface, blend_state, debug_float4(blend_factor), sample_mask);
1192 if (!blend_factor)
1193 blend_factor = default_blend_factor;
1195 wined3d_mutex_lock();
1196 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1197 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1198 (const struct wined3d_color *)blend_factor, sample_mask);
1199 else
1200 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1201 (const struct wined3d_color *)blend_factor, sample_mask);
1202 wined3d_mutex_unlock();
1205 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1206 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1208 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1209 struct d3d_depthstencil_state *state_impl;
1211 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1212 iface, depth_stencil_state, stencil_ref);
1214 wined3d_mutex_lock();
1215 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1217 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1218 wined3d_mutex_unlock();
1219 return;
1222 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1223 wined3d_mutex_unlock();
1226 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1227 ID3D11Buffer *const *buffers, const UINT *offsets)
1229 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
1230 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1231 unsigned int count, i;
1233 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1235 count = min(buffer_count, ARRAY_SIZE(outputs));
1236 for (i = 0; i < count; ++i)
1238 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1240 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
1241 outputs[i].offset = offsets ? offsets[i] : 0;
1244 wined3d_mutex_lock();
1245 wined3d_device_context_set_stream_outputs(context->wined3d_context, outputs);
1246 wined3d_mutex_unlock();
1249 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1251 FIXME("iface %p stub!\n", iface);
1254 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1255 ID3D11Buffer *buffer, UINT offset)
1257 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1258 struct d3d_buffer *d3d_buffer;
1260 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1262 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1264 wined3d_mutex_lock();
1265 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1266 wined3d_mutex_unlock();
1269 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1270 ID3D11Buffer *buffer, UINT offset)
1272 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1273 struct d3d_buffer *d3d_buffer;
1275 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1277 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1279 wined3d_mutex_lock();
1280 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1281 wined3d_mutex_unlock();
1284 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1285 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1287 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1289 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1290 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1292 wined3d_mutex_lock();
1293 wined3d_device_context_dispatch(context->wined3d_context,
1294 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1295 wined3d_mutex_unlock();
1298 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1299 ID3D11Buffer *buffer, UINT offset)
1301 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1302 struct d3d_buffer *buffer_impl;
1304 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1306 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1308 wined3d_mutex_lock();
1309 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1310 wined3d_mutex_unlock();
1313 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1314 ID3D11RasterizerState *rasterizer_state)
1316 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1317 struct d3d_rasterizer_state *rasterizer_state_impl;
1319 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1321 wined3d_mutex_lock();
1322 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1323 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1324 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1325 wined3d_mutex_unlock();
1328 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1329 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1331 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1332 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1333 unsigned int i;
1335 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1337 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1338 return;
1340 for (i = 0; i < viewport_count; ++i)
1342 wined3d_vp[i].x = viewports[i].TopLeftX;
1343 wined3d_vp[i].y = viewports[i].TopLeftY;
1344 wined3d_vp[i].width = viewports[i].Width;
1345 wined3d_vp[i].height = viewports[i].Height;
1346 wined3d_vp[i].min_z = viewports[i].MinDepth;
1347 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1350 wined3d_mutex_lock();
1351 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1352 wined3d_mutex_unlock();
1355 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1356 UINT rect_count, const D3D11_RECT *rects)
1358 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1360 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1362 if (rect_count > WINED3D_MAX_VIEWPORTS)
1363 return;
1365 wined3d_mutex_lock();
1366 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1367 wined3d_mutex_unlock();
1370 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1371 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1372 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1374 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1375 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1376 struct wined3d_box wined3d_src_box;
1378 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1379 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1380 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1381 src_resource, src_subresource_idx, src_box);
1383 if (!dst_resource || !src_resource)
1384 return;
1386 if (src_box)
1387 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1388 src_box->right, src_box->bottom, src_box->front, src_box->back);
1390 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1391 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1392 wined3d_mutex_lock();
1393 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1394 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1395 wined3d_mutex_unlock();
1398 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1399 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1401 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1402 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1404 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1406 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1407 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1408 wined3d_mutex_lock();
1409 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1410 wined3d_mutex_unlock();
1413 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1414 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1415 const void *data, UINT row_pitch, UINT depth_pitch)
1417 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1418 struct wined3d_resource *wined3d_resource;
1419 struct wined3d_box wined3d_box;
1421 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1422 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1424 if (box)
1425 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1427 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1428 wined3d_mutex_lock();
1429 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1430 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1431 wined3d_mutex_unlock();
1434 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1435 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1437 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1438 struct d3d11_unordered_access_view *uav;
1439 struct d3d_buffer *buffer_impl;
1441 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1442 iface, dst_buffer, dst_offset, src_view);
1444 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1445 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1447 wined3d_mutex_lock();
1448 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1449 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1450 wined3d_mutex_unlock();
1453 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1454 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1456 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1457 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1458 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1459 HRESULT hr;
1461 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1462 iface, render_target_view, debug_float4(color_rgba));
1464 if (!view)
1465 return;
1467 wined3d_mutex_lock();
1468 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1469 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1470 ERR("Failed to clear view, hr %#x.\n", hr);
1471 wined3d_mutex_unlock();
1474 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1475 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1477 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1478 struct d3d11_unordered_access_view *view;
1480 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1481 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1483 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1484 wined3d_mutex_lock();
1485 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1486 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1487 wined3d_mutex_unlock();
1490 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1491 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1493 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1494 struct d3d11_unordered_access_view *view;
1496 TRACE("iface %p, unordered_access_view %p, values %s.\n",
1497 iface, unordered_access_view, debug_float4(values));
1499 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1500 wined3d_mutex_lock();
1501 wined3d_device_context_clear_uav_float(context->wined3d_context,
1502 view->wined3d_view, (const struct wined3d_vec4 *)values);
1503 wined3d_mutex_unlock();
1506 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1507 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1509 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1510 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1511 DWORD wined3d_flags;
1512 HRESULT hr;
1514 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1515 iface, depth_stencil_view, flags, depth, stencil);
1517 if (!view)
1518 return;
1520 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1522 wined3d_mutex_lock();
1523 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1524 wined3d_flags, NULL, depth, stencil)))
1525 ERR("Failed to clear view, hr %#x.\n", hr);
1526 wined3d_mutex_unlock();
1529 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1530 ID3D11ShaderResourceView *view)
1532 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1533 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1535 TRACE("iface %p, view %p.\n", iface, view);
1537 wined3d_mutex_lock();
1538 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1539 wined3d_mutex_unlock();
1542 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1543 ID3D11Resource *resource, FLOAT min_lod)
1545 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1548 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1549 ID3D11Resource *resource)
1551 FIXME("iface %p, resource %p stub!\n", iface, resource);
1553 return 0.0f;
1556 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1557 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1558 ID3D11Resource *src_resource, UINT src_subresource_idx,
1559 DXGI_FORMAT format)
1561 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1562 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1563 enum wined3d_format_id wined3d_format;
1565 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1566 "src_resource %p, src_subresource_idx %u, format %s.\n",
1567 iface, dst_resource, dst_subresource_idx,
1568 src_resource, src_subresource_idx, debug_dxgi_format(format));
1570 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1571 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1572 wined3d_format = wined3dformat_from_dxgi_format(format);
1573 wined3d_mutex_lock();
1574 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1575 wined3d_dst_resource, dst_subresource_idx,
1576 wined3d_src_resource, src_subresource_idx, wined3d_format);
1577 wined3d_mutex_unlock();
1580 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1581 ID3D11CommandList *command_list, BOOL restore_state)
1583 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1584 struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);
1586 TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);
1588 wined3d_mutex_lock();
1589 wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
1590 wined3d_mutex_unlock();
1593 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1594 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1596 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1597 iface, start_slot, view_count, views);
1599 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_HULL, start_slot, view_count, views);
1602 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1603 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1605 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1606 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1608 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1609 iface, shader, class_instances, class_instance_count);
1611 if (class_instances)
1612 FIXME("Dynamic linking is not implemented yet.\n");
1614 wined3d_mutex_lock();
1615 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1616 hs ? hs->wined3d_shader : NULL);
1617 wined3d_mutex_unlock();
1620 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1621 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1623 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1624 iface, start_slot, sampler_count, samplers);
1626 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_HULL, start_slot, sampler_count, samplers);
1629 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1630 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1632 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1633 iface, start_slot, buffer_count, buffers);
1635 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1636 buffer_count, buffers, NULL, NULL);
1639 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1640 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1642 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1643 iface, start_slot, view_count, views);
1645 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, view_count, views);
1648 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1649 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1651 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1652 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1654 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1655 iface, shader, class_instances, class_instance_count);
1657 if (class_instances)
1658 FIXME("Dynamic linking is not implemented yet.\n");
1660 wined3d_mutex_lock();
1661 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1662 ds ? ds->wined3d_shader : NULL);
1663 wined3d_mutex_unlock();
1666 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1667 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1669 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1670 iface, start_slot, sampler_count, samplers);
1672 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, sampler_count, samplers);
1675 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1676 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1678 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1679 iface, start_slot, buffer_count, buffers);
1681 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1682 buffer_count, buffers, NULL, NULL);
1685 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1686 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1688 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1689 iface, start_slot, view_count, views);
1691 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, view_count, views);
1694 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1695 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1697 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1698 struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT];
1699 unsigned int i;
1701 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1702 iface, start_slot, view_count, views, initial_counts);
1704 if (view_count > ARRAY_SIZE(wined3d_views))
1706 WARN("View count %u exceeds limit; ignoring call.\n", view_count);
1707 return;
1710 for (i = 0; i < view_count; ++i)
1712 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1714 wined3d_views[i] = view ? view->wined3d_view : NULL;
1717 wined3d_mutex_lock();
1718 wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1719 start_slot, view_count, wined3d_views, initial_counts);
1720 wined3d_mutex_unlock();
1723 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1724 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1726 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1727 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1729 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1730 iface, shader, class_instances, class_instance_count);
1732 if (class_instances)
1733 FIXME("Dynamic linking is not implemented yet.\n");
1735 wined3d_mutex_lock();
1736 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1737 cs ? cs->wined3d_shader : NULL);
1738 wined3d_mutex_unlock();
1741 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1742 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1744 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1745 iface, start_slot, sampler_count, samplers);
1747 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, sampler_count, samplers);
1750 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1751 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1753 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1754 iface, start_slot, buffer_count, buffers);
1756 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1757 buffer_count, buffers, NULL, NULL);
1760 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1761 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1763 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1764 iface, start_slot, buffer_count, buffers);
1766 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1767 buffer_count, buffers, NULL, NULL);
1770 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1771 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1773 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1774 unsigned int i;
1776 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1777 iface, start_slot, view_count, views);
1779 wined3d_mutex_lock();
1780 for (i = 0; i < view_count; ++i)
1782 struct wined3d_shader_resource_view *wined3d_view;
1783 struct d3d_shader_resource_view *view_impl;
1785 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1786 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1788 views[i] = NULL;
1789 continue;
1792 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1793 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1794 ID3D11ShaderResourceView_AddRef(views[i]);
1796 wined3d_mutex_unlock();
1799 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1800 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1802 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1803 struct wined3d_shader *wined3d_shader;
1804 struct d3d_pixel_shader *shader_impl;
1806 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1807 iface, shader, class_instances, class_instance_count);
1809 if (class_instances || class_instance_count)
1810 FIXME("Dynamic linking not implemented yet.\n");
1811 if (class_instance_count)
1812 *class_instance_count = 0;
1814 wined3d_mutex_lock();
1815 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1817 wined3d_mutex_unlock();
1818 *shader = NULL;
1819 return;
1822 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1823 wined3d_mutex_unlock();
1824 *shader = &shader_impl->ID3D11PixelShader_iface;
1825 ID3D11PixelShader_AddRef(*shader);
1828 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1829 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1831 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1832 unsigned int i;
1834 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1835 iface, start_slot, sampler_count, samplers);
1837 wined3d_mutex_lock();
1838 for (i = 0; i < sampler_count; ++i)
1840 struct wined3d_sampler *wined3d_sampler;
1841 struct d3d_sampler_state *sampler_impl;
1843 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1844 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1846 samplers[i] = NULL;
1847 continue;
1850 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1851 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1852 ID3D11SamplerState_AddRef(samplers[i]);
1854 wined3d_mutex_unlock();
1857 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1858 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1860 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1861 struct d3d_vertex_shader *shader_impl;
1862 struct wined3d_shader *wined3d_shader;
1864 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1865 iface, shader, class_instances, class_instance_count);
1867 if (class_instances || class_instance_count)
1868 FIXME("Dynamic linking not implemented yet.\n");
1869 if (class_instance_count)
1870 *class_instance_count = 0;
1872 wined3d_mutex_lock();
1873 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1875 wined3d_mutex_unlock();
1876 *shader = NULL;
1877 return;
1880 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1881 wined3d_mutex_unlock();
1882 *shader = &shader_impl->ID3D11VertexShader_iface;
1883 ID3D11VertexShader_AddRef(*shader);
1886 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1887 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1889 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1890 iface, start_slot, buffer_count, buffers);
1892 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1893 buffer_count, buffers, NULL, NULL);
1896 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1897 ID3D11InputLayout **input_layout)
1899 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1900 struct wined3d_vertex_declaration *wined3d_declaration;
1901 struct d3d_input_layout *input_layout_impl;
1903 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1905 wined3d_mutex_lock();
1906 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1908 wined3d_mutex_unlock();
1909 *input_layout = NULL;
1910 return;
1913 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1914 wined3d_mutex_unlock();
1915 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1916 ID3D11InputLayout_AddRef(*input_layout);
1919 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1920 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1922 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1923 unsigned int i;
1925 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1926 iface, start_slot, buffer_count, buffers, strides, offsets);
1928 wined3d_mutex_lock();
1929 for (i = 0; i < buffer_count; ++i)
1931 struct wined3d_buffer *wined3d_buffer = NULL;
1932 struct d3d_buffer *buffer_impl;
1934 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1935 &wined3d_buffer, &offsets[i], &strides[i])))
1937 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1938 if (strides)
1939 strides[i] = 0;
1940 if (offsets)
1941 offsets[i] = 0;
1944 if (!wined3d_buffer)
1946 buffers[i] = NULL;
1947 continue;
1950 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1951 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1953 wined3d_mutex_unlock();
1956 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1957 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1959 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1960 enum wined3d_format_id wined3d_format;
1961 struct wined3d_buffer *wined3d_buffer;
1962 struct d3d_buffer *buffer_impl;
1964 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1966 wined3d_mutex_lock();
1967 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1968 *format = dxgi_format_from_wined3dformat(wined3d_format);
1969 if (!wined3d_buffer)
1971 wined3d_mutex_unlock();
1972 *buffer = NULL;
1973 return;
1976 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1977 wined3d_mutex_unlock();
1978 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1981 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1982 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1984 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1985 iface, start_slot, buffer_count, buffers);
1987 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1988 buffer_count, buffers, NULL, NULL);
1991 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1992 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1994 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1995 struct d3d_geometry_shader *shader_impl;
1996 struct wined3d_shader *wined3d_shader;
1998 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1999 iface, shader, class_instances, class_instance_count);
2001 if (class_instances || class_instance_count)
2002 FIXME("Dynamic linking not implemented yet.\n");
2003 if (class_instance_count)
2004 *class_instance_count = 0;
2006 wined3d_mutex_lock();
2007 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
2009 wined3d_mutex_unlock();
2010 *shader = NULL;
2011 return;
2014 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2015 wined3d_mutex_unlock();
2016 *shader = &shader_impl->ID3D11GeometryShader_iface;
2017 ID3D11GeometryShader_AddRef(*shader);
2020 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
2021 D3D11_PRIMITIVE_TOPOLOGY *topology)
2023 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2024 enum wined3d_primitive_type primitive_type;
2025 unsigned int patch_vertex_count;
2027 TRACE("iface %p, topology %p.\n", iface, topology);
2029 wined3d_mutex_lock();
2030 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
2031 wined3d_mutex_unlock();
2033 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
2036 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
2037 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2039 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2040 unsigned int i;
2042 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2044 wined3d_mutex_lock();
2045 for (i = 0; i < view_count; ++i)
2047 struct wined3d_shader_resource_view *wined3d_view;
2048 struct d3d_shader_resource_view *view_impl;
2050 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2051 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2053 views[i] = NULL;
2054 continue;
2057 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2058 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2059 ID3D11ShaderResourceView_AddRef(views[i]);
2061 wined3d_mutex_unlock();
2064 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
2065 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2067 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2068 unsigned int i;
2070 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2071 iface, start_slot, sampler_count, samplers);
2073 wined3d_mutex_lock();
2074 for (i = 0; i < sampler_count; ++i)
2076 struct wined3d_sampler *wined3d_sampler;
2077 struct d3d_sampler_state *sampler_impl;
2079 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2080 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2082 samplers[i] = NULL;
2083 continue;
2086 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2087 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2088 ID3D11SamplerState_AddRef(samplers[i]);
2090 wined3d_mutex_unlock();
2093 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2094 ID3D11Predicate **predicate, BOOL *value)
2096 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2097 struct wined3d_query *wined3d_predicate;
2098 struct d3d_query *predicate_impl;
2100 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2102 wined3d_mutex_lock();
2103 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2105 wined3d_mutex_unlock();
2106 *predicate = NULL;
2107 return;
2110 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2111 wined3d_mutex_unlock();
2112 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2113 ID3D11Predicate_AddRef(*predicate);
2116 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2117 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2119 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2120 unsigned int i;
2122 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2124 wined3d_mutex_lock();
2125 for (i = 0; i < view_count; ++i)
2127 struct wined3d_shader_resource_view *wined3d_view;
2128 struct d3d_shader_resource_view *view_impl;
2130 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2131 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2133 views[i] = NULL;
2134 continue;
2137 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2138 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2139 ID3D11ShaderResourceView_AddRef(views[i]);
2141 wined3d_mutex_unlock();
2144 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2145 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2147 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2148 unsigned int i;
2150 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2151 iface, start_slot, sampler_count, samplers);
2153 wined3d_mutex_lock();
2154 for (i = 0; i < sampler_count; ++i)
2156 struct d3d_sampler_state *sampler_impl;
2157 struct wined3d_sampler *wined3d_sampler;
2159 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2160 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2162 samplers[i] = NULL;
2163 continue;
2166 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2167 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2168 ID3D11SamplerState_AddRef(samplers[i]);
2170 wined3d_mutex_unlock();
2173 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2174 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2175 ID3D11DepthStencilView **depth_stencil_view)
2177 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2178 struct wined3d_rendertarget_view *wined3d_view;
2180 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2181 iface, render_target_view_count, render_target_views, depth_stencil_view);
2183 wined3d_mutex_lock();
2184 if (render_target_views)
2186 struct d3d_rendertarget_view *view_impl;
2187 unsigned int i;
2189 for (i = 0; i < render_target_view_count; ++i)
2191 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2192 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2194 render_target_views[i] = NULL;
2195 continue;
2198 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2199 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2203 if (depth_stencil_view)
2205 struct d3d_depthstencil_view *view_impl;
2207 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2208 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2210 *depth_stencil_view = NULL;
2212 else
2214 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2215 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2218 wined3d_mutex_unlock();
2221 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2222 ID3D11DeviceContext1 *iface,
2223 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2224 ID3D11DepthStencilView **depth_stencil_view,
2225 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2226 ID3D11UnorderedAccessView **unordered_access_views)
2228 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2229 struct wined3d_unordered_access_view *wined3d_view;
2230 struct d3d11_unordered_access_view *view_impl;
2231 unsigned int i;
2233 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2234 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2235 "unordered_access_views %p.\n",
2236 iface, render_target_view_count, render_target_views, depth_stencil_view,
2237 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2239 if (render_target_views || depth_stencil_view)
2240 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2241 render_target_views, depth_stencil_view);
2243 if (unordered_access_views)
2245 wined3d_mutex_lock();
2246 for (i = 0; i < unordered_access_view_count; ++i)
2248 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2249 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2251 unordered_access_views[i] = NULL;
2252 continue;
2255 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2256 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2257 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2259 wined3d_mutex_unlock();
2263 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2264 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2266 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2267 struct wined3d_blend_state *wined3d_state;
2268 struct d3d_blend_state *blend_state_impl;
2270 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2271 iface, blend_state, blend_factor, sample_mask);
2273 wined3d_mutex_lock();
2274 if ((wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2275 (struct wined3d_color *)blend_factor, sample_mask)))
2277 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2278 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2280 else
2282 *blend_state = NULL;
2284 wined3d_mutex_unlock();
2287 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2288 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2290 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2291 struct wined3d_depth_stencil_state *wined3d_state;
2292 struct d3d_depthstencil_state *state_impl;
2294 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2295 iface, depth_stencil_state, stencil_ref);
2297 wined3d_mutex_lock();
2298 if ((wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref)))
2300 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2301 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2303 else
2305 *depth_stencil_state = NULL;
2307 wined3d_mutex_unlock();
2310 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2311 UINT buffer_count, ID3D11Buffer **buffers)
2313 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2314 unsigned int i;
2316 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2318 wined3d_mutex_lock();
2319 for (i = 0; i < buffer_count; ++i)
2321 struct wined3d_buffer *wined3d_buffer;
2322 struct d3d_buffer *buffer_impl;
2324 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2326 buffers[i] = NULL;
2327 continue;
2330 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2331 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2332 ID3D11Buffer_AddRef(buffers[i]);
2334 wined3d_mutex_unlock();
2337 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2338 ID3D11RasterizerState **rasterizer_state)
2340 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2341 struct d3d_rasterizer_state *rasterizer_state_impl;
2342 struct wined3d_rasterizer_state *wined3d_state;
2344 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2346 wined3d_mutex_lock();
2347 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2349 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2350 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2352 else
2354 *rasterizer_state = NULL;
2356 wined3d_mutex_unlock();
2359 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2360 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2362 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2363 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2364 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2366 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2368 if (!viewport_count)
2369 return;
2371 wined3d_mutex_lock();
2372 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2373 wined3d_mutex_unlock();
2375 if (!viewports)
2377 *viewport_count = actual_count;
2378 return;
2381 if (*viewport_count > actual_count)
2382 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2384 *viewport_count = min(actual_count, *viewport_count);
2385 for (i = 0; i < *viewport_count; ++i)
2387 viewports[i].TopLeftX = wined3d_vp[i].x;
2388 viewports[i].TopLeftY = wined3d_vp[i].y;
2389 viewports[i].Width = wined3d_vp[i].width;
2390 viewports[i].Height = wined3d_vp[i].height;
2391 viewports[i].MinDepth = wined3d_vp[i].min_z;
2392 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2396 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2397 UINT *rect_count, D3D11_RECT *rects)
2399 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2400 unsigned int actual_count;
2402 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2404 if (!rect_count)
2405 return;
2407 actual_count = *rect_count;
2409 wined3d_mutex_lock();
2410 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2411 wined3d_mutex_unlock();
2413 if (rects && *rect_count > actual_count)
2414 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2415 *rect_count = actual_count;
2418 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2419 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2421 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2422 unsigned int i;
2424 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2426 wined3d_mutex_lock();
2427 for (i = 0; i < view_count; ++i)
2429 struct wined3d_shader_resource_view *wined3d_view;
2430 struct d3d_shader_resource_view *view_impl;
2432 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2433 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2435 views[i] = NULL;
2436 continue;
2439 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2440 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2442 wined3d_mutex_unlock();
2445 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2446 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2448 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2449 struct d3d11_hull_shader *shader_impl;
2450 struct wined3d_shader *wined3d_shader;
2452 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2453 iface, shader, class_instances, class_instance_count);
2455 if (class_instances || class_instance_count)
2456 FIXME("Dynamic linking not implemented yet.\n");
2457 if (class_instance_count)
2458 *class_instance_count = 0;
2460 wined3d_mutex_lock();
2461 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2463 wined3d_mutex_unlock();
2464 *shader = NULL;
2465 return;
2468 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2469 wined3d_mutex_unlock();
2470 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2473 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2474 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2476 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2477 unsigned int i;
2479 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2480 iface, start_slot, sampler_count, samplers);
2482 wined3d_mutex_lock();
2483 for (i = 0; i < sampler_count; ++i)
2485 struct wined3d_sampler *wined3d_sampler;
2486 struct d3d_sampler_state *sampler_impl;
2488 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2489 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2491 samplers[i] = NULL;
2492 continue;
2495 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2496 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2498 wined3d_mutex_unlock();
2501 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2502 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2504 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2505 iface, start_slot, buffer_count, buffers);
2507 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2508 buffer_count, buffers, NULL, NULL);
2511 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2512 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2514 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2515 unsigned int i;
2517 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2518 iface, start_slot, view_count, views);
2520 wined3d_mutex_lock();
2521 for (i = 0; i < view_count; ++i)
2523 struct wined3d_shader_resource_view *wined3d_view;
2524 struct d3d_shader_resource_view *view_impl;
2526 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2527 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2529 views[i] = NULL;
2530 continue;
2533 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2534 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2536 wined3d_mutex_unlock();
2539 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2540 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2542 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2543 struct d3d11_domain_shader *shader_impl;
2544 struct wined3d_shader *wined3d_shader;
2546 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2547 iface, shader, class_instances, class_instance_count);
2549 if (class_instances || class_instance_count)
2550 FIXME("Dynamic linking not implemented yet.\n");
2551 if (class_instance_count)
2552 *class_instance_count = 0;
2554 wined3d_mutex_lock();
2555 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2557 wined3d_mutex_unlock();
2558 *shader = NULL;
2559 return;
2562 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2563 wined3d_mutex_unlock();
2564 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2567 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2568 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2570 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2571 unsigned int i;
2573 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2574 iface, start_slot, sampler_count, samplers);
2576 wined3d_mutex_lock();
2577 for (i = 0; i < sampler_count; ++i)
2579 struct wined3d_sampler *wined3d_sampler;
2580 struct d3d_sampler_state *sampler_impl;
2582 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2583 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2585 samplers[i] = NULL;
2586 continue;
2589 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2590 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2592 wined3d_mutex_unlock();
2595 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2596 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2598 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2599 iface, start_slot, buffer_count, buffers);
2601 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2602 buffer_count, buffers, NULL, NULL);
2605 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2606 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2608 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2609 unsigned int i;
2611 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2613 wined3d_mutex_lock();
2614 for (i = 0; i < view_count; ++i)
2616 struct wined3d_shader_resource_view *wined3d_view;
2617 struct d3d_shader_resource_view *view_impl;
2619 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2620 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2622 views[i] = NULL;
2623 continue;
2626 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2627 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2629 wined3d_mutex_unlock();
2632 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2633 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2635 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2636 unsigned int i;
2638 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2640 wined3d_mutex_lock();
2641 for (i = 0; i < view_count; ++i)
2643 struct wined3d_unordered_access_view *wined3d_view;
2644 struct d3d11_unordered_access_view *view_impl;
2646 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2647 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2649 views[i] = NULL;
2650 continue;
2653 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2654 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2656 wined3d_mutex_unlock();
2659 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2660 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2662 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2663 struct d3d11_compute_shader *shader_impl;
2664 struct wined3d_shader *wined3d_shader;
2666 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2667 iface, shader, class_instances, class_instance_count);
2669 if (class_instances || class_instance_count)
2670 FIXME("Dynamic linking not implemented yet.\n");
2671 if (class_instance_count)
2672 *class_instance_count = 0;
2674 wined3d_mutex_lock();
2675 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2677 wined3d_mutex_unlock();
2678 *shader = NULL;
2679 return;
2682 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2683 wined3d_mutex_unlock();
2684 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2687 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2688 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2690 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2691 unsigned int i;
2693 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2694 iface, start_slot, sampler_count, samplers);
2696 wined3d_mutex_lock();
2697 for (i = 0; i < sampler_count; ++i)
2699 struct wined3d_sampler *wined3d_sampler;
2700 struct d3d_sampler_state *sampler_impl;
2702 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2703 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2705 samplers[i] = NULL;
2706 continue;
2709 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2710 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2712 wined3d_mutex_unlock();
2715 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2716 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2718 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2719 iface, start_slot, buffer_count, buffers);
2721 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2722 buffer_count, buffers, NULL, NULL);
2725 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2727 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2729 TRACE("iface %p.\n", iface);
2731 wined3d_mutex_lock();
2732 wined3d_device_context_reset_state(context->wined3d_context);
2733 wined3d_mutex_unlock();
2736 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2738 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2740 TRACE("iface %p.\n", iface);
2742 wined3d_mutex_lock();
2743 wined3d_device_context_flush(context->wined3d_context);
2744 wined3d_mutex_unlock();
2747 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2749 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2751 TRACE("iface %p.\n", iface);
2753 return context->type;
2756 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2758 TRACE("iface %p.\n", iface);
2760 return 0;
2763 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2764 BOOL restore, ID3D11CommandList **command_list)
2766 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2767 struct d3d11_command_list *object;
2768 HRESULT hr;
2770 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2772 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2774 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2775 return DXGI_ERROR_INVALID_CALL;
2778 if (!(object = heap_alloc_zero(sizeof(*object))))
2779 return E_OUTOFMEMORY;
2781 wined3d_mutex_lock();
2783 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2784 !!restore, &object->wined3d_list)))
2786 WARN("Failed to record wined3d command list, hr %#x.\n", hr);
2787 heap_free(object);
2788 return hr;
2791 wined3d_mutex_unlock();
2793 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2794 object->refcount = 1;
2795 object->device = &context->device->ID3D11Device2_iface;
2796 wined3d_private_store_init(&object->private_store);
2798 ID3D11Device2_AddRef(object->device);
2800 TRACE("Created command list %p.\n", object);
2801 *command_list = &object->ID3D11CommandList_iface;
2803 return S_OK;
2806 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2807 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2808 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2810 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2811 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2812 struct wined3d_box wined3d_src_box;
2814 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2815 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2816 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2817 src_resource, src_subresource_idx, src_box, flags);
2819 if (!dst_resource || !src_resource)
2820 return;
2822 if (src_box)
2823 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2824 src_box->right, src_box->bottom, src_box->front, src_box->back);
2826 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2827 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2828 wined3d_mutex_lock();
2829 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2830 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2831 wined3d_mutex_unlock();
2834 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2835 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2836 UINT row_pitch, UINT depth_pitch, UINT flags)
2838 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2839 struct wined3d_resource *wined3d_resource;
2840 struct wined3d_box wined3d_box;
2842 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2843 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2845 if (box)
2846 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2847 box->front, box->back);
2849 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2850 wined3d_mutex_lock();
2851 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2852 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2853 wined3d_mutex_unlock();
2856 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2857 ID3D11Resource *resource)
2859 FIXME("iface %p, resource %p stub!\n", iface, resource);
2862 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2864 FIXME("iface %p, view %p stub!\n", iface, view);
2867 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2868 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2869 const UINT *num_constants)
2871 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2872 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2874 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2875 buffer_count, buffers, first_constant, num_constants);
2878 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2879 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2880 const UINT *num_constants)
2882 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2883 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2885 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2886 buffer_count, buffers, first_constant, num_constants);
2889 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2890 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2891 const UINT *num_constants)
2893 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2894 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2896 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2897 buffer_count, buffers, first_constant, num_constants);
2900 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2901 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2902 const UINT *num_constants)
2904 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2905 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2907 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2908 buffer_count, buffers, first_constant, num_constants);
2911 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2912 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2913 const UINT *num_constants)
2915 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2916 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2918 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2919 buffer_count, buffers, first_constant, num_constants);
2922 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2923 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2924 const UINT *num_constants)
2926 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2927 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2929 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2930 buffer_count, buffers, first_constant, num_constants);
2933 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2934 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2936 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2937 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2939 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2940 buffer_count, buffers, first_constant, num_constants);
2943 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2944 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2946 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2947 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2949 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2950 buffer_count, buffers, first_constant, num_constants);
2953 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2954 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2956 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2957 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2959 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2960 buffer_count, buffers, first_constant, num_constants);
2963 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2964 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2966 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2967 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2969 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2970 buffer_count, buffers, first_constant, num_constants);
2973 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2974 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2976 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2977 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2979 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2980 buffer_count, buffers, first_constant, num_constants);
2983 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2984 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2986 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2987 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2989 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2990 buffer_count, buffers, first_constant, num_constants);
2993 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2994 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2996 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2997 struct d3d_device_context_state *state_impl, *prev_impl;
2998 struct d3d_device *device = context->device;
2999 struct wined3d_state *wined3d_state;
3000 static unsigned int once;
3002 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
3004 if (prev)
3005 *prev = NULL;
3007 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
3009 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
3010 return;
3013 if (!state)
3014 return;
3016 wined3d_mutex_lock();
3018 prev_impl = device->state;
3019 state_impl = impl_from_ID3DDeviceContextState(state);
3020 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
3021 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
3022 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
3024 if (prev)
3025 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
3027 d3d_device_context_state_private_addref(state_impl);
3028 device->state = state_impl;
3029 d3d_device_context_state_private_release(prev_impl);
3031 if (d3d_device_is_d3d10_active(device) && !once++)
3032 FIXME("D3D10 interface emulation not fully implemented yet!\n");
3033 wined3d_mutex_unlock();
3036 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
3037 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
3039 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
3042 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
3043 const D3D11_RECT *rects, UINT num_rects)
3045 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
3048 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
3050 /* IUnknown methods */
3051 d3d11_device_context_QueryInterface,
3052 d3d11_device_context_AddRef,
3053 d3d11_device_context_Release,
3054 /* ID3D11DeviceChild methods */
3055 d3d11_device_context_GetDevice,
3056 d3d11_device_context_GetPrivateData,
3057 d3d11_device_context_SetPrivateData,
3058 d3d11_device_context_SetPrivateDataInterface,
3059 /* ID3D11DeviceContext methods */
3060 d3d11_device_context_VSSetConstantBuffers,
3061 d3d11_device_context_PSSetShaderResources,
3062 d3d11_device_context_PSSetShader,
3063 d3d11_device_context_PSSetSamplers,
3064 d3d11_device_context_VSSetShader,
3065 d3d11_device_context_DrawIndexed,
3066 d3d11_device_context_Draw,
3067 d3d11_device_context_Map,
3068 d3d11_device_context_Unmap,
3069 d3d11_device_context_PSSetConstantBuffers,
3070 d3d11_device_context_IASetInputLayout,
3071 d3d11_device_context_IASetVertexBuffers,
3072 d3d11_device_context_IASetIndexBuffer,
3073 d3d11_device_context_DrawIndexedInstanced,
3074 d3d11_device_context_DrawInstanced,
3075 d3d11_device_context_GSSetConstantBuffers,
3076 d3d11_device_context_GSSetShader,
3077 d3d11_device_context_IASetPrimitiveTopology,
3078 d3d11_device_context_VSSetShaderResources,
3079 d3d11_device_context_VSSetSamplers,
3080 d3d11_device_context_Begin,
3081 d3d11_device_context_End,
3082 d3d11_device_context_GetData,
3083 d3d11_device_context_SetPredication,
3084 d3d11_device_context_GSSetShaderResources,
3085 d3d11_device_context_GSSetSamplers,
3086 d3d11_device_context_OMSetRenderTargets,
3087 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3088 d3d11_device_context_OMSetBlendState,
3089 d3d11_device_context_OMSetDepthStencilState,
3090 d3d11_device_context_SOSetTargets,
3091 d3d11_device_context_DrawAuto,
3092 d3d11_device_context_DrawIndexedInstancedIndirect,
3093 d3d11_device_context_DrawInstancedIndirect,
3094 d3d11_device_context_Dispatch,
3095 d3d11_device_context_DispatchIndirect,
3096 d3d11_device_context_RSSetState,
3097 d3d11_device_context_RSSetViewports,
3098 d3d11_device_context_RSSetScissorRects,
3099 d3d11_device_context_CopySubresourceRegion,
3100 d3d11_device_context_CopyResource,
3101 d3d11_device_context_UpdateSubresource,
3102 d3d11_device_context_CopyStructureCount,
3103 d3d11_device_context_ClearRenderTargetView,
3104 d3d11_device_context_ClearUnorderedAccessViewUint,
3105 d3d11_device_context_ClearUnorderedAccessViewFloat,
3106 d3d11_device_context_ClearDepthStencilView,
3107 d3d11_device_context_GenerateMips,
3108 d3d11_device_context_SetResourceMinLOD,
3109 d3d11_device_context_GetResourceMinLOD,
3110 d3d11_device_context_ResolveSubresource,
3111 d3d11_device_context_ExecuteCommandList,
3112 d3d11_device_context_HSSetShaderResources,
3113 d3d11_device_context_HSSetShader,
3114 d3d11_device_context_HSSetSamplers,
3115 d3d11_device_context_HSSetConstantBuffers,
3116 d3d11_device_context_DSSetShaderResources,
3117 d3d11_device_context_DSSetShader,
3118 d3d11_device_context_DSSetSamplers,
3119 d3d11_device_context_DSSetConstantBuffers,
3120 d3d11_device_context_CSSetShaderResources,
3121 d3d11_device_context_CSSetUnorderedAccessViews,
3122 d3d11_device_context_CSSetShader,
3123 d3d11_device_context_CSSetSamplers,
3124 d3d11_device_context_CSSetConstantBuffers,
3125 d3d11_device_context_VSGetConstantBuffers,
3126 d3d11_device_context_PSGetShaderResources,
3127 d3d11_device_context_PSGetShader,
3128 d3d11_device_context_PSGetSamplers,
3129 d3d11_device_context_VSGetShader,
3130 d3d11_device_context_PSGetConstantBuffers,
3131 d3d11_device_context_IAGetInputLayout,
3132 d3d11_device_context_IAGetVertexBuffers,
3133 d3d11_device_context_IAGetIndexBuffer,
3134 d3d11_device_context_GSGetConstantBuffers,
3135 d3d11_device_context_GSGetShader,
3136 d3d11_device_context_IAGetPrimitiveTopology,
3137 d3d11_device_context_VSGetShaderResources,
3138 d3d11_device_context_VSGetSamplers,
3139 d3d11_device_context_GetPredication,
3140 d3d11_device_context_GSGetShaderResources,
3141 d3d11_device_context_GSGetSamplers,
3142 d3d11_device_context_OMGetRenderTargets,
3143 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3144 d3d11_device_context_OMGetBlendState,
3145 d3d11_device_context_OMGetDepthStencilState,
3146 d3d11_device_context_SOGetTargets,
3147 d3d11_device_context_RSGetState,
3148 d3d11_device_context_RSGetViewports,
3149 d3d11_device_context_RSGetScissorRects,
3150 d3d11_device_context_HSGetShaderResources,
3151 d3d11_device_context_HSGetShader,
3152 d3d11_device_context_HSGetSamplers,
3153 d3d11_device_context_HSGetConstantBuffers,
3154 d3d11_device_context_DSGetShaderResources,
3155 d3d11_device_context_DSGetShader,
3156 d3d11_device_context_DSGetSamplers,
3157 d3d11_device_context_DSGetConstantBuffers,
3158 d3d11_device_context_CSGetShaderResources,
3159 d3d11_device_context_CSGetUnorderedAccessViews,
3160 d3d11_device_context_CSGetShader,
3161 d3d11_device_context_CSGetSamplers,
3162 d3d11_device_context_CSGetConstantBuffers,
3163 d3d11_device_context_ClearState,
3164 d3d11_device_context_Flush,
3165 d3d11_device_context_GetType,
3166 d3d11_device_context_GetContextFlags,
3167 d3d11_device_context_FinishCommandList,
3168 /* ID3D11DeviceContext1 methods */
3169 d3d11_device_context_CopySubresourceRegion1,
3170 d3d11_device_context_UpdateSubresource1,
3171 d3d11_device_context_DiscardResource,
3172 d3d11_device_context_DiscardView,
3173 d3d11_device_context_VSSetConstantBuffers1,
3174 d3d11_device_context_HSSetConstantBuffers1,
3175 d3d11_device_context_DSSetConstantBuffers1,
3176 d3d11_device_context_GSSetConstantBuffers1,
3177 d3d11_device_context_PSSetConstantBuffers1,
3178 d3d11_device_context_CSSetConstantBuffers1,
3179 d3d11_device_context_VSGetConstantBuffers1,
3180 d3d11_device_context_HSGetConstantBuffers1,
3181 d3d11_device_context_DSGetConstantBuffers1,
3182 d3d11_device_context_GSGetConstantBuffers1,
3183 d3d11_device_context_PSGetConstantBuffers1,
3184 d3d11_device_context_CSGetConstantBuffers1,
3185 d3d11_device_context_SwapDeviceContextState,
3186 d3d11_device_context_ClearView,
3187 d3d11_device_context_DiscardView1,
3190 /* ID3D11Multithread methods */
3192 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3194 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3197 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3198 REFIID iid, void **out)
3200 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3202 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3204 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3207 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3209 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3211 TRACE("iface %p.\n", iface);
3213 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3216 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3218 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3220 TRACE("iface %p.\n", iface);
3222 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3225 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3227 TRACE("iface %p.\n", iface);
3229 wined3d_mutex_lock();
3232 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3234 TRACE("iface %p.\n", iface);
3236 wined3d_mutex_unlock();
3239 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3240 ID3D11Multithread *iface, BOOL enable)
3242 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3244 return TRUE;
3247 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3249 FIXME("iface %p stub!\n", iface);
3251 return TRUE;
3254 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3256 d3d11_multithread_QueryInterface,
3257 d3d11_multithread_AddRef,
3258 d3d11_multithread_Release,
3259 d3d11_multithread_Enter,
3260 d3d11_multithread_Leave,
3261 d3d11_multithread_SetMultithreadProtected,
3262 d3d11_multithread_GetMultithreadProtected,
3265 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3266 D3D11_DEVICE_CONTEXT_TYPE type)
3268 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3269 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3270 context->refcount = 1;
3271 context->type = type;
3273 context->device = device;
3274 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3276 wined3d_private_store_init(&context->private_store);
3279 /* ID3D11Device methods */
3281 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3283 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3284 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3287 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3289 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3290 return IUnknown_AddRef(device->outer_unk);
3293 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3295 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3296 return IUnknown_Release(device->outer_unk);
3299 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3300 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3302 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3303 struct d3d_buffer *object;
3304 HRESULT hr;
3306 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3308 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3309 return hr;
3311 *buffer = &object->ID3D11Buffer_iface;
3313 return S_OK;
3316 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3317 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3319 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3320 struct d3d_texture1d *object;
3321 HRESULT hr;
3323 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3325 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3326 return hr;
3328 *texture = &object->ID3D11Texture1D_iface;
3330 return S_OK;
3333 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3334 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3336 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3337 struct d3d_texture2d *object;
3338 HRESULT hr;
3340 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3342 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3343 return hr;
3345 *texture = &object->ID3D11Texture2D_iface;
3347 return S_OK;
3350 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3351 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3353 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3354 struct d3d_texture3d *object;
3355 HRESULT hr;
3357 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3359 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3360 return hr;
3362 *texture = &object->ID3D11Texture3D_iface;
3364 return S_OK;
3367 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3368 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3370 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3371 struct d3d_shader_resource_view *object;
3372 HRESULT hr;
3374 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3376 if (!resource)
3377 return E_INVALIDARG;
3379 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3380 return hr;
3382 *view = &object->ID3D11ShaderResourceView_iface;
3384 return S_OK;
3387 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3388 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3390 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3391 struct d3d11_unordered_access_view *object;
3392 HRESULT hr;
3394 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3396 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3397 return hr;
3399 *view = &object->ID3D11UnorderedAccessView_iface;
3401 return S_OK;
3404 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3405 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3407 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3408 struct d3d_rendertarget_view *object;
3409 HRESULT hr;
3411 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3413 if (!resource)
3414 return E_INVALIDARG;
3416 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3417 return hr;
3419 *view = &object->ID3D11RenderTargetView_iface;
3421 return S_OK;
3424 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3425 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3427 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3428 struct d3d_depthstencil_view *object;
3429 HRESULT hr;
3431 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3433 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3434 return hr;
3436 *view = &object->ID3D11DepthStencilView_iface;
3438 return S_OK;
3441 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3442 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3443 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3445 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3446 struct d3d_input_layout *object;
3447 HRESULT hr;
3449 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3450 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3451 shader_byte_code_length, input_layout);
3453 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3454 shader_byte_code, shader_byte_code_length, &object)))
3455 return hr;
3457 *input_layout = &object->ID3D11InputLayout_iface;
3459 return S_OK;
3462 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3463 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3465 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3466 struct d3d_vertex_shader *object;
3467 HRESULT hr;
3469 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3470 iface, byte_code, byte_code_length, class_linkage, shader);
3472 if (class_linkage)
3473 FIXME("Class linkage is not implemented yet.\n");
3475 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3476 return hr;
3478 *shader = &object->ID3D11VertexShader_iface;
3480 return S_OK;
3483 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3484 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3486 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3487 struct d3d_geometry_shader *object;
3488 HRESULT hr;
3490 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3491 iface, byte_code, byte_code_length, class_linkage, shader);
3493 if (class_linkage)
3494 FIXME("Class linkage is not implemented yet.\n");
3496 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3497 NULL, 0, NULL, 0, 0, &object)))
3498 return hr;
3500 *shader = &object->ID3D11GeometryShader_iface;
3502 return S_OK;
3505 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3506 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3507 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3508 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3510 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3511 struct d3d_geometry_shader *object;
3512 HRESULT hr;
3514 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3515 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3516 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3517 rasterizer_stream, class_linkage, shader);
3519 if (class_linkage)
3520 FIXME("Class linkage is not implemented yet.\n");
3522 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3523 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3525 *shader = NULL;
3526 return hr;
3529 *shader = &object->ID3D11GeometryShader_iface;
3531 return hr;
3534 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3535 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3537 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3538 struct d3d_pixel_shader *object;
3539 HRESULT hr;
3541 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3542 iface, byte_code, byte_code_length, class_linkage, shader);
3544 if (class_linkage)
3545 FIXME("Class linkage is not implemented yet.\n");
3547 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3548 return hr;
3550 *shader = &object->ID3D11PixelShader_iface;
3552 return S_OK;
3555 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3556 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3558 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3559 struct d3d11_hull_shader *object;
3560 HRESULT hr;
3562 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3563 iface, byte_code, byte_code_length, class_linkage, shader);
3565 if (class_linkage)
3566 FIXME("Class linkage is not implemented yet.\n");
3568 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3569 return hr;
3571 *shader = &object->ID3D11HullShader_iface;
3573 return S_OK;
3576 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3577 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3579 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3580 struct d3d11_domain_shader *object;
3581 HRESULT hr;
3583 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3584 iface, byte_code, byte_code_length, class_linkage, shader);
3586 if (class_linkage)
3587 FIXME("Class linkage is not implemented yet.\n");
3589 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3590 return hr;
3592 *shader = &object->ID3D11DomainShader_iface;
3594 return S_OK;
3597 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3598 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3600 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3601 struct d3d11_compute_shader *object;
3602 HRESULT hr;
3604 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3605 iface, byte_code, byte_code_length, class_linkage, shader);
3607 if (class_linkage)
3608 FIXME("Class linkage is not implemented yet.\n");
3610 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3611 return hr;
3613 *shader = &object->ID3D11ComputeShader_iface;
3615 return S_OK;
3618 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3619 ID3D11ClassLinkage **class_linkage)
3621 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3622 struct d3d11_class_linkage *object;
3623 HRESULT hr;
3625 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3627 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3628 return hr;
3630 *class_linkage = &object->ID3D11ClassLinkage_iface;
3632 return S_OK;
3635 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3636 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3638 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3639 struct d3d_blend_state *object;
3640 HRESULT hr;
3642 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3644 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3645 return hr;
3647 *blend_state = &object->ID3D11BlendState_iface;
3649 return S_OK;
3652 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3653 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3655 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3656 struct d3d_depthstencil_state *object;
3657 HRESULT hr;
3659 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3661 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3662 return hr;
3664 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3666 return S_OK;
3669 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3670 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3672 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3673 struct d3d_rasterizer_state *object;
3674 HRESULT hr;
3676 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3678 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3679 return hr;
3681 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3683 return S_OK;
3686 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3687 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3689 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3690 struct d3d_sampler_state *object;
3691 HRESULT hr;
3693 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3695 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3696 return hr;
3698 *sampler_state = &object->ID3D11SamplerState_iface;
3700 return S_OK;
3703 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3704 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3706 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3707 struct d3d_query *object;
3708 HRESULT hr;
3710 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3712 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3713 return hr;
3715 if (query)
3717 *query = &object->ID3D11Query_iface;
3718 return S_OK;
3721 ID3D11Query_Release(&object->ID3D11Query_iface);
3722 return S_FALSE;
3725 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3726 ID3D11Predicate **predicate)
3728 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3729 struct d3d_query *object;
3730 HRESULT hr;
3732 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3734 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3735 return hr;
3737 if (predicate)
3739 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3740 return S_OK;
3743 ID3D11Query_Release(&object->ID3D11Query_iface);
3744 return S_FALSE;
3747 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3748 ID3D11Counter **counter)
3750 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3752 return E_NOTIMPL;
3755 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3756 UINT flags, struct d3d11_device_context **context)
3758 struct d3d11_device_context *object;
3759 HRESULT hr;
3761 if (flags)
3762 FIXME("Ignoring flags %#x.\n", flags);
3764 if (!(object = heap_alloc_zero(sizeof(*object))))
3765 return E_OUTOFMEMORY;
3766 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3768 wined3d_mutex_lock();
3769 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3771 WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
3772 heap_free(object);
3773 wined3d_mutex_unlock();
3774 return hr;
3776 wined3d_mutex_unlock();
3778 TRACE("Created deferred context %p.\n", object);
3779 *context = object;
3781 return S_OK;
3784 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3785 ID3D11DeviceContext **context)
3787 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3788 struct d3d11_device_context *object;
3789 HRESULT hr;
3791 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3793 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3794 return hr;
3796 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3797 return S_OK;
3800 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3801 void **out)
3803 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3805 return E_NOTIMPL;
3808 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3809 UINT *format_support)
3811 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3812 struct wined3d_device_creation_parameters params;
3813 struct wined3d_adapter *wined3d_adapter;
3814 enum wined3d_format_id wined3d_format;
3815 D3D_FEATURE_LEVEL feature_level;
3816 struct wined3d *wined3d;
3817 unsigned int i;
3819 static const struct
3821 enum wined3d_resource_type rtype;
3822 unsigned int bind_flags;
3823 unsigned int usage;
3824 D3D11_FORMAT_SUPPORT flag;
3826 flag_mapping[] =
3828 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3829 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3830 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3831 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3832 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3833 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3834 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3835 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3836 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3837 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3839 HRESULT hr;
3841 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3843 wined3d_format = wined3dformat_from_dxgi_format(format);
3844 if (format && !wined3d_format)
3846 WARN("Invalid format %#x.\n", format);
3847 *format_support = 0;
3848 return E_FAIL;
3851 *format_support = 0;
3853 wined3d_mutex_lock();
3854 feature_level = device->state->feature_level;
3855 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3856 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3857 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3858 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3860 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3861 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3862 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3863 continue;
3864 if (hr != WINED3D_OK)
3866 WARN("Failed to check device format support, hr %#x.\n", hr);
3867 wined3d_mutex_unlock();
3868 return E_FAIL;
3871 *format_support |= flag_mapping[i].flag;
3873 wined3d_mutex_unlock();
3875 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3876 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3878 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3879 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3881 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3882 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3883 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3885 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3886 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3888 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3890 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3891 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3893 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3894 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3898 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3899 * support multisample. */
3900 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3901 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3902 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3903 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3905 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3906 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3907 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3910 return S_OK;
3913 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3914 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3916 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3917 struct wined3d_device_creation_parameters params;
3918 struct wined3d_adapter *wined3d_adapter;
3919 struct wined3d *wined3d;
3920 HRESULT hr;
3922 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3923 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3925 if (!quality_level_count)
3926 return E_INVALIDARG;
3928 *quality_level_count = 0;
3930 if (!sample_count)
3931 return E_FAIL;
3932 if (sample_count == 1)
3934 *quality_level_count = 1;
3935 return S_OK;
3937 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3938 return E_FAIL;
3940 wined3d_mutex_lock();
3941 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3942 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3943 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3944 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3945 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3946 wined3d_mutex_unlock();
3948 if (hr == WINED3DERR_INVALIDCALL)
3949 return E_INVALIDARG;
3950 if (hr == WINED3DERR_NOTAVAILABLE)
3951 return S_OK;
3952 return hr;
3955 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3957 FIXME("iface %p, info %p stub!\n", iface, info);
3960 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3961 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3962 char *units, UINT *units_length, char *description, UINT *description_length)
3964 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3965 "units %p, units_length %p, description %p, description_length %p stub!\n",
3966 iface, desc, type, active_counter_count, name, name_length,
3967 units, units_length, description, description_length);
3969 return E_NOTIMPL;
3972 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3973 void *feature_support_data, UINT feature_support_data_size)
3975 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3976 struct wined3d_caps wined3d_caps;
3977 HRESULT hr;
3979 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3980 iface, feature, feature_support_data, feature_support_data_size);
3982 switch (feature)
3984 case D3D11_FEATURE_THREADING:
3986 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3987 if (feature_support_data_size != sizeof(*threading_data))
3989 WARN("Invalid data size.\n");
3990 return E_INVALIDARG;
3993 /* We lie about the threading support to make Tomb Raider 2013 and
3994 * Deus Ex: Human Revolution happy. */
3995 FIXME("Returning fake threading support data.\n");
3996 threading_data->DriverConcurrentCreates = TRUE;
3997 threading_data->DriverCommandLists = TRUE;
3998 return S_OK;
4001 case D3D11_FEATURE_DOUBLES:
4003 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
4004 if (feature_support_data_size != sizeof(*doubles_data))
4006 WARN("Invalid data size.\n");
4007 return E_INVALIDARG;
4010 wined3d_mutex_lock();
4011 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4012 wined3d_mutex_unlock();
4013 if (FAILED(hr))
4015 WARN("Failed to get device caps, hr %#x.\n", hr);
4016 return hr;
4019 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
4020 return S_OK;
4023 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
4025 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
4026 if (feature_support_data_size != sizeof(*options))
4028 WARN("Invalid data size.\n");
4029 return E_INVALIDARG;
4032 wined3d_mutex_lock();
4033 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4034 wined3d_mutex_unlock();
4035 if (FAILED(hr))
4037 WARN("Failed to get device caps, hr %#x.\n", hr);
4038 return hr;
4041 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
4042 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4043 return S_OK;
4046 case D3D11_FEATURE_D3D11_OPTIONS:
4048 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4049 if (feature_support_data_size != sizeof(*options))
4051 WARN("Invalid data size.\n");
4052 return E_INVALIDARG;
4055 FIXME("Returning fake Options support data.\n");
4056 options->OutputMergerLogicOp = FALSE;
4057 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4058 options->DiscardAPIsSeenByDriver = FALSE;
4059 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4060 options->ClearView = FALSE;
4061 options->CopyWithOverlap = FALSE;
4062 options->ConstantBufferPartialUpdate = FALSE;
4063 options->ConstantBufferOffsetting = TRUE;
4064 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
4065 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
4066 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4067 options->SAD4ShaderInstructions = FALSE;
4068 options->ExtendedDoublesShaderInstructions = FALSE;
4069 options->ExtendedResourceSharing = FALSE;
4070 return S_OK;
4073 case D3D11_FEATURE_D3D11_OPTIONS1:
4075 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4076 if (feature_support_data_size != sizeof(*options))
4078 WARN("Invalid data size.\n");
4079 return E_INVALIDARG;
4082 FIXME("Returning fake Options1 support data.\n");
4083 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4084 options->MinMaxFiltering = FALSE;
4085 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4086 options->MapOnDefaultBuffers = FALSE;
4087 return S_OK;
4090 case D3D11_FEATURE_D3D11_OPTIONS3:
4092 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4093 if (feature_support_data_size != sizeof(*options))
4095 WARN("Invalid data size.\n");
4096 return E_INVALIDARG;
4099 wined3d_mutex_lock();
4100 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4101 wined3d_mutex_unlock();
4102 if (FAILED(hr))
4104 WARN("Failed to get device caps, hr %#x.\n", hr);
4105 return hr;
4108 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4109 = wined3d_caps.viewport_array_index_any_shader;
4110 return S_OK;
4113 case D3D11_FEATURE_ARCHITECTURE_INFO:
4115 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4116 if (feature_support_data_size != sizeof(*options))
4118 WARN("Invalid data size.\n");
4119 return E_INVALIDARG;
4122 FIXME("Returning fake data architecture info.\n");
4123 options->TileBasedDeferredRenderer = FALSE;
4124 return S_OK;
4127 default:
4128 FIXME("Unhandled feature %#x.\n", feature);
4129 return E_NOTIMPL;
4133 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4134 UINT *data_size, void *data)
4136 IDXGIDevice *dxgi_device;
4137 HRESULT hr;
4139 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4141 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4142 return hr;
4143 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4144 IDXGIDevice_Release(dxgi_device);
4146 return hr;
4149 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4150 UINT data_size, const void *data)
4152 IDXGIDevice *dxgi_device;
4153 HRESULT hr;
4155 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4157 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4158 return hr;
4159 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4160 IDXGIDevice_Release(dxgi_device);
4162 return hr;
4165 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4166 const IUnknown *data)
4168 IDXGIDevice *dxgi_device;
4169 HRESULT hr;
4171 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4173 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4174 return hr;
4175 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4176 IDXGIDevice_Release(dxgi_device);
4178 return hr;
4181 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4183 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4185 TRACE("iface %p.\n", iface);
4187 return device->state->feature_level;
4190 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4192 FIXME("iface %p stub!\n", iface);
4194 return 0;
4197 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4199 WARN("iface %p stub!\n", iface);
4201 return S_OK;
4204 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4205 ID3D11DeviceContext **immediate_context)
4207 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4209 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4211 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4212 ID3D11DeviceContext_AddRef(*immediate_context);
4215 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4217 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4219 return E_NOTIMPL;
4222 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4224 FIXME("iface %p stub!\n", iface);
4226 return 0;
4229 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4230 ID3D11DeviceContext1 **immediate_context)
4232 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4234 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4236 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4237 ID3D11DeviceContext1_AddRef(*immediate_context);
4240 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4241 ID3D11DeviceContext1 **context)
4243 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4244 struct d3d11_device_context *object;
4245 HRESULT hr;
4247 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4249 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4250 return hr;
4252 *context = &object->ID3D11DeviceContext1_iface;
4253 return S_OK;
4256 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4257 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4259 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4261 return E_NOTIMPL;
4264 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4265 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4267 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4269 return E_NOTIMPL;
4272 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4273 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4274 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4276 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4277 struct d3d_device_context_state *state_impl;
4278 struct wined3d_state *wined3d_state;
4279 D3D_FEATURE_LEVEL feature_level;
4280 HRESULT hr = E_INVALIDARG;
4282 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4283 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4284 iface, flags, feature_levels, feature_level_count,
4285 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4287 if (flags)
4288 FIXME("Ignoring flags %#x.\n", flags);
4290 wined3d_mutex_lock();
4292 if (!feature_level_count)
4293 goto fail;
4295 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4296 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4297 goto fail;
4298 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4300 if (chosen_feature_level)
4301 *chosen_feature_level = feature_level;
4303 if (!state)
4305 wined3d_state_destroy(wined3d_state);
4306 wined3d_mutex_unlock();
4307 return S_FALSE;
4310 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4312 wined3d_state_destroy(wined3d_state);
4313 hr = E_OUTOFMEMORY;
4314 goto fail;
4317 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4318 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4320 wined3d_state_destroy(wined3d_state);
4321 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4322 hr = E_FAIL;
4323 goto fail;
4326 *state = &state_impl->ID3DDeviceContextState_iface;
4327 device->d3d11_only = FALSE;
4328 wined3d_mutex_unlock();
4330 return S_OK;
4332 fail:
4333 wined3d_mutex_unlock();
4334 if (chosen_feature_level)
4335 *chosen_feature_level = 0;
4336 if (state)
4337 *state = NULL;
4338 return hr;
4341 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4342 REFIID iid, void **resource)
4344 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4346 return E_NOTIMPL;
4349 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4350 DWORD access, REFIID iid, void **resource)
4352 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4353 debugstr_guid(iid), resource);
4355 return E_NOTIMPL;
4358 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4359 ID3D11DeviceContext2 **context)
4361 FIXME("iface %p, context %p stub!\n", iface, context);
4364 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4365 UINT flags, ID3D11DeviceContext2 **context)
4367 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4369 return E_NOTIMPL;
4372 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4373 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4374 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4375 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4377 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4378 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4379 iface, resource, tile_count, mip_desc, tile_shape,
4380 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4383 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4384 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4386 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4387 iface, format, sample_count, flags, quality_level_count);
4389 return E_NOTIMPL;
4392 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4394 /* IUnknown methods */
4395 d3d11_device_QueryInterface,
4396 d3d11_device_AddRef,
4397 d3d11_device_Release,
4398 /* ID3D11Device methods */
4399 d3d11_device_CreateBuffer,
4400 d3d11_device_CreateTexture1D,
4401 d3d11_device_CreateTexture2D,
4402 d3d11_device_CreateTexture3D,
4403 d3d11_device_CreateShaderResourceView,
4404 d3d11_device_CreateUnorderedAccessView,
4405 d3d11_device_CreateRenderTargetView,
4406 d3d11_device_CreateDepthStencilView,
4407 d3d11_device_CreateInputLayout,
4408 d3d11_device_CreateVertexShader,
4409 d3d11_device_CreateGeometryShader,
4410 d3d11_device_CreateGeometryShaderWithStreamOutput,
4411 d3d11_device_CreatePixelShader,
4412 d3d11_device_CreateHullShader,
4413 d3d11_device_CreateDomainShader,
4414 d3d11_device_CreateComputeShader,
4415 d3d11_device_CreateClassLinkage,
4416 d3d11_device_CreateBlendState,
4417 d3d11_device_CreateDepthStencilState,
4418 d3d11_device_CreateRasterizerState,
4419 d3d11_device_CreateSamplerState,
4420 d3d11_device_CreateQuery,
4421 d3d11_device_CreatePredicate,
4422 d3d11_device_CreateCounter,
4423 d3d11_device_CreateDeferredContext,
4424 d3d11_device_OpenSharedResource,
4425 d3d11_device_CheckFormatSupport,
4426 d3d11_device_CheckMultisampleQualityLevels,
4427 d3d11_device_CheckCounterInfo,
4428 d3d11_device_CheckCounter,
4429 d3d11_device_CheckFeatureSupport,
4430 d3d11_device_GetPrivateData,
4431 d3d11_device_SetPrivateData,
4432 d3d11_device_SetPrivateDataInterface,
4433 d3d11_device_GetFeatureLevel,
4434 d3d11_device_GetCreationFlags,
4435 d3d11_device_GetDeviceRemovedReason,
4436 d3d11_device_GetImmediateContext,
4437 d3d11_device_SetExceptionMode,
4438 d3d11_device_GetExceptionMode,
4439 /* ID3D11Device1 methods */
4440 d3d11_device_GetImmediateContext1,
4441 d3d11_device_CreateDeferredContext1,
4442 d3d11_device_CreateBlendState1,
4443 d3d11_device_CreateRasterizerState1,
4444 d3d11_device_CreateDeviceContextState,
4445 d3d11_device_OpenSharedResource1,
4446 d3d11_device_OpenSharedResourceByName,
4447 /* ID3D11Device2 methods */
4448 d3d11_device_GetImmediateContext2,
4449 d3d11_device_CreateDeferredContext2,
4450 d3d11_device_GetResourceTiling,
4451 d3d11_device_CheckMultisampleQualityLevels1,
4454 /* Inner IUnknown methods */
4456 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4458 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4461 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4463 struct d3d_device *device = impl_from_IUnknown(iface);
4465 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4467 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4468 || IsEqualGUID(riid, &IID_ID3D11Device1)
4469 || IsEqualGUID(riid, &IID_ID3D11Device)
4470 || IsEqualGUID(riid, &IID_IUnknown))
4472 *out = &device->ID3D11Device2_iface;
4474 else if (!device->d3d11_only
4475 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4476 || IsEqualGUID(riid, &IID_ID3D10Device)))
4478 *out = &device->ID3D10Device1_iface;
4480 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4482 *out = &device->ID3D10Multithread_iface;
4484 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4486 *out = &device->IWineDXGIDeviceParent_iface;
4488 else
4490 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4491 *out = NULL;
4492 return E_NOINTERFACE;
4495 IUnknown_AddRef((IUnknown *)*out);
4496 return S_OK;
4499 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4501 struct d3d_device *device = impl_from_IUnknown(iface);
4502 ULONG refcount = InterlockedIncrement(&device->refcount);
4504 TRACE("%p increasing refcount to %u.\n", device, refcount);
4506 return refcount;
4509 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4511 struct d3d_device *device = impl_from_IUnknown(iface);
4512 ULONG refcount = InterlockedDecrement(&device->refcount);
4513 unsigned int i;
4515 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4517 if (!refcount)
4519 if (device->state)
4520 d3d_device_context_state_private_release(device->state);
4521 for (i = 0; i < device->context_state_count; ++i)
4523 d3d_device_context_state_remove_entry(device->context_states[i], device);
4525 heap_free(device->context_states);
4526 d3d11_device_context_cleanup(&device->immediate_context);
4527 if (device->wined3d_device)
4529 wined3d_mutex_lock();
4530 wined3d_device_decref(device->wined3d_device);
4531 wined3d_mutex_unlock();
4533 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4534 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4535 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4536 wine_rb_destroy(&device->blend_states, NULL, NULL);
4539 return refcount;
4542 /* IUnknown methods */
4544 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4545 void **out)
4547 struct d3d_device *device = impl_from_ID3D10Device(iface);
4548 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4551 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4553 struct d3d_device *device = impl_from_ID3D10Device(iface);
4554 return IUnknown_AddRef(device->outer_unk);
4557 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4559 struct d3d_device *device = impl_from_ID3D10Device(iface);
4560 return IUnknown_Release(device->outer_unk);
4563 /* ID3D10Device methods */
4565 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4566 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4568 struct d3d_device *device = impl_from_ID3D10Device(iface);
4569 unsigned int i;
4571 wined3d_mutex_lock();
4572 for (i = 0; i < buffer_count; ++i)
4574 struct wined3d_constant_buffer_state state;
4575 struct d3d_buffer *buffer_impl;
4577 wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4578 type, start_slot + i, &state);
4580 if (!state.buffer)
4582 buffers[i] = NULL;
4583 continue;
4586 buffer_impl = wined3d_buffer_get_parent(state.buffer);
4587 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4588 ID3D10Buffer_AddRef(buffers[i]);
4590 wined3d_mutex_unlock();
4593 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4594 unsigned int start_slot, unsigned int buffer_count, ID3D10Buffer *const *buffers)
4596 struct wined3d_constant_buffer_state wined3d_buffers[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4597 struct d3d_device *device = impl_from_ID3D10Device(iface);
4598 unsigned int i;
4600 if (buffer_count > ARRAY_SIZE(wined3d_buffers))
4602 WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
4603 return;
4606 for (i = 0; i < buffer_count; ++i)
4608 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4610 wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4611 wined3d_buffers[i].offset = 0;
4612 wined3d_buffers[i].size = WINED3D_MAX_CONSTANT_BUFFER_SIZE * sizeof(struct wined3d_vec4);
4615 wined3d_mutex_lock();
4616 wined3d_device_context_set_constant_buffers(device->immediate_context.wined3d_context,
4617 type, start_slot, buffer_count, wined3d_buffers);
4618 wined3d_mutex_unlock();
4621 static void d3d10_device_set_shader_resource_views(ID3D10Device1 *iface, enum wined3d_shader_type type,
4622 unsigned int start_slot, unsigned int count, ID3D10ShaderResourceView *const *views)
4624 struct wined3d_shader_resource_view *wined3d_views[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4625 struct d3d_device *device = impl_from_ID3D10Device(iface);
4626 unsigned int i;
4628 if (count > ARRAY_SIZE(wined3d_views))
4630 WARN("View count %u exceeds limit; ignoring call.\n", count);
4631 return;
4634 for (i = 0; i < count; ++i)
4636 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4638 wined3d_views[i] = view ? view->wined3d_view : NULL;
4641 wined3d_mutex_lock();
4642 wined3d_device_context_set_shader_resource_views(device->immediate_context.wined3d_context,
4643 type, start_slot, count, wined3d_views);
4644 wined3d_mutex_unlock();
4647 static void d3d10_device_set_samplers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4648 unsigned int start_slot, unsigned int count, ID3D10SamplerState *const *samplers)
4650 struct wined3d_sampler *wined3d_samplers[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4651 struct d3d_device *device = impl_from_ID3D10Device(iface);
4652 unsigned int i;
4654 if (count > ARRAY_SIZE(wined3d_samplers))
4656 WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
4657 return;
4660 for (i = 0; i < count; ++i)
4662 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4664 wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
4667 wined3d_mutex_lock();
4668 wined3d_device_context_set_samplers(device->immediate_context.wined3d_context,
4669 type, start_slot, count, wined3d_samplers);
4670 wined3d_mutex_unlock();
4673 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4674 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4676 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4677 iface, start_slot, buffer_count, buffers);
4679 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4680 buffer_count, buffers);
4683 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4684 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4686 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4687 iface, start_slot, view_count, views);
4689 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
4692 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4693 ID3D10PixelShader *shader)
4695 struct d3d_device *device = impl_from_ID3D10Device(iface);
4696 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4698 TRACE("iface %p, shader %p\n", iface, shader);
4700 wined3d_mutex_lock();
4701 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4702 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4703 wined3d_mutex_unlock();
4706 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4707 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4709 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4710 iface, start_slot, sampler_count, samplers);
4712 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
4715 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4716 ID3D10VertexShader *shader)
4718 struct d3d_device *device = impl_from_ID3D10Device(iface);
4719 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4721 TRACE("iface %p, shader %p\n", iface, shader);
4723 wined3d_mutex_lock();
4724 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4725 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4726 wined3d_mutex_unlock();
4729 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4730 UINT start_index_location, INT base_vertex_location)
4732 struct d3d_device *device = impl_from_ID3D10Device(iface);
4734 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4735 iface, index_count, start_index_location, base_vertex_location);
4737 wined3d_mutex_lock();
4738 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4739 base_vertex_location, start_index_location, index_count, 0, 0);
4740 wined3d_mutex_unlock();
4743 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4744 UINT start_vertex_location)
4746 struct d3d_device *device = impl_from_ID3D10Device(iface);
4748 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4749 iface, vertex_count, start_vertex_location);
4751 wined3d_mutex_lock();
4752 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4753 wined3d_mutex_unlock();
4756 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4757 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4759 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4760 iface, start_slot, buffer_count, buffers);
4762 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4763 buffer_count, buffers);
4766 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4767 ID3D10InputLayout *input_layout)
4769 struct d3d_device *device = impl_from_ID3D10Device(iface);
4770 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4772 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4774 wined3d_mutex_lock();
4775 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4776 layout ? layout->wined3d_decl : NULL);
4777 wined3d_mutex_unlock();
4780 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4781 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4783 struct wined3d_stream_state streams[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4784 struct d3d_device *device = impl_from_ID3D10Device(iface);
4785 unsigned int i;
4787 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4788 iface, start_slot, buffer_count, buffers, strides, offsets);
4790 if (buffer_count > ARRAY_SIZE(streams))
4792 WARN("Buffer count %u exceeds limit.\n", buffer_count);
4793 buffer_count = ARRAY_SIZE(streams);
4796 for (i = 0; i < buffer_count; ++i)
4798 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4800 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4801 streams[i].offset = offsets[i];
4802 streams[i].stride = strides[i];
4803 streams[i].frequency = 1;
4804 streams[i].flags = 0;
4807 wined3d_mutex_lock();
4808 wined3d_device_context_set_stream_sources(device->immediate_context.wined3d_context,
4809 start_slot, buffer_count, streams);
4810 wined3d_mutex_unlock();
4813 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4814 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4816 struct d3d_device *device = impl_from_ID3D10Device(iface);
4817 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4819 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4820 iface, buffer, debug_dxgi_format(format), offset);
4822 wined3d_mutex_lock();
4823 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4824 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4825 wined3dformat_from_dxgi_format(format), offset);
4826 wined3d_mutex_unlock();
4829 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4830 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4831 INT base_vertex_location, UINT start_instance_location)
4833 struct d3d_device *device = impl_from_ID3D10Device(iface);
4835 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4836 "base_vertex_location %d, start_instance_location %u.\n",
4837 iface, instance_index_count, instance_count, start_index_location,
4838 base_vertex_location, start_instance_location);
4840 wined3d_mutex_lock();
4841 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4842 start_index_location, instance_index_count, start_instance_location, instance_count);
4843 wined3d_mutex_unlock();
4846 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4847 UINT instance_vertex_count, UINT instance_count,
4848 UINT start_vertex_location, UINT start_instance_location)
4850 struct d3d_device *device = impl_from_ID3D10Device(iface);
4852 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4853 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4854 start_vertex_location, start_instance_location);
4856 wined3d_mutex_lock();
4857 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4858 instance_vertex_count, start_instance_location, instance_count);
4859 wined3d_mutex_unlock();
4862 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4863 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4865 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4866 iface, start_slot, buffer_count, buffers);
4868 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4869 buffer_count, buffers);
4872 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4874 struct d3d_device *device = impl_from_ID3D10Device(iface);
4875 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4877 TRACE("iface %p, shader %p.\n", iface, shader);
4879 wined3d_mutex_lock();
4880 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4881 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4882 wined3d_mutex_unlock();
4885 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4886 D3D10_PRIMITIVE_TOPOLOGY topology)
4888 struct d3d_device *device = impl_from_ID3D10Device(iface);
4890 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4892 wined3d_mutex_lock();
4893 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4894 (enum wined3d_primitive_type)topology, 0);
4895 wined3d_mutex_unlock();
4898 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4899 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4901 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4902 iface, start_slot, view_count, views);
4904 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
4907 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4908 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4910 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4911 iface, start_slot, sampler_count, samplers);
4913 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
4916 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4918 struct d3d_device *device = impl_from_ID3D10Device(iface);
4919 struct d3d_query *query;
4921 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4923 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4924 wined3d_mutex_lock();
4925 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4926 query ? query->wined3d_query : NULL, value);
4927 wined3d_mutex_unlock();
4930 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4931 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4933 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4934 iface, start_slot, view_count, views);
4936 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
4939 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4940 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4942 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4943 iface, start_slot, sampler_count, samplers);
4945 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
4948 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4949 UINT rtv_count, ID3D10RenderTargetView *const *rtvs, ID3D10DepthStencilView *depth_stencil_view)
4951 struct wined3d_rendertarget_view *wined3d_rtvs[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
4952 struct d3d_device *device = impl_from_ID3D10Device(iface);
4953 struct d3d_depthstencil_view *dsv;
4954 unsigned int i;
4956 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
4958 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
4960 WARN("View count %u exceeds limit.\n", rtv_count);
4961 rtv_count = ARRAY_SIZE(wined3d_rtvs);
4964 for (i = 0; i < rtv_count; ++i)
4966 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(rtvs[i]);
4968 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
4971 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4973 wined3d_mutex_lock();
4974 wined3d_device_context_set_rendertarget_views(device->immediate_context.wined3d_context, 0,
4975 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
4976 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4977 dsv ? dsv->wined3d_view : NULL);
4978 wined3d_mutex_unlock();
4981 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4982 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4984 struct d3d_device *device = impl_from_ID3D10Device(iface);
4985 struct d3d_blend_state *blend_state_object;
4987 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4988 iface, blend_state, debug_float4(blend_factor), sample_mask);
4990 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4991 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4992 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4995 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4996 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4998 struct d3d_device *device = impl_from_ID3D10Device(iface);
4999 struct d3d_depthstencil_state *ds_state_object;
5001 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
5002 iface, depth_stencil_state, stencil_ref);
5004 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
5005 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5006 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
5009 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
5010 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
5012 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
5013 struct d3d_device *device = impl_from_ID3D10Device(iface);
5014 unsigned int count, i;
5016 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
5018 count = min(target_count, ARRAY_SIZE(outputs));
5019 for (i = 0; i < count; ++i)
5021 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
5023 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
5024 outputs[i].offset = offsets ? offsets[i] : 0;
5027 wined3d_mutex_lock();
5028 wined3d_device_context_set_stream_outputs(device->immediate_context.wined3d_context, outputs);
5029 wined3d_mutex_unlock();
5032 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
5034 FIXME("iface %p stub!\n", iface);
5037 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
5039 struct d3d_device *device = impl_from_ID3D10Device(iface);
5040 struct d3d_rasterizer_state *rasterizer_state_object;
5042 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5044 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5045 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5046 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
5049 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
5050 UINT viewport_count, const D3D10_VIEWPORT *viewports)
5052 struct d3d_device *device = impl_from_ID3D10Device(iface);
5053 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5054 unsigned int i;
5056 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5058 if (viewport_count > ARRAY_SIZE(wined3d_vp))
5059 return;
5061 for (i = 0; i < viewport_count; ++i)
5063 wined3d_vp[i].x = viewports[i].TopLeftX;
5064 wined3d_vp[i].y = viewports[i].TopLeftY;
5065 wined3d_vp[i].width = viewports[i].Width;
5066 wined3d_vp[i].height = viewports[i].Height;
5067 wined3d_vp[i].min_z = viewports[i].MinDepth;
5068 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5071 wined3d_mutex_lock();
5072 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5073 wined3d_mutex_unlock();
5076 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
5077 UINT rect_count, const D3D10_RECT *rects)
5079 struct d3d_device *device = impl_from_ID3D10Device(iface);
5081 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5083 if (rect_count > WINED3D_MAX_VIEWPORTS)
5084 return;
5086 wined3d_mutex_lock();
5087 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5088 wined3d_mutex_unlock();
5091 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5092 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5093 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5095 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5096 struct d3d_device *device = impl_from_ID3D10Device(iface);
5097 struct wined3d_box wined3d_src_box;
5099 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5100 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5101 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5102 src_resource, src_subresource_idx, src_box);
5104 if (!dst_resource || !src_resource)
5105 return;
5107 if (src_box)
5108 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5109 src_box->right, src_box->bottom, src_box->front, src_box->back);
5111 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5112 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5113 wined3d_mutex_lock();
5114 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5115 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5116 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5117 wined3d_mutex_unlock();
5120 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5121 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5123 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5124 struct d3d_device *device = impl_from_ID3D10Device(iface);
5126 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5128 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5129 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5130 wined3d_mutex_lock();
5131 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5132 wined3d_dst_resource, wined3d_src_resource);
5133 wined3d_mutex_unlock();
5136 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5137 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5138 const void *data, UINT row_pitch, UINT depth_pitch)
5140 struct d3d_device *device = impl_from_ID3D10Device(iface);
5141 ID3D11Resource *d3d11_resource;
5143 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5144 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5146 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5147 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5148 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5149 ID3D11Resource_Release(d3d11_resource);
5152 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5153 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5155 struct d3d_device *device = impl_from_ID3D10Device(iface);
5156 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5157 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5158 HRESULT hr;
5160 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5161 iface, render_target_view, debug_float4(color_rgba));
5163 if (!view)
5164 return;
5166 wined3d_mutex_lock();
5167 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5168 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5169 ERR("Failed to clear view, hr %#x.\n", hr);
5170 wined3d_mutex_unlock();
5173 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5174 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5176 struct d3d_device *device = impl_from_ID3D10Device(iface);
5177 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5178 DWORD wined3d_flags;
5179 HRESULT hr;
5181 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5182 iface, depth_stencil_view, flags, depth, stencil);
5184 if (!view)
5185 return;
5187 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5189 wined3d_mutex_lock();
5190 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5191 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5192 ERR("Failed to clear view, hr %#x.\n", hr);
5193 wined3d_mutex_unlock();
5196 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5197 ID3D10ShaderResourceView *view)
5199 struct d3d_device *device = impl_from_ID3D10Device(iface);
5200 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5202 TRACE("iface %p, view %p.\n", iface, view);
5204 wined3d_mutex_lock();
5205 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5206 wined3d_mutex_unlock();
5209 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5210 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5211 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5213 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5214 struct d3d_device *device = impl_from_ID3D10Device(iface);
5215 enum wined3d_format_id wined3d_format;
5217 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5218 "src_resource %p, src_subresource_idx %u, format %s.\n",
5219 iface, dst_resource, dst_subresource_idx,
5220 src_resource, src_subresource_idx, debug_dxgi_format(format));
5222 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5223 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5224 wined3d_format = wined3dformat_from_dxgi_format(format);
5225 wined3d_mutex_lock();
5226 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5227 wined3d_dst_resource, dst_subresource_idx,
5228 wined3d_src_resource, src_subresource_idx, wined3d_format);
5229 wined3d_mutex_unlock();
5232 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5233 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5235 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5236 iface, start_slot, buffer_count, buffers);
5238 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5239 buffers);
5242 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5243 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5245 struct d3d_device *device = impl_from_ID3D10Device(iface);
5246 unsigned int i;
5248 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5249 iface, start_slot, view_count, views);
5251 wined3d_mutex_lock();
5252 for (i = 0; i < view_count; ++i)
5254 struct wined3d_shader_resource_view *wined3d_view;
5255 struct d3d_shader_resource_view *view_impl;
5257 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5258 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5260 views[i] = NULL;
5261 continue;
5264 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5265 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5266 ID3D10ShaderResourceView_AddRef(views[i]);
5268 wined3d_mutex_unlock();
5271 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5273 struct d3d_device *device = impl_from_ID3D10Device(iface);
5274 struct d3d_pixel_shader *shader_impl;
5275 struct wined3d_shader *wined3d_shader;
5277 TRACE("iface %p, shader %p.\n", iface, shader);
5279 wined3d_mutex_lock();
5280 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5281 WINED3D_SHADER_TYPE_PIXEL)))
5283 wined3d_mutex_unlock();
5284 *shader = NULL;
5285 return;
5288 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5289 wined3d_mutex_unlock();
5290 *shader = &shader_impl->ID3D10PixelShader_iface;
5291 ID3D10PixelShader_AddRef(*shader);
5294 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5295 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5297 struct d3d_device *device = impl_from_ID3D10Device(iface);
5298 unsigned int i;
5300 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5301 iface, start_slot, sampler_count, samplers);
5303 wined3d_mutex_lock();
5304 for (i = 0; i < sampler_count; ++i)
5306 struct d3d_sampler_state *sampler_impl;
5307 struct wined3d_sampler *wined3d_sampler;
5309 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5310 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5312 samplers[i] = NULL;
5313 continue;
5316 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5317 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5318 ID3D10SamplerState_AddRef(samplers[i]);
5320 wined3d_mutex_unlock();
5323 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5325 struct d3d_device *device = impl_from_ID3D10Device(iface);
5326 struct d3d_vertex_shader *shader_impl;
5327 struct wined3d_shader *wined3d_shader;
5329 TRACE("iface %p, shader %p.\n", iface, shader);
5331 wined3d_mutex_lock();
5332 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5333 WINED3D_SHADER_TYPE_VERTEX)))
5335 wined3d_mutex_unlock();
5336 *shader = NULL;
5337 return;
5340 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5341 wined3d_mutex_unlock();
5342 *shader = &shader_impl->ID3D10VertexShader_iface;
5343 ID3D10VertexShader_AddRef(*shader);
5346 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5347 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5349 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5350 iface, start_slot, buffer_count, buffers);
5352 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5353 buffers);
5356 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5358 struct d3d_device *device = impl_from_ID3D10Device(iface);
5359 struct wined3d_vertex_declaration *wined3d_declaration;
5360 struct d3d_input_layout *input_layout_impl;
5362 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5364 wined3d_mutex_lock();
5365 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5366 device->immediate_context.wined3d_context)))
5368 wined3d_mutex_unlock();
5369 *input_layout = NULL;
5370 return;
5373 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5374 wined3d_mutex_unlock();
5375 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5376 ID3D10InputLayout_AddRef(*input_layout);
5379 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5380 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5382 struct d3d_device *device = impl_from_ID3D10Device(iface);
5383 unsigned int i;
5385 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5386 iface, start_slot, buffer_count, buffers, strides, offsets);
5388 wined3d_mutex_lock();
5389 for (i = 0; i < buffer_count; ++i)
5391 struct wined3d_buffer *wined3d_buffer = NULL;
5392 struct d3d_buffer *buffer_impl;
5394 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5395 &wined3d_buffer, &offsets[i], &strides[i])))
5396 ERR("Failed to get vertex buffer.\n");
5398 if (!wined3d_buffer)
5400 buffers[i] = NULL;
5401 continue;
5404 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5405 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5406 ID3D10Buffer_AddRef(buffers[i]);
5408 wined3d_mutex_unlock();
5411 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5412 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5414 struct d3d_device *device = impl_from_ID3D10Device(iface);
5415 enum wined3d_format_id wined3d_format;
5416 struct wined3d_buffer *wined3d_buffer;
5417 struct d3d_buffer *buffer_impl;
5419 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5421 wined3d_mutex_lock();
5422 wined3d_buffer = wined3d_device_context_get_index_buffer(
5423 device->immediate_context.wined3d_context, &wined3d_format, offset);
5424 *format = dxgi_format_from_wined3dformat(wined3d_format);
5425 if (!wined3d_buffer)
5427 wined3d_mutex_unlock();
5428 *buffer = NULL;
5429 return;
5432 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5433 wined3d_mutex_unlock();
5434 *buffer = &buffer_impl->ID3D10Buffer_iface;
5435 ID3D10Buffer_AddRef(*buffer);
5438 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5439 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5441 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5442 iface, start_slot, buffer_count, buffers);
5444 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5445 buffers);
5448 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5450 struct d3d_device *device = impl_from_ID3D10Device(iface);
5451 struct d3d_geometry_shader *shader_impl;
5452 struct wined3d_shader *wined3d_shader;
5454 TRACE("iface %p, shader %p.\n", iface, shader);
5456 wined3d_mutex_lock();
5457 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5458 WINED3D_SHADER_TYPE_GEOMETRY)))
5460 wined3d_mutex_unlock();
5461 *shader = NULL;
5462 return;
5465 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5466 wined3d_mutex_unlock();
5467 *shader = &shader_impl->ID3D10GeometryShader_iface;
5468 ID3D10GeometryShader_AddRef(*shader);
5471 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5472 D3D10_PRIMITIVE_TOPOLOGY *topology)
5474 struct d3d_device *device = impl_from_ID3D10Device(iface);
5476 TRACE("iface %p, topology %p.\n", iface, topology);
5478 wined3d_mutex_lock();
5479 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5480 (enum wined3d_primitive_type *)topology, NULL);
5481 wined3d_mutex_unlock();
5484 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5485 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5487 struct d3d_device *device = impl_from_ID3D10Device(iface);
5488 unsigned int i;
5490 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5491 iface, start_slot, view_count, views);
5493 wined3d_mutex_lock();
5494 for (i = 0; i < view_count; ++i)
5496 struct wined3d_shader_resource_view *wined3d_view;
5497 struct d3d_shader_resource_view *view_impl;
5499 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5500 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5502 views[i] = NULL;
5503 continue;
5506 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5507 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5508 ID3D10ShaderResourceView_AddRef(views[i]);
5510 wined3d_mutex_unlock();
5513 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5514 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5516 struct d3d_device *device = impl_from_ID3D10Device(iface);
5517 unsigned int i;
5519 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5520 iface, start_slot, sampler_count, samplers);
5522 wined3d_mutex_lock();
5523 for (i = 0; i < sampler_count; ++i)
5525 struct d3d_sampler_state *sampler_impl;
5526 struct wined3d_sampler *wined3d_sampler;
5528 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5529 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5531 samplers[i] = NULL;
5532 continue;
5535 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5536 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5537 ID3D10SamplerState_AddRef(samplers[i]);
5539 wined3d_mutex_unlock();
5542 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5543 ID3D10Predicate **predicate, BOOL *value)
5545 struct d3d_device *device = impl_from_ID3D10Device(iface);
5546 struct wined3d_query *wined3d_predicate;
5547 struct d3d_query *predicate_impl;
5549 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5551 wined3d_mutex_lock();
5552 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5554 wined3d_mutex_unlock();
5555 *predicate = NULL;
5556 return;
5559 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5560 wined3d_mutex_unlock();
5561 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5562 ID3D10Predicate_AddRef(*predicate);
5565 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5566 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5568 struct d3d_device *device = impl_from_ID3D10Device(iface);
5569 unsigned int i;
5571 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5572 iface, start_slot, view_count, views);
5574 wined3d_mutex_lock();
5575 for (i = 0; i < view_count; ++i)
5577 struct wined3d_shader_resource_view *wined3d_view;
5578 struct d3d_shader_resource_view *view_impl;
5580 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5581 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5583 views[i] = NULL;
5584 continue;
5587 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5588 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5589 ID3D10ShaderResourceView_AddRef(views[i]);
5591 wined3d_mutex_unlock();
5594 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5595 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5597 struct d3d_device *device = impl_from_ID3D10Device(iface);
5598 unsigned int i;
5600 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5601 iface, start_slot, sampler_count, samplers);
5603 wined3d_mutex_lock();
5604 for (i = 0; i < sampler_count; ++i)
5606 struct d3d_sampler_state *sampler_impl;
5607 struct wined3d_sampler *wined3d_sampler;
5609 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5610 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5612 samplers[i] = NULL;
5613 continue;
5616 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5617 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5618 ID3D10SamplerState_AddRef(samplers[i]);
5620 wined3d_mutex_unlock();
5623 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5624 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5626 struct d3d_device *device = impl_from_ID3D10Device(iface);
5627 struct wined3d_rendertarget_view *wined3d_view;
5629 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5630 iface, view_count, render_target_views, depth_stencil_view);
5632 wined3d_mutex_lock();
5633 if (render_target_views)
5635 struct d3d_rendertarget_view *view_impl;
5636 unsigned int i;
5638 for (i = 0; i < view_count; ++i)
5640 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5641 device->immediate_context.wined3d_context, i))
5642 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5644 render_target_views[i] = NULL;
5645 continue;
5648 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5649 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5653 if (depth_stencil_view)
5655 struct d3d_depthstencil_view *view_impl;
5657 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5658 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5660 *depth_stencil_view = NULL;
5662 else
5664 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5665 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5668 wined3d_mutex_unlock();
5671 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5672 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5674 struct d3d_device *device = impl_from_ID3D10Device(iface);
5675 ID3D11BlendState *d3d11_blend_state;
5677 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5678 iface, blend_state, blend_factor, sample_mask);
5680 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5681 &d3d11_blend_state, blend_factor, sample_mask);
5683 if (d3d11_blend_state)
5684 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5685 else
5686 *blend_state = NULL;
5689 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5690 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5692 struct d3d_device *device = impl_from_ID3D10Device(iface);
5693 ID3D11DepthStencilState *d3d11_iface;
5695 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5696 iface, depth_stencil_state, stencil_ref);
5698 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5699 &d3d11_iface, stencil_ref);
5701 if (d3d11_iface)
5702 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5703 else
5704 *depth_stencil_state = NULL;
5707 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5708 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5710 struct d3d_device *device = impl_from_ID3D10Device(iface);
5711 unsigned int i;
5713 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5714 iface, buffer_count, buffers, offsets);
5716 wined3d_mutex_lock();
5717 for (i = 0; i < buffer_count; ++i)
5719 struct wined3d_buffer *wined3d_buffer;
5720 struct d3d_buffer *buffer_impl;
5722 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5723 device->immediate_context.wined3d_context, i, &offsets[i])))
5725 buffers[i] = NULL;
5726 continue;
5729 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5730 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5731 ID3D10Buffer_AddRef(buffers[i]);
5733 wined3d_mutex_unlock();
5736 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5738 struct d3d_device *device = impl_from_ID3D10Device(iface);
5739 struct d3d_rasterizer_state *rasterizer_state_impl;
5740 struct wined3d_rasterizer_state *wined3d_state;
5742 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5744 wined3d_mutex_lock();
5745 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5747 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5748 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5750 else
5752 *rasterizer_state = NULL;
5754 wined3d_mutex_unlock();
5757 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5758 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5760 struct d3d_device *device = impl_from_ID3D10Device(iface);
5761 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5762 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5764 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5766 if (!viewport_count)
5767 return;
5769 wined3d_mutex_lock();
5770 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5771 &actual_count, viewports ? wined3d_vp : NULL);
5772 wined3d_mutex_unlock();
5774 if (!viewports)
5776 *viewport_count = actual_count;
5777 return;
5780 if (*viewport_count > actual_count)
5781 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5783 *viewport_count = min(actual_count, *viewport_count);
5784 for (i = 0; i < *viewport_count; ++i)
5786 viewports[i].TopLeftX = wined3d_vp[i].x;
5787 viewports[i].TopLeftY = wined3d_vp[i].y;
5788 viewports[i].Width = wined3d_vp[i].width;
5789 viewports[i].Height = wined3d_vp[i].height;
5790 viewports[i].MinDepth = wined3d_vp[i].min_z;
5791 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5795 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5797 struct d3d_device *device = impl_from_ID3D10Device(iface);
5798 unsigned int actual_count;
5800 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5802 if (!rect_count)
5803 return;
5805 actual_count = *rect_count;
5807 wined3d_mutex_lock();
5808 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5809 wined3d_mutex_unlock();
5811 if (!rects)
5813 *rect_count = actual_count;
5814 return;
5817 if (*rect_count > actual_count)
5818 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5821 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5823 TRACE("iface %p.\n", iface);
5825 /* In the current implementation the device is never removed, so we can
5826 * just return S_OK here. */
5828 return S_OK;
5831 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5833 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5835 return E_NOTIMPL;
5838 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5840 FIXME("iface %p stub!\n", iface);
5842 return 0;
5845 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5846 REFGUID guid, UINT *data_size, void *data)
5848 struct d3d_device *device = impl_from_ID3D10Device(iface);
5850 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5852 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5855 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5856 REFGUID guid, UINT data_size, const void *data)
5858 struct d3d_device *device = impl_from_ID3D10Device(iface);
5860 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5862 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5865 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5866 REFGUID guid, const IUnknown *data)
5868 struct d3d_device *device = impl_from_ID3D10Device(iface);
5870 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5872 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5875 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5877 struct d3d_device *device = impl_from_ID3D10Device(iface);
5879 TRACE("iface %p.\n", iface);
5881 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5884 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5886 struct d3d_device *device = impl_from_ID3D10Device(iface);
5888 TRACE("iface %p.\n", iface);
5890 wined3d_mutex_lock();
5891 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5892 wined3d_mutex_unlock();
5895 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5896 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5898 struct d3d_device *device = impl_from_ID3D10Device(iface);
5899 D3D11_BUFFER_DESC d3d11_desc;
5900 struct d3d_buffer *object;
5901 HRESULT hr;
5903 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5905 d3d11_desc.ByteWidth = desc->ByteWidth;
5906 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5907 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5908 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5909 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5910 d3d11_desc.StructureByteStride = 0;
5912 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5913 return hr;
5915 *buffer = &object->ID3D10Buffer_iface;
5917 return S_OK;
5920 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5921 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5923 struct d3d_device *device = impl_from_ID3D10Device(iface);
5924 D3D11_TEXTURE1D_DESC d3d11_desc;
5925 struct d3d_texture1d *object;
5926 HRESULT hr;
5928 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5930 d3d11_desc.Width = desc->Width;
5931 d3d11_desc.MipLevels = desc->MipLevels;
5932 d3d11_desc.ArraySize = desc->ArraySize;
5933 d3d11_desc.Format = desc->Format;
5934 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5935 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5936 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5937 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5939 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5940 return hr;
5942 *texture = &object->ID3D10Texture1D_iface;
5944 return S_OK;
5947 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5948 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5949 ID3D10Texture2D **texture)
5951 struct d3d_device *device = impl_from_ID3D10Device(iface);
5952 D3D11_TEXTURE2D_DESC d3d11_desc;
5953 struct d3d_texture2d *object;
5954 HRESULT hr;
5956 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5958 d3d11_desc.Width = desc->Width;
5959 d3d11_desc.Height = desc->Height;
5960 d3d11_desc.MipLevels = desc->MipLevels;
5961 d3d11_desc.ArraySize = desc->ArraySize;
5962 d3d11_desc.Format = desc->Format;
5963 d3d11_desc.SampleDesc = desc->SampleDesc;
5964 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5965 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5966 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5967 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5969 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5970 return hr;
5972 *texture = &object->ID3D10Texture2D_iface;
5974 return S_OK;
5977 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5978 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5979 ID3D10Texture3D **texture)
5981 struct d3d_device *device = impl_from_ID3D10Device(iface);
5982 D3D11_TEXTURE3D_DESC d3d11_desc;
5983 struct d3d_texture3d *object;
5984 HRESULT hr;
5986 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5988 d3d11_desc.Width = desc->Width;
5989 d3d11_desc.Height = desc->Height;
5990 d3d11_desc.Depth = desc->Depth;
5991 d3d11_desc.MipLevels = desc->MipLevels;
5992 d3d11_desc.Format = desc->Format;
5993 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5994 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5995 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5996 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5998 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5999 return hr;
6001 *texture = &object->ID3D10Texture3D_iface;
6003 return S_OK;
6006 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
6007 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
6009 struct d3d_device *device = impl_from_ID3D10Device(iface);
6010 struct d3d_shader_resource_view *object;
6011 ID3D11Resource *d3d11_resource;
6012 HRESULT hr;
6014 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6016 if (!resource)
6017 return E_INVALIDARG;
6019 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6021 ERR("Resource does not implement ID3D11Resource.\n");
6022 return E_FAIL;
6025 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
6026 &object);
6027 ID3D11Resource_Release(d3d11_resource);
6028 if (FAILED(hr))
6029 return hr;
6031 *view = &object->ID3D10ShaderResourceView1_iface;
6033 return S_OK;
6036 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
6037 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
6039 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6041 return d3d10_device_CreateShaderResourceView1(iface, resource,
6042 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
6045 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
6046 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6048 struct d3d_device *device = impl_from_ID3D10Device(iface);
6049 struct d3d_rendertarget_view *object;
6050 ID3D11Resource *d3d11_resource;
6051 HRESULT hr;
6053 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6055 if (!resource)
6056 return E_INVALIDARG;
6058 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6060 ERR("Resource does not implement ID3D11Resource.\n");
6061 return E_FAIL;
6064 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6065 ID3D11Resource_Release(d3d11_resource);
6066 if (FAILED(hr))
6067 return hr;
6069 *view = &object->ID3D10RenderTargetView_iface;
6071 return S_OK;
6074 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6076 return (D3D11_DSV_DIMENSION)dim;
6079 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6080 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6082 struct d3d_device *device = impl_from_ID3D10Device(iface);
6083 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6084 struct d3d_depthstencil_view *object;
6085 ID3D11Resource *d3d11_resource;
6086 HRESULT hr;
6088 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6090 if (desc)
6092 d3d11_desc.Format = desc->Format;
6093 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6094 d3d11_desc.Flags = 0;
6095 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6098 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6100 ERR("Resource does not implement ID3D11Resource.\n");
6101 return E_FAIL;
6104 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6105 ID3D11Resource_Release(d3d11_resource);
6106 if (FAILED(hr))
6107 return hr;
6109 *view = &object->ID3D10DepthStencilView_iface;
6111 return S_OK;
6114 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6115 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6116 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6117 ID3D10InputLayout **input_layout)
6119 struct d3d_device *device = impl_from_ID3D10Device(iface);
6120 struct d3d_input_layout *object;
6121 HRESULT hr;
6123 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6124 "shader_byte_code_length %lu, input_layout %p\n",
6125 iface, element_descs, element_count, shader_byte_code,
6126 shader_byte_code_length, input_layout);
6128 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6129 shader_byte_code, shader_byte_code_length, &object)))
6130 return hr;
6132 *input_layout = &object->ID3D10InputLayout_iface;
6134 return S_OK;
6137 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6138 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6140 struct d3d_device *device = impl_from_ID3D10Device(iface);
6141 struct d3d_vertex_shader *object;
6142 HRESULT hr;
6144 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6145 iface, byte_code, byte_code_length, shader);
6147 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6148 return hr;
6150 *shader = &object->ID3D10VertexShader_iface;
6152 return S_OK;
6155 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6156 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6158 struct d3d_device *device = impl_from_ID3D10Device(iface);
6159 struct d3d_geometry_shader *object;
6160 HRESULT hr;
6162 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6163 iface, byte_code, byte_code_length, shader);
6165 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6166 NULL, 0, NULL, 0, 0, &object)))
6167 return hr;
6169 *shader = &object->ID3D10GeometryShader_iface;
6171 return S_OK;
6174 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6175 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6176 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6178 struct d3d_device *device = impl_from_ID3D10Device(iface);
6179 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6180 struct d3d_geometry_shader *object;
6181 unsigned int i, stride_count = 1;
6182 HRESULT hr;
6184 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
6185 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6186 iface, byte_code, byte_code_length, output_stream_decls,
6187 output_stream_decl_count, output_stream_stride, shader);
6189 if (!output_stream_decl_count && output_stream_stride)
6191 WARN("Stride must be 0 when declaration entry count is 0.\n");
6192 *shader = NULL;
6193 return E_INVALIDARG;
6196 if (output_stream_decl_count
6197 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6199 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6200 *shader = NULL;
6201 return E_OUTOFMEMORY;
6204 for (i = 0; i < output_stream_decl_count; ++i)
6206 so_entries[i].Stream = 0;
6207 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6208 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6209 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6210 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6211 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6213 if (output_stream_decls[i].OutputSlot)
6215 stride_count = 0;
6216 if (output_stream_stride)
6218 WARN("Stride must be 0 when multiple output slots are used.\n");
6219 heap_free(so_entries);
6220 *shader = NULL;
6221 return E_INVALIDARG;
6226 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6227 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6228 heap_free(so_entries);
6229 if (FAILED(hr))
6231 *shader = NULL;
6232 return hr;
6235 *shader = &object->ID3D10GeometryShader_iface;
6237 return hr;
6240 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6241 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6243 struct d3d_device *device = impl_from_ID3D10Device(iface);
6244 struct d3d_pixel_shader *object;
6245 HRESULT hr;
6247 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6248 iface, byte_code, byte_code_length, shader);
6250 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6251 return hr;
6253 *shader = &object->ID3D10PixelShader_iface;
6255 return S_OK;
6258 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6259 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6261 struct d3d_device *device = impl_from_ID3D10Device(iface);
6262 struct d3d_blend_state *object;
6263 HRESULT hr;
6265 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6267 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6268 return hr;
6270 *blend_state = &object->ID3D10BlendState1_iface;
6272 return S_OK;
6275 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6276 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6278 D3D10_BLEND_DESC1 d3d10_1_desc;
6279 unsigned int i;
6281 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6283 if (!desc)
6284 return E_INVALIDARG;
6286 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6287 d3d10_1_desc.IndependentBlendEnable = FALSE;
6288 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6290 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6291 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6292 d3d10_1_desc.IndependentBlendEnable = TRUE;
6295 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6297 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6298 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6299 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6300 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6301 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6302 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6303 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6304 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6307 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6310 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6311 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6313 struct d3d_device *device = impl_from_ID3D10Device(iface);
6314 struct d3d_depthstencil_state *object;
6315 HRESULT hr;
6317 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6319 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6320 return hr;
6322 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6324 return S_OK;
6327 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6328 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6330 struct d3d_device *device = impl_from_ID3D10Device(iface);
6331 struct d3d_rasterizer_state *object;
6332 HRESULT hr;
6334 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6336 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6337 return hr;
6339 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6341 return S_OK;
6344 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6345 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6347 struct d3d_device *device = impl_from_ID3D10Device(iface);
6348 struct d3d_sampler_state *object;
6349 HRESULT hr;
6351 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6353 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6354 return hr;
6356 *sampler_state = &object->ID3D10SamplerState_iface;
6358 return S_OK;
6361 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6362 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6364 struct d3d_device *device = impl_from_ID3D10Device(iface);
6365 struct d3d_query *object;
6366 HRESULT hr;
6368 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6370 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6371 return hr;
6373 if (query)
6375 *query = &object->ID3D10Query_iface;
6376 return S_OK;
6379 ID3D10Query_Release(&object->ID3D10Query_iface);
6380 return S_FALSE;
6383 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6384 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6386 struct d3d_device *device = impl_from_ID3D10Device(iface);
6387 struct d3d_query *object;
6388 HRESULT hr;
6390 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6392 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6393 return hr;
6395 if (predicate)
6397 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6398 return S_OK;
6401 ID3D10Query_Release(&object->ID3D10Query_iface);
6402 return S_FALSE;
6405 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6406 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6408 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6410 return E_NOTIMPL;
6413 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6414 DXGI_FORMAT format, UINT *format_support)
6416 struct d3d_device *device = impl_from_ID3D10Device(iface);
6418 TRACE("iface %p, format %s, format_support %p.\n",
6419 iface, debug_dxgi_format(format), format_support);
6421 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6424 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6425 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6427 struct d3d_device *device = impl_from_ID3D10Device(iface);
6429 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6430 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6432 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6433 sample_count, quality_level_count);
6436 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6438 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6441 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6442 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6443 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6445 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6446 "units %p, units_length %p, description %p, description_length %p stub!\n",
6447 iface, desc, type, active_counters, name, name_length,
6448 units, units_length, description, description_length);
6450 return E_NOTIMPL;
6453 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6455 FIXME("iface %p stub!\n", iface);
6457 return 0;
6460 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6461 HANDLE resource_handle, REFIID guid, void **resource)
6463 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6464 iface, resource_handle, debugstr_guid(guid), resource);
6466 return E_NOTIMPL;
6469 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6471 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6474 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6476 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6479 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6481 return (D3D10_FEATURE_LEVEL1)level;
6484 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6486 struct d3d_device *device = impl_from_ID3D10Device(iface);
6488 TRACE("iface %p.\n", iface);
6490 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6493 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6495 /* IUnknown methods */
6496 d3d10_device_QueryInterface,
6497 d3d10_device_AddRef,
6498 d3d10_device_Release,
6499 /* ID3D10Device methods */
6500 d3d10_device_VSSetConstantBuffers,
6501 d3d10_device_PSSetShaderResources,
6502 d3d10_device_PSSetShader,
6503 d3d10_device_PSSetSamplers,
6504 d3d10_device_VSSetShader,
6505 d3d10_device_DrawIndexed,
6506 d3d10_device_Draw,
6507 d3d10_device_PSSetConstantBuffers,
6508 d3d10_device_IASetInputLayout,
6509 d3d10_device_IASetVertexBuffers,
6510 d3d10_device_IASetIndexBuffer,
6511 d3d10_device_DrawIndexedInstanced,
6512 d3d10_device_DrawInstanced,
6513 d3d10_device_GSSetConstantBuffers,
6514 d3d10_device_GSSetShader,
6515 d3d10_device_IASetPrimitiveTopology,
6516 d3d10_device_VSSetShaderResources,
6517 d3d10_device_VSSetSamplers,
6518 d3d10_device_SetPredication,
6519 d3d10_device_GSSetShaderResources,
6520 d3d10_device_GSSetSamplers,
6521 d3d10_device_OMSetRenderTargets,
6522 d3d10_device_OMSetBlendState,
6523 d3d10_device_OMSetDepthStencilState,
6524 d3d10_device_SOSetTargets,
6525 d3d10_device_DrawAuto,
6526 d3d10_device_RSSetState,
6527 d3d10_device_RSSetViewports,
6528 d3d10_device_RSSetScissorRects,
6529 d3d10_device_CopySubresourceRegion,
6530 d3d10_device_CopyResource,
6531 d3d10_device_UpdateSubresource,
6532 d3d10_device_ClearRenderTargetView,
6533 d3d10_device_ClearDepthStencilView,
6534 d3d10_device_GenerateMips,
6535 d3d10_device_ResolveSubresource,
6536 d3d10_device_VSGetConstantBuffers,
6537 d3d10_device_PSGetShaderResources,
6538 d3d10_device_PSGetShader,
6539 d3d10_device_PSGetSamplers,
6540 d3d10_device_VSGetShader,
6541 d3d10_device_PSGetConstantBuffers,
6542 d3d10_device_IAGetInputLayout,
6543 d3d10_device_IAGetVertexBuffers,
6544 d3d10_device_IAGetIndexBuffer,
6545 d3d10_device_GSGetConstantBuffers,
6546 d3d10_device_GSGetShader,
6547 d3d10_device_IAGetPrimitiveTopology,
6548 d3d10_device_VSGetShaderResources,
6549 d3d10_device_VSGetSamplers,
6550 d3d10_device_GetPredication,
6551 d3d10_device_GSGetShaderResources,
6552 d3d10_device_GSGetSamplers,
6553 d3d10_device_OMGetRenderTargets,
6554 d3d10_device_OMGetBlendState,
6555 d3d10_device_OMGetDepthStencilState,
6556 d3d10_device_SOGetTargets,
6557 d3d10_device_RSGetState,
6558 d3d10_device_RSGetViewports,
6559 d3d10_device_RSGetScissorRects,
6560 d3d10_device_GetDeviceRemovedReason,
6561 d3d10_device_SetExceptionMode,
6562 d3d10_device_GetExceptionMode,
6563 d3d10_device_GetPrivateData,
6564 d3d10_device_SetPrivateData,
6565 d3d10_device_SetPrivateDataInterface,
6566 d3d10_device_ClearState,
6567 d3d10_device_Flush,
6568 d3d10_device_CreateBuffer,
6569 d3d10_device_CreateTexture1D,
6570 d3d10_device_CreateTexture2D,
6571 d3d10_device_CreateTexture3D,
6572 d3d10_device_CreateShaderResourceView,
6573 d3d10_device_CreateRenderTargetView,
6574 d3d10_device_CreateDepthStencilView,
6575 d3d10_device_CreateInputLayout,
6576 d3d10_device_CreateVertexShader,
6577 d3d10_device_CreateGeometryShader,
6578 d3d10_device_CreateGeometryShaderWithStreamOutput,
6579 d3d10_device_CreatePixelShader,
6580 d3d10_device_CreateBlendState,
6581 d3d10_device_CreateDepthStencilState,
6582 d3d10_device_CreateRasterizerState,
6583 d3d10_device_CreateSamplerState,
6584 d3d10_device_CreateQuery,
6585 d3d10_device_CreatePredicate,
6586 d3d10_device_CreateCounter,
6587 d3d10_device_CheckFormatSupport,
6588 d3d10_device_CheckMultisampleQualityLevels,
6589 d3d10_device_CheckCounterInfo,
6590 d3d10_device_CheckCounter,
6591 d3d10_device_GetCreationFlags,
6592 d3d10_device_OpenSharedResource,
6593 d3d10_device_SetTextFilterSize,
6594 d3d10_device_GetTextFilterSize,
6595 d3d10_device_CreateShaderResourceView1,
6596 d3d10_device_CreateBlendState1,
6597 d3d10_device_GetFeatureLevel,
6600 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6602 /* IUnknown methods */
6603 d3d_device_inner_QueryInterface,
6604 d3d_device_inner_AddRef,
6605 d3d_device_inner_Release,
6608 /* ID3D10Multithread methods */
6610 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6612 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6615 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6617 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6619 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6621 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6624 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6626 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6628 TRACE("iface %p.\n", iface);
6630 return IUnknown_AddRef(device->outer_unk);
6633 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6635 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6637 TRACE("iface %p.\n", iface);
6639 return IUnknown_Release(device->outer_unk);
6642 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6644 TRACE("iface %p.\n", iface);
6646 wined3d_mutex_lock();
6649 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6651 TRACE("iface %p.\n", iface);
6653 wined3d_mutex_unlock();
6656 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6658 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6660 return TRUE;
6663 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6665 FIXME("iface %p stub!\n", iface);
6667 return TRUE;
6670 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6672 d3d10_multithread_QueryInterface,
6673 d3d10_multithread_AddRef,
6674 d3d10_multithread_Release,
6675 d3d10_multithread_Enter,
6676 d3d10_multithread_Leave,
6677 d3d10_multithread_SetMultithreadProtected,
6678 d3d10_multithread_GetMultithreadProtected,
6681 /* IWineDXGIDeviceParent IUnknown methods */
6683 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6685 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6688 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6689 REFIID iid, void **out)
6691 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6692 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6695 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6697 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6698 return IUnknown_AddRef(device->outer_unk);
6701 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6703 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6704 return IUnknown_Release(device->outer_unk);
6707 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6708 IWineDXGIDeviceParent *iface)
6710 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6711 return &device->device_parent;
6714 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6716 /* IUnknown methods */
6717 dxgi_device_parent_QueryInterface,
6718 dxgi_device_parent_AddRef,
6719 dxgi_device_parent_Release,
6720 /* IWineDXGIDeviceParent methods */
6721 dxgi_device_parent_get_wined3d_device_parent,
6724 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6726 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6729 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6730 struct wined3d_device *wined3d_device)
6732 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6733 struct d3d_device_context_state *state;
6734 struct wined3d_state *wined3d_state;
6735 D3D_FEATURE_LEVEL feature_level;
6737 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6739 wined3d_device_incref(wined3d_device);
6740 device->wined3d_device = wined3d_device;
6741 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6743 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6744 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6746 if (!(state = heap_alloc_zero(sizeof(*state))))
6748 ERR("Failed to create the initial device context state.\n");
6749 return;
6752 d3d_device_context_state_init(state, device, feature_level,
6753 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6755 device->state = state;
6756 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6757 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6759 d3d_device_context_state_private_addref(state);
6760 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6763 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6765 TRACE("device_parent %p.\n", device_parent);
6768 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6770 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6773 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6774 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6775 void **parent, const struct wined3d_parent_ops **parent_ops)
6777 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6778 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6780 *parent = NULL;
6781 *parent_ops = &d3d_null_wined3d_parent_ops;
6783 return S_OK;
6786 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6787 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6788 struct wined3d_texture **wined3d_texture)
6790 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6791 struct d3d_texture2d *texture;
6792 ID3D11Texture2D *texture_iface;
6793 D3D11_TEXTURE2D_DESC desc;
6794 HRESULT hr;
6796 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6797 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6799 desc.Width = wined3d_desc->width;
6800 desc.Height = wined3d_desc->height;
6801 desc.MipLevels = 1;
6802 desc.ArraySize = 1;
6803 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6804 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6805 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6806 desc.Usage = D3D11_USAGE_DEFAULT;
6807 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6808 desc.CPUAccessFlags = 0;
6809 desc.MiscFlags = 0;
6811 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6813 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6814 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6817 if (texture_flags)
6818 FIXME("Unhandled flags %#x.\n", texture_flags);
6820 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6821 &desc, NULL, &texture_iface)))
6823 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6824 return hr;
6827 texture = impl_from_ID3D11Texture2D(texture_iface);
6829 *wined3d_texture = texture->wined3d_texture;
6830 wined3d_texture_incref(*wined3d_texture);
6831 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6833 return S_OK;
6836 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6838 device_parent_wined3d_device_created,
6839 device_parent_mode_changed,
6840 device_parent_activate,
6841 device_parent_texture_sub_resource_created,
6842 device_parent_create_swapchain_texture,
6845 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6847 const D3D11_SAMPLER_DESC *ka = key;
6848 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6850 return memcmp(ka, kb, sizeof(*ka));
6853 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6855 const D3D11_BLEND_DESC *ka = key;
6856 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6858 return memcmp(ka, kb, sizeof(*ka));
6861 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6863 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6864 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6865 const struct d3d_depthstencil_state, entry)->desc;
6867 return memcmp(ka, kb, sizeof(*ka));
6870 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6872 const D3D11_RASTERIZER_DESC *ka = key;
6873 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6875 return memcmp(ka, kb, sizeof(*ka));
6878 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6880 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6881 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6882 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6883 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6884 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6885 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6886 device->refcount = 1;
6887 /* COM aggregation always takes place */
6888 device->outer_unk = outer_unknown;
6889 device->d3d11_only = FALSE;
6890 device->state = NULL;
6892 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6893 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6895 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6896 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6897 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6898 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);