mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / d3d11 / device.c
blob9845f93eebfe2dd8c0b50b3ae137f81bde7b6acf
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 wined3d_resource *wined3d_resource;
607 struct wined3d_map_desc map_desc;
608 HRESULT hr;
610 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
611 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
613 if (map_flags)
614 FIXME("Ignoring map_flags %#x.\n", map_flags);
616 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
618 wined3d_mutex_lock();
619 hr = wined3d_resource_map(wined3d_resource, subresource_idx,
620 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
621 wined3d_mutex_unlock();
623 mapped_subresource->pData = map_desc.data;
624 mapped_subresource->RowPitch = map_desc.row_pitch;
625 mapped_subresource->DepthPitch = map_desc.slice_pitch;
627 return hr;
630 static void STDMETHODCALLTYPE d3d11_immediate_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
631 UINT subresource_idx)
633 struct wined3d_resource *wined3d_resource;
635 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
637 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
639 wined3d_mutex_lock();
640 wined3d_resource_unmap(wined3d_resource, subresource_idx);
641 wined3d_mutex_unlock();
644 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
645 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
647 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
648 iface, start_slot, buffer_count, buffers);
650 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
651 buffer_count, buffers);
654 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
655 ID3D11InputLayout *input_layout)
657 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
658 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
660 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
662 wined3d_mutex_lock();
663 wined3d_device_context_set_vertex_declaration(context->wined3d_context, layout ? layout->wined3d_decl : NULL);
664 wined3d_mutex_unlock();
667 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
668 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
670 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
671 unsigned int i;
673 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
674 iface, start_slot, buffer_count, buffers, strides, offsets);
676 wined3d_mutex_lock();
677 for (i = 0; i < buffer_count; ++i)
679 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
681 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
682 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
684 wined3d_mutex_unlock();
687 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
688 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
690 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
691 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
693 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
694 iface, buffer, debug_dxgi_format(format), offset);
696 wined3d_mutex_lock();
697 wined3d_device_context_set_index_buffer(context->wined3d_context,
698 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
699 wined3dformat_from_dxgi_format(format), offset);
700 wined3d_mutex_unlock();
703 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
704 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
705 UINT start_instance_location)
707 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
709 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
710 "base_vertex_location %d, start_instance_location %u.\n",
711 iface, instance_index_count, instance_count, start_index_location,
712 base_vertex_location, start_instance_location);
714 wined3d_mutex_lock();
715 wined3d_device_context_draw_indexed(context->wined3d_context, base_vertex_location,
716 start_index_location, instance_index_count, start_instance_location, instance_count);
717 wined3d_mutex_unlock();
720 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstanced(ID3D11DeviceContext1 *iface,
721 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
723 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
725 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
726 "start_instance_location %u.\n",
727 iface, instance_vertex_count, instance_count, start_vertex_location,
728 start_instance_location);
730 wined3d_mutex_lock();
731 wined3d_device_context_draw(context->wined3d_context, start_vertex_location,
732 instance_vertex_count, start_instance_location, instance_count);
733 wined3d_mutex_unlock();
736 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers(ID3D11DeviceContext1 *iface,
737 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
739 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
740 iface, start_slot, buffer_count, buffers);
742 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
743 buffer_count, buffers);
746 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShader(ID3D11DeviceContext1 *iface,
747 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
749 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
750 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
752 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
753 iface, shader, class_instances, class_instance_count);
755 if (class_instances)
756 FIXME("Dynamic linking is not implemented yet.\n");
758 wined3d_mutex_lock();
759 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
760 gs ? gs->wined3d_shader : NULL);
761 wined3d_mutex_unlock();
764 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetPrimitiveTopology(ID3D11DeviceContext1 *iface,
765 D3D11_PRIMITIVE_TOPOLOGY topology)
767 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
768 enum wined3d_primitive_type primitive_type;
769 unsigned int patch_vertex_count;
771 TRACE("iface %p, topology %#x.\n", iface, topology);
773 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
775 wined3d_mutex_lock();
776 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, patch_vertex_count);
777 wined3d_mutex_unlock();
780 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShaderResources(ID3D11DeviceContext1 *iface,
781 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
783 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
784 unsigned int i;
786 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
788 wined3d_mutex_lock();
789 for (i = 0; i < view_count; ++i)
791 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
793 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
794 start_slot + i, view ? view->wined3d_view : NULL);
796 wined3d_mutex_unlock();
799 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetSamplers(ID3D11DeviceContext1 *iface,
800 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
802 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
803 unsigned int i;
805 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
806 iface, start_slot, sampler_count, samplers);
808 wined3d_mutex_lock();
809 for (i = 0; i < sampler_count; ++i)
811 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
813 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX, start_slot + i,
814 sampler ? sampler->wined3d_sampler : NULL);
816 wined3d_mutex_unlock();
819 static void STDMETHODCALLTYPE d3d11_immediate_context_Begin(ID3D11DeviceContext1 *iface,
820 ID3D11Asynchronous *asynchronous)
822 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
823 HRESULT hr;
825 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
827 wined3d_mutex_lock();
828 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_BEGIN)))
829 ERR("Failed to issue query, hr %#x.\n", hr);
830 wined3d_mutex_unlock();
833 static void STDMETHODCALLTYPE d3d11_immediate_context_End(ID3D11DeviceContext1 *iface,
834 ID3D11Asynchronous *asynchronous)
836 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
837 HRESULT hr;
839 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
841 wined3d_mutex_lock();
842 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_END)))
843 ERR("Failed to issue query, hr %#x.\n", hr);
844 wined3d_mutex_unlock();
847 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetData(ID3D11DeviceContext1 *iface,
848 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
850 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
851 unsigned int wined3d_flags;
852 HRESULT hr;
854 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
855 iface, asynchronous, data, data_size, data_flags);
857 if (!data && data_size)
858 return E_INVALIDARG;
860 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
862 wined3d_mutex_lock();
863 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
865 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
866 if (hr == WINED3DERR_INVALIDCALL)
867 hr = DXGI_ERROR_INVALID_CALL;
869 else
871 WARN("Invalid data size %u.\n", data_size);
872 hr = E_INVALIDARG;
874 wined3d_mutex_unlock();
876 return hr;
879 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext1 *iface,
880 ID3D11Predicate *predicate, BOOL value)
882 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
883 struct d3d_query *query;
885 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
887 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
889 wined3d_mutex_lock();
890 wined3d_device_context_set_predication(context->wined3d_context, query ? query->wined3d_query : NULL, value);
891 wined3d_mutex_unlock();
894 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext1 *iface,
895 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
897 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
898 unsigned int i;
900 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
902 wined3d_mutex_lock();
903 for (i = 0; i < view_count; ++i)
905 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
907 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
908 start_slot + i, view ? view->wined3d_view : NULL);
910 wined3d_mutex_unlock();
913 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext1 *iface,
914 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
916 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
917 unsigned int i;
919 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
920 iface, start_slot, sampler_count, samplers);
922 wined3d_mutex_lock();
923 for (i = 0; i < sampler_count; ++i)
925 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
927 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i,
928 sampler ? sampler->wined3d_sampler : NULL);
930 wined3d_mutex_unlock();
933 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
934 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
935 ID3D11DepthStencilView *depth_stencil_view)
937 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
938 struct d3d_depthstencil_view *dsv;
939 unsigned int i;
941 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
942 iface, render_target_view_count, render_target_views, depth_stencil_view);
944 wined3d_mutex_lock();
945 for (i = 0; i < render_target_view_count; ++i)
947 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
948 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
949 rtv ? rtv->wined3d_view : NULL, FALSE);
951 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
953 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
956 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
957 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
958 wined3d_mutex_unlock();
961 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
962 ID3D11DeviceContext1 *iface, UINT render_target_view_count,
963 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
964 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
965 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
967 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
968 unsigned int i;
970 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
971 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
972 "initial_counts %p.\n",
973 iface, render_target_view_count, render_target_views, depth_stencil_view,
974 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
975 initial_counts);
977 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
979 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
980 depth_stencil_view);
983 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
985 wined3d_mutex_lock();
986 for (i = 0; i < unordered_access_view_start_slot; ++i)
988 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
989 WINED3D_PIPELINE_GRAPHICS, i, NULL, ~0u);
991 for (i = 0; i < unordered_access_view_count; ++i)
993 struct d3d11_unordered_access_view *view
994 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
996 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
997 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i,
998 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1000 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
1002 wined3d_device_context_set_unordered_access_view(context->wined3d_context,
1003 WINED3D_PIPELINE_GRAPHICS, unordered_access_view_start_slot + i, NULL, ~0u);
1005 wined3d_mutex_unlock();
1009 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext1 *iface,
1010 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
1012 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1013 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1014 struct d3d_blend_state *blend_state_impl;
1016 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
1017 iface, blend_state, debug_float4(blend_factor), sample_mask);
1019 if (!blend_factor)
1020 blend_factor = default_blend_factor;
1022 wined3d_mutex_lock();
1023 if (!(blend_state_impl = unsafe_impl_from_ID3D11BlendState(blend_state)))
1024 wined3d_device_context_set_blend_state(context->wined3d_context, NULL,
1025 (const struct wined3d_color *)blend_factor, sample_mask);
1026 else
1027 wined3d_device_context_set_blend_state(context->wined3d_context, blend_state_impl->wined3d_state,
1028 (const struct wined3d_color *)blend_factor, sample_mask);
1029 wined3d_mutex_unlock();
1032 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext1 *iface,
1033 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
1035 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1036 struct d3d_depthstencil_state *state_impl;
1038 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1039 iface, depth_stencil_state, stencil_ref);
1041 wined3d_mutex_lock();
1042 if (!(state_impl = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
1044 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, NULL, stencil_ref);
1045 wined3d_mutex_unlock();
1046 return;
1049 wined3d_device_context_set_depth_stencil_state(context->wined3d_context, state_impl->wined3d_state, stencil_ref);
1050 wined3d_mutex_unlock();
1053 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext1 *iface, UINT buffer_count,
1054 ID3D11Buffer *const *buffers, const UINT *offsets)
1056 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1057 unsigned int count, i;
1059 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
1061 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
1062 wined3d_mutex_lock();
1063 for (i = 0; i < count; ++i)
1065 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1067 wined3d_device_context_set_stream_output(context->wined3d_context, i,
1068 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1070 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1072 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
1074 wined3d_mutex_unlock();
1077 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext1 *iface)
1079 FIXME("iface %p stub!\n", iface);
1082 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext1 *iface,
1083 ID3D11Buffer *buffer, UINT offset)
1085 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1086 struct d3d_buffer *d3d_buffer;
1088 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1090 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1092 wined3d_mutex_lock();
1093 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, true);
1094 wined3d_mutex_unlock();
1097 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1098 ID3D11Buffer *buffer, UINT offset)
1100 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1101 struct d3d_buffer *d3d_buffer;
1103 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1105 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1107 wined3d_mutex_lock();
1108 wined3d_device_context_draw_indirect(context->wined3d_context, d3d_buffer->wined3d_buffer, offset, false);
1109 wined3d_mutex_unlock();
1112 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext1 *iface,
1113 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1115 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1117 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1118 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1120 wined3d_mutex_lock();
1121 wined3d_device_context_dispatch(context->wined3d_context,
1122 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1123 wined3d_mutex_unlock();
1126 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1127 ID3D11Buffer *buffer, UINT offset)
1129 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1130 struct d3d_buffer *buffer_impl;
1132 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1134 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1136 wined3d_mutex_lock();
1137 wined3d_device_context_dispatch_indirect(context->wined3d_context, buffer_impl->wined3d_buffer, offset);
1138 wined3d_mutex_unlock();
1141 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext1 *iface,
1142 ID3D11RasterizerState *rasterizer_state)
1144 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1145 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1146 struct d3d_rasterizer_state *rasterizer_state_impl;
1147 const D3D11_RASTERIZER_DESC *desc;
1149 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1151 wined3d_mutex_lock();
1152 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
1154 wined3d_device_context_set_rasterizer_state(context->wined3d_context, NULL);
1155 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1156 wined3d_mutex_unlock();
1157 return;
1160 wined3d_device_context_set_rasterizer_state(context->wined3d_context, rasterizer_state_impl->wined3d_state);
1162 desc = &rasterizer_state_impl->desc;
1163 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1164 wined3d_mutex_unlock();
1167 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1168 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1170 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1171 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1172 unsigned int i;
1174 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1176 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1177 return;
1179 for (i = 0; i < viewport_count; ++i)
1181 wined3d_vp[i].x = viewports[i].TopLeftX;
1182 wined3d_vp[i].y = viewports[i].TopLeftY;
1183 wined3d_vp[i].width = viewports[i].Width;
1184 wined3d_vp[i].height = viewports[i].Height;
1185 wined3d_vp[i].min_z = viewports[i].MinDepth;
1186 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1189 wined3d_mutex_lock();
1190 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1191 wined3d_mutex_unlock();
1194 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1195 UINT rect_count, const D3D11_RECT *rects)
1197 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1199 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1201 if (rect_count > WINED3D_MAX_VIEWPORTS)
1202 return;
1204 wined3d_mutex_lock();
1205 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1206 wined3d_mutex_unlock();
1209 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1210 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1211 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1213 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1214 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1215 struct wined3d_box wined3d_src_box;
1217 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1218 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1219 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1220 src_resource, src_subresource_idx, src_box);
1222 if (!dst_resource || !src_resource)
1223 return;
1225 if (src_box)
1226 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1227 src_box->right, src_box->bottom, src_box->front, src_box->back);
1229 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1230 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1231 wined3d_mutex_lock();
1232 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
1233 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1234 wined3d_mutex_unlock();
1237 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext1 *iface,
1238 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1240 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1241 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1243 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1245 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1246 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1247 wined3d_mutex_lock();
1248 wined3d_device_context_copy_resource(context->wined3d_context, wined3d_dst_resource, wined3d_src_resource);
1249 wined3d_mutex_unlock();
1252 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1253 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1254 const void *data, UINT row_pitch, UINT depth_pitch)
1256 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1257 struct wined3d_resource *wined3d_resource;
1258 struct wined3d_box wined3d_box;
1260 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1261 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1263 if (box)
1264 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1266 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1267 wined3d_mutex_lock();
1268 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource,
1269 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1270 wined3d_mutex_unlock();
1273 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1274 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1276 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1277 struct d3d11_unordered_access_view *uav;
1278 struct d3d_buffer *buffer_impl;
1280 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1281 iface, dst_buffer, dst_offset, src_view);
1283 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1284 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1286 wined3d_mutex_lock();
1287 wined3d_device_context_copy_uav_counter(context->wined3d_context,
1288 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1289 wined3d_mutex_unlock();
1292 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1293 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1295 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1296 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1297 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1298 HRESULT hr;
1300 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1301 iface, render_target_view, debug_float4(color_rgba));
1303 if (!view)
1304 return;
1306 wined3d_mutex_lock();
1307 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1308 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1309 ERR("Failed to clear view, hr %#x.\n", hr);
1310 wined3d_mutex_unlock();
1313 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1314 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1316 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1317 struct d3d11_unordered_access_view *view;
1319 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1320 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1322 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1323 wined3d_mutex_lock();
1324 wined3d_device_context_clear_uav_uint(context->wined3d_context,
1325 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1326 wined3d_mutex_unlock();
1329 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1330 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1332 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1333 iface, unordered_access_view, debug_float4(values));
1336 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1337 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1339 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1340 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1341 DWORD wined3d_flags;
1342 HRESULT hr;
1344 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1345 iface, depth_stencil_view, flags, depth, stencil);
1347 if (!view)
1348 return;
1350 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1352 wined3d_mutex_lock();
1353 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(context->wined3d_context, view->wined3d_view, NULL,
1354 wined3d_flags, NULL, depth, stencil)))
1355 ERR("Failed to clear view, hr %#x.\n", hr);
1356 wined3d_mutex_unlock();
1359 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext1 *iface,
1360 ID3D11ShaderResourceView *view)
1362 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1363 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1365 TRACE("iface %p, view %p.\n", iface, view);
1367 wined3d_mutex_lock();
1368 wined3d_device_context_generate_mipmaps(context->wined3d_context, srv->wined3d_view);
1369 wined3d_mutex_unlock();
1372 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1373 ID3D11Resource *resource, FLOAT min_lod)
1375 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1378 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1379 ID3D11Resource *resource)
1381 FIXME("iface %p, resource %p stub!\n", iface, resource);
1383 return 0.0f;
1386 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1387 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1388 ID3D11Resource *src_resource, UINT src_subresource_idx,
1389 DXGI_FORMAT format)
1391 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1392 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1393 enum wined3d_format_id wined3d_format;
1395 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1396 "src_resource %p, src_subresource_idx %u, format %s.\n",
1397 iface, dst_resource, dst_subresource_idx,
1398 src_resource, src_subresource_idx, debug_dxgi_format(format));
1400 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1401 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1402 wined3d_format = wined3dformat_from_dxgi_format(format);
1403 wined3d_mutex_lock();
1404 wined3d_device_context_resolve_sub_resource(context->wined3d_context,
1405 wined3d_dst_resource, dst_subresource_idx,
1406 wined3d_src_resource, src_subresource_idx, wined3d_format);
1407 wined3d_mutex_unlock();
1410 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1411 ID3D11CommandList *command_list, BOOL restore_state)
1413 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1416 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1417 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1419 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1420 unsigned int i;
1422 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1423 iface, start_slot, view_count, views);
1425 wined3d_mutex_lock();
1426 for (i = 0; i < view_count; ++i)
1428 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1430 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1431 start_slot + i, view ? view->wined3d_view : NULL);
1433 wined3d_mutex_unlock();
1436 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext1 *iface,
1437 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1439 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1440 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1442 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1443 iface, shader, class_instances, class_instance_count);
1445 if (class_instances)
1446 FIXME("Dynamic linking is not implemented yet.\n");
1448 wined3d_mutex_lock();
1449 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1450 hs ? hs->wined3d_shader : NULL);
1451 wined3d_mutex_unlock();
1454 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1455 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1457 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1458 unsigned int i;
1460 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1461 iface, start_slot, sampler_count, samplers);
1463 wined3d_mutex_lock();
1464 for (i = 0; i < sampler_count; ++i)
1466 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1468 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1469 sampler ? sampler->wined3d_sampler : NULL);
1471 wined3d_mutex_unlock();
1474 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1475 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1477 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1478 iface, start_slot, buffer_count, buffers);
1480 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1481 buffer_count, buffers);
1484 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1485 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1487 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1488 unsigned int i;
1490 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1491 iface, start_slot, view_count, views);
1493 wined3d_mutex_lock();
1494 for (i = 0; i < view_count; ++i)
1496 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1498 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1499 start_slot + i, view ? view->wined3d_view : NULL);
1501 wined3d_mutex_unlock();
1504 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext1 *iface,
1505 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1507 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1508 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1510 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1511 iface, shader, class_instances, class_instance_count);
1513 if (class_instances)
1514 FIXME("Dynamic linking is not implemented yet.\n");
1516 wined3d_mutex_lock();
1517 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1518 ds ? ds->wined3d_shader : NULL);
1519 wined3d_mutex_unlock();
1522 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1523 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1525 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1526 unsigned int i;
1528 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1529 iface, start_slot, sampler_count, samplers);
1531 wined3d_mutex_lock();
1532 for (i = 0; i < sampler_count; ++i)
1534 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1536 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1537 sampler ? sampler->wined3d_sampler : NULL);
1539 wined3d_mutex_unlock();
1542 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1543 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1545 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1546 iface, start_slot, buffer_count, buffers);
1548 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1549 buffer_count, buffers);
1552 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1553 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1555 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1556 unsigned int i;
1558 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1559 iface, start_slot, view_count, views);
1561 wined3d_mutex_lock();
1562 for (i = 0; i < view_count; ++i)
1564 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1566 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1567 start_slot + i, view ? view->wined3d_view : NULL);
1569 wined3d_mutex_unlock();
1572 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1573 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1575 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1576 unsigned int i;
1578 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1579 iface, start_slot, view_count, views, initial_counts);
1581 wined3d_mutex_lock();
1582 for (i = 0; i < view_count; ++i)
1584 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1586 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1587 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1589 wined3d_mutex_unlock();
1592 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext1 *iface,
1593 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1595 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1596 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1598 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1599 iface, shader, class_instances, class_instance_count);
1601 if (class_instances)
1602 FIXME("Dynamic linking is not implemented yet.\n");
1604 wined3d_mutex_lock();
1605 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1606 cs ? cs->wined3d_shader : NULL);
1607 wined3d_mutex_unlock();
1610 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1611 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1613 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1614 unsigned int i;
1616 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1617 iface, start_slot, sampler_count, samplers);
1619 wined3d_mutex_lock();
1620 for (i = 0; i < sampler_count; ++i)
1622 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1624 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1625 sampler ? sampler->wined3d_sampler : NULL);
1627 wined3d_mutex_unlock();
1630 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1631 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1633 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1634 iface, start_slot, buffer_count, buffers);
1636 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1637 buffer_count, buffers);
1640 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1641 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1643 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1644 iface, start_slot, buffer_count, buffers);
1646 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1647 buffer_count, buffers);
1650 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1651 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1653 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1654 unsigned int i;
1656 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1657 iface, start_slot, view_count, views);
1659 wined3d_mutex_lock();
1660 for (i = 0; i < view_count; ++i)
1662 struct wined3d_shader_resource_view *wined3d_view;
1663 struct d3d_shader_resource_view *view_impl;
1665 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1667 views[i] = NULL;
1668 continue;
1671 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1672 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1673 ID3D11ShaderResourceView_AddRef(views[i]);
1675 wined3d_mutex_unlock();
1678 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext1 *iface,
1679 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1681 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1682 struct wined3d_shader *wined3d_shader;
1683 struct d3d_pixel_shader *shader_impl;
1685 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1686 iface, shader, class_instances, class_instance_count);
1688 if (class_instances || class_instance_count)
1689 FIXME("Dynamic linking not implemented yet.\n");
1690 if (class_instance_count)
1691 *class_instance_count = 0;
1693 wined3d_mutex_lock();
1694 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1696 wined3d_mutex_unlock();
1697 *shader = NULL;
1698 return;
1701 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1702 wined3d_mutex_unlock();
1703 *shader = &shader_impl->ID3D11PixelShader_iface;
1704 ID3D11PixelShader_AddRef(*shader);
1707 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1708 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1710 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1711 unsigned int i;
1713 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1714 iface, start_slot, sampler_count, samplers);
1716 wined3d_mutex_lock();
1717 for (i = 0; i < sampler_count; ++i)
1719 struct wined3d_sampler *wined3d_sampler;
1720 struct d3d_sampler_state *sampler_impl;
1722 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1724 samplers[i] = NULL;
1725 continue;
1728 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1729 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1730 ID3D11SamplerState_AddRef(samplers[i]);
1732 wined3d_mutex_unlock();
1735 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext1 *iface,
1736 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1738 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1739 struct d3d_vertex_shader *shader_impl;
1740 struct wined3d_shader *wined3d_shader;
1742 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1743 iface, shader, class_instances, class_instance_count);
1745 if (class_instances || class_instance_count)
1746 FIXME("Dynamic linking not implemented yet.\n");
1747 if (class_instance_count)
1748 *class_instance_count = 0;
1750 wined3d_mutex_lock();
1751 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1753 wined3d_mutex_unlock();
1754 *shader = NULL;
1755 return;
1758 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1759 wined3d_mutex_unlock();
1760 *shader = &shader_impl->ID3D11VertexShader_iface;
1761 ID3D11VertexShader_AddRef(*shader);
1764 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1765 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1767 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1768 iface, start_slot, buffer_count, buffers);
1770 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1771 buffer_count, buffers);
1774 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1775 ID3D11InputLayout **input_layout)
1777 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1778 struct wined3d_vertex_declaration *wined3d_declaration;
1779 struct d3d_input_layout *input_layout_impl;
1781 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1783 wined3d_mutex_lock();
1784 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1786 wined3d_mutex_unlock();
1787 *input_layout = NULL;
1788 return;
1791 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1792 wined3d_mutex_unlock();
1793 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1794 ID3D11InputLayout_AddRef(*input_layout);
1797 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1798 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1800 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1801 unsigned int i;
1803 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1804 iface, start_slot, buffer_count, buffers, strides, offsets);
1806 wined3d_mutex_lock();
1807 for (i = 0; i < buffer_count; ++i)
1809 struct wined3d_buffer *wined3d_buffer = NULL;
1810 struct d3d_buffer *buffer_impl;
1812 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1813 &wined3d_buffer, &offsets[i], &strides[i])))
1815 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1816 if (strides)
1817 strides[i] = 0;
1818 if (offsets)
1819 offsets[i] = 0;
1822 if (!wined3d_buffer)
1824 buffers[i] = NULL;
1825 continue;
1828 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1829 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1831 wined3d_mutex_unlock();
1834 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1835 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1837 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1838 enum wined3d_format_id wined3d_format;
1839 struct wined3d_buffer *wined3d_buffer;
1840 struct d3d_buffer *buffer_impl;
1842 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1844 wined3d_mutex_lock();
1845 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1846 *format = dxgi_format_from_wined3dformat(wined3d_format);
1847 if (!wined3d_buffer)
1849 wined3d_mutex_unlock();
1850 *buffer = NULL;
1851 return;
1854 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1855 wined3d_mutex_unlock();
1856 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1859 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1860 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1862 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1863 iface, start_slot, buffer_count, buffers);
1865 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1866 buffer_count, buffers);
1869 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext1 *iface,
1870 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1872 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1873 struct d3d_geometry_shader *shader_impl;
1874 struct wined3d_shader *wined3d_shader;
1876 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1877 iface, shader, class_instances, class_instance_count);
1879 if (class_instances || class_instance_count)
1880 FIXME("Dynamic linking not implemented yet.\n");
1881 if (class_instance_count)
1882 *class_instance_count = 0;
1884 wined3d_mutex_lock();
1885 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1887 wined3d_mutex_unlock();
1888 *shader = NULL;
1889 return;
1892 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1893 wined3d_mutex_unlock();
1894 *shader = &shader_impl->ID3D11GeometryShader_iface;
1895 ID3D11GeometryShader_AddRef(*shader);
1898 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
1899 D3D11_PRIMITIVE_TOPOLOGY *topology)
1901 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1902 enum wined3d_primitive_type primitive_type;
1903 unsigned int patch_vertex_count;
1905 TRACE("iface %p, topology %p.\n", iface, topology);
1907 wined3d_mutex_lock();
1908 wined3d_device_get_primitive_type(device->wined3d_device, &primitive_type, &patch_vertex_count);
1909 wined3d_mutex_unlock();
1911 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1914 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
1915 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1917 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1918 unsigned int i;
1920 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1922 wined3d_mutex_lock();
1923 for (i = 0; i < view_count; ++i)
1925 struct wined3d_shader_resource_view *wined3d_view;
1926 struct d3d_shader_resource_view *view_impl;
1928 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1930 views[i] = NULL;
1931 continue;
1934 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1935 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1936 ID3D11ShaderResourceView_AddRef(views[i]);
1938 wined3d_mutex_unlock();
1941 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
1942 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1944 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1945 unsigned int i;
1947 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1948 iface, start_slot, sampler_count, samplers);
1950 wined3d_mutex_lock();
1951 for (i = 0; i < sampler_count; ++i)
1953 struct wined3d_sampler *wined3d_sampler;
1954 struct d3d_sampler_state *sampler_impl;
1956 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1958 samplers[i] = NULL;
1959 continue;
1962 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1963 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1964 ID3D11SamplerState_AddRef(samplers[i]);
1966 wined3d_mutex_unlock();
1969 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext1 *iface,
1970 ID3D11Predicate **predicate, BOOL *value)
1972 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1973 struct wined3d_query *wined3d_predicate;
1974 struct d3d_query *predicate_impl;
1976 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1978 wined3d_mutex_lock();
1979 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1981 wined3d_mutex_unlock();
1982 *predicate = NULL;
1983 return;
1986 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1987 wined3d_mutex_unlock();
1988 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1989 ID3D11Predicate_AddRef(*predicate);
1992 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
1993 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1995 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1996 unsigned int i;
1998 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2000 wined3d_mutex_lock();
2001 for (i = 0; i < view_count; ++i)
2003 struct wined3d_shader_resource_view *wined3d_view;
2004 struct d3d_shader_resource_view *view_impl;
2006 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
2008 views[i] = NULL;
2009 continue;
2012 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2013 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2014 ID3D11ShaderResourceView_AddRef(views[i]);
2016 wined3d_mutex_unlock();
2019 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2020 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2022 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2023 unsigned int i;
2025 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2026 iface, start_slot, sampler_count, samplers);
2028 wined3d_mutex_lock();
2029 for (i = 0; i < sampler_count; ++i)
2031 struct d3d_sampler_state *sampler_impl;
2032 struct wined3d_sampler *wined3d_sampler;
2034 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
2036 samplers[i] = NULL;
2037 continue;
2040 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2041 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2042 ID3D11SamplerState_AddRef(samplers[i]);
2044 wined3d_mutex_unlock();
2047 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2048 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2049 ID3D11DepthStencilView **depth_stencil_view)
2051 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2052 struct wined3d_rendertarget_view *wined3d_view;
2054 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2055 iface, render_target_view_count, render_target_views, depth_stencil_view);
2057 wined3d_mutex_lock();
2058 if (render_target_views)
2060 struct d3d_rendertarget_view *view_impl;
2061 unsigned int i;
2063 for (i = 0; i < render_target_view_count; ++i)
2065 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
2066 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2068 render_target_views[i] = NULL;
2069 continue;
2072 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2073 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2077 if (depth_stencil_view)
2079 struct d3d_depthstencil_view *view_impl;
2081 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
2082 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2084 *depth_stencil_view = NULL;
2086 else
2088 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2089 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2092 wined3d_mutex_unlock();
2095 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
2096 ID3D11DeviceContext1 *iface,
2097 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2098 ID3D11DepthStencilView **depth_stencil_view,
2099 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2100 ID3D11UnorderedAccessView **unordered_access_views)
2102 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2103 struct wined3d_unordered_access_view *wined3d_view;
2104 struct d3d11_unordered_access_view *view_impl;
2105 unsigned int i;
2107 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2108 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2109 "unordered_access_views %p.\n",
2110 iface, render_target_view_count, render_target_views, depth_stencil_view,
2111 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2113 if (render_target_views || depth_stencil_view)
2114 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
2115 render_target_views, depth_stencil_view);
2117 if (unordered_access_views)
2119 wined3d_mutex_lock();
2120 for (i = 0; i < unordered_access_view_count; ++i)
2122 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
2123 unordered_access_view_start_slot + i)))
2125 unordered_access_views[i] = NULL;
2126 continue;
2129 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2130 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2131 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2133 wined3d_mutex_unlock();
2137 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2138 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2140 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2141 struct wined3d_blend_state *wined3d_state;
2142 struct d3d_blend_state *blend_state_impl;
2144 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2145 iface, blend_state, blend_factor, sample_mask);
2147 wined3d_mutex_lock();
2148 if ((wined3d_state = wined3d_device_get_blend_state(device->wined3d_device,
2149 (struct wined3d_color *)blend_factor, sample_mask)))
2151 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2152 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2154 else
2156 *blend_state = NULL;
2158 wined3d_mutex_unlock();
2161 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2162 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2164 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2165 struct wined3d_depth_stencil_state *wined3d_state;
2166 struct d3d_depthstencil_state *state_impl;
2168 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2169 iface, depth_stencil_state, stencil_ref);
2171 wined3d_mutex_lock();
2172 if ((wined3d_state = wined3d_device_get_depth_stencil_state(device->wined3d_device, stencil_ref)))
2174 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2175 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2177 else
2179 *depth_stencil_state = NULL;
2181 wined3d_mutex_unlock();
2184 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2185 UINT buffer_count, ID3D11Buffer **buffers)
2187 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2188 unsigned int i;
2190 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2192 wined3d_mutex_lock();
2193 for (i = 0; i < buffer_count; ++i)
2195 struct wined3d_buffer *wined3d_buffer;
2196 struct d3d_buffer *buffer_impl;
2198 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
2200 buffers[i] = NULL;
2201 continue;
2204 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2205 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2206 ID3D11Buffer_AddRef(buffers[i]);
2208 wined3d_mutex_unlock();
2211 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext1 *iface,
2212 ID3D11RasterizerState **rasterizer_state)
2214 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2215 struct d3d_rasterizer_state *rasterizer_state_impl;
2216 struct wined3d_rasterizer_state *wined3d_state;
2218 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2220 wined3d_mutex_lock();
2221 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
2223 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2224 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2226 else
2228 *rasterizer_state = NULL;
2230 wined3d_mutex_unlock();
2233 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2234 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2236 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2237 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2238 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2240 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2242 if (!viewport_count)
2243 return;
2245 wined3d_mutex_lock();
2246 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
2247 wined3d_mutex_unlock();
2249 if (!viewports)
2251 *viewport_count = actual_count;
2252 return;
2255 if (*viewport_count > actual_count)
2256 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2258 *viewport_count = min(actual_count, *viewport_count);
2259 for (i = 0; i < *viewport_count; ++i)
2261 viewports[i].TopLeftX = wined3d_vp[i].x;
2262 viewports[i].TopLeftY = wined3d_vp[i].y;
2263 viewports[i].Width = wined3d_vp[i].width;
2264 viewports[i].Height = wined3d_vp[i].height;
2265 viewports[i].MinDepth = wined3d_vp[i].min_z;
2266 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2270 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2271 UINT *rect_count, D3D11_RECT *rects)
2273 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2274 unsigned int actual_count;
2276 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2278 if (!rect_count)
2279 return;
2281 actual_count = *rect_count;
2283 wined3d_mutex_lock();
2284 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
2285 wined3d_mutex_unlock();
2287 if (rects && *rect_count > actual_count)
2288 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2289 *rect_count = actual_count;
2292 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2293 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2295 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2296 unsigned int i;
2298 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2300 wined3d_mutex_lock();
2301 for (i = 0; i < view_count; ++i)
2303 struct wined3d_shader_resource_view *wined3d_view;
2304 struct d3d_shader_resource_view *view_impl;
2306 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2308 views[i] = NULL;
2309 continue;
2312 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2313 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2315 wined3d_mutex_unlock();
2318 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext1 *iface,
2319 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2321 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2322 struct d3d11_hull_shader *shader_impl;
2323 struct wined3d_shader *wined3d_shader;
2325 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2326 iface, shader, class_instances, class_instance_count);
2328 if (class_instances || class_instance_count)
2329 FIXME("Dynamic linking not implemented yet.\n");
2330 if (class_instance_count)
2331 *class_instance_count = 0;
2333 wined3d_mutex_lock();
2334 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2336 wined3d_mutex_unlock();
2337 *shader = NULL;
2338 return;
2341 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2342 wined3d_mutex_unlock();
2343 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2346 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2347 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2349 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2350 unsigned int i;
2352 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2353 iface, start_slot, sampler_count, samplers);
2355 wined3d_mutex_lock();
2356 for (i = 0; i < sampler_count; ++i)
2358 struct wined3d_sampler *wined3d_sampler;
2359 struct d3d_sampler_state *sampler_impl;
2361 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2363 samplers[i] = NULL;
2364 continue;
2367 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2368 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2370 wined3d_mutex_unlock();
2373 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2374 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2376 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2377 iface, start_slot, buffer_count, buffers);
2379 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2380 buffer_count, buffers);
2383 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2384 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2386 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2387 unsigned int i;
2389 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2390 iface, start_slot, view_count, views);
2392 wined3d_mutex_lock();
2393 for (i = 0; i < view_count; ++i)
2395 struct wined3d_shader_resource_view *wined3d_view;
2396 struct d3d_shader_resource_view *view_impl;
2398 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2400 views[i] = NULL;
2401 continue;
2404 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2405 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2407 wined3d_mutex_unlock();
2410 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext1 *iface,
2411 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2413 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2414 struct d3d11_domain_shader *shader_impl;
2415 struct wined3d_shader *wined3d_shader;
2417 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2418 iface, shader, class_instances, class_instance_count);
2420 if (class_instances || class_instance_count)
2421 FIXME("Dynamic linking not implemented yet.\n");
2422 if (class_instance_count)
2423 *class_instance_count = 0;
2425 wined3d_mutex_lock();
2426 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2428 wined3d_mutex_unlock();
2429 *shader = NULL;
2430 return;
2433 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2434 wined3d_mutex_unlock();
2435 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2438 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2439 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2441 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2442 unsigned int i;
2444 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2445 iface, start_slot, sampler_count, samplers);
2447 wined3d_mutex_lock();
2448 for (i = 0; i < sampler_count; ++i)
2450 struct wined3d_sampler *wined3d_sampler;
2451 struct d3d_sampler_state *sampler_impl;
2453 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2455 samplers[i] = NULL;
2456 continue;
2459 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2460 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2462 wined3d_mutex_unlock();
2465 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2466 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2468 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2469 iface, start_slot, buffer_count, buffers);
2471 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2472 buffer_count, buffers);
2475 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2476 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2478 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2479 unsigned int i;
2481 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2483 wined3d_mutex_lock();
2484 for (i = 0; i < view_count; ++i)
2486 struct wined3d_shader_resource_view *wined3d_view;
2487 struct d3d_shader_resource_view *view_impl;
2489 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2491 views[i] = NULL;
2492 continue;
2495 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2496 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2498 wined3d_mutex_unlock();
2501 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2502 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2504 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2505 unsigned int i;
2507 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2509 wined3d_mutex_lock();
2510 for (i = 0; i < view_count; ++i)
2512 struct wined3d_unordered_access_view *wined3d_view;
2513 struct d3d11_unordered_access_view *view_impl;
2515 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2517 views[i] = NULL;
2518 continue;
2521 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2522 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2524 wined3d_mutex_unlock();
2527 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext1 *iface,
2528 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2530 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2531 struct d3d11_compute_shader *shader_impl;
2532 struct wined3d_shader *wined3d_shader;
2534 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2535 iface, shader, class_instances, class_instance_count);
2537 if (class_instances || class_instance_count)
2538 FIXME("Dynamic linking not implemented yet.\n");
2539 if (class_instance_count)
2540 *class_instance_count = 0;
2542 wined3d_mutex_lock();
2543 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2545 wined3d_mutex_unlock();
2546 *shader = NULL;
2547 return;
2550 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2551 wined3d_mutex_unlock();
2552 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2555 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2556 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2558 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2559 unsigned int i;
2561 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2562 iface, start_slot, sampler_count, samplers);
2564 wined3d_mutex_lock();
2565 for (i = 0; i < sampler_count; ++i)
2567 struct wined3d_sampler *wined3d_sampler;
2568 struct d3d_sampler_state *sampler_impl;
2570 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2572 samplers[i] = NULL;
2573 continue;
2576 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2577 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2579 wined3d_mutex_unlock();
2582 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2583 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2585 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2586 iface, start_slot, buffer_count, buffers);
2588 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2589 buffer_count, buffers);
2592 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext1 *iface)
2594 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2595 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2596 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2597 unsigned int i, j;
2599 TRACE("iface %p.\n", iface);
2601 wined3d_mutex_lock();
2602 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
2604 wined3d_device_context_set_shader(context->wined3d_context, i, NULL);
2605 for (j = 0; j < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++j)
2606 wined3d_device_context_set_constant_buffer(context->wined3d_context, i, j, NULL);
2607 for (j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++j)
2608 wined3d_device_context_set_shader_resource_view(context->wined3d_context, i, j, NULL);
2609 for (j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++j)
2610 wined3d_device_context_set_sampler(context->wined3d_context, i, j, NULL);
2612 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2614 wined3d_device_context_set_stream_source(context->wined3d_context, i, NULL, 0, 0);
2616 wined3d_device_context_set_index_buffer(context->wined3d_context, NULL, WINED3DFMT_UNKNOWN, 0);
2617 wined3d_device_context_set_vertex_declaration(context->wined3d_context, NULL);
2618 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED, 0);
2619 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2621 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
2623 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, NULL);
2624 for (i = 0; i < WINED3D_PIPELINE_COUNT; ++i)
2626 for (j = 0; j < D3D11_PS_CS_UAV_REGISTER_COUNT; ++j)
2627 wined3d_device_context_set_unordered_access_view(context->wined3d_context, i, j, NULL, ~0u);
2629 ID3D11DeviceContext1_OMSetDepthStencilState(iface, NULL, 0);
2630 ID3D11DeviceContext1_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2631 ID3D11DeviceContext1_RSSetViewports(iface, 0, NULL);
2632 ID3D11DeviceContext1_RSSetScissorRects(iface, 0, NULL);
2633 ID3D11DeviceContext1_RSSetState(iface, NULL);
2634 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2636 wined3d_device_context_set_stream_output(context->wined3d_context, i, NULL, 0);
2638 wined3d_device_context_set_predication(context->wined3d_context, NULL, FALSE);
2639 wined3d_mutex_unlock();
2642 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext1 *iface)
2644 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2646 TRACE("iface %p.\n", iface);
2648 wined3d_mutex_lock();
2649 wined3d_device_flush(device->wined3d_device);
2650 wined3d_mutex_unlock();
2653 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext1 *iface)
2655 TRACE("iface %p.\n", iface);
2657 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2660 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2662 TRACE("iface %p.\n", iface);
2664 return 0;
2667 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2668 BOOL restore, ID3D11CommandList **command_list)
2670 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2672 return DXGI_ERROR_INVALID_CALL;
2675 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2676 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2677 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2679 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2680 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2681 struct wined3d_box wined3d_src_box;
2683 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2684 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2685 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2686 src_resource, src_subresource_idx, src_box, flags);
2688 if (!dst_resource || !src_resource)
2689 return;
2691 if (src_box)
2692 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2693 src_box->right, src_box->bottom, src_box->front, src_box->back);
2695 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2696 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2697 wined3d_mutex_lock();
2698 wined3d_device_context_copy_sub_resource_region(context->wined3d_context, wined3d_dst_resource, dst_subresource_idx,
2699 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2700 wined3d_mutex_unlock();
2703 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2704 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2705 UINT row_pitch, UINT depth_pitch, UINT flags)
2707 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2708 struct wined3d_resource *wined3d_resource;
2709 struct wined3d_box wined3d_box;
2711 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2712 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2714 if (box)
2715 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2716 box->front, box->back);
2718 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2719 wined3d_mutex_lock();
2720 wined3d_device_context_update_sub_resource(context->wined3d_context, wined3d_resource, subresource_idx,
2721 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2722 wined3d_mutex_unlock();
2725 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardResource(ID3D11DeviceContext1 *iface,
2726 ID3D11Resource *resource)
2728 FIXME("iface %p, resource %p stub!\n", iface, resource);
2731 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2733 FIXME("iface %p, view %p stub!\n", iface, view);
2736 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2737 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2738 const UINT *num_constants)
2740 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2741 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2744 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2745 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2746 const UINT *num_constants)
2748 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2749 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2752 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2753 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2754 const UINT *num_constants)
2756 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2757 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2760 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2761 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2762 const UINT *num_constants)
2764 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2765 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2768 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2769 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2770 const UINT *num_constants)
2772 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2773 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2776 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2777 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2778 const UINT *num_constants)
2780 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2781 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2784 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2785 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2787 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2788 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2791 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2792 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2794 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2795 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2798 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2799 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2801 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2802 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2805 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2806 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2808 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2809 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2812 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2813 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2815 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2816 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2819 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2820 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2822 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2823 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2826 static void STDMETHODCALLTYPE d3d11_immediate_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2827 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2829 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2830 struct d3d_device_context_state *state_impl, *prev_impl;
2831 struct wined3d_state *wined3d_state;
2833 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2835 if (!state)
2837 if (prev)
2838 *prev = NULL;
2839 return;
2842 wined3d_mutex_lock();
2844 prev_impl = device->state;
2845 state_impl = impl_from_ID3DDeviceContextState(state);
2846 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2847 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2848 wined3d_device_set_state(device->wined3d_device, wined3d_state);
2850 if (prev)
2851 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2853 d3d_device_context_state_private_addref(state_impl);
2854 device->state = state_impl;
2855 d3d_device_context_state_private_release(prev_impl);
2857 if (d3d_device_is_d3d10_active(device))
2858 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2859 wined3d_mutex_unlock();
2862 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2863 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2865 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2868 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2869 const D3D11_RECT *rects, UINT num_rects)
2871 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
2874 static const struct ID3D11DeviceContext1Vtbl d3d11_immediate_context_vtbl =
2876 /* IUnknown methods */
2877 d3d11_immediate_context_QueryInterface,
2878 d3d11_immediate_context_AddRef,
2879 d3d11_immediate_context_Release,
2880 /* ID3D11DeviceChild methods */
2881 d3d11_immediate_context_GetDevice,
2882 d3d11_immediate_context_GetPrivateData,
2883 d3d11_immediate_context_SetPrivateData,
2884 d3d11_immediate_context_SetPrivateDataInterface,
2885 /* ID3D11DeviceContext methods */
2886 d3d11_immediate_context_VSSetConstantBuffers,
2887 d3d11_immediate_context_PSSetShaderResources,
2888 d3d11_immediate_context_PSSetShader,
2889 d3d11_immediate_context_PSSetSamplers,
2890 d3d11_immediate_context_VSSetShader,
2891 d3d11_immediate_context_DrawIndexed,
2892 d3d11_immediate_context_Draw,
2893 d3d11_immediate_context_Map,
2894 d3d11_immediate_context_Unmap,
2895 d3d11_immediate_context_PSSetConstantBuffers,
2896 d3d11_immediate_context_IASetInputLayout,
2897 d3d11_immediate_context_IASetVertexBuffers,
2898 d3d11_immediate_context_IASetIndexBuffer,
2899 d3d11_immediate_context_DrawIndexedInstanced,
2900 d3d11_immediate_context_DrawInstanced,
2901 d3d11_immediate_context_GSSetConstantBuffers,
2902 d3d11_immediate_context_GSSetShader,
2903 d3d11_immediate_context_IASetPrimitiveTopology,
2904 d3d11_immediate_context_VSSetShaderResources,
2905 d3d11_immediate_context_VSSetSamplers,
2906 d3d11_immediate_context_Begin,
2907 d3d11_immediate_context_End,
2908 d3d11_immediate_context_GetData,
2909 d3d11_immediate_context_SetPredication,
2910 d3d11_immediate_context_GSSetShaderResources,
2911 d3d11_immediate_context_GSSetSamplers,
2912 d3d11_immediate_context_OMSetRenderTargets,
2913 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2914 d3d11_immediate_context_OMSetBlendState,
2915 d3d11_immediate_context_OMSetDepthStencilState,
2916 d3d11_immediate_context_SOSetTargets,
2917 d3d11_immediate_context_DrawAuto,
2918 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2919 d3d11_immediate_context_DrawInstancedIndirect,
2920 d3d11_immediate_context_Dispatch,
2921 d3d11_immediate_context_DispatchIndirect,
2922 d3d11_immediate_context_RSSetState,
2923 d3d11_immediate_context_RSSetViewports,
2924 d3d11_immediate_context_RSSetScissorRects,
2925 d3d11_immediate_context_CopySubresourceRegion,
2926 d3d11_immediate_context_CopyResource,
2927 d3d11_immediate_context_UpdateSubresource,
2928 d3d11_immediate_context_CopyStructureCount,
2929 d3d11_immediate_context_ClearRenderTargetView,
2930 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2931 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2932 d3d11_immediate_context_ClearDepthStencilView,
2933 d3d11_immediate_context_GenerateMips,
2934 d3d11_immediate_context_SetResourceMinLOD,
2935 d3d11_immediate_context_GetResourceMinLOD,
2936 d3d11_immediate_context_ResolveSubresource,
2937 d3d11_immediate_context_ExecuteCommandList,
2938 d3d11_immediate_context_HSSetShaderResources,
2939 d3d11_immediate_context_HSSetShader,
2940 d3d11_immediate_context_HSSetSamplers,
2941 d3d11_immediate_context_HSSetConstantBuffers,
2942 d3d11_immediate_context_DSSetShaderResources,
2943 d3d11_immediate_context_DSSetShader,
2944 d3d11_immediate_context_DSSetSamplers,
2945 d3d11_immediate_context_DSSetConstantBuffers,
2946 d3d11_immediate_context_CSSetShaderResources,
2947 d3d11_immediate_context_CSSetUnorderedAccessViews,
2948 d3d11_immediate_context_CSSetShader,
2949 d3d11_immediate_context_CSSetSamplers,
2950 d3d11_immediate_context_CSSetConstantBuffers,
2951 d3d11_immediate_context_VSGetConstantBuffers,
2952 d3d11_immediate_context_PSGetShaderResources,
2953 d3d11_immediate_context_PSGetShader,
2954 d3d11_immediate_context_PSGetSamplers,
2955 d3d11_immediate_context_VSGetShader,
2956 d3d11_immediate_context_PSGetConstantBuffers,
2957 d3d11_immediate_context_IAGetInputLayout,
2958 d3d11_immediate_context_IAGetVertexBuffers,
2959 d3d11_immediate_context_IAGetIndexBuffer,
2960 d3d11_immediate_context_GSGetConstantBuffers,
2961 d3d11_immediate_context_GSGetShader,
2962 d3d11_immediate_context_IAGetPrimitiveTopology,
2963 d3d11_immediate_context_VSGetShaderResources,
2964 d3d11_immediate_context_VSGetSamplers,
2965 d3d11_immediate_context_GetPredication,
2966 d3d11_immediate_context_GSGetShaderResources,
2967 d3d11_immediate_context_GSGetSamplers,
2968 d3d11_immediate_context_OMGetRenderTargets,
2969 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2970 d3d11_immediate_context_OMGetBlendState,
2971 d3d11_immediate_context_OMGetDepthStencilState,
2972 d3d11_immediate_context_SOGetTargets,
2973 d3d11_immediate_context_RSGetState,
2974 d3d11_immediate_context_RSGetViewports,
2975 d3d11_immediate_context_RSGetScissorRects,
2976 d3d11_immediate_context_HSGetShaderResources,
2977 d3d11_immediate_context_HSGetShader,
2978 d3d11_immediate_context_HSGetSamplers,
2979 d3d11_immediate_context_HSGetConstantBuffers,
2980 d3d11_immediate_context_DSGetShaderResources,
2981 d3d11_immediate_context_DSGetShader,
2982 d3d11_immediate_context_DSGetSamplers,
2983 d3d11_immediate_context_DSGetConstantBuffers,
2984 d3d11_immediate_context_CSGetShaderResources,
2985 d3d11_immediate_context_CSGetUnorderedAccessViews,
2986 d3d11_immediate_context_CSGetShader,
2987 d3d11_immediate_context_CSGetSamplers,
2988 d3d11_immediate_context_CSGetConstantBuffers,
2989 d3d11_immediate_context_ClearState,
2990 d3d11_immediate_context_Flush,
2991 d3d11_immediate_context_GetType,
2992 d3d11_immediate_context_GetContextFlags,
2993 d3d11_immediate_context_FinishCommandList,
2994 /* ID3D11DeviceContext1 methods */
2995 d3d11_immediate_context_CopySubresourceRegion1,
2996 d3d11_immediate_context_UpdateSubresource1,
2997 d3d11_immediate_context_DiscardResource,
2998 d3d11_immediate_context_DiscardView,
2999 d3d11_immediate_context_VSSetConstantBuffers1,
3000 d3d11_immediate_context_HSSetConstantBuffers1,
3001 d3d11_immediate_context_DSSetConstantBuffers1,
3002 d3d11_immediate_context_GSSetConstantBuffers1,
3003 d3d11_immediate_context_PSSetConstantBuffers1,
3004 d3d11_immediate_context_CSSetConstantBuffers1,
3005 d3d11_immediate_context_VSGetConstantBuffers1,
3006 d3d11_immediate_context_HSGetConstantBuffers1,
3007 d3d11_immediate_context_DSGetConstantBuffers1,
3008 d3d11_immediate_context_GSGetConstantBuffers1,
3009 d3d11_immediate_context_PSGetConstantBuffers1,
3010 d3d11_immediate_context_CSGetConstantBuffers1,
3011 d3d11_immediate_context_SwapDeviceContextState,
3012 d3d11_immediate_context_ClearView,
3013 d3d11_immediate_context_DiscardView1,
3016 /* ID3D11Multithread methods */
3018 static inline struct d3d11_immediate_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3020 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11Multithread_iface);
3023 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3024 REFIID iid, void **out)
3026 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3028 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3030 return d3d11_immediate_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3033 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3035 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3037 TRACE("iface %p.\n", iface);
3039 return d3d11_immediate_context_AddRef(&context->ID3D11DeviceContext1_iface);
3042 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3044 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3046 TRACE("iface %p.\n", iface);
3048 return d3d11_immediate_context_Release(&context->ID3D11DeviceContext1_iface);
3051 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3053 TRACE("iface %p.\n", iface);
3055 wined3d_mutex_lock();
3058 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3060 TRACE("iface %p.\n", iface);
3062 wined3d_mutex_unlock();
3065 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3066 ID3D11Multithread *iface, BOOL enable)
3068 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3070 return TRUE;
3073 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3075 FIXME("iface %p stub!\n", iface);
3077 return TRUE;
3080 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3082 d3d11_multithread_QueryInterface,
3083 d3d11_multithread_AddRef,
3084 d3d11_multithread_Release,
3085 d3d11_multithread_Enter,
3086 d3d11_multithread_Leave,
3087 d3d11_multithread_SetMultithreadProtected,
3088 d3d11_multithread_GetMultithreadProtected,
3091 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
3093 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_immediate_context_vtbl;
3094 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3095 context->refcount = 1;
3097 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3099 wined3d_private_store_init(&context->private_store);
3102 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
3104 wined3d_private_store_cleanup(&context->private_store);
3107 /* ID3D11Device methods */
3109 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3111 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3112 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3115 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3117 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3118 return IUnknown_AddRef(device->outer_unk);
3121 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3123 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3124 return IUnknown_Release(device->outer_unk);
3127 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3128 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3130 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3131 struct d3d_buffer *object;
3132 HRESULT hr;
3134 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3136 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3137 return hr;
3139 *buffer = &object->ID3D11Buffer_iface;
3141 return S_OK;
3144 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3145 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3147 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3148 struct d3d_texture1d *object;
3149 HRESULT hr;
3151 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3153 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3154 return hr;
3156 *texture = &object->ID3D11Texture1D_iface;
3158 return S_OK;
3161 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3162 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3164 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3165 struct d3d_texture2d *object;
3166 HRESULT hr;
3168 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3170 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3171 return hr;
3173 *texture = &object->ID3D11Texture2D_iface;
3175 return S_OK;
3178 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3179 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3181 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3182 struct d3d_texture3d *object;
3183 HRESULT hr;
3185 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3187 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3188 return hr;
3190 *texture = &object->ID3D11Texture3D_iface;
3192 return S_OK;
3195 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3196 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3198 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3199 struct d3d_shader_resource_view *object;
3200 HRESULT hr;
3202 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3204 if (!resource)
3205 return E_INVALIDARG;
3207 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3208 return hr;
3210 *view = &object->ID3D11ShaderResourceView_iface;
3212 return S_OK;
3215 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3216 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3218 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3219 struct d3d11_unordered_access_view *object;
3220 HRESULT hr;
3222 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3224 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3225 return hr;
3227 *view = &object->ID3D11UnorderedAccessView_iface;
3229 return S_OK;
3232 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3233 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3235 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3236 struct d3d_rendertarget_view *object;
3237 HRESULT hr;
3239 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3241 if (!resource)
3242 return E_INVALIDARG;
3244 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3245 return hr;
3247 *view = &object->ID3D11RenderTargetView_iface;
3249 return S_OK;
3252 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3253 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3255 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3256 struct d3d_depthstencil_view *object;
3257 HRESULT hr;
3259 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3261 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3262 return hr;
3264 *view = &object->ID3D11DepthStencilView_iface;
3266 return S_OK;
3269 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3270 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3271 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3273 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3274 struct d3d_input_layout *object;
3275 HRESULT hr;
3277 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3278 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3279 shader_byte_code_length, input_layout);
3281 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3282 shader_byte_code, shader_byte_code_length, &object)))
3283 return hr;
3285 *input_layout = &object->ID3D11InputLayout_iface;
3287 return S_OK;
3290 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3291 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3293 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3294 struct d3d_vertex_shader *object;
3295 HRESULT hr;
3297 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3298 iface, byte_code, byte_code_length, class_linkage, shader);
3300 if (class_linkage)
3301 FIXME("Class linkage is not implemented yet.\n");
3303 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3304 return hr;
3306 *shader = &object->ID3D11VertexShader_iface;
3308 return S_OK;
3311 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3312 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3314 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3315 struct d3d_geometry_shader *object;
3316 HRESULT hr;
3318 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3319 iface, byte_code, byte_code_length, class_linkage, shader);
3321 if (class_linkage)
3322 FIXME("Class linkage is not implemented yet.\n");
3324 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3325 NULL, 0, NULL, 0, 0, &object)))
3326 return hr;
3328 *shader = &object->ID3D11GeometryShader_iface;
3330 return S_OK;
3333 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3334 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3335 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3336 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3338 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3339 struct d3d_geometry_shader *object;
3340 HRESULT hr;
3342 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3343 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3344 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3345 rasterizer_stream, class_linkage, shader);
3347 if (class_linkage)
3348 FIXME("Class linkage is not implemented yet.\n");
3350 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3351 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3353 *shader = NULL;
3354 return hr;
3357 *shader = &object->ID3D11GeometryShader_iface;
3359 return hr;
3362 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3363 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3365 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3366 struct d3d_pixel_shader *object;
3367 HRESULT hr;
3369 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3370 iface, byte_code, byte_code_length, class_linkage, shader);
3372 if (class_linkage)
3373 FIXME("Class linkage is not implemented yet.\n");
3375 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3376 return hr;
3378 *shader = &object->ID3D11PixelShader_iface;
3380 return S_OK;
3383 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3384 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3386 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3387 struct d3d11_hull_shader *object;
3388 HRESULT hr;
3390 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3391 iface, byte_code, byte_code_length, class_linkage, shader);
3393 if (class_linkage)
3394 FIXME("Class linkage is not implemented yet.\n");
3396 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3397 return hr;
3399 *shader = &object->ID3D11HullShader_iface;
3401 return S_OK;
3404 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3405 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3407 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3408 struct d3d11_domain_shader *object;
3409 HRESULT hr;
3411 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3412 iface, byte_code, byte_code_length, class_linkage, shader);
3414 if (class_linkage)
3415 FIXME("Class linkage is not implemented yet.\n");
3417 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3418 return hr;
3420 *shader = &object->ID3D11DomainShader_iface;
3422 return S_OK;
3425 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3426 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3428 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3429 struct d3d11_compute_shader *object;
3430 HRESULT hr;
3432 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3433 iface, byte_code, byte_code_length, class_linkage, shader);
3435 if (class_linkage)
3436 FIXME("Class linkage is not implemented yet.\n");
3438 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3439 return hr;
3441 *shader = &object->ID3D11ComputeShader_iface;
3443 return S_OK;
3446 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3447 ID3D11ClassLinkage **class_linkage)
3449 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3450 struct d3d11_class_linkage *object;
3451 HRESULT hr;
3453 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3455 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3456 return hr;
3458 *class_linkage = &object->ID3D11ClassLinkage_iface;
3460 return S_OK;
3463 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3464 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3466 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3467 struct d3d_blend_state *object;
3468 HRESULT hr;
3470 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3472 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3473 return hr;
3475 *blend_state = &object->ID3D11BlendState_iface;
3477 return S_OK;
3480 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3481 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3483 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3484 struct d3d_depthstencil_state *object;
3485 HRESULT hr;
3487 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3489 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3490 return hr;
3492 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3494 return S_OK;
3497 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3498 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3500 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3501 struct d3d_rasterizer_state *object;
3502 HRESULT hr;
3504 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3506 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3507 return hr;
3509 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3511 return S_OK;
3514 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3515 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3517 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3518 struct d3d_sampler_state *object;
3519 HRESULT hr;
3521 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3523 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3524 return hr;
3526 *sampler_state = &object->ID3D11SamplerState_iface;
3528 return S_OK;
3531 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3532 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3534 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3535 struct d3d_query *object;
3536 HRESULT hr;
3538 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3540 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3541 return hr;
3543 if (query)
3545 *query = &object->ID3D11Query_iface;
3546 return S_OK;
3549 ID3D11Query_Release(&object->ID3D11Query_iface);
3550 return S_FALSE;
3553 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3554 ID3D11Predicate **predicate)
3556 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3557 struct d3d_query *object;
3558 HRESULT hr;
3560 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3562 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3563 return hr;
3565 if (predicate)
3567 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3568 return S_OK;
3571 ID3D11Query_Release(&object->ID3D11Query_iface);
3572 return S_FALSE;
3575 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3576 ID3D11Counter **counter)
3578 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3580 return E_NOTIMPL;
3583 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3584 ID3D11DeviceContext **context)
3586 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3588 *context = NULL;
3589 return E_NOTIMPL;
3592 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3593 void **out)
3595 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3597 return E_NOTIMPL;
3600 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3601 UINT *format_support)
3603 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3604 struct wined3d_device_creation_parameters params;
3605 struct wined3d_adapter *wined3d_adapter;
3606 enum wined3d_format_id wined3d_format;
3607 D3D_FEATURE_LEVEL feature_level;
3608 struct wined3d *wined3d;
3609 unsigned int i;
3611 static const struct
3613 enum wined3d_resource_type rtype;
3614 unsigned int bind_flags;
3615 unsigned int usage;
3616 D3D11_FORMAT_SUPPORT flag;
3618 flag_mapping[] =
3620 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3621 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3622 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3623 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3624 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3625 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3626 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3627 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3628 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3629 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3631 HRESULT hr;
3633 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3635 wined3d_format = wined3dformat_from_dxgi_format(format);
3636 if (format && !wined3d_format)
3638 WARN("Invalid format %#x.\n", format);
3639 *format_support = 0;
3640 return E_FAIL;
3643 *format_support = 0;
3645 wined3d_mutex_lock();
3646 feature_level = device->state->feature_level;
3647 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3648 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3649 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3650 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3652 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3653 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3654 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3655 continue;
3656 if (hr != WINED3D_OK)
3658 WARN("Failed to check device format support, hr %#x.\n", hr);
3659 wined3d_mutex_unlock();
3660 return E_FAIL;
3663 *format_support |= flag_mapping[i].flag;
3665 wined3d_mutex_unlock();
3667 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3668 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3670 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3671 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3673 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3674 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3675 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3677 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3678 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3680 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3682 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3683 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3685 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3686 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3690 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3691 * support multisample. */
3692 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3693 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3694 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3695 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3697 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3698 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3699 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3702 return S_OK;
3705 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3706 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3708 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3709 struct wined3d_device_creation_parameters params;
3710 struct wined3d_adapter *wined3d_adapter;
3711 struct wined3d *wined3d;
3712 HRESULT hr;
3714 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3715 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3717 if (!quality_level_count)
3718 return E_INVALIDARG;
3720 *quality_level_count = 0;
3722 if (!sample_count)
3723 return E_FAIL;
3724 if (sample_count == 1)
3726 *quality_level_count = 1;
3727 return S_OK;
3729 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3730 return E_FAIL;
3732 wined3d_mutex_lock();
3733 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3734 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3735 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3736 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3737 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3738 wined3d_mutex_unlock();
3740 if (hr == WINED3DERR_INVALIDCALL)
3741 return E_INVALIDARG;
3742 if (hr == WINED3DERR_NOTAVAILABLE)
3743 return S_OK;
3744 return hr;
3747 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3749 FIXME("iface %p, info %p stub!\n", iface, info);
3752 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3753 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3754 char *units, UINT *units_length, char *description, UINT *description_length)
3756 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3757 "units %p, units_length %p, description %p, description_length %p stub!\n",
3758 iface, desc, type, active_counter_count, name, name_length,
3759 units, units_length, description, description_length);
3761 return E_NOTIMPL;
3764 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3765 void *feature_support_data, UINT feature_support_data_size)
3767 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3768 struct wined3d_caps wined3d_caps;
3769 HRESULT hr;
3771 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3772 iface, feature, feature_support_data, feature_support_data_size);
3774 switch (feature)
3776 case D3D11_FEATURE_THREADING:
3778 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3779 if (feature_support_data_size != sizeof(*threading_data))
3781 WARN("Invalid data size.\n");
3782 return E_INVALIDARG;
3785 /* We lie about the threading support to make Tomb Raider 2013 and
3786 * Deus Ex: Human Revolution happy. */
3787 FIXME("Returning fake threading support data.\n");
3788 threading_data->DriverConcurrentCreates = TRUE;
3789 threading_data->DriverCommandLists = TRUE;
3790 return S_OK;
3793 case D3D11_FEATURE_DOUBLES:
3795 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3796 if (feature_support_data_size != sizeof(*doubles_data))
3798 WARN("Invalid data size.\n");
3799 return E_INVALIDARG;
3802 wined3d_mutex_lock();
3803 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3804 wined3d_mutex_unlock();
3805 if (FAILED(hr))
3807 WARN("Failed to get device caps, hr %#x.\n", hr);
3808 return hr;
3811 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3812 return S_OK;
3815 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3817 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3818 if (feature_support_data_size != sizeof(*options))
3820 WARN("Invalid data size.\n");
3821 return E_INVALIDARG;
3824 wined3d_mutex_lock();
3825 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3826 wined3d_mutex_unlock();
3827 if (FAILED(hr))
3829 WARN("Failed to get device caps, hr %#x.\n", hr);
3830 return hr;
3833 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
3834 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
3835 return S_OK;
3838 case D3D11_FEATURE_D3D11_OPTIONS:
3840 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
3841 if (feature_support_data_size != sizeof(*options))
3843 WARN("Invalid data size.\n");
3844 return E_INVALIDARG;
3847 FIXME("Returning fake Options support data.\n");
3848 options->OutputMergerLogicOp = FALSE;
3849 options->UAVOnlyRenderingForcedSampleCount = FALSE;
3850 options->DiscardAPIsSeenByDriver = FALSE;
3851 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
3852 options->ClearView = FALSE;
3853 options->CopyWithOverlap = FALSE;
3854 options->ConstantBufferPartialUpdate = FALSE;
3855 options->ConstantBufferOffsetting = FALSE;
3856 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
3857 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
3858 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
3859 options->SAD4ShaderInstructions = FALSE;
3860 options->ExtendedDoublesShaderInstructions = FALSE;
3861 options->ExtendedResourceSharing = FALSE;
3862 return S_OK;
3865 case D3D11_FEATURE_D3D11_OPTIONS1:
3867 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
3868 if (feature_support_data_size != sizeof(*options))
3870 WARN("Invalid data size.\n");
3871 return E_INVALIDARG;
3874 FIXME("Returning fake Options1 support data.\n");
3875 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
3876 options->MinMaxFiltering = FALSE;
3877 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
3878 options->MapOnDefaultBuffers = FALSE;
3879 return S_OK;
3882 case D3D11_FEATURE_D3D11_OPTIONS3:
3884 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
3885 if (feature_support_data_size != sizeof(*options))
3887 WARN("Invalid data size.\n");
3888 return E_INVALIDARG;
3891 wined3d_mutex_lock();
3892 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3893 wined3d_mutex_unlock();
3894 if (FAILED(hr))
3896 WARN("Failed to get device caps, hr %#x.\n", hr);
3897 return hr;
3900 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
3901 = wined3d_caps.viewport_array_index_any_shader;
3902 return S_OK;
3905 case D3D11_FEATURE_ARCHITECTURE_INFO:
3907 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
3908 if (feature_support_data_size != sizeof(*options))
3910 WARN("Invalid data size.\n");
3911 return E_INVALIDARG;
3914 FIXME("Returning fake data architecture info.\n");
3915 options->TileBasedDeferredRenderer = FALSE;
3916 return S_OK;
3919 default:
3920 FIXME("Unhandled feature %#x.\n", feature);
3921 return E_NOTIMPL;
3925 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3926 UINT *data_size, void *data)
3928 IDXGIDevice *dxgi_device;
3929 HRESULT hr;
3931 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3933 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3934 return hr;
3935 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3936 IDXGIDevice_Release(dxgi_device);
3938 return hr;
3941 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3942 UINT data_size, const void *data)
3944 IDXGIDevice *dxgi_device;
3945 HRESULT hr;
3947 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3949 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3950 return hr;
3951 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3952 IDXGIDevice_Release(dxgi_device);
3954 return hr;
3957 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
3958 const IUnknown *data)
3960 IDXGIDevice *dxgi_device;
3961 HRESULT hr;
3963 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3965 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3966 return hr;
3967 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3968 IDXGIDevice_Release(dxgi_device);
3970 return hr;
3973 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
3975 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3977 TRACE("iface %p.\n", iface);
3979 return device->state->feature_level;
3982 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
3984 FIXME("iface %p stub!\n", iface);
3986 return 0;
3989 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
3991 WARN("iface %p stub!\n", iface);
3993 return S_OK;
3996 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
3997 ID3D11DeviceContext **immediate_context)
3999 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4001 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4003 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4004 ID3D11DeviceContext_AddRef(*immediate_context);
4007 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4009 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4011 return E_NOTIMPL;
4014 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4016 FIXME("iface %p stub!\n", iface);
4018 return 0;
4021 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4022 ID3D11DeviceContext1 **immediate_context)
4024 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4026 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4028 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4029 ID3D11DeviceContext1_AddRef(*immediate_context);
4032 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4033 ID3D11DeviceContext1 **context)
4035 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4037 return E_NOTIMPL;
4040 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4041 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4043 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4045 return E_NOTIMPL;
4048 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4049 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4051 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4053 return E_NOTIMPL;
4056 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4057 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4058 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4060 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4061 struct d3d_device_context_state *state_impl;
4062 struct wined3d_state *wined3d_state;
4063 D3D_FEATURE_LEVEL feature_level;
4064 HRESULT hr = E_INVALIDARG;
4066 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4067 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4068 iface, flags, feature_levels, feature_level_count,
4069 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4071 if (flags)
4072 FIXME("Ignoring flags %#x.\n", flags);
4074 wined3d_mutex_lock();
4076 if (!feature_level_count)
4077 goto fail;
4079 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4080 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4081 goto fail;
4082 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4084 if (chosen_feature_level)
4085 *chosen_feature_level = feature_level;
4087 if (!state)
4089 wined3d_state_destroy(wined3d_state);
4090 wined3d_mutex_unlock();
4091 return S_FALSE;
4094 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4096 wined3d_state_destroy(wined3d_state);
4097 hr = E_OUTOFMEMORY;
4098 goto fail;
4101 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4102 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4104 wined3d_state_destroy(wined3d_state);
4105 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4106 hr = E_FAIL;
4107 goto fail;
4110 *state = &state_impl->ID3DDeviceContextState_iface;
4111 device->d3d11_only = FALSE;
4112 wined3d_mutex_unlock();
4114 return S_OK;
4116 fail:
4117 wined3d_mutex_unlock();
4118 if (chosen_feature_level)
4119 *chosen_feature_level = 0;
4120 if (state)
4121 *state = NULL;
4122 return hr;
4125 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4126 REFIID iid, void **resource)
4128 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4130 return E_NOTIMPL;
4133 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4134 DWORD access, REFIID iid, void **resource)
4136 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4137 debugstr_guid(iid), resource);
4139 return E_NOTIMPL;
4142 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4143 ID3D11DeviceContext2 **context)
4145 FIXME("iface %p, context %p stub!\n", iface, context);
4148 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4149 UINT flags, ID3D11DeviceContext2 **context)
4151 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4153 return E_NOTIMPL;
4156 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4157 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4158 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4159 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4161 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4162 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4163 iface, resource, tile_count, mip_desc, tile_shape,
4164 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4167 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4168 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4170 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4171 iface, format, sample_count, flags, quality_level_count);
4173 return E_NOTIMPL;
4176 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4178 /* IUnknown methods */
4179 d3d11_device_QueryInterface,
4180 d3d11_device_AddRef,
4181 d3d11_device_Release,
4182 /* ID3D11Device methods */
4183 d3d11_device_CreateBuffer,
4184 d3d11_device_CreateTexture1D,
4185 d3d11_device_CreateTexture2D,
4186 d3d11_device_CreateTexture3D,
4187 d3d11_device_CreateShaderResourceView,
4188 d3d11_device_CreateUnorderedAccessView,
4189 d3d11_device_CreateRenderTargetView,
4190 d3d11_device_CreateDepthStencilView,
4191 d3d11_device_CreateInputLayout,
4192 d3d11_device_CreateVertexShader,
4193 d3d11_device_CreateGeometryShader,
4194 d3d11_device_CreateGeometryShaderWithStreamOutput,
4195 d3d11_device_CreatePixelShader,
4196 d3d11_device_CreateHullShader,
4197 d3d11_device_CreateDomainShader,
4198 d3d11_device_CreateComputeShader,
4199 d3d11_device_CreateClassLinkage,
4200 d3d11_device_CreateBlendState,
4201 d3d11_device_CreateDepthStencilState,
4202 d3d11_device_CreateRasterizerState,
4203 d3d11_device_CreateSamplerState,
4204 d3d11_device_CreateQuery,
4205 d3d11_device_CreatePredicate,
4206 d3d11_device_CreateCounter,
4207 d3d11_device_CreateDeferredContext,
4208 d3d11_device_OpenSharedResource,
4209 d3d11_device_CheckFormatSupport,
4210 d3d11_device_CheckMultisampleQualityLevels,
4211 d3d11_device_CheckCounterInfo,
4212 d3d11_device_CheckCounter,
4213 d3d11_device_CheckFeatureSupport,
4214 d3d11_device_GetPrivateData,
4215 d3d11_device_SetPrivateData,
4216 d3d11_device_SetPrivateDataInterface,
4217 d3d11_device_GetFeatureLevel,
4218 d3d11_device_GetCreationFlags,
4219 d3d11_device_GetDeviceRemovedReason,
4220 d3d11_device_GetImmediateContext,
4221 d3d11_device_SetExceptionMode,
4222 d3d11_device_GetExceptionMode,
4223 /* ID3D11Device1 methods */
4224 d3d11_device_GetImmediateContext1,
4225 d3d11_device_CreateDeferredContext1,
4226 d3d11_device_CreateBlendState1,
4227 d3d11_device_CreateRasterizerState1,
4228 d3d11_device_CreateDeviceContextState,
4229 d3d11_device_OpenSharedResource1,
4230 d3d11_device_OpenSharedResourceByName,
4231 /* ID3D11Device2 methods */
4232 d3d11_device_GetImmediateContext2,
4233 d3d11_device_CreateDeferredContext2,
4234 d3d11_device_GetResourceTiling,
4235 d3d11_device_CheckMultisampleQualityLevels1,
4238 /* Inner IUnknown methods */
4240 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4242 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4245 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4247 struct d3d_device *device = impl_from_IUnknown(iface);
4249 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4251 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4252 || IsEqualGUID(riid, &IID_ID3D11Device1)
4253 || IsEqualGUID(riid, &IID_ID3D11Device)
4254 || IsEqualGUID(riid, &IID_IUnknown))
4256 *out = &device->ID3D11Device2_iface;
4258 else if (!device->d3d11_only
4259 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4260 || IsEqualGUID(riid, &IID_ID3D10Device)))
4262 *out = &device->ID3D10Device1_iface;
4264 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4266 *out = &device->ID3D10Multithread_iface;
4268 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4270 *out = &device->IWineDXGIDeviceParent_iface;
4272 else
4274 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4275 *out = NULL;
4276 return E_NOINTERFACE;
4279 IUnknown_AddRef((IUnknown *)*out);
4280 return S_OK;
4283 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4285 struct d3d_device *device = impl_from_IUnknown(iface);
4286 ULONG refcount = InterlockedIncrement(&device->refcount);
4288 TRACE("%p increasing refcount to %u.\n", device, refcount);
4290 return refcount;
4293 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4295 struct d3d_device *device = impl_from_IUnknown(iface);
4296 ULONG refcount = InterlockedDecrement(&device->refcount);
4297 unsigned int i;
4299 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4301 if (!refcount)
4303 if (device->state)
4304 d3d_device_context_state_private_release(device->state);
4305 for (i = 0; i < device->context_state_count; ++i)
4307 d3d_device_context_state_remove_entry(device->context_states[i], device);
4309 heap_free(device->context_states);
4310 d3d11_immediate_context_destroy(&device->immediate_context);
4311 if (device->wined3d_device)
4313 wined3d_mutex_lock();
4314 wined3d_device_decref(device->wined3d_device);
4315 wined3d_mutex_unlock();
4317 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4318 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4319 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4320 wine_rb_destroy(&device->blend_states, NULL, NULL);
4323 return refcount;
4326 /* IUnknown methods */
4328 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4329 void **out)
4331 struct d3d_device *device = impl_from_ID3D10Device(iface);
4332 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4335 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4337 struct d3d_device *device = impl_from_ID3D10Device(iface);
4338 return IUnknown_AddRef(device->outer_unk);
4341 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4343 struct d3d_device *device = impl_from_ID3D10Device(iface);
4344 return IUnknown_Release(device->outer_unk);
4347 /* ID3D10Device methods */
4349 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4350 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4352 struct d3d_device *device = impl_from_ID3D10Device(iface);
4353 unsigned int i;
4355 wined3d_mutex_lock();
4356 for (i = 0; i < buffer_count; ++i)
4358 struct wined3d_buffer *wined3d_buffer;
4359 struct d3d_buffer *buffer_impl;
4361 if (!(wined3d_buffer = wined3d_device_get_constant_buffer(device->wined3d_device,
4362 type, start_slot + i)))
4364 buffers[i] = NULL;
4365 continue;
4368 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4369 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4370 ID3D10Buffer_AddRef(buffers[i]);
4372 wined3d_mutex_unlock();
4375 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4376 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4378 struct d3d_device *device = impl_from_ID3D10Device(iface);
4379 unsigned int i;
4381 wined3d_mutex_lock();
4382 for (i = 0; i < buffer_count; ++i)
4384 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4386 wined3d_device_context_set_constant_buffer(device->immediate_context.wined3d_context, type, start_slot + i,
4387 buffer ? buffer->wined3d_buffer : NULL);
4389 wined3d_mutex_unlock();
4392 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4393 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4395 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4396 iface, start_slot, buffer_count, buffers);
4398 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4399 buffer_count, buffers);
4402 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4403 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4405 struct d3d_device *device = impl_from_ID3D10Device(iface);
4406 unsigned int i;
4408 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4409 iface, start_slot, view_count, views);
4411 wined3d_mutex_lock();
4412 for (i = 0; i < view_count; ++i)
4414 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4416 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4417 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, view ? view->wined3d_view : NULL);
4419 wined3d_mutex_unlock();
4422 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4423 ID3D10PixelShader *shader)
4425 struct d3d_device *device = impl_from_ID3D10Device(iface);
4426 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4428 TRACE("iface %p, shader %p\n", iface, shader);
4430 wined3d_mutex_lock();
4431 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4432 WINED3D_SHADER_TYPE_PIXEL, ps ? ps->wined3d_shader : NULL);
4433 wined3d_mutex_unlock();
4436 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4437 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4439 struct d3d_device *device = impl_from_ID3D10Device(iface);
4440 unsigned int i;
4442 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4443 iface, start_slot, sampler_count, samplers);
4445 wined3d_mutex_lock();
4446 for (i = 0; i < sampler_count; ++i)
4448 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4450 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4451 WINED3D_SHADER_TYPE_PIXEL, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4453 wined3d_mutex_unlock();
4456 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4457 ID3D10VertexShader *shader)
4459 struct d3d_device *device = impl_from_ID3D10Device(iface);
4460 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4462 TRACE("iface %p, shader %p\n", iface, shader);
4464 wined3d_mutex_lock();
4465 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4466 WINED3D_SHADER_TYPE_VERTEX, vs ? vs->wined3d_shader : NULL);
4467 wined3d_mutex_unlock();
4470 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
4471 UINT start_index_location, INT base_vertex_location)
4473 struct d3d_device *device = impl_from_ID3D10Device(iface);
4475 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
4476 iface, index_count, start_index_location, base_vertex_location);
4478 wined3d_mutex_lock();
4479 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context,
4480 base_vertex_location, start_index_location, index_count, 0, 0);
4481 wined3d_mutex_unlock();
4484 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
4485 UINT start_vertex_location)
4487 struct d3d_device *device = impl_from_ID3D10Device(iface);
4489 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
4490 iface, vertex_count, start_vertex_location);
4492 wined3d_mutex_lock();
4493 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location, vertex_count, 0, 0);
4494 wined3d_mutex_unlock();
4497 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
4498 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4500 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4501 iface, start_slot, buffer_count, buffers);
4503 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
4504 buffer_count, buffers);
4507 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
4508 ID3D10InputLayout *input_layout)
4510 struct d3d_device *device = impl_from_ID3D10Device(iface);
4511 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
4513 TRACE("iface %p, input_layout %p\n", iface, input_layout);
4515 wined3d_mutex_lock();
4516 wined3d_device_context_set_vertex_declaration(device->immediate_context.wined3d_context,
4517 layout ? layout->wined3d_decl : NULL);
4518 wined3d_mutex_unlock();
4521 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
4522 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
4524 struct d3d_device *device = impl_from_ID3D10Device(iface);
4525 unsigned int i;
4527 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
4528 iface, start_slot, buffer_count, buffers, strides, offsets);
4530 wined3d_mutex_lock();
4531 for (i = 0; i < buffer_count; ++i)
4533 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4535 wined3d_device_context_set_stream_source(device->immediate_context.wined3d_context, start_slot + i,
4536 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
4538 wined3d_mutex_unlock();
4541 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
4542 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
4544 struct d3d_device *device = impl_from_ID3D10Device(iface);
4545 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
4547 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
4548 iface, buffer, debug_dxgi_format(format), offset);
4550 wined3d_mutex_lock();
4551 wined3d_device_context_set_index_buffer(device->immediate_context.wined3d_context,
4552 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
4553 wined3dformat_from_dxgi_format(format), offset);
4554 wined3d_mutex_unlock();
4557 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
4558 UINT instance_index_count, UINT instance_count, UINT start_index_location,
4559 INT base_vertex_location, UINT start_instance_location)
4561 struct d3d_device *device = impl_from_ID3D10Device(iface);
4563 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
4564 "base_vertex_location %d, start_instance_location %u.\n",
4565 iface, instance_index_count, instance_count, start_index_location,
4566 base_vertex_location, start_instance_location);
4568 wined3d_mutex_lock();
4569 wined3d_device_context_draw_indexed(device->immediate_context.wined3d_context, base_vertex_location,
4570 start_index_location, instance_index_count, start_instance_location, instance_count);
4571 wined3d_mutex_unlock();
4574 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4575 UINT instance_vertex_count, UINT instance_count,
4576 UINT start_vertex_location, UINT start_instance_location)
4578 struct d3d_device *device = impl_from_ID3D10Device(iface);
4580 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4581 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4582 start_vertex_location, start_instance_location);
4584 wined3d_mutex_lock();
4585 wined3d_device_context_draw(device->immediate_context.wined3d_context, start_vertex_location,
4586 instance_vertex_count, start_instance_location, instance_count);
4587 wined3d_mutex_unlock();
4590 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4591 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4593 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4594 iface, start_slot, buffer_count, buffers);
4596 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4597 buffer_count, buffers);
4600 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4602 struct d3d_device *device = impl_from_ID3D10Device(iface);
4603 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4605 TRACE("iface %p, shader %p.\n", iface, shader);
4607 wined3d_mutex_lock();
4608 wined3d_device_context_set_shader(device->immediate_context.wined3d_context,
4609 WINED3D_SHADER_TYPE_GEOMETRY, gs ? gs->wined3d_shader : NULL);
4610 wined3d_mutex_unlock();
4613 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
4614 D3D10_PRIMITIVE_TOPOLOGY topology)
4616 struct d3d_device *device = impl_from_ID3D10Device(iface);
4618 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4620 wined3d_mutex_lock();
4621 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology, 0);
4622 wined3d_mutex_unlock();
4625 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4626 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4628 struct d3d_device *device = impl_from_ID3D10Device(iface);
4629 unsigned int i;
4631 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4632 iface, start_slot, view_count, views);
4634 wined3d_mutex_lock();
4635 for (i = 0; i < view_count; ++i)
4637 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4639 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4640 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, view ? view->wined3d_view : NULL);
4642 wined3d_mutex_unlock();
4645 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4646 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4648 struct d3d_device *device = impl_from_ID3D10Device(iface);
4649 unsigned int i;
4651 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4652 iface, start_slot, sampler_count, samplers);
4654 wined3d_mutex_lock();
4655 for (i = 0; i < sampler_count; ++i)
4657 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4659 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context,
4660 WINED3D_SHADER_TYPE_VERTEX, start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4662 wined3d_mutex_unlock();
4665 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4667 struct d3d_device *device = impl_from_ID3D10Device(iface);
4668 struct d3d_query *query;
4670 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4672 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4673 wined3d_mutex_lock();
4674 wined3d_device_context_set_predication(device->immediate_context.wined3d_context,
4675 query ? query->wined3d_query : NULL, value);
4676 wined3d_mutex_unlock();
4679 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4680 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4682 struct d3d_device *device = impl_from_ID3D10Device(iface);
4683 unsigned int i;
4685 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4686 iface, start_slot, view_count, views);
4688 wined3d_mutex_lock();
4689 for (i = 0; i < view_count; ++i)
4691 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4693 wined3d_device_context_set_shader_resource_view(device->immediate_context.wined3d_context,
4694 WINED3D_SHADER_TYPE_GEOMETRY, start_slot + i, view ? view->wined3d_view : NULL);
4696 wined3d_mutex_unlock();
4699 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4700 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4702 struct d3d_device *device = impl_from_ID3D10Device(iface);
4703 unsigned int i;
4705 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4706 iface, start_slot, sampler_count, samplers);
4708 wined3d_mutex_lock();
4709 for (i = 0; i < sampler_count; ++i)
4711 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4713 wined3d_device_context_set_sampler(device->immediate_context.wined3d_context, WINED3D_SHADER_TYPE_GEOMETRY,
4714 start_slot + i, sampler ? sampler->wined3d_sampler : NULL);
4716 wined3d_mutex_unlock();
4719 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4720 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4721 ID3D10DepthStencilView *depth_stencil_view)
4723 struct d3d_device *device = impl_from_ID3D10Device(iface);
4724 struct d3d_depthstencil_view *dsv;
4725 unsigned int i;
4727 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4728 iface, render_target_view_count, render_target_views, depth_stencil_view);
4730 wined3d_mutex_lock();
4731 for (i = 0; i < render_target_view_count; ++i)
4733 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4735 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
4736 rtv ? rtv->wined3d_view : NULL, FALSE);
4738 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4740 wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
4743 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4744 wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
4745 dsv ? dsv->wined3d_view : NULL);
4746 wined3d_mutex_unlock();
4749 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4750 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4752 struct d3d_device *device = impl_from_ID3D10Device(iface);
4753 struct d3d_blend_state *blend_state_object;
4755 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4756 iface, blend_state, debug_float4(blend_factor), sample_mask);
4758 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4759 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4760 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4763 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4764 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4766 struct d3d_device *device = impl_from_ID3D10Device(iface);
4767 struct d3d_depthstencil_state *ds_state_object;
4769 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4770 iface, depth_stencil_state, stencil_ref);
4772 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4773 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4774 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4777 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4778 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4780 struct d3d_device *device = impl_from_ID3D10Device(iface);
4781 unsigned int count, i;
4783 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4785 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4786 wined3d_mutex_lock();
4787 for (i = 0; i < count; ++i)
4789 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4791 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i,
4792 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4795 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4797 wined3d_device_context_set_stream_output(device->immediate_context.wined3d_context, i, NULL, 0);
4799 wined3d_mutex_unlock();
4802 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4804 FIXME("iface %p stub!\n", iface);
4807 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4809 struct d3d_device *device = impl_from_ID3D10Device(iface);
4810 struct d3d_rasterizer_state *rasterizer_state_object;
4812 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4814 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4815 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
4816 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4819 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4820 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4822 struct d3d_device *device = impl_from_ID3D10Device(iface);
4823 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
4824 unsigned int i;
4826 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4828 if (viewport_count > ARRAY_SIZE(wined3d_vp))
4829 return;
4831 for (i = 0; i < viewport_count; ++i)
4833 wined3d_vp[i].x = viewports[i].TopLeftX;
4834 wined3d_vp[i].y = viewports[i].TopLeftY;
4835 wined3d_vp[i].width = viewports[i].Width;
4836 wined3d_vp[i].height = viewports[i].Height;
4837 wined3d_vp[i].min_z = viewports[i].MinDepth;
4838 wined3d_vp[i].max_z = viewports[i].MaxDepth;
4841 wined3d_mutex_lock();
4842 wined3d_device_context_set_viewports(device->immediate_context.wined3d_context, viewport_count, wined3d_vp);
4843 wined3d_mutex_unlock();
4846 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4847 UINT rect_count, const D3D10_RECT *rects)
4849 struct d3d_device *device = impl_from_ID3D10Device(iface);
4851 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4853 if (rect_count > WINED3D_MAX_VIEWPORTS)
4854 return;
4856 wined3d_mutex_lock();
4857 wined3d_device_context_set_scissor_rects(device->immediate_context.wined3d_context, rect_count, rects);
4858 wined3d_mutex_unlock();
4861 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4862 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4863 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4865 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4866 struct d3d_device *device = impl_from_ID3D10Device(iface);
4867 struct wined3d_box wined3d_src_box;
4869 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4870 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4871 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4872 src_resource, src_subresource_idx, src_box);
4874 if (!dst_resource || !src_resource)
4875 return;
4877 if (src_box)
4878 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4879 src_box->right, src_box->bottom, src_box->front, src_box->back);
4881 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4882 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4883 wined3d_mutex_lock();
4884 wined3d_device_context_copy_sub_resource_region(device->immediate_context.wined3d_context,
4885 wined3d_dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4886 wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
4887 wined3d_mutex_unlock();
4890 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4891 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4893 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4894 struct d3d_device *device = impl_from_ID3D10Device(iface);
4896 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4898 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4899 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4900 wined3d_mutex_lock();
4901 wined3d_device_context_copy_resource(device->immediate_context.wined3d_context,
4902 wined3d_dst_resource, wined3d_src_resource);
4903 wined3d_mutex_unlock();
4906 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4907 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4908 const void *data, UINT row_pitch, UINT depth_pitch)
4910 struct d3d_device *device = impl_from_ID3D10Device(iface);
4911 ID3D11Resource *d3d11_resource;
4913 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4914 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4916 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4917 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
4918 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4919 ID3D11Resource_Release(d3d11_resource);
4922 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4923 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4925 struct d3d_device *device = impl_from_ID3D10Device(iface);
4926 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4927 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4928 HRESULT hr;
4930 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4931 iface, render_target_view, debug_float4(color_rgba));
4933 if (!view)
4934 return;
4936 wined3d_mutex_lock();
4937 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
4938 view->wined3d_view, NULL, WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4939 ERR("Failed to clear view, hr %#x.\n", hr);
4940 wined3d_mutex_unlock();
4943 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4944 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4946 struct d3d_device *device = impl_from_ID3D10Device(iface);
4947 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4948 DWORD wined3d_flags;
4949 HRESULT hr;
4951 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4952 iface, depth_stencil_view, flags, depth, stencil);
4954 if (!view)
4955 return;
4957 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4959 wined3d_mutex_lock();
4960 if (FAILED(hr = wined3d_device_context_clear_rendertarget_view(device->immediate_context.wined3d_context,
4961 view->wined3d_view, NULL, wined3d_flags, NULL, depth, stencil)))
4962 ERR("Failed to clear view, hr %#x.\n", hr);
4963 wined3d_mutex_unlock();
4966 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4967 ID3D10ShaderResourceView *view)
4969 struct d3d_device *device = impl_from_ID3D10Device(iface);
4970 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
4972 TRACE("iface %p, view %p.\n", iface, view);
4974 wined3d_mutex_lock();
4975 wined3d_device_context_generate_mipmaps(device->immediate_context.wined3d_context, srv->wined3d_view);
4976 wined3d_mutex_unlock();
4979 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4980 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4981 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4983 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4984 struct d3d_device *device = impl_from_ID3D10Device(iface);
4985 enum wined3d_format_id wined3d_format;
4987 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
4988 "src_resource %p, src_subresource_idx %u, format %s.\n",
4989 iface, dst_resource, dst_subresource_idx,
4990 src_resource, src_subresource_idx, debug_dxgi_format(format));
4992 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4993 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4994 wined3d_format = wined3dformat_from_dxgi_format(format);
4995 wined3d_mutex_lock();
4996 wined3d_device_context_resolve_sub_resource(device->immediate_context.wined3d_context,
4997 wined3d_dst_resource, dst_subresource_idx,
4998 wined3d_src_resource, src_subresource_idx, wined3d_format);
4999 wined3d_mutex_unlock();
5002 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
5003 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5005 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5006 iface, start_slot, buffer_count, buffers);
5008 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5009 buffers);
5012 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5013 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5015 struct d3d_device *device = impl_from_ID3D10Device(iface);
5016 unsigned int i;
5018 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5019 iface, start_slot, view_count, views);
5021 wined3d_mutex_lock();
5022 for (i = 0; i < view_count; ++i)
5024 struct wined3d_shader_resource_view *wined3d_view;
5025 struct d3d_shader_resource_view *view_impl;
5027 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
5029 views[i] = NULL;
5030 continue;
5033 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5034 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5035 ID3D10ShaderResourceView_AddRef(views[i]);
5037 wined3d_mutex_unlock();
5040 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5042 struct d3d_device *device = impl_from_ID3D10Device(iface);
5043 struct d3d_pixel_shader *shader_impl;
5044 struct wined3d_shader *wined3d_shader;
5046 TRACE("iface %p, shader %p.\n", iface, shader);
5048 wined3d_mutex_lock();
5049 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
5051 wined3d_mutex_unlock();
5052 *shader = NULL;
5053 return;
5056 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5057 wined3d_mutex_unlock();
5058 *shader = &shader_impl->ID3D10PixelShader_iface;
5059 ID3D10PixelShader_AddRef(*shader);
5062 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5063 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5065 struct d3d_device *device = impl_from_ID3D10Device(iface);
5066 unsigned int i;
5068 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5069 iface, start_slot, sampler_count, samplers);
5071 wined3d_mutex_lock();
5072 for (i = 0; i < sampler_count; ++i)
5074 struct d3d_sampler_state *sampler_impl;
5075 struct wined3d_sampler *wined3d_sampler;
5077 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
5079 samplers[i] = NULL;
5080 continue;
5083 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5084 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5085 ID3D10SamplerState_AddRef(samplers[i]);
5087 wined3d_mutex_unlock();
5090 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5092 struct d3d_device *device = impl_from_ID3D10Device(iface);
5093 struct d3d_vertex_shader *shader_impl;
5094 struct wined3d_shader *wined3d_shader;
5096 TRACE("iface %p, shader %p.\n", iface, shader);
5098 wined3d_mutex_lock();
5099 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
5101 wined3d_mutex_unlock();
5102 *shader = NULL;
5103 return;
5106 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5107 wined3d_mutex_unlock();
5108 *shader = &shader_impl->ID3D10VertexShader_iface;
5109 ID3D10VertexShader_AddRef(*shader);
5112 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5113 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5115 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5116 iface, start_slot, buffer_count, buffers);
5118 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5119 buffers);
5122 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5124 struct d3d_device *device = impl_from_ID3D10Device(iface);
5125 struct wined3d_vertex_declaration *wined3d_declaration;
5126 struct d3d_input_layout *input_layout_impl;
5128 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5130 wined3d_mutex_lock();
5131 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
5133 wined3d_mutex_unlock();
5134 *input_layout = NULL;
5135 return;
5138 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5139 wined3d_mutex_unlock();
5140 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5141 ID3D10InputLayout_AddRef(*input_layout);
5144 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5145 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5147 struct d3d_device *device = impl_from_ID3D10Device(iface);
5148 unsigned int i;
5150 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5151 iface, start_slot, buffer_count, buffers, strides, offsets);
5153 wined3d_mutex_lock();
5154 for (i = 0; i < buffer_count; ++i)
5156 struct wined3d_buffer *wined3d_buffer = NULL;
5157 struct d3d_buffer *buffer_impl;
5159 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
5160 &wined3d_buffer, &offsets[i], &strides[i])))
5161 ERR("Failed to get vertex buffer.\n");
5163 if (!wined3d_buffer)
5165 buffers[i] = NULL;
5166 continue;
5169 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5170 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5171 ID3D10Buffer_AddRef(buffers[i]);
5173 wined3d_mutex_unlock();
5176 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5177 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5179 struct d3d_device *device = impl_from_ID3D10Device(iface);
5180 enum wined3d_format_id wined3d_format;
5181 struct wined3d_buffer *wined3d_buffer;
5182 struct d3d_buffer *buffer_impl;
5184 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5186 wined3d_mutex_lock();
5187 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
5188 *format = dxgi_format_from_wined3dformat(wined3d_format);
5189 if (!wined3d_buffer)
5191 wined3d_mutex_unlock();
5192 *buffer = NULL;
5193 return;
5196 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5197 wined3d_mutex_unlock();
5198 *buffer = &buffer_impl->ID3D10Buffer_iface;
5199 ID3D10Buffer_AddRef(*buffer);
5202 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5203 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5205 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5206 iface, start_slot, buffer_count, buffers);
5208 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5209 buffers);
5212 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5214 struct d3d_device *device = impl_from_ID3D10Device(iface);
5215 struct d3d_geometry_shader *shader_impl;
5216 struct wined3d_shader *wined3d_shader;
5218 TRACE("iface %p, shader %p.\n", iface, shader);
5220 wined3d_mutex_lock();
5221 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
5223 wined3d_mutex_unlock();
5224 *shader = NULL;
5225 return;
5228 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5229 wined3d_mutex_unlock();
5230 *shader = &shader_impl->ID3D10GeometryShader_iface;
5231 ID3D10GeometryShader_AddRef(*shader);
5234 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5235 D3D10_PRIMITIVE_TOPOLOGY *topology)
5237 struct d3d_device *device = impl_from_ID3D10Device(iface);
5239 TRACE("iface %p, topology %p.\n", iface, topology);
5241 wined3d_mutex_lock();
5242 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology, NULL);
5243 wined3d_mutex_unlock();
5246 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5247 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5249 struct d3d_device *device = impl_from_ID3D10Device(iface);
5250 unsigned int i;
5252 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5253 iface, start_slot, view_count, views);
5255 wined3d_mutex_lock();
5256 for (i = 0; i < view_count; ++i)
5258 struct wined3d_shader_resource_view *wined3d_view;
5259 struct d3d_shader_resource_view *view_impl;
5261 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
5263 views[i] = NULL;
5264 continue;
5267 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5268 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5269 ID3D10ShaderResourceView_AddRef(views[i]);
5271 wined3d_mutex_unlock();
5274 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5275 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5277 struct d3d_device *device = impl_from_ID3D10Device(iface);
5278 unsigned int i;
5280 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5281 iface, start_slot, sampler_count, samplers);
5283 wined3d_mutex_lock();
5284 for (i = 0; i < sampler_count; ++i)
5286 struct d3d_sampler_state *sampler_impl;
5287 struct wined3d_sampler *wined3d_sampler;
5289 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
5291 samplers[i] = NULL;
5292 continue;
5295 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5296 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5297 ID3D10SamplerState_AddRef(samplers[i]);
5299 wined3d_mutex_unlock();
5302 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5303 ID3D10Predicate **predicate, BOOL *value)
5305 struct d3d_device *device = impl_from_ID3D10Device(iface);
5306 struct wined3d_query *wined3d_predicate;
5307 struct d3d_query *predicate_impl;
5309 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5311 wined3d_mutex_lock();
5312 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
5314 wined3d_mutex_unlock();
5315 *predicate = NULL;
5316 return;
5319 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5320 wined3d_mutex_unlock();
5321 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5322 ID3D10Predicate_AddRef(*predicate);
5325 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5326 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5328 struct d3d_device *device = impl_from_ID3D10Device(iface);
5329 unsigned int i;
5331 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5332 iface, start_slot, view_count, views);
5334 wined3d_mutex_lock();
5335 for (i = 0; i < view_count; ++i)
5337 struct wined3d_shader_resource_view *wined3d_view;
5338 struct d3d_shader_resource_view *view_impl;
5340 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
5342 views[i] = NULL;
5343 continue;
5346 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5347 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5348 ID3D10ShaderResourceView_AddRef(views[i]);
5350 wined3d_mutex_unlock();
5353 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5354 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5356 struct d3d_device *device = impl_from_ID3D10Device(iface);
5357 unsigned int i;
5359 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5360 iface, start_slot, sampler_count, samplers);
5362 wined3d_mutex_lock();
5363 for (i = 0; i < sampler_count; ++i)
5365 struct d3d_sampler_state *sampler_impl;
5366 struct wined3d_sampler *wined3d_sampler;
5368 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
5370 samplers[i] = NULL;
5371 continue;
5374 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5375 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5376 ID3D10SamplerState_AddRef(samplers[i]);
5378 wined3d_mutex_unlock();
5381 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5382 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5384 struct d3d_device *device = impl_from_ID3D10Device(iface);
5385 struct wined3d_rendertarget_view *wined3d_view;
5387 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5388 iface, view_count, render_target_views, depth_stencil_view);
5390 wined3d_mutex_lock();
5391 if (render_target_views)
5393 struct d3d_rendertarget_view *view_impl;
5394 unsigned int i;
5396 for (i = 0; i < view_count; ++i)
5398 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
5399 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5401 render_target_views[i] = NULL;
5402 continue;
5405 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5406 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5410 if (depth_stencil_view)
5412 struct d3d_depthstencil_view *view_impl;
5414 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
5415 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5417 *depth_stencil_view = NULL;
5419 else
5421 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5422 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5425 wined3d_mutex_unlock();
5428 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5429 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5431 struct d3d_device *device = impl_from_ID3D10Device(iface);
5432 ID3D11BlendState *d3d11_blend_state;
5434 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5435 iface, blend_state, blend_factor, sample_mask);
5437 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5438 &d3d11_blend_state, blend_factor, sample_mask);
5440 if (d3d11_blend_state)
5441 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5442 else
5443 *blend_state = NULL;
5446 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5447 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5449 struct d3d_device *device = impl_from_ID3D10Device(iface);
5450 ID3D11DepthStencilState *d3d11_iface;
5452 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5453 iface, depth_stencil_state, stencil_ref);
5455 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5456 &d3d11_iface, stencil_ref);
5458 if (d3d11_iface)
5459 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5460 else
5461 *depth_stencil_state = NULL;
5464 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5465 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5467 struct d3d_device *device = impl_from_ID3D10Device(iface);
5468 unsigned int i;
5470 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5471 iface, buffer_count, buffers, offsets);
5473 wined3d_mutex_lock();
5474 for (i = 0; i < buffer_count; ++i)
5476 struct wined3d_buffer *wined3d_buffer;
5477 struct d3d_buffer *buffer_impl;
5479 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
5481 buffers[i] = NULL;
5482 continue;
5485 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5486 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5487 ID3D10Buffer_AddRef(buffers[i]);
5489 wined3d_mutex_unlock();
5492 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5494 struct d3d_device *device = impl_from_ID3D10Device(iface);
5495 struct d3d_rasterizer_state *rasterizer_state_impl;
5496 struct wined3d_rasterizer_state *wined3d_state;
5498 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5500 wined3d_mutex_lock();
5501 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
5503 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5504 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5506 else
5508 *rasterizer_state = NULL;
5510 wined3d_mutex_unlock();
5513 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5514 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5516 struct d3d_device *device = impl_from_ID3D10Device(iface);
5517 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5518 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5520 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5522 if (!viewport_count)
5523 return;
5525 wined3d_mutex_lock();
5526 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
5527 wined3d_mutex_unlock();
5529 if (!viewports)
5531 *viewport_count = actual_count;
5532 return;
5535 if (*viewport_count > actual_count)
5536 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5538 *viewport_count = min(actual_count, *viewport_count);
5539 for (i = 0; i < *viewport_count; ++i)
5541 viewports[i].TopLeftX = wined3d_vp[i].x;
5542 viewports[i].TopLeftY = wined3d_vp[i].y;
5543 viewports[i].Width = wined3d_vp[i].width;
5544 viewports[i].Height = wined3d_vp[i].height;
5545 viewports[i].MinDepth = wined3d_vp[i].min_z;
5546 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5550 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5552 struct d3d_device *device = impl_from_ID3D10Device(iface);
5553 unsigned int actual_count;
5555 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5557 if (!rect_count)
5558 return;
5560 actual_count = *rect_count;
5562 wined3d_mutex_lock();
5563 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
5564 wined3d_mutex_unlock();
5566 if (!rects)
5568 *rect_count = actual_count;
5569 return;
5572 if (*rect_count > actual_count)
5573 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5576 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5578 TRACE("iface %p.\n", iface);
5580 /* In the current implementation the device is never removed, so we can
5581 * just return S_OK here. */
5583 return S_OK;
5586 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5588 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5590 return E_NOTIMPL;
5593 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5595 FIXME("iface %p stub!\n", iface);
5597 return 0;
5600 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5601 REFGUID guid, UINT *data_size, void *data)
5603 struct d3d_device *device = impl_from_ID3D10Device(iface);
5605 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5607 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5610 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5611 REFGUID guid, UINT data_size, const void *data)
5613 struct d3d_device *device = impl_from_ID3D10Device(iface);
5615 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5617 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5620 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5621 REFGUID guid, const IUnknown *data)
5623 struct d3d_device *device = impl_from_ID3D10Device(iface);
5625 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5627 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5630 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5632 struct d3d_device *device = impl_from_ID3D10Device(iface);
5634 TRACE("iface %p.\n", iface);
5636 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5639 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5641 struct d3d_device *device = impl_from_ID3D10Device(iface);
5643 TRACE("iface %p.\n", iface);
5645 wined3d_mutex_lock();
5646 wined3d_device_flush(device->wined3d_device);
5647 wined3d_mutex_unlock();
5650 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5651 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5653 struct d3d_device *device = impl_from_ID3D10Device(iface);
5654 D3D11_BUFFER_DESC d3d11_desc;
5655 struct d3d_buffer *object;
5656 HRESULT hr;
5658 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5660 d3d11_desc.ByteWidth = desc->ByteWidth;
5661 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5662 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5663 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5664 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5665 d3d11_desc.StructureByteStride = 0;
5667 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5668 return hr;
5670 *buffer = &object->ID3D10Buffer_iface;
5672 return S_OK;
5675 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5676 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5678 struct d3d_device *device = impl_from_ID3D10Device(iface);
5679 D3D11_TEXTURE1D_DESC d3d11_desc;
5680 struct d3d_texture1d *object;
5681 HRESULT hr;
5683 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5685 d3d11_desc.Width = desc->Width;
5686 d3d11_desc.MipLevels = desc->MipLevels;
5687 d3d11_desc.ArraySize = desc->ArraySize;
5688 d3d11_desc.Format = desc->Format;
5689 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5690 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5691 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5692 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5694 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5695 return hr;
5697 *texture = &object->ID3D10Texture1D_iface;
5699 return S_OK;
5702 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5703 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5704 ID3D10Texture2D **texture)
5706 struct d3d_device *device = impl_from_ID3D10Device(iface);
5707 D3D11_TEXTURE2D_DESC d3d11_desc;
5708 struct d3d_texture2d *object;
5709 HRESULT hr;
5711 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5713 d3d11_desc.Width = desc->Width;
5714 d3d11_desc.Height = desc->Height;
5715 d3d11_desc.MipLevels = desc->MipLevels;
5716 d3d11_desc.ArraySize = desc->ArraySize;
5717 d3d11_desc.Format = desc->Format;
5718 d3d11_desc.SampleDesc = desc->SampleDesc;
5719 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5720 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5721 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5722 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5724 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5725 return hr;
5727 *texture = &object->ID3D10Texture2D_iface;
5729 return S_OK;
5732 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5733 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5734 ID3D10Texture3D **texture)
5736 struct d3d_device *device = impl_from_ID3D10Device(iface);
5737 D3D11_TEXTURE3D_DESC d3d11_desc;
5738 struct d3d_texture3d *object;
5739 HRESULT hr;
5741 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5743 d3d11_desc.Width = desc->Width;
5744 d3d11_desc.Height = desc->Height;
5745 d3d11_desc.Depth = desc->Depth;
5746 d3d11_desc.MipLevels = desc->MipLevels;
5747 d3d11_desc.Format = desc->Format;
5748 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5749 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5750 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5751 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5753 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5754 return hr;
5756 *texture = &object->ID3D10Texture3D_iface;
5758 return S_OK;
5761 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5762 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5764 struct d3d_device *device = impl_from_ID3D10Device(iface);
5765 struct d3d_shader_resource_view *object;
5766 ID3D11Resource *d3d11_resource;
5767 HRESULT hr;
5769 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5771 if (!resource)
5772 return E_INVALIDARG;
5774 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5776 ERR("Resource does not implement ID3D11Resource.\n");
5777 return E_FAIL;
5780 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5781 &object);
5782 ID3D11Resource_Release(d3d11_resource);
5783 if (FAILED(hr))
5784 return hr;
5786 *view = &object->ID3D10ShaderResourceView1_iface;
5788 return S_OK;
5791 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5792 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5794 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5796 return d3d10_device_CreateShaderResourceView1(iface, resource,
5797 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5800 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5801 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5803 struct d3d_device *device = impl_from_ID3D10Device(iface);
5804 struct d3d_rendertarget_view *object;
5805 ID3D11Resource *d3d11_resource;
5806 HRESULT hr;
5808 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5810 if (!resource)
5811 return E_INVALIDARG;
5813 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5815 ERR("Resource does not implement ID3D11Resource.\n");
5816 return E_FAIL;
5819 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5820 ID3D11Resource_Release(d3d11_resource);
5821 if (FAILED(hr))
5822 return hr;
5824 *view = &object->ID3D10RenderTargetView_iface;
5826 return S_OK;
5829 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
5831 return (D3D11_DSV_DIMENSION)dim;
5834 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5835 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5837 struct d3d_device *device = impl_from_ID3D10Device(iface);
5838 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5839 struct d3d_depthstencil_view *object;
5840 ID3D11Resource *d3d11_resource;
5841 HRESULT hr;
5843 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5845 if (desc)
5847 d3d11_desc.Format = desc->Format;
5848 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
5849 d3d11_desc.Flags = 0;
5850 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5853 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5855 ERR("Resource does not implement ID3D11Resource.\n");
5856 return E_FAIL;
5859 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5860 ID3D11Resource_Release(d3d11_resource);
5861 if (FAILED(hr))
5862 return hr;
5864 *view = &object->ID3D10DepthStencilView_iface;
5866 return S_OK;
5869 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5870 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5871 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5872 ID3D10InputLayout **input_layout)
5874 struct d3d_device *device = impl_from_ID3D10Device(iface);
5875 struct d3d_input_layout *object;
5876 HRESULT hr;
5878 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5879 "shader_byte_code_length %lu, input_layout %p\n",
5880 iface, element_descs, element_count, shader_byte_code,
5881 shader_byte_code_length, input_layout);
5883 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5884 shader_byte_code, shader_byte_code_length, &object)))
5885 return hr;
5887 *input_layout = &object->ID3D10InputLayout_iface;
5889 return S_OK;
5892 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5893 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5895 struct d3d_device *device = impl_from_ID3D10Device(iface);
5896 struct d3d_vertex_shader *object;
5897 HRESULT hr;
5899 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5900 iface, byte_code, byte_code_length, shader);
5902 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5903 return hr;
5905 *shader = &object->ID3D10VertexShader_iface;
5907 return S_OK;
5910 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5911 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5913 struct d3d_device *device = impl_from_ID3D10Device(iface);
5914 struct d3d_geometry_shader *object;
5915 HRESULT hr;
5917 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5918 iface, byte_code, byte_code_length, shader);
5920 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5921 NULL, 0, NULL, 0, 0, &object)))
5922 return hr;
5924 *shader = &object->ID3D10GeometryShader_iface;
5926 return S_OK;
5929 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5930 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5931 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5933 struct d3d_device *device = impl_from_ID3D10Device(iface);
5934 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5935 struct d3d_geometry_shader *object;
5936 unsigned int i, stride_count = 1;
5937 HRESULT hr;
5939 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5940 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5941 iface, byte_code, byte_code_length, output_stream_decls,
5942 output_stream_decl_count, output_stream_stride, shader);
5944 if (!output_stream_decl_count && output_stream_stride)
5946 WARN("Stride must be 0 when declaration entry count is 0.\n");
5947 *shader = NULL;
5948 return E_INVALIDARG;
5951 if (output_stream_decl_count
5952 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
5954 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5955 *shader = NULL;
5956 return E_OUTOFMEMORY;
5959 for (i = 0; i < output_stream_decl_count; ++i)
5961 so_entries[i].Stream = 0;
5962 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5963 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5964 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5965 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5966 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5968 if (output_stream_decls[i].OutputSlot)
5970 stride_count = 0;
5971 if (output_stream_stride)
5973 WARN("Stride must be 0 when multiple output slots are used.\n");
5974 heap_free(so_entries);
5975 *shader = NULL;
5976 return E_INVALIDARG;
5981 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5982 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5983 heap_free(so_entries);
5984 if (FAILED(hr))
5986 *shader = NULL;
5987 return hr;
5990 *shader = &object->ID3D10GeometryShader_iface;
5992 return hr;
5995 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5996 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5998 struct d3d_device *device = impl_from_ID3D10Device(iface);
5999 struct d3d_pixel_shader *object;
6000 HRESULT hr;
6002 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
6003 iface, byte_code, byte_code_length, shader);
6005 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6006 return hr;
6008 *shader = &object->ID3D10PixelShader_iface;
6010 return S_OK;
6013 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6014 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6016 struct d3d_device *device = impl_from_ID3D10Device(iface);
6017 struct d3d_blend_state *object;
6018 HRESULT hr;
6020 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6022 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6023 return hr;
6025 *blend_state = &object->ID3D10BlendState1_iface;
6027 return S_OK;
6030 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6031 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6033 D3D10_BLEND_DESC1 d3d10_1_desc;
6034 unsigned int i;
6036 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6038 if (!desc)
6039 return E_INVALIDARG;
6041 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6042 d3d10_1_desc.IndependentBlendEnable = FALSE;
6043 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6045 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6046 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6047 d3d10_1_desc.IndependentBlendEnable = TRUE;
6050 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6052 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6053 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6054 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6055 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6056 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6057 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6058 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6059 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6062 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6065 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6066 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6068 struct d3d_device *device = impl_from_ID3D10Device(iface);
6069 struct d3d_depthstencil_state *object;
6070 HRESULT hr;
6072 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6074 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6075 return hr;
6077 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6079 return S_OK;
6082 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6083 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6085 struct d3d_device *device = impl_from_ID3D10Device(iface);
6086 struct d3d_rasterizer_state *object;
6087 HRESULT hr;
6089 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6091 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6092 return hr;
6094 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6096 return S_OK;
6099 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6100 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6102 struct d3d_device *device = impl_from_ID3D10Device(iface);
6103 struct d3d_sampler_state *object;
6104 HRESULT hr;
6106 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6108 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6109 return hr;
6111 *sampler_state = &object->ID3D10SamplerState_iface;
6113 return S_OK;
6116 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6117 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6119 struct d3d_device *device = impl_from_ID3D10Device(iface);
6120 struct d3d_query *object;
6121 HRESULT hr;
6123 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6125 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6126 return hr;
6128 if (query)
6130 *query = &object->ID3D10Query_iface;
6131 return S_OK;
6134 ID3D10Query_Release(&object->ID3D10Query_iface);
6135 return S_FALSE;
6138 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6139 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6141 struct d3d_device *device = impl_from_ID3D10Device(iface);
6142 struct d3d_query *object;
6143 HRESULT hr;
6145 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6147 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6148 return hr;
6150 if (predicate)
6152 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6153 return S_OK;
6156 ID3D10Query_Release(&object->ID3D10Query_iface);
6157 return S_FALSE;
6160 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6161 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6163 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6165 return E_NOTIMPL;
6168 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6169 DXGI_FORMAT format, UINT *format_support)
6171 struct d3d_device *device = impl_from_ID3D10Device(iface);
6173 TRACE("iface %p, format %s, format_support %p.\n",
6174 iface, debug_dxgi_format(format), format_support);
6176 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6179 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6180 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6182 struct d3d_device *device = impl_from_ID3D10Device(iface);
6184 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6185 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6187 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6188 sample_count, quality_level_count);
6191 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6193 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6196 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6197 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6198 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6200 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6201 "units %p, units_length %p, description %p, description_length %p stub!\n",
6202 iface, desc, type, active_counters, name, name_length,
6203 units, units_length, description, description_length);
6205 return E_NOTIMPL;
6208 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6210 FIXME("iface %p stub!\n", iface);
6212 return 0;
6215 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6216 HANDLE resource_handle, REFIID guid, void **resource)
6218 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6219 iface, resource_handle, debugstr_guid(guid), resource);
6221 return E_NOTIMPL;
6224 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6226 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6229 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6231 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6234 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6236 return (D3D10_FEATURE_LEVEL1)level;
6239 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6241 struct d3d_device *device = impl_from_ID3D10Device(iface);
6243 TRACE("iface %p.\n", iface);
6245 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6248 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6250 /* IUnknown methods */
6251 d3d10_device_QueryInterface,
6252 d3d10_device_AddRef,
6253 d3d10_device_Release,
6254 /* ID3D10Device methods */
6255 d3d10_device_VSSetConstantBuffers,
6256 d3d10_device_PSSetShaderResources,
6257 d3d10_device_PSSetShader,
6258 d3d10_device_PSSetSamplers,
6259 d3d10_device_VSSetShader,
6260 d3d10_device_DrawIndexed,
6261 d3d10_device_Draw,
6262 d3d10_device_PSSetConstantBuffers,
6263 d3d10_device_IASetInputLayout,
6264 d3d10_device_IASetVertexBuffers,
6265 d3d10_device_IASetIndexBuffer,
6266 d3d10_device_DrawIndexedInstanced,
6267 d3d10_device_DrawInstanced,
6268 d3d10_device_GSSetConstantBuffers,
6269 d3d10_device_GSSetShader,
6270 d3d10_device_IASetPrimitiveTopology,
6271 d3d10_device_VSSetShaderResources,
6272 d3d10_device_VSSetSamplers,
6273 d3d10_device_SetPredication,
6274 d3d10_device_GSSetShaderResources,
6275 d3d10_device_GSSetSamplers,
6276 d3d10_device_OMSetRenderTargets,
6277 d3d10_device_OMSetBlendState,
6278 d3d10_device_OMSetDepthStencilState,
6279 d3d10_device_SOSetTargets,
6280 d3d10_device_DrawAuto,
6281 d3d10_device_RSSetState,
6282 d3d10_device_RSSetViewports,
6283 d3d10_device_RSSetScissorRects,
6284 d3d10_device_CopySubresourceRegion,
6285 d3d10_device_CopyResource,
6286 d3d10_device_UpdateSubresource,
6287 d3d10_device_ClearRenderTargetView,
6288 d3d10_device_ClearDepthStencilView,
6289 d3d10_device_GenerateMips,
6290 d3d10_device_ResolveSubresource,
6291 d3d10_device_VSGetConstantBuffers,
6292 d3d10_device_PSGetShaderResources,
6293 d3d10_device_PSGetShader,
6294 d3d10_device_PSGetSamplers,
6295 d3d10_device_VSGetShader,
6296 d3d10_device_PSGetConstantBuffers,
6297 d3d10_device_IAGetInputLayout,
6298 d3d10_device_IAGetVertexBuffers,
6299 d3d10_device_IAGetIndexBuffer,
6300 d3d10_device_GSGetConstantBuffers,
6301 d3d10_device_GSGetShader,
6302 d3d10_device_IAGetPrimitiveTopology,
6303 d3d10_device_VSGetShaderResources,
6304 d3d10_device_VSGetSamplers,
6305 d3d10_device_GetPredication,
6306 d3d10_device_GSGetShaderResources,
6307 d3d10_device_GSGetSamplers,
6308 d3d10_device_OMGetRenderTargets,
6309 d3d10_device_OMGetBlendState,
6310 d3d10_device_OMGetDepthStencilState,
6311 d3d10_device_SOGetTargets,
6312 d3d10_device_RSGetState,
6313 d3d10_device_RSGetViewports,
6314 d3d10_device_RSGetScissorRects,
6315 d3d10_device_GetDeviceRemovedReason,
6316 d3d10_device_SetExceptionMode,
6317 d3d10_device_GetExceptionMode,
6318 d3d10_device_GetPrivateData,
6319 d3d10_device_SetPrivateData,
6320 d3d10_device_SetPrivateDataInterface,
6321 d3d10_device_ClearState,
6322 d3d10_device_Flush,
6323 d3d10_device_CreateBuffer,
6324 d3d10_device_CreateTexture1D,
6325 d3d10_device_CreateTexture2D,
6326 d3d10_device_CreateTexture3D,
6327 d3d10_device_CreateShaderResourceView,
6328 d3d10_device_CreateRenderTargetView,
6329 d3d10_device_CreateDepthStencilView,
6330 d3d10_device_CreateInputLayout,
6331 d3d10_device_CreateVertexShader,
6332 d3d10_device_CreateGeometryShader,
6333 d3d10_device_CreateGeometryShaderWithStreamOutput,
6334 d3d10_device_CreatePixelShader,
6335 d3d10_device_CreateBlendState,
6336 d3d10_device_CreateDepthStencilState,
6337 d3d10_device_CreateRasterizerState,
6338 d3d10_device_CreateSamplerState,
6339 d3d10_device_CreateQuery,
6340 d3d10_device_CreatePredicate,
6341 d3d10_device_CreateCounter,
6342 d3d10_device_CheckFormatSupport,
6343 d3d10_device_CheckMultisampleQualityLevels,
6344 d3d10_device_CheckCounterInfo,
6345 d3d10_device_CheckCounter,
6346 d3d10_device_GetCreationFlags,
6347 d3d10_device_OpenSharedResource,
6348 d3d10_device_SetTextFilterSize,
6349 d3d10_device_GetTextFilterSize,
6350 d3d10_device_CreateShaderResourceView1,
6351 d3d10_device_CreateBlendState1,
6352 d3d10_device_GetFeatureLevel,
6355 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6357 /* IUnknown methods */
6358 d3d_device_inner_QueryInterface,
6359 d3d_device_inner_AddRef,
6360 d3d_device_inner_Release,
6363 /* ID3D10Multithread methods */
6365 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6367 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6370 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6372 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6374 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6376 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6379 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6381 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6383 TRACE("iface %p.\n", iface);
6385 return IUnknown_AddRef(device->outer_unk);
6388 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6390 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6392 TRACE("iface %p.\n", iface);
6394 return IUnknown_Release(device->outer_unk);
6397 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6399 TRACE("iface %p.\n", iface);
6401 wined3d_mutex_lock();
6404 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6406 TRACE("iface %p.\n", iface);
6408 wined3d_mutex_unlock();
6411 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6413 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6415 return TRUE;
6418 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6420 FIXME("iface %p stub!\n", iface);
6422 return TRUE;
6425 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6427 d3d10_multithread_QueryInterface,
6428 d3d10_multithread_AddRef,
6429 d3d10_multithread_Release,
6430 d3d10_multithread_Enter,
6431 d3d10_multithread_Leave,
6432 d3d10_multithread_SetMultithreadProtected,
6433 d3d10_multithread_GetMultithreadProtected,
6436 /* IWineDXGIDeviceParent IUnknown methods */
6438 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6440 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6443 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6444 REFIID iid, void **out)
6446 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6447 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6450 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6452 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6453 return IUnknown_AddRef(device->outer_unk);
6456 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6458 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6459 return IUnknown_Release(device->outer_unk);
6462 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6463 IWineDXGIDeviceParent *iface)
6465 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6466 return &device->device_parent;
6469 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6471 /* IUnknown methods */
6472 dxgi_device_parent_QueryInterface,
6473 dxgi_device_parent_AddRef,
6474 dxgi_device_parent_Release,
6475 /* IWineDXGIDeviceParent methods */
6476 dxgi_device_parent_get_wined3d_device_parent,
6479 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6481 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6484 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6485 struct wined3d_device *wined3d_device)
6487 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6488 struct d3d_device_context_state *state;
6489 struct wined3d_state *wined3d_state;
6490 D3D_FEATURE_LEVEL feature_level;
6492 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6494 wined3d_device_incref(wined3d_device);
6495 device->wined3d_device = wined3d_device;
6496 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6498 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6499 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6501 if (!(state = heap_alloc_zero(sizeof(*state))))
6503 ERR("Failed to create the initial device context state.\n");
6504 return;
6507 d3d_device_context_state_init(state, device, feature_level,
6508 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6510 device->state = state;
6511 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6512 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6514 d3d_device_context_state_private_addref(state);
6515 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6518 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6520 TRACE("device_parent %p.\n", device_parent);
6523 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6525 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6528 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6529 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6530 void **parent, const struct wined3d_parent_ops **parent_ops)
6532 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6533 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6535 *parent = NULL;
6536 *parent_ops = &d3d_null_wined3d_parent_ops;
6538 return S_OK;
6541 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6542 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6543 struct wined3d_texture **wined3d_texture)
6545 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6546 struct d3d_texture2d *texture;
6547 ID3D11Texture2D *texture_iface;
6548 D3D11_TEXTURE2D_DESC desc;
6549 HRESULT hr;
6551 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6552 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6554 desc.Width = wined3d_desc->width;
6555 desc.Height = wined3d_desc->height;
6556 desc.MipLevels = 1;
6557 desc.ArraySize = 1;
6558 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6559 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6560 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6561 desc.Usage = D3D11_USAGE_DEFAULT;
6562 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6563 desc.CPUAccessFlags = 0;
6564 desc.MiscFlags = 0;
6566 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6568 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6569 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6572 if (texture_flags)
6573 FIXME("Unhandled flags %#x.\n", texture_flags);
6575 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6576 &desc, NULL, &texture_iface)))
6578 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6579 return hr;
6582 texture = impl_from_ID3D11Texture2D(texture_iface);
6584 *wined3d_texture = texture->wined3d_texture;
6585 wined3d_texture_incref(*wined3d_texture);
6586 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6588 return S_OK;
6591 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6593 device_parent_wined3d_device_created,
6594 device_parent_mode_changed,
6595 device_parent_activate,
6596 device_parent_texture_sub_resource_created,
6597 device_parent_create_swapchain_texture,
6600 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6602 const D3D11_SAMPLER_DESC *ka = key;
6603 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6605 return memcmp(ka, kb, sizeof(*ka));
6608 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6610 const D3D11_BLEND_DESC *ka = key;
6611 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6613 return memcmp(ka, kb, sizeof(*ka));
6616 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6618 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6619 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6620 const struct d3d_depthstencil_state, entry)->desc;
6622 return memcmp(ka, kb, sizeof(*ka));
6625 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6627 const D3D11_RASTERIZER_DESC *ka = key;
6628 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6630 return memcmp(ka, kb, sizeof(*ka));
6633 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6635 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6636 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6637 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6638 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6639 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6640 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6641 device->refcount = 1;
6642 /* COM aggregation always takes place */
6643 device->outer_unk = outer_unknown;
6644 device->d3d11_only = FALSE;
6645 device->state = NULL;
6647 d3d11_immediate_context_init(&device->immediate_context, device);
6648 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6650 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6651 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6652 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6653 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);