winex11.drv: Release window data before calling sync_window_cursor().
[wine.git] / dlls / d3d11 / device.c
blob65706a414d8f679b0a022331d22121286e56693f
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 = 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 %lu.\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 %lu.\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 %lu.\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 free(state->entries);
162 wined3d_device_decref(state->wined3d_device);
163 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 %lu.\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 %lu.\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 %lu.\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 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 %lu.\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 %lu.\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 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 mapped_subresource->pData = NULL;
804 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE
805 && map_type != D3D11_MAP_WRITE_DISCARD && map_type != D3D11_MAP_WRITE_NO_OVERWRITE)
806 return E_INVALIDARG;
808 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
810 if (SUCCEEDED(hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
811 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type))))
813 mapped_subresource->pData = map_desc.data;
814 mapped_subresource->RowPitch = map_desc.row_pitch;
815 mapped_subresource->DepthPitch = map_desc.slice_pitch;
818 return hr;
821 static void STDMETHODCALLTYPE d3d11_device_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
822 UINT subresource_idx)
824 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
825 struct wined3d_resource *wined3d_resource;
827 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
829 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
831 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
834 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
835 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
837 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
838 iface, start_slot, buffer_count, buffers);
840 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
841 buffer_count, buffers, NULL, NULL);
844 static void STDMETHODCALLTYPE d3d11_device_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
845 ID3D11InputLayout *input_layout)
847 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
848 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
850 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
852 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
855 static void STDMETHODCALLTYPE d3d11_device_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
856 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
858 struct wined3d_stream_state streams[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
859 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
860 unsigned int i;
862 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
863 iface, start_slot, buffer_count, buffers, strides, offsets);
865 if (buffer_count > ARRAY_SIZE(streams))
867 WARN("Buffer count %u exceeds limit.\n", buffer_count);
868 buffer_count = ARRAY_SIZE(streams);
871 for (i = 0; i < buffer_count; ++i)
873 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
875 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
876 streams[i].offset = offsets[i];
877 streams[i].stride = strides[i];
878 streams[i].frequency = 1;
879 streams[i].flags = 0;
882 wined3d_device_context_set_stream_sources(context->wined3d_context, start_slot, buffer_count, streams);
885 static void STDMETHODCALLTYPE d3d11_device_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
886 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
888 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
889 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
891 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
892 iface, buffer, debug_dxgi_format(format), offset);
894 wined3d_device_context_set_index_buffer(context->wined3d_context,
895 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
896 wined3dformat_from_dxgi_format(format), offset);
899 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
900 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
901 UINT start_instance_location)
903 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
905 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
906 "base_vertex_location %d, start_instance_location %u.\n",
907 iface, instance_index_count, instance_count, start_index_location,
908 base_vertex_location, start_instance_location);
910 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
911 start_index_location, instance_index_count, start_instance_location, instance_count);
914 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstanced(ID3D11DeviceContext1 *iface,
915 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
917 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
919 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
920 "start_instance_location %u.\n",
921 iface, instance_vertex_count, instance_count, start_vertex_location,
922 start_instance_location);
924 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
925 instance_vertex_count, start_instance_location, instance_count);
928 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
929 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
931 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
932 iface, start_slot, buffer_count, buffers);
934 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
935 buffer_count, buffers, NULL, NULL);
938 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShader(ID3D11DeviceContext1 *iface,
939 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
941 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
942 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
944 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
945 iface, shader, class_instances, class_instance_count);
947 if (class_instance_count)
948 FIXME("Dynamic linking is not implemented yet.\n");
950 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
951 gs ? gs->wined3d_shader : NULL);
954 static void STDMETHODCALLTYPE d3d11_device_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
955 D3D11_PRIMITIVE_TOPOLOGY topology)
957 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
958 enum wined3d_primitive_type primitive_type;
959 unsigned int patch_vertex_count;
961 TRACE("iface %p, topology %#x.\n", iface, topology);
963 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
965 wined3d_device_context_set_primitive_type(context->wined3d_context, primitive_type, patch_vertex_count);
968 static void STDMETHODCALLTYPE d3d11_device_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
969 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
971 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
973 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
976 static void STDMETHODCALLTYPE d3d11_device_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
977 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
979 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
980 iface, start_slot, sampler_count, samplers);
982 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
985 static void STDMETHODCALLTYPE d3d11_device_context_Begin(ID3D11DeviceContext1 *iface,
986 ID3D11Asynchronous *asynchronous)
988 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
989 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
991 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
993 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_BEGIN);
996 static void STDMETHODCALLTYPE d3d11_device_context_End(ID3D11DeviceContext1 *iface,
997 ID3D11Asynchronous *asynchronous)
999 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1000 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1002 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
1004 wined3d_device_context_issue_query(context->wined3d_context, query->wined3d_query, WINED3DISSUE_END);
1007 static HRESULT STDMETHODCALLTYPE d3d11_device_context_GetData(ID3D11DeviceContext1 *iface,
1008 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
1010 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1011 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
1012 unsigned int wined3d_flags;
1013 HRESULT hr;
1015 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
1016 iface, asynchronous, data, data_size, data_flags);
1018 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
1019 return DXGI_ERROR_INVALID_CALL;
1021 if (!data && data_size)
1022 return E_INVALIDARG;
1024 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
1026 wined3d_mutex_lock();
1027 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
1029 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
1030 if (hr == WINED3DERR_INVALIDCALL)
1031 hr = DXGI_ERROR_INVALID_CALL;
1033 else
1035 WARN("Invalid data size %u.\n", data_size);
1036 hr = E_INVALIDARG;
1038 wined3d_mutex_unlock();
1040 return hr;
1043 static void STDMETHODCALLTYPE d3d11_device_context_SetPredication(ID3D11DeviceContext1 *iface,
1044 ID3D11Predicate *predicate, BOOL value)
1046 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1047 struct d3d_query *query;
1049 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1051 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
1053 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
1056 static void STDMETHODCALLTYPE d3d11_device_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
1057 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1059 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1061 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
1064 static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
1065 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1067 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1068 iface, start_slot, sampler_count, samplers);
1070 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
1073 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
1074 UINT rtv_count, ID3D11RenderTargetView *const *rtvs, ID3D11DepthStencilView *depth_stencil_view)
1076 struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1077 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1078 struct d3d_depthstencil_view *dsv;
1079 unsigned int i;
1081 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
1083 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
1085 WARN("View count %u exceeds limit.\n", rtv_count);
1086 rtv_count = ARRAY_SIZE(wined3d_rtvs);
1089 for (i = 0; i < rtv_count; ++i)
1091 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(rtvs[i]);
1093 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1096 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1098 wined3d_device_context_set_render_targets_and_unordered_access_views(context->wined3d_context,
1099 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ~0u, NULL, NULL);
1102 static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews(
1103 ID3D11DeviceContext1 *iface, UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
1104 ID3D11DepthStencilView *depth_stencil_view, UINT uav_start_idx, UINT uav_count,
1105 ID3D11UnorderedAccessView *const *uavs, const UINT *initial_counts)
1107 struct d3d_depthstencil_view *dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1108 struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
1109 struct wined3d_unordered_access_view *wined3d_uavs[D3D11_PS_CS_UAV_REGISTER_COUNT] = {0};
1110 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1111 unsigned int wined3d_initial_counts[D3D11_PS_CS_UAV_REGISTER_COUNT];
1112 unsigned int i;
1114 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1115 "uav_start_idx %u, uav_count %u, uavs %p, initial_counts %p.\n",
1116 iface, render_target_view_count, render_target_views, depth_stencil_view,
1117 uav_start_idx, uav_count, uavs, initial_counts);
1119 if (render_target_view_count == D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
1120 render_target_view_count = ~0u;
1121 else
1123 if (render_target_view_count > ARRAY_SIZE(wined3d_rtvs))
1125 WARN("View count %u exceeds limit.\n", render_target_view_count);
1126 render_target_view_count = ARRAY_SIZE(wined3d_rtvs);
1129 for (i = 0; i < render_target_view_count; ++i)
1131 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
1133 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
1137 if (uav_count == D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
1138 uav_count = ~0u;
1139 else
1141 if (!wined3d_bound_range(uav_start_idx, uav_count, ARRAY_SIZE(wined3d_uavs)))
1143 WARN("View count %u exceeds limit; ignoring call.\n", uav_count);
1144 return;
1147 memset(wined3d_initial_counts, 0xff, sizeof(wined3d_initial_counts));
1149 for (i = 0; i < uav_count; ++i)
1151 struct d3d11_unordered_access_view *view =
1152 unsafe_impl_from_ID3D11UnorderedAccessView(uavs[i]);
1154 wined3d_uavs[uav_start_idx + i] = view ? view->wined3d_view : NULL;
1155 wined3d_initial_counts[uav_start_idx + i] = initial_counts ? initial_counts[i] : ~0u;
1159 wined3d_device_context_set_render_targets_and_unordered_access_views(context->wined3d_context, ARRAY_SIZE(wined3d_rtvs),
1160 wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ARRAY_SIZE(wined3d_uavs), wined3d_uavs,
1161 wined3d_initial_counts);
1164 static void STDMETHODCALLTYPE d3d11_device_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1165 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1167 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1168 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1169 struct d3d_blend_state *blend_state_impl;
1171 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1172 iface, blend_state, debug_float4(blend_factor), sample_mask);
1174 if (!blend_factor)
1175 blend_factor = default_blend_factor;
1177 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1178 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1179 (const struct wined3d_color *)blend_factor, sample_mask);
1180 else
1181 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1182 (const struct wined3d_color *)blend_factor, sample_mask);
1185 static void STDMETHODCALLTYPE d3d11_device_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1186 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1188 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1189 struct d3d_depthstencil_state *state_impl;
1191 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1192 iface, depth_stencil_state, stencil_ref);
1194 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1196 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1197 return;
1200 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1203 static void STDMETHODCALLTYPE d3d11_device_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1204 ID3D11Buffer *const *buffers, const UINT *offsets)
1206 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
1207 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1208 unsigned int count, i;
1210 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1212 count = min(buffer_count, ARRAY_SIZE(outputs));
1213 for (i = 0; i < count; ++i)
1215 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1217 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
1218 outputs[i].offset = offsets ? offsets[i] : 0;
1221 wined3d_device_context_set_stream_outputs(context->wined3d_context, outputs);
1224 static void STDMETHODCALLTYPE d3d11_device_context_DrawAuto(ID3D11DeviceContext1 *iface)
1226 FIXME("iface %p stub!\n", iface);
1229 static void STDMETHODCALLTYPE d3d11_device_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1230 ID3D11Buffer *buffer, UINT offset)
1232 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1233 struct d3d_buffer *d3d_buffer;
1235 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1237 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1239 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1242 static void STDMETHODCALLTYPE d3d11_device_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1243 ID3D11Buffer *buffer, UINT offset)
1245 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1246 struct d3d_buffer *d3d_buffer;
1248 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1250 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1252 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1255 static void STDMETHODCALLTYPE d3d11_device_context_Dispatch(ID3D11DeviceContext1 *iface,
1256 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1258 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1260 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1261 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1263 wined3d_device_context_dispatch(context->wined3d_context,
1264 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1267 static void STDMETHODCALLTYPE d3d11_device_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1268 ID3D11Buffer *buffer, UINT offset)
1270 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1271 struct d3d_buffer *buffer_impl;
1273 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1275 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1277 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1280 static void STDMETHODCALLTYPE d3d11_device_context_RSSetState(ID3D11DeviceContext1 *iface,
1281 ID3D11RasterizerState *rasterizer_state)
1283 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1284 struct d3d_rasterizer_state *rasterizer_state_impl;
1286 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1288 rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
1289 wined3d_device_context_set_rasterizer_state(context->wined3d_context,
1290 rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
1293 static void STDMETHODCALLTYPE d3d11_device_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1294 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1296 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1297 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1298 unsigned int i;
1300 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1302 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1303 return;
1305 for (i = 0; i < viewport_count; ++i)
1307 wined3d_vp[i].x = viewports[i].TopLeftX;
1308 wined3d_vp[i].y = viewports[i].TopLeftY;
1309 wined3d_vp[i].width = viewports[i].Width;
1310 wined3d_vp[i].height = viewports[i].Height;
1311 wined3d_vp[i].min_z = viewports[i].MinDepth;
1312 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1315 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1318 static void STDMETHODCALLTYPE d3d11_device_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1319 UINT rect_count, const D3D11_RECT *rects)
1321 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1323 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1325 if (rect_count > WINED3D_MAX_VIEWPORTS)
1326 return;
1328 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1331 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1332 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1333 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1335 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1336 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1337 struct wined3d_box wined3d_src_box;
1339 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1340 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1341 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1342 src_resource, src_subresource_idx, src_box);
1344 if (!dst_resource || !src_resource)
1345 return;
1347 if (src_box)
1348 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1349 src_box->right, src_box->bottom, src_box->front, src_box->back);
1351 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1352 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1353 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1354 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1357 static void STDMETHODCALLTYPE d3d11_device_context_CopyResource(ID3D11DeviceContext1 *iface,
1358 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1360 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1361 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1363 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1365 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1366 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1367 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1370 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1371 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1372 const void *data, UINT row_pitch, UINT depth_pitch)
1374 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1375 struct wined3d_resource *wined3d_resource;
1376 struct wined3d_box wined3d_box;
1378 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1379 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1381 if (box)
1382 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1384 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1385 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1386 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1389 static void STDMETHODCALLTYPE d3d11_device_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1390 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1392 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1393 struct d3d11_unordered_access_view *uav;
1394 struct d3d_buffer *buffer_impl;
1396 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1397 iface, dst_buffer, dst_offset, src_view);
1399 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1400 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1402 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1403 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1406 static void STDMETHODCALLTYPE d3d11_device_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1407 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1409 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1410 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1411 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1412 HRESULT hr;
1414 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1415 iface, render_target_view, debug_float4(color_rgba));
1417 if (!view)
1418 return;
1420 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1421 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1422 ERR("Failed to clear view, hr %#lx.\n", hr);
1425 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1426 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1428 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1429 struct d3d11_unordered_access_view *view;
1431 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1432 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1434 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1435 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1436 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1439 static void STDMETHODCALLTYPE d3d11_device_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1440 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1442 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1443 struct d3d11_unordered_access_view *view;
1445 TRACE("iface %p, unordered_access_view %p, values %s.\n",
1446 iface, unordered_access_view, debug_float4(values));
1448 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1449 wined3d_device_context_clear_uav_float(context->wined3d_context,
1450 view->wined3d_view, (const struct wined3d_vec4 *)values);
1453 static void STDMETHODCALLTYPE d3d11_device_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1454 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1456 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1457 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1458 DWORD wined3d_flags;
1459 HRESULT hr;
1461 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1462 iface, depth_stencil_view, flags, depth, stencil);
1464 if (!view)
1465 return;
1467 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1469 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1470 wined3d_flags, NULL, depth, stencil)))
1471 ERR("Failed to clear view, hr %#lx.\n", hr);
1474 static void STDMETHODCALLTYPE d3d11_device_context_GenerateMips(ID3D11DeviceContext1 *iface,
1475 ID3D11ShaderResourceView *view)
1477 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1478 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1480 TRACE("iface %p, view %p.\n", iface, view);
1482 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1485 static void STDMETHODCALLTYPE d3d11_device_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1486 ID3D11Resource *resource, FLOAT min_lod)
1488 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1491 static FLOAT STDMETHODCALLTYPE d3d11_device_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1492 ID3D11Resource *resource)
1494 FIXME("iface %p, resource %p stub!\n", iface, resource);
1496 return 0.0f;
1499 static void STDMETHODCALLTYPE d3d11_device_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1500 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1501 ID3D11Resource *src_resource, UINT src_subresource_idx,
1502 DXGI_FORMAT format)
1504 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1505 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1506 enum wined3d_format_id wined3d_format;
1508 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1509 "src_resource %p, src_subresource_idx %u, format %s.\n",
1510 iface, dst_resource, dst_subresource_idx,
1511 src_resource, src_subresource_idx, debug_dxgi_format(format));
1513 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1514 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1515 wined3d_format = wined3dformat_from_dxgi_format(format);
1516 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1517 wined3d_dst_resource, dst_subresource_idx,
1518 wined3d_src_resource, src_subresource_idx, wined3d_format);
1521 static void STDMETHODCALLTYPE d3d11_device_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1522 ID3D11CommandList *command_list, BOOL restore_state)
1524 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1525 struct d3d11_command_list *list_impl = unsafe_impl_from_ID3D11CommandList(command_list);
1527 TRACE("iface %p, command_list %p, restore_state %#x.\n", iface, command_list, restore_state);
1529 wined3d_device_context_execute_command_list(context->wined3d_context, list_impl->wined3d_list, !!restore_state);
1532 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1533 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1535 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1536 iface, start_slot, view_count, views);
1538 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_HULL, start_slot, view_count, views);
1541 static void STDMETHODCALLTYPE d3d11_device_context_HSSetShader(ID3D11DeviceContext1 *iface,
1542 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1544 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1545 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1547 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1548 iface, shader, class_instances, class_instance_count);
1550 if (class_instance_count)
1551 FIXME("Dynamic linking is not implemented yet.\n");
1553 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1554 hs ? hs->wined3d_shader : NULL);
1557 static void STDMETHODCALLTYPE d3d11_device_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1558 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1560 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1561 iface, start_slot, sampler_count, samplers);
1563 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_HULL, start_slot, sampler_count, samplers);
1566 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1567 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1569 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1570 iface, start_slot, buffer_count, buffers);
1572 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1573 buffer_count, buffers, NULL, NULL);
1576 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1577 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1579 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1580 iface, start_slot, view_count, views);
1582 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, view_count, views);
1585 static void STDMETHODCALLTYPE d3d11_device_context_DSSetShader(ID3D11DeviceContext1 *iface,
1586 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1588 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1589 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1591 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1592 iface, shader, class_instances, class_instance_count);
1594 if (class_instance_count)
1595 FIXME("Dynamic linking is not implemented yet.\n");
1597 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1598 ds ? ds->wined3d_shader : NULL);
1601 static void STDMETHODCALLTYPE d3d11_device_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1602 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1604 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1605 iface, start_slot, sampler_count, samplers);
1607 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot, sampler_count, samplers);
1610 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1611 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1613 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1614 iface, start_slot, buffer_count, buffers);
1616 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1617 buffer_count, buffers, NULL, NULL);
1620 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1621 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1623 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1624 iface, start_slot, view_count, views);
1626 d3d11_device_context_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, view_count, views);
1629 static void STDMETHODCALLTYPE d3d11_device_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1630 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1632 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1633 struct wined3d_unordered_access_view *wined3d_views[D3D11_PS_CS_UAV_REGISTER_COUNT];
1634 unsigned int i;
1636 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1637 iface, start_slot, view_count, views, initial_counts);
1639 if (view_count > ARRAY_SIZE(wined3d_views))
1641 WARN("View count %u exceeds limit; ignoring call.\n", view_count);
1642 return;
1645 for (i = 0; i < view_count; ++i)
1647 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1649 wined3d_views[i] = view ? view->wined3d_view : NULL;
1652 wined3d_device_context_set_unordered_access_views(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1653 start_slot, view_count, wined3d_views, initial_counts);
1656 static void STDMETHODCALLTYPE d3d11_device_context_CSSetShader(ID3D11DeviceContext1 *iface,
1657 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1659 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1660 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1662 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1663 iface, shader, class_instances, class_instance_count);
1665 if (class_instance_count)
1666 FIXME("Dynamic linking is not implemented yet.\n");
1668 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1669 cs ? cs->wined3d_shader : NULL);
1672 static void STDMETHODCALLTYPE d3d11_device_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1673 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1675 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1676 iface, start_slot, sampler_count, samplers);
1678 d3d11_device_context_set_samplers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot, sampler_count, samplers);
1681 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1682 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1684 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1685 iface, start_slot, buffer_count, buffers);
1687 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1688 buffer_count, buffers, NULL, NULL);
1691 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1692 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1694 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1695 iface, start_slot, buffer_count, buffers);
1697 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1698 buffer_count, buffers, NULL, NULL);
1701 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1702 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1704 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1705 unsigned int i;
1707 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1708 iface, start_slot, view_count, views);
1710 wined3d_mutex_lock();
1711 for (i = 0; i < view_count; ++i)
1713 struct wined3d_shader_resource_view *wined3d_view;
1714 struct d3d_shader_resource_view *view_impl;
1716 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1717 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1719 views[i] = NULL;
1720 continue;
1723 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1724 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1725 ID3D11ShaderResourceView_AddRef(views[i]);
1727 wined3d_mutex_unlock();
1730 static void STDMETHODCALLTYPE d3d11_device_context_PSGetShader(ID3D11DeviceContext1 *iface,
1731 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1733 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1734 struct wined3d_shader *wined3d_shader;
1735 struct d3d_pixel_shader *shader_impl;
1737 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1738 iface, shader, class_instances, class_instance_count);
1740 if (class_instance_count)
1741 *class_instance_count = 0;
1743 wined3d_mutex_lock();
1744 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL)))
1746 wined3d_mutex_unlock();
1747 *shader = NULL;
1748 return;
1751 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1752 wined3d_mutex_unlock();
1753 *shader = &shader_impl->ID3D11PixelShader_iface;
1754 ID3D11PixelShader_AddRef(*shader);
1757 static void STDMETHODCALLTYPE d3d11_device_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1758 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1760 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1761 unsigned int i;
1763 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1764 iface, start_slot, sampler_count, samplers);
1766 wined3d_mutex_lock();
1767 for (i = 0; i < sampler_count; ++i)
1769 struct wined3d_sampler *wined3d_sampler;
1770 struct d3d_sampler_state *sampler_impl;
1772 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
1773 context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
1775 samplers[i] = NULL;
1776 continue;
1779 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1780 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1781 ID3D11SamplerState_AddRef(samplers[i]);
1783 wined3d_mutex_unlock();
1786 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShader(ID3D11DeviceContext1 *iface,
1787 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1789 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1790 struct d3d_vertex_shader *shader_impl;
1791 struct wined3d_shader *wined3d_shader;
1793 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1794 iface, shader, class_instances, class_instance_count);
1796 if (class_instance_count)
1797 *class_instance_count = 0;
1799 wined3d_mutex_lock();
1800 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX)))
1802 wined3d_mutex_unlock();
1803 *shader = NULL;
1804 return;
1807 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1808 wined3d_mutex_unlock();
1809 *shader = &shader_impl->ID3D11VertexShader_iface;
1810 ID3D11VertexShader_AddRef(*shader);
1813 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1814 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1816 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1817 iface, start_slot, buffer_count, buffers);
1819 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1820 buffer_count, buffers, NULL, NULL);
1823 static void STDMETHODCALLTYPE d3d11_device_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1824 ID3D11InputLayout **input_layout)
1826 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1827 struct wined3d_vertex_declaration *wined3d_declaration;
1828 struct d3d_input_layout *input_layout_impl;
1830 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1832 wined3d_mutex_lock();
1833 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(context->wined3d_context)))
1835 wined3d_mutex_unlock();
1836 *input_layout = NULL;
1837 return;
1840 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1841 wined3d_mutex_unlock();
1842 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1843 ID3D11InputLayout_AddRef(*input_layout);
1846 static void STDMETHODCALLTYPE d3d11_device_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1847 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1849 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1850 unsigned int i;
1852 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1853 iface, start_slot, buffer_count, buffers, strides, offsets);
1855 wined3d_mutex_lock();
1856 for (i = 0; i < buffer_count; ++i)
1858 struct wined3d_buffer *wined3d_buffer = NULL;
1859 struct d3d_buffer *buffer_impl;
1861 if (FAILED(wined3d_device_context_get_stream_source(context->wined3d_context, start_slot + i,
1862 &wined3d_buffer, &offsets[i], &strides[i])))
1864 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1865 if (strides)
1866 strides[i] = 0;
1867 if (offsets)
1868 offsets[i] = 0;
1871 if (!wined3d_buffer)
1873 buffers[i] = NULL;
1874 continue;
1877 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1878 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1880 wined3d_mutex_unlock();
1883 static void STDMETHODCALLTYPE d3d11_device_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1884 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1886 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1887 enum wined3d_format_id wined3d_format;
1888 struct wined3d_buffer *wined3d_buffer;
1889 struct d3d_buffer *buffer_impl;
1891 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1893 wined3d_mutex_lock();
1894 wined3d_buffer = wined3d_device_context_get_index_buffer(context->wined3d_context, &wined3d_format, offset);
1895 *format = dxgi_format_from_wined3dformat(wined3d_format);
1896 if (!wined3d_buffer)
1898 wined3d_mutex_unlock();
1899 *buffer = NULL;
1900 return;
1903 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1904 wined3d_mutex_unlock();
1905 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1908 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1909 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1911 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1912 iface, start_slot, buffer_count, buffers);
1914 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1915 buffer_count, buffers, NULL, NULL);
1918 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShader(ID3D11DeviceContext1 *iface,
1919 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1921 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1922 struct d3d_geometry_shader *shader_impl;
1923 struct wined3d_shader *wined3d_shader;
1925 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1926 iface, shader, class_instances, class_instance_count);
1928 if (class_instance_count)
1929 *class_instance_count = 0;
1931 wined3d_mutex_lock();
1932 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY)))
1934 wined3d_mutex_unlock();
1935 *shader = NULL;
1936 return;
1939 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1940 wined3d_mutex_unlock();
1941 *shader = &shader_impl->ID3D11GeometryShader_iface;
1942 ID3D11GeometryShader_AddRef(*shader);
1945 static void STDMETHODCALLTYPE d3d11_device_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
1946 D3D11_PRIMITIVE_TOPOLOGY *topology)
1948 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1949 enum wined3d_primitive_type primitive_type;
1950 unsigned int patch_vertex_count;
1952 TRACE("iface %p, topology %p.\n", iface, topology);
1954 wined3d_mutex_lock();
1955 wined3d_device_context_get_primitive_type(context->wined3d_context, &primitive_type, &patch_vertex_count);
1956 wined3d_mutex_unlock();
1958 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1961 static void STDMETHODCALLTYPE d3d11_device_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
1962 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1964 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1965 unsigned int i;
1967 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1969 wined3d_mutex_lock();
1970 for (i = 0; i < view_count; ++i)
1972 struct wined3d_shader_resource_view *wined3d_view;
1973 struct d3d_shader_resource_view *view_impl;
1975 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
1976 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
1978 views[i] = NULL;
1979 continue;
1982 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1983 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1984 ID3D11ShaderResourceView_AddRef(views[i]);
1986 wined3d_mutex_unlock();
1989 static void STDMETHODCALLTYPE d3d11_device_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
1990 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1992 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
1993 unsigned int i;
1995 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1996 iface, start_slot, sampler_count, samplers);
1998 wined3d_mutex_lock();
1999 for (i = 0; i < sampler_count; ++i)
2001 struct wined3d_sampler *wined3d_sampler;
2002 struct d3d_sampler_state *sampler_impl;
2004 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2005 context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
2007 samplers[i] = NULL;
2008 continue;
2011 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2012 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2013 ID3D11SamplerState_AddRef(samplers[i]);
2015 wined3d_mutex_unlock();
2018 static void STDMETHODCALLTYPE d3d11_device_context_GetPredication(ID3D11DeviceContext1 *iface,
2019 ID3D11Predicate **predicate, BOOL *value)
2021 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2022 struct wined3d_query *wined3d_predicate;
2023 struct d3d_query *predicate_impl;
2025 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
2027 wined3d_mutex_lock();
2028 if (!(wined3d_predicate = wined3d_device_context_get_predication(context->wined3d_context, value)))
2030 wined3d_mutex_unlock();
2031 *predicate = NULL;
2032 return;
2035 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
2036 wined3d_mutex_unlock();
2037 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
2038 ID3D11Predicate_AddRef(*predicate);
2041 static void STDMETHODCALLTYPE d3d11_device_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
2042 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2044 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2045 unsigned int i;
2047 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2049 wined3d_mutex_lock();
2050 for (i = 0; i < view_count; ++i)
2052 struct wined3d_shader_resource_view *wined3d_view;
2053 struct d3d_shader_resource_view *view_impl;
2055 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2056 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2058 views[i] = NULL;
2059 continue;
2062 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2063 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2064 ID3D11ShaderResourceView_AddRef(views[i]);
2066 wined3d_mutex_unlock();
2069 static void STDMETHODCALLTYPE d3d11_device_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2070 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2072 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2073 unsigned int i;
2075 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2076 iface, start_slot, sampler_count, samplers);
2078 wined3d_mutex_lock();
2079 for (i = 0; i < sampler_count; ++i)
2081 struct d3d_sampler_state *sampler_impl;
2082 struct wined3d_sampler *wined3d_sampler;
2084 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2085 context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
2087 samplers[i] = NULL;
2088 continue;
2091 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2092 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2093 ID3D11SamplerState_AddRef(samplers[i]);
2095 wined3d_mutex_unlock();
2098 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2099 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2100 ID3D11DepthStencilView **depth_stencil_view)
2102 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2103 struct wined3d_rendertarget_view *wined3d_view;
2105 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2106 iface, render_target_view_count, render_target_views, depth_stencil_view);
2108 wined3d_mutex_lock();
2109 if (render_target_views)
2111 struct d3d_rendertarget_view *view_impl;
2112 unsigned int i;
2114 for (i = 0; i < render_target_view_count; ++i)
2116 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(context->wined3d_context, i))
2117 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2119 render_target_views[i] = NULL;
2120 continue;
2123 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2124 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2128 if (depth_stencil_view)
2130 struct d3d_depthstencil_view *view_impl;
2132 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(context->wined3d_context))
2133 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2135 *depth_stencil_view = NULL;
2137 else
2139 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2140 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2143 wined3d_mutex_unlock();
2146 static void STDMETHODCALLTYPE d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews(
2147 ID3D11DeviceContext1 *iface,
2148 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2149 ID3D11DepthStencilView **depth_stencil_view,
2150 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2151 ID3D11UnorderedAccessView **unordered_access_views)
2153 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2154 struct wined3d_unordered_access_view *wined3d_view;
2155 struct d3d11_unordered_access_view *view_impl;
2156 unsigned int i;
2158 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2159 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2160 "unordered_access_views %p.\n",
2161 iface, render_target_view_count, render_target_views, depth_stencil_view,
2162 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2164 if (render_target_views || depth_stencil_view)
2165 d3d11_device_context_OMGetRenderTargets(iface, render_target_view_count,
2166 render_target_views, depth_stencil_view);
2168 if (unordered_access_views)
2170 wined3d_mutex_lock();
2171 for (i = 0; i < unordered_access_view_count; ++i)
2173 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(context->wined3d_context,
2174 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i)))
2176 unordered_access_views[i] = NULL;
2177 continue;
2180 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2181 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2182 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2184 wined3d_mutex_unlock();
2188 static void STDMETHODCALLTYPE d3d11_device_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2189 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2191 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2192 struct wined3d_blend_state *wined3d_state;
2193 struct d3d_blend_state *blend_state_impl;
2194 unsigned int tmp_sample_mask;
2195 float tmp_blend_factor[4];
2197 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2198 iface, blend_state, blend_factor, sample_mask);
2200 wined3d_mutex_lock();
2201 if (!blend_factor) blend_factor = tmp_blend_factor;
2202 if (!sample_mask) sample_mask = &tmp_sample_mask;
2203 wined3d_state = wined3d_device_context_get_blend_state(context->wined3d_context,
2204 (struct wined3d_color *)blend_factor, sample_mask);
2205 if (blend_state)
2207 if (wined3d_state)
2209 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2210 ID3D11BlendState_AddRef(*blend_state = (ID3D11BlendState *)&blend_state_impl->ID3D11BlendState1_iface);
2212 else
2213 *blend_state = NULL;
2215 wined3d_mutex_unlock();
2218 static void STDMETHODCALLTYPE d3d11_device_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2219 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2221 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2222 struct wined3d_depth_stencil_state *wined3d_state;
2223 struct d3d_depthstencil_state *state_impl;
2224 UINT stencil_ref_tmp;
2226 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2227 iface, depth_stencil_state, stencil_ref);
2229 wined3d_mutex_lock();
2230 if (!stencil_ref) stencil_ref = &stencil_ref_tmp;
2231 wined3d_state = wined3d_device_context_get_depth_stencil_state(context->wined3d_context, stencil_ref);
2232 if (depth_stencil_state)
2234 if (wined3d_state)
2236 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2237 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2239 else
2241 *depth_stencil_state = NULL;
2244 wined3d_mutex_unlock();
2247 static void STDMETHODCALLTYPE d3d11_device_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2248 UINT buffer_count, ID3D11Buffer **buffers)
2250 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2251 unsigned int i;
2253 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2255 wined3d_mutex_lock();
2256 for (i = 0; i < buffer_count; ++i)
2258 struct wined3d_buffer *wined3d_buffer;
2259 struct d3d_buffer *buffer_impl;
2261 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(context->wined3d_context, i, NULL)))
2263 buffers[i] = NULL;
2264 continue;
2267 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2268 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2269 ID3D11Buffer_AddRef(buffers[i]);
2271 wined3d_mutex_unlock();
2274 static void STDMETHODCALLTYPE d3d11_device_context_RSGetState(ID3D11DeviceContext1 *iface,
2275 ID3D11RasterizerState **rasterizer_state)
2277 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2278 struct d3d_rasterizer_state *rasterizer_state_impl;
2279 struct wined3d_rasterizer_state *wined3d_state;
2281 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2283 wined3d_mutex_lock();
2284 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(context->wined3d_context)))
2286 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2287 *rasterizer_state = (ID3D11RasterizerState *)&rasterizer_state_impl->ID3D11RasterizerState1_iface;
2288 ID3D11RasterizerState_AddRef(*rasterizer_state);
2290 else
2292 *rasterizer_state = NULL;
2294 wined3d_mutex_unlock();
2297 static void STDMETHODCALLTYPE d3d11_device_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2298 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2300 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2301 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2302 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2304 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2306 if (!viewport_count)
2307 return;
2309 wined3d_mutex_lock();
2310 wined3d_device_context_get_viewports(context->wined3d_context, &actual_count, viewports ? wined3d_vp : NULL);
2311 wined3d_mutex_unlock();
2313 if (!viewports)
2315 *viewport_count = actual_count;
2316 return;
2319 if (*viewport_count > actual_count)
2320 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2322 *viewport_count = min(actual_count, *viewport_count);
2323 for (i = 0; i < *viewport_count; ++i)
2325 viewports[i].TopLeftX = wined3d_vp[i].x;
2326 viewports[i].TopLeftY = wined3d_vp[i].y;
2327 viewports[i].Width = wined3d_vp[i].width;
2328 viewports[i].Height = wined3d_vp[i].height;
2329 viewports[i].MinDepth = wined3d_vp[i].min_z;
2330 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2334 static void STDMETHODCALLTYPE d3d11_device_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2335 UINT *rect_count, D3D11_RECT *rects)
2337 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2338 unsigned int actual_count;
2340 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2342 if (!rect_count)
2343 return;
2345 actual_count = *rect_count;
2347 wined3d_mutex_lock();
2348 wined3d_device_context_get_scissor_rects(context->wined3d_context, &actual_count, rects);
2349 wined3d_mutex_unlock();
2351 if (rects && *rect_count > actual_count)
2352 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2353 *rect_count = actual_count;
2356 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2357 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2359 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2360 unsigned int i;
2362 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2364 wined3d_mutex_lock();
2365 for (i = 0; i < view_count; ++i)
2367 struct wined3d_shader_resource_view *wined3d_view;
2368 struct d3d_shader_resource_view *view_impl;
2370 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2371 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2373 views[i] = NULL;
2374 continue;
2377 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2378 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2380 wined3d_mutex_unlock();
2383 static void STDMETHODCALLTYPE d3d11_device_context_HSGetShader(ID3D11DeviceContext1 *iface,
2384 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2386 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2387 struct d3d11_hull_shader *shader_impl;
2388 struct wined3d_shader *wined3d_shader;
2390 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2391 iface, shader, class_instances, class_instance_count);
2393 if (class_instance_count)
2394 *class_instance_count = 0;
2396 wined3d_mutex_lock();
2397 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL)))
2399 wined3d_mutex_unlock();
2400 *shader = NULL;
2401 return;
2404 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2405 wined3d_mutex_unlock();
2406 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2409 static void STDMETHODCALLTYPE d3d11_device_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2410 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2412 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2413 unsigned int i;
2415 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2416 iface, start_slot, sampler_count, samplers);
2418 wined3d_mutex_lock();
2419 for (i = 0; i < sampler_count; ++i)
2421 struct wined3d_sampler *wined3d_sampler;
2422 struct d3d_sampler_state *sampler_impl;
2424 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2425 context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i)))
2427 samplers[i] = NULL;
2428 continue;
2431 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2432 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2434 wined3d_mutex_unlock();
2437 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2438 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2440 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2441 iface, start_slot, buffer_count, buffers);
2443 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2444 buffer_count, buffers, NULL, NULL);
2447 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2448 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2450 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2451 unsigned int i;
2453 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2454 iface, start_slot, view_count, views);
2456 wined3d_mutex_lock();
2457 for (i = 0; i < view_count; ++i)
2459 struct wined3d_shader_resource_view *wined3d_view;
2460 struct d3d_shader_resource_view *view_impl;
2462 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2463 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2465 views[i] = NULL;
2466 continue;
2469 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2470 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2472 wined3d_mutex_unlock();
2475 static void STDMETHODCALLTYPE d3d11_device_context_DSGetShader(ID3D11DeviceContext1 *iface,
2476 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2478 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2479 struct d3d11_domain_shader *shader_impl;
2480 struct wined3d_shader *wined3d_shader;
2482 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2483 iface, shader, class_instances, class_instance_count);
2485 if (class_instance_count)
2486 *class_instance_count = 0;
2488 wined3d_mutex_lock();
2489 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN)))
2491 wined3d_mutex_unlock();
2492 *shader = NULL;
2493 return;
2496 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2497 wined3d_mutex_unlock();
2498 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2501 static void STDMETHODCALLTYPE d3d11_device_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2502 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2504 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2505 unsigned int i;
2507 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2508 iface, start_slot, sampler_count, samplers);
2510 wined3d_mutex_lock();
2511 for (i = 0; i < sampler_count; ++i)
2513 struct wined3d_sampler *wined3d_sampler;
2514 struct d3d_sampler_state *sampler_impl;
2516 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2517 context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i)))
2519 samplers[i] = NULL;
2520 continue;
2523 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2524 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2526 wined3d_mutex_unlock();
2529 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2530 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2532 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2533 iface, start_slot, buffer_count, buffers);
2535 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2536 buffer_count, buffers, NULL, NULL);
2539 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2540 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2542 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2543 unsigned int i;
2545 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2547 wined3d_mutex_lock();
2548 for (i = 0; i < view_count; ++i)
2550 struct wined3d_shader_resource_view *wined3d_view;
2551 struct d3d_shader_resource_view *view_impl;
2553 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
2554 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2556 views[i] = NULL;
2557 continue;
2560 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2561 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2563 wined3d_mutex_unlock();
2566 static void STDMETHODCALLTYPE d3d11_device_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2567 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2569 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2570 unsigned int i;
2572 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2574 wined3d_mutex_lock();
2575 for (i = 0; i < view_count; ++i)
2577 struct wined3d_unordered_access_view *wined3d_view;
2578 struct d3d11_unordered_access_view *view_impl;
2580 if (!(wined3d_view = wined3d_device_context_get_unordered_access_view(
2581 context->wined3d_context, WINED3D_PIPELINE_COMPUTE, start_slot + i)))
2583 views[i] = NULL;
2584 continue;
2587 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2588 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2590 wined3d_mutex_unlock();
2593 static void STDMETHODCALLTYPE d3d11_device_context_CSGetShader(ID3D11DeviceContext1 *iface,
2594 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2596 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2597 struct d3d11_compute_shader *shader_impl;
2598 struct wined3d_shader *wined3d_shader;
2600 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2601 iface, shader, class_instances, class_instance_count);
2603 if (class_instance_count)
2604 *class_instance_count = 0;
2606 wined3d_mutex_lock();
2607 if (!(wined3d_shader = wined3d_device_context_get_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE)))
2609 wined3d_mutex_unlock();
2610 *shader = NULL;
2611 return;
2614 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2615 wined3d_mutex_unlock();
2616 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2619 static void STDMETHODCALLTYPE d3d11_device_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2620 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2622 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2623 unsigned int i;
2625 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2626 iface, start_slot, sampler_count, samplers);
2628 wined3d_mutex_lock();
2629 for (i = 0; i < sampler_count; ++i)
2631 struct wined3d_sampler *wined3d_sampler;
2632 struct d3d_sampler_state *sampler_impl;
2634 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
2635 context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i)))
2637 samplers[i] = NULL;
2638 continue;
2641 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2642 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2644 wined3d_mutex_unlock();
2647 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2648 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2650 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2651 iface, start_slot, buffer_count, buffers);
2653 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2654 buffer_count, buffers, NULL, NULL);
2657 static void STDMETHODCALLTYPE d3d11_device_context_ClearState(ID3D11DeviceContext1 *iface)
2659 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2661 TRACE("iface %p.\n", iface);
2663 wined3d_device_context_reset_state(context->wined3d_context);
2666 static void STDMETHODCALLTYPE d3d11_device_context_Flush(ID3D11DeviceContext1 *iface)
2668 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2670 TRACE("iface %p.\n", iface);
2672 wined3d_device_context_flush(context->wined3d_context);
2675 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_device_context_GetType(ID3D11DeviceContext1 *iface)
2677 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2679 TRACE("iface %p.\n", iface);
2681 return context->type;
2684 static UINT STDMETHODCALLTYPE d3d11_device_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2686 TRACE("iface %p.\n", iface);
2688 return 0;
2691 static HRESULT STDMETHODCALLTYPE d3d11_device_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2692 BOOL restore, ID3D11CommandList **command_list)
2694 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2695 struct d3d11_command_list *object;
2696 HRESULT hr;
2698 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2700 if (context->type == D3D11_DEVICE_CONTEXT_IMMEDIATE)
2702 WARN("Attempt to record command list on an immediate context; returning DXGI_ERROR_INVALID_CALL.\n");
2703 return DXGI_ERROR_INVALID_CALL;
2706 if (!(object = calloc(1, sizeof(*object))))
2707 return E_OUTOFMEMORY;
2709 if (FAILED(hr = wined3d_deferred_context_record_command_list(context->wined3d_context,
2710 !!restore, &object->wined3d_list)))
2712 WARN("Failed to record wined3d command list, hr %#lx.\n", hr);
2713 free(object);
2714 return hr;
2717 object->ID3D11CommandList_iface.lpVtbl = &d3d11_command_list_vtbl;
2718 object->refcount = 1;
2719 object->device = &context->device->ID3D11Device2_iface;
2720 wined3d_private_store_init(&object->private_store);
2722 ID3D11Device2_AddRef(object->device);
2724 TRACE("Created command list %p.\n", object);
2725 *command_list = &object->ID3D11CommandList_iface;
2727 return S_OK;
2730 static void STDMETHODCALLTYPE d3d11_device_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2731 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2732 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2734 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2735 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2736 struct wined3d_box wined3d_src_box;
2738 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2739 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2740 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2741 src_resource, src_subresource_idx, src_box, flags);
2743 if (!dst_resource || !src_resource)
2744 return;
2746 if (src_box)
2747 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2748 src_box->right, src_box->bottom, src_box->front, src_box->back);
2750 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2751 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2752 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2753 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2756 static void STDMETHODCALLTYPE d3d11_device_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2757 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2758 UINT row_pitch, UINT depth_pitch, UINT flags)
2760 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2761 struct wined3d_resource *wined3d_resource;
2762 struct wined3d_box wined3d_box;
2764 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2765 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2767 if (box)
2768 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2769 box->front, box->back);
2771 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2772 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2773 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2776 static void STDMETHODCALLTYPE d3d11_device_context_DiscardResource(ID3D11DeviceContext1 *iface,
2777 ID3D11Resource *resource)
2779 FIXME("iface %p, resource %p stub!\n", iface, resource);
2782 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2784 FIXME("iface %p, view %p stub!\n", iface, view);
2787 static void STDMETHODCALLTYPE d3d11_device_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2788 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2789 const UINT *num_constants)
2791 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2792 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2794 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2795 buffer_count, buffers, first_constant, num_constants);
2798 static void STDMETHODCALLTYPE d3d11_device_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2799 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2800 const UINT *num_constants)
2802 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2803 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2805 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2806 buffer_count, buffers, first_constant, num_constants);
2809 static void STDMETHODCALLTYPE d3d11_device_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2810 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2811 const UINT *num_constants)
2813 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2814 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2816 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2817 buffer_count, buffers, first_constant, num_constants);
2820 static void STDMETHODCALLTYPE d3d11_device_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2821 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2822 const UINT *num_constants)
2824 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2825 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2827 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2828 buffer_count, buffers, first_constant, num_constants);
2831 static void STDMETHODCALLTYPE d3d11_device_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2832 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2833 const UINT *num_constants)
2835 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2836 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2838 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2839 buffer_count, buffers, first_constant, num_constants);
2842 static void STDMETHODCALLTYPE d3d11_device_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2843 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2844 const UINT *num_constants)
2846 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2847 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2849 d3d11_device_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2850 buffer_count, buffers, first_constant, num_constants);
2853 static void STDMETHODCALLTYPE d3d11_device_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2854 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2856 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2857 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2859 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
2860 buffer_count, buffers, first_constant, num_constants);
2863 static void STDMETHODCALLTYPE d3d11_device_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2864 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2866 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2867 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2869 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2870 buffer_count, buffers, first_constant, num_constants);
2873 static void STDMETHODCALLTYPE d3d11_device_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2874 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2876 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2877 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2879 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2880 buffer_count, buffers, first_constant, num_constants);
2883 static void STDMETHODCALLTYPE d3d11_device_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2884 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2886 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2887 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2889 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
2890 buffer_count, buffers, first_constant, num_constants);
2893 static void STDMETHODCALLTYPE d3d11_device_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2894 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2896 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2897 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2899 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
2900 buffer_count, buffers, first_constant, num_constants);
2903 static void STDMETHODCALLTYPE d3d11_device_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2904 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2906 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p.\n",
2907 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2909 d3d11_device_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2910 buffer_count, buffers, first_constant, num_constants);
2913 static void STDMETHODCALLTYPE d3d11_device_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2914 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2916 struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
2917 struct d3d_device_context_state *state_impl, *prev_impl;
2918 struct d3d_device *device = context->device;
2919 struct wined3d_state *wined3d_state;
2920 static unsigned int once;
2922 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2924 if (prev)
2925 *prev = NULL;
2927 if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE)
2929 WARN("SwapDeviceContextState is not allowed on a deferred context.\n");
2930 return;
2933 if (!state)
2934 return;
2936 wined3d_mutex_lock();
2938 prev_impl = device->state;
2939 state_impl = impl_from_ID3DDeviceContextState(state);
2940 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2941 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2942 wined3d_device_context_set_state(context->wined3d_context, wined3d_state);
2944 if (prev)
2945 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2947 d3d_device_context_state_private_addref(state_impl);
2948 device->state = state_impl;
2949 d3d_device_context_state_private_release(prev_impl);
2951 if (d3d_device_is_d3d10_active(device) && !once++)
2952 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2953 wined3d_mutex_unlock();
2956 static void STDMETHODCALLTYPE d3d11_device_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2957 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2959 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2962 static void STDMETHODCALLTYPE d3d11_device_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2963 const D3D11_RECT *rects, UINT num_rects)
2965 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
2968 static const struct ID3D11DeviceContext1Vtbl d3d11_device_context_vtbl =
2970 /* IUnknown methods */
2971 d3d11_device_context_QueryInterface,
2972 d3d11_device_context_AddRef,
2973 d3d11_device_context_Release,
2974 /* ID3D11DeviceChild methods */
2975 d3d11_device_context_GetDevice,
2976 d3d11_device_context_GetPrivateData,
2977 d3d11_device_context_SetPrivateData,
2978 d3d11_device_context_SetPrivateDataInterface,
2979 /* ID3D11DeviceContext methods */
2980 d3d11_device_context_VSSetConstantBuffers,
2981 d3d11_device_context_PSSetShaderResources,
2982 d3d11_device_context_PSSetShader,
2983 d3d11_device_context_PSSetSamplers,
2984 d3d11_device_context_VSSetShader,
2985 d3d11_device_context_DrawIndexed,
2986 d3d11_device_context_Draw,
2987 d3d11_device_context_Map,
2988 d3d11_device_context_Unmap,
2989 d3d11_device_context_PSSetConstantBuffers,
2990 d3d11_device_context_IASetInputLayout,
2991 d3d11_device_context_IASetVertexBuffers,
2992 d3d11_device_context_IASetIndexBuffer,
2993 d3d11_device_context_DrawIndexedInstanced,
2994 d3d11_device_context_DrawInstanced,
2995 d3d11_device_context_GSSetConstantBuffers,
2996 d3d11_device_context_GSSetShader,
2997 d3d11_device_context_IASetPrimitiveTopology,
2998 d3d11_device_context_VSSetShaderResources,
2999 d3d11_device_context_VSSetSamplers,
3000 d3d11_device_context_Begin,
3001 d3d11_device_context_End,
3002 d3d11_device_context_GetData,
3003 d3d11_device_context_SetPredication,
3004 d3d11_device_context_GSSetShaderResources,
3005 d3d11_device_context_GSSetSamplers,
3006 d3d11_device_context_OMSetRenderTargets,
3007 d3d11_device_context_OMSetRenderTargetsAndUnorderedAccessViews,
3008 d3d11_device_context_OMSetBlendState,
3009 d3d11_device_context_OMSetDepthStencilState,
3010 d3d11_device_context_SOSetTargets,
3011 d3d11_device_context_DrawAuto,
3012 d3d11_device_context_DrawIndexedInstancedIndirect,
3013 d3d11_device_context_DrawInstancedIndirect,
3014 d3d11_device_context_Dispatch,
3015 d3d11_device_context_DispatchIndirect,
3016 d3d11_device_context_RSSetState,
3017 d3d11_device_context_RSSetViewports,
3018 d3d11_device_context_RSSetScissorRects,
3019 d3d11_device_context_CopySubresourceRegion,
3020 d3d11_device_context_CopyResource,
3021 d3d11_device_context_UpdateSubresource,
3022 d3d11_device_context_CopyStructureCount,
3023 d3d11_device_context_ClearRenderTargetView,
3024 d3d11_device_context_ClearUnorderedAccessViewUint,
3025 d3d11_device_context_ClearUnorderedAccessViewFloat,
3026 d3d11_device_context_ClearDepthStencilView,
3027 d3d11_device_context_GenerateMips,
3028 d3d11_device_context_SetResourceMinLOD,
3029 d3d11_device_context_GetResourceMinLOD,
3030 d3d11_device_context_ResolveSubresource,
3031 d3d11_device_context_ExecuteCommandList,
3032 d3d11_device_context_HSSetShaderResources,
3033 d3d11_device_context_HSSetShader,
3034 d3d11_device_context_HSSetSamplers,
3035 d3d11_device_context_HSSetConstantBuffers,
3036 d3d11_device_context_DSSetShaderResources,
3037 d3d11_device_context_DSSetShader,
3038 d3d11_device_context_DSSetSamplers,
3039 d3d11_device_context_DSSetConstantBuffers,
3040 d3d11_device_context_CSSetShaderResources,
3041 d3d11_device_context_CSSetUnorderedAccessViews,
3042 d3d11_device_context_CSSetShader,
3043 d3d11_device_context_CSSetSamplers,
3044 d3d11_device_context_CSSetConstantBuffers,
3045 d3d11_device_context_VSGetConstantBuffers,
3046 d3d11_device_context_PSGetShaderResources,
3047 d3d11_device_context_PSGetShader,
3048 d3d11_device_context_PSGetSamplers,
3049 d3d11_device_context_VSGetShader,
3050 d3d11_device_context_PSGetConstantBuffers,
3051 d3d11_device_context_IAGetInputLayout,
3052 d3d11_device_context_IAGetVertexBuffers,
3053 d3d11_device_context_IAGetIndexBuffer,
3054 d3d11_device_context_GSGetConstantBuffers,
3055 d3d11_device_context_GSGetShader,
3056 d3d11_device_context_IAGetPrimitiveTopology,
3057 d3d11_device_context_VSGetShaderResources,
3058 d3d11_device_context_VSGetSamplers,
3059 d3d11_device_context_GetPredication,
3060 d3d11_device_context_GSGetShaderResources,
3061 d3d11_device_context_GSGetSamplers,
3062 d3d11_device_context_OMGetRenderTargets,
3063 d3d11_device_context_OMGetRenderTargetsAndUnorderedAccessViews,
3064 d3d11_device_context_OMGetBlendState,
3065 d3d11_device_context_OMGetDepthStencilState,
3066 d3d11_device_context_SOGetTargets,
3067 d3d11_device_context_RSGetState,
3068 d3d11_device_context_RSGetViewports,
3069 d3d11_device_context_RSGetScissorRects,
3070 d3d11_device_context_HSGetShaderResources,
3071 d3d11_device_context_HSGetShader,
3072 d3d11_device_context_HSGetSamplers,
3073 d3d11_device_context_HSGetConstantBuffers,
3074 d3d11_device_context_DSGetShaderResources,
3075 d3d11_device_context_DSGetShader,
3076 d3d11_device_context_DSGetSamplers,
3077 d3d11_device_context_DSGetConstantBuffers,
3078 d3d11_device_context_CSGetShaderResources,
3079 d3d11_device_context_CSGetUnorderedAccessViews,
3080 d3d11_device_context_CSGetShader,
3081 d3d11_device_context_CSGetSamplers,
3082 d3d11_device_context_CSGetConstantBuffers,
3083 d3d11_device_context_ClearState,
3084 d3d11_device_context_Flush,
3085 d3d11_device_context_GetType,
3086 d3d11_device_context_GetContextFlags,
3087 d3d11_device_context_FinishCommandList,
3088 /* ID3D11DeviceContext1 methods */
3089 d3d11_device_context_CopySubresourceRegion1,
3090 d3d11_device_context_UpdateSubresource1,
3091 d3d11_device_context_DiscardResource,
3092 d3d11_device_context_DiscardView,
3093 d3d11_device_context_VSSetConstantBuffers1,
3094 d3d11_device_context_HSSetConstantBuffers1,
3095 d3d11_device_context_DSSetConstantBuffers1,
3096 d3d11_device_context_GSSetConstantBuffers1,
3097 d3d11_device_context_PSSetConstantBuffers1,
3098 d3d11_device_context_CSSetConstantBuffers1,
3099 d3d11_device_context_VSGetConstantBuffers1,
3100 d3d11_device_context_HSGetConstantBuffers1,
3101 d3d11_device_context_DSGetConstantBuffers1,
3102 d3d11_device_context_GSGetConstantBuffers1,
3103 d3d11_device_context_PSGetConstantBuffers1,
3104 d3d11_device_context_CSGetConstantBuffers1,
3105 d3d11_device_context_SwapDeviceContextState,
3106 d3d11_device_context_ClearView,
3107 d3d11_device_context_DiscardView1,
3110 /* ID3D11Multithread methods */
3112 static inline struct d3d11_device_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3114 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3D11Multithread_iface);
3117 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3118 REFIID iid, void **out)
3120 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3122 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3124 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3127 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3129 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3131 TRACE("iface %p.\n", iface);
3133 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3136 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3138 struct d3d11_device_context *context = impl_from_ID3D11Multithread(iface);
3140 TRACE("iface %p.\n", iface);
3142 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3145 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3147 TRACE("iface %p.\n", iface);
3149 wined3d_mutex_lock();
3152 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3154 TRACE("iface %p.\n", iface);
3156 wined3d_mutex_unlock();
3159 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3160 ID3D11Multithread *iface, BOOL enable)
3162 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3164 return TRUE;
3167 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3169 FIXME("iface %p stub!\n", iface);
3171 return TRUE;
3174 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3176 d3d11_multithread_QueryInterface,
3177 d3d11_multithread_AddRef,
3178 d3d11_multithread_Release,
3179 d3d11_multithread_Enter,
3180 d3d11_multithread_Leave,
3181 d3d11_multithread_SetMultithreadProtected,
3182 d3d11_multithread_GetMultithreadProtected,
3185 /* ID3DUserDefinedAnnotation methods */
3187 static inline struct d3d11_device_context *impl_from_ID3DUserDefinedAnnotation(ID3DUserDefinedAnnotation *iface)
3189 return CONTAINING_RECORD(iface, struct d3d11_device_context, ID3DUserDefinedAnnotation_iface);
3192 static HRESULT STDMETHODCALLTYPE d3d11_user_defined_annotation_QueryInterface(ID3DUserDefinedAnnotation *iface,
3193 REFIID iid, void **out)
3195 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3197 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3199 return d3d11_device_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3202 static ULONG STDMETHODCALLTYPE d3d11_user_defined_annotation_AddRef(ID3DUserDefinedAnnotation *iface)
3204 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3206 TRACE("iface %p.\n", iface);
3208 return d3d11_device_context_AddRef(&context->ID3D11DeviceContext1_iface);
3211 static ULONG STDMETHODCALLTYPE d3d11_user_defined_annotation_Release(ID3DUserDefinedAnnotation *iface)
3213 struct d3d11_device_context *context = impl_from_ID3DUserDefinedAnnotation(iface);
3215 TRACE("iface %p.\n", iface);
3217 return d3d11_device_context_Release(&context->ID3D11DeviceContext1_iface);
3220 static int STDMETHODCALLTYPE d3d11_user_defined_annotation_BeginEvent(ID3DUserDefinedAnnotation *iface,
3221 const WCHAR *name)
3223 TRACE("iface %p, name %s.\n", iface, debugstr_w(name));
3225 return -1;
3228 static int STDMETHODCALLTYPE d3d11_user_defined_annotation_EndEvent(ID3DUserDefinedAnnotation *iface)
3230 TRACE("iface %p.\n", iface);
3232 return -1;
3235 static void STDMETHODCALLTYPE d3d11_user_defined_annotation_SetMarker(ID3DUserDefinedAnnotation *iface,
3236 const WCHAR *name)
3238 TRACE("iface %p, name %s.\n", iface, debugstr_w(name));
3241 static BOOL STDMETHODCALLTYPE d3d11_user_defined_annotation_GetStatus(ID3DUserDefinedAnnotation *iface)
3243 TRACE("iface %p.\n", iface);
3245 return FALSE;
3248 static const struct ID3DUserDefinedAnnotationVtbl d3d11_user_defined_annotation_vtbl =
3250 d3d11_user_defined_annotation_QueryInterface,
3251 d3d11_user_defined_annotation_AddRef,
3252 d3d11_user_defined_annotation_Release,
3253 d3d11_user_defined_annotation_BeginEvent,
3254 d3d11_user_defined_annotation_EndEvent,
3255 d3d11_user_defined_annotation_SetMarker,
3256 d3d11_user_defined_annotation_GetStatus,
3259 static void d3d11_device_context_init(struct d3d11_device_context *context, struct d3d_device *device,
3260 D3D11_DEVICE_CONTEXT_TYPE type)
3262 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_device_context_vtbl;
3263 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3264 context->ID3DUserDefinedAnnotation_iface.lpVtbl = &d3d11_user_defined_annotation_vtbl;
3265 context->refcount = 1;
3266 context->type = type;
3268 context->device = device;
3269 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3271 wined3d_private_store_init(&context->private_store);
3274 /* ID3D11Device methods */
3276 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3278 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3279 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3282 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3284 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3285 return IUnknown_AddRef(device->outer_unk);
3288 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3290 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3291 return IUnknown_Release(device->outer_unk);
3294 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3295 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3297 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3298 struct d3d_buffer *object;
3299 HRESULT hr;
3301 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3303 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3304 return hr;
3306 *buffer = &object->ID3D11Buffer_iface;
3308 return S_OK;
3311 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3312 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3314 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3315 struct d3d_texture1d *object;
3316 HRESULT hr;
3318 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3320 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3321 return hr;
3323 *texture = &object->ID3D11Texture1D_iface;
3325 return S_OK;
3328 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3329 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3331 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3332 struct d3d_texture2d *object;
3333 HRESULT hr;
3335 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3337 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3338 return hr;
3340 *texture = &object->ID3D11Texture2D_iface;
3342 return S_OK;
3345 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3346 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3348 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3349 struct d3d_texture3d *object;
3350 HRESULT hr;
3352 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3354 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3355 return hr;
3357 *texture = &object->ID3D11Texture3D_iface;
3359 return S_OK;
3362 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3363 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3365 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3366 struct d3d_shader_resource_view *object;
3367 HRESULT hr;
3369 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3371 *view = NULL;
3373 if (!resource)
3374 return E_INVALIDARG;
3376 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3377 return hr;
3379 *view = &object->ID3D11ShaderResourceView_iface;
3381 return S_OK;
3384 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3385 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3387 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3388 struct d3d11_unordered_access_view *object;
3389 HRESULT hr;
3391 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3393 *view = NULL;
3395 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3396 return hr;
3398 *view = &object->ID3D11UnorderedAccessView_iface;
3400 return S_OK;
3403 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3404 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3406 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3407 struct d3d_rendertarget_view *object;
3408 HRESULT hr;
3410 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3412 *view = NULL;
3414 if (!resource)
3415 return E_INVALIDARG;
3417 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3418 return hr;
3420 *view = &object->ID3D11RenderTargetView_iface;
3422 return S_OK;
3425 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3426 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3428 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3429 struct d3d_depthstencil_view *object;
3430 HRESULT hr;
3432 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3434 *view = NULL;
3436 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3437 return hr;
3439 *view = &object->ID3D11DepthStencilView_iface;
3441 return S_OK;
3444 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3445 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3446 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3448 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3449 struct d3d_input_layout *object;
3450 HRESULT hr;
3452 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %Iu, "
3453 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3454 shader_byte_code_length, input_layout);
3456 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3457 shader_byte_code, shader_byte_code_length, &object)))
3458 return hr;
3460 *input_layout = &object->ID3D11InputLayout_iface;
3462 return S_OK;
3465 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3466 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3468 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3469 struct d3d_vertex_shader *object;
3470 HRESULT hr;
3472 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3473 iface, byte_code, byte_code_length, class_linkage, shader);
3475 *shader = NULL;
3477 if (class_linkage)
3478 FIXME("Class linkage is not implemented yet.\n");
3480 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3481 return hr;
3483 *shader = &object->ID3D11VertexShader_iface;
3485 return S_OK;
3488 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3489 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3491 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3492 struct d3d_geometry_shader *object;
3493 HRESULT hr;
3495 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3496 iface, byte_code, byte_code_length, class_linkage, shader);
3498 *shader = NULL;
3500 if (class_linkage)
3501 FIXME("Class linkage is not implemented yet.\n");
3503 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3504 NULL, 0, NULL, 0, 0, &object)))
3505 return hr;
3507 *shader = &object->ID3D11GeometryShader_iface;
3509 return S_OK;
3512 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3513 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3514 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3515 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3517 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3518 struct d3d_geometry_shader *object;
3519 HRESULT hr;
3521 TRACE("iface %p, byte_code %p, byte_code_length %Iu, so_entries %p, entry_count %u, "
3522 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3523 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3524 rasterizer_stream, class_linkage, shader);
3526 *shader = NULL;
3528 if (class_linkage)
3529 FIXME("Class linkage is not implemented yet.\n");
3531 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3532 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3534 return hr;
3537 *shader = &object->ID3D11GeometryShader_iface;
3539 return hr;
3542 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3543 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3545 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3546 struct d3d_pixel_shader *object;
3547 HRESULT hr;
3549 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3550 iface, byte_code, byte_code_length, class_linkage, shader);
3552 *shader = NULL;
3554 if (class_linkage)
3555 FIXME("Class linkage is not implemented yet.\n");
3557 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3558 return hr;
3560 *shader = &object->ID3D11PixelShader_iface;
3562 return S_OK;
3565 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3566 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3568 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3569 struct d3d11_hull_shader *object;
3570 HRESULT hr;
3572 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3573 iface, byte_code, byte_code_length, class_linkage, shader);
3575 *shader = NULL;
3577 if (class_linkage)
3578 FIXME("Class linkage is not implemented yet.\n");
3580 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3581 return hr;
3583 *shader = &object->ID3D11HullShader_iface;
3585 return S_OK;
3588 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3589 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3591 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3592 struct d3d11_domain_shader *object;
3593 HRESULT hr;
3595 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3596 iface, byte_code, byte_code_length, class_linkage, shader);
3598 *shader = NULL;
3600 if (class_linkage)
3601 FIXME("Class linkage is not implemented yet.\n");
3603 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3604 return hr;
3606 *shader = &object->ID3D11DomainShader_iface;
3608 return S_OK;
3611 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3612 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3614 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3615 struct d3d11_compute_shader *object;
3616 HRESULT hr;
3618 TRACE("iface %p, byte_code %p, byte_code_length %Iu, class_linkage %p, shader %p.\n",
3619 iface, byte_code, byte_code_length, class_linkage, shader);
3621 *shader = NULL;
3623 if (class_linkage)
3624 FIXME("Class linkage is not implemented yet.\n");
3626 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3627 return hr;
3629 *shader = &object->ID3D11ComputeShader_iface;
3631 return S_OK;
3634 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3635 ID3D11ClassLinkage **class_linkage)
3637 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3638 struct d3d11_class_linkage *object;
3639 HRESULT hr;
3641 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3643 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3644 return hr;
3646 *class_linkage = &object->ID3D11ClassLinkage_iface;
3648 return S_OK;
3651 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
3652 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
3654 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3655 struct d3d_blend_state *object;
3656 HRESULT hr;
3658 TRACE("iface %p, desc %p, state %p.\n", iface, desc, state);
3660 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3661 return hr;
3663 *state = &object->ID3D11BlendState1_iface;
3665 return S_OK;
3668 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3669 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3671 D3D11_BLEND_DESC1 d3d11_1_desc;
3672 unsigned int i;
3674 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3676 if (!desc)
3677 return E_INVALIDARG;
3679 d3d11_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
3680 d3d11_1_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
3681 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3683 d3d11_1_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[i].BlendEnable;
3684 d3d11_1_desc.RenderTarget[i].LogicOpEnable = FALSE;
3685 d3d11_1_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[i].SrcBlend;
3686 d3d11_1_desc.RenderTarget[i].DestBlend = desc->RenderTarget[i].DestBlend;
3687 d3d11_1_desc.RenderTarget[i].BlendOp = desc->RenderTarget[i].BlendOp;
3688 d3d11_1_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[i].SrcBlendAlpha;
3689 d3d11_1_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[i].DestBlendAlpha;
3690 d3d11_1_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[i].BlendOpAlpha;
3691 d3d11_1_desc.RenderTarget[i].LogicOp = D3D11_LOGIC_OP_COPY;
3692 d3d11_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[i].RenderTargetWriteMask;
3695 return d3d11_device_CreateBlendState1(iface, &d3d11_1_desc, (ID3D11BlendState1 **)blend_state);
3698 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3699 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3701 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3702 struct d3d_depthstencil_state *object;
3703 HRESULT hr;
3705 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3707 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3708 return hr;
3710 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3712 return S_OK;
3715 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3716 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3718 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3719 struct d3d_rasterizer_state *object;
3720 D3D11_RASTERIZER_DESC1 desc1;
3721 HRESULT hr;
3723 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3725 if (!desc)
3726 return E_INVALIDARG;
3728 memcpy(&desc1, desc, sizeof(*desc));
3729 desc1.ForcedSampleCount = 0;
3731 if (FAILED(hr = d3d_rasterizer_state_create(device, &desc1, &object)))
3732 return hr;
3734 *rasterizer_state = (ID3D11RasterizerState *)&object->ID3D11RasterizerState1_iface;
3736 return S_OK;
3739 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3740 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3742 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3743 struct d3d_sampler_state *object;
3744 HRESULT hr;
3746 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3748 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3749 return hr;
3751 *sampler_state = &object->ID3D11SamplerState_iface;
3753 return S_OK;
3756 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3757 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3759 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3760 struct d3d_query *object;
3761 HRESULT hr;
3763 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3765 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3766 return hr;
3768 if (query)
3770 *query = &object->ID3D11Query_iface;
3771 return S_OK;
3774 ID3D11Query_Release(&object->ID3D11Query_iface);
3775 return S_FALSE;
3778 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3779 ID3D11Predicate **predicate)
3781 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3782 struct d3d_query *object;
3783 HRESULT hr;
3785 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3787 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3788 return hr;
3790 if (predicate)
3792 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3793 return S_OK;
3796 ID3D11Query_Release(&object->ID3D11Query_iface);
3797 return S_FALSE;
3800 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3801 ID3D11Counter **counter)
3803 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3805 return E_NOTIMPL;
3808 static HRESULT d3d11_deferred_context_create(struct d3d_device *device,
3809 UINT flags, struct d3d11_device_context **context)
3811 struct d3d11_device_context *object;
3812 HRESULT hr;
3814 if (flags)
3815 FIXME("Ignoring flags %#x.\n", flags);
3817 if (!(object = calloc(1, sizeof(*object))))
3818 return E_OUTOFMEMORY;
3819 d3d11_device_context_init(object, device, D3D11_DEVICE_CONTEXT_DEFERRED);
3821 if (FAILED(hr = wined3d_deferred_context_create(device->wined3d_device, &object->wined3d_context)))
3823 WARN("Failed to create wined3d deferred context, hr %#lx.\n", hr);
3824 free(object);
3825 return hr;
3828 TRACE("Created deferred context %p.\n", object);
3829 *context = object;
3831 return S_OK;
3834 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3835 ID3D11DeviceContext **context)
3837 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3838 struct d3d11_device_context *object;
3839 HRESULT hr;
3841 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
3843 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
3844 return hr;
3846 *context = (ID3D11DeviceContext *)&object->ID3D11DeviceContext1_iface;
3847 return S_OK;
3850 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3851 void **out)
3853 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3855 return E_NOTIMPL;
3858 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3859 UINT *format_support)
3861 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3862 struct wined3d_device_creation_parameters params;
3863 struct wined3d_adapter *wined3d_adapter;
3864 enum wined3d_format_id wined3d_format;
3865 D3D_FEATURE_LEVEL feature_level;
3866 struct wined3d *wined3d;
3867 unsigned int i;
3869 static const struct
3871 enum wined3d_resource_type rtype;
3872 unsigned int bind_flags;
3873 unsigned int usage;
3874 D3D11_FORMAT_SUPPORT flag;
3876 flag_mapping[] =
3878 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3879 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_VERTEX_BUFFER, 0, D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER},
3880 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_INDEX_BUFFER, 0, D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER},
3881 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3882 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3883 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3884 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3885 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3886 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3887 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3888 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3889 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3891 HRESULT hr;
3893 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3895 wined3d_format = wined3dformat_from_dxgi_format(format);
3896 if (format && !wined3d_format)
3898 WARN("Invalid format %#x.\n", format);
3899 *format_support = 0;
3900 return E_FAIL;
3903 *format_support = 0;
3905 wined3d_mutex_lock();
3906 feature_level = device->state->feature_level;
3907 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3908 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3909 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3910 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3912 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3913 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3914 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3915 continue;
3916 if (hr != WINED3D_OK)
3918 WARN("Failed to check device format support, hr %#lx.\n", hr);
3919 wined3d_mutex_unlock();
3920 return E_FAIL;
3923 *format_support |= flag_mapping[i].flag;
3925 wined3d_mutex_unlock();
3927 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3928 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3930 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3931 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3933 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3934 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3935 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3937 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3938 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3940 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3942 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3943 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3945 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3946 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3950 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3951 * support multisample. */
3952 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3953 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3954 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3955 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3957 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3958 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3959 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3962 return *format_support ? S_OK : E_FAIL;
3965 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3966 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3968 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3969 struct wined3d_device_creation_parameters params;
3970 struct wined3d_adapter *wined3d_adapter;
3971 struct wined3d *wined3d;
3972 HRESULT hr;
3974 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3975 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3977 if (!quality_level_count)
3978 return E_INVALIDARG;
3980 *quality_level_count = 0;
3982 if (!sample_count)
3983 return E_FAIL;
3984 if (sample_count == 1)
3986 *quality_level_count = 1;
3987 return S_OK;
3989 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3990 return E_FAIL;
3992 wined3d_mutex_lock();
3993 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3994 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3995 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3996 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3997 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3998 wined3d_mutex_unlock();
4000 if (hr == WINED3DERR_INVALIDCALL)
4001 return E_INVALIDARG;
4002 if (hr == WINED3DERR_NOTAVAILABLE)
4003 return S_OK;
4004 return hr;
4007 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
4009 FIXME("iface %p, info %p stub!\n", iface, info);
4012 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
4013 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
4014 char *units, UINT *units_length, char *description, UINT *description_length)
4016 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
4017 "units %p, units_length %p, description %p, description_length %p stub!\n",
4018 iface, desc, type, active_counter_count, name, name_length,
4019 units, units_length, description, description_length);
4021 return E_NOTIMPL;
4024 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
4025 void *feature_support_data, UINT feature_support_data_size)
4027 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4028 struct wined3d_caps wined3d_caps;
4029 HRESULT hr;
4031 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
4032 iface, feature, feature_support_data, feature_support_data_size);
4034 switch (feature)
4036 case D3D11_FEATURE_THREADING:
4038 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
4039 if (feature_support_data_size != sizeof(*threading_data))
4041 WARN("Invalid data size.\n");
4042 return E_INVALIDARG;
4045 /* We lie about the threading support to make Tomb Raider 2013 and
4046 * Deus Ex: Human Revolution happy. */
4047 FIXME("Returning fake threading support data.\n");
4048 threading_data->DriverConcurrentCreates = TRUE;
4049 threading_data->DriverCommandLists = TRUE;
4050 return S_OK;
4053 case D3D11_FEATURE_DOUBLES:
4055 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
4056 if (feature_support_data_size != sizeof(*doubles_data))
4058 WARN("Invalid data size.\n");
4059 return E_INVALIDARG;
4062 wined3d_mutex_lock();
4063 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4064 wined3d_mutex_unlock();
4065 if (FAILED(hr))
4067 WARN("Failed to get device caps, hr %#lx.\n", hr);
4068 return hr;
4071 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
4072 return S_OK;
4075 case D3D11_FEATURE_D3D9_OPTIONS:
4077 D3D11_FEATURE_DATA_D3D9_OPTIONS *options = feature_support_data;
4078 if (feature_support_data_size != sizeof(*options))
4080 WARN("Invalid data size.\n");
4081 return E_INVALIDARG;
4084 wined3d_mutex_lock();
4085 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4086 wined3d_mutex_unlock();
4087 if (FAILED(hr))
4089 WARN("Failed to get device caps, hr %#lx.\n", hr);
4090 return hr;
4093 options->FullNonPow2TextureSupport = !(wined3d_caps.TextureCaps & WINED3DPTEXTURECAPS_POW2);
4094 return S_OK;
4097 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
4099 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
4100 if (feature_support_data_size != sizeof(*options))
4102 WARN("Invalid data size.\n");
4103 return E_INVALIDARG;
4106 wined3d_mutex_lock();
4107 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4108 wined3d_mutex_unlock();
4109 if (FAILED(hr))
4111 WARN("Failed to get device caps, hr %#lx.\n", hr);
4112 return hr;
4115 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
4116 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
4117 return S_OK;
4120 case D3D11_FEATURE_D3D11_OPTIONS:
4122 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
4123 if (feature_support_data_size != sizeof(*options))
4125 WARN("Invalid data size.\n");
4126 return E_INVALIDARG;
4129 FIXME("Returning fake Options support data.\n");
4130 options->OutputMergerLogicOp = FALSE;
4131 options->UAVOnlyRenderingForcedSampleCount = FALSE;
4132 options->DiscardAPIsSeenByDriver = FALSE;
4133 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
4134 options->ClearView = FALSE;
4135 options->CopyWithOverlap = FALSE;
4136 options->ConstantBufferPartialUpdate = TRUE;
4137 options->ConstantBufferOffsetting = TRUE;
4138 options->MapNoOverwriteOnDynamicConstantBuffer = TRUE;
4139 options->MapNoOverwriteOnDynamicBufferSRV = TRUE;
4140 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
4141 options->SAD4ShaderInstructions = FALSE;
4142 options->ExtendedDoublesShaderInstructions = FALSE;
4143 options->ExtendedResourceSharing = FALSE;
4144 return S_OK;
4147 case D3D11_FEATURE_D3D11_OPTIONS1:
4149 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
4150 if (feature_support_data_size != sizeof(*options))
4152 WARN("Invalid data size.\n");
4153 return E_INVALIDARG;
4156 FIXME("Returning fake Options1 support data.\n");
4157 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
4158 options->MinMaxFiltering = FALSE;
4159 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
4160 options->MapOnDefaultBuffers = FALSE;
4161 return S_OK;
4164 case D3D11_FEATURE_D3D11_OPTIONS3:
4166 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
4167 if (feature_support_data_size != sizeof(*options))
4169 WARN("Invalid data size.\n");
4170 return E_INVALIDARG;
4173 wined3d_mutex_lock();
4174 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
4175 wined3d_mutex_unlock();
4176 if (FAILED(hr))
4178 WARN("Failed to get device caps, hr %#lx.\n", hr);
4179 return hr;
4182 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
4183 = wined3d_caps.viewport_array_index_any_shader;
4184 return S_OK;
4187 case D3D11_FEATURE_ARCHITECTURE_INFO:
4189 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
4190 if (feature_support_data_size != sizeof(*options))
4192 WARN("Invalid data size.\n");
4193 return E_INVALIDARG;
4196 FIXME("Returning fake data architecture info.\n");
4197 options->TileBasedDeferredRenderer = FALSE;
4198 return S_OK;
4201 case D3D11_FEATURE_FORMAT_SUPPORT:
4203 D3D11_FEATURE_DATA_FORMAT_SUPPORT *data = feature_support_data;
4204 if (feature_support_data_size != sizeof(*data))
4206 WARN("Invalid size %u for D3D11_FEATURE_FORMAT_SUPPORT.\n", feature_support_data_size);
4207 return E_INVALIDARG;
4210 return d3d11_device_CheckFormatSupport(iface, data->InFormat, &data->OutFormatSupport);
4213 default:
4214 FIXME("Unhandled feature %#x.\n", feature);
4215 return E_NOTIMPL;
4219 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4220 UINT *data_size, void *data)
4222 IDXGIDevice *dxgi_device;
4223 HRESULT hr;
4225 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4227 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4228 return hr;
4229 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
4230 IDXGIDevice_Release(dxgi_device);
4232 return hr;
4235 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
4236 UINT data_size, const void *data)
4238 IDXGIDevice *dxgi_device;
4239 HRESULT hr;
4241 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4243 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4244 return hr;
4245 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
4246 IDXGIDevice_Release(dxgi_device);
4248 return hr;
4251 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
4252 const IUnknown *data)
4254 IDXGIDevice *dxgi_device;
4255 HRESULT hr;
4257 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4259 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
4260 return hr;
4261 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
4262 IDXGIDevice_Release(dxgi_device);
4264 return hr;
4267 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
4269 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4271 TRACE("iface %p.\n", iface);
4273 return device->state->feature_level;
4276 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
4278 FIXME("iface %p stub!\n", iface);
4280 return 0;
4283 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
4285 WARN("iface %p stub!\n", iface);
4287 return S_OK;
4290 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
4291 ID3D11DeviceContext **immediate_context)
4293 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4295 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4297 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4298 ID3D11DeviceContext_AddRef(*immediate_context);
4301 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4303 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4305 return E_NOTIMPL;
4308 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4310 FIXME("iface %p stub!\n", iface);
4312 return 0;
4315 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4316 ID3D11DeviceContext1 **immediate_context)
4318 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4320 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4322 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4323 ID3D11DeviceContext1_AddRef(*immediate_context);
4326 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4327 ID3D11DeviceContext1 **context)
4329 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4330 struct d3d11_device_context *object;
4331 HRESULT hr;
4333 TRACE("iface %p, flags %#x, context %p.\n", iface, flags, context);
4335 if (FAILED(hr = d3d11_deferred_context_create(device, flags, &object)))
4336 return hr;
4338 *context = &object->ID3D11DeviceContext1_iface;
4339 return S_OK;
4342 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4343 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4345 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4346 struct d3d_rasterizer_state *object;
4347 HRESULT hr;
4349 TRACE("iface %p, desc %p, state %p.\n", iface, desc, state);
4351 if (!desc)
4352 return E_INVALIDARG;
4354 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
4355 return hr;
4357 *state = &object->ID3D11RasterizerState1_iface;
4359 return S_OK;
4362 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4363 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4364 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4366 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4367 struct d3d_device_context_state *state_impl;
4368 struct wined3d_state *wined3d_state;
4369 D3D_FEATURE_LEVEL feature_level;
4370 HRESULT hr = E_INVALIDARG;
4372 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4373 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4374 iface, flags, feature_levels, feature_level_count,
4375 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4377 if (flags)
4378 FIXME("Ignoring flags %#x.\n", flags);
4380 wined3d_mutex_lock();
4382 if (!feature_level_count)
4383 goto fail;
4385 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4386 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4387 goto fail;
4388 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4390 if (chosen_feature_level)
4391 *chosen_feature_level = feature_level;
4393 if (!state)
4395 wined3d_state_destroy(wined3d_state);
4396 wined3d_mutex_unlock();
4397 return S_FALSE;
4400 if (!(state_impl = calloc(1, sizeof(*state_impl))))
4402 wined3d_state_destroy(wined3d_state);
4403 hr = E_OUTOFMEMORY;
4404 goto fail;
4407 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4408 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4410 wined3d_state_destroy(wined3d_state);
4411 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4412 hr = E_FAIL;
4413 goto fail;
4416 *state = &state_impl->ID3DDeviceContextState_iface;
4417 device->d3d11_only = FALSE;
4418 wined3d_mutex_unlock();
4420 return S_OK;
4422 fail:
4423 wined3d_mutex_unlock();
4424 if (chosen_feature_level)
4425 *chosen_feature_level = 0;
4426 if (state)
4427 *state = NULL;
4428 return hr;
4431 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4432 REFIID iid, void **resource)
4434 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4436 return E_NOTIMPL;
4439 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4440 DWORD access, REFIID iid, void **resource)
4442 FIXME("iface %p, name %s, access %#lx, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4443 debugstr_guid(iid), resource);
4445 return E_NOTIMPL;
4448 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4449 ID3D11DeviceContext2 **context)
4451 FIXME("iface %p, context %p stub!\n", iface, context);
4454 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4455 UINT flags, ID3D11DeviceContext2 **context)
4457 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4459 return E_NOTIMPL;
4462 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4463 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4464 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4465 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4467 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4468 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4469 iface, resource, tile_count, mip_desc, tile_shape,
4470 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4473 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4474 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4476 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4477 iface, format, sample_count, flags, quality_level_count);
4479 return E_NOTIMPL;
4482 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4484 /* IUnknown methods */
4485 d3d11_device_QueryInterface,
4486 d3d11_device_AddRef,
4487 d3d11_device_Release,
4488 /* ID3D11Device methods */
4489 d3d11_device_CreateBuffer,
4490 d3d11_device_CreateTexture1D,
4491 d3d11_device_CreateTexture2D,
4492 d3d11_device_CreateTexture3D,
4493 d3d11_device_CreateShaderResourceView,
4494 d3d11_device_CreateUnorderedAccessView,
4495 d3d11_device_CreateRenderTargetView,
4496 d3d11_device_CreateDepthStencilView,
4497 d3d11_device_CreateInputLayout,
4498 d3d11_device_CreateVertexShader,
4499 d3d11_device_CreateGeometryShader,
4500 d3d11_device_CreateGeometryShaderWithStreamOutput,
4501 d3d11_device_CreatePixelShader,
4502 d3d11_device_CreateHullShader,
4503 d3d11_device_CreateDomainShader,
4504 d3d11_device_CreateComputeShader,
4505 d3d11_device_CreateClassLinkage,
4506 d3d11_device_CreateBlendState,
4507 d3d11_device_CreateDepthStencilState,
4508 d3d11_device_CreateRasterizerState,
4509 d3d11_device_CreateSamplerState,
4510 d3d11_device_CreateQuery,
4511 d3d11_device_CreatePredicate,
4512 d3d11_device_CreateCounter,
4513 d3d11_device_CreateDeferredContext,
4514 d3d11_device_OpenSharedResource,
4515 d3d11_device_CheckFormatSupport,
4516 d3d11_device_CheckMultisampleQualityLevels,
4517 d3d11_device_CheckCounterInfo,
4518 d3d11_device_CheckCounter,
4519 d3d11_device_CheckFeatureSupport,
4520 d3d11_device_GetPrivateData,
4521 d3d11_device_SetPrivateData,
4522 d3d11_device_SetPrivateDataInterface,
4523 d3d11_device_GetFeatureLevel,
4524 d3d11_device_GetCreationFlags,
4525 d3d11_device_GetDeviceRemovedReason,
4526 d3d11_device_GetImmediateContext,
4527 d3d11_device_SetExceptionMode,
4528 d3d11_device_GetExceptionMode,
4529 /* ID3D11Device1 methods */
4530 d3d11_device_GetImmediateContext1,
4531 d3d11_device_CreateDeferredContext1,
4532 d3d11_device_CreateBlendState1,
4533 d3d11_device_CreateRasterizerState1,
4534 d3d11_device_CreateDeviceContextState,
4535 d3d11_device_OpenSharedResource1,
4536 d3d11_device_OpenSharedResourceByName,
4537 /* ID3D11Device2 methods */
4538 d3d11_device_GetImmediateContext2,
4539 d3d11_device_CreateDeferredContext2,
4540 d3d11_device_GetResourceTiling,
4541 d3d11_device_CheckMultisampleQualityLevels1,
4544 /* Inner IUnknown methods */
4546 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4548 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4551 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4553 struct d3d_device *device = impl_from_IUnknown(iface);
4555 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4557 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4558 || IsEqualGUID(riid, &IID_ID3D11Device1)
4559 || IsEqualGUID(riid, &IID_ID3D11Device)
4560 || IsEqualGUID(riid, &IID_IUnknown))
4562 *out = &device->ID3D11Device2_iface;
4564 else if (!device->d3d11_only
4565 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4566 || IsEqualGUID(riid, &IID_ID3D10Device)))
4568 *out = &device->ID3D10Device1_iface;
4570 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4572 *out = &device->ID3D10Multithread_iface;
4574 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4576 *out = &device->IWineDXGIDeviceParent_iface;
4578 else
4580 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4581 *out = NULL;
4582 return E_NOINTERFACE;
4585 IUnknown_AddRef((IUnknown *)*out);
4586 return S_OK;
4589 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4591 struct d3d_device *device = impl_from_IUnknown(iface);
4592 ULONG refcount = InterlockedIncrement(&device->refcount);
4594 TRACE("%p increasing refcount to %lu.\n", device, refcount);
4596 return refcount;
4599 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4601 struct d3d_device *device = impl_from_IUnknown(iface);
4602 ULONG refcount = InterlockedDecrement(&device->refcount);
4603 unsigned int i;
4605 TRACE("%p decreasing refcount to %lu.\n", device, refcount);
4607 if (!refcount)
4609 if (device->state)
4610 d3d_device_context_state_private_release(device->state);
4611 for (i = 0; i < device->context_state_count; ++i)
4613 d3d_device_context_state_remove_entry(device->context_states[i], device);
4615 free(device->context_states);
4616 d3d11_device_context_cleanup(&device->immediate_context);
4617 if (device->wined3d_device)
4619 wined3d_device_decref(device->wined3d_device);
4621 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4622 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4623 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4624 wine_rb_destroy(&device->blend_states, NULL, NULL);
4627 return refcount;
4630 /* IUnknown methods */
4632 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4633 void **out)
4635 struct d3d_device *device = impl_from_ID3D10Device(iface);
4636 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4639 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4641 struct d3d_device *device = impl_from_ID3D10Device(iface);
4642 return IUnknown_AddRef(device->outer_unk);
4645 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4647 struct d3d_device *device = impl_from_ID3D10Device(iface);
4648 return IUnknown_Release(device->outer_unk);
4651 /* ID3D10Device methods */
4653 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4654 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4656 struct d3d_device *device = impl_from_ID3D10Device(iface);
4657 unsigned int i;
4659 wined3d_mutex_lock();
4660 for (i = 0; i < buffer_count; ++i)
4662 struct wined3d_constant_buffer_state state;
4663 struct d3d_buffer *buffer_impl;
4665 wined3d_device_context_get_constant_buffer(device->immediate_context.wined3d_context,
4666 type, start_slot + i, &state);
4668 if (!state.buffer)
4670 buffers[i] = NULL;
4671 continue;
4674 buffer_impl = wined3d_buffer_get_parent(state.buffer);
4675 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4676 ID3D10Buffer_AddRef(buffers[i]);
4678 wined3d_mutex_unlock();
4681 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4682 unsigned int start_slot, unsigned int buffer_count, ID3D10Buffer *const *buffers)
4684 struct wined3d_constant_buffer_state wined3d_buffers[D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
4685 struct d3d_device *device = impl_from_ID3D10Device(iface);
4686 unsigned int i;
4688 if (buffer_count > ARRAY_SIZE(wined3d_buffers))
4690 WARN("Buffer count %u exceeds limit; ignoring call.\n", buffer_count);
4691 return;
4694 for (i = 0; i < buffer_count; ++i)
4696 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4698 wined3d_buffers[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4699 wined3d_buffers[i].offset = 0;
4700 wined3d_buffers[i].size = WINED3D_MAX_CONSTANT_BUFFER_SIZE * sizeof(struct wined3d_vec4);
4703 wined3d_device_context_set_constant_buffers(device->immediate_context.wined3d_context,
4704 type, start_slot, buffer_count, wined3d_buffers);
4707 static void d3d10_device_set_shader_resource_views(ID3D10Device1 *iface, enum wined3d_shader_type type,
4708 unsigned int start_slot, unsigned int count, ID3D10ShaderResourceView *const *views)
4710 struct wined3d_shader_resource_view *wined3d_views[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
4711 struct d3d_device *device = impl_from_ID3D10Device(iface);
4712 unsigned int i;
4714 if (count > ARRAY_SIZE(wined3d_views))
4716 WARN("View count %u exceeds limit; ignoring call.\n", count);
4717 return;
4720 for (i = 0; i < count; ++i)
4722 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4724 wined3d_views[i] = view ? view->wined3d_view : NULL;
4727 wined3d_device_context_set_shader_resource_views(device->immediate_context.wined3d_context,
4728 type, start_slot, count, wined3d_views);
4731 static void d3d10_device_set_samplers(ID3D10Device1 *iface, enum wined3d_shader_type type,
4732 unsigned int start_slot, unsigned int count, ID3D10SamplerState *const *samplers)
4734 struct wined3d_sampler *wined3d_samplers[D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT];
4735 struct d3d_device *device = impl_from_ID3D10Device(iface);
4736 unsigned int i;
4738 if (count > ARRAY_SIZE(wined3d_samplers))
4740 WARN("Sampler count %u exceeds limit; ignoring call.\n", count);
4741 return;
4744 for (i = 0; i < count; ++i)
4746 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4748 wined3d_samplers[i] = sampler ? sampler->wined3d_sampler : NULL;
4751 wined3d_device_context_set_samplers(device->immediate_context.wined3d_context,
4752 type, start_slot, count, wined3d_samplers);
4755 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4756 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4758 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4759 iface, start_slot, buffer_count, buffers);
4761 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4762 buffer_count, buffers);
4765 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4766 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4768 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4769 iface, start_slot, view_count, views);
4771 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, view_count, views);
4774 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4775 ID3D10PixelShader *shader)
4777 struct d3d_device *device = impl_from_ID3D10Device(iface);
4778 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4780 TRACE("iface %p, shader %p\n", iface, shader);
4782 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4783 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4786 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4787 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4789 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4790 iface, start_slot, sampler_count, samplers);
4792 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, sampler_count, samplers);
4795 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4796 ID3D10VertexShader *shader)
4798 struct d3d_device *device = impl_from_ID3D10Device(iface);
4799 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4801 TRACE("iface %p, shader %p\n", iface, shader);
4803 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4804 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4807 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4808 UINT start_index_location, INT base_vertex_location)
4810 struct d3d_device *device = impl_from_ID3D10Device(iface);
4812 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4813 iface, index_count, start_index_location, base_vertex_location);
4815 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4816 base_vertex_location, start_index_location, index_count, 0, 0);
4819 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4820 UINT start_vertex_location)
4822 struct d3d_device *device = impl_from_ID3D10Device(iface);
4824 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4825 iface, vertex_count, start_vertex_location);
4827 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4830 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4831 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4833 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4834 iface, start_slot, buffer_count, buffers);
4836 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4837 buffer_count, buffers);
4840 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4841 ID3D10InputLayout *input_layout)
4843 struct d3d_device *device = impl_from_ID3D10Device(iface);
4844 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4846 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4848 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4849 layout ? layout->wined3d_decl : NULL);
4852 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4853 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4855 struct wined3d_stream_state streams[D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
4856 struct d3d_device *device = impl_from_ID3D10Device(iface);
4857 unsigned int i;
4859 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4860 iface, start_slot, buffer_count, buffers, strides, offsets);
4862 if (buffer_count > ARRAY_SIZE(streams))
4864 WARN("Buffer count %u exceeds limit.\n", buffer_count);
4865 buffer_count = ARRAY_SIZE(streams);
4868 for (i = 0; i < buffer_count; ++i)
4870 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4872 streams[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
4873 streams[i].offset = offsets[i];
4874 streams[i].stride = strides[i];
4875 streams[i].frequency = 1;
4876 streams[i].flags = 0;
4879 wined3d_device_context_set_stream_sources(device->immediate_context.wined3d_context,
4880 start_slot, buffer_count, streams);
4883 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4884 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4886 struct d3d_device *device = impl_from_ID3D10Device(iface);
4887 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4889 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4890 iface, buffer, debug_dxgi_format(format), offset);
4892 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4893 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4894 wined3dformat_from_dxgi_format(format), offset);
4897 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4898 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4899 INT base_vertex_location, UINT start_instance_location)
4901 struct d3d_device *device = impl_from_ID3D10Device(iface);
4903 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4904 "base_vertex_location %d, start_instance_location %u.\n",
4905 iface, instance_index_count, instance_count, start_index_location,
4906 base_vertex_location, start_instance_location);
4908 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4909 start_index_location, instance_index_count, start_instance_location, instance_count);
4912 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4913 UINT instance_vertex_count, UINT instance_count,
4914 UINT start_vertex_location, UINT start_instance_location)
4916 struct d3d_device *device = impl_from_ID3D10Device(iface);
4918 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4919 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4920 start_vertex_location, start_instance_location);
4922 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4923 instance_vertex_count, start_instance_location, instance_count);
4926 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4927 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4929 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4930 iface, start_slot, buffer_count, buffers);
4932 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4933 buffer_count, buffers);
4936 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4938 struct d3d_device *device = impl_from_ID3D10Device(iface);
4939 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4941 TRACE("iface %p, shader %p.\n", iface, shader);
4943 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4944 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4947 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4948 D3D10_PRIMITIVE_TOPOLOGY topology)
4950 struct d3d_device *device = impl_from_ID3D10Device(iface);
4952 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4954 wined3d_device_context_set_primitive_type(device->immediate_context.wined3d_context,
4955 (enum wined3d_primitive_type)topology, 0);
4958 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4959 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4961 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4962 iface, start_slot, view_count, views);
4964 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, view_count, views);
4967 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4968 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4970 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4971 iface, start_slot, sampler_count, samplers);
4973 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, sampler_count, samplers);
4976 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4978 struct d3d_device *device = impl_from_ID3D10Device(iface);
4979 struct d3d_query *query;
4981 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4983 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4984 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4985 query ? query->wined3d_query : NULL, value);
4988 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4989 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4991 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4992 iface, start_slot, view_count, views);
4994 d3d10_device_set_shader_resource_views(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, view_count, views);
4997 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4998 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
5000 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5001 iface, start_slot, sampler_count, samplers);
5003 d3d10_device_set_samplers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, sampler_count, samplers);
5006 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
5007 UINT rtv_count, ID3D10RenderTargetView *const *rtvs, ID3D10DepthStencilView *depth_stencil_view)
5009 struct wined3d_rendertarget_view *wined3d_rtvs[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
5010 struct d3d_device *device = impl_from_ID3D10Device(iface);
5011 struct d3d_depthstencil_view *dsv;
5012 unsigned int i;
5014 TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
5016 if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
5018 WARN("View count %u exceeds limit.\n", rtv_count);
5019 rtv_count = ARRAY_SIZE(wined3d_rtvs);
5022 for (i = 0; i < rtv_count; ++i)
5024 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(rtvs[i]);
5026 wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
5029 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5031 wined3d_device_context_set_render_targets_and_unordered_access_views(device->immediate_context.wined3d_context,
5032 ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, dsv ? dsv->wined3d_view : NULL, ~0u, NULL, NULL);
5035 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
5036 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
5038 struct d3d_device *device = impl_from_ID3D10Device(iface);
5039 struct d3d_blend_state *blend_state_object;
5041 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
5042 iface, blend_state, debug_float4(blend_factor), sample_mask);
5044 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
5045 d3d11_device_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5046 blend_state_object ? (ID3D11BlendState *)&blend_state_object->ID3D11BlendState1_iface : NULL,
5047 blend_factor, sample_mask);
5050 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
5051 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
5053 struct d3d_device *device = impl_from_ID3D10Device(iface);
5054 struct d3d_depthstencil_state *ds_state_object;
5056 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
5057 iface, depth_stencil_state, stencil_ref);
5059 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
5060 d3d11_device_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5061 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
5064 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
5065 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
5067 struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS] = {0};
5068 struct d3d_device *device = impl_from_ID3D10Device(iface);
5069 unsigned int count, i;
5071 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
5073 count = min(target_count, ARRAY_SIZE(outputs));
5074 for (i = 0; i < count; ++i)
5076 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
5078 outputs[i].buffer = buffer ? buffer->wined3d_buffer : NULL;
5079 outputs[i].offset = offsets ? offsets[i] : 0;
5082 wined3d_device_context_set_stream_outputs(device->immediate_context.wined3d_context, outputs);
5085 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
5087 FIXME("iface %p stub!\n", iface);
5090 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
5092 struct d3d_device *device = impl_from_ID3D10Device(iface);
5093 struct d3d_rasterizer_state *rasterizer_state_object;
5095 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5097 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
5098 d3d11_device_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
5099 rasterizer_state_object ? (ID3D11RasterizerState *)&rasterizer_state_object->ID3D11RasterizerState1_iface : NULL);
5102 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
5103 UINT viewport_count, const D3D10_VIEWPORT *viewports)
5105 struct d3d_device *device = impl_from_ID3D10Device(iface);
5106 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5107 unsigned int i;
5109 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
5111 if (viewport_count > ARRAY_SIZE(wined3d_vp))
5112 return;
5114 for (i = 0; i < viewport_count; ++i)
5116 wined3d_vp[i].x = viewports[i].TopLeftX;
5117 wined3d_vp[i].y = viewports[i].TopLeftY;
5118 wined3d_vp[i].width = viewports[i].Width;
5119 wined3d_vp[i].height = viewports[i].Height;
5120 wined3d_vp[i].min_z = viewports[i].MinDepth;
5121 wined3d_vp[i].max_z = viewports[i].MaxDepth;
5124 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
5127 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
5128 UINT rect_count, const D3D10_RECT *rects)
5130 struct d3d_device *device = impl_from_ID3D10Device(iface);
5132 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
5134 if (rect_count > WINED3D_MAX_VIEWPORTS)
5135 return;
5137 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
5140 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
5141 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
5142 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
5144 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5145 struct d3d_device *device = impl_from_ID3D10Device(iface);
5146 struct wined3d_box wined3d_src_box;
5148 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
5149 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
5150 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5151 src_resource, src_subresource_idx, src_box);
5153 if (!dst_resource || !src_resource)
5154 return;
5156 if (src_box)
5157 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
5158 src_box->right, src_box->bottom, src_box->front, src_box->back);
5160 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5161 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5162 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
5163 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
5164 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
5167 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
5168 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
5170 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5171 struct d3d_device *device = impl_from_ID3D10Device(iface);
5173 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
5175 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5176 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5177 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
5178 wined3d_dst_resource, wined3d_src_resource);
5181 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
5182 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
5183 const void *data, UINT row_pitch, UINT depth_pitch)
5185 struct d3d_device *device = impl_from_ID3D10Device(iface);
5186 ID3D11Resource *d3d11_resource;
5188 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
5189 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
5191 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
5192 d3d11_device_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
5193 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
5194 ID3D11Resource_Release(d3d11_resource);
5197 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
5198 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
5200 struct d3d_device *device = impl_from_ID3D10Device(iface);
5201 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
5202 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
5203 HRESULT hr;
5205 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
5206 iface, render_target_view, debug_float4(color_rgba));
5208 if (!view)
5209 return;
5211 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5212 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
5213 ERR("Failed to clear view, hr %#lx.\n", hr);
5216 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
5217 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
5219 struct d3d_device *device = impl_from_ID3D10Device(iface);
5220 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
5221 DWORD wined3d_flags;
5222 HRESULT hr;
5224 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
5225 iface, depth_stencil_view, flags, depth, stencil);
5227 if (!view)
5228 return;
5230 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
5232 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
5233 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
5234 ERR("Failed to clear view, hr %#lx.\n", hr);
5237 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
5238 ID3D10ShaderResourceView *view)
5240 struct d3d_device *device = impl_from_ID3D10Device(iface);
5241 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
5243 TRACE("iface %p, view %p.\n", iface, view);
5245 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
5248 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
5249 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
5250 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
5252 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
5253 struct d3d_device *device = impl_from_ID3D10Device(iface);
5254 enum wined3d_format_id wined3d_format;
5256 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
5257 "src_resource %p, src_subresource_idx %u, format %s.\n",
5258 iface, dst_resource, dst_subresource_idx,
5259 src_resource, src_subresource_idx, debug_dxgi_format(format));
5261 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
5262 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
5263 wined3d_format = wined3dformat_from_dxgi_format(format);
5264 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
5265 wined3d_dst_resource, dst_subresource_idx,
5266 wined3d_src_resource, src_subresource_idx, wined3d_format);
5269 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5270 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5272 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5273 iface, start_slot, buffer_count, buffers);
5275 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5276 buffers);
5279 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5280 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5282 struct d3d_device *device = impl_from_ID3D10Device(iface);
5283 unsigned int i;
5285 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5286 iface, start_slot, view_count, views);
5288 wined3d_mutex_lock();
5289 for (i = 0; i < view_count; ++i)
5291 struct wined3d_shader_resource_view *wined3d_view;
5292 struct d3d_shader_resource_view *view_impl;
5294 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5295 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5297 views[i] = NULL;
5298 continue;
5301 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5302 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5303 ID3D10ShaderResourceView_AddRef(views[i]);
5305 wined3d_mutex_unlock();
5308 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5310 struct d3d_device *device = impl_from_ID3D10Device(iface);
5311 struct d3d_pixel_shader *shader_impl;
5312 struct wined3d_shader *wined3d_shader;
5314 TRACE("iface %p, shader %p.\n", iface, shader);
5316 wined3d_mutex_lock();
5317 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5318 WINED3D_SHADER_TYPE_PIXEL)))
5320 wined3d_mutex_unlock();
5321 *shader = NULL;
5322 return;
5325 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5326 wined3d_mutex_unlock();
5327 *shader = &shader_impl->ID3D10PixelShader_iface;
5328 ID3D10PixelShader_AddRef(*shader);
5331 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5332 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5334 struct d3d_device *device = impl_from_ID3D10Device(iface);
5335 unsigned int i;
5337 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5338 iface, start_slot, sampler_count, samplers);
5340 wined3d_mutex_lock();
5341 for (i = 0; i < sampler_count; ++i)
5343 struct d3d_sampler_state *sampler_impl;
5344 struct wined3d_sampler *wined3d_sampler;
5346 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5347 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i)))
5349 samplers[i] = NULL;
5350 continue;
5353 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5354 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5355 ID3D10SamplerState_AddRef(samplers[i]);
5357 wined3d_mutex_unlock();
5360 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5362 struct d3d_device *device = impl_from_ID3D10Device(iface);
5363 struct d3d_vertex_shader *shader_impl;
5364 struct wined3d_shader *wined3d_shader;
5366 TRACE("iface %p, shader %p.\n", iface, shader);
5368 wined3d_mutex_lock();
5369 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5370 WINED3D_SHADER_TYPE_VERTEX)))
5372 wined3d_mutex_unlock();
5373 *shader = NULL;
5374 return;
5377 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5378 wined3d_mutex_unlock();
5379 *shader = &shader_impl->ID3D10VertexShader_iface;
5380 ID3D10VertexShader_AddRef(*shader);
5383 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5384 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5386 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5387 iface, start_slot, buffer_count, buffers);
5389 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5390 buffers);
5393 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5395 struct d3d_device *device = impl_from_ID3D10Device(iface);
5396 struct wined3d_vertex_declaration *wined3d_declaration;
5397 struct d3d_input_layout *input_layout_impl;
5399 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5401 wined3d_mutex_lock();
5402 if (!(wined3d_declaration = wined3d_device_context_get_vertex_declaration(
5403 device->immediate_context.wined3d_context)))
5405 wined3d_mutex_unlock();
5406 *input_layout = NULL;
5407 return;
5410 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5411 wined3d_mutex_unlock();
5412 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5413 ID3D10InputLayout_AddRef(*input_layout);
5416 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5417 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5419 struct d3d_device *device = impl_from_ID3D10Device(iface);
5420 unsigned int i;
5422 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5423 iface, start_slot, buffer_count, buffers, strides, offsets);
5425 wined3d_mutex_lock();
5426 for (i = 0; i < buffer_count; ++i)
5428 struct wined3d_buffer *wined3d_buffer = NULL;
5429 struct d3d_buffer *buffer_impl;
5431 if (FAILED(wined3d_device_context_get_stream_source(device->immediate_context.wined3d_context, start_slot + i,
5432 &wined3d_buffer, &offsets[i], &strides[i])))
5433 ERR("Failed to get vertex buffer.\n");
5435 if (!wined3d_buffer)
5437 buffers[i] = NULL;
5438 continue;
5441 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5442 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5443 ID3D10Buffer_AddRef(buffers[i]);
5445 wined3d_mutex_unlock();
5448 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5449 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5451 struct d3d_device *device = impl_from_ID3D10Device(iface);
5452 enum wined3d_format_id wined3d_format;
5453 struct wined3d_buffer *wined3d_buffer;
5454 struct d3d_buffer *buffer_impl;
5456 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5458 wined3d_mutex_lock();
5459 wined3d_buffer = wined3d_device_context_get_index_buffer(
5460 device->immediate_context.wined3d_context, &wined3d_format, offset);
5461 *format = dxgi_format_from_wined3dformat(wined3d_format);
5462 if (!wined3d_buffer)
5464 wined3d_mutex_unlock();
5465 *buffer = NULL;
5466 return;
5469 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5470 wined3d_mutex_unlock();
5471 *buffer = &buffer_impl->ID3D10Buffer_iface;
5472 ID3D10Buffer_AddRef(*buffer);
5475 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5476 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5478 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5479 iface, start_slot, buffer_count, buffers);
5481 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5482 buffers);
5485 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5487 struct d3d_device *device = impl_from_ID3D10Device(iface);
5488 struct d3d_geometry_shader *shader_impl;
5489 struct wined3d_shader *wined3d_shader;
5491 TRACE("iface %p, shader %p.\n", iface, shader);
5493 wined3d_mutex_lock();
5494 if (!(wined3d_shader = wined3d_device_context_get_shader(device->immediate_context.wined3d_context,
5495 WINED3D_SHADER_TYPE_GEOMETRY)))
5497 wined3d_mutex_unlock();
5498 *shader = NULL;
5499 return;
5502 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5503 wined3d_mutex_unlock();
5504 *shader = &shader_impl->ID3D10GeometryShader_iface;
5505 ID3D10GeometryShader_AddRef(*shader);
5508 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5509 D3D10_PRIMITIVE_TOPOLOGY *topology)
5511 struct d3d_device *device = impl_from_ID3D10Device(iface);
5513 TRACE("iface %p, topology %p.\n", iface, topology);
5515 wined3d_mutex_lock();
5516 wined3d_device_context_get_primitive_type(device->immediate_context.wined3d_context,
5517 (enum wined3d_primitive_type *)topology, NULL);
5518 wined3d_mutex_unlock();
5521 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5522 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5524 struct d3d_device *device = impl_from_ID3D10Device(iface);
5525 unsigned int i;
5527 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5528 iface, start_slot, view_count, views);
5530 wined3d_mutex_lock();
5531 for (i = 0; i < view_count; ++i)
5533 struct wined3d_shader_resource_view *wined3d_view;
5534 struct d3d_shader_resource_view *view_impl;
5536 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5537 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5539 views[i] = NULL;
5540 continue;
5543 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5544 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5545 ID3D10ShaderResourceView_AddRef(views[i]);
5547 wined3d_mutex_unlock();
5550 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5551 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5553 struct d3d_device *device = impl_from_ID3D10Device(iface);
5554 unsigned int i;
5556 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5557 iface, start_slot, sampler_count, samplers);
5559 wined3d_mutex_lock();
5560 for (i = 0; i < sampler_count; ++i)
5562 struct d3d_sampler_state *sampler_impl;
5563 struct wined3d_sampler *wined3d_sampler;
5565 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5566 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i)))
5568 samplers[i] = NULL;
5569 continue;
5572 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5573 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5574 ID3D10SamplerState_AddRef(samplers[i]);
5576 wined3d_mutex_unlock();
5579 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5580 ID3D10Predicate **predicate, BOOL *value)
5582 struct d3d_device *device = impl_from_ID3D10Device(iface);
5583 struct wined3d_query *wined3d_predicate;
5584 struct d3d_query *predicate_impl;
5586 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5588 wined3d_mutex_lock();
5589 if (!(wined3d_predicate = wined3d_device_context_get_predication(device->immediate_context.wined3d_context, value)))
5591 wined3d_mutex_unlock();
5592 *predicate = NULL;
5593 return;
5596 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5597 wined3d_mutex_unlock();
5598 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5599 ID3D10Predicate_AddRef(*predicate);
5602 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5603 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5605 struct d3d_device *device = impl_from_ID3D10Device(iface);
5606 unsigned int i;
5608 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5609 iface, start_slot, view_count, views);
5611 wined3d_mutex_lock();
5612 for (i = 0; i < view_count; ++i)
5614 struct wined3d_shader_resource_view *wined3d_view;
5615 struct d3d_shader_resource_view *view_impl;
5617 if (!(wined3d_view = wined3d_device_context_get_shader_resource_view(
5618 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5620 views[i] = NULL;
5621 continue;
5624 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5625 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5626 ID3D10ShaderResourceView_AddRef(views[i]);
5628 wined3d_mutex_unlock();
5631 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5632 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5634 struct d3d_device *device = impl_from_ID3D10Device(iface);
5635 unsigned int i;
5637 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5638 iface, start_slot, sampler_count, samplers);
5640 wined3d_mutex_lock();
5641 for (i = 0; i < sampler_count; ++i)
5643 struct d3d_sampler_state *sampler_impl;
5644 struct wined3d_sampler *wined3d_sampler;
5646 if (!(wined3d_sampler = wined3d_device_context_get_sampler(
5647 device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i)))
5649 samplers[i] = NULL;
5650 continue;
5653 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5654 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5655 ID3D10SamplerState_AddRef(samplers[i]);
5657 wined3d_mutex_unlock();
5660 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5661 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5663 struct d3d_device *device = impl_from_ID3D10Device(iface);
5664 struct wined3d_rendertarget_view *wined3d_view;
5666 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5667 iface, view_count, render_target_views, depth_stencil_view);
5669 wined3d_mutex_lock();
5670 if (render_target_views)
5672 struct d3d_rendertarget_view *view_impl;
5673 unsigned int i;
5675 for (i = 0; i < view_count; ++i)
5677 if (!(wined3d_view = wined3d_device_context_get_rendertarget_view(
5678 device->immediate_context.wined3d_context, i))
5679 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5681 render_target_views[i] = NULL;
5682 continue;
5685 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5686 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5690 if (depth_stencil_view)
5692 struct d3d_depthstencil_view *view_impl;
5694 if (!(wined3d_view = wined3d_device_context_get_depth_stencil_view(device->immediate_context.wined3d_context))
5695 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5697 *depth_stencil_view = NULL;
5699 else
5701 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5702 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5705 wined3d_mutex_unlock();
5708 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5709 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5711 struct d3d_device *device = impl_from_ID3D10Device(iface);
5712 ID3D11BlendState *d3d11_blend_state;
5714 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5715 iface, blend_state, blend_factor, sample_mask);
5717 d3d11_device_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5718 &d3d11_blend_state, blend_factor, sample_mask);
5720 if (blend_state)
5722 if (d3d11_blend_state)
5724 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState1(
5725 (ID3D11BlendState1 *)d3d11_blend_state)->ID3D10BlendState1_iface;
5726 ID3D10BlendState_AddRef(*blend_state);
5728 else
5729 *blend_state = NULL;
5732 if (d3d11_blend_state)
5733 ID3D11BlendState_Release(d3d11_blend_state);
5736 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5737 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5739 struct d3d_device *device = impl_from_ID3D10Device(iface);
5740 ID3D11DepthStencilState *d3d11_iface = NULL;
5742 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5743 iface, depth_stencil_state, stencil_ref);
5745 d3d11_device_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5746 &d3d11_iface, stencil_ref);
5748 if (depth_stencil_state)
5750 if (d3d11_iface)
5752 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5753 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
5755 else
5756 *depth_stencil_state = NULL;
5759 if (d3d11_iface)
5760 ID3D11DepthStencilState_Release(d3d11_iface);
5763 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5764 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5766 struct d3d_device *device = impl_from_ID3D10Device(iface);
5767 unsigned int i;
5769 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5770 iface, buffer_count, buffers, offsets);
5772 wined3d_mutex_lock();
5773 for (i = 0; i < buffer_count; ++i)
5775 struct wined3d_buffer *wined3d_buffer;
5776 struct d3d_buffer *buffer_impl;
5778 if (!(wined3d_buffer = wined3d_device_context_get_stream_output(
5779 device->immediate_context.wined3d_context, i, &offsets[i])))
5781 buffers[i] = NULL;
5782 continue;
5785 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5786 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5787 ID3D10Buffer_AddRef(buffers[i]);
5789 wined3d_mutex_unlock();
5792 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5794 struct d3d_device *device = impl_from_ID3D10Device(iface);
5795 struct d3d_rasterizer_state *rasterizer_state_impl;
5796 struct wined3d_rasterizer_state *wined3d_state;
5798 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5800 wined3d_mutex_lock();
5801 if ((wined3d_state = wined3d_device_context_get_rasterizer_state(device->immediate_context.wined3d_context)))
5803 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5804 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5806 else
5808 *rasterizer_state = NULL;
5810 wined3d_mutex_unlock();
5813 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5814 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5816 struct d3d_device *device = impl_from_ID3D10Device(iface);
5817 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5818 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5820 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5822 if (!viewport_count)
5823 return;
5825 wined3d_mutex_lock();
5826 wined3d_device_context_get_viewports(device->immediate_context.wined3d_context,
5827 &actual_count, viewports ? wined3d_vp : NULL);
5828 wined3d_mutex_unlock();
5830 if (!viewports)
5832 *viewport_count = actual_count;
5833 return;
5836 if (*viewport_count > actual_count)
5837 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5839 *viewport_count = min(actual_count, *viewport_count);
5840 for (i = 0; i < *viewport_count; ++i)
5842 viewports[i].TopLeftX = wined3d_vp[i].x;
5843 viewports[i].TopLeftY = wined3d_vp[i].y;
5844 viewports[i].Width = wined3d_vp[i].width;
5845 viewports[i].Height = wined3d_vp[i].height;
5846 viewports[i].MinDepth = wined3d_vp[i].min_z;
5847 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5851 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5853 struct d3d_device *device = impl_from_ID3D10Device(iface);
5854 unsigned int actual_count;
5856 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5858 if (!rect_count)
5859 return;
5861 actual_count = *rect_count;
5863 wined3d_mutex_lock();
5864 wined3d_device_context_get_scissor_rects(device->immediate_context.wined3d_context, &actual_count, rects);
5865 wined3d_mutex_unlock();
5867 if (!rects)
5869 *rect_count = actual_count;
5870 return;
5873 if (*rect_count > actual_count)
5874 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5877 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5879 TRACE("iface %p.\n", iface);
5881 /* In the current implementation the device is never removed, so we can
5882 * just return S_OK here. */
5884 return S_OK;
5887 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5889 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5891 return E_NOTIMPL;
5894 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5896 FIXME("iface %p stub!\n", iface);
5898 return 0;
5901 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5902 REFGUID guid, UINT *data_size, void *data)
5904 struct d3d_device *device = impl_from_ID3D10Device(iface);
5906 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5908 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5911 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5912 REFGUID guid, UINT data_size, const void *data)
5914 struct d3d_device *device = impl_from_ID3D10Device(iface);
5916 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5918 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5921 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5922 REFGUID guid, const IUnknown *data)
5924 struct d3d_device *device = impl_from_ID3D10Device(iface);
5926 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5928 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5931 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5933 struct d3d_device *device = impl_from_ID3D10Device(iface);
5935 TRACE("iface %p.\n", iface);
5937 d3d11_device_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5940 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5942 struct d3d_device *device = impl_from_ID3D10Device(iface);
5944 TRACE("iface %p.\n", iface);
5946 wined3d_device_context_flush(device->immediate_context.wined3d_context);
5949 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5950 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5952 struct d3d_device *device = impl_from_ID3D10Device(iface);
5953 D3D11_BUFFER_DESC d3d11_desc;
5954 struct d3d_buffer *object;
5955 HRESULT hr;
5957 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5959 d3d11_desc.ByteWidth = desc->ByteWidth;
5960 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5961 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5962 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5963 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5964 d3d11_desc.StructureByteStride = 0;
5966 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5967 return hr;
5969 *buffer = &object->ID3D10Buffer_iface;
5971 return S_OK;
5974 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5975 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5977 struct d3d_device *device = impl_from_ID3D10Device(iface);
5978 D3D11_TEXTURE1D_DESC d3d11_desc;
5979 struct d3d_texture1d *object;
5980 HRESULT hr;
5982 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5984 d3d11_desc.Width = desc->Width;
5985 d3d11_desc.MipLevels = desc->MipLevels;
5986 d3d11_desc.ArraySize = desc->ArraySize;
5987 d3d11_desc.Format = desc->Format;
5988 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5989 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5990 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5991 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5993 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5994 return hr;
5996 *texture = &object->ID3D10Texture1D_iface;
5998 return S_OK;
6001 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
6002 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
6003 ID3D10Texture2D **texture)
6005 struct d3d_device *device = impl_from_ID3D10Device(iface);
6006 D3D11_TEXTURE2D_DESC d3d11_desc;
6007 struct d3d_texture2d *object;
6008 HRESULT hr;
6010 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
6012 d3d11_desc.Width = desc->Width;
6013 d3d11_desc.Height = desc->Height;
6014 d3d11_desc.MipLevels = desc->MipLevels;
6015 d3d11_desc.ArraySize = desc->ArraySize;
6016 d3d11_desc.Format = desc->Format;
6017 d3d11_desc.SampleDesc = desc->SampleDesc;
6018 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
6019 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
6020 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
6021 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
6023 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
6024 return hr;
6026 *texture = &object->ID3D10Texture2D_iface;
6028 return S_OK;
6031 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
6032 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
6033 ID3D10Texture3D **texture)
6035 struct d3d_device *device = impl_from_ID3D10Device(iface);
6036 D3D11_TEXTURE3D_DESC d3d11_desc;
6037 struct d3d_texture3d *object;
6038 HRESULT hr;
6040 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
6042 d3d11_desc.Width = desc->Width;
6043 d3d11_desc.Height = desc->Height;
6044 d3d11_desc.Depth = desc->Depth;
6045 d3d11_desc.MipLevels = desc->MipLevels;
6046 d3d11_desc.Format = desc->Format;
6047 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
6048 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
6049 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
6050 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
6052 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
6053 return hr;
6055 *texture = &object->ID3D10Texture3D_iface;
6057 return S_OK;
6060 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
6061 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
6063 struct d3d_device *device = impl_from_ID3D10Device(iface);
6064 struct d3d_shader_resource_view *object;
6065 ID3D11Resource *d3d11_resource;
6066 HRESULT hr;
6068 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6070 *view = NULL;
6072 if (!resource)
6073 return E_INVALIDARG;
6075 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6077 ERR("Resource does not implement ID3D11Resource.\n");
6078 return E_FAIL;
6081 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
6082 &object);
6083 ID3D11Resource_Release(d3d11_resource);
6084 if (FAILED(hr))
6085 return hr;
6087 *view = &object->ID3D10ShaderResourceView1_iface;
6089 return S_OK;
6092 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
6093 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
6095 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6097 return d3d10_device_CreateShaderResourceView1(iface, resource,
6098 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
6101 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
6102 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
6104 struct d3d_device *device = impl_from_ID3D10Device(iface);
6105 struct d3d_rendertarget_view *object;
6106 ID3D11Resource *d3d11_resource;
6107 HRESULT hr;
6109 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6111 *view = NULL;
6113 if (!resource)
6114 return E_INVALIDARG;
6116 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6118 ERR("Resource does not implement ID3D11Resource.\n");
6119 return E_FAIL;
6122 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
6123 ID3D11Resource_Release(d3d11_resource);
6124 if (FAILED(hr))
6125 return hr;
6127 *view = &object->ID3D10RenderTargetView_iface;
6129 return S_OK;
6132 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
6134 return (D3D11_DSV_DIMENSION)dim;
6137 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
6138 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
6140 struct d3d_device *device = impl_from_ID3D10Device(iface);
6141 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
6142 struct d3d_depthstencil_view *object;
6143 ID3D11Resource *d3d11_resource;
6144 HRESULT hr;
6146 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
6148 *view = NULL;
6150 if (desc)
6152 d3d11_desc.Format = desc->Format;
6153 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
6154 d3d11_desc.Flags = 0;
6155 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
6158 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
6160 ERR("Resource does not implement ID3D11Resource.\n");
6161 return E_FAIL;
6164 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
6165 ID3D11Resource_Release(d3d11_resource);
6166 if (FAILED(hr))
6167 return hr;
6169 *view = &object->ID3D10DepthStencilView_iface;
6171 return S_OK;
6174 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
6175 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
6176 const void *shader_byte_code, SIZE_T shader_byte_code_length,
6177 ID3D10InputLayout **input_layout)
6179 struct d3d_device *device = impl_from_ID3D10Device(iface);
6180 struct d3d_input_layout *object;
6181 HRESULT hr;
6183 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
6184 "shader_byte_code_length %Iu, input_layout %p.\n",
6185 iface, element_descs, element_count, shader_byte_code,
6186 shader_byte_code_length, input_layout);
6188 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
6189 shader_byte_code, shader_byte_code_length, &object)))
6190 return hr;
6192 *input_layout = &object->ID3D10InputLayout_iface;
6194 return S_OK;
6197 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
6198 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
6200 struct d3d_device *device = impl_from_ID3D10Device(iface);
6201 struct d3d_vertex_shader *object;
6202 HRESULT hr;
6204 TRACE("iface %p, byte_code %p, byte_code_length %Iu, shader %p.\n",
6205 iface, byte_code, byte_code_length, shader);
6207 *shader = NULL;
6209 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
6210 return hr;
6212 *shader = &object->ID3D10VertexShader_iface;
6214 return S_OK;
6217 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
6218 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
6220 struct d3d_device *device = impl_from_ID3D10Device(iface);
6221 struct d3d_geometry_shader *object;
6222 HRESULT hr;
6224 TRACE("iface %p, byte_code %p, byte_code_length %Iu, shader %p.\n",
6225 iface, byte_code, byte_code_length, shader);
6227 *shader = NULL;
6229 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6230 NULL, 0, NULL, 0, 0, &object)))
6231 return hr;
6233 *shader = &object->ID3D10GeometryShader_iface;
6235 return S_OK;
6238 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
6239 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
6240 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
6242 struct d3d_device *device = impl_from_ID3D10Device(iface);
6243 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
6244 struct d3d_geometry_shader *object;
6245 unsigned int i, stride_count = 1;
6246 HRESULT hr;
6248 TRACE("iface %p, byte_code %p, byte_code_length %Iu, output_stream_decls %p, "
6249 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
6250 iface, byte_code, byte_code_length, output_stream_decls,
6251 output_stream_decl_count, output_stream_stride, shader);
6253 *shader = NULL;
6255 if (!output_stream_decl_count && output_stream_stride)
6257 WARN("Stride must be 0 when declaration entry count is 0.\n");
6258 return E_INVALIDARG;
6261 if (output_stream_decl_count
6262 && !(so_entries = calloc(output_stream_decl_count, sizeof(*so_entries))))
6264 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
6265 return E_OUTOFMEMORY;
6268 for (i = 0; i < output_stream_decl_count; ++i)
6270 so_entries[i].Stream = 0;
6271 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
6272 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
6273 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
6274 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
6275 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
6277 if (output_stream_decls[i].OutputSlot)
6279 stride_count = 0;
6280 if (output_stream_stride)
6282 WARN("Stride must be 0 when multiple output slots are used.\n");
6283 free(so_entries);
6284 return E_INVALIDARG;
6289 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
6290 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
6291 free(so_entries);
6292 if (FAILED(hr))
6293 return hr;
6295 *shader = &object->ID3D10GeometryShader_iface;
6297 return hr;
6300 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
6301 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6303 struct d3d_device *device = impl_from_ID3D10Device(iface);
6304 struct d3d_pixel_shader *object;
6305 HRESULT hr;
6307 TRACE("iface %p, byte_code %p, byte_code_length %Iu, shader %p.\n",
6308 iface, byte_code, byte_code_length, shader);
6310 *shader = NULL;
6312 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6313 return hr;
6315 *shader = &object->ID3D10PixelShader_iface;
6317 return S_OK;
6320 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6321 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6323 struct d3d_device *device = impl_from_ID3D10Device(iface);
6324 ID3D11BlendState *object;
6325 HRESULT hr;
6327 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6329 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device2_iface, (const D3D11_BLEND_DESC *)desc, &object)))
6330 return hr;
6332 *blend_state = &impl_from_ID3D11BlendState1((ID3D11BlendState1 *)object)->ID3D10BlendState1_iface;
6333 return S_OK;
6336 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6337 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6339 D3D10_BLEND_DESC1 d3d10_1_desc;
6340 unsigned int i;
6342 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6344 if (!desc)
6345 return E_INVALIDARG;
6347 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6348 d3d10_1_desc.IndependentBlendEnable = FALSE;
6349 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6351 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6352 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6353 d3d10_1_desc.IndependentBlendEnable = TRUE;
6356 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6358 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6359 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6360 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6361 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6362 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6363 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6364 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6365 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6368 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6371 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6372 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6374 struct d3d_device *device = impl_from_ID3D10Device(iface);
6375 struct d3d_depthstencil_state *object;
6376 HRESULT hr;
6378 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6380 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6381 return hr;
6383 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6385 return S_OK;
6388 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6389 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6391 struct d3d_device *device = impl_from_ID3D10Device(iface);
6392 struct d3d_rasterizer_state *object;
6393 D3D11_RASTERIZER_DESC1 desc1;
6394 HRESULT hr;
6396 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6398 if (!desc)
6399 return E_INVALIDARG;
6401 memcpy(&desc1, desc, sizeof(*desc));
6402 desc1.ForcedSampleCount = 0;
6404 if (FAILED(hr = d3d_rasterizer_state_create(device, &desc1, &object)))
6405 return hr;
6407 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6409 return S_OK;
6412 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6413 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6415 struct d3d_device *device = impl_from_ID3D10Device(iface);
6416 struct d3d_sampler_state *object;
6417 HRESULT hr;
6419 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6421 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6422 return hr;
6424 *sampler_state = &object->ID3D10SamplerState_iface;
6426 return S_OK;
6429 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6430 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6432 struct d3d_device *device = impl_from_ID3D10Device(iface);
6433 struct d3d_query *object;
6434 HRESULT hr;
6436 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6438 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6439 return hr;
6441 if (query)
6443 *query = &object->ID3D10Query_iface;
6444 return S_OK;
6447 ID3D10Query_Release(&object->ID3D10Query_iface);
6448 return S_FALSE;
6451 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6452 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6454 struct d3d_device *device = impl_from_ID3D10Device(iface);
6455 struct d3d_query *object;
6456 HRESULT hr;
6458 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6460 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6461 return hr;
6463 if (predicate)
6465 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6466 return S_OK;
6469 ID3D10Query_Release(&object->ID3D10Query_iface);
6470 return S_FALSE;
6473 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6474 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6476 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6478 return E_NOTIMPL;
6481 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6482 DXGI_FORMAT format, UINT *format_support)
6484 struct d3d_device *device = impl_from_ID3D10Device(iface);
6486 TRACE("iface %p, format %s, format_support %p.\n",
6487 iface, debug_dxgi_format(format), format_support);
6489 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6492 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6493 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6495 struct d3d_device *device = impl_from_ID3D10Device(iface);
6497 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6498 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6500 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6501 sample_count, quality_level_count);
6504 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6506 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6509 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6510 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6511 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6513 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6514 "units %p, units_length %p, description %p, description_length %p stub!\n",
6515 iface, desc, type, active_counters, name, name_length,
6516 units, units_length, description, description_length);
6518 return E_NOTIMPL;
6521 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6523 FIXME("iface %p stub!\n", iface);
6525 return 0;
6528 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6529 HANDLE resource_handle, REFIID guid, void **resource)
6531 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6532 iface, resource_handle, debugstr_guid(guid), resource);
6534 return E_NOTIMPL;
6537 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6539 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6542 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6544 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6547 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6549 return (D3D10_FEATURE_LEVEL1)level;
6552 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6554 struct d3d_device *device = impl_from_ID3D10Device(iface);
6556 TRACE("iface %p.\n", iface);
6558 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6561 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6563 /* IUnknown methods */
6564 d3d10_device_QueryInterface,
6565 d3d10_device_AddRef,
6566 d3d10_device_Release,
6567 /* ID3D10Device methods */
6568 d3d10_device_VSSetConstantBuffers,
6569 d3d10_device_PSSetShaderResources,
6570 d3d10_device_PSSetShader,
6571 d3d10_device_PSSetSamplers,
6572 d3d10_device_VSSetShader,
6573 d3d10_device_DrawIndexed,
6574 d3d10_device_Draw,
6575 d3d10_device_PSSetConstantBuffers,
6576 d3d10_device_IASetInputLayout,
6577 d3d10_device_IASetVertexBuffers,
6578 d3d10_device_IASetIndexBuffer,
6579 d3d10_device_DrawIndexedInstanced,
6580 d3d10_device_DrawInstanced,
6581 d3d10_device_GSSetConstantBuffers,
6582 d3d10_device_GSSetShader,
6583 d3d10_device_IASetPrimitiveTopology,
6584 d3d10_device_VSSetShaderResources,
6585 d3d10_device_VSSetSamplers,
6586 d3d10_device_SetPredication,
6587 d3d10_device_GSSetShaderResources,
6588 d3d10_device_GSSetSamplers,
6589 d3d10_device_OMSetRenderTargets,
6590 d3d10_device_OMSetBlendState,
6591 d3d10_device_OMSetDepthStencilState,
6592 d3d10_device_SOSetTargets,
6593 d3d10_device_DrawAuto,
6594 d3d10_device_RSSetState,
6595 d3d10_device_RSSetViewports,
6596 d3d10_device_RSSetScissorRects,
6597 d3d10_device_CopySubresourceRegion,
6598 d3d10_device_CopyResource,
6599 d3d10_device_UpdateSubresource,
6600 d3d10_device_ClearRenderTargetView,
6601 d3d10_device_ClearDepthStencilView,
6602 d3d10_device_GenerateMips,
6603 d3d10_device_ResolveSubresource,
6604 d3d10_device_VSGetConstantBuffers,
6605 d3d10_device_PSGetShaderResources,
6606 d3d10_device_PSGetShader,
6607 d3d10_device_PSGetSamplers,
6608 d3d10_device_VSGetShader,
6609 d3d10_device_PSGetConstantBuffers,
6610 d3d10_device_IAGetInputLayout,
6611 d3d10_device_IAGetVertexBuffers,
6612 d3d10_device_IAGetIndexBuffer,
6613 d3d10_device_GSGetConstantBuffers,
6614 d3d10_device_GSGetShader,
6615 d3d10_device_IAGetPrimitiveTopology,
6616 d3d10_device_VSGetShaderResources,
6617 d3d10_device_VSGetSamplers,
6618 d3d10_device_GetPredication,
6619 d3d10_device_GSGetShaderResources,
6620 d3d10_device_GSGetSamplers,
6621 d3d10_device_OMGetRenderTargets,
6622 d3d10_device_OMGetBlendState,
6623 d3d10_device_OMGetDepthStencilState,
6624 d3d10_device_SOGetTargets,
6625 d3d10_device_RSGetState,
6626 d3d10_device_RSGetViewports,
6627 d3d10_device_RSGetScissorRects,
6628 d3d10_device_GetDeviceRemovedReason,
6629 d3d10_device_SetExceptionMode,
6630 d3d10_device_GetExceptionMode,
6631 d3d10_device_GetPrivateData,
6632 d3d10_device_SetPrivateData,
6633 d3d10_device_SetPrivateDataInterface,
6634 d3d10_device_ClearState,
6635 d3d10_device_Flush,
6636 d3d10_device_CreateBuffer,
6637 d3d10_device_CreateTexture1D,
6638 d3d10_device_CreateTexture2D,
6639 d3d10_device_CreateTexture3D,
6640 d3d10_device_CreateShaderResourceView,
6641 d3d10_device_CreateRenderTargetView,
6642 d3d10_device_CreateDepthStencilView,
6643 d3d10_device_CreateInputLayout,
6644 d3d10_device_CreateVertexShader,
6645 d3d10_device_CreateGeometryShader,
6646 d3d10_device_CreateGeometryShaderWithStreamOutput,
6647 d3d10_device_CreatePixelShader,
6648 d3d10_device_CreateBlendState,
6649 d3d10_device_CreateDepthStencilState,
6650 d3d10_device_CreateRasterizerState,
6651 d3d10_device_CreateSamplerState,
6652 d3d10_device_CreateQuery,
6653 d3d10_device_CreatePredicate,
6654 d3d10_device_CreateCounter,
6655 d3d10_device_CheckFormatSupport,
6656 d3d10_device_CheckMultisampleQualityLevels,
6657 d3d10_device_CheckCounterInfo,
6658 d3d10_device_CheckCounter,
6659 d3d10_device_GetCreationFlags,
6660 d3d10_device_OpenSharedResource,
6661 d3d10_device_SetTextFilterSize,
6662 d3d10_device_GetTextFilterSize,
6663 d3d10_device_CreateShaderResourceView1,
6664 d3d10_device_CreateBlendState1,
6665 d3d10_device_GetFeatureLevel,
6668 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6670 /* IUnknown methods */
6671 d3d_device_inner_QueryInterface,
6672 d3d_device_inner_AddRef,
6673 d3d_device_inner_Release,
6676 /* ID3D10Multithread methods */
6678 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6680 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6683 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6685 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6687 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6689 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6692 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6694 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6696 TRACE("iface %p.\n", iface);
6698 return IUnknown_AddRef(device->outer_unk);
6701 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6703 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6705 TRACE("iface %p.\n", iface);
6707 return IUnknown_Release(device->outer_unk);
6710 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6712 TRACE("iface %p.\n", iface);
6714 wined3d_mutex_lock();
6717 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6719 TRACE("iface %p.\n", iface);
6721 wined3d_mutex_unlock();
6724 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6726 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6728 return TRUE;
6731 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6733 FIXME("iface %p stub!\n", iface);
6735 return TRUE;
6738 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6740 d3d10_multithread_QueryInterface,
6741 d3d10_multithread_AddRef,
6742 d3d10_multithread_Release,
6743 d3d10_multithread_Enter,
6744 d3d10_multithread_Leave,
6745 d3d10_multithread_SetMultithreadProtected,
6746 d3d10_multithread_GetMultithreadProtected,
6749 /* IWineDXGIDeviceParent IUnknown methods */
6751 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6753 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6756 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6757 REFIID iid, void **out)
6759 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6760 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6763 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6765 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6766 return IUnknown_AddRef(device->outer_unk);
6769 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6771 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6772 return IUnknown_Release(device->outer_unk);
6775 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6776 IWineDXGIDeviceParent *iface)
6778 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6779 return &device->device_parent;
6782 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6784 /* IUnknown methods */
6785 dxgi_device_parent_QueryInterface,
6786 dxgi_device_parent_AddRef,
6787 dxgi_device_parent_Release,
6788 /* IWineDXGIDeviceParent methods */
6789 dxgi_device_parent_get_wined3d_device_parent,
6792 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6794 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6797 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6798 struct wined3d_device *wined3d_device)
6800 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6801 struct d3d_device_context_state *state;
6802 struct wined3d_state *wined3d_state;
6803 D3D_FEATURE_LEVEL feature_level;
6805 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6807 wined3d_device_incref(wined3d_device);
6808 device->wined3d_device = wined3d_device;
6809 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6811 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6812 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6814 if (!(state = calloc(1, sizeof(*state))))
6816 ERR("Failed to create the initial device context state.\n");
6817 return;
6820 d3d_device_context_state_init(state, device, feature_level,
6821 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6823 device->state = state;
6824 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6825 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6827 d3d_device_context_state_private_addref(state);
6828 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6831 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6833 TRACE("device_parent %p.\n", device_parent);
6836 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6838 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6841 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6842 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6843 void **parent, const struct wined3d_parent_ops **parent_ops)
6845 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6846 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6848 *parent = NULL;
6849 *parent_ops = &d3d_null_wined3d_parent_ops;
6851 return S_OK;
6854 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6855 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6856 struct wined3d_texture **wined3d_texture)
6858 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6859 struct d3d_texture2d *texture;
6860 ID3D11Texture2D *texture_iface;
6861 D3D11_TEXTURE2D_DESC desc;
6862 HRESULT hr;
6864 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#lx, wined3d_texture %p.\n",
6865 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6867 desc.Width = wined3d_desc->width;
6868 desc.Height = wined3d_desc->height;
6869 desc.MipLevels = 1;
6870 desc.ArraySize = 1;
6871 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6872 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6873 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6874 desc.Usage = D3D11_USAGE_DEFAULT;
6875 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6876 desc.CPUAccessFlags = 0;
6877 desc.MiscFlags = 0;
6879 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6881 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6882 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6885 if (texture_flags)
6886 FIXME("Unhandled flags %#lx.\n", texture_flags);
6888 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6889 &desc, NULL, &texture_iface)))
6891 WARN("Failed to create 2D texture, hr %#lx.\n", hr);
6892 return hr;
6895 texture = impl_from_ID3D11Texture2D(texture_iface);
6897 *wined3d_texture = texture->wined3d_texture;
6898 wined3d_texture_incref(*wined3d_texture);
6899 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6901 return S_OK;
6904 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6906 device_parent_wined3d_device_created,
6907 device_parent_mode_changed,
6908 device_parent_activate,
6909 device_parent_texture_sub_resource_created,
6910 device_parent_create_swapchain_texture,
6913 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6915 const D3D11_SAMPLER_DESC *ka = key;
6916 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6918 return memcmp(ka, kb, sizeof(*ka));
6921 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6923 const D3D11_BLEND_DESC1 *ka = key;
6924 const D3D11_BLEND_DESC1 *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6926 return memcmp(ka, kb, sizeof(*ka));
6929 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6931 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6932 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6933 const struct d3d_depthstencil_state, entry)->desc;
6935 return memcmp(ka, kb, sizeof(*ka));
6938 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6940 const D3D11_RASTERIZER_DESC1 *ka = key;
6941 const D3D11_RASTERIZER_DESC1 *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6943 return memcmp(ka, kb, sizeof(*ka));
6946 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6948 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6949 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6950 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6951 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6952 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6953 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6954 device->refcount = 1;
6955 /* COM aggregation always takes place */
6956 device->outer_unk = outer_unknown;
6957 device->d3d11_only = FALSE;
6958 device->state = NULL;
6960 d3d11_device_context_init(&device->immediate_context, device, D3D11_DEVICE_CONTEXT_IMMEDIATE);
6961 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6963 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6964 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6965 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6966 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);