winegstreamer: Unblock waits in sink_chain_cb() when disabling a stream.
[wine.git] / dlls / d3d11 / device.c
blobe73d6726f5d2a6f60871b4e3c1af0223453a7d0b
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_command_list_decref(list->wined3d_list);
379 wined3d_private_store_cleanup(&list->private_store);
380 ID3D11Device2_Release(list->device);
381 heap_free(list);
384 return refcount;
387 static void STDMETHODCALLTYPE d3d11_command_list_GetDevice(ID3D11CommandList *iface, ID3D11Device **device)
389 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
391 TRACE("iface %p, device %p.\n", iface, device);
393 *device = (ID3D11Device *)list->device;
394 ID3D11Device2_AddRef(list->device);
397 static HRESULT STDMETHODCALLTYPE d3d11_command_list_GetPrivateData(ID3D11CommandList *iface, REFGUID guid,
398 UINT *data_size, void *data)
400 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
402 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
404 return d3d_get_private_data(&list->private_store, guid, data_size, data);
407 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateData(ID3D11CommandList *iface, REFGUID guid,
408 UINT data_size, const void *data)
410 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
412 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
414 return d3d_set_private_data(&list->private_store, guid, data_size, data);
417 static HRESULT STDMETHODCALLTYPE d3d11_command_list_SetPrivateDataInterface(ID3D11CommandList *iface,
418 REFGUID guid, const IUnknown *data)
420 struct d3d11_command_list *list = impl_from_ID3D11CommandList(iface);
422 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
424 return d3d_set_private_data_interface(&list->private_store, guid, data);
427 static UINT STDMETHODCALLTYPE d3d11_command_list_GetContextFlags(ID3D11CommandList *iface)
429 TRACE("iface %p.\n", iface);
431 return 0;
434 static const struct ID3D11CommandListVtbl d3d11_command_list_vtbl =
436 /* IUnknown methods */
437 d3d11_command_list_QueryInterface,
438 d3d11_command_list_AddRef,
439 d3d11_command_list_Release,
440 /* ID3D11DeviceChild methods */
441 d3d11_command_list_GetDevice,
442 d3d11_command_list_GetPrivateData,
443 d3d11_command_list_SetPrivateData,
444 d3d11_command_list_SetPrivateDataInterface,
445 /* ID3D11CommandList methods */
446 d3d11_command_list_GetContextFlags,
449 static struct d3d11_command_list *unsafe_impl_from_ID3D11CommandList(ID3D11CommandList *iface)
451 if (!iface)
452 return NULL;
453 assert(iface->lpVtbl == &d3d11_command_list_vtbl);
454 return impl_from_ID3D11CommandList(iface);
457 static void d3d11_device_context_cleanup(struct d3d11_device_context *context)
459 wined3d_private_store_cleanup(&context->private_store);
462 /* ID3D11DeviceContext - immediate context methods */
464 static inline struct d3d11_device_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
466 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11DeviceContext1_iface);
469 static HRESULT STDMETHODCALLTYPE d3d11_device_context_QueryInterface(ID3D11DeviceContext1 *iface,
470 REFIID iid, void **out)
472 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
474 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
476 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
477 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
478 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
479 || IsEqualGUID(iid, &IID_IUnknown))
481 *out = &context->ID3D11DeviceContext1_iface;
483 else if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE && IsEqualGUID(iid, &IID_ID3D11Multithread))
485 *out = &context->ID3D11Multithread_iface;
487 else if (IsEqualGUID(iid, &IID_ID3DUserDefinedAnnotation))
489 *out = &context->ID3DUserDefinedAnnotation_iface;
491 else
493 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
494 *out = NULL;
495 return E_NOINTERFACE;
498 ID3D11DeviceContext1_AddRef(iface);
499 return S_OK;
502 static ULONG STDMETHODCALLTYPE d3d11_device_context_AddRef(ID3D11DeviceContext1 *iface)
504 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
505 ULONG refcount = InterlockedIncrement(&context->refcount);
507 TRACE("%p increasing refcount to %u.\n", context, refcount);
509 if (refcount == 1)
511 ID3D11Device2_AddRef(&context->device->ID3D11Device2_iface);
514 return refcount;
517 static ULONG STDMETHODCALLTYPE d3d11_device_context_Release(ID3D11DeviceContext1 *iface)
519 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
520 ULONG refcount = InterlockedDecrement(&context->refcount);
522 TRACE("%p decreasing refcount to %u.\n", context, refcount);
524 if (!refcount)
526 ID3D11Device2 *device = &context->device->ID3D11Device2_iface;
527 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
529 wined3d_deferred_context_destroy(context->wined3d_context);
530 d3d11_device_context_cleanup(context);
531 heap_free(context);
533 ID3D11Device2_Release(device);
536 return refcount;
539 static void d3d11_device_context_get_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
540 unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer **buffers,
541 unsigned int *offsets, unsigned int *counts)
543 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
544 unsigned int i;
546 wined3d_mutex_lock();
547 for (i = 0; i < buffer_count; ++i)
549 struct wined3d_constant_buffer_state state;
550 struct d3d_buffer *buffer_impl;
552 wined3d_device_context_get_constant_buffer(context->wined3d_context, type, start_slot + i, &state);
554 if (offsets)
555 offsets[i] = state.offset / sizeof(struct wined3d_vec4);
556 if (counts)
557 counts[i] = state.size / sizeof(struct wined3d_vec4);
559 if (!state.buffer)
561 buffers[i] = NULL;
562 continue;
565 buffer_impl = wined3d_buffer_get_parent(state.buffer);
566 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
567 ID3D11Buffer_AddRef(buffers[i]);
569 wined3d_mutex_unlock();
572 static void d3d11_device_context_set_constant_buffers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
573 unsigned int start_slot, unsigned int buffer_count, ID3D11Buffer *const *buffers,
574 const unsigned int *offsets, const unsigned int *counts)
576 static const unsigned int alignment = D3D11_COMMONSHADER_CONSTANT_BUFFER_PARTIAL_UPDATE_EXTENTS_BYTE_ALIGNMENT;
577 struct wined3d_constant_buffer_state wined3d_buffers[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
578 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
579 unsigned int i;
581 if (buffer_count > ARRAY_SIZE(wined3d_buffers))
583 WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
584 return;
587 if (!offsets != !counts)
589 WARN("Got offsets pointer %p but counts pointer %p; ignoring call.\n", offsets, counts);
590 return;
593 for (i = 0; i < buffer_count; ++i)
595 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
597 if (offsets && (offsets[i] & (alignment - 1)))
599 WARN("Offset %u is not aligned.\n", offsets[i]);
600 return;
603 if (counts && (counts[i] & (alignment - 1)))
605 WARN("Count %u is not aligned.\n", counts[i]);
606 return;
609 wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
610 wined3d_buffers[i].offset = (offsets ? offsets[i] : 0) * sizeof(struct wined3d_vec4);
611 wined3d_buffers[i].size = (counts ? counts[i] : WINED3D_MAX_CONSTANT_BUFFER_SIZE) * sizeof(struct wined3d_vec4);
614 wined3d_device_context_set_constant_buffers(context->wined3d_context,
615 type, start_slot, buffer_count, wined3d_buffers);
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_device_context_set_shader_resource_views(context->wined3d_context,
639 type, start_slot, count, wined3d_views);
642 static void d3d11_device_context_set_samplers(ID3D11DeviceContext1 *iface, enum wined3d_shader_type type,
643 unsigned int start_slot, unsigned int count, ID3D11SamplerState *const *samplers)
645 struct wined3d_sampler *wined3d_samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
646 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
647 unsigned int i;
649 if (count > ARRAY_SIZE(wined3d_samplers))
651 WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
652 return;
655 for (i = 0; i < count; ++i)
657 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
659 wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
662 wined3d_device_context_set_samplers(context->wined3d_context, type, start_slot, count, wined3d_samplers);
665 static void STDMETHODCALLTYPE d3d11_device_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
667 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
669 TRACE("iface %p, device %p.\n", iface, device);
671 *device = (ID3D11Device *)&context->device->ID3D11Device2_iface;
672 ID3D11Device_AddRef(*device);
675 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
676 UINT *data_size, void *data)
678 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
680 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
682 return d3d_get_private_data(&context->private_store, guid, data_size, data);
685 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
686 UINT data_size, const void *data)
688 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
690 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
692 return d3d_set_private_data(&context->private_store, guid, data_size, data);
695 static HRESULT STDMETHODCALLTYPE d3d11_device_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
696 REFGUID guid, const IUnknown *data)
698 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
700 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
702 return d3d_set_private_data_interface(&context->private_store, guid, data);
705 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
706 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
708 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
709 iface, start_slot, buffer_count, buffers);
711 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
712 buffer_count, buffers, NULL, NULL);
715 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
716 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
718 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
719 iface, start_slot, view_count, views);
721 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
724 static void STDMETHODCALLTYPE d3d11_device_context_PSSetShader(ID3D11DeviceContext1 *iface,
725 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
727 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
728 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
730 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
731 iface, shader, class_instances, class_instance_count);
733 if (class_instance_count)
734 FIXME("Dynamic linking is not implemented yet.\n");
736 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
737 ps ? ps->wined3d_shader : NULL);
740 static void STDMETHODCALLTYPE d3d11_device_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
741 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
743 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
744 iface, start_slot, sampler_count, samplers);
746 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
749 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShader(ID3D11DeviceContext1 *iface,
750 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
752 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
753 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
755 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
756 iface, shader, class_instances, class_instance_count);
758 if (class_instance_count)
759 FIXME("Dynamic linking is not implemented yet.\n");
761 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
762 vs ? vs->wined3d_shader : NULL);
765 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexed(ID3D11DeviceContext1 *iface,
766 UINT index_count, UINT start_index_location, INT base_vertex_location)
768 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
770 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
771 iface, index_count, start_index_location, base_vertex_location);
773 wined3d_device_context_draw_indexed(context->wined3d_context,
774 base_vertex_location, start_index_location, index_count, 0, 0);
777 static void STDMETHODCALLTYPE d3d11_device_context_Draw(ID3D11DeviceContext1 *iface,
778 UINT vertex_count, UINT start_vertex_location)
780 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
782 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
783 iface, vertex_count, start_vertex_location);
785 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
788 static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
789 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
791 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
792 struct wined3d_resource *wined3d_resource;
793 struct wined3d_map_desc map_desc;
794 HRESULT hr;
796 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
797 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
799 if (map_flags)
800 FIXME("Ignoring map_flags %#x.\n", map_flags);
802 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE
803 && map_type != D3D11_MAP_WRITE_DISCARD && map_type != D3D11_MAP_WRITE_NO_OVERWRITE)
804 return E_INVALIDARG;
806 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
808 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
809 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
811 mapped_subresource->pData = map_desc.data;
812 mapped_subresource->RowPitch = map_desc.row_pitch;
813 mapped_subresource->DepthPitch = map_desc.slice_pitch;
815 return hr;
818 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
819 UINT subresource_idx)
821 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
822 struct wined3d_resource *wined3d_resource;
824 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
826 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
828 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
831 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
832 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
834 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
835 iface, start_slot, buffer_count, buffers);
837 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
838 buffer_count, buffers, NULL, NULL);
841 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
842 ID3D11InputLayout *input_layout)
844 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
845 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
847 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
849 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
852 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
853 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
855 struct wined3d_stream_state streams[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
856 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
857 unsigned int i;
859 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
860 iface, start_slot, buffer_count, buffers, strides, offsets);
862 if (buffer_count > ARRAY_SIZE(streams))
864 WARN("Buffer count %u exceeds limit.\n", buffer_count);
865 buffer_count = ARRAY_SIZE(streams);
868 for (i = 0; i < buffer_count; ++i)
870 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
872 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
873 streams[i].offset = offsets[i];
874 streams[i].stride = strides[i];
875 streams[i].frequency = 1;
876 streams[i].flags = 0;
879 wined3d_device_context_set_stream_sources(context->wined3d_context, start_slot, buffer_count, streams);
882 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
883 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
885 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
886 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
888 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
889 iface, buffer, debug_dxgi_format(format), offset);
891 wined3d_device_context_set_index_buffer(context->wined3d_context,
892 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
893 wined3dformat_from_dxgi_format(format), offset);
896 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
897 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
898 UINT start_instance_location)
900 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
902 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
903 "base_vertex_location %d, start_instance_location %u.\n",
904 iface, instance_index_count, instance_count, start_index_location,
905 base_vertex_location, start_instance_location);
907 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
908 start_index_location, instance_index_count, start_instance_location, instance_count);
911 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
912 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
914 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
916 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
917 "start_instance_location %u.\n",
918 iface, instance_vertex_count, instance_count, start_vertex_location,
919 start_instance_location);
921 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
922 instance_vertex_count, start_instance_location, instance_count);
925 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
926 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
928 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
929 iface, start_slot, buffer_count, buffers);
931 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
932 buffer_count, buffers, NULL, NULL);
935 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
936 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
938 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
939 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
941 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
942 iface, shader, class_instances, class_instance_count);
944 if (class_instance_count)
945 FIXME("Dynamic linking is not implemented yet.\n");
947 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
948 gs ? gs->wined3d_shader : NULL);
951 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
952 D3D11_PRIMITIVE_TOPOLOGY topology)
954 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
955 enum wined3d_primitive_type primitive_type;
956 unsigned int patch_vertex_count;
958 TRACE("iface %p, topology %#x.\n", iface, topology);
960 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
962 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
965 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
966 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
968 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
970 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
973 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
974 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
976 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
977 iface, start_slot, sampler_count, samplers);
979 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
982 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
983 ID3D11Asynchronous *asynchronous)
985 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
986 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
988 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
990 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
993 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
994 ID3D11Asynchronous *asynchronous)
996 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
997 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
999 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
1001 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
1004 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
1005 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
1007 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1008 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1009 unsigned int wined3d_flags;
1010 HRESULT hr;
1012 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
1013 iface, asynchronous, data, data_size, data_flags);
1015 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
1016 return DXGI_ERROR_INVALID_CALL;
1018 if (!data && data_size)
1019 return E_INVALIDARG;
1021 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
1023 wined3d_mutex_lock();
1024 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
1026 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
1027 if (hr == WINED3DERR_INVALIDCALL)
1028 hr = DXGI_ERROR_INVALID_CALL;
1030 else
1032 WARN("Invalid data size %u.\n", data_size);
1033 hr = E_INVALIDARG;
1035 wined3d_mutex_unlock();
1037 return hr;
1040 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1041 ID3D11Predicate *predicate, BOOL value)
1043 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1044 struct d3d_query *query;
1046 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1048 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1050 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1053 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1054 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1056 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1058 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
1061 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1062 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1064 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1065 iface, start_slot, sampler_count, samplers);
1067 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
1070 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1071 UINT rtv_count, ID3D11RenderTargetView *const *rtvs, ID3D11DepthStencilView *depth_stencil_view)
1073 struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1074 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1075 struct d3d_depthstencil_view *dsv;
1076 unsigned int i;
1078 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
1080 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
1082 WARN("View count %u exceeds limit.\n", rtv_count);
1083 rtv_count = ARRAY_SIZE(wined3d_rtvs);
1086 for (i = 0; i < rtv_count; ++i)
1088 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(rtvs[i]);
1090 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1093 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1095 wined3d_device_context_set_render_targets_and_unordered_access_views(context->wined3d_context,
1096 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ~0u, NULL, NULL);
1099 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1100 ID3D11DeviceContext1 *iface, UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1101 ID3D11DepthStencilView *depth_stencil_view, UINT uav_start_idx, UINT uav_count,
1102 ID3D11UnorderedAccessView *const *uavs, const UINT *initial_counts)
1104 struct d3d_depthstencil_view *dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1105 struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1106 struct wined3d_unordered_access_view *wined3d_uavs[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0};
1107 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1108 unsigned int wined3d_initial_counts[D3D11_PS_CS_UAV_REGISTER_COUNT];
1109 unsigned int i;
1111 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1112 "uav_start_idx %u, uav_count %u, uavs %p, initial_counts %p.\n",
1113 iface, render_target_view_count, render_target_views, depth_stencil_view,
1114 uav_start_idx, uav_count, uavs, initial_counts);
1116 if (render_target_view_count == D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1117 render_target_view_count = ~0u;
1118 else
1120 if (render_target_view_count > ARRAY_SIZE(wined3d_rtvs))
1122 WARN("View count %u exceeds limit.\n", render_target_view_count);
1123 render_target_view_count = ARRAY_SIZE(wined3d_rtvs);
1126 for (i = 0; i < render_target_view_count; ++i)
1128 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
1130 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1134 if (uav_count == D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1135 uav_count = ~0u;
1136 else
1138 if (!wined3d_bound_range(uav_start_idx, uav_count, ARRAY_SIZE(wined3d_uavs)))
1140 WARN("View count %u exceeds limit; ignoring call.\n", uav_count);
1141 return;
1144 memset(wined3d_initial_counts, 0xff, sizeof(wined3d_initial_counts));
1146 for (i = 0; i < uav_count; ++i)
1148 struct d3d11_unordered_access_view *view =
1149 unsafe_impl_from_ID3D11UnorderedAccessView(uavs[i]);
1151 wined3d_uavs[uav_start_idx + i] = view ? view->wined3d_view : NULL;
1152 wined3d_initial_counts[uav_start_idx + i] = initial_counts ? initial_counts[i] : ~0u;
1156 wined3d_device_context_set_render_targets_and_unordered_access_views(context->wined3d_context, ARRAY_SIZE(wined3d_rtvs),
1157 wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ARRAY_SIZE(wined3d_uavs), wined3d_uavs,
1158 wined3d_initial_counts);
1161 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1162 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1164 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1165 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1166 struct d3d_blend_state *blend_state_impl;
1168 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1169 iface, blend_state, debug_float4(blend_factor), sample_mask);
1171 if (!blend_factor)
1172 blend_factor = default_blend_factor;
1174 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1175 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1176 (const struct wined3d_color *)blend_factor, sample_mask);
1177 else
1178 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1179 (const struct wined3d_color *)blend_factor, sample_mask);
1182 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1183 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1185 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1186 struct d3d_depthstencil_state *state_impl;
1188 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1189 iface, depth_stencil_state, stencil_ref);
1191 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1193 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1194 return;
1197 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1200 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1201 ID3D11Buffer *const *buffers, const UINT *offsets)
1203 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
1204 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1205 unsigned int count, i;
1207 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1209 count = min(buffer_count, ARRAY_SIZE(outputs));
1210 for (i = 0; i < count; ++i)
1212 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1214 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
1215 outputs[i].offset = offsets ? offsets[i] : 0;
1218 wined3d_device_context_set_stream_outputs(context->wined3d_context, outputs);
1221 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1223 FIXME("iface %p stub!\n", iface);
1226 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1227 ID3D11Buffer *buffer, UINT offset)
1229 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1230 struct d3d_buffer *d3d_buffer;
1232 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1234 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1236 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1239 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1240 ID3D11Buffer *buffer, UINT offset)
1242 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1243 struct d3d_buffer *d3d_buffer;
1245 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1247 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1249 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1252 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1253 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1255 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1257 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1258 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1260 wined3d_device_context_dispatch(context->wined3d_context,
1261 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1264 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1265 ID3D11Buffer *buffer, UINT offset)
1267 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1268 struct d3d_buffer *buffer_impl;
1270 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1272 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1274 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1277 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1278 ID3D11RasterizerState *rasterizer_state)
1280 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1281 struct d3d_rasterizer_state *rasterizer_state_impl;
1283 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1285 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1286 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1287 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1290 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1291 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1293 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1294 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1295 unsigned int i;
1297 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1299 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1300 return;
1302 for (i = 0; i < viewport_count; ++i)
1304 wined3d_vp[i].x = viewports[i].TopLeftX;
1305 wined3d_vp[i].y = viewports[i].TopLeftY;
1306 wined3d_vp[i].width = viewports[i].Width;
1307 wined3d_vp[i].height = viewports[i].Height;
1308 wined3d_vp[i].min_z = viewports[i].MinDepth;
1309 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1312 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1315 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1316 UINT rect_count, const D3D11_RECT *rects)
1318 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1320 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1322 if (rect_count > WINED3D_MAX_VIEWPORTS)
1323 return;
1325 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1328 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1329 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1330 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1332 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1333 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1334 struct wined3d_box wined3d_src_box;
1336 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1337 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1338 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1339 src_resource, src_subresource_idx, src_box);
1341 if (!dst_resource || !src_resource)
1342 return;
1344 if (src_box)
1345 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1346 src_box->right, src_box->bottom, src_box->front, src_box->back);
1348 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1349 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1350 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1351 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1354 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1355 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1357 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1358 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1360 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1362 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1363 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1364 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1367 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1368 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1369 const void *data, UINT row_pitch, UINT depth_pitch)
1371 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1372 struct wined3d_resource *wined3d_resource;
1373 struct wined3d_box wined3d_box;
1375 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1376 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1378 if (box)
1379 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1381 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1382 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1383 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1386 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1387 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1389 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1390 struct d3d11_unordered_access_view *uav;
1391 struct d3d_buffer *buffer_impl;
1393 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1394 iface, dst_buffer, dst_offset, src_view);
1396 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1397 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1399 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1400 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1403 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1404 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1406 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1407 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1408 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1409 HRESULT hr;
1411 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1412 iface, render_target_view, debug_float4(color_rgba));
1414 if (!view)
1415 return;
1417 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1418 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1419 ERR("Failed to clear view, hr %#x.\n", hr);
1422 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1423 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1425 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1426 struct d3d11_unordered_access_view *view;
1428 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1429 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1431 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1432 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1433 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1436 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1437 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1439 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1440 struct d3d11_unordered_access_view *view;
1442 TRACE("iface %p, unordered_access_view %p, values %s.\n",
1443 iface, unordered_access_view, debug_float4(values));
1445 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1446 wined3d_device_context_clear_uav_float(context->wined3d_context,
1447 view->wined3d_view, (const struct wined3d_vec4 *)values);
1450 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1451 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1453 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1454 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1455 DWORD wined3d_flags;
1456 HRESULT hr;
1458 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1459 iface, depth_stencil_view, flags, depth, stencil);
1461 if (!view)
1462 return;
1464 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1466 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1467 wined3d_flags, NULL, depth, stencil)))
1468 ERR("Failed to clear view, hr %#x.\n", hr);
1471 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1472 ID3D11ShaderResourceView *view)
1474 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1475 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1477 TRACE("iface %p, view %p.\n", iface, view);
1479 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1482 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1483 ID3D11Resource *resource, FLOAT min_lod)
1485 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1488 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1489 ID3D11Resource *resource)
1491 FIXME("iface %p, resource %p stub!\n", iface, resource);
1493 return 0.0f;
1496 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1497 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1498 ID3D11Resource *src_resource, UINT src_subresource_idx,
1499 DXGI_FORMAT format)
1501 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1502 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1503 enum wined3d_format_id wined3d_format;
1505 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1506 "src_resource %p, src_subresource_idx %u, format %s.\n",
1507 iface, dst_resource, dst_subresource_idx,
1508 src_resource, src_subresource_idx, debug_dxgi_format(format));
1510 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1511 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1512 wined3d_format = wined3dformat_from_dxgi_format(format);
1513 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1514 wined3d_dst_resource, dst_subresource_idx,
1515 wined3d_src_resource, src_subresource_idx, wined3d_format);
1518 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1519 ID3D11CommandList *command_list, BOOL restore_state)
1521 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1522 struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);
1524 TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);
1526 wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
1529 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1530 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1532 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1533 iface, start_slot, view_count, views);
1535 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_HULL, start_slot, view_count, views);
1538 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1539 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1541 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1542 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1544 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1545 iface, shader, class_instances, class_instance_count);
1547 if (class_instance_count)
1548 FIXME("Dynamic linking is not implemented yet.\n");
1550 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1551 hs ? hs->wined3d_shader : NULL);
1554 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1555 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1557 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1558 iface, start_slot, sampler_count, samplers);
1560 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_HULL, start_slot, sampler_count, samplers);
1563 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1564 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1566 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1567 iface, start_slot, buffer_count, buffers);
1569 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1570 buffer_count, buffers, NULL, NULL);
1573 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1574 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1576 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1577 iface, start_slot, view_count, views);
1579 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, view_count, views);
1582 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1583 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1585 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1586 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1588 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1589 iface, shader, class_instances, class_instance_count);
1591 if (class_instance_count)
1592 FIXME("Dynamic linking is not implemented yet.\n");
1594 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1595 ds ? ds->wined3d_shader : NULL);
1598 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1599 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1601 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1602 iface, start_slot, sampler_count, samplers);
1604 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, sampler_count, samplers);
1607 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1608 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1610 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1611 iface, start_slot, buffer_count, buffers);
1613 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1614 buffer_count, buffers, NULL, NULL);
1617 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1618 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1620 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1621 iface, start_slot, view_count, views);
1623 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, view_count, views);
1626 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1627 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1629 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1630 struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT];
1631 unsigned int i;
1633 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1634 iface, start_slot, view_count, views, initial_counts);
1636 if (view_count > ARRAY_SIZE(wined3d_views))
1638 WARN("View count %u exceeds limit; ignoring call.\n", view_count);
1639 return;
1642 for (i = 0; i < view_count; ++i)
1644 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1646 wined3d_views[i] = view ? view->wined3d_view : NULL;
1649 wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1650 start_slot, view_count, wined3d_views, initial_counts);
1653 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1654 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1656 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1657 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1659 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1660 iface, shader, class_instances, class_instance_count);
1662 if (class_instance_count)
1663 FIXME("Dynamic linking is not implemented yet.\n");
1665 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1666 cs ? cs->wined3d_shader : NULL);
1669 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1670 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1672 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1673 iface, start_slot, sampler_count, samplers);
1675 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, sampler_count, samplers);
1678 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1679 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1681 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1682 iface, start_slot, buffer_count, buffers);
1684 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1685 buffer_count, buffers, NULL, NULL);
1688 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1689 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1691 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1692 iface, start_slot, buffer_count, buffers);
1694 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1695 buffer_count, buffers, NULL, NULL);
1698 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1699 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1701 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1702 unsigned int i;
1704 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1705 iface, start_slot, view_count, views);
1707 wined3d_mutex_lock();
1708 for (i = 0; i < view_count; ++i)
1710 struct wined3d_shader_resource_view *wined3d_view;
1711 struct d3d_shader_resource_view *view_impl;
1713 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1714 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1716 views[i] = NULL;
1717 continue;
1720 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1721 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1722 ID3D11ShaderResourceView_AddRef(views[i]);
1724 wined3d_mutex_unlock();
1727 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1728 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1730 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1731 struct wined3d_shader *wined3d_shader;
1732 struct d3d_pixel_shader *shader_impl;
1734 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1735 iface, shader, class_instances, class_instance_count);
1737 if (class_instance_count)
1738 *class_instance_count = 0;
1740 wined3d_mutex_lock();
1741 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1743 wined3d_mutex_unlock();
1744 *shader = NULL;
1745 return;
1748 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1749 wined3d_mutex_unlock();
1750 *shader = &shader_impl->ID3D11PixelShader_iface;
1751 ID3D11PixelShader_AddRef(*shader);
1754 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1755 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1757 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1758 unsigned int i;
1760 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1761 iface, start_slot, sampler_count, samplers);
1763 wined3d_mutex_lock();
1764 for (i = 0; i < sampler_count; ++i)
1766 struct wined3d_sampler *wined3d_sampler;
1767 struct d3d_sampler_state *sampler_impl;
1769 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1770 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1772 samplers[i] = NULL;
1773 continue;
1776 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1777 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1778 ID3D11SamplerState_AddRef(samplers[i]);
1780 wined3d_mutex_unlock();
1783 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1784 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1786 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1787 struct d3d_vertex_shader *shader_impl;
1788 struct wined3d_shader *wined3d_shader;
1790 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1791 iface, shader, class_instances, class_instance_count);
1793 if (class_instance_count)
1794 *class_instance_count = 0;
1796 wined3d_mutex_lock();
1797 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1799 wined3d_mutex_unlock();
1800 *shader = NULL;
1801 return;
1804 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1805 wined3d_mutex_unlock();
1806 *shader = &shader_impl->ID3D11VertexShader_iface;
1807 ID3D11VertexShader_AddRef(*shader);
1810 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1811 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1813 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1814 iface, start_slot, buffer_count, buffers);
1816 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1817 buffer_count, buffers, NULL, NULL);
1820 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1821 ID3D11InputLayout **input_layout)
1823 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1824 struct wined3d_vertex_declaration *wined3d_declaration;
1825 struct d3d_input_layout *input_layout_impl;
1827 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1829 wined3d_mutex_lock();
1830 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1832 wined3d_mutex_unlock();
1833 *input_layout = NULL;
1834 return;
1837 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1838 wined3d_mutex_unlock();
1839 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1840 ID3D11InputLayout_AddRef(*input_layout);
1843 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1844 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1846 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1847 unsigned int i;
1849 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1850 iface, start_slot, buffer_count, buffers, strides, offsets);
1852 wined3d_mutex_lock();
1853 for (i = 0; i < buffer_count; ++i)
1855 struct wined3d_buffer *wined3d_buffer = NULL;
1856 struct d3d_buffer *buffer_impl;
1858 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1859 &wined3d_buffer, &offsets[i], &strides[i])))
1861 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1862 if (strides)
1863 strides[i] = 0;
1864 if (offsets)
1865 offsets[i] = 0;
1868 if (!wined3d_buffer)
1870 buffers[i] = NULL;
1871 continue;
1874 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1875 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1877 wined3d_mutex_unlock();
1880 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1881 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1883 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1884 enum wined3d_format_id wined3d_format;
1885 struct wined3d_buffer *wined3d_buffer;
1886 struct d3d_buffer *buffer_impl;
1888 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1890 wined3d_mutex_lock();
1891 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1892 *format = dxgi_format_from_wined3dformat(wined3d_format);
1893 if (!wined3d_buffer)
1895 wined3d_mutex_unlock();
1896 *buffer = NULL;
1897 return;
1900 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1901 wined3d_mutex_unlock();
1902 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1905 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1906 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1908 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1909 iface, start_slot, buffer_count, buffers);
1911 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1912 buffer_count, buffers, NULL, NULL);
1915 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1916 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1918 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1919 struct d3d_geometry_shader *shader_impl;
1920 struct wined3d_shader *wined3d_shader;
1922 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1923 iface, shader, class_instances, class_instance_count);
1925 if (class_instance_count)
1926 *class_instance_count = 0;
1928 wined3d_mutex_lock();
1929 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
1931 wined3d_mutex_unlock();
1932 *shader = NULL;
1933 return;
1936 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1937 wined3d_mutex_unlock();
1938 *shader = &shader_impl->ID3D11GeometryShader_iface;
1939 ID3D11GeometryShader_AddRef(*shader);
1942 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
1943 D3D11_PRIMITIVE_TOPOLOGY *topology)
1945 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1946 enum wined3d_primitive_type primitive_type;
1947 unsigned int patch_vertex_count;
1949 TRACE("iface %p, topology %p.\n", iface, topology);
1951 wined3d_mutex_lock();
1952 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
1953 wined3d_mutex_unlock();
1955 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1958 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
1959 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1961 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1962 unsigned int i;
1964 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1966 wined3d_mutex_lock();
1967 for (i = 0; i < view_count; ++i)
1969 struct wined3d_shader_resource_view *wined3d_view;
1970 struct d3d_shader_resource_view *view_impl;
1972 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1973 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
1975 views[i] = NULL;
1976 continue;
1979 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1980 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1981 ID3D11ShaderResourceView_AddRef(views[i]);
1983 wined3d_mutex_unlock();
1986 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
1987 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1989 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1990 unsigned int i;
1992 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1993 iface, start_slot, sampler_count, samplers);
1995 wined3d_mutex_lock();
1996 for (i = 0; i < sampler_count; ++i)
1998 struct wined3d_sampler *wined3d_sampler;
1999 struct d3d_sampler_state *sampler_impl;
2001 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2002 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2004 samplers[i] = NULL;
2005 continue;
2008 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2009 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2010 ID3D11SamplerState_AddRef(samplers[i]);
2012 wined3d_mutex_unlock();
2015 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2016 ID3D11Predicate **predicate, BOOL *value)
2018 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2019 struct wined3d_query *wined3d_predicate;
2020 struct d3d_query *predicate_impl;
2022 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2024 wined3d_mutex_lock();
2025 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2027 wined3d_mutex_unlock();
2028 *predicate = NULL;
2029 return;
2032 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2033 wined3d_mutex_unlock();
2034 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2035 ID3D11Predicate_AddRef(*predicate);
2038 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2039 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2041 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2042 unsigned int i;
2044 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2046 wined3d_mutex_lock();
2047 for (i = 0; i < view_count; ++i)
2049 struct wined3d_shader_resource_view *wined3d_view;
2050 struct d3d_shader_resource_view *view_impl;
2052 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2053 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2055 views[i] = NULL;
2056 continue;
2059 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2060 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2061 ID3D11ShaderResourceView_AddRef(views[i]);
2063 wined3d_mutex_unlock();
2066 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2067 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2069 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2070 unsigned int i;
2072 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2073 iface, start_slot, sampler_count, samplers);
2075 wined3d_mutex_lock();
2076 for (i = 0; i < sampler_count; ++i)
2078 struct d3d_sampler_state *sampler_impl;
2079 struct wined3d_sampler *wined3d_sampler;
2081 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2082 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2084 samplers[i] = NULL;
2085 continue;
2088 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2089 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2090 ID3D11SamplerState_AddRef(samplers[i]);
2092 wined3d_mutex_unlock();
2095 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2096 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2097 ID3D11DepthStencilView **depth_stencil_view)
2099 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2100 struct wined3d_rendertarget_view *wined3d_view;
2102 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2103 iface, render_target_view_count, render_target_views, depth_stencil_view);
2105 wined3d_mutex_lock();
2106 if (render_target_views)
2108 struct d3d_rendertarget_view *view_impl;
2109 unsigned int i;
2111 for (i = 0; i < render_target_view_count; ++i)
2113 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2114 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2116 render_target_views[i] = NULL;
2117 continue;
2120 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2121 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2125 if (depth_stencil_view)
2127 struct d3d_depthstencil_view *view_impl;
2129 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2130 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2132 *depth_stencil_view = NULL;
2134 else
2136 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2137 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2140 wined3d_mutex_unlock();
2143 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2144 ID3D11DeviceContext1 *iface,
2145 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2146 ID3D11DepthStencilView **depth_stencil_view,
2147 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2148 ID3D11UnorderedAccessView **unordered_access_views)
2150 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2151 struct wined3d_unordered_access_view *wined3d_view;
2152 struct d3d11_unordered_access_view *view_impl;
2153 unsigned int i;
2155 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2156 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2157 "unordered_access_views %p.\n",
2158 iface, render_target_view_count, render_target_views, depth_stencil_view,
2159 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2161 if (render_target_views || depth_stencil_view)
2162 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2163 render_target_views, depth_stencil_view);
2165 if (unordered_access_views)
2167 wined3d_mutex_lock();
2168 for (i = 0; i < unordered_access_view_count; ++i)
2170 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2171 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2173 unordered_access_views[i] = NULL;
2174 continue;
2177 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2178 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2179 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2181 wined3d_mutex_unlock();
2185 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2186 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2188 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2189 struct wined3d_blend_state *wined3d_state;
2190 struct d3d_blend_state *blend_state_impl;
2191 unsigned int tmp_sample_mask;
2192 float tmp_blend_factor[4];
2194 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2195 iface, blend_state, blend_factor, sample_mask);
2197 wined3d_mutex_lock();
2198 if (!blend_factor) blend_factor = tmp_blend_factor;
2199 if (!sample_mask) sample_mask = &tmp_sample_mask;
2200 wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2201 (struct wined3d_color *)blend_factor, sample_mask);
2202 if (blend_state)
2204 if (wined3d_state)
2206 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2207 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2209 else
2210 *blend_state = NULL;
2212 wined3d_mutex_unlock();
2215 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2216 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2218 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2219 struct wined3d_depth_stencil_state *wined3d_state;
2220 struct d3d_depthstencil_state *state_impl;
2221 UINT stencil_ref_tmp;
2223 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2224 iface, depth_stencil_state, stencil_ref);
2226 wined3d_mutex_lock();
2227 if (!stencil_ref) stencil_ref = &stencil_ref_tmp;
2228 wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref);
2229 if (depth_stencil_state)
2231 if (wined3d_state)
2233 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2234 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2236 else
2238 *depth_stencil_state = NULL;
2241 wined3d_mutex_unlock();
2244 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2245 UINT buffer_count, ID3D11Buffer **buffers)
2247 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2248 unsigned int i;
2250 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2252 wined3d_mutex_lock();
2253 for (i = 0; i < buffer_count; ++i)
2255 struct wined3d_buffer *wined3d_buffer;
2256 struct d3d_buffer *buffer_impl;
2258 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2260 buffers[i] = NULL;
2261 continue;
2264 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2265 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2266 ID3D11Buffer_AddRef(buffers[i]);
2268 wined3d_mutex_unlock();
2271 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2272 ID3D11RasterizerState **rasterizer_state)
2274 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2275 struct d3d_rasterizer_state *rasterizer_state_impl;
2276 struct wined3d_rasterizer_state *wined3d_state;
2278 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2280 wined3d_mutex_lock();
2281 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2283 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2284 *rasterizer_state = (ID3D11RasterizerState *)&rasterizer_state_impl->ID3D11RasterizerState1_iface;
2285 ID3D11RasterizerState_AddRef(*rasterizer_state);
2287 else
2289 *rasterizer_state = NULL;
2291 wined3d_mutex_unlock();
2294 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2295 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2297 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2298 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2299 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2301 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2303 if (!viewport_count)
2304 return;
2306 wined3d_mutex_lock();
2307 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2308 wined3d_mutex_unlock();
2310 if (!viewports)
2312 *viewport_count = actual_count;
2313 return;
2316 if (*viewport_count > actual_count)
2317 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2319 *viewport_count = min(actual_count, *viewport_count);
2320 for (i = 0; i < *viewport_count; ++i)
2322 viewports[i].TopLeftX = wined3d_vp[i].x;
2323 viewports[i].TopLeftY = wined3d_vp[i].y;
2324 viewports[i].Width = wined3d_vp[i].width;
2325 viewports[i].Height = wined3d_vp[i].height;
2326 viewports[i].MinDepth = wined3d_vp[i].min_z;
2327 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2331 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2332 UINT *rect_count, D3D11_RECT *rects)
2334 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2335 unsigned int actual_count;
2337 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2339 if (!rect_count)
2340 return;
2342 actual_count = *rect_count;
2344 wined3d_mutex_lock();
2345 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2346 wined3d_mutex_unlock();
2348 if (rects && *rect_count > actual_count)
2349 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2350 *rect_count = actual_count;
2353 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2354 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2356 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2357 unsigned int i;
2359 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2361 wined3d_mutex_lock();
2362 for (i = 0; i < view_count; ++i)
2364 struct wined3d_shader_resource_view *wined3d_view;
2365 struct d3d_shader_resource_view *view_impl;
2367 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2368 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2370 views[i] = NULL;
2371 continue;
2374 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2375 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2377 wined3d_mutex_unlock();
2380 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2381 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2383 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2384 struct d3d11_hull_shader *shader_impl;
2385 struct wined3d_shader *wined3d_shader;
2387 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2388 iface, shader, class_instances, class_instance_count);
2390 if (class_instance_count)
2391 *class_instance_count = 0;
2393 wined3d_mutex_lock();
2394 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2396 wined3d_mutex_unlock();
2397 *shader = NULL;
2398 return;
2401 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2402 wined3d_mutex_unlock();
2403 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2406 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2407 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2409 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2410 unsigned int i;
2412 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2413 iface, start_slot, sampler_count, samplers);
2415 wined3d_mutex_lock();
2416 for (i = 0; i < sampler_count; ++i)
2418 struct wined3d_sampler *wined3d_sampler;
2419 struct d3d_sampler_state *sampler_impl;
2421 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2422 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2424 samplers[i] = NULL;
2425 continue;
2428 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2429 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2431 wined3d_mutex_unlock();
2434 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2435 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2437 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2438 iface, start_slot, buffer_count, buffers);
2440 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2441 buffer_count, buffers, NULL, NULL);
2444 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2445 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2447 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2448 unsigned int i;
2450 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2451 iface, start_slot, view_count, views);
2453 wined3d_mutex_lock();
2454 for (i = 0; i < view_count; ++i)
2456 struct wined3d_shader_resource_view *wined3d_view;
2457 struct d3d_shader_resource_view *view_impl;
2459 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2460 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2462 views[i] = NULL;
2463 continue;
2466 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2467 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2469 wined3d_mutex_unlock();
2472 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2473 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2475 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2476 struct d3d11_domain_shader *shader_impl;
2477 struct wined3d_shader *wined3d_shader;
2479 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2480 iface, shader, class_instances, class_instance_count);
2482 if (class_instance_count)
2483 *class_instance_count = 0;
2485 wined3d_mutex_lock();
2486 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2488 wined3d_mutex_unlock();
2489 *shader = NULL;
2490 return;
2493 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2494 wined3d_mutex_unlock();
2495 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2498 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2499 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2501 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2502 unsigned int i;
2504 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2505 iface, start_slot, sampler_count, samplers);
2507 wined3d_mutex_lock();
2508 for (i = 0; i < sampler_count; ++i)
2510 struct wined3d_sampler *wined3d_sampler;
2511 struct d3d_sampler_state *sampler_impl;
2513 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2514 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2516 samplers[i] = NULL;
2517 continue;
2520 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2521 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2523 wined3d_mutex_unlock();
2526 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2527 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2529 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2530 iface, start_slot, buffer_count, buffers);
2532 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2533 buffer_count, buffers, NULL, NULL);
2536 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2537 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2539 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2540 unsigned int i;
2542 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2544 wined3d_mutex_lock();
2545 for (i = 0; i < view_count; ++i)
2547 struct wined3d_shader_resource_view *wined3d_view;
2548 struct d3d_shader_resource_view *view_impl;
2550 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2551 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2553 views[i] = NULL;
2554 continue;
2557 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2558 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2560 wined3d_mutex_unlock();
2563 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2564 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2566 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2567 unsigned int i;
2569 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2571 wined3d_mutex_lock();
2572 for (i = 0; i < view_count; ++i)
2574 struct wined3d_unordered_access_view *wined3d_view;
2575 struct d3d11_unordered_access_view *view_impl;
2577 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2578 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2580 views[i] = NULL;
2581 continue;
2584 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2585 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2587 wined3d_mutex_unlock();
2590 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2591 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2593 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2594 struct d3d11_compute_shader *shader_impl;
2595 struct wined3d_shader *wined3d_shader;
2597 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2598 iface, shader, class_instances, class_instance_count);
2600 if (class_instance_count)
2601 *class_instance_count = 0;
2603 wined3d_mutex_lock();
2604 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2606 wined3d_mutex_unlock();
2607 *shader = NULL;
2608 return;
2611 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2612 wined3d_mutex_unlock();
2613 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2616 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2617 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2619 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2620 unsigned int i;
2622 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2623 iface, start_slot, sampler_count, samplers);
2625 wined3d_mutex_lock();
2626 for (i = 0; i < sampler_count; ++i)
2628 struct wined3d_sampler *wined3d_sampler;
2629 struct d3d_sampler_state *sampler_impl;
2631 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2632 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2634 samplers[i] = NULL;
2635 continue;
2638 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2639 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2641 wined3d_mutex_unlock();
2644 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2645 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2647 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2648 iface, start_slot, buffer_count, buffers);
2650 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2651 buffer_count, buffers, NULL, NULL);
2654 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2656 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2658 TRACE("iface %p.\n", iface);
2660 wined3d_device_context_reset_state(context->wined3d_context);
2663 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2665 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2667 TRACE("iface %p.\n", iface);
2669 wined3d_device_context_flush(context->wined3d_context);
2672 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2674 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2676 TRACE("iface %p.\n", iface);
2678 return context->type;
2681 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2683 TRACE("iface %p.\n", iface);
2685 return 0;
2688 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2689 BOOL restore, ID3D11CommandList **command_list)
2691 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2692 struct d3d11_command_list *object;
2693 HRESULT hr;
2695 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2697 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2699 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2700 return DXGI_ERROR_INVALID_CALL;
2703 if (!(object = heap_alloc_zero(sizeof(*object))))
2704 return E_OUTOFMEMORY;
2706 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2707 !!restore, &object->wined3d_list)))
2709 WARN("Failed to record wined3d command list, hr %#x.\n", hr);
2710 heap_free(object);
2711 return hr;
2714 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2715 object->refcount = 1;
2716 object->device = &context->device->ID3D11Device2_iface;
2717 wined3d_private_store_init(&object->private_store);
2719 ID3D11Device2_AddRef(object->device);
2721 TRACE("Created command list %p.\n", object);
2722 *command_list = &object->ID3D11CommandList_iface;
2724 return S_OK;
2727 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2728 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2729 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2731 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2732 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2733 struct wined3d_box wined3d_src_box;
2735 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2736 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2737 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2738 src_resource, src_subresource_idx, src_box, flags);
2740 if (!dst_resource || !src_resource)
2741 return;
2743 if (src_box)
2744 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2745 src_box->right, src_box->bottom, src_box->front, src_box->back);
2747 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2748 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2749 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2750 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2753 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2754 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2755 UINT row_pitch, UINT depth_pitch, UINT flags)
2757 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2758 struct wined3d_resource *wined3d_resource;
2759 struct wined3d_box wined3d_box;
2761 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2762 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2764 if (box)
2765 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2766 box->front, box->back);
2768 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2769 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2770 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2773 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2774 ID3D11Resource *resource)
2776 FIXME("iface %p, resource %p stub!\n", iface, resource);
2779 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2781 FIXME("iface %p, view %p stub!\n", iface, view);
2784 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2785 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2786 const UINT *num_constants)
2788 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2789 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2791 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2792 buffer_count, buffers, first_constant, num_constants);
2795 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2796 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2797 const UINT *num_constants)
2799 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2800 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2802 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2803 buffer_count, buffers, first_constant, num_constants);
2806 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2807 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2808 const UINT *num_constants)
2810 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2811 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2813 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2814 buffer_count, buffers, first_constant, num_constants);
2817 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2818 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2819 const UINT *num_constants)
2821 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2822 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2824 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2825 buffer_count, buffers, first_constant, num_constants);
2828 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2829 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2830 const UINT *num_constants)
2832 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2833 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2835 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2836 buffer_count, buffers, first_constant, num_constants);
2839 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2840 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2841 const UINT *num_constants)
2843 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2844 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2846 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2847 buffer_count, buffers, first_constant, num_constants);
2850 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2851 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2853 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2854 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2856 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2857 buffer_count, buffers, first_constant, num_constants);
2860 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2861 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2863 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2864 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2866 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2867 buffer_count, buffers, first_constant, num_constants);
2870 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2871 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2873 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2874 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2876 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2877 buffer_count, buffers, first_constant, num_constants);
2880 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2881 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2883 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2884 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2886 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2887 buffer_count, buffers, first_constant, num_constants);
2890 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2891 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, 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_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2897 buffer_count, buffers, first_constant, num_constants);
2900 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2901 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2903 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2904 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2906 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2907 buffer_count, buffers, first_constant, num_constants);
2910 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2911 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2913 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2914 struct d3d_device_context_state *state_impl, *prev_impl;
2915 struct d3d_device *device = context->device;
2916 struct wined3d_state *wined3d_state;
2917 static unsigned int once;
2919 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2921 if (prev)
2922 *prev = NULL;
2924 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
2926 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
2927 return;
2930 if (!state)
2931 return;
2933 wined3d_mutex_lock();
2935 prev_impl = device->state;
2936 state_impl = impl_from_ID3DDeviceContextState(state);
2937 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2938 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2939 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
2941 if (prev)
2942 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2944 d3d_device_context_state_private_addref(state_impl);
2945 device->state = state_impl;
2946 d3d_device_context_state_private_release(prev_impl);
2948 if (d3d_device_is_d3d10_active(device) && !once++)
2949 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2950 wined3d_mutex_unlock();
2953 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2954 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2956 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2959 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2960 const D3D11_RECT *rects, UINT num_rects)
2962 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
2965 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
2967 /* IUnknown methods */
2968 d3d11_device_context_QueryInterface,
2969 d3d11_device_context_AddRef,
2970 d3d11_device_context_Release,
2971 /* ID3D11DeviceChild methods */
2972 d3d11_device_context_GetDevice,
2973 d3d11_device_context_GetPrivateData,
2974 d3d11_device_context_SetPrivateData,
2975 d3d11_device_context_SetPrivateDataInterface,
2976 /* ID3D11DeviceContext methods */
2977 d3d11_device_context_VSSetConstantBuffers,
2978 d3d11_device_context_PSSetShaderResources,
2979 d3d11_device_context_PSSetShader,
2980 d3d11_device_context_PSSetSamplers,
2981 d3d11_device_context_VSSetShader,
2982 d3d11_device_context_DrawIndexed,
2983 d3d11_device_context_Draw,
2984 d3d11_device_context_Map,
2985 d3d11_device_context_Unmap,
2986 d3d11_device_context_PSSetConstantBuffers,
2987 d3d11_device_context_IASetInputLayout,
2988 d3d11_device_context_IASetVertexBuffers,
2989 d3d11_device_context_IASetIndexBuffer,
2990 d3d11_device_context_DrawIndexedInstanced,
2991 d3d11_device_context_DrawInstanced,
2992 d3d11_device_context_GSSetConstantBuffers,
2993 d3d11_device_context_GSSetShader,
2994 d3d11_device_context_IASetPrimitiveTopology,
2995 d3d11_device_context_VSSetShaderResources,
2996 d3d11_device_context_VSSetSamplers,
2997 d3d11_device_context_Begin,
2998 d3d11_device_context_End,
2999 d3d11_device_context_GetData,
3000 d3d11_device_context_SetPredication,
3001 d3d11_device_context_GSSetShaderResources,
3002 d3d11_device_context_GSSetSamplers,
3003 d3d11_device_context_OMSetRenderTargets,
3004 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3005 d3d11_device_context_OMSetBlendState,
3006 d3d11_device_context_OMSetDepthStencilState,
3007 d3d11_device_context_SOSetTargets,
3008 d3d11_device_context_DrawAuto,
3009 d3d11_device_context_DrawIndexedInstancedIndirect,
3010 d3d11_device_context_DrawInstancedIndirect,
3011 d3d11_device_context_Dispatch,
3012 d3d11_device_context_DispatchIndirect,
3013 d3d11_device_context_RSSetState,
3014 d3d11_device_context_RSSetViewports,
3015 d3d11_device_context_RSSetScissorRects,
3016 d3d11_device_context_CopySubresourceRegion,
3017 d3d11_device_context_CopyResource,
3018 d3d11_device_context_UpdateSubresource,
3019 d3d11_device_context_CopyStructureCount,
3020 d3d11_device_context_ClearRenderTargetView,
3021 d3d11_device_context_ClearUnorderedAccessViewUint,
3022 d3d11_device_context_ClearUnorderedAccessViewFloat,
3023 d3d11_device_context_ClearDepthStencilView,
3024 d3d11_device_context_GenerateMips,
3025 d3d11_device_context_SetResourceMinLOD,
3026 d3d11_device_context_GetResourceMinLOD,
3027 d3d11_device_context_ResolveSubresource,
3028 d3d11_device_context_ExecuteCommandList,
3029 d3d11_device_context_HSSetShaderResources,
3030 d3d11_device_context_HSSetShader,
3031 d3d11_device_context_HSSetSamplers,
3032 d3d11_device_context_HSSetConstantBuffers,
3033 d3d11_device_context_DSSetShaderResources,
3034 d3d11_device_context_DSSetShader,
3035 d3d11_device_context_DSSetSamplers,
3036 d3d11_device_context_DSSetConstantBuffers,
3037 d3d11_device_context_CSSetShaderResources,
3038 d3d11_device_context_CSSetUnorderedAccessViews,
3039 d3d11_device_context_CSSetShader,
3040 d3d11_device_context_CSSetSamplers,
3041 d3d11_device_context_CSSetConstantBuffers,
3042 d3d11_device_context_VSGetConstantBuffers,
3043 d3d11_device_context_PSGetShaderResources,
3044 d3d11_device_context_PSGetShader,
3045 d3d11_device_context_PSGetSamplers,
3046 d3d11_device_context_VSGetShader,
3047 d3d11_device_context_PSGetConstantBuffers,
3048 d3d11_device_context_IAGetInputLayout,
3049 d3d11_device_context_IAGetVertexBuffers,
3050 d3d11_device_context_IAGetIndexBuffer,
3051 d3d11_device_context_GSGetConstantBuffers,
3052 d3d11_device_context_GSGetShader,
3053 d3d11_device_context_IAGetPrimitiveTopology,
3054 d3d11_device_context_VSGetShaderResources,
3055 d3d11_device_context_VSGetSamplers,
3056 d3d11_device_context_GetPredication,
3057 d3d11_device_context_GSGetShaderResources,
3058 d3d11_device_context_GSGetSamplers,
3059 d3d11_device_context_OMGetRenderTargets,
3060 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3061 d3d11_device_context_OMGetBlendState,
3062 d3d11_device_context_OMGetDepthStencilState,
3063 d3d11_device_context_SOGetTargets,
3064 d3d11_device_context_RSGetState,
3065 d3d11_device_context_RSGetViewports,
3066 d3d11_device_context_RSGetScissorRects,
3067 d3d11_device_context_HSGetShaderResources,
3068 d3d11_device_context_HSGetShader,
3069 d3d11_device_context_HSGetSamplers,
3070 d3d11_device_context_HSGetConstantBuffers,
3071 d3d11_device_context_DSGetShaderResources,
3072 d3d11_device_context_DSGetShader,
3073 d3d11_device_context_DSGetSamplers,
3074 d3d11_device_context_DSGetConstantBuffers,
3075 d3d11_device_context_CSGetShaderResources,
3076 d3d11_device_context_CSGetUnorderedAccessViews,
3077 d3d11_device_context_CSGetShader,
3078 d3d11_device_context_CSGetSamplers,
3079 d3d11_device_context_CSGetConstantBuffers,
3080 d3d11_device_context_ClearState,
3081 d3d11_device_context_Flush,
3082 d3d11_device_context_GetType,
3083 d3d11_device_context_GetContextFlags,
3084 d3d11_device_context_FinishCommandList,
3085 /* ID3D11DeviceContext1 methods */
3086 d3d11_device_context_CopySubresourceRegion1,
3087 d3d11_device_context_UpdateSubresource1,
3088 d3d11_device_context_DiscardResource,
3089 d3d11_device_context_DiscardView,
3090 d3d11_device_context_VSSetConstantBuffers1,
3091 d3d11_device_context_HSSetConstantBuffers1,
3092 d3d11_device_context_DSSetConstantBuffers1,
3093 d3d11_device_context_GSSetConstantBuffers1,
3094 d3d11_device_context_PSSetConstantBuffers1,
3095 d3d11_device_context_CSSetConstantBuffers1,
3096 d3d11_device_context_VSGetConstantBuffers1,
3097 d3d11_device_context_HSGetConstantBuffers1,
3098 d3d11_device_context_DSGetConstantBuffers1,
3099 d3d11_device_context_GSGetConstantBuffers1,
3100 d3d11_device_context_PSGetConstantBuffers1,
3101 d3d11_device_context_CSGetConstantBuffers1,
3102 d3d11_device_context_SwapDeviceContextState,
3103 d3d11_device_context_ClearView,
3104 d3d11_device_context_DiscardView1,
3107 /* ID3D11Multithread methods */
3109 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3111 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3114 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3115 REFIID iid, void **out)
3117 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3119 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3121 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3124 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3126 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3128 TRACE("iface %p.\n", iface);
3130 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3133 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3135 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3137 TRACE("iface %p.\n", iface);
3139 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3142 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3144 TRACE("iface %p.\n", iface);
3146 wined3d_mutex_lock();
3149 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3151 TRACE("iface %p.\n", iface);
3153 wined3d_mutex_unlock();
3156 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3157 ID3D11Multithread *iface, BOOL enable)
3159 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3161 return TRUE;
3164 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3166 FIXME("iface %p stub!\n", iface);
3168 return TRUE;
3171 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3173 d3d11_multithread_QueryInterface,
3174 d3d11_multithread_AddRef,
3175 d3d11_multithread_Release,
3176 d3d11_multithread_Enter,
3177 d3d11_multithread_Leave,
3178 d3d11_multithread_SetMultithreadProtected,
3179 d3d11_multithread_GetMultithreadProtected,
3182 /* ID3DUserDefinedAnnotation methods */
3184 static inline struct d3d11_device_context *impl_from_ID3DUserDefinedAnnotation(ID3DUserDefinedAnnotation *iface)
3186 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3DUserDefinedAnnotation_iface);
3189 static HRESULT STDMETHODCALLTYPE d3d11_user_defined_annotation_QueryInterface(ID3DUserDefinedAnnotation *iface,
3190 REFIID iid, void **out)
3192 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3194 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3196 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3199 static ULONG STDMETHODCALLTYPE d3d11_user_defined_annotation_AddRef(ID3DUserDefinedAnnotation *iface)
3201 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3203 TRACE("iface %p.\n", iface);
3205 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3208 static ULONG STDMETHODCALLTYPE d3d11_user_defined_annotation_Release(ID3DUserDefinedAnnotation *iface)
3210 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3212 TRACE("iface %p.\n", iface);
3214 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3217 static int STDMETHODCALLTYPE d3d11_user_defined_annotation_BeginEvent(ID3DUserDefinedAnnotation *iface,
3218 const WCHAR *name)
3220 TRACE("iface %p, name %s.\n", iface, debugstr_w(name));
3222 return -1;
3225 static int STDMETHODCALLTYPE d3d11_user_defined_annotation_EndEvent(ID3DUserDefinedAnnotation *iface)
3227 TRACE("iface %p.\n", iface);
3229 return -1;
3232 static void STDMETHODCALLTYPE d3d11_user_defined_annotation_SetMarker(ID3DUserDefinedAnnotation *iface,
3233 const WCHAR *name)
3235 TRACE("iface %p, name %s.\n", iface, debugstr_w(name));
3238 static BOOL STDMETHODCALLTYPE d3d11_user_defined_annotation_GetStatus(ID3DUserDefinedAnnotation *iface)
3240 TRACE("iface %p.\n", iface);
3242 return FALSE;
3245 static const struct ID3DUserDefinedAnnotationVtbl d3d11_user_defined_annotation_vtbl =
3247 d3d11_user_defined_annotation_QueryInterface,
3248 d3d11_user_defined_annotation_AddRef,
3249 d3d11_user_defined_annotation_Release,
3250 d3d11_user_defined_annotation_BeginEvent,
3251 d3d11_user_defined_annotation_EndEvent,
3252 d3d11_user_defined_annotation_SetMarker,
3253 d3d11_user_defined_annotation_GetStatus,
3256 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3257 D3D11_DEVICE_CONTEXT_TYPE type)
3259 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3260 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3261 context->ID3DUserDefinedAnnotation_iface.lpVtbl = &d3d11_user_defined_annotation_vtbl;
3262 context->refcount = 1;
3263 context->type = type;
3265 context->device = device;
3266 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3268 wined3d_private_store_init(&context->private_store);
3271 /* ID3D11Device methods */
3273 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3275 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3276 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3279 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3281 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3282 return IUnknown_AddRef(device->outer_unk);
3285 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3287 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3288 return IUnknown_Release(device->outer_unk);
3291 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3292 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3294 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3295 struct d3d_buffer *object;
3296 HRESULT hr;
3298 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3300 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3301 return hr;
3303 *buffer = &object->ID3D11Buffer_iface;
3305 return S_OK;
3308 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3309 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3311 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3312 struct d3d_texture1d *object;
3313 HRESULT hr;
3315 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3317 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3318 return hr;
3320 *texture = &object->ID3D11Texture1D_iface;
3322 return S_OK;
3325 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3326 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3328 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3329 struct d3d_texture2d *object;
3330 HRESULT hr;
3332 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3334 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3335 return hr;
3337 *texture = &object->ID3D11Texture2D_iface;
3339 return S_OK;
3342 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3343 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3345 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3346 struct d3d_texture3d *object;
3347 HRESULT hr;
3349 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3351 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3352 return hr;
3354 *texture = &object->ID3D11Texture3D_iface;
3356 return S_OK;
3359 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3360 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3362 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3363 struct d3d_shader_resource_view *object;
3364 HRESULT hr;
3366 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3368 *view = NULL;
3370 if (!resource)
3371 return E_INVALIDARG;
3373 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3374 return hr;
3376 *view = &object->ID3D11ShaderResourceView_iface;
3378 return S_OK;
3381 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3382 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3384 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3385 struct d3d11_unordered_access_view *object;
3386 HRESULT hr;
3388 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3390 *view = NULL;
3392 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3393 return hr;
3395 *view = &object->ID3D11UnorderedAccessView_iface;
3397 return S_OK;
3400 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3401 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3403 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3404 struct d3d_rendertarget_view *object;
3405 HRESULT hr;
3407 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3409 *view = NULL;
3411 if (!resource)
3412 return E_INVALIDARG;
3414 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3415 return hr;
3417 *view = &object->ID3D11RenderTargetView_iface;
3419 return S_OK;
3422 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3423 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3425 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3426 struct d3d_depthstencil_view *object;
3427 HRESULT hr;
3429 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3431 *view = NULL;
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 D3D11_RASTERIZER_DESC1 desc1;
3675 HRESULT hr;
3677 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3679 if (!desc)
3680 return E_INVALIDARG;
3682 memcpy(&desc1, desc, sizeof(*desc));
3683 desc1.ForcedSampleCount = 0;
3685 if (FAILED(hr = d3d_rasterizer_state_create(device, &desc1, &object)))
3686 return hr;
3688 *rasterizer_state = (ID3D11RasterizerState *)&object->ID3D11RasterizerState1_iface;
3690 return S_OK;
3693 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3694 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3696 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3697 struct d3d_sampler_state *object;
3698 HRESULT hr;
3700 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3702 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3703 return hr;
3705 *sampler_state = &object->ID3D11SamplerState_iface;
3707 return S_OK;
3710 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3711 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3713 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3714 struct d3d_query *object;
3715 HRESULT hr;
3717 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3719 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3720 return hr;
3722 if (query)
3724 *query = &object->ID3D11Query_iface;
3725 return S_OK;
3728 ID3D11Query_Release(&object->ID3D11Query_iface);
3729 return S_FALSE;
3732 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3733 ID3D11Predicate **predicate)
3735 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3736 struct d3d_query *object;
3737 HRESULT hr;
3739 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3741 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3742 return hr;
3744 if (predicate)
3746 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3747 return S_OK;
3750 ID3D11Query_Release(&object->ID3D11Query_iface);
3751 return S_FALSE;
3754 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3755 ID3D11Counter **counter)
3757 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3759 return E_NOTIMPL;
3762 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3763 UINT flags, struct d3d11_device_context **context)
3765 struct d3d11_device_context *object;
3766 HRESULT hr;
3768 if (flags)
3769 FIXME("Ignoring flags %#x.\n", flags);
3771 if (!(object = heap_alloc_zero(sizeof(*object))))
3772 return E_OUTOFMEMORY;
3773 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3775 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3777 WARN("Failed to create wined3d deferred context, hr %#x.\n", hr);
3778 heap_free(object);
3779 return hr;
3782 TRACE("Created deferred context %p.\n", object);
3783 *context = object;
3785 return S_OK;
3788 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3789 ID3D11DeviceContext **context)
3791 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3792 struct d3d11_device_context *object;
3793 HRESULT hr;
3795 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3797 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3798 return hr;
3800 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3801 return S_OK;
3804 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3805 void **out)
3807 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3809 return E_NOTIMPL;
3812 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3813 UINT *format_support)
3815 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3816 struct wined3d_device_creation_parameters params;
3817 struct wined3d_adapter *wined3d_adapter;
3818 enum wined3d_format_id wined3d_format;
3819 D3D_FEATURE_LEVEL feature_level;
3820 struct wined3d *wined3d;
3821 unsigned int i;
3823 static const struct
3825 enum wined3d_resource_type rtype;
3826 unsigned int bind_flags;
3827 unsigned int usage;
3828 D3D11_FORMAT_SUPPORT flag;
3830 flag_mapping[] =
3832 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3833 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_VERTEX_BUFFER, 0, D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER},
3834 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_INDEX_BUFFER, 0, D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER},
3835 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3836 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3837 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3838 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3839 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3840 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3841 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3842 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3843 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3845 HRESULT hr;
3847 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3849 wined3d_format = wined3dformat_from_dxgi_format(format);
3850 if (format && !wined3d_format)
3852 WARN("Invalid format %#x.\n", format);
3853 *format_support = 0;
3854 return E_FAIL;
3857 *format_support = 0;
3859 wined3d_mutex_lock();
3860 feature_level = device->state->feature_level;
3861 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3862 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3863 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3864 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3866 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3867 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3868 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3869 continue;
3870 if (hr != WINED3D_OK)
3872 WARN("Failed to check device format support, hr %#x.\n", hr);
3873 wined3d_mutex_unlock();
3874 return E_FAIL;
3877 *format_support |= flag_mapping[i].flag;
3879 wined3d_mutex_unlock();
3881 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3882 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3884 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3885 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3887 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3888 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3889 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3891 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3892 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3894 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3896 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3897 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3899 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3900 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3904 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3905 * support multisample. */
3906 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3907 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3908 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3909 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3911 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3912 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3913 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3916 return S_OK;
3919 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3920 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3922 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3923 struct wined3d_device_creation_parameters params;
3924 struct wined3d_adapter *wined3d_adapter;
3925 struct wined3d *wined3d;
3926 HRESULT hr;
3928 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3929 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3931 if (!quality_level_count)
3932 return E_INVALIDARG;
3934 *quality_level_count = 0;
3936 if (!sample_count)
3937 return E_FAIL;
3938 if (sample_count == 1)
3940 *quality_level_count = 1;
3941 return S_OK;
3943 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3944 return E_FAIL;
3946 wined3d_mutex_lock();
3947 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3948 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3949 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3950 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3951 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3952 wined3d_mutex_unlock();
3954 if (hr == WINED3DERR_INVALIDCALL)
3955 return E_INVALIDARG;
3956 if (hr == WINED3DERR_NOTAVAILABLE)
3957 return S_OK;
3958 return hr;
3961 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3963 FIXME("iface %p, info %p stub!\n", iface, info);
3966 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3967 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3968 char *units, UINT *units_length, char *description, UINT *description_length)
3970 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3971 "units %p, units_length %p, description %p, description_length %p stub!\n",
3972 iface, desc, type, active_counter_count, name, name_length,
3973 units, units_length, description, description_length);
3975 return E_NOTIMPL;
3978 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3979 void *feature_support_data, UINT feature_support_data_size)
3981 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3982 struct wined3d_caps wined3d_caps;
3983 HRESULT hr;
3985 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3986 iface, feature, feature_support_data, feature_support_data_size);
3988 switch (feature)
3990 case D3D11_FEATURE_THREADING:
3992 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3993 if (feature_support_data_size != sizeof(*threading_data))
3995 WARN("Invalid data size.\n");
3996 return E_INVALIDARG;
3999 /* We lie about the threading support to make Tomb Raider 2013 and
4000 * Deus Ex: Human Revolution happy. */
4001 FIXME("Returning fake threading support data.\n");
4002 threading_data->DriverConcurrentCreates = TRUE;
4003 threading_data->DriverCommandLists = TRUE;
4004 return S_OK;
4007 case D3D11_FEATURE_DOUBLES:
4009 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
4010 if (feature_support_data_size != sizeof(*doubles_data))
4012 WARN("Invalid data size.\n");
4013 return E_INVALIDARG;
4016 wined3d_mutex_lock();
4017 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4018 wined3d_mutex_unlock();
4019 if (FAILED(hr))
4021 WARN("Failed to get device caps, hr %#x.\n", hr);
4022 return hr;
4025 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
4026 return S_OK;
4029 case D3D11_FEATURE_D3D9_OPTIONS:
4031 D3D11_FEATURE_DATA_D3D9_OPTIONS *options = feature_support_data;
4032 if (feature_support_data_size != sizeof(*options))
4034 WARN("Invalid data size.\n");
4035 return E_INVALIDARG;
4038 wined3d_mutex_lock();
4039 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4040 wined3d_mutex_unlock();
4041 if (FAILED(hr))
4043 WARN("Failed to get device caps, hr %#x.\n", hr);
4044 return hr;
4047 options->FullNonPow2TextureSupport = !(wined3d_caps.TextureCaps & WINED3DPTEXTURECAPS_POW2);
4048 return S_OK;
4051 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
4053 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
4054 if (feature_support_data_size != sizeof(*options))
4056 WARN("Invalid data size.\n");
4057 return E_INVALIDARG;
4060 wined3d_mutex_lock();
4061 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4062 wined3d_mutex_unlock();
4063 if (FAILED(hr))
4065 WARN("Failed to get device caps, hr %#x.\n", hr);
4066 return hr;
4069 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
4070 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4071 return S_OK;
4074 case D3D11_FEATURE_D3D11_OPTIONS:
4076 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4077 if (feature_support_data_size != sizeof(*options))
4079 WARN("Invalid data size.\n");
4080 return E_INVALIDARG;
4083 FIXME("Returning fake Options support data.\n");
4084 options->OutputMergerLogicOp = FALSE;
4085 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4086 options->DiscardAPIsSeenByDriver = FALSE;
4087 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4088 options->ClearView = FALSE;
4089 options->CopyWithOverlap = FALSE;
4090 options->ConstantBufferPartialUpdate = TRUE;
4091 options->ConstantBufferOffsetting = TRUE;
4092 options->MapNoOverwriteOnDynamicConstantBuffer = TRUE;
4093 options->MapNoOverwriteOnDynamicBufferSRV = TRUE;
4094 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4095 options->SAD4ShaderInstructions = FALSE;
4096 options->ExtendedDoublesShaderInstructions = FALSE;
4097 options->ExtendedResourceSharing = FALSE;
4098 return S_OK;
4101 case D3D11_FEATURE_D3D11_OPTIONS1:
4103 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4104 if (feature_support_data_size != sizeof(*options))
4106 WARN("Invalid data size.\n");
4107 return E_INVALIDARG;
4110 FIXME("Returning fake Options1 support data.\n");
4111 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4112 options->MinMaxFiltering = FALSE;
4113 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4114 options->MapOnDefaultBuffers = FALSE;
4115 return S_OK;
4118 case D3D11_FEATURE_D3D11_OPTIONS3:
4120 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4121 if (feature_support_data_size != sizeof(*options))
4123 WARN("Invalid data size.\n");
4124 return E_INVALIDARG;
4127 wined3d_mutex_lock();
4128 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4129 wined3d_mutex_unlock();
4130 if (FAILED(hr))
4132 WARN("Failed to get device caps, hr %#x.\n", hr);
4133 return hr;
4136 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4137 = wined3d_caps.viewport_array_index_any_shader;
4138 return S_OK;
4141 case D3D11_FEATURE_ARCHITECTURE_INFO:
4143 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4144 if (feature_support_data_size != sizeof(*options))
4146 WARN("Invalid data size.\n");
4147 return E_INVALIDARG;
4150 FIXME("Returning fake data architecture info.\n");
4151 options->TileBasedDeferredRenderer = FALSE;
4152 return S_OK;
4155 default:
4156 FIXME("Unhandled feature %#x.\n", feature);
4157 return E_NOTIMPL;
4161 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4162 UINT *data_size, void *data)
4164 IDXGIDevice *dxgi_device;
4165 HRESULT hr;
4167 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4169 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4170 return hr;
4171 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4172 IDXGIDevice_Release(dxgi_device);
4174 return hr;
4177 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4178 UINT data_size, const void *data)
4180 IDXGIDevice *dxgi_device;
4181 HRESULT hr;
4183 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4185 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4186 return hr;
4187 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4188 IDXGIDevice_Release(dxgi_device);
4190 return hr;
4193 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4194 const IUnknown *data)
4196 IDXGIDevice *dxgi_device;
4197 HRESULT hr;
4199 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4201 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4202 return hr;
4203 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4204 IDXGIDevice_Release(dxgi_device);
4206 return hr;
4209 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4211 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4213 TRACE("iface %p.\n", iface);
4215 return device->state->feature_level;
4218 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4220 FIXME("iface %p stub!\n", iface);
4222 return 0;
4225 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4227 WARN("iface %p stub!\n", iface);
4229 return S_OK;
4232 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4233 ID3D11DeviceContext **immediate_context)
4235 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4237 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4239 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4240 ID3D11DeviceContext_AddRef(*immediate_context);
4243 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4245 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4247 return E_NOTIMPL;
4250 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4252 FIXME("iface %p stub!\n", iface);
4254 return 0;
4257 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4258 ID3D11DeviceContext1 **immediate_context)
4260 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4262 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4264 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4265 ID3D11DeviceContext1_AddRef(*immediate_context);
4268 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4269 ID3D11DeviceContext1 **context)
4271 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4272 struct d3d11_device_context *object;
4273 HRESULT hr;
4275 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4277 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4278 return hr;
4280 *context = &object->ID3D11DeviceContext1_iface;
4281 return S_OK;
4284 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4285 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4287 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4289 return E_NOTIMPL;
4292 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4293 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4295 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4296 struct d3d_rasterizer_state *object;
4297 HRESULT hr;
4299 TRACE("iface %p, desc %p, state %p.\n", iface, desc, state);
4301 if (!desc)
4302 return E_INVALIDARG;
4304 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
4305 return hr;
4307 *state = &object->ID3D11RasterizerState1_iface;
4309 return S_OK;
4312 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4313 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4314 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4316 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4317 struct d3d_device_context_state *state_impl;
4318 struct wined3d_state *wined3d_state;
4319 D3D_FEATURE_LEVEL feature_level;
4320 HRESULT hr = E_INVALIDARG;
4322 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4323 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4324 iface, flags, feature_levels, feature_level_count,
4325 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4327 if (flags)
4328 FIXME("Ignoring flags %#x.\n", flags);
4330 wined3d_mutex_lock();
4332 if (!feature_level_count)
4333 goto fail;
4335 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4336 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4337 goto fail;
4338 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4340 if (chosen_feature_level)
4341 *chosen_feature_level = feature_level;
4343 if (!state)
4345 wined3d_state_destroy(wined3d_state);
4346 wined3d_mutex_unlock();
4347 return S_FALSE;
4350 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4352 wined3d_state_destroy(wined3d_state);
4353 hr = E_OUTOFMEMORY;
4354 goto fail;
4357 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4358 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4360 wined3d_state_destroy(wined3d_state);
4361 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4362 hr = E_FAIL;
4363 goto fail;
4366 *state = &state_impl->ID3DDeviceContextState_iface;
4367 device->d3d11_only = FALSE;
4368 wined3d_mutex_unlock();
4370 return S_OK;
4372 fail:
4373 wined3d_mutex_unlock();
4374 if (chosen_feature_level)
4375 *chosen_feature_level = 0;
4376 if (state)
4377 *state = NULL;
4378 return hr;
4381 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4382 REFIID iid, void **resource)
4384 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4386 return E_NOTIMPL;
4389 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4390 DWORD access, REFIID iid, void **resource)
4392 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4393 debugstr_guid(iid), resource);
4395 return E_NOTIMPL;
4398 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4399 ID3D11DeviceContext2 **context)
4401 FIXME("iface %p, context %p stub!\n", iface, context);
4404 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4405 UINT flags, ID3D11DeviceContext2 **context)
4407 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4409 return E_NOTIMPL;
4412 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4413 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4414 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4415 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4417 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4418 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4419 iface, resource, tile_count, mip_desc, tile_shape,
4420 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4423 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4424 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4426 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4427 iface, format, sample_count, flags, quality_level_count);
4429 return E_NOTIMPL;
4432 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4434 /* IUnknown methods */
4435 d3d11_device_QueryInterface,
4436 d3d11_device_AddRef,
4437 d3d11_device_Release,
4438 /* ID3D11Device methods */
4439 d3d11_device_CreateBuffer,
4440 d3d11_device_CreateTexture1D,
4441 d3d11_device_CreateTexture2D,
4442 d3d11_device_CreateTexture3D,
4443 d3d11_device_CreateShaderResourceView,
4444 d3d11_device_CreateUnorderedAccessView,
4445 d3d11_device_CreateRenderTargetView,
4446 d3d11_device_CreateDepthStencilView,
4447 d3d11_device_CreateInputLayout,
4448 d3d11_device_CreateVertexShader,
4449 d3d11_device_CreateGeometryShader,
4450 d3d11_device_CreateGeometryShaderWithStreamOutput,
4451 d3d11_device_CreatePixelShader,
4452 d3d11_device_CreateHullShader,
4453 d3d11_device_CreateDomainShader,
4454 d3d11_device_CreateComputeShader,
4455 d3d11_device_CreateClassLinkage,
4456 d3d11_device_CreateBlendState,
4457 d3d11_device_CreateDepthStencilState,
4458 d3d11_device_CreateRasterizerState,
4459 d3d11_device_CreateSamplerState,
4460 d3d11_device_CreateQuery,
4461 d3d11_device_CreatePredicate,
4462 d3d11_device_CreateCounter,
4463 d3d11_device_CreateDeferredContext,
4464 d3d11_device_OpenSharedResource,
4465 d3d11_device_CheckFormatSupport,
4466 d3d11_device_CheckMultisampleQualityLevels,
4467 d3d11_device_CheckCounterInfo,
4468 d3d11_device_CheckCounter,
4469 d3d11_device_CheckFeatureSupport,
4470 d3d11_device_GetPrivateData,
4471 d3d11_device_SetPrivateData,
4472 d3d11_device_SetPrivateDataInterface,
4473 d3d11_device_GetFeatureLevel,
4474 d3d11_device_GetCreationFlags,
4475 d3d11_device_GetDeviceRemovedReason,
4476 d3d11_device_GetImmediateContext,
4477 d3d11_device_SetExceptionMode,
4478 d3d11_device_GetExceptionMode,
4479 /* ID3D11Device1 methods */
4480 d3d11_device_GetImmediateContext1,
4481 d3d11_device_CreateDeferredContext1,
4482 d3d11_device_CreateBlendState1,
4483 d3d11_device_CreateRasterizerState1,
4484 d3d11_device_CreateDeviceContextState,
4485 d3d11_device_OpenSharedResource1,
4486 d3d11_device_OpenSharedResourceByName,
4487 /* ID3D11Device2 methods */
4488 d3d11_device_GetImmediateContext2,
4489 d3d11_device_CreateDeferredContext2,
4490 d3d11_device_GetResourceTiling,
4491 d3d11_device_CheckMultisampleQualityLevels1,
4494 /* Inner IUnknown methods */
4496 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4498 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4501 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4503 struct d3d_device *device = impl_from_IUnknown(iface);
4505 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4507 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4508 || IsEqualGUID(riid, &IID_ID3D11Device1)
4509 || IsEqualGUID(riid, &IID_ID3D11Device)
4510 || IsEqualGUID(riid, &IID_IUnknown))
4512 *out = &device->ID3D11Device2_iface;
4514 else if (!device->d3d11_only
4515 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4516 || IsEqualGUID(riid, &IID_ID3D10Device)))
4518 *out = &device->ID3D10Device1_iface;
4520 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4522 *out = &device->ID3D10Multithread_iface;
4524 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4526 *out = &device->IWineDXGIDeviceParent_iface;
4528 else
4530 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4531 *out = NULL;
4532 return E_NOINTERFACE;
4535 IUnknown_AddRef((IUnknown *)*out);
4536 return S_OK;
4539 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4541 struct d3d_device *device = impl_from_IUnknown(iface);
4542 ULONG refcount = InterlockedIncrement(&device->refcount);
4544 TRACE("%p increasing refcount to %u.\n", device, refcount);
4546 return refcount;
4549 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4551 struct d3d_device *device = impl_from_IUnknown(iface);
4552 ULONG refcount = InterlockedDecrement(&device->refcount);
4553 unsigned int i;
4555 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4557 if (!refcount)
4559 if (device->state)
4560 d3d_device_context_state_private_release(device->state);
4561 for (i = 0; i < device->context_state_count; ++i)
4563 d3d_device_context_state_remove_entry(device->context_states[i], device);
4565 heap_free(device->context_states);
4566 d3d11_device_context_cleanup(&device->immediate_context);
4567 if (device->wined3d_device)
4569 wined3d_device_decref(device->wined3d_device);
4571 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4572 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4573 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4574 wine_rb_destroy(&device->blend_states, NULL, NULL);
4577 return refcount;
4580 /* IUnknown methods */
4582 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4583 void **out)
4585 struct d3d_device *device = impl_from_ID3D10Device(iface);
4586 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4589 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4591 struct d3d_device *device = impl_from_ID3D10Device(iface);
4592 return IUnknown_AddRef(device->outer_unk);
4595 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4597 struct d3d_device *device = impl_from_ID3D10Device(iface);
4598 return IUnknown_Release(device->outer_unk);
4601 /* ID3D10Device methods */
4603 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4604 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4606 struct d3d_device *device = impl_from_ID3D10Device(iface);
4607 unsigned int i;
4609 wined3d_mutex_lock();
4610 for (i = 0; i < buffer_count; ++i)
4612 struct wined3d_constant_buffer_state state;
4613 struct d3d_buffer *buffer_impl;
4615 wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4616 type, start_slot + i, &state);
4618 if (!state.buffer)
4620 buffers[i] = NULL;
4621 continue;
4624 buffer_impl = wined3d_buffer_get_parent(state.buffer);
4625 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4626 ID3D10Buffer_AddRef(buffers[i]);
4628 wined3d_mutex_unlock();
4631 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4632 unsigned int start_slot, unsigned int buffer_count, ID3D10Buffer *const *buffers)
4634 struct wined3d_constant_buffer_state wined3d_buffers[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4635 struct d3d_device *device = impl_from_ID3D10Device(iface);
4636 unsigned int i;
4638 if (buffer_count > ARRAY_SIZE(wined3d_buffers))
4640 WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
4641 return;
4644 for (i = 0; i < buffer_count; ++i)
4646 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4648 wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4649 wined3d_buffers[i].offset = 0;
4650 wined3d_buffers[i].size = WINED3D_MAX_CONSTANT_BUFFER_SIZE * sizeof(struct wined3d_vec4);
4653 wined3d_device_context_set_constant_buffers(device->immediate_context.wined3d_context,
4654 type, start_slot, buffer_count, wined3d_buffers);
4657 static void d3d10_device_set_shader_resource_views(ID3D10Device1 *iface, enum wined3d_shader_type type,
4658 unsigned int start_slot, unsigned int count, ID3D10ShaderResourceView *const *views)
4660 struct wined3d_shader_resource_view *wined3d_views[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4661 struct d3d_device *device = impl_from_ID3D10Device(iface);
4662 unsigned int i;
4664 if (count > ARRAY_SIZE(wined3d_views))
4666 WARN("View count %u exceeds limit; ignoring call.\n", count);
4667 return;
4670 for (i = 0; i < count; ++i)
4672 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4674 wined3d_views[i] = view ? view->wined3d_view : NULL;
4677 wined3d_device_context_set_shader_resource_views(device->immediate_context.wined3d_context,
4678 type, start_slot, count, wined3d_views);
4681 static void d3d10_device_set_samplers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4682 unsigned int start_slot, unsigned int count, ID3D10SamplerState *const *samplers)
4684 struct wined3d_sampler *wined3d_samplers[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4685 struct d3d_device *device = impl_from_ID3D10Device(iface);
4686 unsigned int i;
4688 if (count > ARRAY_SIZE(wined3d_samplers))
4690 WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
4691 return;
4694 for (i = 0; i < count; ++i)
4696 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4698 wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
4701 wined3d_device_context_set_samplers(device->immediate_context.wined3d_context,
4702 type, start_slot, count, wined3d_samplers);
4705 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4706 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4708 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4709 iface, start_slot, buffer_count, buffers);
4711 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4712 buffer_count, buffers);
4715 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4716 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4718 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4719 iface, start_slot, view_count, views);
4721 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
4724 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4725 ID3D10PixelShader *shader)
4727 struct d3d_device *device = impl_from_ID3D10Device(iface);
4728 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4730 TRACE("iface %p, shader %p\n", iface, shader);
4732 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4733 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4736 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4737 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4739 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4740 iface, start_slot, sampler_count, samplers);
4742 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
4745 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4746 ID3D10VertexShader *shader)
4748 struct d3d_device *device = impl_from_ID3D10Device(iface);
4749 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4751 TRACE("iface %p, shader %p\n", iface, shader);
4753 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4754 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4757 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4758 UINT start_index_location, INT base_vertex_location)
4760 struct d3d_device *device = impl_from_ID3D10Device(iface);
4762 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4763 iface, index_count, start_index_location, base_vertex_location);
4765 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4766 base_vertex_location, start_index_location, index_count, 0, 0);
4769 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4770 UINT start_vertex_location)
4772 struct d3d_device *device = impl_from_ID3D10Device(iface);
4774 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4775 iface, vertex_count, start_vertex_location);
4777 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4780 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4781 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4783 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4784 iface, start_slot, buffer_count, buffers);
4786 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4787 buffer_count, buffers);
4790 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4791 ID3D10InputLayout *input_layout)
4793 struct d3d_device *device = impl_from_ID3D10Device(iface);
4794 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4796 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4798 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4799 layout ? layout->wined3d_decl : NULL);
4802 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4803 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4805 struct wined3d_stream_state streams[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4806 struct d3d_device *device = impl_from_ID3D10Device(iface);
4807 unsigned int i;
4809 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4810 iface, start_slot, buffer_count, buffers, strides, offsets);
4812 if (buffer_count > ARRAY_SIZE(streams))
4814 WARN("Buffer count %u exceeds limit.\n", buffer_count);
4815 buffer_count = ARRAY_SIZE(streams);
4818 for (i = 0; i < buffer_count; ++i)
4820 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4822 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4823 streams[i].offset = offsets[i];
4824 streams[i].stride = strides[i];
4825 streams[i].frequency = 1;
4826 streams[i].flags = 0;
4829 wined3d_device_context_set_stream_sources(device->immediate_context.wined3d_context,
4830 start_slot, buffer_count, streams);
4833 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4834 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4836 struct d3d_device *device = impl_from_ID3D10Device(iface);
4837 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4839 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4840 iface, buffer, debug_dxgi_format(format), offset);
4842 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4843 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4844 wined3dformat_from_dxgi_format(format), offset);
4847 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4848 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4849 INT base_vertex_location, UINT start_instance_location)
4851 struct d3d_device *device = impl_from_ID3D10Device(iface);
4853 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4854 "base_vertex_location %d, start_instance_location %u.\n",
4855 iface, instance_index_count, instance_count, start_index_location,
4856 base_vertex_location, start_instance_location);
4858 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4859 start_index_location, instance_index_count, start_instance_location, instance_count);
4862 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4863 UINT instance_vertex_count, UINT instance_count,
4864 UINT start_vertex_location, UINT start_instance_location)
4866 struct d3d_device *device = impl_from_ID3D10Device(iface);
4868 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4869 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4870 start_vertex_location, start_instance_location);
4872 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4873 instance_vertex_count, start_instance_location, instance_count);
4876 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4877 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4879 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4880 iface, start_slot, buffer_count, buffers);
4882 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4883 buffer_count, buffers);
4886 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4888 struct d3d_device *device = impl_from_ID3D10Device(iface);
4889 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4891 TRACE("iface %p, shader %p.\n", iface, shader);
4893 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4894 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4897 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4898 D3D10_PRIMITIVE_TOPOLOGY topology)
4900 struct d3d_device *device = impl_from_ID3D10Device(iface);
4902 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4904 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4905 (enum wined3d_primitive_type)topology, 0);
4908 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4909 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4911 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4912 iface, start_slot, view_count, views);
4914 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
4917 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4918 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4920 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4921 iface, start_slot, sampler_count, samplers);
4923 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
4926 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4928 struct d3d_device *device = impl_from_ID3D10Device(iface);
4929 struct d3d_query *query;
4931 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4933 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4934 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4935 query ? query->wined3d_query : NULL, value);
4938 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4939 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4941 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4942 iface, start_slot, view_count, views);
4944 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
4947 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4948 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4950 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4951 iface, start_slot, sampler_count, samplers);
4953 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
4956 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4957 UINT rtv_count, ID3D10RenderTargetView *const *rtvs, ID3D10DepthStencilView *depth_stencil_view)
4959 struct wined3d_rendertarget_view *wined3d_rtvs[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
4960 struct d3d_device *device = impl_from_ID3D10Device(iface);
4961 struct d3d_depthstencil_view *dsv;
4962 unsigned int i;
4964 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
4966 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
4968 WARN("View count %u exceeds limit.\n", rtv_count);
4969 rtv_count = ARRAY_SIZE(wined3d_rtvs);
4972 for (i = 0; i < rtv_count; ++i)
4974 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(rtvs[i]);
4976 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
4979 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4981 wined3d_device_context_set_render_targets_and_unordered_access_views(device->immediate_context.wined3d_context,
4982 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ~0u, NULL, NULL);
4985 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4986 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4988 struct d3d_device *device = impl_from_ID3D10Device(iface);
4989 struct d3d_blend_state *blend_state_object;
4991 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4992 iface, blend_state, debug_float4(blend_factor), sample_mask);
4994 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4995 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4996 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4999 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
5000 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
5002 struct d3d_device *device = impl_from_ID3D10Device(iface);
5003 struct d3d_depthstencil_state *ds_state_object;
5005 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
5006 iface, depth_stencil_state, stencil_ref);
5008 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
5009 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5010 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
5013 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
5014 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
5016 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
5017 struct d3d_device *device = impl_from_ID3D10Device(iface);
5018 unsigned int count, i;
5020 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
5022 count = min(target_count, ARRAY_SIZE(outputs));
5023 for (i = 0; i < count; ++i)
5025 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
5027 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
5028 outputs[i].offset = offsets ? offsets[i] : 0;
5031 wined3d_device_context_set_stream_outputs(device->immediate_context.wined3d_context, outputs);
5034 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
5036 FIXME("iface %p stub!\n", iface);
5039 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
5041 struct d3d_device *device = impl_from_ID3D10Device(iface);
5042 struct d3d_rasterizer_state *rasterizer_state_object;
5044 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5046 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5047 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5048 rasterizer_state_object ? (ID3D11RasterizerState *)&rasterizer_state_object->ID3D11RasterizerState1_iface : NULL);
5051 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
5052 UINT viewport_count, const D3D10_VIEWPORT *viewports)
5054 struct d3d_device *device = impl_from_ID3D10Device(iface);
5055 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5056 unsigned int i;
5058 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5060 if (viewport_count > ARRAY_SIZE(wined3d_vp))
5061 return;
5063 for (i = 0; i < viewport_count; ++i)
5065 wined3d_vp[i].x = viewports[i].TopLeftX;
5066 wined3d_vp[i].y = viewports[i].TopLeftY;
5067 wined3d_vp[i].width = viewports[i].Width;
5068 wined3d_vp[i].height = viewports[i].Height;
5069 wined3d_vp[i].min_z = viewports[i].MinDepth;
5070 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5073 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
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_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5089 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5090 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5091 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5093 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5094 struct d3d_device *device = impl_from_ID3D10Device(iface);
5095 struct wined3d_box wined3d_src_box;
5097 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5098 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5099 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5100 src_resource, src_subresource_idx, src_box);
5102 if (!dst_resource || !src_resource)
5103 return;
5105 if (src_box)
5106 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5107 src_box->right, src_box->bottom, src_box->front, src_box->back);
5109 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5110 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5111 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5112 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5113 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5116 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5117 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5119 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5120 struct d3d_device *device = impl_from_ID3D10Device(iface);
5122 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5124 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5125 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5126 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5127 wined3d_dst_resource, wined3d_src_resource);
5130 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5131 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5132 const void *data, UINT row_pitch, UINT depth_pitch)
5134 struct d3d_device *device = impl_from_ID3D10Device(iface);
5135 ID3D11Resource *d3d11_resource;
5137 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5138 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5140 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5141 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5142 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5143 ID3D11Resource_Release(d3d11_resource);
5146 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5147 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5149 struct d3d_device *device = impl_from_ID3D10Device(iface);
5150 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5151 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5152 HRESULT hr;
5154 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5155 iface, render_target_view, debug_float4(color_rgba));
5157 if (!view)
5158 return;
5160 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5161 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5162 ERR("Failed to clear view, hr %#x.\n", hr);
5165 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5166 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5168 struct d3d_device *device = impl_from_ID3D10Device(iface);
5169 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5170 DWORD wined3d_flags;
5171 HRESULT hr;
5173 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5174 iface, depth_stencil_view, flags, depth, stencil);
5176 if (!view)
5177 return;
5179 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5181 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5182 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5183 ERR("Failed to clear view, hr %#x.\n", hr);
5186 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5187 ID3D10ShaderResourceView *view)
5189 struct d3d_device *device = impl_from_ID3D10Device(iface);
5190 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5192 TRACE("iface %p, view %p.\n", iface, view);
5194 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5197 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5198 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5199 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5201 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5202 struct d3d_device *device = impl_from_ID3D10Device(iface);
5203 enum wined3d_format_id wined3d_format;
5205 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5206 "src_resource %p, src_subresource_idx %u, format %s.\n",
5207 iface, dst_resource, dst_subresource_idx,
5208 src_resource, src_subresource_idx, debug_dxgi_format(format));
5210 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5211 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5212 wined3d_format = wined3dformat_from_dxgi_format(format);
5213 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5214 wined3d_dst_resource, dst_subresource_idx,
5215 wined3d_src_resource, src_subresource_idx, wined3d_format);
5218 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5219 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5221 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5222 iface, start_slot, buffer_count, buffers);
5224 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5225 buffers);
5228 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5229 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5231 struct d3d_device *device = impl_from_ID3D10Device(iface);
5232 unsigned int i;
5234 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5235 iface, start_slot, view_count, views);
5237 wined3d_mutex_lock();
5238 for (i = 0; i < view_count; ++i)
5240 struct wined3d_shader_resource_view *wined3d_view;
5241 struct d3d_shader_resource_view *view_impl;
5243 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5244 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5246 views[i] = NULL;
5247 continue;
5250 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5251 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5252 ID3D10ShaderResourceView_AddRef(views[i]);
5254 wined3d_mutex_unlock();
5257 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5259 struct d3d_device *device = impl_from_ID3D10Device(iface);
5260 struct d3d_pixel_shader *shader_impl;
5261 struct wined3d_shader *wined3d_shader;
5263 TRACE("iface %p, shader %p.\n", iface, shader);
5265 wined3d_mutex_lock();
5266 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5267 WINED3D_SHADER_TYPE_PIXEL)))
5269 wined3d_mutex_unlock();
5270 *shader = NULL;
5271 return;
5274 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5275 wined3d_mutex_unlock();
5276 *shader = &shader_impl->ID3D10PixelShader_iface;
5277 ID3D10PixelShader_AddRef(*shader);
5280 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5281 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5283 struct d3d_device *device = impl_from_ID3D10Device(iface);
5284 unsigned int i;
5286 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5287 iface, start_slot, sampler_count, samplers);
5289 wined3d_mutex_lock();
5290 for (i = 0; i < sampler_count; ++i)
5292 struct d3d_sampler_state *sampler_impl;
5293 struct wined3d_sampler *wined3d_sampler;
5295 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5296 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5298 samplers[i] = NULL;
5299 continue;
5302 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5303 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5304 ID3D10SamplerState_AddRef(samplers[i]);
5306 wined3d_mutex_unlock();
5309 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5311 struct d3d_device *device = impl_from_ID3D10Device(iface);
5312 struct d3d_vertex_shader *shader_impl;
5313 struct wined3d_shader *wined3d_shader;
5315 TRACE("iface %p, shader %p.\n", iface, shader);
5317 wined3d_mutex_lock();
5318 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5319 WINED3D_SHADER_TYPE_VERTEX)))
5321 wined3d_mutex_unlock();
5322 *shader = NULL;
5323 return;
5326 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5327 wined3d_mutex_unlock();
5328 *shader = &shader_impl->ID3D10VertexShader_iface;
5329 ID3D10VertexShader_AddRef(*shader);
5332 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5333 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5335 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5336 iface, start_slot, buffer_count, buffers);
5338 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5339 buffers);
5342 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5344 struct d3d_device *device = impl_from_ID3D10Device(iface);
5345 struct wined3d_vertex_declaration *wined3d_declaration;
5346 struct d3d_input_layout *input_layout_impl;
5348 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5350 wined3d_mutex_lock();
5351 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5352 device->immediate_context.wined3d_context)))
5354 wined3d_mutex_unlock();
5355 *input_layout = NULL;
5356 return;
5359 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5360 wined3d_mutex_unlock();
5361 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5362 ID3D10InputLayout_AddRef(*input_layout);
5365 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5366 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5368 struct d3d_device *device = impl_from_ID3D10Device(iface);
5369 unsigned int i;
5371 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5372 iface, start_slot, buffer_count, buffers, strides, offsets);
5374 wined3d_mutex_lock();
5375 for (i = 0; i < buffer_count; ++i)
5377 struct wined3d_buffer *wined3d_buffer = NULL;
5378 struct d3d_buffer *buffer_impl;
5380 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5381 &wined3d_buffer, &offsets[i], &strides[i])))
5382 ERR("Failed to get vertex buffer.\n");
5384 if (!wined3d_buffer)
5386 buffers[i] = NULL;
5387 continue;
5390 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5391 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5392 ID3D10Buffer_AddRef(buffers[i]);
5394 wined3d_mutex_unlock();
5397 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5398 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5400 struct d3d_device *device = impl_from_ID3D10Device(iface);
5401 enum wined3d_format_id wined3d_format;
5402 struct wined3d_buffer *wined3d_buffer;
5403 struct d3d_buffer *buffer_impl;
5405 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5407 wined3d_mutex_lock();
5408 wined3d_buffer = wined3d_device_context_get_index_buffer(
5409 device->immediate_context.wined3d_context, &wined3d_format, offset);
5410 *format = dxgi_format_from_wined3dformat(wined3d_format);
5411 if (!wined3d_buffer)
5413 wined3d_mutex_unlock();
5414 *buffer = NULL;
5415 return;
5418 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5419 wined3d_mutex_unlock();
5420 *buffer = &buffer_impl->ID3D10Buffer_iface;
5421 ID3D10Buffer_AddRef(*buffer);
5424 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5425 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5427 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5428 iface, start_slot, buffer_count, buffers);
5430 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5431 buffers);
5434 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5436 struct d3d_device *device = impl_from_ID3D10Device(iface);
5437 struct d3d_geometry_shader *shader_impl;
5438 struct wined3d_shader *wined3d_shader;
5440 TRACE("iface %p, shader %p.\n", iface, shader);
5442 wined3d_mutex_lock();
5443 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5444 WINED3D_SHADER_TYPE_GEOMETRY)))
5446 wined3d_mutex_unlock();
5447 *shader = NULL;
5448 return;
5451 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5452 wined3d_mutex_unlock();
5453 *shader = &shader_impl->ID3D10GeometryShader_iface;
5454 ID3D10GeometryShader_AddRef(*shader);
5457 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5458 D3D10_PRIMITIVE_TOPOLOGY *topology)
5460 struct d3d_device *device = impl_from_ID3D10Device(iface);
5462 TRACE("iface %p, topology %p.\n", iface, topology);
5464 wined3d_mutex_lock();
5465 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5466 (enum wined3d_primitive_type *)topology, NULL);
5467 wined3d_mutex_unlock();
5470 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5471 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5473 struct d3d_device *device = impl_from_ID3D10Device(iface);
5474 unsigned int i;
5476 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5477 iface, start_slot, view_count, views);
5479 wined3d_mutex_lock();
5480 for (i = 0; i < view_count; ++i)
5482 struct wined3d_shader_resource_view *wined3d_view;
5483 struct d3d_shader_resource_view *view_impl;
5485 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5486 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5488 views[i] = NULL;
5489 continue;
5492 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5493 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5494 ID3D10ShaderResourceView_AddRef(views[i]);
5496 wined3d_mutex_unlock();
5499 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5500 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5502 struct d3d_device *device = impl_from_ID3D10Device(iface);
5503 unsigned int i;
5505 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5506 iface, start_slot, sampler_count, samplers);
5508 wined3d_mutex_lock();
5509 for (i = 0; i < sampler_count; ++i)
5511 struct d3d_sampler_state *sampler_impl;
5512 struct wined3d_sampler *wined3d_sampler;
5514 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5515 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5517 samplers[i] = NULL;
5518 continue;
5521 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5522 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5523 ID3D10SamplerState_AddRef(samplers[i]);
5525 wined3d_mutex_unlock();
5528 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5529 ID3D10Predicate **predicate, BOOL *value)
5531 struct d3d_device *device = impl_from_ID3D10Device(iface);
5532 struct wined3d_query *wined3d_predicate;
5533 struct d3d_query *predicate_impl;
5535 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5537 wined3d_mutex_lock();
5538 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5540 wined3d_mutex_unlock();
5541 *predicate = NULL;
5542 return;
5545 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5546 wined3d_mutex_unlock();
5547 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5548 ID3D10Predicate_AddRef(*predicate);
5551 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5552 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5554 struct d3d_device *device = impl_from_ID3D10Device(iface);
5555 unsigned int i;
5557 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5558 iface, start_slot, view_count, views);
5560 wined3d_mutex_lock();
5561 for (i = 0; i < view_count; ++i)
5563 struct wined3d_shader_resource_view *wined3d_view;
5564 struct d3d_shader_resource_view *view_impl;
5566 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5567 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5569 views[i] = NULL;
5570 continue;
5573 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5574 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5575 ID3D10ShaderResourceView_AddRef(views[i]);
5577 wined3d_mutex_unlock();
5580 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5581 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5583 struct d3d_device *device = impl_from_ID3D10Device(iface);
5584 unsigned int i;
5586 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5587 iface, start_slot, sampler_count, samplers);
5589 wined3d_mutex_lock();
5590 for (i = 0; i < sampler_count; ++i)
5592 struct d3d_sampler_state *sampler_impl;
5593 struct wined3d_sampler *wined3d_sampler;
5595 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5596 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5598 samplers[i] = NULL;
5599 continue;
5602 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5603 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5604 ID3D10SamplerState_AddRef(samplers[i]);
5606 wined3d_mutex_unlock();
5609 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5610 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5612 struct d3d_device *device = impl_from_ID3D10Device(iface);
5613 struct wined3d_rendertarget_view *wined3d_view;
5615 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5616 iface, view_count, render_target_views, depth_stencil_view);
5618 wined3d_mutex_lock();
5619 if (render_target_views)
5621 struct d3d_rendertarget_view *view_impl;
5622 unsigned int i;
5624 for (i = 0; i < view_count; ++i)
5626 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5627 device->immediate_context.wined3d_context, i))
5628 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5630 render_target_views[i] = NULL;
5631 continue;
5634 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5635 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5639 if (depth_stencil_view)
5641 struct d3d_depthstencil_view *view_impl;
5643 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5644 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5646 *depth_stencil_view = NULL;
5648 else
5650 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5651 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5654 wined3d_mutex_unlock();
5657 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5658 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5660 struct d3d_device *device = impl_from_ID3D10Device(iface);
5661 ID3D11BlendState *d3d11_blend_state;
5663 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5664 iface, blend_state, blend_factor, sample_mask);
5666 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5667 &d3d11_blend_state, blend_factor, sample_mask);
5669 if (blend_state)
5671 if (d3d11_blend_state)
5673 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5674 ID3D10BlendState_AddRef(*blend_state);
5676 else
5677 *blend_state = NULL;
5680 if (d3d11_blend_state)
5681 ID3D11BlendState_Release(d3d11_blend_state);
5684 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5685 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5687 struct d3d_device *device = impl_from_ID3D10Device(iface);
5688 ID3D11DepthStencilState *d3d11_iface = NULL;
5690 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5691 iface, depth_stencil_state, stencil_ref);
5693 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5694 &d3d11_iface, stencil_ref);
5696 if (depth_stencil_state)
5698 if (d3d11_iface)
5700 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5701 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
5703 else
5704 *depth_stencil_state = NULL;
5707 if (d3d11_iface)
5708 ID3D11DepthStencilState_Release(d3d11_iface);
5711 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5712 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5714 struct d3d_device *device = impl_from_ID3D10Device(iface);
5715 unsigned int i;
5717 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5718 iface, buffer_count, buffers, offsets);
5720 wined3d_mutex_lock();
5721 for (i = 0; i < buffer_count; ++i)
5723 struct wined3d_buffer *wined3d_buffer;
5724 struct d3d_buffer *buffer_impl;
5726 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5727 device->immediate_context.wined3d_context, i, &offsets[i])))
5729 buffers[i] = NULL;
5730 continue;
5733 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5734 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5735 ID3D10Buffer_AddRef(buffers[i]);
5737 wined3d_mutex_unlock();
5740 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5742 struct d3d_device *device = impl_from_ID3D10Device(iface);
5743 struct d3d_rasterizer_state *rasterizer_state_impl;
5744 struct wined3d_rasterizer_state *wined3d_state;
5746 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5748 wined3d_mutex_lock();
5749 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5751 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5752 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5754 else
5756 *rasterizer_state = NULL;
5758 wined3d_mutex_unlock();
5761 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5762 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5764 struct d3d_device *device = impl_from_ID3D10Device(iface);
5765 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5766 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5768 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5770 if (!viewport_count)
5771 return;
5773 wined3d_mutex_lock();
5774 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5775 &actual_count, viewports ? wined3d_vp : NULL);
5776 wined3d_mutex_unlock();
5778 if (!viewports)
5780 *viewport_count = actual_count;
5781 return;
5784 if (*viewport_count > actual_count)
5785 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5787 *viewport_count = min(actual_count, *viewport_count);
5788 for (i = 0; i < *viewport_count; ++i)
5790 viewports[i].TopLeftX = wined3d_vp[i].x;
5791 viewports[i].TopLeftY = wined3d_vp[i].y;
5792 viewports[i].Width = wined3d_vp[i].width;
5793 viewports[i].Height = wined3d_vp[i].height;
5794 viewports[i].MinDepth = wined3d_vp[i].min_z;
5795 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5799 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5801 struct d3d_device *device = impl_from_ID3D10Device(iface);
5802 unsigned int actual_count;
5804 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5806 if (!rect_count)
5807 return;
5809 actual_count = *rect_count;
5811 wined3d_mutex_lock();
5812 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5813 wined3d_mutex_unlock();
5815 if (!rects)
5817 *rect_count = actual_count;
5818 return;
5821 if (*rect_count > actual_count)
5822 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5825 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5827 TRACE("iface %p.\n", iface);
5829 /* In the current implementation the device is never removed, so we can
5830 * just return S_OK here. */
5832 return S_OK;
5835 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5837 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5839 return E_NOTIMPL;
5842 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5844 FIXME("iface %p stub!\n", iface);
5846 return 0;
5849 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5850 REFGUID guid, UINT *data_size, void *data)
5852 struct d3d_device *device = impl_from_ID3D10Device(iface);
5854 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5856 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5859 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5860 REFGUID guid, UINT data_size, const void *data)
5862 struct d3d_device *device = impl_from_ID3D10Device(iface);
5864 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5866 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5869 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5870 REFGUID guid, const IUnknown *data)
5872 struct d3d_device *device = impl_from_ID3D10Device(iface);
5874 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5876 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5879 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5881 struct d3d_device *device = impl_from_ID3D10Device(iface);
5883 TRACE("iface %p.\n", iface);
5885 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5888 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5890 struct d3d_device *device = impl_from_ID3D10Device(iface);
5892 TRACE("iface %p.\n", iface);
5894 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5897 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5898 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5900 struct d3d_device *device = impl_from_ID3D10Device(iface);
5901 D3D11_BUFFER_DESC d3d11_desc;
5902 struct d3d_buffer *object;
5903 HRESULT hr;
5905 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5907 d3d11_desc.ByteWidth = desc->ByteWidth;
5908 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5909 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5910 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5911 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5912 d3d11_desc.StructureByteStride = 0;
5914 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5915 return hr;
5917 *buffer = &object->ID3D10Buffer_iface;
5919 return S_OK;
5922 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5923 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5925 struct d3d_device *device = impl_from_ID3D10Device(iface);
5926 D3D11_TEXTURE1D_DESC d3d11_desc;
5927 struct d3d_texture1d *object;
5928 HRESULT hr;
5930 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5932 d3d11_desc.Width = desc->Width;
5933 d3d11_desc.MipLevels = desc->MipLevels;
5934 d3d11_desc.ArraySize = desc->ArraySize;
5935 d3d11_desc.Format = desc->Format;
5936 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5937 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5938 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5939 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5941 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5942 return hr;
5944 *texture = &object->ID3D10Texture1D_iface;
5946 return S_OK;
5949 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5950 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5951 ID3D10Texture2D **texture)
5953 struct d3d_device *device = impl_from_ID3D10Device(iface);
5954 D3D11_TEXTURE2D_DESC d3d11_desc;
5955 struct d3d_texture2d *object;
5956 HRESULT hr;
5958 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5960 d3d11_desc.Width = desc->Width;
5961 d3d11_desc.Height = desc->Height;
5962 d3d11_desc.MipLevels = desc->MipLevels;
5963 d3d11_desc.ArraySize = desc->ArraySize;
5964 d3d11_desc.Format = desc->Format;
5965 d3d11_desc.SampleDesc = desc->SampleDesc;
5966 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5967 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5968 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5969 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5971 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5972 return hr;
5974 *texture = &object->ID3D10Texture2D_iface;
5976 return S_OK;
5979 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5980 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5981 ID3D10Texture3D **texture)
5983 struct d3d_device *device = impl_from_ID3D10Device(iface);
5984 D3D11_TEXTURE3D_DESC d3d11_desc;
5985 struct d3d_texture3d *object;
5986 HRESULT hr;
5988 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5990 d3d11_desc.Width = desc->Width;
5991 d3d11_desc.Height = desc->Height;
5992 d3d11_desc.Depth = desc->Depth;
5993 d3d11_desc.MipLevels = desc->MipLevels;
5994 d3d11_desc.Format = desc->Format;
5995 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5996 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5997 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5998 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
6000 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
6001 return hr;
6003 *texture = &object->ID3D10Texture3D_iface;
6005 return S_OK;
6008 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
6009 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
6011 struct d3d_device *device = impl_from_ID3D10Device(iface);
6012 struct d3d_shader_resource_view *object;
6013 ID3D11Resource *d3d11_resource;
6014 HRESULT hr;
6016 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6018 *view = NULL;
6020 if (!resource)
6021 return E_INVALIDARG;
6023 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6025 ERR("Resource does not implement ID3D11Resource.\n");
6026 return E_FAIL;
6029 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
6030 &object);
6031 ID3D11Resource_Release(d3d11_resource);
6032 if (FAILED(hr))
6033 return hr;
6035 *view = &object->ID3D10ShaderResourceView1_iface;
6037 return S_OK;
6040 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
6041 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
6043 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6045 return d3d10_device_CreateShaderResourceView1(iface, resource,
6046 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
6049 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
6050 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6052 struct d3d_device *device = impl_from_ID3D10Device(iface);
6053 struct d3d_rendertarget_view *object;
6054 ID3D11Resource *d3d11_resource;
6055 HRESULT hr;
6057 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6059 *view = NULL;
6061 if (!resource)
6062 return E_INVALIDARG;
6064 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6066 ERR("Resource does not implement ID3D11Resource.\n");
6067 return E_FAIL;
6070 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6071 ID3D11Resource_Release(d3d11_resource);
6072 if (FAILED(hr))
6073 return hr;
6075 *view = &object->ID3D10RenderTargetView_iface;
6077 return S_OK;
6080 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6082 return (D3D11_DSV_DIMENSION)dim;
6085 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6086 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6088 struct d3d_device *device = impl_from_ID3D10Device(iface);
6089 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6090 struct d3d_depthstencil_view *object;
6091 ID3D11Resource *d3d11_resource;
6092 HRESULT hr;
6094 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6096 *view = NULL;
6098 if (desc)
6100 d3d11_desc.Format = desc->Format;
6101 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6102 d3d11_desc.Flags = 0;
6103 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6106 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6108 ERR("Resource does not implement ID3D11Resource.\n");
6109 return E_FAIL;
6112 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6113 ID3D11Resource_Release(d3d11_resource);
6114 if (FAILED(hr))
6115 return hr;
6117 *view = &object->ID3D10DepthStencilView_iface;
6119 return S_OK;
6122 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6123 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6124 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6125 ID3D10InputLayout **input_layout)
6127 struct d3d_device *device = impl_from_ID3D10Device(iface);
6128 struct d3d_input_layout *object;
6129 HRESULT hr;
6131 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6132 "shader_byte_code_length %lu, input_layout %p\n",
6133 iface, element_descs, element_count, shader_byte_code,
6134 shader_byte_code_length, input_layout);
6136 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6137 shader_byte_code, shader_byte_code_length, &object)))
6138 return hr;
6140 *input_layout = &object->ID3D10InputLayout_iface;
6142 return S_OK;
6145 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6146 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6148 struct d3d_device *device = impl_from_ID3D10Device(iface);
6149 struct d3d_vertex_shader *object;
6150 HRESULT hr;
6152 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6153 iface, byte_code, byte_code_length, shader);
6155 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6156 return hr;
6158 *shader = &object->ID3D10VertexShader_iface;
6160 return S_OK;
6163 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6164 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6166 struct d3d_device *device = impl_from_ID3D10Device(iface);
6167 struct d3d_geometry_shader *object;
6168 HRESULT hr;
6170 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6171 iface, byte_code, byte_code_length, shader);
6173 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6174 NULL, 0, NULL, 0, 0, &object)))
6175 return hr;
6177 *shader = &object->ID3D10GeometryShader_iface;
6179 return S_OK;
6182 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6183 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6184 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6186 struct d3d_device *device = impl_from_ID3D10Device(iface);
6187 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6188 struct d3d_geometry_shader *object;
6189 unsigned int i, stride_count = 1;
6190 HRESULT hr;
6192 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
6193 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6194 iface, byte_code, byte_code_length, output_stream_decls,
6195 output_stream_decl_count, output_stream_stride, shader);
6197 if (!output_stream_decl_count && output_stream_stride)
6199 WARN("Stride must be 0 when declaration entry count is 0.\n");
6200 *shader = NULL;
6201 return E_INVALIDARG;
6204 if (output_stream_decl_count
6205 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
6207 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6208 *shader = NULL;
6209 return E_OUTOFMEMORY;
6212 for (i = 0; i < output_stream_decl_count; ++i)
6214 so_entries[i].Stream = 0;
6215 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6216 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6217 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6218 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6219 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6221 if (output_stream_decls[i].OutputSlot)
6223 stride_count = 0;
6224 if (output_stream_stride)
6226 WARN("Stride must be 0 when multiple output slots are used.\n");
6227 heap_free(so_entries);
6228 *shader = NULL;
6229 return E_INVALIDARG;
6234 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6235 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6236 heap_free(so_entries);
6237 if (FAILED(hr))
6239 *shader = NULL;
6240 return hr;
6243 *shader = &object->ID3D10GeometryShader_iface;
6245 return hr;
6248 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6249 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6251 struct d3d_device *device = impl_from_ID3D10Device(iface);
6252 struct d3d_pixel_shader *object;
6253 HRESULT hr;
6255 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6256 iface, byte_code, byte_code_length, shader);
6258 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6259 return hr;
6261 *shader = &object->ID3D10PixelShader_iface;
6263 return S_OK;
6266 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6267 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6269 struct d3d_device *device = impl_from_ID3D10Device(iface);
6270 struct d3d_blend_state *object;
6271 HRESULT hr;
6273 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6275 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6276 return hr;
6278 *blend_state = &object->ID3D10BlendState1_iface;
6280 return S_OK;
6283 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6284 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6286 D3D10_BLEND_DESC1 d3d10_1_desc;
6287 unsigned int i;
6289 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6291 if (!desc)
6292 return E_INVALIDARG;
6294 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6295 d3d10_1_desc.IndependentBlendEnable = FALSE;
6296 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6298 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6299 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6300 d3d10_1_desc.IndependentBlendEnable = TRUE;
6303 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6305 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6306 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6307 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6308 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6309 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6310 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6311 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6312 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6315 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6318 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6319 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6321 struct d3d_device *device = impl_from_ID3D10Device(iface);
6322 struct d3d_depthstencil_state *object;
6323 HRESULT hr;
6325 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6327 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6328 return hr;
6330 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6332 return S_OK;
6335 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6336 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6338 struct d3d_device *device = impl_from_ID3D10Device(iface);
6339 struct d3d_rasterizer_state *object;
6340 D3D11_RASTERIZER_DESC1 desc1;
6341 HRESULT hr;
6343 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6345 if (!desc)
6346 return E_INVALIDARG;
6348 memcpy(&desc1, desc, sizeof(*desc));
6349 desc1.ForcedSampleCount = 0;
6351 if (FAILED(hr = d3d_rasterizer_state_create(device, &desc1, &object)))
6352 return hr;
6354 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6356 return S_OK;
6359 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6360 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6362 struct d3d_device *device = impl_from_ID3D10Device(iface);
6363 struct d3d_sampler_state *object;
6364 HRESULT hr;
6366 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6368 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6369 return hr;
6371 *sampler_state = &object->ID3D10SamplerState_iface;
6373 return S_OK;
6376 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6377 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6379 struct d3d_device *device = impl_from_ID3D10Device(iface);
6380 struct d3d_query *object;
6381 HRESULT hr;
6383 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6385 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6386 return hr;
6388 if (query)
6390 *query = &object->ID3D10Query_iface;
6391 return S_OK;
6394 ID3D10Query_Release(&object->ID3D10Query_iface);
6395 return S_FALSE;
6398 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6399 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6401 struct d3d_device *device = impl_from_ID3D10Device(iface);
6402 struct d3d_query *object;
6403 HRESULT hr;
6405 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6407 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6408 return hr;
6410 if (predicate)
6412 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6413 return S_OK;
6416 ID3D10Query_Release(&object->ID3D10Query_iface);
6417 return S_FALSE;
6420 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6421 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6423 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6425 return E_NOTIMPL;
6428 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6429 DXGI_FORMAT format, UINT *format_support)
6431 struct d3d_device *device = impl_from_ID3D10Device(iface);
6433 TRACE("iface %p, format %s, format_support %p.\n",
6434 iface, debug_dxgi_format(format), format_support);
6436 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6439 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6440 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6442 struct d3d_device *device = impl_from_ID3D10Device(iface);
6444 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6445 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6447 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6448 sample_count, quality_level_count);
6451 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6453 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6456 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6457 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6458 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6460 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6461 "units %p, units_length %p, description %p, description_length %p stub!\n",
6462 iface, desc, type, active_counters, name, name_length,
6463 units, units_length, description, description_length);
6465 return E_NOTIMPL;
6468 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6470 FIXME("iface %p stub!\n", iface);
6472 return 0;
6475 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6476 HANDLE resource_handle, REFIID guid, void **resource)
6478 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6479 iface, resource_handle, debugstr_guid(guid), resource);
6481 return E_NOTIMPL;
6484 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6486 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6489 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6491 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6494 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6496 return (D3D10_FEATURE_LEVEL1)level;
6499 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6501 struct d3d_device *device = impl_from_ID3D10Device(iface);
6503 TRACE("iface %p.\n", iface);
6505 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6508 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6510 /* IUnknown methods */
6511 d3d10_device_QueryInterface,
6512 d3d10_device_AddRef,
6513 d3d10_device_Release,
6514 /* ID3D10Device methods */
6515 d3d10_device_VSSetConstantBuffers,
6516 d3d10_device_PSSetShaderResources,
6517 d3d10_device_PSSetShader,
6518 d3d10_device_PSSetSamplers,
6519 d3d10_device_VSSetShader,
6520 d3d10_device_DrawIndexed,
6521 d3d10_device_Draw,
6522 d3d10_device_PSSetConstantBuffers,
6523 d3d10_device_IASetInputLayout,
6524 d3d10_device_IASetVertexBuffers,
6525 d3d10_device_IASetIndexBuffer,
6526 d3d10_device_DrawIndexedInstanced,
6527 d3d10_device_DrawInstanced,
6528 d3d10_device_GSSetConstantBuffers,
6529 d3d10_device_GSSetShader,
6530 d3d10_device_IASetPrimitiveTopology,
6531 d3d10_device_VSSetShaderResources,
6532 d3d10_device_VSSetSamplers,
6533 d3d10_device_SetPredication,
6534 d3d10_device_GSSetShaderResources,
6535 d3d10_device_GSSetSamplers,
6536 d3d10_device_OMSetRenderTargets,
6537 d3d10_device_OMSetBlendState,
6538 d3d10_device_OMSetDepthStencilState,
6539 d3d10_device_SOSetTargets,
6540 d3d10_device_DrawAuto,
6541 d3d10_device_RSSetState,
6542 d3d10_device_RSSetViewports,
6543 d3d10_device_RSSetScissorRects,
6544 d3d10_device_CopySubresourceRegion,
6545 d3d10_device_CopyResource,
6546 d3d10_device_UpdateSubresource,
6547 d3d10_device_ClearRenderTargetView,
6548 d3d10_device_ClearDepthStencilView,
6549 d3d10_device_GenerateMips,
6550 d3d10_device_ResolveSubresource,
6551 d3d10_device_VSGetConstantBuffers,
6552 d3d10_device_PSGetShaderResources,
6553 d3d10_device_PSGetShader,
6554 d3d10_device_PSGetSamplers,
6555 d3d10_device_VSGetShader,
6556 d3d10_device_PSGetConstantBuffers,
6557 d3d10_device_IAGetInputLayout,
6558 d3d10_device_IAGetVertexBuffers,
6559 d3d10_device_IAGetIndexBuffer,
6560 d3d10_device_GSGetConstantBuffers,
6561 d3d10_device_GSGetShader,
6562 d3d10_device_IAGetPrimitiveTopology,
6563 d3d10_device_VSGetShaderResources,
6564 d3d10_device_VSGetSamplers,
6565 d3d10_device_GetPredication,
6566 d3d10_device_GSGetShaderResources,
6567 d3d10_device_GSGetSamplers,
6568 d3d10_device_OMGetRenderTargets,
6569 d3d10_device_OMGetBlendState,
6570 d3d10_device_OMGetDepthStencilState,
6571 d3d10_device_SOGetTargets,
6572 d3d10_device_RSGetState,
6573 d3d10_device_RSGetViewports,
6574 d3d10_device_RSGetScissorRects,
6575 d3d10_device_GetDeviceRemovedReason,
6576 d3d10_device_SetExceptionMode,
6577 d3d10_device_GetExceptionMode,
6578 d3d10_device_GetPrivateData,
6579 d3d10_device_SetPrivateData,
6580 d3d10_device_SetPrivateDataInterface,
6581 d3d10_device_ClearState,
6582 d3d10_device_Flush,
6583 d3d10_device_CreateBuffer,
6584 d3d10_device_CreateTexture1D,
6585 d3d10_device_CreateTexture2D,
6586 d3d10_device_CreateTexture3D,
6587 d3d10_device_CreateShaderResourceView,
6588 d3d10_device_CreateRenderTargetView,
6589 d3d10_device_CreateDepthStencilView,
6590 d3d10_device_CreateInputLayout,
6591 d3d10_device_CreateVertexShader,
6592 d3d10_device_CreateGeometryShader,
6593 d3d10_device_CreateGeometryShaderWithStreamOutput,
6594 d3d10_device_CreatePixelShader,
6595 d3d10_device_CreateBlendState,
6596 d3d10_device_CreateDepthStencilState,
6597 d3d10_device_CreateRasterizerState,
6598 d3d10_device_CreateSamplerState,
6599 d3d10_device_CreateQuery,
6600 d3d10_device_CreatePredicate,
6601 d3d10_device_CreateCounter,
6602 d3d10_device_CheckFormatSupport,
6603 d3d10_device_CheckMultisampleQualityLevels,
6604 d3d10_device_CheckCounterInfo,
6605 d3d10_device_CheckCounter,
6606 d3d10_device_GetCreationFlags,
6607 d3d10_device_OpenSharedResource,
6608 d3d10_device_SetTextFilterSize,
6609 d3d10_device_GetTextFilterSize,
6610 d3d10_device_CreateShaderResourceView1,
6611 d3d10_device_CreateBlendState1,
6612 d3d10_device_GetFeatureLevel,
6615 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6617 /* IUnknown methods */
6618 d3d_device_inner_QueryInterface,
6619 d3d_device_inner_AddRef,
6620 d3d_device_inner_Release,
6623 /* ID3D10Multithread methods */
6625 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6627 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6630 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6632 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6634 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6636 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6639 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6641 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6643 TRACE("iface %p.\n", iface);
6645 return IUnknown_AddRef(device->outer_unk);
6648 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6650 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6652 TRACE("iface %p.\n", iface);
6654 return IUnknown_Release(device->outer_unk);
6657 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6659 TRACE("iface %p.\n", iface);
6661 wined3d_mutex_lock();
6664 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6666 TRACE("iface %p.\n", iface);
6668 wined3d_mutex_unlock();
6671 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6673 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6675 return TRUE;
6678 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6680 FIXME("iface %p stub!\n", iface);
6682 return TRUE;
6685 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6687 d3d10_multithread_QueryInterface,
6688 d3d10_multithread_AddRef,
6689 d3d10_multithread_Release,
6690 d3d10_multithread_Enter,
6691 d3d10_multithread_Leave,
6692 d3d10_multithread_SetMultithreadProtected,
6693 d3d10_multithread_GetMultithreadProtected,
6696 /* IWineDXGIDeviceParent IUnknown methods */
6698 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6700 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6703 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6704 REFIID iid, void **out)
6706 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6707 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6710 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6712 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6713 return IUnknown_AddRef(device->outer_unk);
6716 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6718 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6719 return IUnknown_Release(device->outer_unk);
6722 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6723 IWineDXGIDeviceParent *iface)
6725 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6726 return &device->device_parent;
6729 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6731 /* IUnknown methods */
6732 dxgi_device_parent_QueryInterface,
6733 dxgi_device_parent_AddRef,
6734 dxgi_device_parent_Release,
6735 /* IWineDXGIDeviceParent methods */
6736 dxgi_device_parent_get_wined3d_device_parent,
6739 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6741 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6744 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6745 struct wined3d_device *wined3d_device)
6747 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6748 struct d3d_device_context_state *state;
6749 struct wined3d_state *wined3d_state;
6750 D3D_FEATURE_LEVEL feature_level;
6752 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6754 wined3d_device_incref(wined3d_device);
6755 device->wined3d_device = wined3d_device;
6756 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6758 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6759 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6761 if (!(state = heap_alloc_zero(sizeof(*state))))
6763 ERR("Failed to create the initial device context state.\n");
6764 return;
6767 d3d_device_context_state_init(state, device, feature_level,
6768 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6770 device->state = state;
6771 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6772 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6774 d3d_device_context_state_private_addref(state);
6775 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6778 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6780 TRACE("device_parent %p.\n", device_parent);
6783 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6785 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6788 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6789 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6790 void **parent, const struct wined3d_parent_ops **parent_ops)
6792 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6793 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6795 *parent = NULL;
6796 *parent_ops = &d3d_null_wined3d_parent_ops;
6798 return S_OK;
6801 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6802 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6803 struct wined3d_texture **wined3d_texture)
6805 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6806 struct d3d_texture2d *texture;
6807 ID3D11Texture2D *texture_iface;
6808 D3D11_TEXTURE2D_DESC desc;
6809 HRESULT hr;
6811 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6812 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6814 desc.Width = wined3d_desc->width;
6815 desc.Height = wined3d_desc->height;
6816 desc.MipLevels = 1;
6817 desc.ArraySize = 1;
6818 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6819 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6820 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6821 desc.Usage = D3D11_USAGE_DEFAULT;
6822 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6823 desc.CPUAccessFlags = 0;
6824 desc.MiscFlags = 0;
6826 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6828 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6829 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6832 if (texture_flags)
6833 FIXME("Unhandled flags %#x.\n", texture_flags);
6835 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6836 &desc, NULL, &texture_iface)))
6838 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6839 return hr;
6842 texture = impl_from_ID3D11Texture2D(texture_iface);
6844 *wined3d_texture = texture->wined3d_texture;
6845 wined3d_texture_incref(*wined3d_texture);
6846 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6848 return S_OK;
6851 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6853 device_parent_wined3d_device_created,
6854 device_parent_mode_changed,
6855 device_parent_activate,
6856 device_parent_texture_sub_resource_created,
6857 device_parent_create_swapchain_texture,
6860 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6862 const D3D11_SAMPLER_DESC *ka = key;
6863 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6865 return memcmp(ka, kb, sizeof(*ka));
6868 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6870 const D3D11_BLEND_DESC *ka = key;
6871 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6873 return memcmp(ka, kb, sizeof(*ka));
6876 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6878 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6879 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6880 const struct d3d_depthstencil_state, entry)->desc;
6882 return memcmp(ka, kb, sizeof(*ka));
6885 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6887 const D3D11_RASTERIZER_DESC1 *ka = key;
6888 const D3D11_RASTERIZER_DESC1 *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6890 return memcmp(ka, kb, sizeof(*ka));
6893 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6895 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6896 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6897 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6898 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6899 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6900 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6901 device->refcount = 1;
6902 /* COM aggregation always takes place */
6903 device->outer_unk = outer_unknown;
6904 device->d3d11_only = FALSE;
6905 device->state = NULL;
6907 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6908 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6910 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6911 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6912 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6913 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);