d3d11: Use wined3d_device_context_set_index_buffer().
[wine.git] / dlls / d3d11 / device.c
blob9b2652b49ec1537db90e926f29ace1851dcdf5b5
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 #include "d3d11_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
25 static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
27 SIZE_T max_capacity, new_capacity;
28 void *new_elements;
30 if (count <= *capacity)
31 return TRUE;
33 max_capacity = ~(SIZE_T)0 / size;
34 if (count > max_capacity)
35 return FALSE;
37 new_capacity = max(1, *capacity);
38 while (new_capacity < count && new_capacity <= max_capacity / 2)
39 new_capacity *= 2;
40 if (new_capacity < count)
41 new_capacity = count;
43 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
44 return FALSE;
46 *elements = new_elements;
47 *capacity = new_capacity;
48 return TRUE;
51 static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
53 static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
55 d3d_null_wined3d_object_destroyed,
58 static inline BOOL d3d_device_is_d3d10_active(struct d3d_device *device)
60 return !device->state
61 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device)
62 || IsEqualGUID(&device->state->emulated_interface, &IID_ID3D10Device1);
65 static D3D_FEATURE_LEVEL d3d_feature_level_from_wined3d(enum wined3d_feature_level level)
67 return (D3D_FEATURE_LEVEL)level;
70 /* ID3DDeviceContextState methods */
72 static inline struct d3d_device_context_state *impl_from_ID3DDeviceContextState(ID3DDeviceContextState *iface)
74 return CONTAINING_RECORD(iface, struct d3d_device_context_state, ID3DDeviceContextState_iface);
77 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_QueryInterface(ID3DDeviceContextState *iface,
78 REFIID iid, void **out)
80 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
82 if (IsEqualGUID(iid, &IID_ID3DDeviceContextState)
83 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
84 || IsEqualGUID(iid, &IID_IUnknown))
86 ID3DDeviceContextState_AddRef(iface);
87 *out = iface;
88 return S_OK;
91 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
92 *out = NULL;
94 return E_NOINTERFACE;
97 static ULONG d3d_device_context_state_private_addref(struct d3d_device_context_state *state)
99 ULONG refcount = InterlockedIncrement(&state->private_refcount);
101 TRACE("%p increasing private refcount to %u.\n", state, refcount);
103 return refcount;
106 static ULONG STDMETHODCALLTYPE d3d_device_context_state_AddRef(ID3DDeviceContextState *iface)
108 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
109 ULONG refcount = InterlockedIncrement(&state->refcount);
111 TRACE("%p increasing refcount to %u.\n", state, refcount);
113 if (refcount == 1)
115 d3d_device_context_state_private_addref(state);
116 ID3D11Device2_AddRef(state->device);
119 return refcount;
122 static void d3d_device_remove_context_state(struct d3d_device *device, struct d3d_device_context_state *state)
124 unsigned int i;
126 for (i = 0; i < device->context_state_count; ++i)
128 if (device->context_states[i] != state)
129 continue;
131 if (i != device->context_state_count - 1)
132 device->context_states[i] = device->context_states[device->context_state_count - 1];
133 --device->context_state_count;
134 break;
138 static void d3d_device_context_state_private_release(struct d3d_device_context_state *state)
140 ULONG refcount = InterlockedDecrement(&state->private_refcount);
141 struct d3d_device_context_state_entry *entry;
142 struct d3d_device *device;
143 unsigned int i;
145 TRACE("%p decreasing private refcount to %u.\n", state, refcount);
147 if (!refcount)
149 wined3d_private_store_cleanup(&state->private_store);
150 for (i = 0; i < state->entry_count; ++i)
152 entry = &state->entries[i];
153 device = entry->device;
155 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
156 wined3d_state_destroy(entry->wined3d_state);
158 d3d_device_remove_context_state(device, state);
160 heap_free(state->entries);
161 wined3d_device_decref(state->wined3d_device);
162 heap_free(state);
166 static ULONG STDMETHODCALLTYPE d3d_device_context_state_Release(ID3DDeviceContextState *iface)
168 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
169 ULONG refcount = InterlockedDecrement(&state->refcount);
171 TRACE("%p decreasing refcount to %u.\n", state, refcount);
173 if (!refcount)
175 ID3D11Device2_Release(state->device);
176 d3d_device_context_state_private_release(state);
179 return refcount;
182 static void STDMETHODCALLTYPE d3d_device_context_state_GetDevice(ID3DDeviceContextState *iface, ID3D11Device **device)
184 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
186 TRACE("iface %p, device %p.\n", iface, device);
188 *device = (ID3D11Device *)state->device;
189 ID3D11Device_AddRef(*device);
192 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_GetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
193 UINT *data_size, void *data)
195 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
197 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
199 return d3d_get_private_data(&state->private_store, guid, data_size, data);
202 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateData(ID3DDeviceContextState *iface, REFGUID guid,
203 UINT data_size, const void *data)
205 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
207 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
209 return d3d_set_private_data(&state->private_store, guid, data_size, data);
212 static HRESULT STDMETHODCALLTYPE d3d_device_context_state_SetPrivateDataInterface(ID3DDeviceContextState *iface,
213 REFGUID guid, const IUnknown *data)
215 struct d3d_device_context_state *state = impl_from_ID3DDeviceContextState(iface);
217 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
219 return d3d_set_private_data_interface(&state->private_store, guid, data);
222 static const struct ID3DDeviceContextStateVtbl d3d_device_context_state_vtbl =
224 /* IUnknown methods */
225 d3d_device_context_state_QueryInterface,
226 d3d_device_context_state_AddRef,
227 d3d_device_context_state_Release,
228 /* ID3D11DeviceChild methods */
229 d3d_device_context_state_GetDevice,
230 d3d_device_context_state_GetPrivateData,
231 d3d_device_context_state_SetPrivateData,
232 d3d_device_context_state_SetPrivateDataInterface,
233 /* ID3DDeviceContextState methods */
236 static struct d3d_device_context_state_entry *d3d_device_context_state_get_entry(
237 struct d3d_device_context_state *state, struct d3d_device *device)
239 unsigned int i;
241 for (i = 0; i < state->entry_count; ++i)
243 if (state->entries[i].device == device)
244 return &state->entries[i];
247 return NULL;
250 static BOOL d3d_device_context_state_add_entry(struct d3d_device_context_state *state,
251 struct d3d_device *device, struct wined3d_state *wined3d_state)
253 struct d3d_device_context_state_entry *entry;
255 if (!d3d_array_reserve((void **)&state->entries, &state->entries_size,
256 state->entry_count + 1, sizeof(*state->entries)))
257 return FALSE;
259 if (!d3d_array_reserve((void **)&device->context_states, &device->context_states_size,
260 device->context_state_count + 1, sizeof(*device->context_states)))
261 return FALSE;
263 entry = &state->entries[state->entry_count++];
264 entry->device = device;
265 entry->wined3d_state = wined3d_state;
267 device->context_states[device->context_state_count++] = state;
269 return TRUE;
272 static void d3d_device_context_state_remove_entry(struct d3d_device_context_state *state, struct d3d_device *device)
274 struct d3d_device_context_state_entry *entry;
275 unsigned int i;
277 for (i = 0; i < state->entry_count; ++i)
279 entry = &state->entries[i];
280 if (entry->device != device)
281 continue;
283 if (entry->wined3d_state != wined3d_device_get_state(device->wined3d_device))
284 wined3d_state_destroy(entry->wined3d_state);
286 if (i != state->entry_count)
287 state->entries[i] = state->entries[state->entry_count - 1];
288 --state->entry_count;
290 break;
294 static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d3d_device_context_state *state,
295 struct d3d_device *device)
297 struct d3d_device_context_state_entry *entry;
298 struct wined3d_state *wined3d_state;
300 if ((entry = d3d_device_context_state_get_entry(state, device)))
301 return entry->wined3d_state;
303 if (FAILED(wined3d_state_create(device->wined3d_device,
304 (enum wined3d_feature_level *)&state->feature_level, 1, &wined3d_state)))
305 return NULL;
307 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
309 wined3d_state_destroy(wined3d_state);
310 return NULL;
313 return wined3d_state;
316 static void d3d_device_context_state_init(struct d3d_device_context_state *state,
317 struct d3d_device *device, D3D_FEATURE_LEVEL feature_level, REFIID emulated_interface)
319 state->ID3DDeviceContextState_iface.lpVtbl = &d3d_device_context_state_vtbl;
320 state->refcount = state->private_refcount = 0;
322 wined3d_private_store_init(&state->private_store);
324 state->feature_level = feature_level;
325 state->emulated_interface = *emulated_interface;
326 wined3d_device_incref(state->wined3d_device = device->wined3d_device);
327 state->device = &device->ID3D11Device2_iface;
329 d3d_device_context_state_AddRef(&state->ID3DDeviceContextState_iface);
332 /* ID3D11DeviceContext - immediate context methods */
334 static inline struct d3d11_immediate_context *impl_from_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
336 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11DeviceContext1_iface);
339 static inline struct d3d_device *device_from_immediate_ID3D11DeviceContext1(ID3D11DeviceContext1 *iface)
341 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
342 return CONTAINING_RECORD(context, struct d3d_device, immediate_context);
345 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_QueryInterface(ID3D11DeviceContext1 *iface,
346 REFIID iid, void **out)
348 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
350 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
352 if (IsEqualGUID(iid, &IID_ID3D11DeviceContext1)
353 || IsEqualGUID(iid, &IID_ID3D11DeviceContext)
354 || IsEqualGUID(iid, &IID_ID3D11DeviceChild)
355 || IsEqualGUID(iid, &IID_IUnknown))
357 *out = &context->ID3D11DeviceContext1_iface;
359 else if (IsEqualGUID(iid, &IID_ID3D11Multithread))
361 *out = &context->ID3D11Multithread_iface;
363 else
365 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
366 *out = NULL;
367 return E_NOINTERFACE;
370 ID3D11DeviceContext1_AddRef(iface);
371 return S_OK;
374 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_AddRef(ID3D11DeviceContext1 *iface)
376 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
377 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
378 ULONG refcount = InterlockedIncrement(&context->refcount);
380 TRACE("%p increasing refcount to %u.\n", context, refcount);
382 if (refcount == 1)
384 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
387 return refcount;
390 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_Release(ID3D11DeviceContext1 *iface)
392 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
393 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
394 ULONG refcount = InterlockedDecrement(&context->refcount);
396 TRACE("%p decreasing refcount to %u.\n", context, refcount);
398 if (!refcount)
400 ID3D11Device2_Release(&device->ID3D11Device2_iface);
403 return refcount;
406 static void d3d11_immediate_context_get_constant_buffers(ID3D11DeviceContext1 *iface,
407 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
409 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
410 unsigned int i;
412 wined3d_mutex_lock();
413 for (i = 0; i < buffer_count; ++i)
415 struct wined3d_buffer *wined3d_buffer;
416 struct d3d_buffer *buffer_impl;
418 if (!(wined3d_buffer = wined3d_device_get_constant_buffer(device->wined3d_device,
419 type, start_slot + i)))
421 buffers[i] = NULL;
422 continue;
425 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
426 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
427 ID3D11Buffer_AddRef(buffers[i]);
429 wined3d_mutex_unlock();
432 static void d3d11_immediate_context_set_constant_buffers(ID3D11DeviceContext1 *iface,
433 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
435 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
436 unsigned int i;
438 wined3d_mutex_lock();
439 for (i = 0; i < buffer_count; ++i)
441 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
443 wined3d_device_context_set_constant_buffer(context->wined3d_context, type, start_slot + i,
444 buffer ? buffer->wined3d_buffer : NULL);
446 wined3d_mutex_unlock();
449 static void STDMETHODCALLTYPE d3d11_immediate_context_GetDevice(ID3D11DeviceContext1 *iface, ID3D11Device **device)
451 struct d3d_device *device_object = device_from_immediate_ID3D11DeviceContext1(iface);
453 TRACE("iface %p, device %p.\n", iface, device);
455 *device = (ID3D11Device *)&device_object->ID3D11Device2_iface;
456 ID3D11Device_AddRef(*device);
459 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
460 UINT *data_size, void *data)
462 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
464 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
466 return d3d_get_private_data(&context->private_store, guid, data_size, data);
469 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateData(ID3D11DeviceContext1 *iface, REFGUID guid,
470 UINT data_size, const void *data)
472 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
474 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
476 return d3d_set_private_data(&context->private_store, guid, data_size, data);
479 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateDataInterface(ID3D11DeviceContext1 *iface,
480 REFGUID guid, const IUnknown *data)
482 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
484 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
486 return d3d_set_private_data_interface(&context->private_store, guid, data);
489 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers(ID3D11DeviceContext1 *iface,
490 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
492 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
493 iface, start_slot, buffer_count, buffers);
495 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
496 buffer_count, buffers);
499 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShaderResources(ID3D11DeviceContext1 *iface,
500 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
502 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
503 unsigned int i;
505 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
506 iface, start_slot, view_count, views);
508 wined3d_mutex_lock();
509 for (i = 0; i < view_count; ++i)
511 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
513 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
514 start_slot + i, view ? view->wined3d_view : NULL);
516 wined3d_mutex_unlock();
519 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShader(ID3D11DeviceContext1 *iface,
520 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
522 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
523 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
525 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
526 iface, shader, class_instances, class_instance_count);
528 if (class_instances)
529 FIXME("Dynamic linking is not implemented yet.\n");
531 wined3d_mutex_lock();
532 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL,
533 ps ? ps->wined3d_shader : NULL);
534 wined3d_mutex_unlock();
537 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetSamplers(ID3D11DeviceContext1 *iface,
538 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
540 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
541 unsigned int i;
543 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
544 iface, start_slot, sampler_count, samplers);
546 wined3d_mutex_lock();
547 for (i = 0; i < sampler_count; ++i)
549 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
551 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_PIXEL, start_slot + i,
552 sampler ? sampler->wined3d_sampler : NULL);
554 wined3d_mutex_unlock();
557 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShader(ID3D11DeviceContext1 *iface,
558 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
560 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
561 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
563 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
564 iface, shader, class_instances, class_instance_count);
566 if (class_instances)
567 FIXME("Dynamic linking is not implemented yet.\n");
569 wined3d_mutex_lock();
570 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_VERTEX,
571 vs ? vs->wined3d_shader : NULL);
572 wined3d_mutex_unlock();
575 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexed(ID3D11DeviceContext1 *iface,
576 UINT index_count, UINT start_index_location, INT base_vertex_location)
578 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
580 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
581 iface, index_count, start_index_location, base_vertex_location);
583 wined3d_mutex_lock();
584 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
585 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
586 wined3d_mutex_unlock();
589 static void STDMETHODCALLTYPE d3d11_immediate_context_Draw(ID3D11DeviceContext1 *iface,
590 UINT vertex_count, UINT start_vertex_location)
592 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
594 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
595 iface, vertex_count, start_vertex_location);
597 wined3d_mutex_lock();
598 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
599 wined3d_mutex_unlock();
602 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_Map(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
603 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
605 struct wined3d_resource *wined3d_resource;
606 struct wined3d_map_desc map_desc;
607 HRESULT hr;
609 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
610 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
612 if (map_flags)
613 FIXME("Ignoring map_flags %#x.\n", map_flags);
615 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
617 wined3d_mutex_lock();
618 hr = wined3d_resource_map(wined3d_resource, subresource_idx,
619 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
620 wined3d_mutex_unlock();
622 mapped_subresource->pData = map_desc.data;
623 mapped_subresource->RowPitch = map_desc.row_pitch;
624 mapped_subresource->DepthPitch = map_desc.slice_pitch;
626 return hr;
629 static void STDMETHODCALLTYPE d3d11_immediate_context_Unmap(ID3D11DeviceContext1 *iface, ID3D11Resource *resource,
630 UINT subresource_idx)
632 struct wined3d_resource *wined3d_resource;
634 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
636 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
638 wined3d_mutex_lock();
639 wined3d_resource_unmap(wined3d_resource, subresource_idx);
640 wined3d_mutex_unlock();
643 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers(ID3D11DeviceContext1 *iface,
644 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
646 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
647 iface, start_slot, buffer_count, buffers);
649 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
650 buffer_count, buffers);
653 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetInputLayout(ID3D11DeviceContext1 *iface,
654 ID3D11InputLayout *input_layout)
656 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
657 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
659 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
661 wined3d_mutex_lock();
662 wined3d_device_set_vertex_declaration(device->wined3d_device, layout ? layout->wined3d_decl : NULL);
663 wined3d_mutex_unlock();
666 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetVertexBuffers(ID3D11DeviceContext1 *iface,
667 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
669 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
670 unsigned int i;
672 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
673 iface, start_slot, buffer_count, buffers, strides, offsets);
675 wined3d_mutex_lock();
676 for (i = 0; i < buffer_count; ++i)
678 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
680 wined3d_device_context_set_stream_source(context->wined3d_context, start_slot + i,
681 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
683 wined3d_mutex_unlock();
686 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetIndexBuffer(ID3D11DeviceContext1 *iface,
687 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
689 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
690 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
692 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
693 iface, buffer, debug_dxgi_format(format), offset);
695 wined3d_mutex_lock();
696 wined3d_device_context_set_index_buffer(context->wined3d_context,
697 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
698 wined3dformat_from_dxgi_format(format), offset);
699 wined3d_mutex_unlock();
702 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstanced(ID3D11DeviceContext1 *iface,
703 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
704 UINT start_instance_location)
706 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
708 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
709 "base_vertex_location %d, start_instance_location %u.\n",
710 iface, instance_index_count, instance_count, start_index_location,
711 base_vertex_location, start_instance_location);
713 wined3d_mutex_lock();
714 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
715 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
716 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 d3d_device *device = device_from_immediate_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_draw_primitive_instanced(device->wined3d_device, 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 d3d_device *device = device_from_immediate_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_set_stream_output(device->wined3d_device, i,
1068 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
1070 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
1072 wined3d_device_set_stream_output(device->wined3d_device, 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 d3d_device *device = device_from_immediate_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_draw_indexed_primitive_instanced_indirect(device->wined3d_device,
1094 d3d_buffer->wined3d_buffer, offset);
1095 wined3d_mutex_unlock();
1098 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext1 *iface,
1099 ID3D11Buffer *buffer, UINT offset)
1101 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1102 struct d3d_buffer *d3d_buffer;
1104 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1106 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
1108 wined3d_mutex_lock();
1109 wined3d_device_draw_primitive_instanced_indirect(device->wined3d_device,
1110 d3d_buffer->wined3d_buffer, offset);
1111 wined3d_mutex_unlock();
1114 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext1 *iface,
1115 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
1117 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1119 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
1120 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
1122 wined3d_mutex_lock();
1123 wined3d_device_dispatch_compute(device->wined3d_device,
1124 thread_group_count_x, thread_group_count_y, thread_group_count_z);
1125 wined3d_mutex_unlock();
1128 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext1 *iface,
1129 ID3D11Buffer *buffer, UINT offset)
1131 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1132 struct d3d_buffer *buffer_impl;
1134 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
1136 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
1138 wined3d_mutex_lock();
1139 wined3d_device_dispatch_compute_indirect(device->wined3d_device,
1140 buffer_impl->wined3d_buffer, offset);
1141 wined3d_mutex_unlock();
1144 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext1 *iface,
1145 ID3D11RasterizerState *rasterizer_state)
1147 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1148 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1149 struct d3d_rasterizer_state *rasterizer_state_impl;
1150 const D3D11_RASTERIZER_DESC *desc;
1152 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1154 wined3d_mutex_lock();
1155 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
1157 wined3d_device_context_set_rasterizer_state(context->wined3d_context, NULL);
1158 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1159 wined3d_mutex_unlock();
1160 return;
1163 wined3d_device_context_set_rasterizer_state(context->wined3d_context, rasterizer_state_impl->wined3d_state);
1165 desc = &rasterizer_state_impl->desc;
1166 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1167 wined3d_mutex_unlock();
1170 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext1 *iface,
1171 UINT viewport_count, const D3D11_VIEWPORT *viewports)
1173 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1174 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
1175 unsigned int i;
1177 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1179 if (viewport_count > ARRAY_SIZE(wined3d_vp))
1180 return;
1182 for (i = 0; i < viewport_count; ++i)
1184 wined3d_vp[i].x = viewports[i].TopLeftX;
1185 wined3d_vp[i].y = viewports[i].TopLeftY;
1186 wined3d_vp[i].width = viewports[i].Width;
1187 wined3d_vp[i].height = viewports[i].Height;
1188 wined3d_vp[i].min_z = viewports[i].MinDepth;
1189 wined3d_vp[i].max_z = viewports[i].MaxDepth;
1192 wined3d_mutex_lock();
1193 wined3d_device_context_set_viewports(context->wined3d_context, viewport_count, wined3d_vp);
1194 wined3d_mutex_unlock();
1197 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext1 *iface,
1198 UINT rect_count, const D3D11_RECT *rects)
1200 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1202 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1204 if (rect_count > WINED3D_MAX_VIEWPORTS)
1205 return;
1207 wined3d_mutex_lock();
1208 wined3d_device_context_set_scissor_rects(context->wined3d_context, rect_count, rects);
1209 wined3d_mutex_unlock();
1212 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext1 *iface,
1213 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1214 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1216 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1217 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1218 struct wined3d_box wined3d_src_box;
1220 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1221 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1222 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1223 src_resource, src_subresource_idx, src_box);
1225 if (!dst_resource || !src_resource)
1226 return;
1228 if (src_box)
1229 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1230 src_box->right, src_box->bottom, src_box->front, src_box->back);
1232 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1233 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1234 wined3d_mutex_lock();
1235 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
1236 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
1237 wined3d_mutex_unlock();
1240 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext1 *iface,
1241 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1243 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1244 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1246 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1248 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1249 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1250 wined3d_mutex_lock();
1251 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1252 wined3d_mutex_unlock();
1255 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext1 *iface,
1256 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1257 const void *data, UINT row_pitch, UINT depth_pitch)
1259 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1260 struct wined3d_resource *wined3d_resource;
1261 struct wined3d_box wined3d_box;
1263 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1264 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1266 if (box)
1267 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1269 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1270 wined3d_mutex_lock();
1271 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1272 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, 0);
1273 wined3d_mutex_unlock();
1276 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext1 *iface,
1277 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1279 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1280 struct d3d11_unordered_access_view *uav;
1281 struct d3d_buffer *buffer_impl;
1283 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1284 iface, dst_buffer, dst_offset, src_view);
1286 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1287 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1289 wined3d_mutex_lock();
1290 wined3d_device_copy_uav_counter(device->wined3d_device,
1291 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1292 wined3d_mutex_unlock();
1295 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext1 *iface,
1296 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1298 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1299 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1300 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1301 HRESULT hr;
1303 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1304 iface, render_target_view, debug_float4(color_rgba));
1306 if (!view)
1307 return;
1309 wined3d_mutex_lock();
1310 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1311 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1312 ERR("Failed to clear view, hr %#x.\n", hr);
1313 wined3d_mutex_unlock();
1316 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext1 *iface,
1317 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1319 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1320 struct d3d11_unordered_access_view *view;
1322 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1323 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1325 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1326 wined3d_mutex_lock();
1327 wined3d_device_clear_unordered_access_view_uint(device->wined3d_device,
1328 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1329 wined3d_mutex_unlock();
1332 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext1 *iface,
1333 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1335 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1336 iface, unordered_access_view, debug_float4(values));
1339 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext1 *iface,
1340 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1342 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1343 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1344 DWORD wined3d_flags;
1345 HRESULT hr;
1347 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1348 iface, depth_stencil_view, flags, depth, stencil);
1350 if (!view)
1351 return;
1353 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1355 wined3d_mutex_lock();
1356 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1357 wined3d_flags, NULL, depth, stencil)))
1358 ERR("Failed to clear view, hr %#x.\n", hr);
1359 wined3d_mutex_unlock();
1362 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext1 *iface,
1363 ID3D11ShaderResourceView *view)
1365 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1367 TRACE("iface %p, view %p.\n", iface, view);
1369 wined3d_mutex_lock();
1370 wined3d_shader_resource_view_generate_mipmaps(srv->wined3d_view);
1371 wined3d_mutex_unlock();
1374 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext1 *iface,
1375 ID3D11Resource *resource, FLOAT min_lod)
1377 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1380 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext1 *iface,
1381 ID3D11Resource *resource)
1383 FIXME("iface %p, resource %p stub!\n", iface, resource);
1385 return 0.0f;
1388 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext1 *iface,
1389 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1390 ID3D11Resource *src_resource, UINT src_subresource_idx,
1391 DXGI_FORMAT format)
1393 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1394 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1395 enum wined3d_format_id wined3d_format;
1397 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
1398 "src_resource %p, src_subresource_idx %u, format %s.\n",
1399 iface, dst_resource, dst_subresource_idx,
1400 src_resource, src_subresource_idx, debug_dxgi_format(format));
1402 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1403 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1404 wined3d_format = wined3dformat_from_dxgi_format(format);
1405 wined3d_mutex_lock();
1406 wined3d_device_resolve_sub_resource(device->wined3d_device,
1407 wined3d_dst_resource, dst_subresource_idx,
1408 wined3d_src_resource, src_subresource_idx, wined3d_format);
1409 wined3d_mutex_unlock();
1412 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext1 *iface,
1413 ID3D11CommandList *command_list, BOOL restore_state)
1415 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1418 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext1 *iface,
1419 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1421 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1422 unsigned int i;
1424 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1425 iface, start_slot, view_count, views);
1427 wined3d_mutex_lock();
1428 for (i = 0; i < view_count; ++i)
1430 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1432 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1433 start_slot + i, view ? view->wined3d_view : NULL);
1435 wined3d_mutex_unlock();
1438 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext1 *iface,
1439 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1441 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1442 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1444 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1445 iface, shader, class_instances, class_instance_count);
1447 if (class_instances)
1448 FIXME("Dynamic linking is not implemented yet.\n");
1450 wined3d_mutex_lock();
1451 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_HULL,
1452 hs ? hs->wined3d_shader : NULL);
1453 wined3d_mutex_unlock();
1456 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext1 *iface,
1457 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1459 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1460 unsigned int i;
1462 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1463 iface, start_slot, sampler_count, samplers);
1465 wined3d_mutex_lock();
1466 for (i = 0; i < sampler_count; ++i)
1468 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1470 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_HULL, start_slot + i,
1471 sampler ? sampler->wined3d_sampler : NULL);
1473 wined3d_mutex_unlock();
1476 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1477 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1479 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1480 iface, start_slot, buffer_count, buffers);
1482 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
1483 buffer_count, buffers);
1486 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext1 *iface,
1487 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1489 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1490 unsigned int i;
1492 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1493 iface, start_slot, view_count, views);
1495 wined3d_mutex_lock();
1496 for (i = 0; i < view_count; ++i)
1498 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1500 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1501 start_slot + i, view ? view->wined3d_view : NULL);
1503 wined3d_mutex_unlock();
1506 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext1 *iface,
1507 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1509 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1510 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1512 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1513 iface, shader, class_instances, class_instance_count);
1515 if (class_instances)
1516 FIXME("Dynamic linking is not implemented yet.\n");
1518 wined3d_mutex_lock();
1519 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN,
1520 ds ? ds->wined3d_shader : NULL);
1521 wined3d_mutex_unlock();
1524 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext1 *iface,
1525 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1527 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1528 unsigned int i;
1530 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1531 iface, start_slot, sampler_count, samplers);
1533 wined3d_mutex_lock();
1534 for (i = 0; i < sampler_count; ++i)
1536 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1538 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_DOMAIN, start_slot + i,
1539 sampler ? sampler->wined3d_sampler : NULL);
1541 wined3d_mutex_unlock();
1544 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1545 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1547 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1548 iface, start_slot, buffer_count, buffers);
1550 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
1551 buffer_count, buffers);
1554 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext1 *iface,
1555 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1557 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1558 unsigned int i;
1560 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1561 iface, start_slot, view_count, views);
1563 wined3d_mutex_lock();
1564 for (i = 0; i < view_count; ++i)
1566 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1568 wined3d_device_context_set_shader_resource_view(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1569 start_slot + i, view ? view->wined3d_view : NULL);
1571 wined3d_mutex_unlock();
1574 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
1575 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1577 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1578 unsigned int i;
1580 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1581 iface, start_slot, view_count, views, initial_counts);
1583 wined3d_mutex_lock();
1584 for (i = 0; i < view_count; ++i)
1586 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1588 wined3d_device_context_set_unordered_access_view(context->wined3d_context, WINED3D_PIPELINE_COMPUTE,
1589 start_slot + i, view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1591 wined3d_mutex_unlock();
1594 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext1 *iface,
1595 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1597 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1598 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1600 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1601 iface, shader, class_instances, class_instance_count);
1603 if (class_instances)
1604 FIXME("Dynamic linking is not implemented yet.\n");
1606 wined3d_mutex_lock();
1607 wined3d_device_context_set_shader(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE,
1608 cs ? cs->wined3d_shader : NULL);
1609 wined3d_mutex_unlock();
1612 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext1 *iface,
1613 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1615 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
1616 unsigned int i;
1618 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1619 iface, start_slot, sampler_count, samplers);
1621 wined3d_mutex_lock();
1622 for (i = 0; i < sampler_count; ++i)
1624 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1626 wined3d_device_context_set_sampler(context->wined3d_context, WINED3D_SHADER_TYPE_COMPUTE, start_slot + i,
1627 sampler ? sampler->wined3d_sampler : NULL);
1629 wined3d_mutex_unlock();
1632 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext1 *iface,
1633 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1635 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1636 iface, start_slot, buffer_count, buffers);
1638 d3d11_immediate_context_set_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
1639 buffer_count, buffers);
1642 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1643 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1645 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1646 iface, start_slot, buffer_count, buffers);
1648 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
1649 buffer_count, buffers);
1652 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext1 *iface,
1653 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1655 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1656 unsigned int i;
1658 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1659 iface, start_slot, view_count, views);
1661 wined3d_mutex_lock();
1662 for (i = 0; i < view_count; ++i)
1664 struct wined3d_shader_resource_view *wined3d_view;
1665 struct d3d_shader_resource_view *view_impl;
1667 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1669 views[i] = NULL;
1670 continue;
1673 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1674 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1675 ID3D11ShaderResourceView_AddRef(views[i]);
1677 wined3d_mutex_unlock();
1680 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext1 *iface,
1681 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1683 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1684 struct wined3d_shader *wined3d_shader;
1685 struct d3d_pixel_shader *shader_impl;
1687 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1688 iface, shader, class_instances, class_instance_count);
1690 if (class_instances || class_instance_count)
1691 FIXME("Dynamic linking not implemented yet.\n");
1692 if (class_instance_count)
1693 *class_instance_count = 0;
1695 wined3d_mutex_lock();
1696 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1698 wined3d_mutex_unlock();
1699 *shader = NULL;
1700 return;
1703 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1704 wined3d_mutex_unlock();
1705 *shader = &shader_impl->ID3D11PixelShader_iface;
1706 ID3D11PixelShader_AddRef(*shader);
1709 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext1 *iface,
1710 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1712 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1713 unsigned int i;
1715 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1716 iface, start_slot, sampler_count, samplers);
1718 wined3d_mutex_lock();
1719 for (i = 0; i < sampler_count; ++i)
1721 struct wined3d_sampler *wined3d_sampler;
1722 struct d3d_sampler_state *sampler_impl;
1724 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1726 samplers[i] = NULL;
1727 continue;
1730 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1731 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1732 ID3D11SamplerState_AddRef(samplers[i]);
1734 wined3d_mutex_unlock();
1737 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext1 *iface,
1738 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1740 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1741 struct d3d_vertex_shader *shader_impl;
1742 struct wined3d_shader *wined3d_shader;
1744 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1745 iface, shader, class_instances, class_instance_count);
1747 if (class_instances || class_instance_count)
1748 FIXME("Dynamic linking not implemented yet.\n");
1749 if (class_instance_count)
1750 *class_instance_count = 0;
1752 wined3d_mutex_lock();
1753 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1755 wined3d_mutex_unlock();
1756 *shader = NULL;
1757 return;
1760 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1761 wined3d_mutex_unlock();
1762 *shader = &shader_impl->ID3D11VertexShader_iface;
1763 ID3D11VertexShader_AddRef(*shader);
1766 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1767 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1769 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1770 iface, start_slot, buffer_count, buffers);
1772 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot,
1773 buffer_count, buffers);
1776 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext1 *iface,
1777 ID3D11InputLayout **input_layout)
1779 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1780 struct wined3d_vertex_declaration *wined3d_declaration;
1781 struct d3d_input_layout *input_layout_impl;
1783 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1785 wined3d_mutex_lock();
1786 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1788 wined3d_mutex_unlock();
1789 *input_layout = NULL;
1790 return;
1793 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1794 wined3d_mutex_unlock();
1795 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1796 ID3D11InputLayout_AddRef(*input_layout);
1799 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext1 *iface,
1800 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1802 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1803 unsigned int i;
1805 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1806 iface, start_slot, buffer_count, buffers, strides, offsets);
1808 wined3d_mutex_lock();
1809 for (i = 0; i < buffer_count; ++i)
1811 struct wined3d_buffer *wined3d_buffer = NULL;
1812 struct d3d_buffer *buffer_impl;
1814 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1815 &wined3d_buffer, &offsets[i], &strides[i])))
1817 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1818 if (strides)
1819 strides[i] = 0;
1820 if (offsets)
1821 offsets[i] = 0;
1824 if (!wined3d_buffer)
1826 buffers[i] = NULL;
1827 continue;
1830 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1831 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1833 wined3d_mutex_unlock();
1836 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext1 *iface,
1837 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1839 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1840 enum wined3d_format_id wined3d_format;
1841 struct wined3d_buffer *wined3d_buffer;
1842 struct d3d_buffer *buffer_impl;
1844 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1846 wined3d_mutex_lock();
1847 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1848 *format = dxgi_format_from_wined3dformat(wined3d_format);
1849 if (!wined3d_buffer)
1851 wined3d_mutex_unlock();
1852 *buffer = NULL;
1853 return;
1856 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1857 wined3d_mutex_unlock();
1858 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1861 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext1 *iface,
1862 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1864 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1865 iface, start_slot, buffer_count, buffers);
1867 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
1868 buffer_count, buffers);
1871 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext1 *iface,
1872 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1874 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1875 struct d3d_geometry_shader *shader_impl;
1876 struct wined3d_shader *wined3d_shader;
1878 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1879 iface, shader, class_instances, class_instance_count);
1881 if (class_instances || class_instance_count)
1882 FIXME("Dynamic linking not implemented yet.\n");
1883 if (class_instance_count)
1884 *class_instance_count = 0;
1886 wined3d_mutex_lock();
1887 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1889 wined3d_mutex_unlock();
1890 *shader = NULL;
1891 return;
1894 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1895 wined3d_mutex_unlock();
1896 *shader = &shader_impl->ID3D11GeometryShader_iface;
1897 ID3D11GeometryShader_AddRef(*shader);
1900 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext1 *iface,
1901 D3D11_PRIMITIVE_TOPOLOGY *topology)
1903 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1904 enum wined3d_primitive_type primitive_type;
1905 unsigned int patch_vertex_count;
1907 TRACE("iface %p, topology %p.\n", iface, topology);
1909 wined3d_mutex_lock();
1910 wined3d_device_get_primitive_type(device->wined3d_device, &primitive_type, &patch_vertex_count);
1911 wined3d_mutex_unlock();
1913 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1916 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext1 *iface,
1917 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1919 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1920 unsigned int i;
1922 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1924 wined3d_mutex_lock();
1925 for (i = 0; i < view_count; ++i)
1927 struct wined3d_shader_resource_view *wined3d_view;
1928 struct d3d_shader_resource_view *view_impl;
1930 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1932 views[i] = NULL;
1933 continue;
1936 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1937 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1938 ID3D11ShaderResourceView_AddRef(views[i]);
1940 wined3d_mutex_unlock();
1943 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext1 *iface,
1944 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1946 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1947 unsigned int i;
1949 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1950 iface, start_slot, sampler_count, samplers);
1952 wined3d_mutex_lock();
1953 for (i = 0; i < sampler_count; ++i)
1955 struct wined3d_sampler *wined3d_sampler;
1956 struct d3d_sampler_state *sampler_impl;
1958 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1960 samplers[i] = NULL;
1961 continue;
1964 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1965 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1966 ID3D11SamplerState_AddRef(samplers[i]);
1968 wined3d_mutex_unlock();
1971 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext1 *iface,
1972 ID3D11Predicate **predicate, BOOL *value)
1974 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1975 struct wined3d_query *wined3d_predicate;
1976 struct d3d_query *predicate_impl;
1978 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1980 wined3d_mutex_lock();
1981 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1983 wined3d_mutex_unlock();
1984 *predicate = NULL;
1985 return;
1988 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1989 wined3d_mutex_unlock();
1990 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1991 ID3D11Predicate_AddRef(*predicate);
1994 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext1 *iface,
1995 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1997 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
1998 unsigned int i;
2000 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2002 wined3d_mutex_lock();
2003 for (i = 0; i < view_count; ++i)
2005 struct wined3d_shader_resource_view *wined3d_view;
2006 struct d3d_shader_resource_view *view_impl;
2008 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
2010 views[i] = NULL;
2011 continue;
2014 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2015 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
2016 ID3D11ShaderResourceView_AddRef(views[i]);
2018 wined3d_mutex_unlock();
2021 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext1 *iface,
2022 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2024 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2025 unsigned int i;
2027 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2028 iface, start_slot, sampler_count, samplers);
2030 wined3d_mutex_lock();
2031 for (i = 0; i < sampler_count; ++i)
2033 struct d3d_sampler_state *sampler_impl;
2034 struct wined3d_sampler *wined3d_sampler;
2036 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
2038 samplers[i] = NULL;
2039 continue;
2042 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2043 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
2044 ID3D11SamplerState_AddRef(samplers[i]);
2046 wined3d_mutex_unlock();
2049 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext1 *iface,
2050 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2051 ID3D11DepthStencilView **depth_stencil_view)
2053 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2054 struct wined3d_rendertarget_view *wined3d_view;
2056 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
2057 iface, render_target_view_count, render_target_views, depth_stencil_view);
2059 wined3d_mutex_lock();
2060 if (render_target_views)
2062 struct d3d_rendertarget_view *view_impl;
2063 unsigned int i;
2065 for (i = 0; i < render_target_view_count; ++i)
2067 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
2068 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2070 render_target_views[i] = NULL;
2071 continue;
2074 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
2075 ID3D11RenderTargetView_AddRef(render_target_views[i]);
2079 if (depth_stencil_view)
2081 struct d3d_depthstencil_view *view_impl;
2083 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
2084 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
2086 *depth_stencil_view = NULL;
2088 else
2090 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
2091 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
2094 wined3d_mutex_unlock();
2097 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
2098 ID3D11DeviceContext1 *iface,
2099 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
2100 ID3D11DepthStencilView **depth_stencil_view,
2101 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
2102 ID3D11UnorderedAccessView **unordered_access_views)
2104 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2105 struct wined3d_unordered_access_view *wined3d_view;
2106 struct d3d11_unordered_access_view *view_impl;
2107 unsigned int i;
2109 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
2110 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
2111 "unordered_access_views %p.\n",
2112 iface, render_target_view_count, render_target_views, depth_stencil_view,
2113 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
2115 if (render_target_views || depth_stencil_view)
2116 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
2117 render_target_views, depth_stencil_view);
2119 if (unordered_access_views)
2121 wined3d_mutex_lock();
2122 for (i = 0; i < unordered_access_view_count; ++i)
2124 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
2125 unordered_access_view_start_slot + i)))
2127 unordered_access_views[i] = NULL;
2128 continue;
2131 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2132 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
2133 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
2135 wined3d_mutex_unlock();
2139 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext1 *iface,
2140 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
2142 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2143 struct wined3d_blend_state *wined3d_state;
2144 struct d3d_blend_state *blend_state_impl;
2146 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
2147 iface, blend_state, blend_factor, sample_mask);
2149 wined3d_mutex_lock();
2150 if ((wined3d_state = wined3d_device_get_blend_state(device->wined3d_device,
2151 (struct wined3d_color *)blend_factor, sample_mask)))
2153 blend_state_impl = wined3d_blend_state_get_parent(wined3d_state);
2154 ID3D11BlendState_AddRef(*blend_state = &blend_state_impl->ID3D11BlendState_iface);
2156 else
2158 *blend_state = NULL;
2160 wined3d_mutex_unlock();
2163 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext1 *iface,
2164 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2166 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2167 struct wined3d_depth_stencil_state *wined3d_state;
2168 struct d3d_depthstencil_state *state_impl;
2170 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2171 iface, depth_stencil_state, stencil_ref);
2173 wined3d_mutex_lock();
2174 if ((wined3d_state = wined3d_device_get_depth_stencil_state(device->wined3d_device, stencil_ref)))
2176 state_impl = wined3d_depth_stencil_state_get_parent(wined3d_state);
2177 ID3D11DepthStencilState_AddRef(*depth_stencil_state = &state_impl->ID3D11DepthStencilState_iface);
2179 else
2181 *depth_stencil_state = NULL;
2183 wined3d_mutex_unlock();
2186 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext1 *iface,
2187 UINT buffer_count, ID3D11Buffer **buffers)
2189 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2190 unsigned int i;
2192 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2194 wined3d_mutex_lock();
2195 for (i = 0; i < buffer_count; ++i)
2197 struct wined3d_buffer *wined3d_buffer;
2198 struct d3d_buffer *buffer_impl;
2200 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
2202 buffers[i] = NULL;
2203 continue;
2206 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2207 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2208 ID3D11Buffer_AddRef(buffers[i]);
2210 wined3d_mutex_unlock();
2213 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext1 *iface,
2214 ID3D11RasterizerState **rasterizer_state)
2216 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2217 struct d3d_rasterizer_state *rasterizer_state_impl;
2218 struct wined3d_rasterizer_state *wined3d_state;
2220 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2222 wined3d_mutex_lock();
2223 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
2225 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2226 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2228 else
2230 *rasterizer_state = NULL;
2232 wined3d_mutex_unlock();
2235 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext1 *iface,
2236 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2238 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2239 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
2240 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
2242 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2244 if (!viewport_count)
2245 return;
2247 wined3d_mutex_lock();
2248 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
2249 wined3d_mutex_unlock();
2251 if (!viewports)
2253 *viewport_count = actual_count;
2254 return;
2257 if (*viewport_count > actual_count)
2258 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
2260 *viewport_count = min(actual_count, *viewport_count);
2261 for (i = 0; i < *viewport_count; ++i)
2263 viewports[i].TopLeftX = wined3d_vp[i].x;
2264 viewports[i].TopLeftY = wined3d_vp[i].y;
2265 viewports[i].Width = wined3d_vp[i].width;
2266 viewports[i].Height = wined3d_vp[i].height;
2267 viewports[i].MinDepth = wined3d_vp[i].min_z;
2268 viewports[i].MaxDepth = wined3d_vp[i].max_z;
2272 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext1 *iface,
2273 UINT *rect_count, D3D11_RECT *rects)
2275 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2276 unsigned int actual_count;
2278 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2280 if (!rect_count)
2281 return;
2283 actual_count = *rect_count;
2285 wined3d_mutex_lock();
2286 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
2287 wined3d_mutex_unlock();
2289 if (rects && *rect_count > actual_count)
2290 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
2291 *rect_count = actual_count;
2294 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext1 *iface,
2295 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2297 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2298 unsigned int i;
2300 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2302 wined3d_mutex_lock();
2303 for (i = 0; i < view_count; ++i)
2305 struct wined3d_shader_resource_view *wined3d_view;
2306 struct d3d_shader_resource_view *view_impl;
2308 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2310 views[i] = NULL;
2311 continue;
2314 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2315 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2317 wined3d_mutex_unlock();
2320 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext1 *iface,
2321 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2323 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2324 struct d3d11_hull_shader *shader_impl;
2325 struct wined3d_shader *wined3d_shader;
2327 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2328 iface, shader, class_instances, class_instance_count);
2330 if (class_instances || class_instance_count)
2331 FIXME("Dynamic linking not implemented yet.\n");
2332 if (class_instance_count)
2333 *class_instance_count = 0;
2335 wined3d_mutex_lock();
2336 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2338 wined3d_mutex_unlock();
2339 *shader = NULL;
2340 return;
2343 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2344 wined3d_mutex_unlock();
2345 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2348 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext1 *iface,
2349 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2351 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2352 unsigned int i;
2354 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2355 iface, start_slot, sampler_count, samplers);
2357 wined3d_mutex_lock();
2358 for (i = 0; i < sampler_count; ++i)
2360 struct wined3d_sampler *wined3d_sampler;
2361 struct d3d_sampler_state *sampler_impl;
2363 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2365 samplers[i] = NULL;
2366 continue;
2369 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2370 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2372 wined3d_mutex_unlock();
2375 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2376 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2378 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2379 iface, start_slot, buffer_count, buffers);
2381 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_HULL, start_slot,
2382 buffer_count, buffers);
2385 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext1 *iface,
2386 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2388 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2389 unsigned int i;
2391 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2392 iface, start_slot, view_count, views);
2394 wined3d_mutex_lock();
2395 for (i = 0; i < view_count; ++i)
2397 struct wined3d_shader_resource_view *wined3d_view;
2398 struct d3d_shader_resource_view *view_impl;
2400 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2402 views[i] = NULL;
2403 continue;
2406 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2407 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2409 wined3d_mutex_unlock();
2412 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext1 *iface,
2413 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2415 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2416 struct d3d11_domain_shader *shader_impl;
2417 struct wined3d_shader *wined3d_shader;
2419 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2420 iface, shader, class_instances, class_instance_count);
2422 if (class_instances || class_instance_count)
2423 FIXME("Dynamic linking not implemented yet.\n");
2424 if (class_instance_count)
2425 *class_instance_count = 0;
2427 wined3d_mutex_lock();
2428 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2430 wined3d_mutex_unlock();
2431 *shader = NULL;
2432 return;
2435 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2436 wined3d_mutex_unlock();
2437 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2440 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext1 *iface,
2441 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2443 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2444 unsigned int i;
2446 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2447 iface, start_slot, sampler_count, samplers);
2449 wined3d_mutex_lock();
2450 for (i = 0; i < sampler_count; ++i)
2452 struct wined3d_sampler *wined3d_sampler;
2453 struct d3d_sampler_state *sampler_impl;
2455 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2457 samplers[i] = NULL;
2458 continue;
2461 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2462 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2464 wined3d_mutex_unlock();
2467 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2468 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2470 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2471 iface, start_slot, buffer_count, buffers);
2473 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_DOMAIN, start_slot,
2474 buffer_count, buffers);
2477 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext1 *iface,
2478 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2480 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2481 unsigned int i;
2483 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2485 wined3d_mutex_lock();
2486 for (i = 0; i < view_count; ++i)
2488 struct wined3d_shader_resource_view *wined3d_view;
2489 struct d3d_shader_resource_view *view_impl;
2491 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2493 views[i] = NULL;
2494 continue;
2497 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2498 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2500 wined3d_mutex_unlock();
2503 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext1 *iface,
2504 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2506 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2507 unsigned int i;
2509 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2511 wined3d_mutex_lock();
2512 for (i = 0; i < view_count; ++i)
2514 struct wined3d_unordered_access_view *wined3d_view;
2515 struct d3d11_unordered_access_view *view_impl;
2517 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2519 views[i] = NULL;
2520 continue;
2523 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2524 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2526 wined3d_mutex_unlock();
2529 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext1 *iface,
2530 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2532 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2533 struct d3d11_compute_shader *shader_impl;
2534 struct wined3d_shader *wined3d_shader;
2536 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2537 iface, shader, class_instances, class_instance_count);
2539 if (class_instances || class_instance_count)
2540 FIXME("Dynamic linking not implemented yet.\n");
2541 if (class_instance_count)
2542 *class_instance_count = 0;
2544 wined3d_mutex_lock();
2545 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2547 wined3d_mutex_unlock();
2548 *shader = NULL;
2549 return;
2552 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2553 wined3d_mutex_unlock();
2554 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2557 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext1 *iface,
2558 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2560 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2561 unsigned int i;
2563 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2564 iface, start_slot, sampler_count, samplers);
2566 wined3d_mutex_lock();
2567 for (i = 0; i < sampler_count; ++i)
2569 struct wined3d_sampler *wined3d_sampler;
2570 struct d3d_sampler_state *sampler_impl;
2572 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2574 samplers[i] = NULL;
2575 continue;
2578 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2579 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2581 wined3d_mutex_unlock();
2584 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext1 *iface,
2585 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2587 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2588 iface, start_slot, buffer_count, buffers);
2590 d3d11_immediate_context_get_constant_buffers(iface, WINED3D_SHADER_TYPE_COMPUTE, start_slot,
2591 buffer_count, buffers);
2594 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext1 *iface)
2596 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext1(iface);
2597 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2598 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2599 unsigned int i, j;
2601 TRACE("iface %p.\n", iface);
2603 wined3d_mutex_lock();
2604 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
2606 wined3d_device_context_set_shader(context->wined3d_context, i, NULL);
2607 for (j = 0; j < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++j)
2608 wined3d_device_context_set_constant_buffer(context->wined3d_context, i, j, NULL);
2609 for (j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++j)
2610 wined3d_device_context_set_shader_resource_view(context->wined3d_context, i, j, NULL);
2611 for (j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++j)
2612 wined3d_device_context_set_sampler(context->wined3d_context, i, j, NULL);
2614 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2616 wined3d_device_context_set_stream_source(context->wined3d_context, i, NULL, 0, 0);
2618 wined3d_device_context_set_index_buffer(context->wined3d_context, NULL, WINED3DFMT_UNKNOWN, 0);
2619 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
2620 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED, 0);
2621 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2623 wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
2625 wined3d_device_context_set_depth_stencil_view(context->wined3d_context, NULL);
2626 for (i = 0; i < WINED3D_PIPELINE_COUNT; ++i)
2628 for (j = 0; j < D3D11_PS_CS_UAV_REGISTER_COUNT; ++j)
2629 wined3d_device_context_set_unordered_access_view(context->wined3d_context, i, j, NULL, ~0u);
2631 ID3D11DeviceContext1_OMSetDepthStencilState(iface, NULL, 0);
2632 ID3D11DeviceContext1_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2633 ID3D11DeviceContext1_RSSetViewports(iface, 0, NULL);
2634 ID3D11DeviceContext1_RSSetScissorRects(iface, 0, NULL);
2635 ID3D11DeviceContext1_RSSetState(iface, NULL);
2636 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2638 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2640 wined3d_device_context_set_predication(context->wined3d_context, NULL, FALSE);
2641 wined3d_mutex_unlock();
2644 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext1 *iface)
2646 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2648 TRACE("iface %p.\n", iface);
2650 wined3d_mutex_lock();
2651 wined3d_device_flush(device->wined3d_device);
2652 wined3d_mutex_unlock();
2655 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext1 *iface)
2657 TRACE("iface %p.\n", iface);
2659 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2662 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext1 *iface)
2664 TRACE("iface %p.\n", iface);
2666 return 0;
2669 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext1 *iface,
2670 BOOL restore, ID3D11CommandList **command_list)
2672 TRACE("iface %p, restore %#x, command_list %p.\n", iface, restore, command_list);
2674 return DXGI_ERROR_INVALID_CALL;
2677 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion1(ID3D11DeviceContext1 *iface,
2678 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
2679 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box, UINT flags)
2681 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2682 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
2683 struct wined3d_box wined3d_src_box;
2685 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
2686 "src_resource %p, src_subresource_idx %u, src_box %p, flags %#x.\n",
2687 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
2688 src_resource, src_subresource_idx, src_box, flags);
2690 if (!dst_resource || !src_resource)
2691 return;
2693 if (src_box)
2694 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
2695 src_box->right, src_box->bottom, src_box->front, src_box->back);
2697 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
2698 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
2699 wined3d_mutex_lock();
2700 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
2701 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, flags);
2702 wined3d_mutex_unlock();
2705 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource1(ID3D11DeviceContext1 *iface,
2706 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box, const void *data,
2707 UINT row_pitch, UINT depth_pitch, UINT flags)
2709 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2710 struct wined3d_resource *wined3d_resource;
2711 struct wined3d_box wined3d_box;
2713 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
2714 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch, flags);
2716 if (box)
2717 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom,
2718 box->front, box->back);
2720 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
2721 wined3d_mutex_lock();
2722 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource, subresource_idx,
2723 box ? &wined3d_box : NULL, data, row_pitch, depth_pitch, flags);
2724 wined3d_mutex_unlock();
2727 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardResource(ID3D11DeviceContext1 *iface,
2728 ID3D11Resource *resource)
2730 FIXME("iface %p, resource %p stub!\n", iface, resource);
2733 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView(ID3D11DeviceContext1 *iface, ID3D11View *view)
2735 FIXME("iface %p, view %p stub!\n", iface, view);
2738 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2739 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2740 const UINT *num_constants)
2742 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2743 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2746 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2747 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2748 const UINT *num_constants)
2750 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2751 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2754 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2755 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2756 const UINT *num_constants)
2758 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2759 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2762 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2763 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2764 const UINT *num_constants)
2766 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2767 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2770 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2771 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2772 const UINT *num_constants)
2774 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2775 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2778 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers1(ID3D11DeviceContext1 *iface,
2779 UINT start_slot, UINT buffer_count, ID3D11Buffer * const *buffers, const UINT *first_constant,
2780 const UINT *num_constants)
2782 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2783 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2786 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2787 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2789 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2790 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2793 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2794 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2796 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2797 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2800 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2801 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2803 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2804 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2807 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2808 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2810 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2811 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2814 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2815 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2817 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2818 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2821 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers1(ID3D11DeviceContext1 *iface,
2822 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *first_constant, UINT *num_constants)
2824 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, first_constant %p, num_constants %p stub!\n",
2825 iface, start_slot, buffer_count, buffers, first_constant, num_constants);
2828 static void STDMETHODCALLTYPE d3d11_immediate_context_SwapDeviceContextState(ID3D11DeviceContext1 *iface,
2829 ID3DDeviceContextState *state, ID3DDeviceContextState **prev)
2831 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext1(iface);
2832 struct d3d_device_context_state *state_impl, *prev_impl;
2833 struct wined3d_state *wined3d_state;
2835 TRACE("iface %p, state %p, prev %p.\n", iface, state, prev);
2837 if (!state)
2839 if (prev)
2840 *prev = NULL;
2841 return;
2844 wined3d_mutex_lock();
2846 prev_impl = device->state;
2847 state_impl = impl_from_ID3DDeviceContextState(state);
2848 if (!(wined3d_state = d3d_device_context_state_get_wined3d_state(state_impl, device)))
2849 ERR("Failed to get wined3d state for device context state %p.\n", state_impl);
2850 wined3d_device_set_state(device->wined3d_device, wined3d_state);
2852 if (prev)
2853 ID3DDeviceContextState_AddRef(*prev = &prev_impl->ID3DDeviceContextState_iface);
2855 d3d_device_context_state_private_addref(state_impl);
2856 device->state = state_impl;
2857 d3d_device_context_state_private_release(prev_impl);
2859 if (d3d_device_is_d3d10_active(device))
2860 FIXME("D3D10 interface emulation not fully implemented yet!\n");
2861 wined3d_mutex_unlock();
2864 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearView(ID3D11DeviceContext1 *iface, ID3D11View *view,
2865 const FLOAT color[4], const D3D11_RECT *rect, UINT num_rects)
2867 FIXME("iface %p, view %p, color %p, rect %p, num_rects %u stub!\n", iface, view, color, rect, num_rects);
2870 static void STDMETHODCALLTYPE d3d11_immediate_context_DiscardView1(ID3D11DeviceContext1 *iface, ID3D11View *view,
2871 const D3D11_RECT *rects, UINT num_rects)
2873 FIXME("iface %p, view %p, rects %p, num_rects %u stub!\n", iface, view, rects, num_rects);
2876 static const struct ID3D11DeviceContext1Vtbl d3d11_immediate_context_vtbl =
2878 /* IUnknown methods */
2879 d3d11_immediate_context_QueryInterface,
2880 d3d11_immediate_context_AddRef,
2881 d3d11_immediate_context_Release,
2882 /* ID3D11DeviceChild methods */
2883 d3d11_immediate_context_GetDevice,
2884 d3d11_immediate_context_GetPrivateData,
2885 d3d11_immediate_context_SetPrivateData,
2886 d3d11_immediate_context_SetPrivateDataInterface,
2887 /* ID3D11DeviceContext methods */
2888 d3d11_immediate_context_VSSetConstantBuffers,
2889 d3d11_immediate_context_PSSetShaderResources,
2890 d3d11_immediate_context_PSSetShader,
2891 d3d11_immediate_context_PSSetSamplers,
2892 d3d11_immediate_context_VSSetShader,
2893 d3d11_immediate_context_DrawIndexed,
2894 d3d11_immediate_context_Draw,
2895 d3d11_immediate_context_Map,
2896 d3d11_immediate_context_Unmap,
2897 d3d11_immediate_context_PSSetConstantBuffers,
2898 d3d11_immediate_context_IASetInputLayout,
2899 d3d11_immediate_context_IASetVertexBuffers,
2900 d3d11_immediate_context_IASetIndexBuffer,
2901 d3d11_immediate_context_DrawIndexedInstanced,
2902 d3d11_immediate_context_DrawInstanced,
2903 d3d11_immediate_context_GSSetConstantBuffers,
2904 d3d11_immediate_context_GSSetShader,
2905 d3d11_immediate_context_IASetPrimitiveTopology,
2906 d3d11_immediate_context_VSSetShaderResources,
2907 d3d11_immediate_context_VSSetSamplers,
2908 d3d11_immediate_context_Begin,
2909 d3d11_immediate_context_End,
2910 d3d11_immediate_context_GetData,
2911 d3d11_immediate_context_SetPredication,
2912 d3d11_immediate_context_GSSetShaderResources,
2913 d3d11_immediate_context_GSSetSamplers,
2914 d3d11_immediate_context_OMSetRenderTargets,
2915 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2916 d3d11_immediate_context_OMSetBlendState,
2917 d3d11_immediate_context_OMSetDepthStencilState,
2918 d3d11_immediate_context_SOSetTargets,
2919 d3d11_immediate_context_DrawAuto,
2920 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2921 d3d11_immediate_context_DrawInstancedIndirect,
2922 d3d11_immediate_context_Dispatch,
2923 d3d11_immediate_context_DispatchIndirect,
2924 d3d11_immediate_context_RSSetState,
2925 d3d11_immediate_context_RSSetViewports,
2926 d3d11_immediate_context_RSSetScissorRects,
2927 d3d11_immediate_context_CopySubresourceRegion,
2928 d3d11_immediate_context_CopyResource,
2929 d3d11_immediate_context_UpdateSubresource,
2930 d3d11_immediate_context_CopyStructureCount,
2931 d3d11_immediate_context_ClearRenderTargetView,
2932 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2933 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2934 d3d11_immediate_context_ClearDepthStencilView,
2935 d3d11_immediate_context_GenerateMips,
2936 d3d11_immediate_context_SetResourceMinLOD,
2937 d3d11_immediate_context_GetResourceMinLOD,
2938 d3d11_immediate_context_ResolveSubresource,
2939 d3d11_immediate_context_ExecuteCommandList,
2940 d3d11_immediate_context_HSSetShaderResources,
2941 d3d11_immediate_context_HSSetShader,
2942 d3d11_immediate_context_HSSetSamplers,
2943 d3d11_immediate_context_HSSetConstantBuffers,
2944 d3d11_immediate_context_DSSetShaderResources,
2945 d3d11_immediate_context_DSSetShader,
2946 d3d11_immediate_context_DSSetSamplers,
2947 d3d11_immediate_context_DSSetConstantBuffers,
2948 d3d11_immediate_context_CSSetShaderResources,
2949 d3d11_immediate_context_CSSetUnorderedAccessViews,
2950 d3d11_immediate_context_CSSetShader,
2951 d3d11_immediate_context_CSSetSamplers,
2952 d3d11_immediate_context_CSSetConstantBuffers,
2953 d3d11_immediate_context_VSGetConstantBuffers,
2954 d3d11_immediate_context_PSGetShaderResources,
2955 d3d11_immediate_context_PSGetShader,
2956 d3d11_immediate_context_PSGetSamplers,
2957 d3d11_immediate_context_VSGetShader,
2958 d3d11_immediate_context_PSGetConstantBuffers,
2959 d3d11_immediate_context_IAGetInputLayout,
2960 d3d11_immediate_context_IAGetVertexBuffers,
2961 d3d11_immediate_context_IAGetIndexBuffer,
2962 d3d11_immediate_context_GSGetConstantBuffers,
2963 d3d11_immediate_context_GSGetShader,
2964 d3d11_immediate_context_IAGetPrimitiveTopology,
2965 d3d11_immediate_context_VSGetShaderResources,
2966 d3d11_immediate_context_VSGetSamplers,
2967 d3d11_immediate_context_GetPredication,
2968 d3d11_immediate_context_GSGetShaderResources,
2969 d3d11_immediate_context_GSGetSamplers,
2970 d3d11_immediate_context_OMGetRenderTargets,
2971 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2972 d3d11_immediate_context_OMGetBlendState,
2973 d3d11_immediate_context_OMGetDepthStencilState,
2974 d3d11_immediate_context_SOGetTargets,
2975 d3d11_immediate_context_RSGetState,
2976 d3d11_immediate_context_RSGetViewports,
2977 d3d11_immediate_context_RSGetScissorRects,
2978 d3d11_immediate_context_HSGetShaderResources,
2979 d3d11_immediate_context_HSGetShader,
2980 d3d11_immediate_context_HSGetSamplers,
2981 d3d11_immediate_context_HSGetConstantBuffers,
2982 d3d11_immediate_context_DSGetShaderResources,
2983 d3d11_immediate_context_DSGetShader,
2984 d3d11_immediate_context_DSGetSamplers,
2985 d3d11_immediate_context_DSGetConstantBuffers,
2986 d3d11_immediate_context_CSGetShaderResources,
2987 d3d11_immediate_context_CSGetUnorderedAccessViews,
2988 d3d11_immediate_context_CSGetShader,
2989 d3d11_immediate_context_CSGetSamplers,
2990 d3d11_immediate_context_CSGetConstantBuffers,
2991 d3d11_immediate_context_ClearState,
2992 d3d11_immediate_context_Flush,
2993 d3d11_immediate_context_GetType,
2994 d3d11_immediate_context_GetContextFlags,
2995 d3d11_immediate_context_FinishCommandList,
2996 /* ID3D11DeviceContext1 methods */
2997 d3d11_immediate_context_CopySubresourceRegion1,
2998 d3d11_immediate_context_UpdateSubresource1,
2999 d3d11_immediate_context_DiscardResource,
3000 d3d11_immediate_context_DiscardView,
3001 d3d11_immediate_context_VSSetConstantBuffers1,
3002 d3d11_immediate_context_HSSetConstantBuffers1,
3003 d3d11_immediate_context_DSSetConstantBuffers1,
3004 d3d11_immediate_context_GSSetConstantBuffers1,
3005 d3d11_immediate_context_PSSetConstantBuffers1,
3006 d3d11_immediate_context_CSSetConstantBuffers1,
3007 d3d11_immediate_context_VSGetConstantBuffers1,
3008 d3d11_immediate_context_HSGetConstantBuffers1,
3009 d3d11_immediate_context_DSGetConstantBuffers1,
3010 d3d11_immediate_context_GSGetConstantBuffers1,
3011 d3d11_immediate_context_PSGetConstantBuffers1,
3012 d3d11_immediate_context_CSGetConstantBuffers1,
3013 d3d11_immediate_context_SwapDeviceContextState,
3014 d3d11_immediate_context_ClearView,
3015 d3d11_immediate_context_DiscardView1,
3018 /* ID3D11Multithread methods */
3020 static inline struct d3d11_immediate_context *impl_from_ID3D11Multithread(ID3D11Multithread *iface)
3022 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11Multithread_iface);
3025 static HRESULT STDMETHODCALLTYPE d3d11_multithread_QueryInterface(ID3D11Multithread *iface,
3026 REFIID iid, void **out)
3028 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3030 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
3032 return d3d11_immediate_context_QueryInterface(&context->ID3D11DeviceContext1_iface, iid, out);
3035 static ULONG STDMETHODCALLTYPE d3d11_multithread_AddRef(ID3D11Multithread *iface)
3037 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3039 TRACE("iface %p.\n", iface);
3041 return d3d11_immediate_context_AddRef(&context->ID3D11DeviceContext1_iface);
3044 static ULONG STDMETHODCALLTYPE d3d11_multithread_Release(ID3D11Multithread *iface)
3046 struct d3d11_immediate_context *context = impl_from_ID3D11Multithread(iface);
3048 TRACE("iface %p.\n", iface);
3050 return d3d11_immediate_context_Release(&context->ID3D11DeviceContext1_iface);
3053 static void STDMETHODCALLTYPE d3d11_multithread_Enter(ID3D11Multithread *iface)
3055 TRACE("iface %p.\n", iface);
3057 wined3d_mutex_lock();
3060 static void STDMETHODCALLTYPE d3d11_multithread_Leave(ID3D11Multithread *iface)
3062 TRACE("iface %p.\n", iface);
3064 wined3d_mutex_unlock();
3067 static BOOL STDMETHODCALLTYPE d3d11_multithread_SetMultithreadProtected(
3068 ID3D11Multithread *iface, BOOL enable)
3070 FIXME("iface %p, enable %#x stub!\n", iface, enable);
3072 return TRUE;
3075 static BOOL STDMETHODCALLTYPE d3d11_multithread_GetMultithreadProtected(ID3D11Multithread *iface)
3077 FIXME("iface %p stub!\n", iface);
3079 return TRUE;
3082 static const struct ID3D11MultithreadVtbl d3d11_multithread_vtbl =
3084 d3d11_multithread_QueryInterface,
3085 d3d11_multithread_AddRef,
3086 d3d11_multithread_Release,
3087 d3d11_multithread_Enter,
3088 d3d11_multithread_Leave,
3089 d3d11_multithread_SetMultithreadProtected,
3090 d3d11_multithread_GetMultithreadProtected,
3093 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
3095 context->ID3D11DeviceContext1_iface.lpVtbl = &d3d11_immediate_context_vtbl;
3096 context->ID3D11Multithread_iface.lpVtbl = &d3d11_multithread_vtbl;
3097 context->refcount = 1;
3099 ID3D11Device2_AddRef(&device->ID3D11Device2_iface);
3101 wined3d_private_store_init(&context->private_store);
3104 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
3106 wined3d_private_store_cleanup(&context->private_store);
3109 /* ID3D11Device methods */
3111 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device2 *iface, REFIID iid, void **out)
3113 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3114 return IUnknown_QueryInterface(device->outer_unk, iid, out);
3117 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device2 *iface)
3119 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3120 return IUnknown_AddRef(device->outer_unk);
3123 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device2 *iface)
3125 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3126 return IUnknown_Release(device->outer_unk);
3129 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device2 *iface, const D3D11_BUFFER_DESC *desc,
3130 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
3132 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3133 struct d3d_buffer *object;
3134 HRESULT hr;
3136 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
3138 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
3139 return hr;
3141 *buffer = &object->ID3D11Buffer_iface;
3143 return S_OK;
3146 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device2 *iface,
3147 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
3149 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3150 struct d3d_texture1d *object;
3151 HRESULT hr;
3153 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3155 if (FAILED(hr = d3d_texture1d_create(device, desc, data, &object)))
3156 return hr;
3158 *texture = &object->ID3D11Texture1D_iface;
3160 return S_OK;
3163 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device2 *iface,
3164 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
3166 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3167 struct d3d_texture2d *object;
3168 HRESULT hr;
3170 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3172 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
3173 return hr;
3175 *texture = &object->ID3D11Texture2D_iface;
3177 return S_OK;
3180 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device2 *iface,
3181 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
3183 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3184 struct d3d_texture3d *object;
3185 HRESULT hr;
3187 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
3189 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
3190 return hr;
3192 *texture = &object->ID3D11Texture3D_iface;
3194 return S_OK;
3197 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device2 *iface,
3198 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
3200 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3201 struct d3d_shader_resource_view *object;
3202 HRESULT hr;
3204 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3206 if (!resource)
3207 return E_INVALIDARG;
3209 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
3210 return hr;
3212 *view = &object->ID3D11ShaderResourceView_iface;
3214 return S_OK;
3217 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device2 *iface,
3218 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
3220 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3221 struct d3d11_unordered_access_view *object;
3222 HRESULT hr;
3224 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3226 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
3227 return hr;
3229 *view = &object->ID3D11UnorderedAccessView_iface;
3231 return S_OK;
3234 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device2 *iface,
3235 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
3237 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3238 struct d3d_rendertarget_view *object;
3239 HRESULT hr;
3241 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3243 if (!resource)
3244 return E_INVALIDARG;
3246 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
3247 return hr;
3249 *view = &object->ID3D11RenderTargetView_iface;
3251 return S_OK;
3254 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device2 *iface,
3255 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
3257 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3258 struct d3d_depthstencil_view *object;
3259 HRESULT hr;
3261 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
3263 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
3264 return hr;
3266 *view = &object->ID3D11DepthStencilView_iface;
3268 return S_OK;
3271 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device2 *iface,
3272 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
3273 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
3275 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3276 struct d3d_input_layout *object;
3277 HRESULT hr;
3279 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
3280 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
3281 shader_byte_code_length, input_layout);
3283 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
3284 shader_byte_code, shader_byte_code_length, &object)))
3285 return hr;
3287 *input_layout = &object->ID3D11InputLayout_iface;
3289 return S_OK;
3292 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device2 *iface, const void *byte_code,
3293 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
3295 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3296 struct d3d_vertex_shader *object;
3297 HRESULT hr;
3299 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3300 iface, byte_code, byte_code_length, class_linkage, shader);
3302 if (class_linkage)
3303 FIXME("Class linkage is not implemented yet.\n");
3305 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
3306 return hr;
3308 *shader = &object->ID3D11VertexShader_iface;
3310 return S_OK;
3313 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device2 *iface, const void *byte_code,
3314 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3316 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3317 struct d3d_geometry_shader *object;
3318 HRESULT hr;
3320 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3321 iface, byte_code, byte_code_length, class_linkage, shader);
3323 if (class_linkage)
3324 FIXME("Class linkage is not implemented yet.\n");
3326 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3327 NULL, 0, NULL, 0, 0, &object)))
3328 return hr;
3330 *shader = &object->ID3D11GeometryShader_iface;
3332 return S_OK;
3335 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device2 *iface,
3336 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
3337 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
3338 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
3340 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3341 struct d3d_geometry_shader *object;
3342 HRESULT hr;
3344 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
3345 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
3346 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
3347 rasterizer_stream, class_linkage, shader);
3349 if (class_linkage)
3350 FIXME("Class linkage is not implemented yet.\n");
3352 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
3353 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
3355 *shader = NULL;
3356 return hr;
3359 *shader = &object->ID3D11GeometryShader_iface;
3361 return hr;
3364 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device2 *iface, const void *byte_code,
3365 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
3367 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3368 struct d3d_pixel_shader *object;
3369 HRESULT hr;
3371 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3372 iface, byte_code, byte_code_length, class_linkage, shader);
3374 if (class_linkage)
3375 FIXME("Class linkage is not implemented yet.\n");
3377 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
3378 return hr;
3380 *shader = &object->ID3D11PixelShader_iface;
3382 return S_OK;
3385 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device2 *iface, const void *byte_code,
3386 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
3388 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3389 struct d3d11_hull_shader *object;
3390 HRESULT hr;
3392 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3393 iface, byte_code, byte_code_length, class_linkage, shader);
3395 if (class_linkage)
3396 FIXME("Class linkage is not implemented yet.\n");
3398 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
3399 return hr;
3401 *shader = &object->ID3D11HullShader_iface;
3403 return S_OK;
3406 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device2 *iface, const void *byte_code,
3407 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
3409 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3410 struct d3d11_domain_shader *object;
3411 HRESULT hr;
3413 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3414 iface, byte_code, byte_code_length, class_linkage, shader);
3416 if (class_linkage)
3417 FIXME("Class linkage is not implemented yet.\n");
3419 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3420 return hr;
3422 *shader = &object->ID3D11DomainShader_iface;
3424 return S_OK;
3427 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device2 *iface, const void *byte_code,
3428 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3430 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3431 struct d3d11_compute_shader *object;
3432 HRESULT hr;
3434 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3435 iface, byte_code, byte_code_length, class_linkage, shader);
3437 if (class_linkage)
3438 FIXME("Class linkage is not implemented yet.\n");
3440 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3441 return hr;
3443 *shader = &object->ID3D11ComputeShader_iface;
3445 return S_OK;
3448 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device2 *iface,
3449 ID3D11ClassLinkage **class_linkage)
3451 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3452 struct d3d11_class_linkage *object;
3453 HRESULT hr;
3455 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3457 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3458 return hr;
3460 *class_linkage = &object->ID3D11ClassLinkage_iface;
3462 return S_OK;
3465 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device2 *iface,
3466 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3468 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3469 struct d3d_blend_state *object;
3470 HRESULT hr;
3472 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3474 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3475 return hr;
3477 *blend_state = &object->ID3D11BlendState_iface;
3479 return S_OK;
3482 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device2 *iface,
3483 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3485 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3486 struct d3d_depthstencil_state *object;
3487 HRESULT hr;
3489 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3491 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3492 return hr;
3494 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3496 return S_OK;
3499 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device2 *iface,
3500 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3502 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3503 struct d3d_rasterizer_state *object;
3504 HRESULT hr;
3506 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3508 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3509 return hr;
3511 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3513 return S_OK;
3516 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device2 *iface,
3517 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3519 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3520 struct d3d_sampler_state *object;
3521 HRESULT hr;
3523 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3525 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3526 return hr;
3528 *sampler_state = &object->ID3D11SamplerState_iface;
3530 return S_OK;
3533 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device2 *iface,
3534 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3536 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3537 struct d3d_query *object;
3538 HRESULT hr;
3540 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3542 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3543 return hr;
3545 if (query)
3547 *query = &object->ID3D11Query_iface;
3548 return S_OK;
3551 ID3D11Query_Release(&object->ID3D11Query_iface);
3552 return S_FALSE;
3555 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device2 *iface, const D3D11_QUERY_DESC *desc,
3556 ID3D11Predicate **predicate)
3558 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3559 struct d3d_query *object;
3560 HRESULT hr;
3562 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3564 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3565 return hr;
3567 if (predicate)
3569 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3570 return S_OK;
3573 ID3D11Query_Release(&object->ID3D11Query_iface);
3574 return S_FALSE;
3577 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3578 ID3D11Counter **counter)
3580 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3582 return E_NOTIMPL;
3585 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device2 *iface, UINT flags,
3586 ID3D11DeviceContext **context)
3588 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3590 *context = NULL;
3591 return E_NOTIMPL;
3594 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device2 *iface, HANDLE resource, REFIID iid,
3595 void **out)
3597 FIXME("iface %p, resource %p, iid %s, out %p stub!\n", iface, resource, debugstr_guid(iid), out);
3599 return E_NOTIMPL;
3602 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *iface, DXGI_FORMAT format,
3603 UINT *format_support)
3605 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3606 struct wined3d_device_creation_parameters params;
3607 struct wined3d_adapter *wined3d_adapter;
3608 enum wined3d_format_id wined3d_format;
3609 D3D_FEATURE_LEVEL feature_level;
3610 struct wined3d *wined3d;
3611 unsigned int i;
3613 static const struct
3615 enum wined3d_resource_type rtype;
3616 unsigned int bind_flags;
3617 unsigned int usage;
3618 D3D11_FORMAT_SUPPORT flag;
3620 flag_mapping[] =
3622 {WINED3D_RTYPE_BUFFER, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_BUFFER},
3623 {WINED3D_RTYPE_TEXTURE_1D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE1D},
3624 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3625 {WINED3D_RTYPE_TEXTURE_3D, WINED3D_BIND_SHADER_RESOURCE, 0, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3626 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, 0, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3627 {WINED3D_RTYPE_NONE, WINED3D_BIND_DEPTH_STENCIL, 0, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3628 {WINED3D_RTYPE_NONE, WINED3D_BIND_UNORDERED_ACCESS, 0, D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW},
3629 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_WRAPANDMIP, D3D11_FORMAT_SUPPORT_MIP},
3630 {WINED3D_RTYPE_TEXTURE_2D, WINED3D_BIND_SHADER_RESOURCE, WINED3DUSAGE_QUERY_GENMIPMAP, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN},
3631 {WINED3D_RTYPE_NONE, WINED3D_BIND_RENDER_TARGET, WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3D11_FORMAT_SUPPORT_BLENDABLE},
3633 HRESULT hr;
3635 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3637 wined3d_format = wined3dformat_from_dxgi_format(format);
3638 if (format && !wined3d_format)
3640 WARN("Invalid format %#x.\n", format);
3641 *format_support = 0;
3642 return E_FAIL;
3645 *format_support = 0;
3647 wined3d_mutex_lock();
3648 feature_level = device->state->feature_level;
3649 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3650 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3651 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3652 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3654 hr = wined3d_check_device_format(wined3d, wined3d_adapter, params.device_type,
3655 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].bind_flags, flag_mapping[i].rtype, wined3d_format);
3656 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOMIPGEN)
3657 continue;
3658 if (hr != WINED3D_OK)
3660 WARN("Failed to check device format support, hr %#x.\n", hr);
3661 wined3d_mutex_unlock();
3662 return E_FAIL;
3665 *format_support |= flag_mapping[i].flag;
3667 wined3d_mutex_unlock();
3669 if (feature_level < D3D_FEATURE_LEVEL_10_0)
3670 *format_support &= ~D3D11_FORMAT_SUPPORT_BUFFER;
3672 if (*format_support & (D3D11_FORMAT_SUPPORT_TEXTURE1D
3673 | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D))
3675 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
3676 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
3677 *format_support |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
3679 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3680 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
3682 if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
3684 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
3685 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
3687 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
3688 *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
3692 /* d3d11 requires 4 and 8 sample counts support for formats reported to
3693 * support multisample. */
3694 if (wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3695 TRUE, WINED3D_MULTISAMPLE_4_SAMPLES, NULL) == WINED3D_OK &&
3696 wined3d_check_device_multisample_type(wined3d_adapter, params.device_type, wined3d_format,
3697 TRUE, WINED3D_MULTISAMPLE_8_SAMPLES, NULL) == WINED3D_OK)
3699 *format_support |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE
3700 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
3701 | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD;
3704 return S_OK;
3707 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device2 *iface,
3708 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3710 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3711 struct wined3d_device_creation_parameters params;
3712 struct wined3d_adapter *wined3d_adapter;
3713 struct wined3d *wined3d;
3714 HRESULT hr;
3716 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3717 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3719 if (!quality_level_count)
3720 return E_INVALIDARG;
3722 *quality_level_count = 0;
3724 if (!sample_count)
3725 return E_FAIL;
3726 if (sample_count == 1)
3728 *quality_level_count = 1;
3729 return S_OK;
3731 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3732 return E_FAIL;
3734 wined3d_mutex_lock();
3735 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3736 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3737 wined3d_adapter = wined3d_get_adapter(wined3d, params.adapter_idx);
3738 hr = wined3d_check_device_multisample_type(wined3d_adapter, params.device_type,
3739 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3740 wined3d_mutex_unlock();
3742 if (hr == WINED3DERR_INVALIDCALL)
3743 return E_INVALIDARG;
3744 if (hr == WINED3DERR_NOTAVAILABLE)
3745 return S_OK;
3746 return hr;
3749 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device2 *iface, D3D11_COUNTER_INFO *info)
3751 FIXME("iface %p, info %p stub!\n", iface, info);
3754 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device2 *iface, const D3D11_COUNTER_DESC *desc,
3755 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3756 char *units, UINT *units_length, char *description, UINT *description_length)
3758 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3759 "units %p, units_length %p, description %p, description_length %p stub!\n",
3760 iface, desc, type, active_counter_count, name, name_length,
3761 units, units_length, description, description_length);
3763 return E_NOTIMPL;
3766 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device2 *iface, D3D11_FEATURE feature,
3767 void *feature_support_data, UINT feature_support_data_size)
3769 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3770 struct wined3d_caps wined3d_caps;
3771 HRESULT hr;
3773 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3774 iface, feature, feature_support_data, feature_support_data_size);
3776 switch (feature)
3778 case D3D11_FEATURE_THREADING:
3780 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3781 if (feature_support_data_size != sizeof(*threading_data))
3783 WARN("Invalid data size.\n");
3784 return E_INVALIDARG;
3787 /* We lie about the threading support to make Tomb Raider 2013 and
3788 * Deus Ex: Human Revolution happy. */
3789 FIXME("Returning fake threading support data.\n");
3790 threading_data->DriverConcurrentCreates = TRUE;
3791 threading_data->DriverCommandLists = TRUE;
3792 return S_OK;
3795 case D3D11_FEATURE_DOUBLES:
3797 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3798 if (feature_support_data_size != sizeof(*doubles_data))
3800 WARN("Invalid data size.\n");
3801 return E_INVALIDARG;
3804 wined3d_mutex_lock();
3805 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3806 wined3d_mutex_unlock();
3807 if (FAILED(hr))
3809 WARN("Failed to get device caps, hr %#x.\n", hr);
3810 return hr;
3813 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3814 return S_OK;
3817 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3819 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3820 if (feature_support_data_size != sizeof(*options))
3822 WARN("Invalid data size.\n");
3823 return E_INVALIDARG;
3826 wined3d_mutex_lock();
3827 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3828 wined3d_mutex_unlock();
3829 if (FAILED(hr))
3831 WARN("Failed to get device caps, hr %#x.\n", hr);
3832 return hr;
3835 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x
3836 = wined3d_caps.max_feature_level >= WINED3D_FEATURE_LEVEL_11;
3837 return S_OK;
3840 case D3D11_FEATURE_D3D11_OPTIONS:
3842 D3D11_FEATURE_DATA_D3D11_OPTIONS *options = feature_support_data;
3843 if (feature_support_data_size != sizeof(*options))
3845 WARN("Invalid data size.\n");
3846 return E_INVALIDARG;
3849 FIXME("Returning fake Options support data.\n");
3850 options->OutputMergerLogicOp = FALSE;
3851 options->UAVOnlyRenderingForcedSampleCount = FALSE;
3852 options->DiscardAPIsSeenByDriver = FALSE;
3853 options->FlagsForUpdateAndCopySeenByDriver = FALSE;
3854 options->ClearView = FALSE;
3855 options->CopyWithOverlap = FALSE;
3856 options->ConstantBufferPartialUpdate = FALSE;
3857 options->ConstantBufferOffsetting = FALSE;
3858 options->MapNoOverwriteOnDynamicConstantBuffer = FALSE;
3859 options->MapNoOverwriteOnDynamicBufferSRV = FALSE;
3860 options->MultisampleRTVWithForcedSampleCountOne = FALSE;
3861 options->SAD4ShaderInstructions = FALSE;
3862 options->ExtendedDoublesShaderInstructions = FALSE;
3863 options->ExtendedResourceSharing = FALSE;
3864 return S_OK;
3867 case D3D11_FEATURE_D3D11_OPTIONS1:
3869 D3D11_FEATURE_DATA_D3D11_OPTIONS1 *options = feature_support_data;
3870 if (feature_support_data_size != sizeof(*options))
3872 WARN("Invalid data size.\n");
3873 return E_INVALIDARG;
3876 FIXME("Returning fake Options1 support data.\n");
3877 options->TiledResourcesTier = D3D11_TILED_RESOURCES_NOT_SUPPORTED;
3878 options->MinMaxFiltering = FALSE;
3879 options->ClearViewAlsoSupportsDepthOnlyFormats = FALSE;
3880 options->MapOnDefaultBuffers = FALSE;
3881 return S_OK;
3884 case D3D11_FEATURE_D3D11_OPTIONS3:
3886 D3D11_FEATURE_DATA_D3D11_OPTIONS3 *options = feature_support_data;
3887 if (feature_support_data_size != sizeof(*options))
3889 WARN("Invalid data size.\n");
3890 return E_INVALIDARG;
3893 wined3d_mutex_lock();
3894 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3895 wined3d_mutex_unlock();
3896 if (FAILED(hr))
3898 WARN("Failed to get device caps, hr %#x.\n", hr);
3899 return hr;
3902 options->VPAndRTArrayIndexFromAnyShaderFeedingRasterizer
3903 = wined3d_caps.viewport_array_index_any_shader;
3904 return S_OK;
3907 case D3D11_FEATURE_ARCHITECTURE_INFO:
3909 D3D11_FEATURE_DATA_ARCHITECTURE_INFO *options = feature_support_data;
3910 if (feature_support_data_size != sizeof(*options))
3912 WARN("Invalid data size.\n");
3913 return E_INVALIDARG;
3916 FIXME("Returning fake data architecture info.\n");
3917 options->TileBasedDeferredRenderer = FALSE;
3918 return S_OK;
3921 default:
3922 FIXME("Unhandled feature %#x.\n", feature);
3923 return E_NOTIMPL;
3927 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3928 UINT *data_size, void *data)
3930 IDXGIDevice *dxgi_device;
3931 HRESULT hr;
3933 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3935 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3936 return hr;
3937 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3938 IDXGIDevice_Release(dxgi_device);
3940 return hr;
3943 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device2 *iface, REFGUID guid,
3944 UINT data_size, const void *data)
3946 IDXGIDevice *dxgi_device;
3947 HRESULT hr;
3949 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3951 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3952 return hr;
3953 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3954 IDXGIDevice_Release(dxgi_device);
3956 return hr;
3959 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device2 *iface, REFGUID guid,
3960 const IUnknown *data)
3962 IDXGIDevice *dxgi_device;
3963 HRESULT hr;
3965 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3967 if (FAILED(hr = ID3D11Device2_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3968 return hr;
3969 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3970 IDXGIDevice_Release(dxgi_device);
3972 return hr;
3975 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device2 *iface)
3977 struct d3d_device *device = impl_from_ID3D11Device2(iface);
3979 TRACE("iface %p.\n", iface);
3981 return device->state->feature_level;
3984 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device2 *iface)
3986 FIXME("iface %p stub!\n", iface);
3988 return 0;
3991 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device2 *iface)
3993 WARN("iface %p stub!\n", iface);
3995 return S_OK;
3998 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device2 *iface,
3999 ID3D11DeviceContext **immediate_context)
4001 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4003 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4005 *immediate_context = (ID3D11DeviceContext *)&device->immediate_context.ID3D11DeviceContext1_iface;
4006 ID3D11DeviceContext_AddRef(*immediate_context);
4009 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device2 *iface, UINT flags)
4011 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4013 return E_NOTIMPL;
4016 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device2 *iface)
4018 FIXME("iface %p stub!\n", iface);
4020 return 0;
4023 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext1(ID3D11Device2 *iface,
4024 ID3D11DeviceContext1 **immediate_context)
4026 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4028 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
4030 *immediate_context = &device->immediate_context.ID3D11DeviceContext1_iface;
4031 ID3D11DeviceContext1_AddRef(*immediate_context);
4034 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext1(ID3D11Device2 *iface, UINT flags,
4035 ID3D11DeviceContext1 **context)
4037 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4039 return E_NOTIMPL;
4042 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState1(ID3D11Device2 *iface,
4043 const D3D11_BLEND_DESC1 *desc, ID3D11BlendState1 **state)
4045 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4047 return E_NOTIMPL;
4050 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState1(ID3D11Device2 *iface,
4051 const D3D11_RASTERIZER_DESC1 *desc, ID3D11RasterizerState1 **state)
4053 FIXME("iface %p, desc %p, state %p stub!\n", iface, desc, state);
4055 return E_NOTIMPL;
4058 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeviceContextState(ID3D11Device2 *iface, UINT flags,
4059 const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, UINT sdk_version,
4060 REFIID emulated_interface, D3D_FEATURE_LEVEL *chosen_feature_level, ID3DDeviceContextState **state)
4062 struct d3d_device *device = impl_from_ID3D11Device2(iface);
4063 struct d3d_device_context_state *state_impl;
4064 struct wined3d_state *wined3d_state;
4065 D3D_FEATURE_LEVEL feature_level;
4066 HRESULT hr = E_INVALIDARG;
4068 TRACE("iface %p, flags %#x, feature_levels %p, feature_level_count %u, "
4069 "sdk_version %u, emulated_interface %s, chosen_feature_level %p, state %p.\n",
4070 iface, flags, feature_levels, feature_level_count,
4071 sdk_version, debugstr_guid(emulated_interface), chosen_feature_level, state);
4073 if (flags)
4074 FIXME("Ignoring flags %#x.\n", flags);
4076 wined3d_mutex_lock();
4078 if (!feature_level_count)
4079 goto fail;
4081 if (FAILED(hr = wined3d_state_create(device->wined3d_device,
4082 (const enum wined3d_feature_level *)feature_levels, feature_level_count, &wined3d_state)))
4083 goto fail;
4084 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
4086 if (chosen_feature_level)
4087 *chosen_feature_level = feature_level;
4089 if (!state)
4091 wined3d_state_destroy(wined3d_state);
4092 wined3d_mutex_unlock();
4093 return S_FALSE;
4096 if (!(state_impl = heap_alloc_zero(sizeof(*state_impl))))
4098 wined3d_state_destroy(wined3d_state);
4099 hr = E_OUTOFMEMORY;
4100 goto fail;
4103 d3d_device_context_state_init(state_impl, device, feature_level, emulated_interface);
4104 if (!d3d_device_context_state_add_entry(state_impl, device, wined3d_state))
4106 wined3d_state_destroy(wined3d_state);
4107 ID3DDeviceContextState_Release(&state_impl->ID3DDeviceContextState_iface);
4108 hr = E_FAIL;
4109 goto fail;
4112 *state = &state_impl->ID3DDeviceContextState_iface;
4113 device->d3d11_only = FALSE;
4114 wined3d_mutex_unlock();
4116 return S_OK;
4118 fail:
4119 wined3d_mutex_unlock();
4120 if (chosen_feature_level)
4121 *chosen_feature_level = 0;
4122 if (state)
4123 *state = NULL;
4124 return hr;
4127 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource1(ID3D11Device2 *iface, HANDLE handle,
4128 REFIID iid, void **resource)
4130 FIXME("iface %p, handle %p, iid %s, resource %p stub!\n", iface, handle, debugstr_guid(iid), resource);
4132 return E_NOTIMPL;
4135 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResourceByName(ID3D11Device2 *iface, const WCHAR *name,
4136 DWORD access, REFIID iid, void **resource)
4138 FIXME("iface %p, name %s, access %#x, iid %s, resource %p stub!\n", iface, debugstr_w(name), access,
4139 debugstr_guid(iid), resource);
4141 return E_NOTIMPL;
4144 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext2(ID3D11Device2 *iface,
4145 ID3D11DeviceContext2 **context)
4147 FIXME("iface %p, context %p stub!\n", iface, context);
4150 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext2(ID3D11Device2 *iface,
4151 UINT flags, ID3D11DeviceContext2 **context)
4153 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
4155 return E_NOTIMPL;
4158 static void STDMETHODCALLTYPE d3d11_device_GetResourceTiling(ID3D11Device2 *iface,
4159 ID3D11Resource *resource, UINT *tile_count, D3D11_PACKED_MIP_DESC *mip_desc,
4160 D3D11_TILE_SHAPE *tile_shape, UINT *subresource_tiling_count, UINT first_subresource_tiling,
4161 D3D11_SUBRESOURCE_TILING *subresource_tiling)
4163 FIXME("iface %p, resource %p, tile_count %p, mip_desc %p, tile_shape %p, "
4164 "subresource_tiling_count %p, first_subresource_tiling %u, subresource_tiling %p stub!\n",
4165 iface, resource, tile_count, mip_desc, tile_shape,
4166 subresource_tiling_count, first_subresource_tiling, subresource_tiling);
4169 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels1(ID3D11Device2 *iface,
4170 DXGI_FORMAT format, UINT sample_count, UINT flags, UINT *quality_level_count)
4172 FIXME("iface %p, format %#x, sample_count %u, flags %#x, quality_level_count %p stub!\n",
4173 iface, format, sample_count, flags, quality_level_count);
4175 return E_NOTIMPL;
4178 static const struct ID3D11Device2Vtbl d3d11_device_vtbl =
4180 /* IUnknown methods */
4181 d3d11_device_QueryInterface,
4182 d3d11_device_AddRef,
4183 d3d11_device_Release,
4184 /* ID3D11Device methods */
4185 d3d11_device_CreateBuffer,
4186 d3d11_device_CreateTexture1D,
4187 d3d11_device_CreateTexture2D,
4188 d3d11_device_CreateTexture3D,
4189 d3d11_device_CreateShaderResourceView,
4190 d3d11_device_CreateUnorderedAccessView,
4191 d3d11_device_CreateRenderTargetView,
4192 d3d11_device_CreateDepthStencilView,
4193 d3d11_device_CreateInputLayout,
4194 d3d11_device_CreateVertexShader,
4195 d3d11_device_CreateGeometryShader,
4196 d3d11_device_CreateGeometryShaderWithStreamOutput,
4197 d3d11_device_CreatePixelShader,
4198 d3d11_device_CreateHullShader,
4199 d3d11_device_CreateDomainShader,
4200 d3d11_device_CreateComputeShader,
4201 d3d11_device_CreateClassLinkage,
4202 d3d11_device_CreateBlendState,
4203 d3d11_device_CreateDepthStencilState,
4204 d3d11_device_CreateRasterizerState,
4205 d3d11_device_CreateSamplerState,
4206 d3d11_device_CreateQuery,
4207 d3d11_device_CreatePredicate,
4208 d3d11_device_CreateCounter,
4209 d3d11_device_CreateDeferredContext,
4210 d3d11_device_OpenSharedResource,
4211 d3d11_device_CheckFormatSupport,
4212 d3d11_device_CheckMultisampleQualityLevels,
4213 d3d11_device_CheckCounterInfo,
4214 d3d11_device_CheckCounter,
4215 d3d11_device_CheckFeatureSupport,
4216 d3d11_device_GetPrivateData,
4217 d3d11_device_SetPrivateData,
4218 d3d11_device_SetPrivateDataInterface,
4219 d3d11_device_GetFeatureLevel,
4220 d3d11_device_GetCreationFlags,
4221 d3d11_device_GetDeviceRemovedReason,
4222 d3d11_device_GetImmediateContext,
4223 d3d11_device_SetExceptionMode,
4224 d3d11_device_GetExceptionMode,
4225 /* ID3D11Device1 methods */
4226 d3d11_device_GetImmediateContext1,
4227 d3d11_device_CreateDeferredContext1,
4228 d3d11_device_CreateBlendState1,
4229 d3d11_device_CreateRasterizerState1,
4230 d3d11_device_CreateDeviceContextState,
4231 d3d11_device_OpenSharedResource1,
4232 d3d11_device_OpenSharedResourceByName,
4233 /* ID3D11Device2 methods */
4234 d3d11_device_GetImmediateContext2,
4235 d3d11_device_CreateDeferredContext2,
4236 d3d11_device_GetResourceTiling,
4237 d3d11_device_CheckMultisampleQualityLevels1,
4240 /* Inner IUnknown methods */
4242 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
4244 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
4247 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
4249 struct d3d_device *device = impl_from_IUnknown(iface);
4251 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
4253 if (IsEqualGUID(riid, &IID_ID3D11Device2)
4254 || IsEqualGUID(riid, &IID_ID3D11Device1)
4255 || IsEqualGUID(riid, &IID_ID3D11Device)
4256 || IsEqualGUID(riid, &IID_IUnknown))
4258 *out = &device->ID3D11Device2_iface;
4260 else if (!device->d3d11_only
4261 && (IsEqualGUID(riid, &IID_ID3D10Device1)
4262 || IsEqualGUID(riid, &IID_ID3D10Device)))
4264 *out = &device->ID3D10Device1_iface;
4266 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
4268 *out = &device->ID3D10Multithread_iface;
4270 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
4272 *out = &device->IWineDXGIDeviceParent_iface;
4274 else
4276 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
4277 *out = NULL;
4278 return E_NOINTERFACE;
4281 IUnknown_AddRef((IUnknown *)*out);
4282 return S_OK;
4285 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
4287 struct d3d_device *device = impl_from_IUnknown(iface);
4288 ULONG refcount = InterlockedIncrement(&device->refcount);
4290 TRACE("%p increasing refcount to %u.\n", device, refcount);
4292 return refcount;
4295 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
4297 struct d3d_device *device = impl_from_IUnknown(iface);
4298 ULONG refcount = InterlockedDecrement(&device->refcount);
4299 unsigned int i;
4301 TRACE("%p decreasing refcount to %u.\n", device, refcount);
4303 if (!refcount)
4305 if (device->state)
4306 d3d_device_context_state_private_release(device->state);
4307 for (i = 0; i < device->context_state_count; ++i)
4309 d3d_device_context_state_remove_entry(device->context_states[i], device);
4311 heap_free(device->context_states);
4312 d3d11_immediate_context_destroy(&device->immediate_context);
4313 if (device->wined3d_device)
4315 wined3d_mutex_lock();
4316 wined3d_device_decref(device->wined3d_device);
4317 wined3d_mutex_unlock();
4319 wine_rb_destroy(&device->sampler_states, NULL, NULL);
4320 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
4321 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
4322 wine_rb_destroy(&device->blend_states, NULL, NULL);
4325 return refcount;
4328 /* IUnknown methods */
4330 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID iid,
4331 void **out)
4333 struct d3d_device *device = impl_from_ID3D10Device(iface);
4334 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4337 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
4339 struct d3d_device *device = impl_from_ID3D10Device(iface);
4340 return IUnknown_AddRef(device->outer_unk);
4343 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
4345 struct d3d_device *device = impl_from_ID3D10Device(iface);
4346 return IUnknown_Release(device->outer_unk);
4349 /* ID3D10Device methods */
4351 static void d3d10_device_get_constant_buffers(ID3D10Device1 *iface,
4352 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4354 struct d3d_device *device = impl_from_ID3D10Device(iface);
4355 unsigned int i;
4357 wined3d_mutex_lock();
4358 for (i = 0; i < buffer_count; ++i)
4360 struct wined3d_buffer *wined3d_buffer;
4361 struct d3d_buffer *buffer_impl;
4363 if (!(wined3d_buffer = wined3d_device_get_constant_buffer(device->wined3d_device,
4364 type, start_slot + i)))
4366 buffers[i] = NULL;
4367 continue;
4370 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4371 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4372 ID3D10Buffer_AddRef(buffers[i]);
4374 wined3d_mutex_unlock();
4377 static void d3d10_device_set_constant_buffers(ID3D10Device1 *iface,
4378 enum wined3d_shader_type type, UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4380 struct d3d_device *device = impl_from_ID3D10Device(iface);
4381 unsigned int i;
4383 wined3d_mutex_lock();
4384 for (i = 0; i < buffer_count; ++i)
4386 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
4388 wined3d_device_set_constant_buffer(device->wined3d_device, type, start_slot + i,
4389 buffer ? buffer->wined3d_buffer : NULL);
4391 wined3d_mutex_unlock();
4394 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
4395 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4397 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4398 iface, start_slot, buffer_count, buffers);
4400 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot,
4401 buffer_count, buffers);
4404 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
4405 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4407 struct d3d_device *device = impl_from_ID3D10Device(iface);
4408 unsigned int i;
4410 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4411 iface, start_slot, view_count, views);
4413 wined3d_mutex_lock();
4414 for (i = 0; i < view_count; ++i)
4416 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4418 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
4419 view ? view->wined3d_view : NULL);
4421 wined3d_mutex_unlock();
4424 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
4425 ID3D10PixelShader *shader)
4427 struct d3d_device *device = impl_from_ID3D10Device(iface);
4428 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
4430 TRACE("iface %p, shader %p\n", iface, shader);
4432 wined3d_mutex_lock();
4433 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
4434 wined3d_mutex_unlock();
4437 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
4438 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4440 struct d3d_device *device = impl_from_ID3D10Device(iface);
4441 unsigned int i;
4443 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4444 iface, start_slot, sampler_count, samplers);
4446 wined3d_mutex_lock();
4447 for (i = 0; i < sampler_count; ++i)
4449 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4451 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
4452 sampler ? sampler->wined3d_sampler : NULL);
4454 wined3d_mutex_unlock();
4457 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
4458 ID3D10VertexShader *shader)
4460 struct d3d_device *device = impl_from_ID3D10Device(iface);
4461 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
4463 TRACE("iface %p, shader %p\n", iface, shader);
4465 wined3d_mutex_lock();
4466 wined3d_device_set_vertex_shader(device->wined3d_device, 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_set_base_vertex_index(device->wined3d_device, base_vertex_location);
4480 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
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_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
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_set_vertex_declaration(device->wined3d_device,
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_set_stream_source(device->wined3d_device, 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_set_index_buffer(device->wined3d_device,
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_set_base_vertex_index(device->wined3d_device, base_vertex_location);
4570 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
4571 instance_index_count, start_instance_location, instance_count);
4572 wined3d_mutex_unlock();
4575 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
4576 UINT instance_vertex_count, UINT instance_count,
4577 UINT start_vertex_location, UINT start_instance_location)
4579 struct d3d_device *device = impl_from_ID3D10Device(iface);
4581 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
4582 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
4583 start_vertex_location, start_instance_location);
4585 wined3d_mutex_lock();
4586 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
4587 instance_vertex_count, start_instance_location, instance_count);
4588 wined3d_mutex_unlock();
4591 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
4592 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
4594 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4595 iface, start_slot, buffer_count, buffers);
4597 d3d10_device_set_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot,
4598 buffer_count, buffers);
4601 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
4603 struct d3d_device *device = impl_from_ID3D10Device(iface);
4604 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
4606 TRACE("iface %p, shader %p.\n", iface, shader);
4608 wined3d_mutex_lock();
4609 wined3d_device_set_geometry_shader(device->wined3d_device, 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_set_vs_resource_view(device->wined3d_device, start_slot + i,
4640 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_set_vs_sampler(device->wined3d_device, start_slot + i,
4660 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_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
4675 wined3d_mutex_unlock();
4678 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4679 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4681 struct d3d_device *device = impl_from_ID3D10Device(iface);
4682 unsigned int i;
4684 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4685 iface, start_slot, view_count, views);
4687 wined3d_mutex_lock();
4688 for (i = 0; i < view_count; ++i)
4690 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4692 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
4693 view ? view->wined3d_view : NULL);
4695 wined3d_mutex_unlock();
4698 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4699 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4701 struct d3d_device *device = impl_from_ID3D10Device(iface);
4702 unsigned int i;
4704 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4705 iface, start_slot, sampler_count, samplers);
4707 wined3d_mutex_lock();
4708 for (i = 0; i < sampler_count; ++i)
4710 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4712 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
4713 sampler ? sampler->wined3d_sampler : NULL);
4715 wined3d_mutex_unlock();
4718 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4719 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4720 ID3D10DepthStencilView *depth_stencil_view)
4722 struct d3d_device *device = impl_from_ID3D10Device(iface);
4723 struct d3d_depthstencil_view *dsv;
4724 unsigned int i;
4726 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4727 iface, render_target_view_count, render_target_views, depth_stencil_view);
4729 wined3d_mutex_lock();
4730 for (i = 0; i < render_target_view_count; ++i)
4732 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4734 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
4735 rtv ? rtv->wined3d_view : NULL, FALSE);
4737 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4739 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4742 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4743 wined3d_device_set_depth_stencil_view(device->wined3d_device,
4744 dsv ? dsv->wined3d_view : NULL);
4745 wined3d_mutex_unlock();
4748 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4749 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4751 struct d3d_device *device = impl_from_ID3D10Device(iface);
4752 struct d3d_blend_state *blend_state_object;
4754 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4755 iface, blend_state, debug_float4(blend_factor), sample_mask);
4757 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4758 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
4759 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4762 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4763 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4765 struct d3d_device *device = impl_from_ID3D10Device(iface);
4766 struct d3d_depthstencil_state *ds_state_object;
4768 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4769 iface, depth_stencil_state, stencil_ref);
4771 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4772 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
4773 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4776 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4777 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4779 struct d3d_device *device = impl_from_ID3D10Device(iface);
4780 unsigned int count, i;
4782 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4784 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4785 wined3d_mutex_lock();
4786 for (i = 0; i < count; ++i)
4788 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4790 wined3d_device_set_stream_output(device->wined3d_device, i,
4791 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4794 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4796 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4798 wined3d_mutex_unlock();
4801 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4803 FIXME("iface %p stub!\n", iface);
4806 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4808 struct d3d_device *device = impl_from_ID3D10Device(iface);
4809 struct d3d_rasterizer_state *rasterizer_state_object;
4811 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4813 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4814 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext1_iface,
4815 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4818 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4819 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4821 struct d3d_device *device = impl_from_ID3D10Device(iface);
4822 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
4823 unsigned int i;
4825 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4827 if (viewport_count > ARRAY_SIZE(wined3d_vp))
4828 return;
4830 for (i = 0; i < viewport_count; ++i)
4832 wined3d_vp[i].x = viewports[i].TopLeftX;
4833 wined3d_vp[i].y = viewports[i].TopLeftY;
4834 wined3d_vp[i].width = viewports[i].Width;
4835 wined3d_vp[i].height = viewports[i].Height;
4836 wined3d_vp[i].min_z = viewports[i].MinDepth;
4837 wined3d_vp[i].max_z = viewports[i].MaxDepth;
4840 wined3d_mutex_lock();
4841 wined3d_device_set_viewports(device->wined3d_device, viewport_count, wined3d_vp);
4842 wined3d_mutex_unlock();
4845 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4846 UINT rect_count, const D3D10_RECT *rects)
4848 struct d3d_device *device = impl_from_ID3D10Device(iface);
4850 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4852 if (rect_count > WINED3D_MAX_VIEWPORTS)
4853 return;
4855 wined3d_mutex_lock();
4856 wined3d_device_set_scissor_rects(device->wined3d_device, rect_count, rects);
4857 wined3d_mutex_unlock();
4860 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4861 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4862 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4864 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4865 struct d3d_device *device = impl_from_ID3D10Device(iface);
4866 struct wined3d_box wined3d_src_box;
4868 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4869 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4870 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4871 src_resource, src_subresource_idx, src_box);
4873 if (!dst_resource || !src_resource)
4874 return;
4876 if (src_box)
4877 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4878 src_box->right, src_box->bottom, src_box->front, src_box->back);
4880 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4881 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4882 wined3d_mutex_lock();
4883 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
4884 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL, 0);
4885 wined3d_mutex_unlock();
4888 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4889 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4891 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4892 struct d3d_device *device = impl_from_ID3D10Device(iface);
4894 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4896 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4897 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4898 wined3d_mutex_lock();
4899 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
4900 wined3d_mutex_unlock();
4903 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4904 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4905 const void *data, UINT row_pitch, UINT depth_pitch)
4907 struct d3d_device *device = impl_from_ID3D10Device(iface);
4908 ID3D11Resource *d3d11_resource;
4910 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4911 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4913 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4914 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext1_iface,
4915 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4916 ID3D11Resource_Release(d3d11_resource);
4919 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4920 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4922 struct d3d_device *device = impl_from_ID3D10Device(iface);
4923 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4924 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4925 HRESULT hr;
4927 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4928 iface, render_target_view, debug_float4(color_rgba));
4930 if (!view)
4931 return;
4933 wined3d_mutex_lock();
4934 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4935 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4936 ERR("Failed to clear view, hr %#x.\n", hr);
4937 wined3d_mutex_unlock();
4940 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4941 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4943 struct d3d_device *device = impl_from_ID3D10Device(iface);
4944 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4945 DWORD wined3d_flags;
4946 HRESULT hr;
4948 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4949 iface, depth_stencil_view, flags, depth, stencil);
4951 if (!view)
4952 return;
4954 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4956 wined3d_mutex_lock();
4957 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4958 wined3d_flags, NULL, depth, stencil)))
4959 ERR("Failed to clear view, hr %#x.\n", hr);
4960 wined3d_mutex_unlock();
4963 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4964 ID3D10ShaderResourceView *view)
4966 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
4968 TRACE("iface %p, view %p.\n", iface, view);
4970 wined3d_mutex_lock();
4971 wined3d_shader_resource_view_generate_mipmaps(srv->wined3d_view);
4972 wined3d_mutex_unlock();
4975 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4976 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4977 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4979 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4980 struct d3d_device *device = impl_from_ID3D10Device(iface);
4981 enum wined3d_format_id wined3d_format;
4983 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, "
4984 "src_resource %p, src_subresource_idx %u, format %s.\n",
4985 iface, dst_resource, dst_subresource_idx,
4986 src_resource, src_subresource_idx, debug_dxgi_format(format));
4988 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4989 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4990 wined3d_format = wined3dformat_from_dxgi_format(format);
4991 wined3d_mutex_lock();
4992 wined3d_device_resolve_sub_resource(device->wined3d_device,
4993 wined3d_dst_resource, dst_subresource_idx,
4994 wined3d_src_resource, src_subresource_idx, wined3d_format);
4995 wined3d_mutex_unlock();
4998 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
4999 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5001 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5002 iface, start_slot, buffer_count, buffers);
5004 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_VERTEX, start_slot, buffer_count,
5005 buffers);
5008 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
5009 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5011 struct d3d_device *device = impl_from_ID3D10Device(iface);
5012 unsigned int i;
5014 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5015 iface, start_slot, view_count, views);
5017 wined3d_mutex_lock();
5018 for (i = 0; i < view_count; ++i)
5020 struct wined3d_shader_resource_view *wined3d_view;
5021 struct d3d_shader_resource_view *view_impl;
5023 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
5025 views[i] = NULL;
5026 continue;
5029 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5030 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5031 ID3D10ShaderResourceView_AddRef(views[i]);
5033 wined3d_mutex_unlock();
5036 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
5038 struct d3d_device *device = impl_from_ID3D10Device(iface);
5039 struct d3d_pixel_shader *shader_impl;
5040 struct wined3d_shader *wined3d_shader;
5042 TRACE("iface %p, shader %p.\n", iface, shader);
5044 wined3d_mutex_lock();
5045 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
5047 wined3d_mutex_unlock();
5048 *shader = NULL;
5049 return;
5052 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5053 wined3d_mutex_unlock();
5054 *shader = &shader_impl->ID3D10PixelShader_iface;
5055 ID3D10PixelShader_AddRef(*shader);
5058 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
5059 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5061 struct d3d_device *device = impl_from_ID3D10Device(iface);
5062 unsigned int i;
5064 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5065 iface, start_slot, sampler_count, samplers);
5067 wined3d_mutex_lock();
5068 for (i = 0; i < sampler_count; ++i)
5070 struct d3d_sampler_state *sampler_impl;
5071 struct wined3d_sampler *wined3d_sampler;
5073 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
5075 samplers[i] = NULL;
5076 continue;
5079 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5080 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5081 ID3D10SamplerState_AddRef(samplers[i]);
5083 wined3d_mutex_unlock();
5086 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
5088 struct d3d_device *device = impl_from_ID3D10Device(iface);
5089 struct d3d_vertex_shader *shader_impl;
5090 struct wined3d_shader *wined3d_shader;
5092 TRACE("iface %p, shader %p.\n", iface, shader);
5094 wined3d_mutex_lock();
5095 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
5097 wined3d_mutex_unlock();
5098 *shader = NULL;
5099 return;
5102 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5103 wined3d_mutex_unlock();
5104 *shader = &shader_impl->ID3D10VertexShader_iface;
5105 ID3D10VertexShader_AddRef(*shader);
5108 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
5109 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5111 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5112 iface, start_slot, buffer_count, buffers);
5114 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_PIXEL, start_slot, buffer_count,
5115 buffers);
5118 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
5120 struct d3d_device *device = impl_from_ID3D10Device(iface);
5121 struct wined3d_vertex_declaration *wined3d_declaration;
5122 struct d3d_input_layout *input_layout_impl;
5124 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
5126 wined3d_mutex_lock();
5127 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
5129 wined3d_mutex_unlock();
5130 *input_layout = NULL;
5131 return;
5134 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
5135 wined3d_mutex_unlock();
5136 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
5137 ID3D10InputLayout_AddRef(*input_layout);
5140 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
5141 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
5143 struct d3d_device *device = impl_from_ID3D10Device(iface);
5144 unsigned int i;
5146 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
5147 iface, start_slot, buffer_count, buffers, strides, offsets);
5149 wined3d_mutex_lock();
5150 for (i = 0; i < buffer_count; ++i)
5152 struct wined3d_buffer *wined3d_buffer = NULL;
5153 struct d3d_buffer *buffer_impl;
5155 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
5156 &wined3d_buffer, &offsets[i], &strides[i])))
5157 ERR("Failed to get vertex buffer.\n");
5159 if (!wined3d_buffer)
5161 buffers[i] = NULL;
5162 continue;
5165 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5166 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5167 ID3D10Buffer_AddRef(buffers[i]);
5169 wined3d_mutex_unlock();
5172 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
5173 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
5175 struct d3d_device *device = impl_from_ID3D10Device(iface);
5176 enum wined3d_format_id wined3d_format;
5177 struct wined3d_buffer *wined3d_buffer;
5178 struct d3d_buffer *buffer_impl;
5180 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
5182 wined3d_mutex_lock();
5183 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
5184 *format = dxgi_format_from_wined3dformat(wined3d_format);
5185 if (!wined3d_buffer)
5187 wined3d_mutex_unlock();
5188 *buffer = NULL;
5189 return;
5192 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5193 wined3d_mutex_unlock();
5194 *buffer = &buffer_impl->ID3D10Buffer_iface;
5195 ID3D10Buffer_AddRef(*buffer);
5198 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
5199 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
5201 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
5202 iface, start_slot, buffer_count, buffers);
5204 d3d10_device_get_constant_buffers(iface, WINED3D_SHADER_TYPE_GEOMETRY, start_slot, buffer_count,
5205 buffers);
5208 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
5210 struct d3d_device *device = impl_from_ID3D10Device(iface);
5211 struct d3d_geometry_shader *shader_impl;
5212 struct wined3d_shader *wined3d_shader;
5214 TRACE("iface %p, shader %p.\n", iface, shader);
5216 wined3d_mutex_lock();
5217 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
5219 wined3d_mutex_unlock();
5220 *shader = NULL;
5221 return;
5224 shader_impl = wined3d_shader_get_parent(wined3d_shader);
5225 wined3d_mutex_unlock();
5226 *shader = &shader_impl->ID3D10GeometryShader_iface;
5227 ID3D10GeometryShader_AddRef(*shader);
5230 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
5231 D3D10_PRIMITIVE_TOPOLOGY *topology)
5233 struct d3d_device *device = impl_from_ID3D10Device(iface);
5235 TRACE("iface %p, topology %p.\n", iface, topology);
5237 wined3d_mutex_lock();
5238 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology, NULL);
5239 wined3d_mutex_unlock();
5242 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
5243 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5245 struct d3d_device *device = impl_from_ID3D10Device(iface);
5246 unsigned int i;
5248 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5249 iface, start_slot, view_count, views);
5251 wined3d_mutex_lock();
5252 for (i = 0; i < view_count; ++i)
5254 struct wined3d_shader_resource_view *wined3d_view;
5255 struct d3d_shader_resource_view *view_impl;
5257 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
5259 views[i] = NULL;
5260 continue;
5263 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5264 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5265 ID3D10ShaderResourceView_AddRef(views[i]);
5267 wined3d_mutex_unlock();
5270 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
5271 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5273 struct d3d_device *device = impl_from_ID3D10Device(iface);
5274 unsigned int i;
5276 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5277 iface, start_slot, sampler_count, samplers);
5279 wined3d_mutex_lock();
5280 for (i = 0; i < sampler_count; ++i)
5282 struct d3d_sampler_state *sampler_impl;
5283 struct wined3d_sampler *wined3d_sampler;
5285 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
5287 samplers[i] = NULL;
5288 continue;
5291 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5292 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5293 ID3D10SamplerState_AddRef(samplers[i]);
5295 wined3d_mutex_unlock();
5298 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
5299 ID3D10Predicate **predicate, BOOL *value)
5301 struct d3d_device *device = impl_from_ID3D10Device(iface);
5302 struct wined3d_query *wined3d_predicate;
5303 struct d3d_query *predicate_impl;
5305 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
5307 wined3d_mutex_lock();
5308 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
5310 wined3d_mutex_unlock();
5311 *predicate = NULL;
5312 return;
5315 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
5316 wined3d_mutex_unlock();
5317 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
5318 ID3D10Predicate_AddRef(*predicate);
5321 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
5322 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
5324 struct d3d_device *device = impl_from_ID3D10Device(iface);
5325 unsigned int i;
5327 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
5328 iface, start_slot, view_count, views);
5330 wined3d_mutex_lock();
5331 for (i = 0; i < view_count; ++i)
5333 struct wined3d_shader_resource_view *wined3d_view;
5334 struct d3d_shader_resource_view *view_impl;
5336 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
5338 views[i] = NULL;
5339 continue;
5342 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
5343 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
5344 ID3D10ShaderResourceView_AddRef(views[i]);
5346 wined3d_mutex_unlock();
5349 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
5350 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
5352 struct d3d_device *device = impl_from_ID3D10Device(iface);
5353 unsigned int i;
5355 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
5356 iface, start_slot, sampler_count, samplers);
5358 wined3d_mutex_lock();
5359 for (i = 0; i < sampler_count; ++i)
5361 struct d3d_sampler_state *sampler_impl;
5362 struct wined3d_sampler *wined3d_sampler;
5364 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
5366 samplers[i] = NULL;
5367 continue;
5370 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
5371 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
5372 ID3D10SamplerState_AddRef(samplers[i]);
5374 wined3d_mutex_unlock();
5377 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
5378 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
5380 struct d3d_device *device = impl_from_ID3D10Device(iface);
5381 struct wined3d_rendertarget_view *wined3d_view;
5383 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
5384 iface, view_count, render_target_views, depth_stencil_view);
5386 wined3d_mutex_lock();
5387 if (render_target_views)
5389 struct d3d_rendertarget_view *view_impl;
5390 unsigned int i;
5392 for (i = 0; i < view_count; ++i)
5394 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
5395 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5397 render_target_views[i] = NULL;
5398 continue;
5401 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
5402 ID3D10RenderTargetView_AddRef(render_target_views[i]);
5406 if (depth_stencil_view)
5408 struct d3d_depthstencil_view *view_impl;
5410 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
5411 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
5413 *depth_stencil_view = NULL;
5415 else
5417 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
5418 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
5421 wined3d_mutex_unlock();
5424 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
5425 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
5427 struct d3d_device *device = impl_from_ID3D10Device(iface);
5428 ID3D11BlendState *d3d11_blend_state;
5430 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
5431 iface, blend_state, blend_factor, sample_mask);
5433 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext1_iface,
5434 &d3d11_blend_state, blend_factor, sample_mask);
5436 if (d3d11_blend_state)
5437 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
5438 else
5439 *blend_state = NULL;
5442 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
5443 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
5445 struct d3d_device *device = impl_from_ID3D10Device(iface);
5446 ID3D11DepthStencilState *d3d11_iface;
5448 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
5449 iface, depth_stencil_state, stencil_ref);
5451 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext1_iface,
5452 &d3d11_iface, stencil_ref);
5454 if (d3d11_iface)
5455 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
5456 else
5457 *depth_stencil_state = NULL;
5460 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
5461 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
5463 struct d3d_device *device = impl_from_ID3D10Device(iface);
5464 unsigned int i;
5466 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
5467 iface, buffer_count, buffers, offsets);
5469 wined3d_mutex_lock();
5470 for (i = 0; i < buffer_count; ++i)
5472 struct wined3d_buffer *wined3d_buffer;
5473 struct d3d_buffer *buffer_impl;
5475 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
5477 buffers[i] = NULL;
5478 continue;
5481 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
5482 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
5483 ID3D10Buffer_AddRef(buffers[i]);
5485 wined3d_mutex_unlock();
5488 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
5490 struct d3d_device *device = impl_from_ID3D10Device(iface);
5491 struct d3d_rasterizer_state *rasterizer_state_impl;
5492 struct wined3d_rasterizer_state *wined3d_state;
5494 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
5496 wined3d_mutex_lock();
5497 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
5499 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
5500 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
5502 else
5504 *rasterizer_state = NULL;
5506 wined3d_mutex_unlock();
5509 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
5510 UINT *viewport_count, D3D10_VIEWPORT *viewports)
5512 struct d3d_device *device = impl_from_ID3D10Device(iface);
5513 struct wined3d_viewport wined3d_vp[WINED3D_MAX_VIEWPORTS];
5514 unsigned int actual_count = ARRAY_SIZE(wined3d_vp), i;
5516 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
5518 if (!viewport_count)
5519 return;
5521 wined3d_mutex_lock();
5522 wined3d_device_get_viewports(device->wined3d_device, &actual_count, viewports ? wined3d_vp : NULL);
5523 wined3d_mutex_unlock();
5525 if (!viewports)
5527 *viewport_count = actual_count;
5528 return;
5531 if (*viewport_count > actual_count)
5532 memset(&viewports[actual_count], 0, (*viewport_count - actual_count) * sizeof(*viewports));
5534 *viewport_count = min(actual_count, *viewport_count);
5535 for (i = 0; i < *viewport_count; ++i)
5537 viewports[i].TopLeftX = wined3d_vp[i].x;
5538 viewports[i].TopLeftY = wined3d_vp[i].y;
5539 viewports[i].Width = wined3d_vp[i].width;
5540 viewports[i].Height = wined3d_vp[i].height;
5541 viewports[i].MinDepth = wined3d_vp[i].min_z;
5542 viewports[i].MaxDepth = wined3d_vp[i].max_z;
5546 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
5548 struct d3d_device *device = impl_from_ID3D10Device(iface);
5549 unsigned int actual_count;
5551 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
5553 if (!rect_count)
5554 return;
5556 actual_count = *rect_count;
5558 wined3d_mutex_lock();
5559 wined3d_device_get_scissor_rects(device->wined3d_device, &actual_count, rects);
5560 wined3d_mutex_unlock();
5562 if (!rects)
5564 *rect_count = actual_count;
5565 return;
5568 if (*rect_count > actual_count)
5569 memset(&rects[actual_count], 0, (*rect_count - actual_count) * sizeof(*rects));
5572 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
5574 TRACE("iface %p.\n", iface);
5576 /* In the current implementation the device is never removed, so we can
5577 * just return S_OK here. */
5579 return S_OK;
5582 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
5584 FIXME("iface %p, flags %#x stub!\n", iface, flags);
5586 return E_NOTIMPL;
5589 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5591 FIXME("iface %p stub!\n", iface);
5593 return 0;
5596 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5597 REFGUID guid, UINT *data_size, void *data)
5599 struct d3d_device *device = impl_from_ID3D10Device(iface);
5601 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5603 return d3d11_device_GetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5606 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5607 REFGUID guid, UINT data_size, const void *data)
5609 struct d3d_device *device = impl_from_ID3D10Device(iface);
5611 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5613 return d3d11_device_SetPrivateData(&device->ID3D11Device2_iface, guid, data_size, data);
5616 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5617 REFGUID guid, const IUnknown *data)
5619 struct d3d_device *device = impl_from_ID3D10Device(iface);
5621 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5623 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device2_iface, guid, data);
5626 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5628 struct d3d_device *device = impl_from_ID3D10Device(iface);
5630 TRACE("iface %p.\n", iface);
5632 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext1_iface);
5635 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5637 struct d3d_device *device = impl_from_ID3D10Device(iface);
5639 TRACE("iface %p.\n", iface);
5641 wined3d_mutex_lock();
5642 wined3d_device_flush(device->wined3d_device);
5643 wined3d_mutex_unlock();
5646 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5647 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5649 struct d3d_device *device = impl_from_ID3D10Device(iface);
5650 D3D11_BUFFER_DESC d3d11_desc;
5651 struct d3d_buffer *object;
5652 HRESULT hr;
5654 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5656 d3d11_desc.ByteWidth = desc->ByteWidth;
5657 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5658 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5659 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5660 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5661 d3d11_desc.StructureByteStride = 0;
5663 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5664 return hr;
5666 *buffer = &object->ID3D10Buffer_iface;
5668 return S_OK;
5671 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5672 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5674 struct d3d_device *device = impl_from_ID3D10Device(iface);
5675 D3D11_TEXTURE1D_DESC d3d11_desc;
5676 struct d3d_texture1d *object;
5677 HRESULT hr;
5679 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5681 d3d11_desc.Width = desc->Width;
5682 d3d11_desc.MipLevels = desc->MipLevels;
5683 d3d11_desc.ArraySize = desc->ArraySize;
5684 d3d11_desc.Format = desc->Format;
5685 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5686 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5687 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5688 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5690 if (FAILED(hr = d3d_texture1d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5691 return hr;
5693 *texture = &object->ID3D10Texture1D_iface;
5695 return S_OK;
5698 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5699 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5700 ID3D10Texture2D **texture)
5702 struct d3d_device *device = impl_from_ID3D10Device(iface);
5703 D3D11_TEXTURE2D_DESC d3d11_desc;
5704 struct d3d_texture2d *object;
5705 HRESULT hr;
5707 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5709 d3d11_desc.Width = desc->Width;
5710 d3d11_desc.Height = desc->Height;
5711 d3d11_desc.MipLevels = desc->MipLevels;
5712 d3d11_desc.ArraySize = desc->ArraySize;
5713 d3d11_desc.Format = desc->Format;
5714 d3d11_desc.SampleDesc = desc->SampleDesc;
5715 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5716 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5717 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5718 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5720 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5721 return hr;
5723 *texture = &object->ID3D10Texture2D_iface;
5725 return S_OK;
5728 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5729 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5730 ID3D10Texture3D **texture)
5732 struct d3d_device *device = impl_from_ID3D10Device(iface);
5733 D3D11_TEXTURE3D_DESC d3d11_desc;
5734 struct d3d_texture3d *object;
5735 HRESULT hr;
5737 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5739 d3d11_desc.Width = desc->Width;
5740 d3d11_desc.Height = desc->Height;
5741 d3d11_desc.Depth = desc->Depth;
5742 d3d11_desc.MipLevels = desc->MipLevels;
5743 d3d11_desc.Format = desc->Format;
5744 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5745 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5746 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5747 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5749 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5750 return hr;
5752 *texture = &object->ID3D10Texture3D_iface;
5754 return S_OK;
5757 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5758 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5760 struct d3d_device *device = impl_from_ID3D10Device(iface);
5761 struct d3d_shader_resource_view *object;
5762 ID3D11Resource *d3d11_resource;
5763 HRESULT hr;
5765 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5767 if (!resource)
5768 return E_INVALIDARG;
5770 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5772 ERR("Resource does not implement ID3D11Resource.\n");
5773 return E_FAIL;
5776 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5777 &object);
5778 ID3D11Resource_Release(d3d11_resource);
5779 if (FAILED(hr))
5780 return hr;
5782 *view = &object->ID3D10ShaderResourceView1_iface;
5784 return S_OK;
5787 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5788 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5790 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5792 return d3d10_device_CreateShaderResourceView1(iface, resource,
5793 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5796 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5797 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5799 struct d3d_device *device = impl_from_ID3D10Device(iface);
5800 struct d3d_rendertarget_view *object;
5801 ID3D11Resource *d3d11_resource;
5802 HRESULT hr;
5804 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5806 if (!resource)
5807 return E_INVALIDARG;
5809 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5811 ERR("Resource does not implement ID3D11Resource.\n");
5812 return E_FAIL;
5815 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5816 ID3D11Resource_Release(d3d11_resource);
5817 if (FAILED(hr))
5818 return hr;
5820 *view = &object->ID3D10RenderTargetView_iface;
5822 return S_OK;
5825 static D3D11_DSV_DIMENSION d3d11_dsv_dimension_from_d3d10(D3D10_DSV_DIMENSION dim)
5827 return (D3D11_DSV_DIMENSION)dim;
5830 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5831 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5833 struct d3d_device *device = impl_from_ID3D10Device(iface);
5834 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5835 struct d3d_depthstencil_view *object;
5836 ID3D11Resource *d3d11_resource;
5837 HRESULT hr;
5839 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5841 if (desc)
5843 d3d11_desc.Format = desc->Format;
5844 d3d11_desc.ViewDimension = d3d11_dsv_dimension_from_d3d10(desc->ViewDimension);
5845 d3d11_desc.Flags = 0;
5846 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5849 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5851 ERR("Resource does not implement ID3D11Resource.\n");
5852 return E_FAIL;
5855 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5856 ID3D11Resource_Release(d3d11_resource);
5857 if (FAILED(hr))
5858 return hr;
5860 *view = &object->ID3D10DepthStencilView_iface;
5862 return S_OK;
5865 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5866 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5867 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5868 ID3D10InputLayout **input_layout)
5870 struct d3d_device *device = impl_from_ID3D10Device(iface);
5871 struct d3d_input_layout *object;
5872 HRESULT hr;
5874 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5875 "shader_byte_code_length %lu, input_layout %p\n",
5876 iface, element_descs, element_count, shader_byte_code,
5877 shader_byte_code_length, input_layout);
5879 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5880 shader_byte_code, shader_byte_code_length, &object)))
5881 return hr;
5883 *input_layout = &object->ID3D10InputLayout_iface;
5885 return S_OK;
5888 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5889 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5891 struct d3d_device *device = impl_from_ID3D10Device(iface);
5892 struct d3d_vertex_shader *object;
5893 HRESULT hr;
5895 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5896 iface, byte_code, byte_code_length, shader);
5898 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5899 return hr;
5901 *shader = &object->ID3D10VertexShader_iface;
5903 return S_OK;
5906 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5907 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5909 struct d3d_device *device = impl_from_ID3D10Device(iface);
5910 struct d3d_geometry_shader *object;
5911 HRESULT hr;
5913 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5914 iface, byte_code, byte_code_length, shader);
5916 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5917 NULL, 0, NULL, 0, 0, &object)))
5918 return hr;
5920 *shader = &object->ID3D10GeometryShader_iface;
5922 return S_OK;
5925 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5926 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5927 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5929 struct d3d_device *device = impl_from_ID3D10Device(iface);
5930 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5931 struct d3d_geometry_shader *object;
5932 unsigned int i, stride_count = 1;
5933 HRESULT hr;
5935 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5936 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5937 iface, byte_code, byte_code_length, output_stream_decls,
5938 output_stream_decl_count, output_stream_stride, shader);
5940 if (!output_stream_decl_count && output_stream_stride)
5942 WARN("Stride must be 0 when declaration entry count is 0.\n");
5943 *shader = NULL;
5944 return E_INVALIDARG;
5947 if (output_stream_decl_count
5948 && !(so_entries = heap_calloc(output_stream_decl_count, sizeof(*so_entries))))
5950 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5951 *shader = NULL;
5952 return E_OUTOFMEMORY;
5955 for (i = 0; i < output_stream_decl_count; ++i)
5957 so_entries[i].Stream = 0;
5958 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5959 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5960 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5961 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5962 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5964 if (output_stream_decls[i].OutputSlot)
5966 stride_count = 0;
5967 if (output_stream_stride)
5969 WARN("Stride must be 0 when multiple output slots are used.\n");
5970 heap_free(so_entries);
5971 *shader = NULL;
5972 return E_INVALIDARG;
5977 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5978 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5979 heap_free(so_entries);
5980 if (FAILED(hr))
5982 *shader = NULL;
5983 return hr;
5986 *shader = &object->ID3D10GeometryShader_iface;
5988 return hr;
5991 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5992 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5994 struct d3d_device *device = impl_from_ID3D10Device(iface);
5995 struct d3d_pixel_shader *object;
5996 HRESULT hr;
5998 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5999 iface, byte_code, byte_code_length, shader);
6001 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
6002 return hr;
6004 *shader = &object->ID3D10PixelShader_iface;
6006 return S_OK;
6009 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
6010 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
6012 struct d3d_device *device = impl_from_ID3D10Device(iface);
6013 struct d3d_blend_state *object;
6014 HRESULT hr;
6016 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6018 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
6019 return hr;
6021 *blend_state = &object->ID3D10BlendState1_iface;
6023 return S_OK;
6026 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
6027 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
6029 D3D10_BLEND_DESC1 d3d10_1_desc;
6030 unsigned int i;
6032 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
6034 if (!desc)
6035 return E_INVALIDARG;
6037 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
6038 d3d10_1_desc.IndependentBlendEnable = FALSE;
6039 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
6041 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
6042 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
6043 d3d10_1_desc.IndependentBlendEnable = TRUE;
6046 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
6048 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
6049 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
6050 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
6051 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
6052 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
6053 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
6054 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
6055 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
6058 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
6061 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
6062 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
6064 struct d3d_device *device = impl_from_ID3D10Device(iface);
6065 struct d3d_depthstencil_state *object;
6066 HRESULT hr;
6068 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
6070 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
6071 return hr;
6073 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
6075 return S_OK;
6078 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
6079 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
6081 struct d3d_device *device = impl_from_ID3D10Device(iface);
6082 struct d3d_rasterizer_state *object;
6083 HRESULT hr;
6085 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
6087 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
6088 return hr;
6090 *rasterizer_state = &object->ID3D10RasterizerState_iface;
6092 return S_OK;
6095 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
6096 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
6098 struct d3d_device *device = impl_from_ID3D10Device(iface);
6099 struct d3d_sampler_state *object;
6100 HRESULT hr;
6102 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
6104 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
6105 return hr;
6107 *sampler_state = &object->ID3D10SamplerState_iface;
6109 return S_OK;
6112 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
6113 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
6115 struct d3d_device *device = impl_from_ID3D10Device(iface);
6116 struct d3d_query *object;
6117 HRESULT hr;
6119 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
6121 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
6122 return hr;
6124 if (query)
6126 *query = &object->ID3D10Query_iface;
6127 return S_OK;
6130 ID3D10Query_Release(&object->ID3D10Query_iface);
6131 return S_FALSE;
6134 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
6135 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
6137 struct d3d_device *device = impl_from_ID3D10Device(iface);
6138 struct d3d_query *object;
6139 HRESULT hr;
6141 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
6143 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
6144 return hr;
6146 if (predicate)
6148 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
6149 return S_OK;
6152 ID3D10Query_Release(&object->ID3D10Query_iface);
6153 return S_FALSE;
6156 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
6157 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
6159 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
6161 return E_NOTIMPL;
6164 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
6165 DXGI_FORMAT format, UINT *format_support)
6167 struct d3d_device *device = impl_from_ID3D10Device(iface);
6169 TRACE("iface %p, format %s, format_support %p.\n",
6170 iface, debug_dxgi_format(format), format_support);
6172 return d3d11_device_CheckFormatSupport(&device->ID3D11Device2_iface, format, format_support);
6175 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
6176 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
6178 struct d3d_device *device = impl_from_ID3D10Device(iface);
6180 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
6181 iface, debug_dxgi_format(format), sample_count, quality_level_count);
6183 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device2_iface, format,
6184 sample_count, quality_level_count);
6187 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
6189 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
6192 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
6193 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
6194 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
6196 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
6197 "units %p, units_length %p, description %p, description_length %p stub!\n",
6198 iface, desc, type, active_counters, name, name_length,
6199 units, units_length, description, description_length);
6201 return E_NOTIMPL;
6204 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
6206 FIXME("iface %p stub!\n", iface);
6208 return 0;
6211 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
6212 HANDLE resource_handle, REFIID guid, void **resource)
6214 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
6215 iface, resource_handle, debugstr_guid(guid), resource);
6217 return E_NOTIMPL;
6220 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
6222 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
6225 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
6227 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
6230 static D3D10_FEATURE_LEVEL1 d3d10_feature_level1_from_d3d_feature_level(D3D_FEATURE_LEVEL level)
6232 return (D3D10_FEATURE_LEVEL1)level;
6235 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
6237 struct d3d_device *device = impl_from_ID3D10Device(iface);
6239 TRACE("iface %p.\n", iface);
6241 return d3d10_feature_level1_from_d3d_feature_level(device->state->feature_level);
6244 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
6246 /* IUnknown methods */
6247 d3d10_device_QueryInterface,
6248 d3d10_device_AddRef,
6249 d3d10_device_Release,
6250 /* ID3D10Device methods */
6251 d3d10_device_VSSetConstantBuffers,
6252 d3d10_device_PSSetShaderResources,
6253 d3d10_device_PSSetShader,
6254 d3d10_device_PSSetSamplers,
6255 d3d10_device_VSSetShader,
6256 d3d10_device_DrawIndexed,
6257 d3d10_device_Draw,
6258 d3d10_device_PSSetConstantBuffers,
6259 d3d10_device_IASetInputLayout,
6260 d3d10_device_IASetVertexBuffers,
6261 d3d10_device_IASetIndexBuffer,
6262 d3d10_device_DrawIndexedInstanced,
6263 d3d10_device_DrawInstanced,
6264 d3d10_device_GSSetConstantBuffers,
6265 d3d10_device_GSSetShader,
6266 d3d10_device_IASetPrimitiveTopology,
6267 d3d10_device_VSSetShaderResources,
6268 d3d10_device_VSSetSamplers,
6269 d3d10_device_SetPredication,
6270 d3d10_device_GSSetShaderResources,
6271 d3d10_device_GSSetSamplers,
6272 d3d10_device_OMSetRenderTargets,
6273 d3d10_device_OMSetBlendState,
6274 d3d10_device_OMSetDepthStencilState,
6275 d3d10_device_SOSetTargets,
6276 d3d10_device_DrawAuto,
6277 d3d10_device_RSSetState,
6278 d3d10_device_RSSetViewports,
6279 d3d10_device_RSSetScissorRects,
6280 d3d10_device_CopySubresourceRegion,
6281 d3d10_device_CopyResource,
6282 d3d10_device_UpdateSubresource,
6283 d3d10_device_ClearRenderTargetView,
6284 d3d10_device_ClearDepthStencilView,
6285 d3d10_device_GenerateMips,
6286 d3d10_device_ResolveSubresource,
6287 d3d10_device_VSGetConstantBuffers,
6288 d3d10_device_PSGetShaderResources,
6289 d3d10_device_PSGetShader,
6290 d3d10_device_PSGetSamplers,
6291 d3d10_device_VSGetShader,
6292 d3d10_device_PSGetConstantBuffers,
6293 d3d10_device_IAGetInputLayout,
6294 d3d10_device_IAGetVertexBuffers,
6295 d3d10_device_IAGetIndexBuffer,
6296 d3d10_device_GSGetConstantBuffers,
6297 d3d10_device_GSGetShader,
6298 d3d10_device_IAGetPrimitiveTopology,
6299 d3d10_device_VSGetShaderResources,
6300 d3d10_device_VSGetSamplers,
6301 d3d10_device_GetPredication,
6302 d3d10_device_GSGetShaderResources,
6303 d3d10_device_GSGetSamplers,
6304 d3d10_device_OMGetRenderTargets,
6305 d3d10_device_OMGetBlendState,
6306 d3d10_device_OMGetDepthStencilState,
6307 d3d10_device_SOGetTargets,
6308 d3d10_device_RSGetState,
6309 d3d10_device_RSGetViewports,
6310 d3d10_device_RSGetScissorRects,
6311 d3d10_device_GetDeviceRemovedReason,
6312 d3d10_device_SetExceptionMode,
6313 d3d10_device_GetExceptionMode,
6314 d3d10_device_GetPrivateData,
6315 d3d10_device_SetPrivateData,
6316 d3d10_device_SetPrivateDataInterface,
6317 d3d10_device_ClearState,
6318 d3d10_device_Flush,
6319 d3d10_device_CreateBuffer,
6320 d3d10_device_CreateTexture1D,
6321 d3d10_device_CreateTexture2D,
6322 d3d10_device_CreateTexture3D,
6323 d3d10_device_CreateShaderResourceView,
6324 d3d10_device_CreateRenderTargetView,
6325 d3d10_device_CreateDepthStencilView,
6326 d3d10_device_CreateInputLayout,
6327 d3d10_device_CreateVertexShader,
6328 d3d10_device_CreateGeometryShader,
6329 d3d10_device_CreateGeometryShaderWithStreamOutput,
6330 d3d10_device_CreatePixelShader,
6331 d3d10_device_CreateBlendState,
6332 d3d10_device_CreateDepthStencilState,
6333 d3d10_device_CreateRasterizerState,
6334 d3d10_device_CreateSamplerState,
6335 d3d10_device_CreateQuery,
6336 d3d10_device_CreatePredicate,
6337 d3d10_device_CreateCounter,
6338 d3d10_device_CheckFormatSupport,
6339 d3d10_device_CheckMultisampleQualityLevels,
6340 d3d10_device_CheckCounterInfo,
6341 d3d10_device_CheckCounter,
6342 d3d10_device_GetCreationFlags,
6343 d3d10_device_OpenSharedResource,
6344 d3d10_device_SetTextFilterSize,
6345 d3d10_device_GetTextFilterSize,
6346 d3d10_device_CreateShaderResourceView1,
6347 d3d10_device_CreateBlendState1,
6348 d3d10_device_GetFeatureLevel,
6351 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
6353 /* IUnknown methods */
6354 d3d_device_inner_QueryInterface,
6355 d3d_device_inner_AddRef,
6356 d3d_device_inner_Release,
6359 /* ID3D10Multithread methods */
6361 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
6363 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
6366 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
6368 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6370 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
6372 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6375 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
6377 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6379 TRACE("iface %p.\n", iface);
6381 return IUnknown_AddRef(device->outer_unk);
6384 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
6386 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
6388 TRACE("iface %p.\n", iface);
6390 return IUnknown_Release(device->outer_unk);
6393 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
6395 TRACE("iface %p.\n", iface);
6397 wined3d_mutex_lock();
6400 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
6402 TRACE("iface %p.\n", iface);
6404 wined3d_mutex_unlock();
6407 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL enable)
6409 FIXME("iface %p, enable %#x stub!\n", iface, enable);
6411 return TRUE;
6414 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
6416 FIXME("iface %p stub!\n", iface);
6418 return TRUE;
6421 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
6423 d3d10_multithread_QueryInterface,
6424 d3d10_multithread_AddRef,
6425 d3d10_multithread_Release,
6426 d3d10_multithread_Enter,
6427 d3d10_multithread_Leave,
6428 d3d10_multithread_SetMultithreadProtected,
6429 d3d10_multithread_GetMultithreadProtected,
6432 /* IWineDXGIDeviceParent IUnknown methods */
6434 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
6436 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
6439 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
6440 REFIID iid, void **out)
6442 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6443 return IUnknown_QueryInterface(device->outer_unk, iid, out);
6446 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
6448 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6449 return IUnknown_AddRef(device->outer_unk);
6452 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
6454 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6455 return IUnknown_Release(device->outer_unk);
6458 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
6459 IWineDXGIDeviceParent *iface)
6461 struct d3d_device *device = device_from_dxgi_device_parent(iface);
6462 return &device->device_parent;
6465 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
6467 /* IUnknown methods */
6468 dxgi_device_parent_QueryInterface,
6469 dxgi_device_parent_AddRef,
6470 dxgi_device_parent_Release,
6471 /* IWineDXGIDeviceParent methods */
6472 dxgi_device_parent_get_wined3d_device_parent,
6475 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
6477 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
6480 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
6481 struct wined3d_device *wined3d_device)
6483 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6484 struct d3d_device_context_state *state;
6485 struct wined3d_state *wined3d_state;
6486 D3D_FEATURE_LEVEL feature_level;
6488 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
6490 wined3d_device_incref(wined3d_device);
6491 device->wined3d_device = wined3d_device;
6492 device->immediate_context.wined3d_context = wined3d_device_get_immediate_context(wined3d_device);
6494 wined3d_state = wined3d_device_get_state(device->wined3d_device);
6495 feature_level = d3d_feature_level_from_wined3d(wined3d_state_get_feature_level(wined3d_state));
6497 if (!(state = heap_alloc_zero(sizeof(*state))))
6499 ERR("Failed to create the initial device context state.\n");
6500 return;
6503 d3d_device_context_state_init(state, device, feature_level,
6504 device->d3d11_only ? &IID_ID3D11Device2 : &IID_ID3D10Device1);
6506 device->state = state;
6507 if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
6508 ERR("Failed to add entry for wined3d state %p, device %p.\n", wined3d_state, device);
6510 d3d_device_context_state_private_addref(state);
6511 ID3DDeviceContextState_Release(&state->ID3DDeviceContextState_iface);
6514 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
6516 TRACE("device_parent %p.\n", device_parent);
6519 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
6521 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
6524 static HRESULT CDECL device_parent_texture_sub_resource_created(struct wined3d_device_parent *device_parent,
6525 enum wined3d_resource_type type, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx,
6526 void **parent, const struct wined3d_parent_ops **parent_ops)
6528 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
6529 device_parent, type, wined3d_texture, sub_resource_idx, parent, parent_ops);
6531 *parent = NULL;
6532 *parent_ops = &d3d_null_wined3d_parent_ops;
6534 return S_OK;
6537 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
6538 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
6539 struct wined3d_texture **wined3d_texture)
6541 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
6542 struct d3d_texture2d *texture;
6543 ID3D11Texture2D *texture_iface;
6544 D3D11_TEXTURE2D_DESC desc;
6545 HRESULT hr;
6547 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, texture_flags %#x, wined3d_texture %p.\n",
6548 device_parent, container_parent, wined3d_desc, texture_flags, wined3d_texture);
6550 desc.Width = wined3d_desc->width;
6551 desc.Height = wined3d_desc->height;
6552 desc.MipLevels = 1;
6553 desc.ArraySize = 1;
6554 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
6555 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
6556 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
6557 desc.Usage = D3D11_USAGE_DEFAULT;
6558 desc.BindFlags = d3d11_bind_flags_from_wined3d(wined3d_desc->bind_flags);
6559 desc.CPUAccessFlags = 0;
6560 desc.MiscFlags = 0;
6562 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
6564 desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
6565 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
6568 if (texture_flags)
6569 FIXME("Unhandled flags %#x.\n", texture_flags);
6571 if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device2_iface,
6572 &desc, NULL, &texture_iface)))
6574 WARN("Failed to create 2D texture, hr %#x.\n", hr);
6575 return hr;
6578 texture = impl_from_ID3D11Texture2D(texture_iface);
6580 *wined3d_texture = texture->wined3d_texture;
6581 wined3d_texture_incref(*wined3d_texture);
6582 ID3D11Texture2D_Release(&texture->ID3D11Texture2D_iface);
6584 return S_OK;
6587 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
6589 device_parent_wined3d_device_created,
6590 device_parent_mode_changed,
6591 device_parent_activate,
6592 device_parent_texture_sub_resource_created,
6593 device_parent_create_swapchain_texture,
6596 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
6598 const D3D11_SAMPLER_DESC *ka = key;
6599 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
6601 return memcmp(ka, kb, sizeof(*ka));
6604 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
6606 const D3D11_BLEND_DESC *ka = key;
6607 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
6609 return memcmp(ka, kb, sizeof(*ka));
6612 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6614 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6615 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6616 const struct d3d_depthstencil_state, entry)->desc;
6618 return memcmp(ka, kb, sizeof(*ka));
6621 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6623 const D3D11_RASTERIZER_DESC *ka = key;
6624 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6626 return memcmp(ka, kb, sizeof(*ka));
6629 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6631 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6632 device->ID3D11Device2_iface.lpVtbl = &d3d11_device_vtbl;
6633 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6634 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6635 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6636 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6637 device->refcount = 1;
6638 /* COM aggregation always takes place */
6639 device->outer_unk = outer_unknown;
6640 device->d3d11_only = FALSE;
6641 device->state = NULL;
6643 d3d11_immediate_context_init(&device->immediate_context, device);
6644 ID3D11DeviceContext1_Release(&device->immediate_context.ID3D11DeviceContext1_iface);
6646 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6647 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6648 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6649 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);