d3d11: Use wined3d_device_context_unmap().
[wine.git] / dlls / d3d11 / device.c
blob47f865ed14c09a4a5f53c4b1678352653a154151
1 /*
2 * Copyright 2008-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
21 #define WINE_NO_NAMELESS_EXTENSION
22 #include "d3d11_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
26 static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
28 SIZE_T max_capacity, new_capacity;
29 void *new_elements;
31 if (count <= *capacity)
32 return TRUE;
34 max_capacity = ~(SIZE_T)0 / size;
35 if (count > max_capacity)
36 return FALSE;
38 new_capacity = max(1, *capacity);
39 while (new_capacity < count && new_capacity <= max_capacity / 2)
40 new_capacity *= 2;
41 if (new_capacity < count)
42 new_capacity = count;
44 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
45 return FALSE;
47 *elements = new_elements;
48 *capacity = new_capacity;
49 return TRUE;
52 static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
54 static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
56 d3d_null_wined3d_object_destroyed,
59 static inline BOOL d3d_device_is_d3d10_active(struct d3d_device *device)
61 return !device->state
62 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device)
63 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device1);
66 static D3D_FEATURE_LEVEL d3d_feature_level_from_wined3d(enum wined3d_feature_level level)
68 return (D3D_FEATURE_LEVEL)level;
71 /* ID3DDeviceContextState methods */
73 static inline struct d3d_device_context_state *impl_from_ID3DDeviceContextState(ID3DDeviceContextState *iface)
75 return CONTAINING_RECORD(iface, struct d3d_device_context_state, ID3DDeviceContextState_iface);
78 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface,
79 REFIID iid, void **out)
81 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
83 if (IsEqualGUID(iid, &IID_ID3DDeviceContextState)
84 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
85 || IsEqualGUID(iid, &IID_IUnknown))
87 ID3DDeviceContextState_AddRef(iface);
88 *out = iface;
89 return S_OK;
92 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
93 *out = NULL;
95 return E_NOINTERFACE;
98 static ULONG d3d_device_context_state_private_addref(struct d3d_device_context_state *state)
100 ULONG refcount = InterlockedIncrement(&state->private_refcount);
102 TRACE("%p increasing private refcount to %u.\n", state, refcount);
104 return refcount;
107 static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface)
109 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
110 ULONG refcount = InterlockedIncrement(&state->refcount);
112 TRACE("%p increasing refcount to %u.\n", state, refcount);
114 if (refcount == 1)
116 d3d_device_context_state_private_addref(state);
117 ID3D11Device2_AddRef(state->device);
120 return refcount;
123 static void d3d_device_remove_context_state(struct d3d_device *device, struct d3d_device_context_state *state)
125 unsigned int i;
127 for (i = 0; i < device->context_state_count; ++i)
129 if (device->context_states[i] != state)
130 continue;
132 if (i != device->context_state_count - 1)
133 device->context_states[i] = device->context_states[device->context_state_count - 1];
134 --device->context_state_count;
135 break;
139 static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
141 ULONG refcount = InterlockedDecrement(&state->private_refcount);
142 struct d3d_device_context_state_entry *entry;
143 struct d3d_device *device;
144 unsigned int i;
146 TRACE("%p decreasing private refcount to %u.\n", state, refcount);
148 if (!refcount)
150 wined3d_private_store_cleanup(&state->private_store);
151 for (i = 0; i < state->entry_count; ++i)
153 entry = &state->entries[i];
154 device = entry->device;
156 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
157 wined3d_state_destroy(entry->wined3d_state);
159 d3d_device_remove_context_state(device, state);
161 heap_free(state->entries);
162 wined3d_device_decref(state->wined3d_device);
163 heap_free(state);
167 static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface)
169 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
170 ULONG refcount = InterlockedDecrement(&state->refcount);
172 TRACE("%p decreasing refcount to %u.\n", state, refcount);
174 if (!refcount)
176 ID3D11Device2_Release(state->device);
177 d3d_device_context_state_private_release(state);
180 return refcount;
183 static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device)
185 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
187 TRACE("iface %p, device %p.\n", iface, device);
189 *device = (ID3D11Device *)state->device;
190 ID3D11Device_AddRef(*device);
193 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_GetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
194 UINT *data_size, void *data)
196 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
198 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
200 return d3d_get_private_data(&state->private_store, guid, data_size, data);
203 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
204 UINT data_size, const void *data)
206 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
208 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
210 return d3d_set_private_data(&state->private_store, guid, data_size, data);
213 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateDataInterface(ID3DDeviceContextState *iface,
214 REFGUID guid, const IUnknown *data)
216 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
218 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
220 return d3d_set_private_data_interface(&state->private_store, guid, data);
223 static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
225 /* IUnknown methods */
226 d3d_device_context_state_QueryInterface,
227 d3d_device_context_state_AddRef,
228 d3d_device_context_state_Release,
229 /* ID3D11DeviceChild methods */
230 d3d_device_context_state_GetDevice,
231 d3d_device_context_state_GetPrivateData,
232 d3d_device_context_state_SetPrivateData,
233 d3d_device_context_state_SetPrivateDataInterface,
234 /* ID3DDeviceContextState methods */
237 static struct d3d_device_context_state_entry *d3d_device_context_state_get_entry(
238 struct d3d_device_context_state *state, struct d3d_device *device)
240 unsigned int i;
242 for (i = 0; i < state->entry_count; ++i)
244 if (state->entries[i].device == device)
245 return &state->entries[i];
248 return NULL;
251 static BOOL d3d_device_context_state_add_entry(struct d3d_device_context_state *state,
252 struct d3d_device *device, struct wined3d_state *wined3d_state)
254 struct d3d_device_context_state_entry *entry;
256 if (!d3d_array_reserve((void **)&state->entries, &state->entries_size,
257 state->entry_count + 1, sizeof(*state->entries)))
258 return FALSE;
260 if (!d3d_array_reserve((void **)&device->context_states, &device->context_states_size,
261 device->context_state_count + 1, sizeof(*device->context_states)))
262 return FALSE;
264 entry = &state->entries[state->entry_count++];
265 entry->device = device;
266 entry->wined3d_state = wined3d_state;
268 device->context_states[device->context_state_count++] = state;
270 return TRUE;
273 static void d3d_device_context_state_remove_entry(struct d3d_device_context_state *state, struct d3d_device *device)
275 struct d3d_device_context_state_entry *entry;
276 unsigned int i;
278 for (i = 0; i < state->entry_count; ++i)
280 entry = &state->entries[i];
281 if (entry->device != device)
282 continue;
284 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
285 wined3d_state_destroy(entry->wined3d_state);
287 if (i != state->entry_count)
288 state->entries[i] = state->entries[state->entry_count - 1];
289 --state->entry_count;
291 break;
295 static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d3d_device_context_state *state,
296 struct d3d_device *device)
298 struct d3d_device_context_state_entry *entry;
299 struct wined3d_state *wined3d_state;
301 if ((entry = d3d_device_context_state_get_entry(state, device)))
302 return entry->wined3d_state;
304 if (FAILED(wined3d_state_create(device->wined3d_device,
305 (enum wined3d_feature_level *)&state->feature_level, 1, &wined3d_state)))
306 return NULL;
308 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
310 wined3d_state_destroy(wined3d_state);
311 return NULL;
314 return wined3d_state;
317 static void d3d_device_context_state_init(struct d3d_device_context_state *state,
318 struct d3d_device *device, D3D_FEATURE_LEVEL feature_level, REFIID emulated_interface)
320 state->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl;
321 state->refcount = state->private_refcount = 0;
323 wined3d_private_store_init(&state->private_store);
325 state->feature_level = feature_level;
326 state->emulated_interface = *emulated_interface;
327 wined3d_device_incref(state->wined3d_device = device->wined3d_device);
328 state->device = &device->ID3D11Device2_iface;
330 d3d_device_context_state_AddRef(&state->ID3DDeviceContextState_iface);
333 /* ID3D11DeviceContext - immediate context methods */
335 static inline struct d3d11_immediate_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
337 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11DeviceContext1_iface);
340 static inline struct d3d_device *device_from_immediate_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
342 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
343 return CONTAINING_RECORD(context, struct d3d_device, immediate_context);
346 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_QueryInterface(ID3D11DeviceContext1 *iface,
347 REFIID iid, void **out)
349 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
351 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
353 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
354 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
355 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
356 || IsEqualGUID(iid, &IID_IUnknown))
358 *out = &context->ID3D11DeviceContext1_iface;
360 else if (IsEqualGUID(iid, &IID_ID3D11Multithread))
362 *out = &context->ID3D11Multithread_iface;
364 else
366 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
367 *out = NULL;
368 return E_NOINTERFACE;
371 ID3D11DeviceContext1_AddRef(iface);
372 return S_OK;
375 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_AddRef(ID3D11DeviceContext1 *iface)
377 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
378 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
379 ULONG refcount = InterlockedIncrement(&context->refcount);
381 TRACE("%p increasing refcount to %u.\n", context, refcount);
383 if (refcount == 1)
385 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
388 return refcount;
391 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_Release(ID3D11DeviceContext1 *iface)
393 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
394 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
395 ULONG refcount = InterlockedDecrement(&context->refcount);
397 TRACE("%p decreasing refcount to %u.\n", context, refcount);
399 if (!refcount)
401 ID3D11Device2_Release(&device->ID3D11Device2_iface);
404 return refcount;
407 static void d3d11_immediate_context_get_constant_buffers(ID3D11DeviceContext1 *iface,
408 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
410 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
411 unsigned int i;
413 wined3d_mutex_lock();
414 for (i = 0; i < buffer_count; ++i)
416 struct wined3d_buffer *wined3d_buffer;
417 struct d3d_buffer *buffer_impl;
419 if (!(wined3d_buffer = wined3d_device_get_constant_buffer(device->wined3d_device,
420 type, start_slot + i)))
422 buffers[i] = NULL;
423 continue;
426 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
427 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
428 ID3D11Buffer_AddRef(buffers[i]);
430 wined3d_mutex_unlock();
433 static void d3d11_immediate_context_set_constant_buffers(ID3D11DeviceContext1 *iface,
434 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
436 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
437 unsigned int i;
439 wined3d_mutex_lock();
440 for (i = 0; i < buffer_count; ++i)
442 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
444 wined3d_device_context_set_constant_buffer(context->wined3d_context, type, start_slot + i,
445 buffer ? buffer->wined3d_buffer : NULL);
447 wined3d_mutex_unlock();
450 static void STDMETHODCALLTYPE d3d11_immediate_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
452 struct d3d_device *device_object = device_from_immediate_ID3D11DeviceContext1(iface);
454 TRACE("iface %p, device %p.\n", iface, device);
456 *device = (ID3D11Device *)&device_object->ID3D11Device2_iface;
457 ID3D11Device_AddRef(*device);
460 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
461 UINT *data_size, void *data)
463 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
465 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
467 return d3d_get_private_data(&context->private_store, guid, data_size, data);
470 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
471 UINT data_size, const void *data)
473 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
475 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
477 return d3d_set_private_data(&context->private_store, guid, data_size, data);
480 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
481 REFGUID guid, const IUnknown *data)
483 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
485 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
487 return d3d_set_private_data_interface(&context->private_store, guid, data);
490 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
491 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
493 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
494 iface, start_slot, buffer_count, buffers);
496 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
497 buffer_count, buffers);
500 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
501 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
503 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
504 unsigned int i;
506 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
507 iface, start_slot, view_count, views);
509 wined3d_mutex_lock();
510 for (i = 0; i < view_count; ++i)
512 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
514 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
515 start_slot + i, view ? view->wined3d_view : NULL);
517 wined3d_mutex_unlock();
520 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShader(ID3D11DeviceContext1 *iface,
521 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
523 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
524 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
526 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
527 iface, shader, class_instances, class_instance_count);
529 if (class_instances)
530 FIXME("Dynamic linking is not implemented yet.\n");
532 wined3d_mutex_lock();
533 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
534 ps ? ps->wined3d_shader : NULL);
535 wined3d_mutex_unlock();
538 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
539 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
541 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
542 unsigned int i;
544 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
545 iface, start_slot, sampler_count, samplers);
547 wined3d_mutex_lock();
548 for (i = 0; i < sampler_count; ++i)
550 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
552 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i,
553 sampler ? sampler->wined3d_sampler : NULL);
555 wined3d_mutex_unlock();
558 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShader(ID3D11DeviceContext1 *iface,
559 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
561 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
562 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
564 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
565 iface, shader, class_instances, class_instance_count);
567 if (class_instances)
568 FIXME("Dynamic linking is not implemented yet.\n");
570 wined3d_mutex_lock();
571 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
572 vs ? vs->wined3d_shader : NULL);
573 wined3d_mutex_unlock();
576 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexed(ID3D11DeviceContext1 *iface,
577 UINT index_count, UINT start_index_location, INT base_vertex_location)
579 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
581 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
582 iface, index_count, start_index_location, base_vertex_location);
584 wined3d_mutex_lock();
585 wined3d_device_context_draw_indexed(context->wined3d_context,
586 base_vertex_location, start_index_location, index_count, 0, 0);
587 wined3d_mutex_unlock();
590 static void STDMETHODCALLTYPE d3d11_immediate_context_Draw(ID3D11DeviceContext1 *iface,
591 UINT vertex_count, UINT start_vertex_location)
593 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
595 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
596 iface, vertex_count, start_vertex_location);
598 wined3d_mutex_lock();
599 wined3d_device_context_draw(context->wined3d_context, start_vertex_location, vertex_count, 0, 0);
600 wined3d_mutex_unlock();
603 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
604 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
606 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
607 struct wined3d_resource *wined3d_resource;
608 struct wined3d_map_desc map_desc;
609 HRESULT hr;
611 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
612 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
614 if (map_flags)
615 FIXME("Ignoring map_flags %#x.\n", map_flags);
617 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
619 wined3d_mutex_lock();
620 hr = wined3d_device_context_map(context->wined3d_context, wined3d_resource, subresource_idx,
621 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
622 wined3d_mutex_unlock();
624 mapped_subresource->pData = map_desc.data;
625 mapped_subresource->RowPitch = map_desc.row_pitch;
626 mapped_subresource->DepthPitch = map_desc.slice_pitch;
628 return hr;
631 static void STDMETHODCALLTYPE d3d11_immediate_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
632 UINT subresource_idx)
634 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
635 struct wined3d_resource *wined3d_resource;
637 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
639 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
641 wined3d_mutex_lock();
642 wined3d_device_context_unmap(context->wined3d_context, wined3d_resource, subresource_idx);
643 wined3d_mutex_unlock();
646 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
647 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
649 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
650 iface, start_slot, buffer_count, buffers);
652 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
653 buffer_count, buffers);
656 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
657 ID3D11InputLayout *input_layout)
659 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
660 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
662 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
664 wined3d_mutex_lock();
665 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
666 wined3d_mutex_unlock();
669 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
670 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
672 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
673 unsigned int i;
675 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
676 iface, start_slot, buffer_count, buffers, strides, offsets);
678 wined3d_mutex_lock();
679 for (i = 0; i < buffer_count; ++i)
681 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
683 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
684 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
686 wined3d_mutex_unlock();
689 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
690 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
692 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
693 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
695 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
696 iface, buffer, debug_dxgi_format(format), offset);
698 wined3d_mutex_lock();
699 wined3d_device_context_set_index_buffer(context->wined3d_context,
700 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
701 wined3dformat_from_dxgi_format(format), offset);
702 wined3d_mutex_unlock();
705 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
706 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
707 UINT start_instance_location)
709 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
711 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
712 "base_vertex_location %d, start_instance_location %u.\n",
713 iface, instance_index_count, instance_count, start_index_location,
714 base_vertex_location, start_instance_location);
716 wined3d_mutex_lock();
717 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
718 start_index_location, instance_index_count, start_instance_location, instance_count);
719 wined3d_mutex_unlock();
722 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstanced(ID3D11DeviceContext1 *iface,
723 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
725 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
727 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
728 "start_instance_location %u.\n",
729 iface, instance_vertex_count, instance_count, start_vertex_location,
730 start_instance_location);
732 wined3d_mutex_lock();
733 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
734 instance_vertex_count, start_instance_location, instance_count);
735 wined3d_mutex_unlock();
738 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
739 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
741 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
742 iface, start_slot, buffer_count, buffers);
744 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
745 buffer_count, buffers);
748 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShader(ID3D11DeviceContext1 *iface,
749 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
751 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
752 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
754 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
755 iface, shader, class_instances, class_instance_count);
757 if (class_instances)
758 FIXME("Dynamic linking is not implemented yet.\n");
760 wined3d_mutex_lock();
761 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
762 gs ? gs->wined3d_shader : NULL);
763 wined3d_mutex_unlock();
766 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
767 D3D11_PRIMITIVE_TOPOLOGY topology)
769 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
770 enum wined3d_primitive_type primitive_type;
771 unsigned int patch_vertex_count;
773 TRACE("iface %p, topology %#x.\n", iface, topology);
775 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
777 wined3d_mutex_lock();
778 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, patch_vertex_count);
779 wined3d_mutex_unlock();
782 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
783 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
785 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
786 unsigned int i;
788 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
790 wined3d_mutex_lock();
791 for (i = 0; i < view_count; ++i)
793 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
795 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
796 start_slot + i, view ? view->wined3d_view : NULL);
798 wined3d_mutex_unlock();
801 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
802 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
804 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
805 unsigned int i;
807 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
808 iface, start_slot, sampler_count, samplers);
810 wined3d_mutex_lock();
811 for (i = 0; i < sampler_count; ++i)
813 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
815 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i,
816 sampler ? sampler->wined3d_sampler : NULL);
818 wined3d_mutex_unlock();
821 static void STDMETHODCALLTYPE d3d11_immediate_context_Begin(ID3D11DeviceContext1 *iface,
822 ID3D11Asynchronous *asynchronous)
824 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
825 HRESULT hr;
827 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
829 wined3d_mutex_lock();
830 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_BEGIN)))
831 ERR("Failed to issue query, hr %#x.\n", hr);
832 wined3d_mutex_unlock();
835 static void STDMETHODCALLTYPE d3d11_immediate_context_End(ID3D11DeviceContext1 *iface,
836 ID3D11Asynchronous *asynchronous)
838 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
839 HRESULT hr;
841 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
843 wined3d_mutex_lock();
844 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_END)))
845 ERR("Failed to issue query, hr %#x.\n", hr);
846 wined3d_mutex_unlock();
849 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetData(ID3D11DeviceContext1 *iface,
850 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
852 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
853 unsigned int wined3d_flags;
854 HRESULT hr;
856 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
857 iface, asynchronous, data, data_size, data_flags);
859 if (!data && data_size)
860 return E_INVALIDARG;
862 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
864 wined3d_mutex_lock();
865 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
867 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
868 if (hr == WINED3DERR_INVALIDCALL)
869 hr = DXGI_ERROR_INVALID_CALL;
871 else
873 WARN("Invalid data size %u.\n", data_size);
874 hr = E_INVALIDARG;
876 wined3d_mutex_unlock();
878 return hr;
881 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext1 *iface,
882 ID3D11Predicate *predicate, BOOL value)
884 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
885 struct d3d_query *query;
887 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
889 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
891 wined3d_mutex_lock();
892 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
893 wined3d_mutex_unlock();
896 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
897 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
899 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
900 unsigned int i;
902 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
904 wined3d_mutex_lock();
905 for (i = 0; i < view_count; ++i)
907 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
909 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
910 start_slot + i, view ? view->wined3d_view : NULL);
912 wined3d_mutex_unlock();
915 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
916 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
918 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
919 unsigned int i;
921 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
922 iface, start_slot, sampler_count, samplers);
924 wined3d_mutex_lock();
925 for (i = 0; i < sampler_count; ++i)
927 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
929 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i,
930 sampler ? sampler->wined3d_sampler : NULL);
932 wined3d_mutex_unlock();
935 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
936 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
937 ID3D11DepthStencilView *depth_stencil_view)
939 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
940 struct d3d_depthstencil_view *dsv;
941 unsigned int i;
943 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
944 iface, render_target_view_count, render_target_views, depth_stencil_view);
946 wined3d_mutex_lock();
947 for (i = 0; i < render_target_view_count; ++i)
949 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
950 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
951 rtv ? rtv->wined3d_view : NULL, FALSE);
953 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
955 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
958 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
959 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
960 wined3d_mutex_unlock();
963 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
964 ID3D11DeviceContext1 *iface, UINT render_target_view_count,
965 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
966 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
967 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
969 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
970 unsigned int i;
972 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
973 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
974 "initial_counts %p.\n",
975 iface, render_target_view_count, render_target_views, depth_stencil_view,
976 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
977 initial_counts);
979 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
981 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
982 depth_stencil_view);
985 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
987 wined3d_mutex_lock();
988 for (i = 0; i < unordered_access_view_start_slot; ++i)
990 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
991 WINED3D_PIPELINE_GRAPHICS, i, NULL, ~0u);
993 for (i = 0; i < unordered_access_view_count; ++i)
995 struct d3d11_unordered_access_view *view
996 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
998 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
999 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i,
1000 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1002 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
1004 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1005 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i, NULL, ~0u);
1007 wined3d_mutex_unlock();
1011 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1012 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1014 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1015 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1016 struct d3d_blend_state *blend_state_impl;
1018 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1019 iface, blend_state, debug_float4(blend_factor), sample_mask);
1021 if (!blend_factor)
1022 blend_factor = default_blend_factor;
1024 wined3d_mutex_lock();
1025 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1026 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1027 (const struct wined3d_color *)blend_factor, sample_mask);
1028 else
1029 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1030 (const struct wined3d_color *)blend_factor, sample_mask);
1031 wined3d_mutex_unlock();
1034 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1035 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1037 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1038 struct d3d_depthstencil_state *state_impl;
1040 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1041 iface, depth_stencil_state, stencil_ref);
1043 wined3d_mutex_lock();
1044 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1046 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1047 wined3d_mutex_unlock();
1048 return;
1051 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1052 wined3d_mutex_unlock();
1055 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1056 ID3D11Buffer *const *buffers, const UINT *offsets)
1058 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1059 unsigned int count, i;
1061 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1063 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
1064 wined3d_mutex_lock();
1065 for (i = 0; i < count; ++i)
1067 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1069 wined3d_device_context_set_stream_output(context->wined3d_context, i,
1070 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1072 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1074 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
1076 wined3d_mutex_unlock();
1079 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext1 *iface)
1081 FIXME("iface %p stub!\n", iface);
1084 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1085 ID3D11Buffer *buffer, UINT offset)
1087 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1088 struct d3d_buffer *d3d_buffer;
1090 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1092 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1094 wined3d_mutex_lock();
1095 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1096 wined3d_mutex_unlock();
1099 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1100 ID3D11Buffer *buffer, UINT offset)
1102 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1103 struct d3d_buffer *d3d_buffer;
1105 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1107 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1109 wined3d_mutex_lock();
1110 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1111 wined3d_mutex_unlock();
1114 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext1 *iface,
1115 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1117 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1119 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1120 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1122 wined3d_mutex_lock();
1123 wined3d_device_context_dispatch(context->wined3d_context,
1124 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1125 wined3d_mutex_unlock();
1128 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1129 ID3D11Buffer *buffer, UINT offset)
1131 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1132 struct d3d_buffer *buffer_impl;
1134 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1136 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1138 wined3d_mutex_lock();
1139 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1140 wined3d_mutex_unlock();
1143 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext1 *iface,
1144 ID3D11RasterizerState *rasterizer_state)
1146 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1147 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1148 struct d3d_rasterizer_state *rasterizer_state_impl;
1149 const D3D11_RASTERIZER_DESC *desc;
1151 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1153 wined3d_mutex_lock();
1154 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
1156 wined3d_device_context_set_rasterizer_state(context->wined3d_context, NULL);
1157 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1158 wined3d_mutex_unlock();
1159 return;
1162 wined3d_device_context_set_rasterizer_state(context->wined3d_context, rasterizer_state_impl->wined3d_state);
1164 desc = &rasterizer_state_impl->desc;
1165 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1166 wined3d_mutex_unlock();
1169 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1170 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1172 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1173 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1174 unsigned int i;
1176 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1178 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1179 return;
1181 for (i = 0; i < viewport_count; ++i)
1183 wined3d_vp[i].x = viewports[i].TopLeftX;
1184 wined3d_vp[i].y = viewports[i].TopLeftY;
1185 wined3d_vp[i].width = viewports[i].Width;
1186 wined3d_vp[i].height = viewports[i].Height;
1187 wined3d_vp[i].min_z = viewports[i].MinDepth;
1188 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1191 wined3d_mutex_lock();
1192 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1193 wined3d_mutex_unlock();
1196 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1197 UINT rect_count, const D3D11_RECT *rects)
1199 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1201 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1203 if (rect_count > WINED3D_MAX_VIEWPORTS)
1204 return;
1206 wined3d_mutex_lock();
1207 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1208 wined3d_mutex_unlock();
1211 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1212 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1213 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1215 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1216 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1217 struct wined3d_box wined3d_src_box;
1219 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1220 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1221 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1222 src_resource, src_subresource_idx, src_box);
1224 if (!dst_resource || !src_resource)
1225 return;
1227 if (src_box)
1228 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1229 src_box->right, src_box->bottom, src_box->front, src_box->back);
1231 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1232 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1233 wined3d_mutex_lock();
1234 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1235 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1236 wined3d_mutex_unlock();
1239 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext1 *iface,
1240 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1242 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1243 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1245 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1247 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1248 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1249 wined3d_mutex_lock();
1250 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1251 wined3d_mutex_unlock();
1254 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1255 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1256 const void *data, UINT row_pitch, UINT depth_pitch)
1258 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1259 struct wined3d_resource *wined3d_resource;
1260 struct wined3d_box wined3d_box;
1262 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1263 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1265 if (box)
1266 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1268 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1269 wined3d_mutex_lock();
1270 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1271 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1272 wined3d_mutex_unlock();
1275 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1276 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1278 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1279 struct d3d11_unordered_access_view *uav;
1280 struct d3d_buffer *buffer_impl;
1282 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1283 iface, dst_buffer, dst_offset, src_view);
1285 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1286 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1288 wined3d_mutex_lock();
1289 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1290 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1291 wined3d_mutex_unlock();
1294 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1295 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1297 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1298 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1299 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1300 HRESULT hr;
1302 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1303 iface, render_target_view, debug_float4(color_rgba));
1305 if (!view)
1306 return;
1308 wined3d_mutex_lock();
1309 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1310 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1311 ERR("Failed to clear view, hr %#x.\n", hr);
1312 wined3d_mutex_unlock();
1315 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1316 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1318 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1319 struct d3d11_unordered_access_view *view;
1321 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1322 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1324 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1325 wined3d_mutex_lock();
1326 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1327 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1328 wined3d_mutex_unlock();
1331 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1332 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1334 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1335 iface, unordered_access_view, debug_float4(values));
1338 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1339 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1341 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1342 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1343 DWORD wined3d_flags;
1344 HRESULT hr;
1346 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1347 iface, depth_stencil_view, flags, depth, stencil);
1349 if (!view)
1350 return;
1352 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1354 wined3d_mutex_lock();
1355 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1356 wined3d_flags, NULL, depth, stencil)))
1357 ERR("Failed to clear view, hr %#x.\n", hr);
1358 wined3d_mutex_unlock();
1361 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext1 *iface,
1362 ID3D11ShaderResourceView *view)
1364 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1365 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1367 TRACE("iface %p, view %p.\n", iface, view);
1369 wined3d_mutex_lock();
1370 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1371 wined3d_mutex_unlock();
1374 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1375 ID3D11Resource *resource, FLOAT min_lod)
1377 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1380 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1381 ID3D11Resource *resource)
1383 FIXME("iface %p, resource %p stub!\n", iface, resource);
1385 return 0.0f;
1388 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1389 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1390 ID3D11Resource *src_resource, UINT src_subresource_idx,
1391 DXGI_FORMAT format)
1393 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1394 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1395 enum wined3d_format_id wined3d_format;
1397 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1398 "src_resource %p, src_subresource_idx %u, format %s.\n",
1399 iface, dst_resource, dst_subresource_idx,
1400 src_resource, src_subresource_idx, debug_dxgi_format(format));
1402 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1403 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1404 wined3d_format = wined3dformat_from_dxgi_format(format);
1405 wined3d_mutex_lock();
1406 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1407 wined3d_dst_resource, dst_subresource_idx,
1408 wined3d_src_resource, src_subresource_idx, wined3d_format);
1409 wined3d_mutex_unlock();
1412 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1413 ID3D11CommandList *command_list, BOOL restore_state)
1415 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1418 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1419 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1421 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1422 unsigned int i;
1424 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1425 iface, start_slot, view_count, views);
1427 wined3d_mutex_lock();
1428 for (i = 0; i < view_count; ++i)
1430 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1432 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1433 start_slot + i, view ? view->wined3d_view : NULL);
1435 wined3d_mutex_unlock();
1438 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext1 *iface,
1439 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1441 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1442 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1444 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1445 iface, shader, class_instances, class_instance_count);
1447 if (class_instances)
1448 FIXME("Dynamic linking is not implemented yet.\n");
1450 wined3d_mutex_lock();
1451 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1452 hs ? hs->wined3d_shader : NULL);
1453 wined3d_mutex_unlock();
1456 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1457 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1459 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1460 unsigned int i;
1462 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1463 iface, start_slot, sampler_count, samplers);
1465 wined3d_mutex_lock();
1466 for (i = 0; i < sampler_count; ++i)
1468 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1470 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1471 sampler ? sampler->wined3d_sampler : NULL);
1473 wined3d_mutex_unlock();
1476 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1477 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1479 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1480 iface, start_slot, buffer_count, buffers);
1482 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1483 buffer_count, buffers);
1486 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1487 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1489 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1490 unsigned int i;
1492 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1493 iface, start_slot, view_count, views);
1495 wined3d_mutex_lock();
1496 for (i = 0; i < view_count; ++i)
1498 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1500 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1501 start_slot + i, view ? view->wined3d_view : NULL);
1503 wined3d_mutex_unlock();
1506 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext1 *iface,
1507 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1509 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1510 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1512 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1513 iface, shader, class_instances, class_instance_count);
1515 if (class_instances)
1516 FIXME("Dynamic linking is not implemented yet.\n");
1518 wined3d_mutex_lock();
1519 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1520 ds ? ds->wined3d_shader : NULL);
1521 wined3d_mutex_unlock();
1524 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1525 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1527 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1528 unsigned int i;
1530 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1531 iface, start_slot, sampler_count, samplers);
1533 wined3d_mutex_lock();
1534 for (i = 0; i < sampler_count; ++i)
1536 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1538 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1539 sampler ? sampler->wined3d_sampler : NULL);
1541 wined3d_mutex_unlock();
1544 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1545 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1547 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1548 iface, start_slot, buffer_count, buffers);
1550 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1551 buffer_count, buffers);
1554 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1555 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1557 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1558 unsigned int i;
1560 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1561 iface, start_slot, view_count, views);
1563 wined3d_mutex_lock();
1564 for (i = 0; i < view_count; ++i)
1566 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1568 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1569 start_slot + i, view ? view->wined3d_view : NULL);
1571 wined3d_mutex_unlock();
1574 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1575 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1577 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1578 unsigned int i;
1580 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1581 iface, start_slot, view_count, views, initial_counts);
1583 wined3d_mutex_lock();
1584 for (i = 0; i < view_count; ++i)
1586 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1588 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1589 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1591 wined3d_mutex_unlock();
1594 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext1 *iface,
1595 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1597 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1598 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1600 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1601 iface, shader, class_instances, class_instance_count);
1603 if (class_instances)
1604 FIXME("Dynamic linking is not implemented yet.\n");
1606 wined3d_mutex_lock();
1607 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1608 cs ? cs->wined3d_shader : NULL);
1609 wined3d_mutex_unlock();
1612 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1613 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1615 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1616 unsigned int i;
1618 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1619 iface, start_slot, sampler_count, samplers);
1621 wined3d_mutex_lock();
1622 for (i = 0; i < sampler_count; ++i)
1624 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1626 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1627 sampler ? sampler->wined3d_sampler : NULL);
1629 wined3d_mutex_unlock();
1632 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1633 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1635 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1636 iface, start_slot, buffer_count, buffers);
1638 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1639 buffer_count, buffers);
1642 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1643 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1645 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1646 iface, start_slot, buffer_count, buffers);
1648 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1649 buffer_count, buffers);
1652 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1653 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1655 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1656 unsigned int i;
1658 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1659 iface, start_slot, view_count, views);
1661 wined3d_mutex_lock();
1662 for (i = 0; i < view_count; ++i)
1664 struct wined3d_shader_resource_view *wined3d_view;
1665 struct d3d_shader_resource_view *view_impl;
1667 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1669 views[i] = NULL;
1670 continue;
1673 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1674 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1675 ID3D11ShaderResourceView_AddRef(views[i]);
1677 wined3d_mutex_unlock();
1680 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext1 *iface,
1681 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1683 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1684 struct wined3d_shader *wined3d_shader;
1685 struct d3d_pixel_shader *shader_impl;
1687 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1688 iface, shader, class_instances, class_instance_count);
1690 if (class_instances || class_instance_count)
1691 FIXME("Dynamic linking not implemented yet.\n");
1692 if (class_instance_count)
1693 *class_instance_count = 0;
1695 wined3d_mutex_lock();
1696 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1698 wined3d_mutex_unlock();
1699 *shader = NULL;
1700 return;
1703 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1704 wined3d_mutex_unlock();
1705 *shader = &shader_impl->ID3D11PixelShader_iface;
1706 ID3D11PixelShader_AddRef(*shader);
1709 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1710 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1712 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1713 unsigned int i;
1715 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1716 iface, start_slot, sampler_count, samplers);
1718 wined3d_mutex_lock();
1719 for (i = 0; i < sampler_count; ++i)
1721 struct wined3d_sampler *wined3d_sampler;
1722 struct d3d_sampler_state *sampler_impl;
1724 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1726 samplers[i] = NULL;
1727 continue;
1730 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1731 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1732 ID3D11SamplerState_AddRef(samplers[i]);
1734 wined3d_mutex_unlock();
1737 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext1 *iface,
1738 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1740 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1741 struct d3d_vertex_shader *shader_impl;
1742 struct wined3d_shader *wined3d_shader;
1744 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1745 iface, shader, class_instances, class_instance_count);
1747 if (class_instances || class_instance_count)
1748 FIXME("Dynamic linking not implemented yet.\n");
1749 if (class_instance_count)
1750 *class_instance_count = 0;
1752 wined3d_mutex_lock();
1753 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1755 wined3d_mutex_unlock();
1756 *shader = NULL;
1757 return;
1760 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1761 wined3d_mutex_unlock();
1762 *shader = &shader_impl->ID3D11VertexShader_iface;
1763 ID3D11VertexShader_AddRef(*shader);
1766 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1767 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1769 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1770 iface, start_slot, buffer_count, buffers);
1772 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1773 buffer_count, buffers);
1776 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1777 ID3D11InputLayout **input_layout)
1779 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1780 struct wined3d_vertex_declaration *wined3d_declaration;
1781 struct d3d_input_layout *input_layout_impl;
1783 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1785 wined3d_mutex_lock();
1786 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1788 wined3d_mutex_unlock();
1789 *input_layout = NULL;
1790 return;
1793 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1794 wined3d_mutex_unlock();
1795 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1796 ID3D11InputLayout_AddRef(*input_layout);
1799 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1800 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1802 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1803 unsigned int i;
1805 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1806 iface, start_slot, buffer_count, buffers, strides, offsets);
1808 wined3d_mutex_lock();
1809 for (i = 0; i < buffer_count; ++i)
1811 struct wined3d_buffer *wined3d_buffer = NULL;
1812 struct d3d_buffer *buffer_impl;
1814 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1815 &wined3d_buffer, &offsets[i], &strides[i])))
1817 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1818 if (strides)
1819 strides[i] = 0;
1820 if (offsets)
1821 offsets[i] = 0;
1824 if (!wined3d_buffer)
1826 buffers[i] = NULL;
1827 continue;
1830 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1831 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1833 wined3d_mutex_unlock();
1836 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1837 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1839 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1840 enum wined3d_format_id wined3d_format;
1841 struct wined3d_buffer *wined3d_buffer;
1842 struct d3d_buffer *buffer_impl;
1844 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1846 wined3d_mutex_lock();
1847 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1848 *format = dxgi_format_from_wined3dformat(wined3d_format);
1849 if (!wined3d_buffer)
1851 wined3d_mutex_unlock();
1852 *buffer = NULL;
1853 return;
1856 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1857 wined3d_mutex_unlock();
1858 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1861 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1862 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1864 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1865 iface, start_slot, buffer_count, buffers);
1867 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1868 buffer_count, buffers);
1871 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext1 *iface,
1872 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1874 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1875 struct d3d_geometry_shader *shader_impl;
1876 struct wined3d_shader *wined3d_shader;
1878 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1879 iface, shader, class_instances, class_instance_count);
1881 if (class_instances || class_instance_count)
1882 FIXME("Dynamic linking not implemented yet.\n");
1883 if (class_instance_count)
1884 *class_instance_count = 0;
1886 wined3d_mutex_lock();
1887 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1889 wined3d_mutex_unlock();
1890 *shader = NULL;
1891 return;
1894 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1895 wined3d_mutex_unlock();
1896 *shader = &shader_impl->ID3D11GeometryShader_iface;
1897 ID3D11GeometryShader_AddRef(*shader);
1900 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
1901 D3D11_PRIMITIVE_TOPOLOGY *topology)
1903 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1904 enum wined3d_primitive_type primitive_type;
1905 unsigned int patch_vertex_count;
1907 TRACE("iface %p, topology %p.\n", iface, topology);
1909 wined3d_mutex_lock();
1910 wined3d_device_get_primitive_type(device->wined3d_device, &primitive_type, &patch_vertex_count);
1911 wined3d_mutex_unlock();
1913 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1916 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
1917 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1919 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1920 unsigned int i;
1922 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1924 wined3d_mutex_lock();
1925 for (i = 0; i < view_count; ++i)
1927 struct wined3d_shader_resource_view *wined3d_view;
1928 struct d3d_shader_resource_view *view_impl;
1930 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1932 views[i] = NULL;
1933 continue;
1936 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1937 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1938 ID3D11ShaderResourceView_AddRef(views[i]);
1940 wined3d_mutex_unlock();
1943 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
1944 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1946 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1947 unsigned int i;
1949 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1950 iface, start_slot, sampler_count, samplers);
1952 wined3d_mutex_lock();
1953 for (i = 0; i < sampler_count; ++i)
1955 struct wined3d_sampler *wined3d_sampler;
1956 struct d3d_sampler_state *sampler_impl;
1958 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1960 samplers[i] = NULL;
1961 continue;
1964 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1965 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1966 ID3D11SamplerState_AddRef(samplers[i]);
1968 wined3d_mutex_unlock();
1971 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext1 *iface,
1972 ID3D11Predicate **predicate, BOOL *value)
1974 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1975 struct wined3d_query *wined3d_predicate;
1976 struct d3d_query *predicate_impl;
1978 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1980 wined3d_mutex_lock();
1981 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1983 wined3d_mutex_unlock();
1984 *predicate = NULL;
1985 return;
1988 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1989 wined3d_mutex_unlock();
1990 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1991 ID3D11Predicate_AddRef(*predicate);
1994 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
1995 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1997 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1998 unsigned int i;
2000 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2002 wined3d_mutex_lock();
2003 for (i = 0; i < view_count; ++i)
2005 struct wined3d_shader_resource_view *wined3d_view;
2006 struct d3d_shader_resource_view *view_impl;
2008 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
2010 views[i] = NULL;
2011 continue;
2014 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2015 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2016 ID3D11ShaderResourceView_AddRef(views[i]);
2018 wined3d_mutex_unlock();
2021 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2022 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2024 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2025 unsigned int i;
2027 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2028 iface, start_slot, sampler_count, samplers);
2030 wined3d_mutex_lock();
2031 for (i = 0; i < sampler_count; ++i)
2033 struct d3d_sampler_state *sampler_impl;
2034 struct wined3d_sampler *wined3d_sampler;
2036 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
2038 samplers[i] = NULL;
2039 continue;
2042 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2043 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2044 ID3D11SamplerState_AddRef(samplers[i]);
2046 wined3d_mutex_unlock();
2049 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2050 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2051 ID3D11DepthStencilView **depth_stencil_view)
2053 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2054 struct wined3d_rendertarget_view *wined3d_view;
2056 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2057 iface, render_target_view_count, render_target_views, depth_stencil_view);
2059 wined3d_mutex_lock();
2060 if (render_target_views)
2062 struct d3d_rendertarget_view *view_impl;
2063 unsigned int i;
2065 for (i = 0; i < render_target_view_count; ++i)
2067 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
2068 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2070 render_target_views[i] = NULL;
2071 continue;
2074 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2075 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2079 if (depth_stencil_view)
2081 struct d3d_depthstencil_view *view_impl;
2083 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
2084 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2086 *depth_stencil_view = NULL;
2088 else
2090 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2091 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2094 wined3d_mutex_unlock();
2097 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
2098 ID3D11DeviceContext1 *iface,
2099 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2100 ID3D11DepthStencilView **depth_stencil_view,
2101 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2102 ID3D11UnorderedAccessView **unordered_access_views)
2104 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2105 struct wined3d_unordered_access_view *wined3d_view;
2106 struct d3d11_unordered_access_view *view_impl;
2107 unsigned int i;
2109 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2110 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2111 "unordered_access_views %p.\n",
2112 iface, render_target_view_count, render_target_views, depth_stencil_view,
2113 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2115 if (render_target_views || depth_stencil_view)
2116 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
2117 render_target_views, depth_stencil_view);
2119 if (unordered_access_views)
2121 wined3d_mutex_lock();
2122 for (i = 0; i < unordered_access_view_count; ++i)
2124 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
2125 unordered_access_view_start_slot + i)))
2127 unordered_access_views[i] = NULL;
2128 continue;
2131 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2132 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2133 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2135 wined3d_mutex_unlock();
2139 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2140 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2142 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2143 struct wined3d_blend_state *wined3d_state;
2144 struct d3d_blend_state *blend_state_impl;
2146 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2147 iface, blend_state, blend_factor, sample_mask);
2149 wined3d_mutex_lock();
2150 if ((wined3d_state = wined3d_device_get_blend_state(device->wined3d_device,
2151 (struct wined3d_color *)blend_factor, sample_mask)))
2153 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2154 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2156 else
2158 *blend_state = NULL;
2160 wined3d_mutex_unlock();
2163 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2164 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2166 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2167 struct wined3d_depth_stencil_state *wined3d_state;
2168 struct d3d_depthstencil_state *state_impl;
2170 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2171 iface, depth_stencil_state, stencil_ref);
2173 wined3d_mutex_lock();
2174 if ((wined3d_state = wined3d_device_get_depth_stencil_state(device->wined3d_device, stencil_ref)))
2176 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2177 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2179 else
2181 *depth_stencil_state = NULL;
2183 wined3d_mutex_unlock();
2186 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2187 UINT buffer_count, ID3D11Buffer **buffers)
2189 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2190 unsigned int i;
2192 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2194 wined3d_mutex_lock();
2195 for (i = 0; i < buffer_count; ++i)
2197 struct wined3d_buffer *wined3d_buffer;
2198 struct d3d_buffer *buffer_impl;
2200 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
2202 buffers[i] = NULL;
2203 continue;
2206 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2207 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2208 ID3D11Buffer_AddRef(buffers[i]);
2210 wined3d_mutex_unlock();
2213 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext1 *iface,
2214 ID3D11RasterizerState **rasterizer_state)
2216 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2217 struct d3d_rasterizer_state *rasterizer_state_impl;
2218 struct wined3d_rasterizer_state *wined3d_state;
2220 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2222 wined3d_mutex_lock();
2223 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
2225 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2226 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2228 else
2230 *rasterizer_state = NULL;
2232 wined3d_mutex_unlock();
2235 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2236 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2238 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2239 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2240 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2242 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2244 if (!viewport_count)
2245 return;
2247 wined3d_mutex_lock();
2248 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
2249 wined3d_mutex_unlock();
2251 if (!viewports)
2253 *viewport_count = actual_count;
2254 return;
2257 if (*viewport_count > actual_count)
2258 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2260 *viewport_count = min(actual_count, *viewport_count);
2261 for (i = 0; i < *viewport_count; ++i)
2263 viewports[i].TopLeftX = wined3d_vp[i].x;
2264 viewports[i].TopLeftY = wined3d_vp[i].y;
2265 viewports[i].Width = wined3d_vp[i].width;
2266 viewports[i].Height = wined3d_vp[i].height;
2267 viewports[i].MinDepth = wined3d_vp[i].min_z;
2268 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2272 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2273 UINT *rect_count, D3D11_RECT *rects)
2275 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2276 unsigned int actual_count;
2278 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2280 if (!rect_count)
2281 return;
2283 actual_count = *rect_count;
2285 wined3d_mutex_lock();
2286 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
2287 wined3d_mutex_unlock();
2289 if (rects && *rect_count > actual_count)
2290 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2291 *rect_count = actual_count;
2294 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2295 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2297 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2298 unsigned int i;
2300 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2302 wined3d_mutex_lock();
2303 for (i = 0; i < view_count; ++i)
2305 struct wined3d_shader_resource_view *wined3d_view;
2306 struct d3d_shader_resource_view *view_impl;
2308 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2310 views[i] = NULL;
2311 continue;
2314 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2315 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2317 wined3d_mutex_unlock();
2320 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext1 *iface,
2321 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2323 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2324 struct d3d11_hull_shader *shader_impl;
2325 struct wined3d_shader *wined3d_shader;
2327 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2328 iface, shader, class_instances, class_instance_count);
2330 if (class_instances || class_instance_count)
2331 FIXME("Dynamic linking not implemented yet.\n");
2332 if (class_instance_count)
2333 *class_instance_count = 0;
2335 wined3d_mutex_lock();
2336 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2338 wined3d_mutex_unlock();
2339 *shader = NULL;
2340 return;
2343 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2344 wined3d_mutex_unlock();
2345 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2348 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2349 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2351 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2352 unsigned int i;
2354 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2355 iface, start_slot, sampler_count, samplers);
2357 wined3d_mutex_lock();
2358 for (i = 0; i < sampler_count; ++i)
2360 struct wined3d_sampler *wined3d_sampler;
2361 struct d3d_sampler_state *sampler_impl;
2363 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2365 samplers[i] = NULL;
2366 continue;
2369 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2370 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2372 wined3d_mutex_unlock();
2375 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2376 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2378 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2379 iface, start_slot, buffer_count, buffers);
2381 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2382 buffer_count, buffers);
2385 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2386 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2388 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2389 unsigned int i;
2391 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2392 iface, start_slot, view_count, views);
2394 wined3d_mutex_lock();
2395 for (i = 0; i < view_count; ++i)
2397 struct wined3d_shader_resource_view *wined3d_view;
2398 struct d3d_shader_resource_view *view_impl;
2400 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2402 views[i] = NULL;
2403 continue;
2406 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2407 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2409 wined3d_mutex_unlock();
2412 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext1 *iface,
2413 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2415 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2416 struct d3d11_domain_shader *shader_impl;
2417 struct wined3d_shader *wined3d_shader;
2419 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2420 iface, shader, class_instances, class_instance_count);
2422 if (class_instances || class_instance_count)
2423 FIXME("Dynamic linking not implemented yet.\n");
2424 if (class_instance_count)
2425 *class_instance_count = 0;
2427 wined3d_mutex_lock();
2428 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2430 wined3d_mutex_unlock();
2431 *shader = NULL;
2432 return;
2435 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2436 wined3d_mutex_unlock();
2437 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2440 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2441 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2443 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2444 unsigned int i;
2446 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2447 iface, start_slot, sampler_count, samplers);
2449 wined3d_mutex_lock();
2450 for (i = 0; i < sampler_count; ++i)
2452 struct wined3d_sampler *wined3d_sampler;
2453 struct d3d_sampler_state *sampler_impl;
2455 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2457 samplers[i] = NULL;
2458 continue;
2461 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2462 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2464 wined3d_mutex_unlock();
2467 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2468 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2470 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2471 iface, start_slot, buffer_count, buffers);
2473 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2474 buffer_count, buffers);
2477 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2478 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2480 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2481 unsigned int i;
2483 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2485 wined3d_mutex_lock();
2486 for (i = 0; i < view_count; ++i)
2488 struct wined3d_shader_resource_view *wined3d_view;
2489 struct d3d_shader_resource_view *view_impl;
2491 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2493 views[i] = NULL;
2494 continue;
2497 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2498 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2500 wined3d_mutex_unlock();
2503 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2504 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2506 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2507 unsigned int i;
2509 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2511 wined3d_mutex_lock();
2512 for (i = 0; i < view_count; ++i)
2514 struct wined3d_unordered_access_view *wined3d_view;
2515 struct d3d11_unordered_access_view *view_impl;
2517 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2519 views[i] = NULL;
2520 continue;
2523 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2524 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2526 wined3d_mutex_unlock();
2529 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext1 *iface,
2530 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2532 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2533 struct d3d11_compute_shader *shader_impl;
2534 struct wined3d_shader *wined3d_shader;
2536 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2537 iface, shader, class_instances, class_instance_count);
2539 if (class_instances || class_instance_count)
2540 FIXME("Dynamic linking not implemented yet.\n");
2541 if (class_instance_count)
2542 *class_instance_count = 0;
2544 wined3d_mutex_lock();
2545 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2547 wined3d_mutex_unlock();
2548 *shader = NULL;
2549 return;
2552 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2553 wined3d_mutex_unlock();
2554 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2557 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2558 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2560 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2561 unsigned int i;
2563 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2564 iface, start_slot, sampler_count, samplers);
2566 wined3d_mutex_lock();
2567 for (i = 0; i < sampler_count; ++i)
2569 struct wined3d_sampler *wined3d_sampler;
2570 struct d3d_sampler_state *sampler_impl;
2572 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2574 samplers[i] = NULL;
2575 continue;
2578 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2579 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2581 wined3d_mutex_unlock();
2584 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2585 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2587 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2588 iface, start_slot, buffer_count, buffers);
2590 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2591 buffer_count, buffers);
2594 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext1 *iface)
2596 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2597 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2598 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2599 unsigned int i, j;
2601 TRACE("iface %p.\n", iface);
2603 wined3d_mutex_lock();
2604 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
2606 wined3d_device_context_set_shader(context->wined3d_context, i, NULL);
2607 for (j = 0; j < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++j)
2608 wined3d_device_context_set_constant_buffer(context->wined3d_context, i, j, NULL);
2609 for (j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++j)
2610 wined3d_device_context_set_shader_resource_view(context->wined3d_context, i, j, NULL);
2611 for (j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++j)
2612 wined3d_device_context_set_sampler(context->wined3d_context, i, j, NULL);
2614 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2616 wined3d_device_context_set_stream_source(context->wined3d_context, i, NULL, 0, 0);
2618 wined3d_device_context_set_index_buffer(context->wined3d_context, NULL, WINED3DFMT_UNKNOWN, 0);
2619 wined3d_device_context_set_vertex_declaration(context->wined3d_context, NULL);
2620 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED, 0);
2621 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2623 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
2625 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, NULL);
2626 for (i = 0; i < WINED3D_PIPELINE_COUNT; ++i)
2628 for (j = 0; j < D3D11_PS_CS_UAV_REGISTER_COUNT; ++j)
2629 wined3d_device_context_set_unordered_access_view(context->wined3d_context, i, j, NULL, ~0u);
2631 ID3D11DeviceContext1_OMSetDepthStencilState(iface, NULL, 0);
2632 ID3D11DeviceContext1_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2633 ID3D11DeviceContext1_RSSetViewports(iface, 0, NULL);
2634 ID3D11DeviceContext1_RSSetScissorRects(iface, 0, NULL);
2635 ID3D11DeviceContext1_RSSetState(iface, NULL);
2636 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2638 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
2640 wined3d_device_context_set_predication(context->wined3d_context, NULL, FALSE);
2641 wined3d_mutex_unlock();
2644 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext1 *iface)
2646 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2648 TRACE("iface %p.\n", iface);
2650 wined3d_mutex_lock();
2651 wined3d_device_flush(device->wined3d_device);
2652 wined3d_mutex_unlock();
2655 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext1 *iface)
2657 TRACE("iface %p.\n", iface);
2659 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2662 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2664 TRACE("iface %p.\n", iface);
2666 return 0;
2669 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2670 BOOL restore, ID3D11CommandList **command_list)
2672 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2674 return DXGI_ERROR_INVALID_CALL;
2677 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2678 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2679 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2681 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2682 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2683 struct wined3d_box wined3d_src_box;
2685 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2686 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2687 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2688 src_resource, src_subresource_idx, src_box, flags);
2690 if (!dst_resource || !src_resource)
2691 return;
2693 if (src_box)
2694 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2695 src_box->right, src_box->bottom, src_box->front, src_box->back);
2697 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2698 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2699 wined3d_mutex_lock();
2700 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2701 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2702 wined3d_mutex_unlock();
2705 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2706 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2707 UINT row_pitch, UINT depth_pitch, UINT flags)
2709 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2710 struct wined3d_resource *wined3d_resource;
2711 struct wined3d_box wined3d_box;
2713 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2714 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2716 if (box)
2717 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2718 box->front, box->back);
2720 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2721 wined3d_mutex_lock();
2722 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2723 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2724 wined3d_mutex_unlock();
2727 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardResource(ID3D11DeviceContext1 *iface,
2728 ID3D11Resource *resource)
2730 FIXME("iface %p, resource %p stub!\n", iface, resource);
2733 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2735 FIXME("iface %p, view %p stub!\n", iface, view);
2738 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2739 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2740 const UINT *num_constants)
2742 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2743 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2746 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2747 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2748 const UINT *num_constants)
2750 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2751 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2754 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2755 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2756 const UINT *num_constants)
2758 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2759 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2762 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2763 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2764 const UINT *num_constants)
2766 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2767 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2770 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2771 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2772 const UINT *num_constants)
2774 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2775 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2778 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2779 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2780 const UINT *num_constants)
2782 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2783 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2786 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2787 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2789 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2790 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2793 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2794 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2796 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2797 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2800 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2801 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2803 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2804 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2807 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2808 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2810 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2811 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2814 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2815 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2817 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2818 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2821 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2822 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2824 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2825 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2828 static void STDMETHODCALLTYPE d3d11_immediate_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2829 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2831 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2832 struct d3d_device_context_state *state_impl, *prev_impl;
2833 struct wined3d_state *wined3d_state;
2835 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2837 if (!state)
2839 if (prev)
2840 *prev = NULL;
2841 return;
2844 wined3d_mutex_lock();
2846 prev_impl = device->state;
2847 state_impl = impl_from_ID3DDeviceContextState(state);
2848 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2849 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2850 wined3d_device_set_state(device->wined3d_device, wined3d_state);
2852 if (prev)
2853 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2855 d3d_device_context_state_private_addref(state_impl);
2856 device->state = state_impl;
2857 d3d_device_context_state_private_release(prev_impl);
2859 if (d3d_device_is_d3d10_active(device))
2860 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2861 wined3d_mutex_unlock();
2864 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2865 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2867 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2870 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2871 const D3D11_RECT *rects, UINT num_rects)
2873 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
2876 static const struct ID3D11DeviceContext1Vtbl d3d11_immediate_context_vtbl =
2878 /* IUnknown methods */
2879 d3d11_immediate_context_QueryInterface,
2880 d3d11_immediate_context_AddRef,
2881 d3d11_immediate_context_Release,
2882 /* ID3D11DeviceChild methods */
2883 d3d11_immediate_context_GetDevice,
2884 d3d11_immediate_context_GetPrivateData,
2885 d3d11_immediate_context_SetPrivateData,
2886 d3d11_immediate_context_SetPrivateDataInterface,
2887 /* ID3D11DeviceContext methods */
2888 d3d11_immediate_context_VSSetConstantBuffers,
2889 d3d11_immediate_context_PSSetShaderResources,
2890 d3d11_immediate_context_PSSetShader,
2891 d3d11_immediate_context_PSSetSamplers,
2892 d3d11_immediate_context_VSSetShader,
2893 d3d11_immediate_context_DrawIndexed,
2894 d3d11_immediate_context_Draw,
2895 d3d11_immediate_context_Map,
2896 d3d11_immediate_context_Unmap,
2897 d3d11_immediate_context_PSSetConstantBuffers,
2898 d3d11_immediate_context_IASetInputLayout,
2899 d3d11_immediate_context_IASetVertexBuffers,
2900 d3d11_immediate_context_IASetIndexBuffer,
2901 d3d11_immediate_context_DrawIndexedInstanced,
2902 d3d11_immediate_context_DrawInstanced,
2903 d3d11_immediate_context_GSSetConstantBuffers,
2904 d3d11_immediate_context_GSSetShader,
2905 d3d11_immediate_context_IASetPrimitiveTopology,
2906 d3d11_immediate_context_VSSetShaderResources,
2907 d3d11_immediate_context_VSSetSamplers,
2908 d3d11_immediate_context_Begin,
2909 d3d11_immediate_context_End,
2910 d3d11_immediate_context_GetData,
2911 d3d11_immediate_context_SetPredication,
2912 d3d11_immediate_context_GSSetShaderResources,
2913 d3d11_immediate_context_GSSetSamplers,
2914 d3d11_immediate_context_OMSetRenderTargets,
2915 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2916 d3d11_immediate_context_OMSetBlendState,
2917 d3d11_immediate_context_OMSetDepthStencilState,
2918 d3d11_immediate_context_SOSetTargets,
2919 d3d11_immediate_context_DrawAuto,
2920 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2921 d3d11_immediate_context_DrawInstancedIndirect,
2922 d3d11_immediate_context_Dispatch,
2923 d3d11_immediate_context_DispatchIndirect,
2924 d3d11_immediate_context_RSSetState,
2925 d3d11_immediate_context_RSSetViewports,
2926 d3d11_immediate_context_RSSetScissorRects,
2927 d3d11_immediate_context_CopySubresourceRegion,
2928 d3d11_immediate_context_CopyResource,
2929 d3d11_immediate_context_UpdateSubresource,
2930 d3d11_immediate_context_CopyStructureCount,
2931 d3d11_immediate_context_ClearRenderTargetView,
2932 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2933 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2934 d3d11_immediate_context_ClearDepthStencilView,
2935 d3d11_immediate_context_GenerateMips,
2936 d3d11_immediate_context_SetResourceMinLOD,
2937 d3d11_immediate_context_GetResourceMinLOD,
2938 d3d11_immediate_context_ResolveSubresource,
2939 d3d11_immediate_context_ExecuteCommandList,
2940 d3d11_immediate_context_HSSetShaderResources,
2941 d3d11_immediate_context_HSSetShader,
2942 d3d11_immediate_context_HSSetSamplers,
2943 d3d11_immediate_context_HSSetConstantBuffers,
2944 d3d11_immediate_context_DSSetShaderResources,
2945 d3d11_immediate_context_DSSetShader,
2946 d3d11_immediate_context_DSSetSamplers,
2947 d3d11_immediate_context_DSSetConstantBuffers,
2948 d3d11_immediate_context_CSSetShaderResources,
2949 d3d11_immediate_context_CSSetUnorderedAccessViews,
2950 d3d11_immediate_context_CSSetShader,
2951 d3d11_immediate_context_CSSetSamplers,
2952 d3d11_immediate_context_CSSetConstantBuffers,
2953 d3d11_immediate_context_VSGetConstantBuffers,
2954 d3d11_immediate_context_PSGetShaderResources,
2955 d3d11_immediate_context_PSGetShader,
2956 d3d11_immediate_context_PSGetSamplers,
2957 d3d11_immediate_context_VSGetShader,
2958 d3d11_immediate_context_PSGetConstantBuffers,
2959 d3d11_immediate_context_IAGetInputLayout,
2960 d3d11_immediate_context_IAGetVertexBuffers,
2961 d3d11_immediate_context_IAGetIndexBuffer,
2962 d3d11_immediate_context_GSGetConstantBuffers,
2963 d3d11_immediate_context_GSGetShader,
2964 d3d11_immediate_context_IAGetPrimitiveTopology,
2965 d3d11_immediate_context_VSGetShaderResources,
2966 d3d11_immediate_context_VSGetSamplers,
2967 d3d11_immediate_context_GetPredication,
2968 d3d11_immediate_context_GSGetShaderResources,
2969 d3d11_immediate_context_GSGetSamplers,
2970 d3d11_immediate_context_OMGetRenderTargets,
2971 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2972 d3d11_immediate_context_OMGetBlendState,
2973 d3d11_immediate_context_OMGetDepthStencilState,
2974 d3d11_immediate_context_SOGetTargets,
2975 d3d11_immediate_context_RSGetState,
2976 d3d11_immediate_context_RSGetViewports,
2977 d3d11_immediate_context_RSGetScissorRects,
2978 d3d11_immediate_context_HSGetShaderResources,
2979 d3d11_immediate_context_HSGetShader,
2980 d3d11_immediate_context_HSGetSamplers,
2981 d3d11_immediate_context_HSGetConstantBuffers,
2982 d3d11_immediate_context_DSGetShaderResources,
2983 d3d11_immediate_context_DSGetShader,
2984 d3d11_immediate_context_DSGetSamplers,
2985 d3d11_immediate_context_DSGetConstantBuffers,
2986 d3d11_immediate_context_CSGetShaderResources,
2987 d3d11_immediate_context_CSGetUnorderedAccessViews,
2988 d3d11_immediate_context_CSGetShader,
2989 d3d11_immediate_context_CSGetSamplers,
2990 d3d11_immediate_context_CSGetConstantBuffers,
2991 d3d11_immediate_context_ClearState,
2992 d3d11_immediate_context_Flush,
2993 d3d11_immediate_context_GetType,
2994 d3d11_immediate_context_GetContextFlags,
2995 d3d11_immediate_context_FinishCommandList,
2996 /* ID3D11DeviceContext1 methods */
2997 d3d11_immediate_context_CopySubresourceRegion1,
2998 d3d11_immediate_context_UpdateSubresource1,
2999 d3d11_immediate_context_DiscardResource,
3000 d3d11_immediate_context_DiscardView,
3001 d3d11_immediate_context_VSSetConstantBuffers1,
3002 d3d11_immediate_context_HSSetConstantBuffers1,
3003 d3d11_immediate_context_DSSetConstantBuffers1,
3004 d3d11_immediate_context_GSSetConstantBuffers1,
3005 d3d11_immediate_context_PSSetConstantBuffers1,
3006 d3d11_immediate_context_CSSetConstantBuffers1,
3007 d3d11_immediate_context_VSGetConstantBuffers1,
3008 d3d11_immediate_context_HSGetConstantBuffers1,
3009 d3d11_immediate_context_DSGetConstantBuffers1,
3010 d3d11_immediate_context_GSGetConstantBuffers1,
3011 d3d11_immediate_context_PSGetConstantBuffers1,
3012 d3d11_immediate_context_CSGetConstantBuffers1,
3013 d3d11_immediate_context_SwapDeviceContextState,
3014 d3d11_immediate_context_ClearView,
3015 d3d11_immediate_context_DiscardView1,
3018 /* ID3D11Multithread methods */
3020 static inline struct d3d11_immediate_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3022 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11Multithread_iface);
3025 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3026 REFIID iid, void **out)
3028 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3030 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3032 return d3d11_immediate_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3035 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3037 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3039 TRACE("iface %p.\n", iface);
3041 return d3d11_immediate_context_AddRef(&context->ID3D11DeviceContext1_iface);
3044 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3046 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3048 TRACE("iface %p.\n", iface);
3050 return d3d11_immediate_context_Release(&context->ID3D11DeviceContext1_iface);
3053 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3055 TRACE("iface %p.\n", iface);
3057 wined3d_mutex_lock();
3060 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3062 TRACE("iface %p.\n", iface);
3064 wined3d_mutex_unlock();
3067 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3068 ID3D11Multithread *iface, BOOL enable)
3070 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3072 return TRUE;
3075 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3077 FIXME("iface %p stub!\n", iface);
3079 return TRUE;
3082 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3084 d3d11_multithread_QueryInterface,
3085 d3d11_multithread_AddRef,
3086 d3d11_multithread_Release,
3087 d3d11_multithread_Enter,
3088 d3d11_multithread_Leave,
3089 d3d11_multithread_SetMultithreadProtected,
3090 d3d11_multithread_GetMultithreadProtected,
3093 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
3095 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_immediate_context_vtbl;
3096 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3097 context->refcount = 1;
3099 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3101 wined3d_private_store_init(&context->private_store);
3104 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
3106 wined3d_private_store_cleanup(&context->private_store);
3109 /* ID3D11Device methods */
3111 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3113 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3114 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3117 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3119 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3120 return IUnknown_AddRef(device->outer_unk);
3123 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3125 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3126 return IUnknown_Release(device->outer_unk);
3129 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3130 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3132 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3133 struct d3d_buffer *object;
3134 HRESULT hr;
3136 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3138 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3139 return hr;
3141 *buffer = &object->ID3D11Buffer_iface;
3143 return S_OK;
3146 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3147 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3149 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3150 struct d3d_texture1d *object;
3151 HRESULT hr;
3153 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3155 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3156 return hr;
3158 *texture = &object->ID3D11Texture1D_iface;
3160 return S_OK;
3163 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3164 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3166 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3167 struct d3d_texture2d *object;
3168 HRESULT hr;
3170 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3172 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3173 return hr;
3175 *texture = &object->ID3D11Texture2D_iface;
3177 return S_OK;
3180 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3181 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3183 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3184 struct d3d_texture3d *object;
3185 HRESULT hr;
3187 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3189 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3190 return hr;
3192 *texture = &object->ID3D11Texture3D_iface;
3194 return S_OK;
3197 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3198 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3200 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3201 struct d3d_shader_resource_view *object;
3202 HRESULT hr;
3204 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3206 if (!resource)
3207 return E_INVALIDARG;
3209 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3210 return hr;
3212 *view = &object->ID3D11ShaderResourceView_iface;
3214 return S_OK;
3217 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3218 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3220 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3221 struct d3d11_unordered_access_view *object;
3222 HRESULT hr;
3224 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3226 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3227 return hr;
3229 *view = &object->ID3D11UnorderedAccessView_iface;
3231 return S_OK;
3234 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3235 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3237 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3238 struct d3d_rendertarget_view *object;
3239 HRESULT hr;
3241 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3243 if (!resource)
3244 return E_INVALIDARG;
3246 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3247 return hr;
3249 *view = &object->ID3D11RenderTargetView_iface;
3251 return S_OK;
3254 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3255 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3257 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3258 struct d3d_depthstencil_view *object;
3259 HRESULT hr;
3261 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3263 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3264 return hr;
3266 *view = &object->ID3D11DepthStencilView_iface;
3268 return S_OK;
3271 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3272 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3273 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3275 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3276 struct d3d_input_layout *object;
3277 HRESULT hr;
3279 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3280 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3281 shader_byte_code_length, input_layout);
3283 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3284 shader_byte_code, shader_byte_code_length, &object)))
3285 return hr;
3287 *input_layout = &object->ID3D11InputLayout_iface;
3289 return S_OK;
3292 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3293 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3295 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3296 struct d3d_vertex_shader *object;
3297 HRESULT hr;
3299 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3300 iface, byte_code, byte_code_length, class_linkage, shader);
3302 if (class_linkage)
3303 FIXME("Class linkage is not implemented yet.\n");
3305 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3306 return hr;
3308 *shader = &object->ID3D11VertexShader_iface;
3310 return S_OK;
3313 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3314 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3316 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3317 struct d3d_geometry_shader *object;
3318 HRESULT hr;
3320 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3321 iface, byte_code, byte_code_length, class_linkage, shader);
3323 if (class_linkage)
3324 FIXME("Class linkage is not implemented yet.\n");
3326 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3327 NULL, 0, NULL, 0, 0, &object)))
3328 return hr;
3330 *shader = &object->ID3D11GeometryShader_iface;
3332 return S_OK;
3335 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3336 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3337 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3338 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3340 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3341 struct d3d_geometry_shader *object;
3342 HRESULT hr;
3344 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3345 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3346 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3347 rasterizer_stream, class_linkage, shader);
3349 if (class_linkage)
3350 FIXME("Class linkage is not implemented yet.\n");
3352 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3353 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3355 *shader = NULL;
3356 return hr;
3359 *shader = &object->ID3D11GeometryShader_iface;
3361 return hr;
3364 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3365 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3367 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3368 struct d3d_pixel_shader *object;
3369 HRESULT hr;
3371 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3372 iface, byte_code, byte_code_length, class_linkage, shader);
3374 if (class_linkage)
3375 FIXME("Class linkage is not implemented yet.\n");
3377 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3378 return hr;
3380 *shader = &object->ID3D11PixelShader_iface;
3382 return S_OK;
3385 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3386 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3388 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3389 struct d3d11_hull_shader *object;
3390 HRESULT hr;
3392 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3393 iface, byte_code, byte_code_length, class_linkage, shader);
3395 if (class_linkage)
3396 FIXME("Class linkage is not implemented yet.\n");
3398 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3399 return hr;
3401 *shader = &object->ID3D11HullShader_iface;
3403 return S_OK;
3406 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3407 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3409 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3410 struct d3d11_domain_shader *object;
3411 HRESULT hr;
3413 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3414 iface, byte_code, byte_code_length, class_linkage, shader);
3416 if (class_linkage)
3417 FIXME("Class linkage is not implemented yet.\n");
3419 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3420 return hr;
3422 *shader = &object->ID3D11DomainShader_iface;
3424 return S_OK;
3427 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3428 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3430 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3431 struct d3d11_compute_shader *object;
3432 HRESULT hr;
3434 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3435 iface, byte_code, byte_code_length, class_linkage, shader);
3437 if (class_linkage)
3438 FIXME("Class linkage is not implemented yet.\n");
3440 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3441 return hr;
3443 *shader = &object->ID3D11ComputeShader_iface;
3445 return S_OK;
3448 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3449 ID3D11ClassLinkage **class_linkage)
3451 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3452 struct d3d11_class_linkage *object;
3453 HRESULT hr;
3455 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3457 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3458 return hr;
3460 *class_linkage = &object->ID3D11ClassLinkage_iface;
3462 return S_OK;
3465 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3466 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3468 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3469 struct d3d_blend_state *object;
3470 HRESULT hr;
3472 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3474 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3475 return hr;
3477 *blend_state = &object->ID3D11BlendState_iface;
3479 return S_OK;
3482 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3483 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3485 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3486 struct d3d_depthstencil_state *object;
3487 HRESULT hr;
3489 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3491 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3492 return hr;
3494 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3496 return S_OK;
3499 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3500 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3502 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3503 struct d3d_rasterizer_state *object;
3504 HRESULT hr;
3506 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3508 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3509 return hr;
3511 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3513 return S_OK;
3516 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3517 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3519 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3520 struct d3d_sampler_state *object;
3521 HRESULT hr;
3523 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3525 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3526 return hr;
3528 *sampler_state = &object->ID3D11SamplerState_iface;
3530 return S_OK;
3533 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3534 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3536 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3537 struct d3d_query *object;
3538 HRESULT hr;
3540 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3542 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3543 return hr;
3545 if (query)
3547 *query = &object->ID3D11Query_iface;
3548 return S_OK;
3551 ID3D11Query_Release(&object->ID3D11Query_iface);
3552 return S_FALSE;
3555 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3556 ID3D11Predicate **predicate)
3558 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3559 struct d3d_query *object;
3560 HRESULT hr;
3562 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3564 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3565 return hr;
3567 if (predicate)
3569 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3570 return S_OK;
3573 ID3D11Query_Release(&object->ID3D11Query_iface);
3574 return S_FALSE;
3577 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3578 ID3D11Counter **counter)
3580 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3582 return E_NOTIMPL;
3585 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3586 ID3D11DeviceContext **context)
3588 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3590 *context = NULL;
3591 return E_NOTIMPL;
3594 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3595 void **out)
3597 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3599 return E_NOTIMPL;
3602 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3603 UINT *format_support)
3605 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3606 struct wined3d_device_creation_parameters params;
3607 struct wined3d_adapter *wined3d_adapter;
3608 enum wined3d_format_id wined3d_format;
3609 D3D_FEATURE_LEVEL feature_level;
3610 struct wined3d *wined3d;
3611 unsigned int i;
3613 static const struct
3615 enum wined3d_resource_type rtype;
3616 unsigned int bind_flags;
3617 unsigned int usage;
3618 D3D11_FORMAT_SUPPORT flag;
3620 flag_mapping[] =
3622 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3623 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3624 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3625 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3626 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3627 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3628 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3629 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3630 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3631 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3633 HRESULT hr;
3635 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3637 wined3d_format = wined3dformat_from_dxgi_format(format);
3638 if (format && !wined3d_format)
3640 WARN("Invalid format %#x.\n", format);
3641 *format_support = 0;
3642 return E_FAIL;
3645 *format_support = 0;
3647 wined3d_mutex_lock();
3648 feature_level = device->state->feature_level;
3649 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3650 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3651 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3652 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3654 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3655 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3656 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3657 continue;
3658 if (hr != WINED3D_OK)
3660 WARN("Failed to check device format support, hr %#x.\n", hr);
3661 wined3d_mutex_unlock();
3662 return E_FAIL;
3665 *format_support |= flag_mapping[i].flag;
3667 wined3d_mutex_unlock();
3669 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3670 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3672 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3673 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3675 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3676 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3677 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3679 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3680 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3682 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3684 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3685 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3687 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3688 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3692 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3693 * support multisample. */
3694 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3695 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3696 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3697 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3699 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3700 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3701 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3704 return S_OK;
3707 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3708 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3710 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3711 struct wined3d_device_creation_parameters params;
3712 struct wined3d_adapter *wined3d_adapter;
3713 struct wined3d *wined3d;
3714 HRESULT hr;
3716 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3717 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3719 if (!quality_level_count)
3720 return E_INVALIDARG;
3722 *quality_level_count = 0;
3724 if (!sample_count)
3725 return E_FAIL;
3726 if (sample_count == 1)
3728 *quality_level_count = 1;
3729 return S_OK;
3731 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3732 return E_FAIL;
3734 wined3d_mutex_lock();
3735 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3736 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3737 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3738 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3739 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3740 wined3d_mutex_unlock();
3742 if (hr == WINED3DERR_INVALIDCALL)
3743 return E_INVALIDARG;
3744 if (hr == WINED3DERR_NOTAVAILABLE)
3745 return S_OK;
3746 return hr;
3749 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3751 FIXME("iface %p, info %p stub!\n", iface, info);
3754 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3755 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3756 char *units, UINT *units_length, char *description, UINT *description_length)
3758 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3759 "units %p, units_length %p, description %p, description_length %p stub!\n",
3760 iface, desc, type, active_counter_count, name, name_length,
3761 units, units_length, description, description_length);
3763 return E_NOTIMPL;
3766 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3767 void *feature_support_data, UINT feature_support_data_size)
3769 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3770 struct wined3d_caps wined3d_caps;
3771 HRESULT hr;
3773 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3774 iface, feature, feature_support_data, feature_support_data_size);
3776 switch (feature)
3778 case D3D11_FEATURE_THREADING:
3780 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3781 if (feature_support_data_size != sizeof(*threading_data))
3783 WARN("Invalid data size.\n");
3784 return E_INVALIDARG;
3787 /* We lie about the threading support to make Tomb Raider 2013 and
3788 * Deus Ex: Human Revolution happy. */
3789 FIXME("Returning fake threading support data.\n");
3790 threading_data->DriverConcurrentCreates = TRUE;
3791 threading_data->DriverCommandLists = TRUE;
3792 return S_OK;
3795 case D3D11_FEATURE_DOUBLES:
3797 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3798 if (feature_support_data_size != sizeof(*doubles_data))
3800 WARN("Invalid data size.\n");
3801 return E_INVALIDARG;
3804 wined3d_mutex_lock();
3805 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3806 wined3d_mutex_unlock();
3807 if (FAILED(hr))
3809 WARN("Failed to get device caps, hr %#x.\n", hr);
3810 return hr;
3813 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3814 return S_OK;
3817 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3819 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3820 if (feature_support_data_size != sizeof(*options))
3822 WARN("Invalid data size.\n");
3823 return E_INVALIDARG;
3826 wined3d_mutex_lock();
3827 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3828 wined3d_mutex_unlock();
3829 if (FAILED(hr))
3831 WARN("Failed to get device caps, hr %#x.\n", hr);
3832 return hr;
3835 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
3836 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
3837 return S_OK;
3840 case D3D11_FEATURE_D3D11_OPTIONS:
3842 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
3843 if (feature_support_data_size != sizeof(*options))
3845 WARN("Invalid data size.\n");
3846 return E_INVALIDARG;
3849 FIXME("Returning fake Options support data.\n");
3850 options->OutputMergerLogicOp = FALSE;
3851 options->UAVOnlyRenderingForcedSampleCount = FALSE;
3852 options->DiscardAPIsSeenByDriver = FALSE;
3853 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
3854 options->ClearView = FALSE;
3855 options->CopyWithOverlap = FALSE;
3856 options->ConstantBufferPartialUpdate = FALSE;
3857 options->ConstantBufferOffsetting = FALSE;
3858 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
3859 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
3860 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
3861 options->SAD4ShaderInstructions = FALSE;
3862 options->ExtendedDoublesShaderInstructions = FALSE;
3863 options->ExtendedResourceSharing = FALSE;
3864 return S_OK;
3867 case D3D11_FEATURE_D3D11_OPTIONS1:
3869 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
3870 if (feature_support_data_size != sizeof(*options))
3872 WARN("Invalid data size.\n");
3873 return E_INVALIDARG;
3876 FIXME("Returning fake Options1 support data.\n");
3877 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
3878 options->MinMaxFiltering = FALSE;
3879 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
3880 options->MapOnDefaultBuffers = FALSE;
3881 return S_OK;
3884 case D3D11_FEATURE_D3D11_OPTIONS3:
3886 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
3887 if (feature_support_data_size != sizeof(*options))
3889 WARN("Invalid data size.\n");
3890 return E_INVALIDARG;
3893 wined3d_mutex_lock();
3894 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3895 wined3d_mutex_unlock();
3896 if (FAILED(hr))
3898 WARN("Failed to get device caps, hr %#x.\n", hr);
3899 return hr;
3902 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
3903 = wined3d_caps.viewport_array_index_any_shader;
3904 return S_OK;
3907 case D3D11_FEATURE_ARCHITECTURE_INFO:
3909 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
3910 if (feature_support_data_size != sizeof(*options))
3912 WARN("Invalid data size.\n");
3913 return E_INVALIDARG;
3916 FIXME("Returning fake data architecture info.\n");
3917 options->TileBasedDeferredRenderer = FALSE;
3918 return S_OK;
3921 default:
3922 FIXME("Unhandled feature %#x.\n", feature);
3923 return E_NOTIMPL;
3927 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3928 UINT *data_size, void *data)
3930 IDXGIDevice *dxgi_device;
3931 HRESULT hr;
3933 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3935 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3936 return hr;
3937 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3938 IDXGIDevice_Release(dxgi_device);
3940 return hr;
3943 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3944 UINT data_size, const void *data)
3946 IDXGIDevice *dxgi_device;
3947 HRESULT hr;
3949 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3951 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3952 return hr;
3953 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3954 IDXGIDevice_Release(dxgi_device);
3956 return hr;
3959 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
3960 const IUnknown *data)
3962 IDXGIDevice *dxgi_device;
3963 HRESULT hr;
3965 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3967 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3968 return hr;
3969 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3970 IDXGIDevice_Release(dxgi_device);
3972 return hr;
3975 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
3977 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3979 TRACE("iface %p.\n", iface);
3981 return device->state->feature_level;
3984 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
3986 FIXME("iface %p stub!\n", iface);
3988 return 0;
3991 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
3993 WARN("iface %p stub!\n", iface);
3995 return S_OK;
3998 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
3999 ID3D11DeviceContext **immediate_context)
4001 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4003 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4005 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4006 ID3D11DeviceContext_AddRef(*immediate_context);
4009 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4011 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4013 return E_NOTIMPL;
4016 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4018 FIXME("iface %p stub!\n", iface);
4020 return 0;
4023 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4024 ID3D11DeviceContext1 **immediate_context)
4026 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4028 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4030 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4031 ID3D11DeviceContext1_AddRef(*immediate_context);
4034 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4035 ID3D11DeviceContext1 **context)
4037 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4039 return E_NOTIMPL;
4042 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4043 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4045 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4047 return E_NOTIMPL;
4050 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4051 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4053 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4055 return E_NOTIMPL;
4058 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4059 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4060 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4062 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4063 struct d3d_device_context_state *state_impl;
4064 struct wined3d_state *wined3d_state;
4065 D3D_FEATURE_LEVEL feature_level;
4066 HRESULT hr = E_INVALIDARG;
4068 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4069 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4070 iface, flags, feature_levels, feature_level_count,
4071 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4073 if (flags)
4074 FIXME("Ignoring flags %#x.\n", flags);
4076 wined3d_mutex_lock();
4078 if (!feature_level_count)
4079 goto fail;
4081 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4082 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4083 goto fail;
4084 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4086 if (chosen_feature_level)
4087 *chosen_feature_level = feature_level;
4089 if (!state)
4091 wined3d_state_destroy(wined3d_state);
4092 wined3d_mutex_unlock();
4093 return S_FALSE;
4096 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4098 wined3d_state_destroy(wined3d_state);
4099 hr = E_OUTOFMEMORY;
4100 goto fail;
4103 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4104 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4106 wined3d_state_destroy(wined3d_state);
4107 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4108 hr = E_FAIL;
4109 goto fail;
4112 *state = &state_impl->ID3DDeviceContextState_iface;
4113 device->d3d11_only = FALSE;
4114 wined3d_mutex_unlock();
4116 return S_OK;
4118 fail:
4119 wined3d_mutex_unlock();
4120 if (chosen_feature_level)
4121 *chosen_feature_level = 0;
4122 if (state)
4123 *state = NULL;
4124 return hr;
4127 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4128 REFIID iid, void **resource)
4130 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4132 return E_NOTIMPL;
4135 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4136 DWORD access, REFIID iid, void **resource)
4138 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4139 debugstr_guid(iid), resource);
4141 return E_NOTIMPL;
4144 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4145 ID3D11DeviceContext2 **context)
4147 FIXME("iface %p, context %p stub!\n", iface, context);
4150 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4151 UINT flags, ID3D11DeviceContext2 **context)
4153 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4155 return E_NOTIMPL;
4158 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4159 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4160 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4161 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4163 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4164 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4165 iface, resource, tile_count, mip_desc, tile_shape,
4166 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4169 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4170 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4172 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4173 iface, format, sample_count, flags, quality_level_count);
4175 return E_NOTIMPL;
4178 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4180 /* IUnknown methods */
4181 d3d11_device_QueryInterface,
4182 d3d11_device_AddRef,
4183 d3d11_device_Release,
4184 /* ID3D11Device methods */
4185 d3d11_device_CreateBuffer,
4186 d3d11_device_CreateTexture1D,
4187 d3d11_device_CreateTexture2D,
4188 d3d11_device_CreateTexture3D,
4189 d3d11_device_CreateShaderResourceView,
4190 d3d11_device_CreateUnorderedAccessView,
4191 d3d11_device_CreateRenderTargetView,
4192 d3d11_device_CreateDepthStencilView,
4193 d3d11_device_CreateInputLayout,
4194 d3d11_device_CreateVertexShader,
4195 d3d11_device_CreateGeometryShader,
4196 d3d11_device_CreateGeometryShaderWithStreamOutput,
4197 d3d11_device_CreatePixelShader,
4198 d3d11_device_CreateHullShader,
4199 d3d11_device_CreateDomainShader,
4200 d3d11_device_CreateComputeShader,
4201 d3d11_device_CreateClassLinkage,
4202 d3d11_device_CreateBlendState,
4203 d3d11_device_CreateDepthStencilState,
4204 d3d11_device_CreateRasterizerState,
4205 d3d11_device_CreateSamplerState,
4206 d3d11_device_CreateQuery,
4207 d3d11_device_CreatePredicate,
4208 d3d11_device_CreateCounter,
4209 d3d11_device_CreateDeferredContext,
4210 d3d11_device_OpenSharedResource,
4211 d3d11_device_CheckFormatSupport,
4212 d3d11_device_CheckMultisampleQualityLevels,
4213 d3d11_device_CheckCounterInfo,
4214 d3d11_device_CheckCounter,
4215 d3d11_device_CheckFeatureSupport,
4216 d3d11_device_GetPrivateData,
4217 d3d11_device_SetPrivateData,
4218 d3d11_device_SetPrivateDataInterface,
4219 d3d11_device_GetFeatureLevel,
4220 d3d11_device_GetCreationFlags,
4221 d3d11_device_GetDeviceRemovedReason,
4222 d3d11_device_GetImmediateContext,
4223 d3d11_device_SetExceptionMode,
4224 d3d11_device_GetExceptionMode,
4225 /* ID3D11Device1 methods */
4226 d3d11_device_GetImmediateContext1,
4227 d3d11_device_CreateDeferredContext1,
4228 d3d11_device_CreateBlendState1,
4229 d3d11_device_CreateRasterizerState1,
4230 d3d11_device_CreateDeviceContextState,
4231 d3d11_device_OpenSharedResource1,
4232 d3d11_device_OpenSharedResourceByName,
4233 /* ID3D11Device2 methods */
4234 d3d11_device_GetImmediateContext2,
4235 d3d11_device_CreateDeferredContext2,
4236 d3d11_device_GetResourceTiling,
4237 d3d11_device_CheckMultisampleQualityLevels1,
4240 /* Inner IUnknown methods */
4242 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4244 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4247 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4249 struct d3d_device *device = impl_from_IUnknown(iface);
4251 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4253 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4254 || IsEqualGUID(riid, &IID_ID3D11Device1)
4255 || IsEqualGUID(riid, &IID_ID3D11Device)
4256 || IsEqualGUID(riid, &IID_IUnknown))
4258 *out = &device->ID3D11Device2_iface;
4260 else if (!device->d3d11_only
4261 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4262 || IsEqualGUID(riid, &IID_ID3D10Device)))
4264 *out = &device->ID3D10Device1_iface;
4266 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4268 *out = &device->ID3D10Multithread_iface;
4270 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4272 *out = &device->IWineDXGIDeviceParent_iface;
4274 else
4276 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4277 *out = NULL;
4278 return E_NOINTERFACE;
4281 IUnknown_AddRef((IUnknown *)*out);
4282 return S_OK;
4285 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4287 struct d3d_device *device = impl_from_IUnknown(iface);
4288 ULONG refcount = InterlockedIncrement(&device->refcount);
4290 TRACE("%p increasing refcount to %u.\n", device, refcount);
4292 return refcount;
4295 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4297 struct d3d_device *device = impl_from_IUnknown(iface);
4298 ULONG refcount = InterlockedDecrement(&device->refcount);
4299 unsigned int i;
4301 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4303 if (!refcount)
4305 if (device->state)
4306 d3d_device_context_state_private_release(device->state);
4307 for (i = 0; i < device->context_state_count; ++i)
4309 d3d_device_context_state_remove_entry(device->context_states[i], device);
4311 heap_free(device->context_states);
4312 d3d11_immediate_context_destroy(&device->immediate_context);
4313 if (device->wined3d_device)
4315 wined3d_mutex_lock();
4316 wined3d_device_decref(device->wined3d_device);
4317 wined3d_mutex_unlock();
4319 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4320 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4321 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4322 wine_rb_destroy(&device->blend_states, NULL, NULL);
4325 return refcount;
4328 /* IUnknown methods */
4330 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4331 void **out)
4333 struct d3d_device *device = impl_from_ID3D10Device(iface);
4334 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4337 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4339 struct d3d_device *device = impl_from_ID3D10Device(iface);
4340 return IUnknown_AddRef(device->outer_unk);
4343 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4345 struct d3d_device *device = impl_from_ID3D10Device(iface);
4346 return IUnknown_Release(device->outer_unk);
4349 /* ID3D10Device methods */
4351 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4352 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4354 struct d3d_device *device = impl_from_ID3D10Device(iface);
4355 unsigned int i;
4357 wined3d_mutex_lock();
4358 for (i = 0; i < buffer_count; ++i)
4360 struct wined3d_buffer *wined3d_buffer;
4361 struct d3d_buffer *buffer_impl;
4363 if (!(wined3d_buffer = wined3d_device_get_constant_buffer(device->wined3d_device,
4364 type, start_slot + i)))
4366 buffers[i] = NULL;
4367 continue;
4370 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4371 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4372 ID3D10Buffer_AddRef(buffers[i]);
4374 wined3d_mutex_unlock();
4377 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4378 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4380 struct d3d_device *device = impl_from_ID3D10Device(iface);
4381 unsigned int i;
4383 wined3d_mutex_lock();
4384 for (i = 0; i < buffer_count; ++i)
4386 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4388 wined3d_device_context_set_constant_buffer(device->immediate_context.wined3d_context, type, start_slot + i,
4389 buffer ? buffer->wined3d_buffer : NULL);
4391 wined3d_mutex_unlock();
4394 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4395 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4397 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4398 iface, start_slot, buffer_count, buffers);
4400 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4401 buffer_count, buffers);
4404 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4405 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4407 struct d3d_device *device = impl_from_ID3D10Device(iface);
4408 unsigned int i;
4410 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4411 iface, start_slot, view_count, views);
4413 wined3d_mutex_lock();
4414 for (i = 0; i < view_count; ++i)
4416 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4418 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4419 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, view ? view->wined3d_view : NULL);
4421 wined3d_mutex_unlock();
4424 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4425 ID3D10PixelShader *shader)
4427 struct d3d_device *device = impl_from_ID3D10Device(iface);
4428 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4430 TRACE("iface %p, shader %p\n", iface, shader);
4432 wined3d_mutex_lock();
4433 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4434 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4435 wined3d_mutex_unlock();
4438 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4439 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4441 struct d3d_device *device = impl_from_ID3D10Device(iface);
4442 unsigned int i;
4444 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4445 iface, start_slot, sampler_count, samplers);
4447 wined3d_mutex_lock();
4448 for (i = 0; i < sampler_count; ++i)
4450 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4452 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4453 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4455 wined3d_mutex_unlock();
4458 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4459 ID3D10VertexShader *shader)
4461 struct d3d_device *device = impl_from_ID3D10Device(iface);
4462 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4464 TRACE("iface %p, shader %p\n", iface, shader);
4466 wined3d_mutex_lock();
4467 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4468 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4469 wined3d_mutex_unlock();
4472 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4473 UINT start_index_location, INT base_vertex_location)
4475 struct d3d_device *device = impl_from_ID3D10Device(iface);
4477 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4478 iface, index_count, start_index_location, base_vertex_location);
4480 wined3d_mutex_lock();
4481 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4482 base_vertex_location, start_index_location, index_count, 0, 0);
4483 wined3d_mutex_unlock();
4486 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4487 UINT start_vertex_location)
4489 struct d3d_device *device = impl_from_ID3D10Device(iface);
4491 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4492 iface, vertex_count, start_vertex_location);
4494 wined3d_mutex_lock();
4495 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4496 wined3d_mutex_unlock();
4499 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4500 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4502 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4503 iface, start_slot, buffer_count, buffers);
4505 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4506 buffer_count, buffers);
4509 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4510 ID3D10InputLayout *input_layout)
4512 struct d3d_device *device = impl_from_ID3D10Device(iface);
4513 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4515 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4517 wined3d_mutex_lock();
4518 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4519 layout ? layout->wined3d_decl : NULL);
4520 wined3d_mutex_unlock();
4523 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4524 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4526 struct d3d_device *device = impl_from_ID3D10Device(iface);
4527 unsigned int i;
4529 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4530 iface, start_slot, buffer_count, buffers, strides, offsets);
4532 wined3d_mutex_lock();
4533 for (i = 0; i < buffer_count; ++i)
4535 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4537 wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
4538 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
4540 wined3d_mutex_unlock();
4543 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4544 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4546 struct d3d_device *device = impl_from_ID3D10Device(iface);
4547 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4549 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4550 iface, buffer, debug_dxgi_format(format), offset);
4552 wined3d_mutex_lock();
4553 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4554 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4555 wined3dformat_from_dxgi_format(format), offset);
4556 wined3d_mutex_unlock();
4559 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4560 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4561 INT base_vertex_location, UINT start_instance_location)
4563 struct d3d_device *device = impl_from_ID3D10Device(iface);
4565 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4566 "base_vertex_location %d, start_instance_location %u.\n",
4567 iface, instance_index_count, instance_count, start_index_location,
4568 base_vertex_location, start_instance_location);
4570 wined3d_mutex_lock();
4571 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4572 start_index_location, instance_index_count, start_instance_location, instance_count);
4573 wined3d_mutex_unlock();
4576 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4577 UINT instance_vertex_count, UINT instance_count,
4578 UINT start_vertex_location, UINT start_instance_location)
4580 struct d3d_device *device = impl_from_ID3D10Device(iface);
4582 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4583 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4584 start_vertex_location, start_instance_location);
4586 wined3d_mutex_lock();
4587 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4588 instance_vertex_count, start_instance_location, instance_count);
4589 wined3d_mutex_unlock();
4592 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4593 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4595 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4596 iface, start_slot, buffer_count, buffers);
4598 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4599 buffer_count, buffers);
4602 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4604 struct d3d_device *device = impl_from_ID3D10Device(iface);
4605 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4607 TRACE("iface %p, shader %p.\n", iface, shader);
4609 wined3d_mutex_lock();
4610 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4611 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4612 wined3d_mutex_unlock();
4615 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4616 D3D10_PRIMITIVE_TOPOLOGY topology)
4618 struct d3d_device *device = impl_from_ID3D10Device(iface);
4620 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4622 wined3d_mutex_lock();
4623 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology, 0);
4624 wined3d_mutex_unlock();
4627 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4628 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4630 struct d3d_device *device = impl_from_ID3D10Device(iface);
4631 unsigned int i;
4633 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4634 iface, start_slot, view_count, views);
4636 wined3d_mutex_lock();
4637 for (i = 0; i < view_count; ++i)
4639 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4641 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4642 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, view ? view->wined3d_view : NULL);
4644 wined3d_mutex_unlock();
4647 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4648 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4650 struct d3d_device *device = impl_from_ID3D10Device(iface);
4651 unsigned int i;
4653 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4654 iface, start_slot, sampler_count, samplers);
4656 wined3d_mutex_lock();
4657 for (i = 0; i < sampler_count; ++i)
4659 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4661 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4662 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4664 wined3d_mutex_unlock();
4667 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4669 struct d3d_device *device = impl_from_ID3D10Device(iface);
4670 struct d3d_query *query;
4672 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4674 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4675 wined3d_mutex_lock();
4676 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4677 query ? query->wined3d_query : NULL, value);
4678 wined3d_mutex_unlock();
4681 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4682 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4684 struct d3d_device *device = impl_from_ID3D10Device(iface);
4685 unsigned int i;
4687 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4688 iface, start_slot, view_count, views);
4690 wined3d_mutex_lock();
4691 for (i = 0; i < view_count; ++i)
4693 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4695 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4696 WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i, view ? view->wined3d_view : NULL);
4698 wined3d_mutex_unlock();
4701 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4702 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4704 struct d3d_device *device = impl_from_ID3D10Device(iface);
4705 unsigned int i;
4707 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4708 iface, start_slot, sampler_count, samplers);
4710 wined3d_mutex_lock();
4711 for (i = 0; i < sampler_count; ++i)
4713 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4715 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
4716 start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4718 wined3d_mutex_unlock();
4721 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4722 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4723 ID3D10DepthStencilView *depth_stencil_view)
4725 struct d3d_device *device = impl_from_ID3D10Device(iface);
4726 struct d3d_depthstencil_view *dsv;
4727 unsigned int i;
4729 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4730 iface, render_target_view_count, render_target_views, depth_stencil_view);
4732 wined3d_mutex_lock();
4733 for (i = 0; i < render_target_view_count; ++i)
4735 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4737 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
4738 rtv ? rtv->wined3d_view : NULL, FALSE);
4740 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4742 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
4745 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4746 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4747 dsv ? dsv->wined3d_view : NULL);
4748 wined3d_mutex_unlock();
4751 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4752 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4754 struct d3d_device *device = impl_from_ID3D10Device(iface);
4755 struct d3d_blend_state *blend_state_object;
4757 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4758 iface, blend_state, debug_float4(blend_factor), sample_mask);
4760 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4761 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4762 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4765 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4766 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4768 struct d3d_device *device = impl_from_ID3D10Device(iface);
4769 struct d3d_depthstencil_state *ds_state_object;
4771 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4772 iface, depth_stencil_state, stencil_ref);
4774 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4775 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4776 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4779 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4780 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4782 struct d3d_device *device = impl_from_ID3D10Device(iface);
4783 unsigned int count, i;
4785 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4787 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4788 wined3d_mutex_lock();
4789 for (i = 0; i < count; ++i)
4791 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4793 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i,
4794 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4797 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4799 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i, NULL, 0);
4801 wined3d_mutex_unlock();
4804 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4806 FIXME("iface %p stub!\n", iface);
4809 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4811 struct d3d_device *device = impl_from_ID3D10Device(iface);
4812 struct d3d_rasterizer_state *rasterizer_state_object;
4814 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4816 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4817 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
4818 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4821 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4822 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4824 struct d3d_device *device = impl_from_ID3D10Device(iface);
4825 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
4826 unsigned int i;
4828 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4830 if (viewport_count > ARRAY_SIZE(wined3d_vp))
4831 return;
4833 for (i = 0; i < viewport_count; ++i)
4835 wined3d_vp[i].x = viewports[i].TopLeftX;
4836 wined3d_vp[i].y = viewports[i].TopLeftY;
4837 wined3d_vp[i].width = viewports[i].Width;
4838 wined3d_vp[i].height = viewports[i].Height;
4839 wined3d_vp[i].min_z = viewports[i].MinDepth;
4840 wined3d_vp[i].max_z = viewports[i].MaxDepth;
4843 wined3d_mutex_lock();
4844 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
4845 wined3d_mutex_unlock();
4848 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4849 UINT rect_count, const D3D10_RECT *rects)
4851 struct d3d_device *device = impl_from_ID3D10Device(iface);
4853 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4855 if (rect_count > WINED3D_MAX_VIEWPORTS)
4856 return;
4858 wined3d_mutex_lock();
4859 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
4860 wined3d_mutex_unlock();
4863 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4864 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4865 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4867 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4868 struct d3d_device *device = impl_from_ID3D10Device(iface);
4869 struct wined3d_box wined3d_src_box;
4871 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4872 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4873 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4874 src_resource, src_subresource_idx, src_box);
4876 if (!dst_resource || !src_resource)
4877 return;
4879 if (src_box)
4880 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4881 src_box->right, src_box->bottom, src_box->front, src_box->back);
4883 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4884 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4885 wined3d_mutex_lock();
4886 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
4887 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4888 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
4889 wined3d_mutex_unlock();
4892 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4893 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4895 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4896 struct d3d_device *device = impl_from_ID3D10Device(iface);
4898 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4900 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4901 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4902 wined3d_mutex_lock();
4903 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
4904 wined3d_dst_resource, wined3d_src_resource);
4905 wined3d_mutex_unlock();
4908 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4909 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4910 const void *data, UINT row_pitch, UINT depth_pitch)
4912 struct d3d_device *device = impl_from_ID3D10Device(iface);
4913 ID3D11Resource *d3d11_resource;
4915 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4916 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4918 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4919 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
4920 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4921 ID3D11Resource_Release(d3d11_resource);
4924 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4925 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4927 struct d3d_device *device = impl_from_ID3D10Device(iface);
4928 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4929 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4930 HRESULT hr;
4932 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4933 iface, render_target_view, debug_float4(color_rgba));
4935 if (!view)
4936 return;
4938 wined3d_mutex_lock();
4939 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
4940 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4941 ERR("Failed to clear view, hr %#x.\n", hr);
4942 wined3d_mutex_unlock();
4945 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4946 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4948 struct d3d_device *device = impl_from_ID3D10Device(iface);
4949 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4950 DWORD wined3d_flags;
4951 HRESULT hr;
4953 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4954 iface, depth_stencil_view, flags, depth, stencil);
4956 if (!view)
4957 return;
4959 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4961 wined3d_mutex_lock();
4962 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
4963 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
4964 ERR("Failed to clear view, hr %#x.\n", hr);
4965 wined3d_mutex_unlock();
4968 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4969 ID3D10ShaderResourceView *view)
4971 struct d3d_device *device = impl_from_ID3D10Device(iface);
4972 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
4974 TRACE("iface %p, view %p.\n", iface, view);
4976 wined3d_mutex_lock();
4977 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
4978 wined3d_mutex_unlock();
4981 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4982 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4983 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4985 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4986 struct d3d_device *device = impl_from_ID3D10Device(iface);
4987 enum wined3d_format_id wined3d_format;
4989 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
4990 "src_resource %p, src_subresource_idx %u, format %s.\n",
4991 iface, dst_resource, dst_subresource_idx,
4992 src_resource, src_subresource_idx, debug_dxgi_format(format));
4994 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4995 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4996 wined3d_format = wined3dformat_from_dxgi_format(format);
4997 wined3d_mutex_lock();
4998 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
4999 wined3d_dst_resource, dst_subresource_idx,
5000 wined3d_src_resource, src_subresource_idx, wined3d_format);
5001 wined3d_mutex_unlock();
5004 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5005 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5007 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5008 iface, start_slot, buffer_count, buffers);
5010 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5011 buffers);
5014 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5015 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5017 struct d3d_device *device = impl_from_ID3D10Device(iface);
5018 unsigned int i;
5020 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5021 iface, start_slot, view_count, views);
5023 wined3d_mutex_lock();
5024 for (i = 0; i < view_count; ++i)
5026 struct wined3d_shader_resource_view *wined3d_view;
5027 struct d3d_shader_resource_view *view_impl;
5029 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
5031 views[i] = NULL;
5032 continue;
5035 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5036 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5037 ID3D10ShaderResourceView_AddRef(views[i]);
5039 wined3d_mutex_unlock();
5042 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5044 struct d3d_device *device = impl_from_ID3D10Device(iface);
5045 struct d3d_pixel_shader *shader_impl;
5046 struct wined3d_shader *wined3d_shader;
5048 TRACE("iface %p, shader %p.\n", iface, shader);
5050 wined3d_mutex_lock();
5051 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
5053 wined3d_mutex_unlock();
5054 *shader = NULL;
5055 return;
5058 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5059 wined3d_mutex_unlock();
5060 *shader = &shader_impl->ID3D10PixelShader_iface;
5061 ID3D10PixelShader_AddRef(*shader);
5064 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5065 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5067 struct d3d_device *device = impl_from_ID3D10Device(iface);
5068 unsigned int i;
5070 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5071 iface, start_slot, sampler_count, samplers);
5073 wined3d_mutex_lock();
5074 for (i = 0; i < sampler_count; ++i)
5076 struct d3d_sampler_state *sampler_impl;
5077 struct wined3d_sampler *wined3d_sampler;
5079 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
5081 samplers[i] = NULL;
5082 continue;
5085 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5086 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5087 ID3D10SamplerState_AddRef(samplers[i]);
5089 wined3d_mutex_unlock();
5092 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5094 struct d3d_device *device = impl_from_ID3D10Device(iface);
5095 struct d3d_vertex_shader *shader_impl;
5096 struct wined3d_shader *wined3d_shader;
5098 TRACE("iface %p, shader %p.\n", iface, shader);
5100 wined3d_mutex_lock();
5101 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
5103 wined3d_mutex_unlock();
5104 *shader = NULL;
5105 return;
5108 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5109 wined3d_mutex_unlock();
5110 *shader = &shader_impl->ID3D10VertexShader_iface;
5111 ID3D10VertexShader_AddRef(*shader);
5114 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5115 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5117 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5118 iface, start_slot, buffer_count, buffers);
5120 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5121 buffers);
5124 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5126 struct d3d_device *device = impl_from_ID3D10Device(iface);
5127 struct wined3d_vertex_declaration *wined3d_declaration;
5128 struct d3d_input_layout *input_layout_impl;
5130 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5132 wined3d_mutex_lock();
5133 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
5135 wined3d_mutex_unlock();
5136 *input_layout = NULL;
5137 return;
5140 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5141 wined3d_mutex_unlock();
5142 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5143 ID3D10InputLayout_AddRef(*input_layout);
5146 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5147 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5149 struct d3d_device *device = impl_from_ID3D10Device(iface);
5150 unsigned int i;
5152 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5153 iface, start_slot, buffer_count, buffers, strides, offsets);
5155 wined3d_mutex_lock();
5156 for (i = 0; i < buffer_count; ++i)
5158 struct wined3d_buffer *wined3d_buffer = NULL;
5159 struct d3d_buffer *buffer_impl;
5161 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
5162 &wined3d_buffer, &offsets[i], &strides[i])))
5163 ERR("Failed to get vertex buffer.\n");
5165 if (!wined3d_buffer)
5167 buffers[i] = NULL;
5168 continue;
5171 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5172 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5173 ID3D10Buffer_AddRef(buffers[i]);
5175 wined3d_mutex_unlock();
5178 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5179 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5181 struct d3d_device *device = impl_from_ID3D10Device(iface);
5182 enum wined3d_format_id wined3d_format;
5183 struct wined3d_buffer *wined3d_buffer;
5184 struct d3d_buffer *buffer_impl;
5186 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5188 wined3d_mutex_lock();
5189 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
5190 *format = dxgi_format_from_wined3dformat(wined3d_format);
5191 if (!wined3d_buffer)
5193 wined3d_mutex_unlock();
5194 *buffer = NULL;
5195 return;
5198 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5199 wined3d_mutex_unlock();
5200 *buffer = &buffer_impl->ID3D10Buffer_iface;
5201 ID3D10Buffer_AddRef(*buffer);
5204 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5205 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5207 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5208 iface, start_slot, buffer_count, buffers);
5210 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5211 buffers);
5214 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5216 struct d3d_device *device = impl_from_ID3D10Device(iface);
5217 struct d3d_geometry_shader *shader_impl;
5218 struct wined3d_shader *wined3d_shader;
5220 TRACE("iface %p, shader %p.\n", iface, shader);
5222 wined3d_mutex_lock();
5223 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
5225 wined3d_mutex_unlock();
5226 *shader = NULL;
5227 return;
5230 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5231 wined3d_mutex_unlock();
5232 *shader = &shader_impl->ID3D10GeometryShader_iface;
5233 ID3D10GeometryShader_AddRef(*shader);
5236 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5237 D3D10_PRIMITIVE_TOPOLOGY *topology)
5239 struct d3d_device *device = impl_from_ID3D10Device(iface);
5241 TRACE("iface %p, topology %p.\n", iface, topology);
5243 wined3d_mutex_lock();
5244 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology, NULL);
5245 wined3d_mutex_unlock();
5248 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5249 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5251 struct d3d_device *device = impl_from_ID3D10Device(iface);
5252 unsigned int i;
5254 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5255 iface, start_slot, view_count, views);
5257 wined3d_mutex_lock();
5258 for (i = 0; i < view_count; ++i)
5260 struct wined3d_shader_resource_view *wined3d_view;
5261 struct d3d_shader_resource_view *view_impl;
5263 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
5265 views[i] = NULL;
5266 continue;
5269 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5270 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5271 ID3D10ShaderResourceView_AddRef(views[i]);
5273 wined3d_mutex_unlock();
5276 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5277 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5279 struct d3d_device *device = impl_from_ID3D10Device(iface);
5280 unsigned int i;
5282 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5283 iface, start_slot, sampler_count, samplers);
5285 wined3d_mutex_lock();
5286 for (i = 0; i < sampler_count; ++i)
5288 struct d3d_sampler_state *sampler_impl;
5289 struct wined3d_sampler *wined3d_sampler;
5291 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
5293 samplers[i] = NULL;
5294 continue;
5297 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5298 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5299 ID3D10SamplerState_AddRef(samplers[i]);
5301 wined3d_mutex_unlock();
5304 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5305 ID3D10Predicate **predicate, BOOL *value)
5307 struct d3d_device *device = impl_from_ID3D10Device(iface);
5308 struct wined3d_query *wined3d_predicate;
5309 struct d3d_query *predicate_impl;
5311 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5313 wined3d_mutex_lock();
5314 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
5316 wined3d_mutex_unlock();
5317 *predicate = NULL;
5318 return;
5321 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5322 wined3d_mutex_unlock();
5323 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5324 ID3D10Predicate_AddRef(*predicate);
5327 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5328 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5330 struct d3d_device *device = impl_from_ID3D10Device(iface);
5331 unsigned int i;
5333 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5334 iface, start_slot, view_count, views);
5336 wined3d_mutex_lock();
5337 for (i = 0; i < view_count; ++i)
5339 struct wined3d_shader_resource_view *wined3d_view;
5340 struct d3d_shader_resource_view *view_impl;
5342 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
5344 views[i] = NULL;
5345 continue;
5348 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5349 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5350 ID3D10ShaderResourceView_AddRef(views[i]);
5352 wined3d_mutex_unlock();
5355 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5356 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5358 struct d3d_device *device = impl_from_ID3D10Device(iface);
5359 unsigned int i;
5361 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5362 iface, start_slot, sampler_count, samplers);
5364 wined3d_mutex_lock();
5365 for (i = 0; i < sampler_count; ++i)
5367 struct d3d_sampler_state *sampler_impl;
5368 struct wined3d_sampler *wined3d_sampler;
5370 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
5372 samplers[i] = NULL;
5373 continue;
5376 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5377 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5378 ID3D10SamplerState_AddRef(samplers[i]);
5380 wined3d_mutex_unlock();
5383 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5384 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5386 struct d3d_device *device = impl_from_ID3D10Device(iface);
5387 struct wined3d_rendertarget_view *wined3d_view;
5389 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5390 iface, view_count, render_target_views, depth_stencil_view);
5392 wined3d_mutex_lock();
5393 if (render_target_views)
5395 struct d3d_rendertarget_view *view_impl;
5396 unsigned int i;
5398 for (i = 0; i < view_count; ++i)
5400 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
5401 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5403 render_target_views[i] = NULL;
5404 continue;
5407 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5408 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5412 if (depth_stencil_view)
5414 struct d3d_depthstencil_view *view_impl;
5416 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
5417 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5419 *depth_stencil_view = NULL;
5421 else
5423 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5424 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5427 wined3d_mutex_unlock();
5430 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5431 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5433 struct d3d_device *device = impl_from_ID3D10Device(iface);
5434 ID3D11BlendState *d3d11_blend_state;
5436 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5437 iface, blend_state, blend_factor, sample_mask);
5439 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5440 &d3d11_blend_state, blend_factor, sample_mask);
5442 if (d3d11_blend_state)
5443 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5444 else
5445 *blend_state = NULL;
5448 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5449 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5451 struct d3d_device *device = impl_from_ID3D10Device(iface);
5452 ID3D11DepthStencilState *d3d11_iface;
5454 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5455 iface, depth_stencil_state, stencil_ref);
5457 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5458 &d3d11_iface, stencil_ref);
5460 if (d3d11_iface)
5461 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5462 else
5463 *depth_stencil_state = NULL;
5466 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5467 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5469 struct d3d_device *device = impl_from_ID3D10Device(iface);
5470 unsigned int i;
5472 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5473 iface, buffer_count, buffers, offsets);
5475 wined3d_mutex_lock();
5476 for (i = 0; i < buffer_count; ++i)
5478 struct wined3d_buffer *wined3d_buffer;
5479 struct d3d_buffer *buffer_impl;
5481 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
5483 buffers[i] = NULL;
5484 continue;
5487 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5488 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5489 ID3D10Buffer_AddRef(buffers[i]);
5491 wined3d_mutex_unlock();
5494 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5496 struct d3d_device *device = impl_from_ID3D10Device(iface);
5497 struct d3d_rasterizer_state *rasterizer_state_impl;
5498 struct wined3d_rasterizer_state *wined3d_state;
5500 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5502 wined3d_mutex_lock();
5503 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
5505 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5506 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5508 else
5510 *rasterizer_state = NULL;
5512 wined3d_mutex_unlock();
5515 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5516 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5518 struct d3d_device *device = impl_from_ID3D10Device(iface);
5519 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5520 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5522 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5524 if (!viewport_count)
5525 return;
5527 wined3d_mutex_lock();
5528 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
5529 wined3d_mutex_unlock();
5531 if (!viewports)
5533 *viewport_count = actual_count;
5534 return;
5537 if (*viewport_count > actual_count)
5538 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5540 *viewport_count = min(actual_count, *viewport_count);
5541 for (i = 0; i < *viewport_count; ++i)
5543 viewports[i].TopLeftX = wined3d_vp[i].x;
5544 viewports[i].TopLeftY = wined3d_vp[i].y;
5545 viewports[i].Width = wined3d_vp[i].width;
5546 viewports[i].Height = wined3d_vp[i].height;
5547 viewports[i].MinDepth = wined3d_vp[i].min_z;
5548 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5552 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5554 struct d3d_device *device = impl_from_ID3D10Device(iface);
5555 unsigned int actual_count;
5557 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5559 if (!rect_count)
5560 return;
5562 actual_count = *rect_count;
5564 wined3d_mutex_lock();
5565 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
5566 wined3d_mutex_unlock();
5568 if (!rects)
5570 *rect_count = actual_count;
5571 return;
5574 if (*rect_count > actual_count)
5575 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5578 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5580 TRACE("iface %p.\n", iface);
5582 /* In the current implementation the device is never removed, so we can
5583 * just return S_OK here. */
5585 return S_OK;
5588 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5590 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5592 return E_NOTIMPL;
5595 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5597 FIXME("iface %p stub!\n", iface);
5599 return 0;
5602 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5603 REFGUID guid, UINT *data_size, void *data)
5605 struct d3d_device *device = impl_from_ID3D10Device(iface);
5607 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5609 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5612 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5613 REFGUID guid, UINT data_size, const void *data)
5615 struct d3d_device *device = impl_from_ID3D10Device(iface);
5617 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5619 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5622 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5623 REFGUID guid, const IUnknown *data)
5625 struct d3d_device *device = impl_from_ID3D10Device(iface);
5627 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5629 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5632 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5634 struct d3d_device *device = impl_from_ID3D10Device(iface);
5636 TRACE("iface %p.\n", iface);
5638 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5641 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5643 struct d3d_device *device = impl_from_ID3D10Device(iface);
5645 TRACE("iface %p.\n", iface);
5647 wined3d_mutex_lock();
5648 wined3d_device_flush(device->wined3d_device);
5649 wined3d_mutex_unlock();
5652 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5653 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5655 struct d3d_device *device = impl_from_ID3D10Device(iface);
5656 D3D11_BUFFER_DESC d3d11_desc;
5657 struct d3d_buffer *object;
5658 HRESULT hr;
5660 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5662 d3d11_desc.ByteWidth = desc->ByteWidth;
5663 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5664 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5665 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5666 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5667 d3d11_desc.StructureByteStride = 0;
5669 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5670 return hr;
5672 *buffer = &object->ID3D10Buffer_iface;
5674 return S_OK;
5677 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5678 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5680 struct d3d_device *device = impl_from_ID3D10Device(iface);
5681 D3D11_TEXTURE1D_DESC d3d11_desc;
5682 struct d3d_texture1d *object;
5683 HRESULT hr;
5685 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5687 d3d11_desc.Width = desc->Width;
5688 d3d11_desc.MipLevels = desc->MipLevels;
5689 d3d11_desc.ArraySize = desc->ArraySize;
5690 d3d11_desc.Format = desc->Format;
5691 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5692 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5693 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5694 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5696 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5697 return hr;
5699 *texture = &object->ID3D10Texture1D_iface;
5701 return S_OK;
5704 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5705 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5706 ID3D10Texture2D **texture)
5708 struct d3d_device *device = impl_from_ID3D10Device(iface);
5709 D3D11_TEXTURE2D_DESC d3d11_desc;
5710 struct d3d_texture2d *object;
5711 HRESULT hr;
5713 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5715 d3d11_desc.Width = desc->Width;
5716 d3d11_desc.Height = desc->Height;
5717 d3d11_desc.MipLevels = desc->MipLevels;
5718 d3d11_desc.ArraySize = desc->ArraySize;
5719 d3d11_desc.Format = desc->Format;
5720 d3d11_desc.SampleDesc = desc->SampleDesc;
5721 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5722 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5723 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5724 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5726 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5727 return hr;
5729 *texture = &object->ID3D10Texture2D_iface;
5731 return S_OK;
5734 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5735 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5736 ID3D10Texture3D **texture)
5738 struct d3d_device *device = impl_from_ID3D10Device(iface);
5739 D3D11_TEXTURE3D_DESC d3d11_desc;
5740 struct d3d_texture3d *object;
5741 HRESULT hr;
5743 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5745 d3d11_desc.Width = desc->Width;
5746 d3d11_desc.Height = desc->Height;
5747 d3d11_desc.Depth = desc->Depth;
5748 d3d11_desc.MipLevels = desc->MipLevels;
5749 d3d11_desc.Format = desc->Format;
5750 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5751 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5752 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5753 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5755 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5756 return hr;
5758 *texture = &object->ID3D10Texture3D_iface;
5760 return S_OK;
5763 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5764 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5766 struct d3d_device *device = impl_from_ID3D10Device(iface);
5767 struct d3d_shader_resource_view *object;
5768 ID3D11Resource *d3d11_resource;
5769 HRESULT hr;
5771 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5773 if (!resource)
5774 return E_INVALIDARG;
5776 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5778 ERR("Resource does not implement ID3D11Resource.\n");
5779 return E_FAIL;
5782 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5783 &object);
5784 ID3D11Resource_Release(d3d11_resource);
5785 if (FAILED(hr))
5786 return hr;
5788 *view = &object->ID3D10ShaderResourceView1_iface;
5790 return S_OK;
5793 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5794 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5796 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5798 return d3d10_device_CreateShaderResourceView1(iface, resource,
5799 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5802 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5803 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5805 struct d3d_device *device = impl_from_ID3D10Device(iface);
5806 struct d3d_rendertarget_view *object;
5807 ID3D11Resource *d3d11_resource;
5808 HRESULT hr;
5810 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5812 if (!resource)
5813 return E_INVALIDARG;
5815 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5817 ERR("Resource does not implement ID3D11Resource.\n");
5818 return E_FAIL;
5821 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5822 ID3D11Resource_Release(d3d11_resource);
5823 if (FAILED(hr))
5824 return hr;
5826 *view = &object->ID3D10RenderTargetView_iface;
5828 return S_OK;
5831 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
5833 return (D3D11_DSV_DIMENSION)dim;
5836 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5837 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5839 struct d3d_device *device = impl_from_ID3D10Device(iface);
5840 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5841 struct d3d_depthstencil_view *object;
5842 ID3D11Resource *d3d11_resource;
5843 HRESULT hr;
5845 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5847 if (desc)
5849 d3d11_desc.Format = desc->Format;
5850 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
5851 d3d11_desc.Flags = 0;
5852 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5855 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5857 ERR("Resource does not implement ID3D11Resource.\n");
5858 return E_FAIL;
5861 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5862 ID3D11Resource_Release(d3d11_resource);
5863 if (FAILED(hr))
5864 return hr;
5866 *view = &object->ID3D10DepthStencilView_iface;
5868 return S_OK;
5871 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5872 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5873 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5874 ID3D10InputLayout **input_layout)
5876 struct d3d_device *device = impl_from_ID3D10Device(iface);
5877 struct d3d_input_layout *object;
5878 HRESULT hr;
5880 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5881 "shader_byte_code_length %lu, input_layout %p\n",
5882 iface, element_descs, element_count, shader_byte_code,
5883 shader_byte_code_length, input_layout);
5885 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5886 shader_byte_code, shader_byte_code_length, &object)))
5887 return hr;
5889 *input_layout = &object->ID3D10InputLayout_iface;
5891 return S_OK;
5894 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5895 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5897 struct d3d_device *device = impl_from_ID3D10Device(iface);
5898 struct d3d_vertex_shader *object;
5899 HRESULT hr;
5901 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5902 iface, byte_code, byte_code_length, shader);
5904 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5905 return hr;
5907 *shader = &object->ID3D10VertexShader_iface;
5909 return S_OK;
5912 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5913 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5915 struct d3d_device *device = impl_from_ID3D10Device(iface);
5916 struct d3d_geometry_shader *object;
5917 HRESULT hr;
5919 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5920 iface, byte_code, byte_code_length, shader);
5922 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5923 NULL, 0, NULL, 0, 0, &object)))
5924 return hr;
5926 *shader = &object->ID3D10GeometryShader_iface;
5928 return S_OK;
5931 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5932 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5933 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5935 struct d3d_device *device = impl_from_ID3D10Device(iface);
5936 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5937 struct d3d_geometry_shader *object;
5938 unsigned int i, stride_count = 1;
5939 HRESULT hr;
5941 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5942 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5943 iface, byte_code, byte_code_length, output_stream_decls,
5944 output_stream_decl_count, output_stream_stride, shader);
5946 if (!output_stream_decl_count && output_stream_stride)
5948 WARN("Stride must be 0 when declaration entry count is 0.\n");
5949 *shader = NULL;
5950 return E_INVALIDARG;
5953 if (output_stream_decl_count
5954 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
5956 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5957 *shader = NULL;
5958 return E_OUTOFMEMORY;
5961 for (i = 0; i < output_stream_decl_count; ++i)
5963 so_entries[i].Stream = 0;
5964 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5965 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5966 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5967 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5968 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5970 if (output_stream_decls[i].OutputSlot)
5972 stride_count = 0;
5973 if (output_stream_stride)
5975 WARN("Stride must be 0 when multiple output slots are used.\n");
5976 heap_free(so_entries);
5977 *shader = NULL;
5978 return E_INVALIDARG;
5983 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5984 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5985 heap_free(so_entries);
5986 if (FAILED(hr))
5988 *shader = NULL;
5989 return hr;
5992 *shader = &object->ID3D10GeometryShader_iface;
5994 return hr;
5997 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5998 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
6000 struct d3d_device *device = impl_from_ID3D10Device(iface);
6001 struct d3d_pixel_shader *object;
6002 HRESULT hr;
6004 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6005 iface, byte_code, byte_code_length, shader);
6007 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6008 return hr;
6010 *shader = &object->ID3D10PixelShader_iface;
6012 return S_OK;
6015 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6016 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6018 struct d3d_device *device = impl_from_ID3D10Device(iface);
6019 struct d3d_blend_state *object;
6020 HRESULT hr;
6022 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6024 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6025 return hr;
6027 *blend_state = &object->ID3D10BlendState1_iface;
6029 return S_OK;
6032 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6033 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6035 D3D10_BLEND_DESC1 d3d10_1_desc;
6036 unsigned int i;
6038 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6040 if (!desc)
6041 return E_INVALIDARG;
6043 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6044 d3d10_1_desc.IndependentBlendEnable = FALSE;
6045 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6047 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6048 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6049 d3d10_1_desc.IndependentBlendEnable = TRUE;
6052 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6054 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6055 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6056 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6057 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6058 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6059 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6060 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6061 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6064 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6067 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6068 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6070 struct d3d_device *device = impl_from_ID3D10Device(iface);
6071 struct d3d_depthstencil_state *object;
6072 HRESULT hr;
6074 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6076 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6077 return hr;
6079 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6081 return S_OK;
6084 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6085 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6087 struct d3d_device *device = impl_from_ID3D10Device(iface);
6088 struct d3d_rasterizer_state *object;
6089 HRESULT hr;
6091 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6093 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6094 return hr;
6096 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6098 return S_OK;
6101 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6102 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6104 struct d3d_device *device = impl_from_ID3D10Device(iface);
6105 struct d3d_sampler_state *object;
6106 HRESULT hr;
6108 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6110 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6111 return hr;
6113 *sampler_state = &object->ID3D10SamplerState_iface;
6115 return S_OK;
6118 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6119 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6121 struct d3d_device *device = impl_from_ID3D10Device(iface);
6122 struct d3d_query *object;
6123 HRESULT hr;
6125 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6127 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6128 return hr;
6130 if (query)
6132 *query = &object->ID3D10Query_iface;
6133 return S_OK;
6136 ID3D10Query_Release(&object->ID3D10Query_iface);
6137 return S_FALSE;
6140 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6141 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6143 struct d3d_device *device = impl_from_ID3D10Device(iface);
6144 struct d3d_query *object;
6145 HRESULT hr;
6147 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6149 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6150 return hr;
6152 if (predicate)
6154 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6155 return S_OK;
6158 ID3D10Query_Release(&object->ID3D10Query_iface);
6159 return S_FALSE;
6162 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6163 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6165 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6167 return E_NOTIMPL;
6170 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6171 DXGI_FORMAT format, UINT *format_support)
6173 struct d3d_device *device = impl_from_ID3D10Device(iface);
6175 TRACE("iface %p, format %s, format_support %p.\n",
6176 iface, debug_dxgi_format(format), format_support);
6178 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6181 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6182 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6184 struct d3d_device *device = impl_from_ID3D10Device(iface);
6186 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6187 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6189 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6190 sample_count, quality_level_count);
6193 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6195 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6198 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6199 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6200 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6202 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6203 "units %p, units_length %p, description %p, description_length %p stub!\n",
6204 iface, desc, type, active_counters, name, name_length,
6205 units, units_length, description, description_length);
6207 return E_NOTIMPL;
6210 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6212 FIXME("iface %p stub!\n", iface);
6214 return 0;
6217 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6218 HANDLE resource_handle, REFIID guid, void **resource)
6220 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6221 iface, resource_handle, debugstr_guid(guid), resource);
6223 return E_NOTIMPL;
6226 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6228 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6231 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6233 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6236 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6238 return (D3D10_FEATURE_LEVEL1)level;
6241 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6243 struct d3d_device *device = impl_from_ID3D10Device(iface);
6245 TRACE("iface %p.\n", iface);
6247 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6250 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6252 /* IUnknown methods */
6253 d3d10_device_QueryInterface,
6254 d3d10_device_AddRef,
6255 d3d10_device_Release,
6256 /* ID3D10Device methods */
6257 d3d10_device_VSSetConstantBuffers,
6258 d3d10_device_PSSetShaderResources,
6259 d3d10_device_PSSetShader,
6260 d3d10_device_PSSetSamplers,
6261 d3d10_device_VSSetShader,
6262 d3d10_device_DrawIndexed,
6263 d3d10_device_Draw,
6264 d3d10_device_PSSetConstantBuffers,
6265 d3d10_device_IASetInputLayout,
6266 d3d10_device_IASetVertexBuffers,
6267 d3d10_device_IASetIndexBuffer,
6268 d3d10_device_DrawIndexedInstanced,
6269 d3d10_device_DrawInstanced,
6270 d3d10_device_GSSetConstantBuffers,
6271 d3d10_device_GSSetShader,
6272 d3d10_device_IASetPrimitiveTopology,
6273 d3d10_device_VSSetShaderResources,
6274 d3d10_device_VSSetSamplers,
6275 d3d10_device_SetPredication,
6276 d3d10_device_GSSetShaderResources,
6277 d3d10_device_GSSetSamplers,
6278 d3d10_device_OMSetRenderTargets,
6279 d3d10_device_OMSetBlendState,
6280 d3d10_device_OMSetDepthStencilState,
6281 d3d10_device_SOSetTargets,
6282 d3d10_device_DrawAuto,
6283 d3d10_device_RSSetState,
6284 d3d10_device_RSSetViewports,
6285 d3d10_device_RSSetScissorRects,
6286 d3d10_device_CopySubresourceRegion,
6287 d3d10_device_CopyResource,
6288 d3d10_device_UpdateSubresource,
6289 d3d10_device_ClearRenderTargetView,
6290 d3d10_device_ClearDepthStencilView,
6291 d3d10_device_GenerateMips,
6292 d3d10_device_ResolveSubresource,
6293 d3d10_device_VSGetConstantBuffers,
6294 d3d10_device_PSGetShaderResources,
6295 d3d10_device_PSGetShader,
6296 d3d10_device_PSGetSamplers,
6297 d3d10_device_VSGetShader,
6298 d3d10_device_PSGetConstantBuffers,
6299 d3d10_device_IAGetInputLayout,
6300 d3d10_device_IAGetVertexBuffers,
6301 d3d10_device_IAGetIndexBuffer,
6302 d3d10_device_GSGetConstantBuffers,
6303 d3d10_device_GSGetShader,
6304 d3d10_device_IAGetPrimitiveTopology,
6305 d3d10_device_VSGetShaderResources,
6306 d3d10_device_VSGetSamplers,
6307 d3d10_device_GetPredication,
6308 d3d10_device_GSGetShaderResources,
6309 d3d10_device_GSGetSamplers,
6310 d3d10_device_OMGetRenderTargets,
6311 d3d10_device_OMGetBlendState,
6312 d3d10_device_OMGetDepthStencilState,
6313 d3d10_device_SOGetTargets,
6314 d3d10_device_RSGetState,
6315 d3d10_device_RSGetViewports,
6316 d3d10_device_RSGetScissorRects,
6317 d3d10_device_GetDeviceRemovedReason,
6318 d3d10_device_SetExceptionMode,
6319 d3d10_device_GetExceptionMode,
6320 d3d10_device_GetPrivateData,
6321 d3d10_device_SetPrivateData,
6322 d3d10_device_SetPrivateDataInterface,
6323 d3d10_device_ClearState,
6324 d3d10_device_Flush,
6325 d3d10_device_CreateBuffer,
6326 d3d10_device_CreateTexture1D,
6327 d3d10_device_CreateTexture2D,
6328 d3d10_device_CreateTexture3D,
6329 d3d10_device_CreateShaderResourceView,
6330 d3d10_device_CreateRenderTargetView,
6331 d3d10_device_CreateDepthStencilView,
6332 d3d10_device_CreateInputLayout,
6333 d3d10_device_CreateVertexShader,
6334 d3d10_device_CreateGeometryShader,
6335 d3d10_device_CreateGeometryShaderWithStreamOutput,
6336 d3d10_device_CreatePixelShader,
6337 d3d10_device_CreateBlendState,
6338 d3d10_device_CreateDepthStencilState,
6339 d3d10_device_CreateRasterizerState,
6340 d3d10_device_CreateSamplerState,
6341 d3d10_device_CreateQuery,
6342 d3d10_device_CreatePredicate,
6343 d3d10_device_CreateCounter,
6344 d3d10_device_CheckFormatSupport,
6345 d3d10_device_CheckMultisampleQualityLevels,
6346 d3d10_device_CheckCounterInfo,
6347 d3d10_device_CheckCounter,
6348 d3d10_device_GetCreationFlags,
6349 d3d10_device_OpenSharedResource,
6350 d3d10_device_SetTextFilterSize,
6351 d3d10_device_GetTextFilterSize,
6352 d3d10_device_CreateShaderResourceView1,
6353 d3d10_device_CreateBlendState1,
6354 d3d10_device_GetFeatureLevel,
6357 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6359 /* IUnknown methods */
6360 d3d_device_inner_QueryInterface,
6361 d3d_device_inner_AddRef,
6362 d3d_device_inner_Release,
6365 /* ID3D10Multithread methods */
6367 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6369 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6372 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6374 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6376 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6378 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6381 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6383 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6385 TRACE("iface %p.\n", iface);
6387 return IUnknown_AddRef(device->outer_unk);
6390 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6392 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6394 TRACE("iface %p.\n", iface);
6396 return IUnknown_Release(device->outer_unk);
6399 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6401 TRACE("iface %p.\n", iface);
6403 wined3d_mutex_lock();
6406 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6408 TRACE("iface %p.\n", iface);
6410 wined3d_mutex_unlock();
6413 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6415 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6417 return TRUE;
6420 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6422 FIXME("iface %p stub!\n", iface);
6424 return TRUE;
6427 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6429 d3d10_multithread_QueryInterface,
6430 d3d10_multithread_AddRef,
6431 d3d10_multithread_Release,
6432 d3d10_multithread_Enter,
6433 d3d10_multithread_Leave,
6434 d3d10_multithread_SetMultithreadProtected,
6435 d3d10_multithread_GetMultithreadProtected,
6438 /* IWineDXGIDeviceParent IUnknown methods */
6440 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6442 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6445 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6446 REFIID iid, void **out)
6448 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6449 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6452 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6454 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6455 return IUnknown_AddRef(device->outer_unk);
6458 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6460 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6461 return IUnknown_Release(device->outer_unk);
6464 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6465 IWineDXGIDeviceParent *iface)
6467 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6468 return &device->device_parent;
6471 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6473 /* IUnknown methods */
6474 dxgi_device_parent_QueryInterface,
6475 dxgi_device_parent_AddRef,
6476 dxgi_device_parent_Release,
6477 /* IWineDXGIDeviceParent methods */
6478 dxgi_device_parent_get_wined3d_device_parent,
6481 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6483 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6486 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6487 struct wined3d_device *wined3d_device)
6489 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6490 struct d3d_device_context_state *state;
6491 struct wined3d_state *wined3d_state;
6492 D3D_FEATURE_LEVEL feature_level;
6494 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6496 wined3d_device_incref(wined3d_device);
6497 device->wined3d_device = wined3d_device;
6498 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6500 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6501 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6503 if (!(state = heap_alloc_zero(sizeof(*state))))
6505 ERR("Failed to create the initial device context state.\n");
6506 return;
6509 d3d_device_context_state_init(state, device, feature_level,
6510 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6512 device->state = state;
6513 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6514 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6516 d3d_device_context_state_private_addref(state);
6517 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6520 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6522 TRACE("device_parent %p.\n", device_parent);
6525 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6527 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6530 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6531 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6532 void **parent, const struct wined3d_parent_ops **parent_ops)
6534 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6535 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6537 *parent = NULL;
6538 *parent_ops = &d3d_null_wined3d_parent_ops;
6540 return S_OK;
6543 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6544 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6545 struct wined3d_texture **wined3d_texture)
6547 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6548 struct d3d_texture2d *texture;
6549 ID3D11Texture2D *texture_iface;
6550 D3D11_TEXTURE2D_DESC desc;
6551 HRESULT hr;
6553 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6554 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6556 desc.Width = wined3d_desc->width;
6557 desc.Height = wined3d_desc->height;
6558 desc.MipLevels = 1;
6559 desc.ArraySize = 1;
6560 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6561 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6562 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6563 desc.Usage = D3D11_USAGE_DEFAULT;
6564 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6565 desc.CPUAccessFlags = 0;
6566 desc.MiscFlags = 0;
6568 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6570 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6571 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6574 if (texture_flags)
6575 FIXME("Unhandled flags %#x.\n", texture_flags);
6577 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6578 &desc, NULL, &texture_iface)))
6580 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6581 return hr;
6584 texture = impl_from_ID3D11Texture2D(texture_iface);
6586 *wined3d_texture = texture->wined3d_texture;
6587 wined3d_texture_incref(*wined3d_texture);
6588 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6590 return S_OK;
6593 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6595 device_parent_wined3d_device_created,
6596 device_parent_mode_changed,
6597 device_parent_activate,
6598 device_parent_texture_sub_resource_created,
6599 device_parent_create_swapchain_texture,
6602 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6604 const D3D11_SAMPLER_DESC *ka = key;
6605 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6607 return memcmp(ka, kb, sizeof(*ka));
6610 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6612 const D3D11_BLEND_DESC *ka = key;
6613 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6615 return memcmp(ka, kb, sizeof(*ka));
6618 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6620 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6621 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6622 const struct d3d_depthstencil_state, entry)->desc;
6624 return memcmp(ka, kb, sizeof(*ka));
6627 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6629 const D3D11_RASTERIZER_DESC *ka = key;
6630 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6632 return memcmp(ka, kb, sizeof(*ka));
6635 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6637 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6638 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6639 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6640 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6641 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6642 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6643 device->refcount = 1;
6644 /* COM aggregation always takes place */
6645 device->outer_unk = outer_unknown;
6646 device->d3d11_only = FALSE;
6647 device->state = NULL;
6649 d3d11_immediate_context_init(&device->immediate_context, device);
6650 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6652 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6653 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6654 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6655 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);