msvcp140: Implement _Stat and _Lstat.
[wine.git] / dlls / d3d11 / device.c
blobe84c3655e08e5eecc7e027d5f440054bcf92447b
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 #include "config.h"
21 #include "wine/port.h"
23 #define NONAMELESSUNION
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
28 static void STDMETHODCALLTYPE d3d_null_wined3d_object_destroyed(void *parent) {}
30 static const struct wined3d_parent_ops d3d_null_wined3d_parent_ops =
32 d3d_null_wined3d_object_destroyed,
35 /* ID3D11DeviceContext - immediate context methods */
37 static inline struct d3d11_immediate_context *impl_from_ID3D11DeviceContext(ID3D11DeviceContext *iface)
39 return CONTAINING_RECORD(iface, struct d3d11_immediate_context, ID3D11DeviceContext_iface);
42 static inline struct d3d_device *device_from_immediate_ID3D11DeviceContext(ID3D11DeviceContext *iface)
44 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
45 return CONTAINING_RECORD(context, struct d3d_device, immediate_context);
48 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_QueryInterface(ID3D11DeviceContext *iface,
49 REFIID riid, void **out)
51 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
53 if (IsEqualGUID(riid, &IID_ID3D11DeviceContext)
54 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
55 || IsEqualGUID(riid, &IID_IUnknown))
57 ID3D11DeviceContext_AddRef(iface);
58 *out = iface;
59 return S_OK;
62 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
63 *out = NULL;
64 return E_NOINTERFACE;
67 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_AddRef(ID3D11DeviceContext *iface)
69 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
70 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
71 ULONG refcount = InterlockedIncrement(&context->refcount);
73 TRACE("%p increasing refcount to %u.\n", context, refcount);
75 if (refcount == 1)
77 ID3D11Device_AddRef(&device->ID3D11Device_iface);
80 return refcount;
83 static ULONG STDMETHODCALLTYPE d3d11_immediate_context_Release(ID3D11DeviceContext *iface)
85 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
86 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
87 ULONG refcount = InterlockedDecrement(&context->refcount);
89 TRACE("%p decreasing refcount to %u.\n", context, refcount);
91 if (!refcount)
93 ID3D11Device_Release(&device->ID3D11Device_iface);
96 return refcount;
99 static void STDMETHODCALLTYPE d3d11_immediate_context_GetDevice(ID3D11DeviceContext *iface, ID3D11Device **device)
101 struct d3d_device *device_object = device_from_immediate_ID3D11DeviceContext(iface);
103 TRACE("iface %p, device %p.\n", iface, device);
105 *device = &device_object->ID3D11Device_iface;
106 ID3D11Device_AddRef(*device);
109 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetPrivateData(ID3D11DeviceContext *iface, REFGUID guid,
110 UINT *data_size, void *data)
112 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
114 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
116 return d3d_get_private_data(&context->private_store, guid, data_size, data);
119 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateData(ID3D11DeviceContext *iface, REFGUID guid,
120 UINT data_size, const void *data)
122 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
124 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
126 return d3d_set_private_data(&context->private_store, guid, data_size, data);
129 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_SetPrivateDataInterface(ID3D11DeviceContext *iface,
130 REFGUID guid, const IUnknown *data)
132 struct d3d11_immediate_context *context = impl_from_ID3D11DeviceContext(iface);
134 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
136 return d3d_set_private_data_interface(&context->private_store, guid, data);
139 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetConstantBuffers(ID3D11DeviceContext *iface,
140 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
142 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
143 unsigned int i;
145 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
146 iface, start_slot, buffer_count, buffers);
148 wined3d_mutex_lock();
149 for (i = 0; i < buffer_count; ++i)
151 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
153 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
154 buffer ? buffer->wined3d_buffer : NULL);
156 wined3d_mutex_unlock();
159 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShaderResources(ID3D11DeviceContext *iface,
160 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
162 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
163 unsigned int i;
165 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
166 iface, start_slot, view_count, views);
168 wined3d_mutex_lock();
169 for (i = 0; i < view_count; ++i)
171 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
173 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
174 view ? view->wined3d_view : NULL);
176 wined3d_mutex_unlock();
179 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetShader(ID3D11DeviceContext *iface,
180 ID3D11PixelShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
182 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
183 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D11PixelShader(shader);
185 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
186 iface, shader, class_instances, class_instance_count);
188 if (class_instances)
189 FIXME("Dynamic linking is not implemented yet.\n");
191 wined3d_mutex_lock();
192 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
193 wined3d_mutex_unlock();
196 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetSamplers(ID3D11DeviceContext *iface,
197 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
199 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
200 unsigned int i;
202 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
203 iface, start_slot, sampler_count, samplers);
205 wined3d_mutex_lock();
206 for (i = 0; i < sampler_count; ++i)
208 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
210 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
211 sampler ? sampler->wined3d_sampler : NULL);
213 wined3d_mutex_unlock();
216 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShader(ID3D11DeviceContext *iface,
217 ID3D11VertexShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
219 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
220 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D11VertexShader(shader);
222 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
223 iface, shader, class_instances, class_instance_count);
225 if (class_instances)
226 FIXME("Dynamic linking is not implemented yet.\n");
228 wined3d_mutex_lock();
229 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
230 wined3d_mutex_unlock();
233 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexed(ID3D11DeviceContext *iface,
234 UINT index_count, UINT start_index_location, INT base_vertex_location)
236 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
238 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
239 iface, index_count, start_index_location, base_vertex_location);
241 wined3d_mutex_lock();
242 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
243 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
244 wined3d_mutex_unlock();
247 static void STDMETHODCALLTYPE d3d11_immediate_context_Draw(ID3D11DeviceContext *iface,
248 UINT vertex_count, UINT start_vertex_location)
250 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
252 TRACE("iface %p, vertex_count %u, start_vertex_location %u.\n",
253 iface, vertex_count, start_vertex_location);
255 wined3d_mutex_lock();
256 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
257 wined3d_mutex_unlock();
260 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_Map(ID3D11DeviceContext *iface, ID3D11Resource *resource,
261 UINT subresource_idx, D3D11_MAP map_type, UINT map_flags, D3D11_MAPPED_SUBRESOURCE *mapped_subresource)
263 struct wined3d_resource *wined3d_resource;
264 struct wined3d_map_desc map_desc;
265 HRESULT hr;
267 TRACE("iface %p, resource %p, subresource_idx %u, map_type %u, map_flags %#x, mapped_subresource %p.\n",
268 iface, resource, subresource_idx, map_type, map_flags, mapped_subresource);
270 if (map_flags)
271 FIXME("Ignoring map_flags %#x.\n", map_flags);
273 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
275 wined3d_mutex_lock();
276 hr = wined3d_resource_map(wined3d_resource, subresource_idx,
277 &map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
278 wined3d_mutex_unlock();
280 mapped_subresource->pData = map_desc.data;
281 mapped_subresource->RowPitch = map_desc.row_pitch;
282 mapped_subresource->DepthPitch = map_desc.slice_pitch;
284 return hr;
287 static void STDMETHODCALLTYPE d3d11_immediate_context_Unmap(ID3D11DeviceContext *iface, ID3D11Resource *resource,
288 UINT subresource_idx)
290 struct wined3d_resource *wined3d_resource;
292 TRACE("iface %p, resource %p, subresource_idx %u.\n", iface, resource, subresource_idx);
294 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
296 wined3d_mutex_lock();
297 wined3d_resource_unmap(wined3d_resource, subresource_idx);
298 wined3d_mutex_unlock();
301 static void STDMETHODCALLTYPE d3d11_immediate_context_PSSetConstantBuffers(ID3D11DeviceContext *iface,
302 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
304 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
305 unsigned int i;
307 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
308 iface, start_slot, buffer_count, buffers);
310 wined3d_mutex_lock();
311 for (i = 0; i < buffer_count; ++i)
313 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
315 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
316 buffer ? buffer->wined3d_buffer : NULL);
318 wined3d_mutex_unlock();
321 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetInputLayout(ID3D11DeviceContext *iface,
322 ID3D11InputLayout *input_layout)
324 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
325 struct d3d_input_layout *layout = unsafe_impl_from_ID3D11InputLayout(input_layout);
327 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
329 wined3d_mutex_lock();
330 wined3d_device_set_vertex_declaration(device->wined3d_device, layout ? layout->wined3d_decl : NULL);
331 wined3d_mutex_unlock();
334 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetVertexBuffers(ID3D11DeviceContext *iface,
335 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers, const UINT *strides, const UINT *offsets)
337 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
338 unsigned int i;
340 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
341 iface, start_slot, buffer_count, buffers, strides, offsets);
343 wined3d_mutex_lock();
344 for (i = 0; i < buffer_count; ++i)
346 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
348 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
349 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
351 wined3d_mutex_unlock();
354 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetIndexBuffer(ID3D11DeviceContext *iface,
355 ID3D11Buffer *buffer, DXGI_FORMAT format, UINT offset)
357 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
358 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
360 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
361 iface, buffer, debug_dxgi_format(format), offset);
363 wined3d_mutex_lock();
364 wined3d_device_set_index_buffer(device->wined3d_device,
365 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
366 wined3dformat_from_dxgi_format(format), offset);
367 wined3d_mutex_unlock();
370 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstanced(ID3D11DeviceContext *iface,
371 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
372 UINT start_instance_location)
374 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
376 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
377 "base_vertex_location %d, start_instance_location %u.\n",
378 iface, instance_index_count, instance_count, start_index_location,
379 base_vertex_location, start_instance_location);
381 wined3d_mutex_lock();
382 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
383 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
384 instance_index_count, start_instance_location, instance_count);
385 wined3d_mutex_unlock();
388 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstanced(ID3D11DeviceContext *iface,
389 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
391 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
393 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
394 "start_instance_location %u.\n",
395 iface, instance_vertex_count, instance_count, start_vertex_location,
396 start_instance_location);
398 wined3d_mutex_lock();
399 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
400 instance_vertex_count, start_instance_location, instance_count);
401 wined3d_mutex_unlock();
404 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers(ID3D11DeviceContext *iface,
405 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
407 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
408 unsigned int i;
410 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
411 iface, start_slot, buffer_count, buffers);
413 wined3d_mutex_lock();
414 for (i = 0; i < buffer_count; ++i)
416 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
418 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
419 buffer ? buffer->wined3d_buffer : NULL);
421 wined3d_mutex_unlock();
424 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShader(ID3D11DeviceContext *iface,
425 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
427 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
428 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
430 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
431 iface, shader, class_instances, class_instance_count);
433 if (class_instances)
434 FIXME("Dynamic linking is not implemented yet.\n");
436 wined3d_mutex_lock();
437 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
438 wined3d_mutex_unlock();
441 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetPrimitiveTopology(ID3D11DeviceContext *iface,
442 D3D11_PRIMITIVE_TOPOLOGY topology)
444 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
445 enum wined3d_primitive_type primitive_type;
446 unsigned int patch_vertex_count;
448 TRACE("iface %p, topology %#x.\n", iface, topology);
450 wined3d_primitive_type_from_d3d11_primitive_topology(topology, &primitive_type, &patch_vertex_count);
452 wined3d_mutex_lock();
453 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, patch_vertex_count);
454 wined3d_mutex_unlock();
457 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShaderResources(ID3D11DeviceContext *iface,
458 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
460 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
461 unsigned int i;
463 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
465 wined3d_mutex_lock();
466 for (i = 0; i < view_count; ++i)
468 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
470 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
471 view ? view->wined3d_view : NULL);
473 wined3d_mutex_unlock();
476 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetSamplers(ID3D11DeviceContext *iface,
477 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
479 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
480 unsigned int i;
482 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
483 iface, start_slot, sampler_count, samplers);
485 wined3d_mutex_lock();
486 for (i = 0; i < sampler_count; ++i)
488 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
490 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
491 sampler ? sampler->wined3d_sampler : NULL);
493 wined3d_mutex_unlock();
496 static void STDMETHODCALLTYPE d3d11_immediate_context_Begin(ID3D11DeviceContext *iface,
497 ID3D11Asynchronous *asynchronous)
499 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
500 HRESULT hr;
502 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
504 wined3d_mutex_lock();
505 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_BEGIN)))
506 ERR("Failed to issue query, hr %#x.\n", hr);
507 wined3d_mutex_unlock();
510 static void STDMETHODCALLTYPE d3d11_immediate_context_End(ID3D11DeviceContext *iface,
511 ID3D11Asynchronous *asynchronous)
513 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
514 HRESULT hr;
516 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
518 wined3d_mutex_lock();
519 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_END)))
520 ERR("Failed to issue query, hr %#x.\n", hr);
521 wined3d_mutex_unlock();
524 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetData(ID3D11DeviceContext *iface,
525 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
527 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
528 unsigned int wined3d_flags;
529 HRESULT hr;
531 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
532 iface, asynchronous, data, data_size, data_flags);
534 if (!data && data_size)
535 return E_INVALIDARG;
537 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
539 wined3d_mutex_lock();
540 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
542 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
543 if (hr == WINED3DERR_INVALIDCALL)
544 hr = DXGI_ERROR_INVALID_CALL;
546 else
548 WARN("Invalid data size %u.\n", data_size);
549 hr = E_INVALIDARG;
551 wined3d_mutex_unlock();
553 return hr;
556 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext *iface,
557 ID3D11Predicate *predicate, BOOL value)
559 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
560 struct d3d_query *query;
562 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
564 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
566 wined3d_mutex_lock();
567 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
568 wined3d_mutex_unlock();
571 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext *iface,
572 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
574 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
575 unsigned int i;
577 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
579 wined3d_mutex_lock();
580 for (i = 0; i < view_count; ++i)
582 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
584 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
585 view ? view->wined3d_view : NULL);
587 wined3d_mutex_unlock();
590 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext *iface,
591 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
593 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
594 unsigned int i;
596 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
597 iface, start_slot, sampler_count, samplers);
599 wined3d_mutex_lock();
600 for (i = 0; i < sampler_count; ++i)
602 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
604 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
605 sampler ? sampler->wined3d_sampler : NULL);
607 wined3d_mutex_unlock();
610 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext *iface,
611 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
612 ID3D11DepthStencilView *depth_stencil_view)
614 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
615 struct d3d_depthstencil_view *dsv;
616 unsigned int i;
618 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
619 iface, render_target_view_count, render_target_views, depth_stencil_view);
621 wined3d_mutex_lock();
622 for (i = 0; i < render_target_view_count; ++i)
624 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
625 wined3d_device_set_rendertarget_view(device->wined3d_device, i, rtv ? rtv->wined3d_view : NULL, FALSE);
627 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
629 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
632 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
633 wined3d_device_set_depth_stencil_view(device->wined3d_device, dsv ? dsv->wined3d_view : NULL);
634 wined3d_mutex_unlock();
637 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
638 ID3D11DeviceContext *iface, UINT render_target_view_count,
639 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
640 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
641 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
643 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
644 unsigned int i;
646 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
647 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
648 "initial_counts %p.\n",
649 iface, render_target_view_count, render_target_views, depth_stencil_view,
650 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
651 initial_counts);
653 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
655 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
656 depth_stencil_view);
659 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
661 wined3d_mutex_lock();
662 for (i = 0; i < unordered_access_view_start_slot; ++i)
664 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
666 for (i = 0; i < unordered_access_view_count; ++i)
668 struct d3d11_unordered_access_view *view
669 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
671 if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
672 && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
673 && initial_counts[i] != ~(UINT)0)
674 FIXME("Ignoring initial count %u for slot %u.\n",
675 initial_counts[i], unordered_access_view_start_slot + i);
677 wined3d_device_set_unordered_access_view(device->wined3d_device,
678 unordered_access_view_start_slot + i,
679 view ? view->wined3d_view : NULL);
681 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
683 wined3d_device_set_unordered_access_view(device->wined3d_device,
684 unordered_access_view_start_slot + i, NULL);
686 wined3d_mutex_unlock();
690 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
691 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
693 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
694 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
695 const D3D11_BLEND_DESC *desc;
697 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
698 iface, blend_state, debug_float4(blend_factor), sample_mask);
700 if (!blend_factor)
701 blend_factor = default_blend_factor;
703 wined3d_mutex_lock();
704 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
705 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
706 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
708 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
709 wined3d_device_set_render_state(device->wined3d_device,
710 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
711 wined3d_device_set_render_state(device->wined3d_device,
712 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
713 wined3d_device_set_render_state(device->wined3d_device,
714 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
715 wined3d_device_set_render_state(device->wined3d_device,
716 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
717 wined3d_mutex_unlock();
718 return;
721 desc = &device->blend_state->desc;
722 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
723 desc->RenderTarget[0].BlendEnable);
724 if (desc->RenderTarget[0].BlendEnable)
726 const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0];
728 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, d->SrcBlend);
729 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, d->DestBlend);
730 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, d->BlendOp);
731 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
732 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, d->SrcBlendAlpha);
733 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, d->DestBlendAlpha);
734 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, d->BlendOpAlpha);
736 if (memcmp(blend_factor, default_blend_factor, sizeof(default_blend_factor))
737 && (d->SrcBlend == D3D11_BLEND_BLEND_FACTOR || d->SrcBlend == D3D11_BLEND_INV_BLEND_FACTOR
738 || d->DestBlend == D3D11_BLEND_BLEND_FACTOR || d->DestBlend == D3D11_BLEND_INV_BLEND_FACTOR
739 || d->SrcBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->SrcBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR
740 || d->DestBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->DestBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR))
741 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
743 wined3d_device_set_render_state(device->wined3d_device,
744 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
745 wined3d_device_set_render_state(device->wined3d_device,
746 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
747 wined3d_device_set_render_state(device->wined3d_device,
748 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
749 wined3d_device_set_render_state(device->wined3d_device,
750 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
751 wined3d_mutex_unlock();
754 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
755 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
757 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
758 const D3D11_DEPTH_STENCILOP_DESC *front, *back;
759 const D3D11_DEPTH_STENCIL_DESC *desc;
761 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
762 iface, depth_stencil_state, stencil_ref);
764 wined3d_mutex_lock();
765 device->stencil_ref = stencil_ref;
766 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
768 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE);
769 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
770 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS);
771 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
772 wined3d_mutex_unlock();
773 return;
776 desc = &device->depth_stencil_state->desc;
778 front = &desc->FrontFace;
779 back = &desc->BackFace;
781 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
782 if (desc->DepthEnable)
784 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
785 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
788 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
789 if (desc->StencilEnable)
791 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
792 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
793 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
795 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, front->StencilFailOp);
796 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL, front->StencilDepthFailOp);
797 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, front->StencilPassOp);
798 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, front->StencilFunc);
799 if (front->StencilFailOp != back->StencilFailOp
800 || front->StencilDepthFailOp != back->StencilDepthFailOp
801 || front->StencilPassOp != back->StencilPassOp
802 || front->StencilFunc != back->StencilFunc)
804 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, TRUE);
805 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFAIL, back->StencilFailOp);
806 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILZFAIL,
807 back->StencilDepthFailOp);
808 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILPASS, back->StencilPassOp);
809 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFUNC, back->StencilFunc);
811 else
813 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, FALSE);
816 wined3d_mutex_unlock();
819 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
820 ID3D11Buffer *const *buffers, const UINT *offsets)
822 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
823 unsigned int count, i;
825 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
827 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
828 wined3d_mutex_lock();
829 for (i = 0; i < count; ++i)
831 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
833 wined3d_device_set_stream_output(device->wined3d_device, i,
834 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
836 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
838 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
840 wined3d_mutex_unlock();
843 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
845 FIXME("iface %p stub!\n", iface);
848 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
849 ID3D11Buffer *buffer, UINT offset)
851 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
854 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
855 ID3D11Buffer *buffer, UINT offset)
857 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
860 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
861 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
863 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
865 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
866 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
868 wined3d_mutex_lock();
869 wined3d_device_dispatch_compute(device->wined3d_device,
870 thread_group_count_x, thread_group_count_y, thread_group_count_z);
871 wined3d_mutex_unlock();
874 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
875 ID3D11Buffer *buffer, UINT offset)
877 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
880 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
881 ID3D11RasterizerState *rasterizer_state)
883 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
884 struct d3d_rasterizer_state *rasterizer_state_impl;
885 const D3D11_RASTERIZER_DESC *desc;
887 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
889 wined3d_mutex_lock();
890 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
892 wined3d_device_set_rasterizer_state(device->wined3d_device, NULL);
893 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
894 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_BACK);
895 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
896 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
897 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
898 wined3d_mutex_unlock();
899 return;
902 wined3d_device_set_rasterizer_state(device->wined3d_device, rasterizer_state_impl->wined3d_state);
904 desc = &rasterizer_state_impl->desc;
905 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
906 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
907 /* OpenGL style depth bias. */
908 if (desc->DepthBias || desc->SlopeScaledDepthBias)
909 FIXME("Ignoring depth bias.\n");
910 /* GL_DEPTH_CLAMP */
911 if (!desc->DepthClipEnable)
912 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
913 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
914 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
915 wined3d_device_set_render_state(device->wined3d_device,
916 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
917 wined3d_mutex_unlock();
920 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
921 UINT viewport_count, const D3D11_VIEWPORT *viewports)
923 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
924 struct wined3d_viewport wined3d_vp;
926 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
928 if (viewport_count > 1)
929 FIXME("Multiple viewports not implemented.\n");
931 if (!viewport_count)
932 return;
934 wined3d_vp.x = viewports[0].TopLeftX;
935 wined3d_vp.y = viewports[0].TopLeftY;
936 wined3d_vp.width = viewports[0].Width;
937 wined3d_vp.height = viewports[0].Height;
938 wined3d_vp.min_z = viewports[0].MinDepth;
939 wined3d_vp.max_z = viewports[0].MaxDepth;
941 wined3d_mutex_lock();
942 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
943 wined3d_mutex_unlock();
946 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
947 UINT rect_count, const D3D11_RECT *rects)
949 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
951 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
953 if (rect_count > 1)
954 FIXME("Multiple scissor rects not implemented.\n");
956 if (!rect_count)
957 return;
959 wined3d_mutex_lock();
960 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
961 wined3d_mutex_unlock();
964 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
965 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
966 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
968 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
969 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
970 struct wined3d_box wined3d_src_box;
972 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
973 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
974 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
975 src_resource, src_subresource_idx, src_box);
977 if (src_box)
978 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
979 src_box->right, src_box->bottom, src_box->front, src_box->back);
981 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
982 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
983 wined3d_mutex_lock();
984 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
985 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
986 wined3d_mutex_unlock();
989 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
990 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
992 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
993 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
995 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
997 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
998 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
999 wined3d_mutex_lock();
1000 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1001 wined3d_mutex_unlock();
1004 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
1005 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1006 const void *data, UINT row_pitch, UINT depth_pitch)
1008 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1009 struct wined3d_resource *wined3d_resource;
1010 struct wined3d_box wined3d_box;
1012 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1013 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1015 if (box)
1016 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1018 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1019 wined3d_mutex_lock();
1020 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1021 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1022 wined3d_mutex_unlock();
1025 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
1026 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1028 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
1029 iface, dst_buffer, dst_offset, src_view);
1032 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
1033 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1035 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1036 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1037 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1038 HRESULT hr;
1040 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1041 iface, render_target_view, debug_float4(color_rgba));
1043 if (!view)
1044 return;
1046 wined3d_mutex_lock();
1047 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1048 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1049 ERR("Failed to clear view, hr %#x.\n", hr);
1050 wined3d_mutex_unlock();
1053 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1054 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1056 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1057 struct d3d11_unordered_access_view *view;
1059 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1060 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1062 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1063 wined3d_mutex_lock();
1064 wined3d_device_clear_unordered_access_view_uint(device->wined3d_device,
1065 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1066 wined3d_mutex_unlock();
1069 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1070 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1072 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1073 iface, unordered_access_view, debug_float4(values));
1076 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1077 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1079 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1080 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1081 DWORD wined3d_flags;
1082 HRESULT hr;
1084 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1085 iface, depth_stencil_view, flags, depth, stencil);
1087 if (!view)
1088 return;
1090 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1092 wined3d_mutex_lock();
1093 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1094 wined3d_flags, NULL, depth, stencil)))
1095 ERR("Failed to clear view, hr %#x.\n", hr);
1096 wined3d_mutex_unlock();
1099 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1100 ID3D11ShaderResourceView *view)
1102 FIXME("iface %p, view %p stub!\n", iface, view);
1105 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1106 ID3D11Resource *resource, FLOAT min_lod)
1108 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1111 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1112 ID3D11Resource *resource)
1114 FIXME("iface %p, resource %p stub!\n", iface, resource);
1116 return 0.0f;
1119 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1120 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1121 ID3D11Resource *src_resource, UINT src_subresource_idx,
1122 DXGI_FORMAT format)
1124 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1125 "format %s stub!\n",
1126 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1127 debug_dxgi_format(format));
1130 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1131 ID3D11CommandList *command_list, BOOL restore_state)
1133 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1136 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1137 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1139 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1140 unsigned int i;
1142 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1143 iface, start_slot, view_count, views);
1145 wined3d_mutex_lock();
1146 for (i = 0; i < view_count; ++i)
1148 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1150 wined3d_device_set_hs_resource_view(device->wined3d_device, start_slot + i,
1151 view ? view->wined3d_view : NULL);
1153 wined3d_mutex_unlock();
1156 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1157 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1159 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1160 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1162 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1163 iface, shader, class_instances, class_instance_count);
1165 if (class_instances)
1166 FIXME("Dynamic linking is not implemented yet.\n");
1168 wined3d_mutex_lock();
1169 wined3d_device_set_hull_shader(device->wined3d_device, hs ? hs->wined3d_shader : NULL);
1170 wined3d_mutex_unlock();
1173 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1174 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1176 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1177 unsigned int i;
1179 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1180 iface, start_slot, sampler_count, samplers);
1182 wined3d_mutex_lock();
1183 for (i = 0; i < sampler_count; ++i)
1185 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1187 wined3d_device_set_hs_sampler(device->wined3d_device, start_slot + i,
1188 sampler ? sampler->wined3d_sampler : NULL);
1190 wined3d_mutex_unlock();
1193 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1194 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1196 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1197 unsigned int i;
1199 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1200 iface, start_slot, buffer_count, buffers);
1202 wined3d_mutex_lock();
1203 for (i = 0; i < buffer_count; ++i)
1205 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1207 wined3d_device_set_hs_cb(device->wined3d_device, start_slot + i,
1208 buffer ? buffer->wined3d_buffer : NULL);
1210 wined3d_mutex_unlock();
1213 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1214 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1216 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1217 unsigned int i;
1219 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1220 iface, start_slot, view_count, views);
1222 wined3d_mutex_lock();
1223 for (i = 0; i < view_count; ++i)
1225 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1227 wined3d_device_set_ds_resource_view(device->wined3d_device, start_slot + i,
1228 view ? view->wined3d_view : NULL);
1230 wined3d_mutex_unlock();
1233 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1234 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1236 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1237 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1239 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1240 iface, shader, class_instances, class_instance_count);
1242 if (class_instances)
1243 FIXME("Dynamic linking is not implemented yet.\n");
1245 wined3d_mutex_lock();
1246 wined3d_device_set_domain_shader(device->wined3d_device, ds ? ds->wined3d_shader : NULL);
1247 wined3d_mutex_unlock();
1250 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1251 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1253 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1254 unsigned int i;
1256 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1257 iface, start_slot, sampler_count, samplers);
1259 wined3d_mutex_lock();
1260 for (i = 0; i < sampler_count; ++i)
1262 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1264 wined3d_device_set_ds_sampler(device->wined3d_device, start_slot + i,
1265 sampler ? sampler->wined3d_sampler : NULL);
1267 wined3d_mutex_unlock();
1270 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1271 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1273 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1274 unsigned int i;
1276 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1277 iface, start_slot, buffer_count, buffers);
1279 wined3d_mutex_lock();
1280 for (i = 0; i < buffer_count; ++i)
1282 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1284 wined3d_device_set_ds_cb(device->wined3d_device, start_slot + i,
1285 buffer ? buffer->wined3d_buffer : NULL);
1287 wined3d_mutex_unlock();
1290 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1291 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1293 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1294 unsigned int i;
1296 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1297 iface, start_slot, view_count, views);
1299 wined3d_mutex_lock();
1300 for (i = 0; i < view_count; ++i)
1302 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1304 wined3d_device_set_cs_resource_view(device->wined3d_device, start_slot + i,
1305 view ? view->wined3d_view : NULL);
1307 wined3d_mutex_unlock();
1310 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1311 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1313 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1314 unsigned int i;
1316 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1317 iface, start_slot, view_count, views, initial_counts);
1319 wined3d_mutex_lock();
1320 for (i = 0; i < view_count; ++i)
1322 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1324 if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
1325 && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
1326 && initial_counts[i] != ~(UINT)0)
1327 FIXME("Ignoring initial count %u for slot %u.\n", initial_counts[i], start_slot + i);
1329 wined3d_device_set_cs_uav(device->wined3d_device, start_slot + i,
1330 view ? view->wined3d_view : NULL);
1332 wined3d_mutex_unlock();
1335 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1336 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1338 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1339 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1341 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1342 iface, shader, class_instances, class_instance_count);
1344 if (class_instances)
1345 FIXME("Dynamic linking is not implemented yet.\n");
1347 wined3d_mutex_lock();
1348 wined3d_device_set_compute_shader(device->wined3d_device, cs ? cs->wined3d_shader : NULL);
1349 wined3d_mutex_unlock();
1352 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1353 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1355 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1356 unsigned int i;
1358 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1359 iface, start_slot, sampler_count, samplers);
1361 wined3d_mutex_lock();
1362 for (i = 0; i < sampler_count; ++i)
1364 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1366 wined3d_device_set_cs_sampler(device->wined3d_device, start_slot + i,
1367 sampler ? sampler->wined3d_sampler : NULL);
1369 wined3d_mutex_unlock();
1372 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1373 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1375 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1376 unsigned int i;
1378 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1379 iface, start_slot, buffer_count, buffers);
1381 wined3d_mutex_lock();
1382 for (i = 0; i < buffer_count; ++i)
1384 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1386 wined3d_device_set_cs_cb(device->wined3d_device, start_slot + i,
1387 buffer ? buffer->wined3d_buffer : NULL);
1389 wined3d_mutex_unlock();
1392 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1393 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1395 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1396 unsigned int i;
1398 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1399 iface, start_slot, buffer_count, buffers);
1401 wined3d_mutex_lock();
1402 for (i = 0; i < buffer_count; ++i)
1404 struct wined3d_buffer *wined3d_buffer;
1405 struct d3d_buffer *buffer_impl;
1407 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1409 buffers[i] = NULL;
1410 continue;
1413 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1414 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1415 ID3D11Buffer_AddRef(buffers[i]);
1417 wined3d_mutex_unlock();
1420 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1421 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1423 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1424 unsigned int i;
1426 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1427 iface, start_slot, view_count, views);
1429 wined3d_mutex_lock();
1430 for (i = 0; i < view_count; ++i)
1432 struct wined3d_shader_resource_view *wined3d_view;
1433 struct d3d_shader_resource_view *view_impl;
1435 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1437 views[i] = NULL;
1438 continue;
1441 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1442 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1443 ID3D11ShaderResourceView_AddRef(views[i]);
1445 wined3d_mutex_unlock();
1448 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1449 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1451 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1452 struct wined3d_shader *wined3d_shader;
1453 struct d3d_pixel_shader *shader_impl;
1455 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1456 iface, shader, class_instances, class_instance_count);
1458 if (class_instances || class_instance_count)
1459 FIXME("Dynamic linking not implemented yet.\n");
1461 wined3d_mutex_lock();
1462 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1464 wined3d_mutex_unlock();
1465 *shader = NULL;
1466 return;
1469 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1470 wined3d_mutex_unlock();
1471 *shader = &shader_impl->ID3D11PixelShader_iface;
1472 ID3D11PixelShader_AddRef(*shader);
1475 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1476 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1478 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1479 unsigned int i;
1481 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1482 iface, start_slot, sampler_count, samplers);
1484 wined3d_mutex_lock();
1485 for (i = 0; i < sampler_count; ++i)
1487 struct wined3d_sampler *wined3d_sampler;
1488 struct d3d_sampler_state *sampler_impl;
1490 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1492 samplers[i] = NULL;
1493 continue;
1496 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1497 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1498 ID3D11SamplerState_AddRef(samplers[i]);
1500 wined3d_mutex_unlock();
1503 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1504 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1506 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1507 struct d3d_vertex_shader *shader_impl;
1508 struct wined3d_shader *wined3d_shader;
1510 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1511 iface, shader, class_instances, class_instance_count);
1513 if (class_instances || class_instance_count)
1514 FIXME("Dynamic linking not implemented yet.\n");
1516 wined3d_mutex_lock();
1517 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1519 wined3d_mutex_unlock();
1520 *shader = NULL;
1521 return;
1524 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1525 wined3d_mutex_unlock();
1526 *shader = &shader_impl->ID3D11VertexShader_iface;
1527 ID3D11VertexShader_AddRef(*shader);
1530 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1531 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1533 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1534 unsigned int i;
1536 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1537 iface, start_slot, buffer_count, buffers);
1539 wined3d_mutex_lock();
1540 for (i = 0; i < buffer_count; ++i)
1542 struct wined3d_buffer *wined3d_buffer;
1543 struct d3d_buffer *buffer_impl;
1545 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1547 buffers[i] = NULL;
1548 continue;
1551 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1552 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1553 ID3D11Buffer_AddRef(buffers[i]);
1555 wined3d_mutex_unlock();
1558 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1559 ID3D11InputLayout **input_layout)
1561 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1562 struct wined3d_vertex_declaration *wined3d_declaration;
1563 struct d3d_input_layout *input_layout_impl;
1565 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1567 wined3d_mutex_lock();
1568 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1570 wined3d_mutex_unlock();
1571 *input_layout = NULL;
1572 return;
1575 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1576 wined3d_mutex_unlock();
1577 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1578 ID3D11InputLayout_AddRef(*input_layout);
1581 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1582 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1584 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1585 unsigned int i;
1587 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1588 iface, start_slot, buffer_count, buffers, strides, offsets);
1590 wined3d_mutex_lock();
1591 for (i = 0; i < buffer_count; ++i)
1593 struct wined3d_buffer *wined3d_buffer = NULL;
1594 struct d3d_buffer *buffer_impl;
1596 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1597 &wined3d_buffer, &offsets[i], &strides[i])))
1599 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1600 if (strides)
1601 strides[i] = 0;
1602 if (offsets)
1603 offsets[i] = 0;
1606 if (!wined3d_buffer)
1608 buffers[i] = NULL;
1609 continue;
1612 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1613 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1615 wined3d_mutex_unlock();
1618 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1619 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1621 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1622 enum wined3d_format_id wined3d_format;
1623 struct wined3d_buffer *wined3d_buffer;
1624 struct d3d_buffer *buffer_impl;
1626 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1628 wined3d_mutex_lock();
1629 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1630 *format = dxgi_format_from_wined3dformat(wined3d_format);
1631 if (!wined3d_buffer)
1633 wined3d_mutex_unlock();
1634 *buffer = NULL;
1635 return;
1638 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1639 wined3d_mutex_unlock();
1640 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1643 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1644 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1646 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1647 unsigned int i;
1649 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1650 iface, start_slot, buffer_count, buffers);
1652 wined3d_mutex_lock();
1653 for (i = 0; i < buffer_count; ++i)
1655 struct wined3d_buffer *wined3d_buffer;
1656 struct d3d_buffer *buffer_impl;
1658 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1660 buffers[i] = NULL;
1661 continue;
1664 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1665 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1666 ID3D11Buffer_AddRef(buffers[i]);
1668 wined3d_mutex_unlock();
1671 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1672 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1674 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1675 struct d3d_geometry_shader *shader_impl;
1676 struct wined3d_shader *wined3d_shader;
1678 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1679 iface, shader, class_instances, class_instance_count);
1681 if (class_instances || class_instance_count)
1682 FIXME("Dynamic linking not implemented yet.\n");
1684 wined3d_mutex_lock();
1685 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1687 wined3d_mutex_unlock();
1688 *shader = NULL;
1689 return;
1692 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1693 wined3d_mutex_unlock();
1694 *shader = &shader_impl->ID3D11GeometryShader_iface;
1695 ID3D11GeometryShader_AddRef(*shader);
1698 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1699 D3D11_PRIMITIVE_TOPOLOGY *topology)
1701 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1702 enum wined3d_primitive_type primitive_type;
1703 unsigned int patch_vertex_count;
1705 TRACE("iface %p, topology %p.\n", iface, topology);
1707 wined3d_mutex_lock();
1708 wined3d_device_get_primitive_type(device->wined3d_device, &primitive_type, &patch_vertex_count);
1709 wined3d_mutex_unlock();
1711 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1714 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1715 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1717 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1718 unsigned int i;
1720 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1722 wined3d_mutex_lock();
1723 for (i = 0; i < view_count; ++i)
1725 struct wined3d_shader_resource_view *wined3d_view;
1726 struct d3d_shader_resource_view *view_impl;
1728 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1730 views[i] = NULL;
1731 continue;
1734 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1735 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1736 ID3D11ShaderResourceView_AddRef(views[i]);
1738 wined3d_mutex_unlock();
1741 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1742 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1744 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1745 unsigned int i;
1747 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1748 iface, start_slot, sampler_count, samplers);
1750 wined3d_mutex_lock();
1751 for (i = 0; i < sampler_count; ++i)
1753 struct wined3d_sampler *wined3d_sampler;
1754 struct d3d_sampler_state *sampler_impl;
1756 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1758 samplers[i] = NULL;
1759 continue;
1762 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1763 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1764 ID3D11SamplerState_AddRef(samplers[i]);
1766 wined3d_mutex_unlock();
1769 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1770 ID3D11Predicate **predicate, BOOL *value)
1772 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1773 struct wined3d_query *wined3d_predicate;
1774 struct d3d_query *predicate_impl;
1776 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1778 wined3d_mutex_lock();
1779 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1781 wined3d_mutex_unlock();
1782 *predicate = NULL;
1783 return;
1786 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1787 wined3d_mutex_unlock();
1788 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1789 ID3D11Predicate_AddRef(*predicate);
1792 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1793 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1795 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1796 unsigned int i;
1798 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1800 wined3d_mutex_lock();
1801 for (i = 0; i < view_count; ++i)
1803 struct wined3d_shader_resource_view *wined3d_view;
1804 struct d3d_shader_resource_view *view_impl;
1806 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1808 views[i] = NULL;
1809 continue;
1812 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1813 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1814 ID3D11ShaderResourceView_AddRef(views[i]);
1816 wined3d_mutex_unlock();
1819 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1820 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1822 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1823 unsigned int i;
1825 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1826 iface, start_slot, sampler_count, samplers);
1828 wined3d_mutex_lock();
1829 for (i = 0; i < sampler_count; ++i)
1831 struct d3d_sampler_state *sampler_impl;
1832 struct wined3d_sampler *wined3d_sampler;
1834 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1836 samplers[i] = NULL;
1837 continue;
1840 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1841 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1842 ID3D11SamplerState_AddRef(samplers[i]);
1844 wined3d_mutex_unlock();
1847 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1848 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1849 ID3D11DepthStencilView **depth_stencil_view)
1851 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1852 struct wined3d_rendertarget_view *wined3d_view;
1854 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1855 iface, render_target_view_count, render_target_views, depth_stencil_view);
1857 wined3d_mutex_lock();
1858 if (render_target_views)
1860 struct d3d_rendertarget_view *view_impl;
1861 unsigned int i;
1863 for (i = 0; i < render_target_view_count; ++i)
1865 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1866 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1868 render_target_views[i] = NULL;
1869 continue;
1872 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1873 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1877 if (depth_stencil_view)
1879 struct d3d_depthstencil_view *view_impl;
1881 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1882 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1884 *depth_stencil_view = NULL;
1886 else
1888 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1889 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1892 wined3d_mutex_unlock();
1895 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1896 ID3D11DeviceContext *iface,
1897 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1898 ID3D11DepthStencilView **depth_stencil_view,
1899 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1900 ID3D11UnorderedAccessView **unordered_access_views)
1902 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1903 struct wined3d_unordered_access_view *wined3d_view;
1904 struct d3d11_unordered_access_view *view_impl;
1905 unsigned int i;
1907 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1908 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1909 "unordered_access_views %p.\n",
1910 iface, render_target_view_count, render_target_views, depth_stencil_view,
1911 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1913 if (render_target_views || depth_stencil_view)
1914 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
1915 render_target_views, depth_stencil_view);
1917 if (unordered_access_views)
1919 wined3d_mutex_lock();
1920 for (i = 0; i < unordered_access_view_count; ++i)
1922 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
1923 unordered_access_view_start_slot + i)))
1925 unordered_access_views[i] = NULL;
1926 continue;
1929 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
1930 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
1931 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
1933 wined3d_mutex_unlock();
1937 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1938 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1940 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1942 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1943 iface, blend_state, blend_factor, sample_mask);
1945 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1946 ID3D11BlendState_AddRef(*blend_state);
1947 wined3d_mutex_lock();
1948 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1949 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1950 wined3d_mutex_unlock();
1953 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1954 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1956 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1958 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1959 iface, depth_stencil_state, stencil_ref);
1961 if ((*depth_stencil_state = device->depth_stencil_state
1962 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
1963 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
1964 *stencil_ref = device->stencil_ref;
1967 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1968 UINT buffer_count, ID3D11Buffer **buffers)
1970 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1971 unsigned int i;
1973 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1975 wined3d_mutex_lock();
1976 for (i = 0; i < buffer_count; ++i)
1978 struct wined3d_buffer *wined3d_buffer;
1979 struct d3d_buffer *buffer_impl;
1981 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1983 buffers[i] = NULL;
1984 continue;
1987 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1988 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1989 ID3D11Buffer_AddRef(buffers[i]);
1991 wined3d_mutex_unlock();
1994 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1995 ID3D11RasterizerState **rasterizer_state)
1997 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1998 struct d3d_rasterizer_state *rasterizer_state_impl;
1999 struct wined3d_rasterizer_state *wined3d_state;
2001 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2003 wined3d_mutex_lock();
2004 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
2006 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2007 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2009 else
2011 *rasterizer_state = NULL;
2013 wined3d_mutex_unlock();
2016 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
2017 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2019 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2020 struct wined3d_viewport wined3d_vp;
2022 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2024 if (!viewports)
2026 *viewport_count = 1;
2027 return;
2030 if (!*viewport_count)
2031 return;
2033 wined3d_mutex_lock();
2034 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
2035 wined3d_mutex_unlock();
2037 viewports[0].TopLeftX = wined3d_vp.x;
2038 viewports[0].TopLeftY = wined3d_vp.y;
2039 viewports[0].Width = wined3d_vp.width;
2040 viewports[0].Height = wined3d_vp.height;
2041 viewports[0].MinDepth = wined3d_vp.min_z;
2042 viewports[0].MaxDepth = wined3d_vp.max_z;
2044 if (*viewport_count > 1)
2045 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
2048 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
2049 UINT *rect_count, D3D11_RECT *rects)
2051 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2053 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2055 if (!rects)
2057 *rect_count = 1;
2058 return;
2061 if (!*rect_count)
2062 return;
2064 wined3d_mutex_lock();
2065 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
2066 wined3d_mutex_unlock();
2067 if (*rect_count > 1)
2068 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
2071 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
2072 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2074 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2075 unsigned int i;
2077 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2079 wined3d_mutex_lock();
2080 for (i = 0; i < view_count; ++i)
2082 struct wined3d_shader_resource_view *wined3d_view;
2083 struct d3d_shader_resource_view *view_impl;
2085 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2087 views[i] = NULL;
2088 continue;
2091 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2092 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2094 wined3d_mutex_unlock();
2097 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
2098 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2100 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2101 struct d3d11_hull_shader *shader_impl;
2102 struct wined3d_shader *wined3d_shader;
2104 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2105 iface, shader, class_instances, class_instance_count);
2107 if (class_instances || class_instance_count)
2108 FIXME("Dynamic linking not implemented yet.\n");
2110 wined3d_mutex_lock();
2111 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2113 wined3d_mutex_unlock();
2114 *shader = NULL;
2115 return;
2118 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2119 wined3d_mutex_unlock();
2120 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2123 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
2124 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2126 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2127 unsigned int i;
2129 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2130 iface, start_slot, sampler_count, samplers);
2132 wined3d_mutex_lock();
2133 for (i = 0; i < sampler_count; ++i)
2135 struct wined3d_sampler *wined3d_sampler;
2136 struct d3d_sampler_state *sampler_impl;
2138 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2140 samplers[i] = NULL;
2141 continue;
2144 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2145 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2147 wined3d_mutex_unlock();
2150 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
2151 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2153 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2154 unsigned int i;
2156 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2157 iface, start_slot, buffer_count, buffers);
2159 wined3d_mutex_lock();
2160 for (i = 0; i < buffer_count; ++i)
2162 struct wined3d_buffer *wined3d_buffer;
2163 struct d3d_buffer *buffer_impl;
2165 if (!(wined3d_buffer = wined3d_device_get_hs_cb(device->wined3d_device, start_slot + i)))
2167 buffers[i] = NULL;
2168 continue;
2171 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2172 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2174 wined3d_mutex_unlock();
2177 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
2178 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2180 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2181 unsigned int i;
2183 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2184 iface, start_slot, view_count, views);
2186 wined3d_mutex_lock();
2187 for (i = 0; i < view_count; ++i)
2189 struct wined3d_shader_resource_view *wined3d_view;
2190 struct d3d_shader_resource_view *view_impl;
2192 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2194 views[i] = NULL;
2195 continue;
2198 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2199 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2201 wined3d_mutex_unlock();
2204 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
2205 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2207 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2208 struct d3d11_domain_shader *shader_impl;
2209 struct wined3d_shader *wined3d_shader;
2211 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2212 iface, shader, class_instances, class_instance_count);
2214 if (class_instances || class_instance_count)
2215 FIXME("Dynamic linking not implemented yet.\n");
2217 wined3d_mutex_lock();
2218 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2220 wined3d_mutex_unlock();
2221 *shader = NULL;
2222 return;
2225 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2226 wined3d_mutex_unlock();
2227 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2230 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
2231 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2233 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2234 unsigned int i;
2236 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2237 iface, start_slot, sampler_count, samplers);
2239 wined3d_mutex_lock();
2240 for (i = 0; i < sampler_count; ++i)
2242 struct wined3d_sampler *wined3d_sampler;
2243 struct d3d_sampler_state *sampler_impl;
2245 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2247 samplers[i] = NULL;
2248 continue;
2251 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2252 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2254 wined3d_mutex_unlock();
2257 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
2258 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2260 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2261 unsigned int i;
2263 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2264 iface, start_slot, buffer_count, buffers);
2266 wined3d_mutex_lock();
2267 for (i = 0; i < buffer_count; ++i)
2269 struct wined3d_buffer *wined3d_buffer;
2270 struct d3d_buffer *buffer_impl;
2272 if (!(wined3d_buffer = wined3d_device_get_ds_cb(device->wined3d_device, start_slot + i)))
2274 buffers[i] = NULL;
2275 continue;
2278 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2279 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2281 wined3d_mutex_unlock();
2284 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
2285 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2287 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2288 unsigned int i;
2290 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2292 wined3d_mutex_lock();
2293 for (i = 0; i < view_count; ++i)
2295 struct wined3d_shader_resource_view *wined3d_view;
2296 struct d3d_shader_resource_view *view_impl;
2298 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2300 views[i] = NULL;
2301 continue;
2304 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2305 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2307 wined3d_mutex_unlock();
2310 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
2311 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2313 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2314 unsigned int i;
2316 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2318 wined3d_mutex_lock();
2319 for (i = 0; i < view_count; ++i)
2321 struct wined3d_unordered_access_view *wined3d_view;
2322 struct d3d11_unordered_access_view *view_impl;
2324 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2326 views[i] = NULL;
2327 continue;
2330 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2331 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2333 wined3d_mutex_unlock();
2336 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
2337 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2339 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2340 struct d3d11_compute_shader *shader_impl;
2341 struct wined3d_shader *wined3d_shader;
2343 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2344 iface, shader, class_instances, class_instance_count);
2346 if (class_instances || class_instance_count)
2347 FIXME("Dynamic linking not implemented yet.\n");
2349 wined3d_mutex_lock();
2350 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2352 wined3d_mutex_unlock();
2353 *shader = NULL;
2354 return;
2357 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2358 wined3d_mutex_unlock();
2359 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2362 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
2363 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2365 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2366 unsigned int i;
2368 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2369 iface, start_slot, sampler_count, samplers);
2371 wined3d_mutex_lock();
2372 for (i = 0; i < sampler_count; ++i)
2374 struct wined3d_sampler *wined3d_sampler;
2375 struct d3d_sampler_state *sampler_impl;
2377 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2379 samplers[i] = NULL;
2380 continue;
2383 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2384 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2386 wined3d_mutex_unlock();
2389 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
2390 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2392 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2393 unsigned int i;
2395 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2396 iface, start_slot, buffer_count, buffers);
2398 wined3d_mutex_lock();
2399 for (i = 0; i < buffer_count; ++i)
2401 struct wined3d_buffer *wined3d_buffer;
2402 struct d3d_buffer *buffer_impl;
2404 if (!(wined3d_buffer = wined3d_device_get_cs_cb(device->wined3d_device, start_slot + i)))
2406 buffers[i] = NULL;
2407 continue;
2410 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2411 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2413 wined3d_mutex_unlock();
2416 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
2418 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2419 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2420 unsigned int i;
2422 TRACE("iface %p.\n", iface);
2424 wined3d_mutex_lock();
2425 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2426 wined3d_device_set_hull_shader(device->wined3d_device, NULL);
2427 wined3d_device_set_domain_shader(device->wined3d_device, NULL);
2428 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
2429 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2430 wined3d_device_set_compute_shader(device->wined3d_device, NULL);
2431 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2433 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
2434 wined3d_device_set_hs_sampler(device->wined3d_device, i, NULL);
2435 wined3d_device_set_ds_sampler(device->wined3d_device, i, NULL);
2436 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
2437 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
2438 wined3d_device_set_cs_sampler(device->wined3d_device, i, NULL);
2440 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2442 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
2443 wined3d_device_set_hs_resource_view(device->wined3d_device, i, NULL);
2444 wined3d_device_set_ds_resource_view(device->wined3d_device, i, NULL);
2445 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
2446 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
2447 wined3d_device_set_cs_resource_view(device->wined3d_device, i, NULL);
2449 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2451 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
2452 wined3d_device_set_hs_cb(device->wined3d_device, i, NULL);
2453 wined3d_device_set_ds_cb(device->wined3d_device, i, NULL);
2454 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
2455 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
2456 wined3d_device_set_cs_cb(device->wined3d_device, i, NULL);
2458 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2460 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
2462 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
2463 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
2464 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED, 0);
2465 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2467 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
2469 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
2470 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
2472 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
2473 wined3d_device_set_cs_uav(device->wined3d_device, i, NULL);
2475 ID3D11DeviceContext_OMSetDepthStencilState(iface, NULL, 0);
2476 ID3D11DeviceContext_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2477 ID3D11DeviceContext_RSSetViewports(iface, 0, NULL);
2478 ID3D11DeviceContext_RSSetScissorRects(iface, 0, NULL);
2479 ID3D11DeviceContext_RSSetState(iface, NULL);
2480 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2482 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2484 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
2485 wined3d_mutex_unlock();
2488 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
2490 FIXME("iface %p stub!\n", iface);
2493 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
2495 TRACE("iface %p.\n", iface);
2497 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2500 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
2502 FIXME("iface %p stub!\n", iface);
2504 return 0;
2507 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
2508 BOOL restore, ID3D11CommandList **command_list)
2510 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
2512 return E_NOTIMPL;
2515 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
2517 /* IUnknown methods */
2518 d3d11_immediate_context_QueryInterface,
2519 d3d11_immediate_context_AddRef,
2520 d3d11_immediate_context_Release,
2521 /* ID3D11DeviceChild methods */
2522 d3d11_immediate_context_GetDevice,
2523 d3d11_immediate_context_GetPrivateData,
2524 d3d11_immediate_context_SetPrivateData,
2525 d3d11_immediate_context_SetPrivateDataInterface,
2526 /* ID3D11DeviceContext methods */
2527 d3d11_immediate_context_VSSetConstantBuffers,
2528 d3d11_immediate_context_PSSetShaderResources,
2529 d3d11_immediate_context_PSSetShader,
2530 d3d11_immediate_context_PSSetSamplers,
2531 d3d11_immediate_context_VSSetShader,
2532 d3d11_immediate_context_DrawIndexed,
2533 d3d11_immediate_context_Draw,
2534 d3d11_immediate_context_Map,
2535 d3d11_immediate_context_Unmap,
2536 d3d11_immediate_context_PSSetConstantBuffers,
2537 d3d11_immediate_context_IASetInputLayout,
2538 d3d11_immediate_context_IASetVertexBuffers,
2539 d3d11_immediate_context_IASetIndexBuffer,
2540 d3d11_immediate_context_DrawIndexedInstanced,
2541 d3d11_immediate_context_DrawInstanced,
2542 d3d11_immediate_context_GSSetConstantBuffers,
2543 d3d11_immediate_context_GSSetShader,
2544 d3d11_immediate_context_IASetPrimitiveTopology,
2545 d3d11_immediate_context_VSSetShaderResources,
2546 d3d11_immediate_context_VSSetSamplers,
2547 d3d11_immediate_context_Begin,
2548 d3d11_immediate_context_End,
2549 d3d11_immediate_context_GetData,
2550 d3d11_immediate_context_SetPredication,
2551 d3d11_immediate_context_GSSetShaderResources,
2552 d3d11_immediate_context_GSSetSamplers,
2553 d3d11_immediate_context_OMSetRenderTargets,
2554 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2555 d3d11_immediate_context_OMSetBlendState,
2556 d3d11_immediate_context_OMSetDepthStencilState,
2557 d3d11_immediate_context_SOSetTargets,
2558 d3d11_immediate_context_DrawAuto,
2559 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2560 d3d11_immediate_context_DrawInstancedIndirect,
2561 d3d11_immediate_context_Dispatch,
2562 d3d11_immediate_context_DispatchIndirect,
2563 d3d11_immediate_context_RSSetState,
2564 d3d11_immediate_context_RSSetViewports,
2565 d3d11_immediate_context_RSSetScissorRects,
2566 d3d11_immediate_context_CopySubresourceRegion,
2567 d3d11_immediate_context_CopyResource,
2568 d3d11_immediate_context_UpdateSubresource,
2569 d3d11_immediate_context_CopyStructureCount,
2570 d3d11_immediate_context_ClearRenderTargetView,
2571 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2572 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2573 d3d11_immediate_context_ClearDepthStencilView,
2574 d3d11_immediate_context_GenerateMips,
2575 d3d11_immediate_context_SetResourceMinLOD,
2576 d3d11_immediate_context_GetResourceMinLOD,
2577 d3d11_immediate_context_ResolveSubresource,
2578 d3d11_immediate_context_ExecuteCommandList,
2579 d3d11_immediate_context_HSSetShaderResources,
2580 d3d11_immediate_context_HSSetShader,
2581 d3d11_immediate_context_HSSetSamplers,
2582 d3d11_immediate_context_HSSetConstantBuffers,
2583 d3d11_immediate_context_DSSetShaderResources,
2584 d3d11_immediate_context_DSSetShader,
2585 d3d11_immediate_context_DSSetSamplers,
2586 d3d11_immediate_context_DSSetConstantBuffers,
2587 d3d11_immediate_context_CSSetShaderResources,
2588 d3d11_immediate_context_CSSetUnorderedAccessViews,
2589 d3d11_immediate_context_CSSetShader,
2590 d3d11_immediate_context_CSSetSamplers,
2591 d3d11_immediate_context_CSSetConstantBuffers,
2592 d3d11_immediate_context_VSGetConstantBuffers,
2593 d3d11_immediate_context_PSGetShaderResources,
2594 d3d11_immediate_context_PSGetShader,
2595 d3d11_immediate_context_PSGetSamplers,
2596 d3d11_immediate_context_VSGetShader,
2597 d3d11_immediate_context_PSGetConstantBuffers,
2598 d3d11_immediate_context_IAGetInputLayout,
2599 d3d11_immediate_context_IAGetVertexBuffers,
2600 d3d11_immediate_context_IAGetIndexBuffer,
2601 d3d11_immediate_context_GSGetConstantBuffers,
2602 d3d11_immediate_context_GSGetShader,
2603 d3d11_immediate_context_IAGetPrimitiveTopology,
2604 d3d11_immediate_context_VSGetShaderResources,
2605 d3d11_immediate_context_VSGetSamplers,
2606 d3d11_immediate_context_GetPredication,
2607 d3d11_immediate_context_GSGetShaderResources,
2608 d3d11_immediate_context_GSGetSamplers,
2609 d3d11_immediate_context_OMGetRenderTargets,
2610 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2611 d3d11_immediate_context_OMGetBlendState,
2612 d3d11_immediate_context_OMGetDepthStencilState,
2613 d3d11_immediate_context_SOGetTargets,
2614 d3d11_immediate_context_RSGetState,
2615 d3d11_immediate_context_RSGetViewports,
2616 d3d11_immediate_context_RSGetScissorRects,
2617 d3d11_immediate_context_HSGetShaderResources,
2618 d3d11_immediate_context_HSGetShader,
2619 d3d11_immediate_context_HSGetSamplers,
2620 d3d11_immediate_context_HSGetConstantBuffers,
2621 d3d11_immediate_context_DSGetShaderResources,
2622 d3d11_immediate_context_DSGetShader,
2623 d3d11_immediate_context_DSGetSamplers,
2624 d3d11_immediate_context_DSGetConstantBuffers,
2625 d3d11_immediate_context_CSGetShaderResources,
2626 d3d11_immediate_context_CSGetUnorderedAccessViews,
2627 d3d11_immediate_context_CSGetShader,
2628 d3d11_immediate_context_CSGetSamplers,
2629 d3d11_immediate_context_CSGetConstantBuffers,
2630 d3d11_immediate_context_ClearState,
2631 d3d11_immediate_context_Flush,
2632 d3d11_immediate_context_GetType,
2633 d3d11_immediate_context_GetContextFlags,
2634 d3d11_immediate_context_FinishCommandList,
2637 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2639 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2640 context->refcount = 1;
2642 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2644 wined3d_private_store_init(&context->private_store);
2647 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2649 wined3d_private_store_cleanup(&context->private_store);
2652 /* ID3D11Device methods */
2654 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2656 struct d3d_device *device = impl_from_ID3D11Device(iface);
2657 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2660 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2662 struct d3d_device *device = impl_from_ID3D11Device(iface);
2663 return IUnknown_AddRef(device->outer_unk);
2666 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2668 struct d3d_device *device = impl_from_ID3D11Device(iface);
2669 return IUnknown_Release(device->outer_unk);
2672 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2673 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2675 struct d3d_device *device = impl_from_ID3D11Device(iface);
2676 struct d3d_buffer *object;
2677 HRESULT hr;
2679 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2681 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2682 return hr;
2684 *buffer = &object->ID3D11Buffer_iface;
2686 return S_OK;
2689 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2690 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2692 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2694 return E_NOTIMPL;
2697 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2698 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2700 struct d3d_device *device = impl_from_ID3D11Device(iface);
2701 struct d3d_texture2d *object;
2702 HRESULT hr;
2704 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2706 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2707 return hr;
2709 *texture = &object->ID3D11Texture2D_iface;
2711 return S_OK;
2714 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2715 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2717 struct d3d_device *device = impl_from_ID3D11Device(iface);
2718 struct d3d_texture3d *object;
2719 HRESULT hr;
2721 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2723 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2724 return hr;
2726 *texture = &object->ID3D11Texture3D_iface;
2728 return S_OK;
2731 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2732 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2734 struct d3d_device *device = impl_from_ID3D11Device(iface);
2735 struct d3d_shader_resource_view *object;
2736 HRESULT hr;
2738 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2740 if (!resource)
2741 return E_INVALIDARG;
2743 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2744 return hr;
2746 *view = &object->ID3D11ShaderResourceView_iface;
2748 return S_OK;
2751 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2752 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2754 struct d3d_device *device = impl_from_ID3D11Device(iface);
2755 struct d3d11_unordered_access_view *object;
2756 HRESULT hr;
2758 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2760 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2761 return hr;
2763 *view = &object->ID3D11UnorderedAccessView_iface;
2765 return S_OK;
2768 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2769 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2771 struct d3d_device *device = impl_from_ID3D11Device(iface);
2772 struct d3d_rendertarget_view *object;
2773 HRESULT hr;
2775 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2777 if (!resource)
2778 return E_INVALIDARG;
2780 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2781 return hr;
2783 *view = &object->ID3D11RenderTargetView_iface;
2785 return S_OK;
2788 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2789 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2791 struct d3d_device *device = impl_from_ID3D11Device(iface);
2792 struct d3d_depthstencil_view *object;
2793 HRESULT hr;
2795 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2797 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2798 return hr;
2800 *view = &object->ID3D11DepthStencilView_iface;
2802 return S_OK;
2805 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2806 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2807 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2809 struct d3d_device *device = impl_from_ID3D11Device(iface);
2810 struct d3d_input_layout *object;
2811 HRESULT hr;
2813 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2814 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2815 shader_byte_code_length, input_layout);
2817 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2818 shader_byte_code, shader_byte_code_length, &object)))
2819 return hr;
2821 *input_layout = &object->ID3D11InputLayout_iface;
2823 return S_OK;
2826 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2827 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2829 struct d3d_device *device = impl_from_ID3D11Device(iface);
2830 struct d3d_vertex_shader *object;
2831 HRESULT hr;
2833 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2834 iface, byte_code, byte_code_length, class_linkage, shader);
2836 if (class_linkage)
2837 FIXME("Class linkage is not implemented yet.\n");
2839 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2840 return hr;
2842 *shader = &object->ID3D11VertexShader_iface;
2844 return S_OK;
2847 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2848 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2850 struct d3d_device *device = impl_from_ID3D11Device(iface);
2851 struct d3d_geometry_shader *object;
2852 HRESULT hr;
2854 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2855 iface, byte_code, byte_code_length, class_linkage, shader);
2857 if (class_linkage)
2858 FIXME("Class linkage is not implemented yet.\n");
2860 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2861 NULL, 0, NULL, 0, 0, &object)))
2862 return hr;
2864 *shader = &object->ID3D11GeometryShader_iface;
2866 return S_OK;
2869 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2870 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2871 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
2872 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2874 struct d3d_device *device = impl_from_ID3D11Device(iface);
2875 struct d3d_geometry_shader *object;
2876 HRESULT hr;
2878 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2879 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
2880 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2881 rasterizer_stream, class_linkage, shader);
2883 if (class_linkage)
2884 FIXME("Class linkage is not implemented yet.\n");
2886 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2887 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
2889 *shader = NULL;
2890 return hr;
2893 *shader = &object->ID3D11GeometryShader_iface;
2895 return hr;
2898 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2899 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2901 struct d3d_device *device = impl_from_ID3D11Device(iface);
2902 struct d3d_pixel_shader *object;
2903 HRESULT hr;
2905 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2906 iface, byte_code, byte_code_length, class_linkage, shader);
2908 if (class_linkage)
2909 FIXME("Class linkage is not implemented yet.\n");
2911 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2912 return hr;
2914 *shader = &object->ID3D11PixelShader_iface;
2916 return S_OK;
2919 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2920 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2922 struct d3d_device *device = impl_from_ID3D11Device(iface);
2923 struct d3d11_hull_shader *object;
2924 HRESULT hr;
2926 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2927 iface, byte_code, byte_code_length, class_linkage, shader);
2929 if (class_linkage)
2930 FIXME("Class linkage is not implemented yet.\n");
2932 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2933 return hr;
2935 *shader = &object->ID3D11HullShader_iface;
2937 return S_OK;
2940 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2941 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2943 struct d3d_device *device = impl_from_ID3D11Device(iface);
2944 struct d3d11_domain_shader *object;
2945 HRESULT hr;
2947 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2948 iface, byte_code, byte_code_length, class_linkage, shader);
2950 if (class_linkage)
2951 FIXME("Class linkage is not implemented yet.\n");
2953 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2954 return hr;
2956 *shader = &object->ID3D11DomainShader_iface;
2958 return S_OK;
2961 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2962 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2964 struct d3d_device *device = impl_from_ID3D11Device(iface);
2965 struct d3d11_compute_shader *object;
2966 HRESULT hr;
2968 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2969 iface, byte_code, byte_code_length, class_linkage, shader);
2971 if (class_linkage)
2972 FIXME("Class linkage is not implemented yet.\n");
2974 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
2975 return hr;
2977 *shader = &object->ID3D11ComputeShader_iface;
2979 return S_OK;
2982 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2983 ID3D11ClassLinkage **class_linkage)
2985 struct d3d_device *device = impl_from_ID3D11Device(iface);
2986 struct d3d11_class_linkage *object;
2987 HRESULT hr;
2989 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
2991 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
2992 return hr;
2994 *class_linkage = &object->ID3D11ClassLinkage_iface;
2996 return S_OK;
2999 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
3000 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3002 struct d3d_device *device = impl_from_ID3D11Device(iface);
3003 struct d3d_blend_state *object;
3004 struct wine_rb_entry *entry;
3005 D3D11_BLEND_DESC tmp_desc;
3006 unsigned int i, j;
3007 HRESULT hr;
3009 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3011 if (!desc)
3012 return E_INVALIDARG;
3014 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
3015 * D3D11_BLEND_DESC as a key in the rbtree. */
3016 memset(&tmp_desc, 0, sizeof(tmp_desc));
3017 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
3018 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
3019 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3021 j = desc->IndependentBlendEnable ? i : 0;
3022 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
3023 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
3024 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
3025 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
3026 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
3027 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
3028 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
3029 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
3031 if (i > 3 && tmp_desc.RenderTarget[i].RenderTargetWriteMask != D3D11_COLOR_WRITE_ENABLE_ALL)
3032 FIXME("Color mask %#x not supported for render target %u.\n",
3033 tmp_desc.RenderTarget[i].RenderTargetWriteMask, i);
3036 /* glSampleCoverage() */
3037 if (tmp_desc.AlphaToCoverageEnable)
3038 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", tmp_desc.AlphaToCoverageEnable);
3039 /* glEnableIndexedEXT(GL_BLEND, ...) */
3040 if (tmp_desc.IndependentBlendEnable)
3041 FIXME("Per-rendertarget blend not implemented.\n");
3043 wined3d_mutex_lock();
3044 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
3046 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
3048 TRACE("Returning existing blend state %p.\n", object);
3049 *blend_state = &object->ID3D11BlendState_iface;
3050 ID3D11BlendState_AddRef(*blend_state);
3051 wined3d_mutex_unlock();
3053 return S_OK;
3055 wined3d_mutex_unlock();
3057 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3058 return E_OUTOFMEMORY;
3060 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
3062 WARN("Failed to initialize blend state, hr %#x.\n", hr);
3063 HeapFree(GetProcessHeap(), 0, object);
3064 return hr;
3067 TRACE("Created blend state %p.\n", object);
3068 *blend_state = &object->ID3D11BlendState_iface;
3070 return S_OK;
3073 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
3074 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3076 struct d3d_device *device = impl_from_ID3D11Device(iface);
3077 struct d3d_depthstencil_state *object;
3078 D3D11_DEPTH_STENCIL_DESC tmp_desc;
3079 struct wine_rb_entry *entry;
3080 HRESULT hr;
3082 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3084 if (!desc)
3085 return E_INVALIDARG;
3087 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
3088 * it as a key in the rbtree. */
3089 memset(&tmp_desc, 0, sizeof(tmp_desc));
3090 tmp_desc.DepthEnable = desc->DepthEnable;
3091 if (desc->DepthEnable)
3093 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
3094 tmp_desc.DepthFunc = desc->DepthFunc;
3096 else
3098 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
3099 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
3101 tmp_desc.StencilEnable = desc->StencilEnable;
3102 if (desc->StencilEnable)
3104 tmp_desc.StencilReadMask = desc->StencilReadMask;
3105 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
3106 tmp_desc.FrontFace = desc->FrontFace;
3107 tmp_desc.BackFace = desc->BackFace;
3109 else
3111 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
3112 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
3113 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3114 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3115 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3116 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3117 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3118 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3119 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3120 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3123 wined3d_mutex_lock();
3124 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
3126 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
3128 TRACE("Returning existing depthstencil state %p.\n", object);
3129 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3130 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
3131 wined3d_mutex_unlock();
3133 return S_OK;
3135 wined3d_mutex_unlock();
3137 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3138 return E_OUTOFMEMORY;
3140 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
3142 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
3143 HeapFree(GetProcessHeap(), 0, object);
3144 return hr;
3147 TRACE("Created depthstencil state %p.\n", object);
3148 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3150 return S_OK;
3153 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
3154 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3156 struct d3d_device *device = impl_from_ID3D11Device(iface);
3157 struct d3d_rasterizer_state *object;
3158 struct wine_rb_entry *entry;
3159 HRESULT hr;
3161 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3163 if (!desc)
3164 return E_INVALIDARG;
3166 wined3d_mutex_lock();
3167 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
3169 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
3171 TRACE("Returning existing rasterizer state %p.\n", object);
3172 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3173 ID3D11RasterizerState_AddRef(*rasterizer_state);
3174 wined3d_mutex_unlock();
3176 return S_OK;
3178 wined3d_mutex_unlock();
3180 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3181 return E_OUTOFMEMORY;
3183 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
3185 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
3186 HeapFree(GetProcessHeap(), 0, object);
3187 return hr;
3190 TRACE("Created rasterizer state %p.\n", object);
3191 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3193 return S_OK;
3196 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
3197 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3199 struct d3d_device *device = impl_from_ID3D11Device(iface);
3200 D3D11_SAMPLER_DESC normalized_desc;
3201 struct d3d_sampler_state *object;
3202 struct wine_rb_entry *entry;
3203 HRESULT hr;
3205 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3207 if (!desc)
3208 return E_INVALIDARG;
3210 normalized_desc = *desc;
3211 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
3212 normalized_desc.MaxAnisotropy = 0;
3213 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
3214 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3215 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
3216 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
3217 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
3218 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
3220 wined3d_mutex_lock();
3221 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
3223 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
3225 TRACE("Returning existing sampler state %p.\n", object);
3226 *sampler_state = &object->ID3D11SamplerState_iface;
3227 ID3D11SamplerState_AddRef(*sampler_state);
3228 wined3d_mutex_unlock();
3230 return S_OK;
3232 wined3d_mutex_unlock();
3234 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3235 return E_OUTOFMEMORY;
3237 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
3239 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
3240 HeapFree(GetProcessHeap(), 0, object);
3241 return hr;
3244 TRACE("Created sampler state %p.\n", object);
3245 *sampler_state = &object->ID3D11SamplerState_iface;
3247 return S_OK;
3250 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
3251 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3253 struct d3d_device *device = impl_from_ID3D11Device(iface);
3254 struct d3d_query *object;
3255 HRESULT hr;
3257 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3259 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3260 return hr;
3262 if (query)
3264 *query = &object->ID3D11Query_iface;
3265 return S_OK;
3268 ID3D11Query_Release(&object->ID3D11Query_iface);
3269 return S_FALSE;
3272 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
3273 ID3D11Predicate **predicate)
3275 struct d3d_device *device = impl_from_ID3D11Device(iface);
3276 struct d3d_query *object;
3277 HRESULT hr;
3279 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3281 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3282 return hr;
3284 if (predicate)
3286 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3287 return S_OK;
3290 ID3D11Query_Release(&object->ID3D11Query_iface);
3291 return S_FALSE;
3294 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3295 ID3D11Counter **counter)
3297 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3299 return E_NOTIMPL;
3302 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
3303 ID3D11DeviceContext **context)
3305 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3307 return E_NOTIMPL;
3310 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
3311 void **out)
3313 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
3315 return E_NOTIMPL;
3318 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
3319 UINT *format_support)
3321 struct d3d_device *device = impl_from_ID3D11Device(iface);
3322 struct wined3d_device_creation_parameters params;
3323 enum wined3d_format_id wined3d_format;
3324 struct wined3d *wined3d;
3325 unsigned int i;
3327 static const struct
3329 enum wined3d_resource_type rtype;
3330 unsigned int usage;
3331 D3D11_FORMAT_SUPPORT flag;
3333 flag_mapping[] =
3335 {WINED3D_RTYPE_TEXTURE_2D, WINED3DUSAGE_TEXTURE, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3336 {WINED3D_RTYPE_TEXTURE_3D, WINED3DUSAGE_TEXTURE, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3337 {WINED3D_RTYPE_NONE, WINED3DUSAGE_RENDERTARGET, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3338 {WINED3D_RTYPE_NONE, WINED3DUSAGE_DEPTHSTENCIL, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3340 HRESULT hr;
3342 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3344 wined3d_format = wined3dformat_from_dxgi_format(format);
3345 if (format && !wined3d_format)
3347 WARN("Invalid format %#x.\n", format);
3348 *format_support = 0;
3349 return E_FAIL;
3352 *format_support = 0;
3354 wined3d_mutex_lock();
3355 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3356 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3357 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3359 hr = wined3d_check_device_format(wined3d, params.adapter_idx, params.device_type,
3360 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].rtype, wined3d_format);
3361 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOAUTOGEN)
3362 continue;
3363 if (hr != WINED3D_OK)
3365 WARN("Failed to check device format support, hr %#x.\n", hr);
3366 wined3d_mutex_unlock();
3367 return E_FAIL;
3370 *format_support |= flag_mapping[i].flag;
3372 wined3d_mutex_unlock();
3374 return S_OK;
3377 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
3378 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3380 struct d3d_device *device = impl_from_ID3D11Device(iface);
3381 struct wined3d_device_creation_parameters params;
3382 struct wined3d *wined3d;
3383 HRESULT hr;
3385 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3386 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3388 if (!quality_level_count)
3389 return E_INVALIDARG;
3391 *quality_level_count = 0;
3393 if (!sample_count)
3394 return E_FAIL;
3395 if (sample_count == 1)
3397 *quality_level_count = 1;
3398 return S_OK;
3400 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3401 return E_FAIL;
3403 wined3d_mutex_lock();
3404 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3405 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3406 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
3407 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3408 wined3d_mutex_unlock();
3410 if (hr == WINED3DERR_INVALIDCALL)
3411 return E_INVALIDARG;
3412 if (hr == WINED3DERR_NOTAVAILABLE)
3413 return S_OK;
3414 return hr;
3417 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
3419 FIXME("iface %p, info %p stub!\n", iface, info);
3422 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3423 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3424 char *units, UINT *units_length, char *description, UINT *description_length)
3426 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3427 "units %p, units_length %p, description %p, description_length %p stub!\n",
3428 iface, desc, type, active_counter_count, name, name_length,
3429 units, units_length, description, description_length);
3431 return E_NOTIMPL;
3434 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
3435 void *feature_support_data, UINT feature_support_data_size)
3437 struct d3d_device *device = impl_from_ID3D11Device(iface);
3438 WINED3DCAPS wined3d_caps;
3439 HRESULT hr;
3441 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3442 iface, feature, feature_support_data, feature_support_data_size);
3444 switch (feature)
3446 case D3D11_FEATURE_THREADING:
3448 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3449 if (feature_support_data_size != sizeof(*threading_data))
3451 WARN("Invalid data size.\n");
3452 return E_INVALIDARG;
3455 /* We lie about the threading support to make Tomb Raider 2013 and
3456 * Deus Ex: Human Revolution happy. */
3457 FIXME("Returning fake threading support data.\n");
3458 threading_data->DriverConcurrentCreates = TRUE;
3459 threading_data->DriverCommandLists = TRUE;
3460 return S_OK;
3463 case D3D11_FEATURE_DOUBLES:
3465 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3466 if (feature_support_data_size != sizeof(*doubles_data))
3468 WARN("Invalid data size.\n");
3469 return E_INVALIDARG;
3472 wined3d_mutex_lock();
3473 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3474 wined3d_mutex_unlock();
3475 if (FAILED(hr))
3477 WARN("Failed to get device caps, hr %#x.\n", hr);
3478 return hr;
3481 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3482 return S_OK;
3485 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3487 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3488 if (feature_support_data_size != sizeof(*options))
3490 WARN("Invalid data size.\n");
3491 return E_INVALIDARG;
3494 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
3495 return S_OK;
3498 default:
3499 FIXME("Unhandled feature %#x.\n", feature);
3500 return E_NOTIMPL;
3504 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
3505 UINT *data_size, void *data)
3507 IDXGIDevice *dxgi_device;
3508 HRESULT hr;
3510 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3512 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3513 return hr;
3514 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3515 IDXGIDevice_Release(dxgi_device);
3517 return hr;
3520 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
3521 UINT data_size, const void *data)
3523 IDXGIDevice *dxgi_device;
3524 HRESULT hr;
3526 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3528 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3529 return hr;
3530 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3531 IDXGIDevice_Release(dxgi_device);
3533 return hr;
3536 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
3537 const IUnknown *data)
3539 IDXGIDevice *dxgi_device;
3540 HRESULT hr;
3542 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3544 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3545 return hr;
3546 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3547 IDXGIDevice_Release(dxgi_device);
3549 return hr;
3552 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
3554 struct d3d_device *device = impl_from_ID3D11Device(iface);
3556 TRACE("iface %p.\n", iface);
3558 return device->feature_level;
3561 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
3563 FIXME("iface %p stub!\n", iface);
3565 return 0;
3568 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
3570 FIXME("iface %p stub!\n", iface);
3572 return S_OK;
3575 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
3576 ID3D11DeviceContext **immediate_context)
3578 struct d3d_device *device = impl_from_ID3D11Device(iface);
3580 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
3582 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
3583 ID3D11DeviceContext_AddRef(*immediate_context);
3586 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
3588 FIXME("iface %p, flags %#x stub!\n", iface, flags);
3590 return E_NOTIMPL;
3593 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
3595 FIXME("iface %p stub!\n", iface);
3597 return 0;
3600 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
3602 /* IUnknown methods */
3603 d3d11_device_QueryInterface,
3604 d3d11_device_AddRef,
3605 d3d11_device_Release,
3606 /* ID3D11Device methods */
3607 d3d11_device_CreateBuffer,
3608 d3d11_device_CreateTexture1D,
3609 d3d11_device_CreateTexture2D,
3610 d3d11_device_CreateTexture3D,
3611 d3d11_device_CreateShaderResourceView,
3612 d3d11_device_CreateUnorderedAccessView,
3613 d3d11_device_CreateRenderTargetView,
3614 d3d11_device_CreateDepthStencilView,
3615 d3d11_device_CreateInputLayout,
3616 d3d11_device_CreateVertexShader,
3617 d3d11_device_CreateGeometryShader,
3618 d3d11_device_CreateGeometryShaderWithStreamOutput,
3619 d3d11_device_CreatePixelShader,
3620 d3d11_device_CreateHullShader,
3621 d3d11_device_CreateDomainShader,
3622 d3d11_device_CreateComputeShader,
3623 d3d11_device_CreateClassLinkage,
3624 d3d11_device_CreateBlendState,
3625 d3d11_device_CreateDepthStencilState,
3626 d3d11_device_CreateRasterizerState,
3627 d3d11_device_CreateSamplerState,
3628 d3d11_device_CreateQuery,
3629 d3d11_device_CreatePredicate,
3630 d3d11_device_CreateCounter,
3631 d3d11_device_CreateDeferredContext,
3632 d3d11_device_OpenSharedResource,
3633 d3d11_device_CheckFormatSupport,
3634 d3d11_device_CheckMultisampleQualityLevels,
3635 d3d11_device_CheckCounterInfo,
3636 d3d11_device_CheckCounter,
3637 d3d11_device_CheckFeatureSupport,
3638 d3d11_device_GetPrivateData,
3639 d3d11_device_SetPrivateData,
3640 d3d11_device_SetPrivateDataInterface,
3641 d3d11_device_GetFeatureLevel,
3642 d3d11_device_GetCreationFlags,
3643 d3d11_device_GetDeviceRemovedReason,
3644 d3d11_device_GetImmediateContext,
3645 d3d11_device_SetExceptionMode,
3646 d3d11_device_GetExceptionMode,
3649 /* Inner IUnknown methods */
3651 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
3653 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
3656 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3658 struct d3d_device *device = impl_from_IUnknown(iface);
3660 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
3662 if (IsEqualGUID(riid, &IID_ID3D11Device)
3663 || IsEqualGUID(riid, &IID_IUnknown))
3665 *out = &device->ID3D11Device_iface;
3667 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
3668 || IsEqualGUID(riid, &IID_ID3D10Device))
3670 *out = &device->ID3D10Device1_iface;
3672 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
3674 *out = &device->ID3D10Multithread_iface;
3676 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
3678 *out = &device->IWineDXGIDeviceParent_iface;
3680 else
3682 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
3683 *out = NULL;
3684 return E_NOINTERFACE;
3687 IUnknown_AddRef((IUnknown *)*out);
3688 return S_OK;
3691 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
3693 struct d3d_device *device = impl_from_IUnknown(iface);
3694 ULONG refcount = InterlockedIncrement(&device->refcount);
3696 TRACE("%p increasing refcount to %u.\n", device, refcount);
3698 return refcount;
3701 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
3703 struct d3d_device *device = impl_from_IUnknown(iface);
3704 ULONG refcount = InterlockedDecrement(&device->refcount);
3706 TRACE("%p decreasing refcount to %u.\n", device, refcount);
3708 if (!refcount)
3710 d3d11_immediate_context_destroy(&device->immediate_context);
3711 if (device->wined3d_device)
3713 wined3d_mutex_lock();
3714 wined3d_device_decref(device->wined3d_device);
3715 wined3d_mutex_unlock();
3717 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3718 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3719 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3720 wine_rb_destroy(&device->blend_states, NULL, NULL);
3723 return refcount;
3726 /* IUnknown methods */
3728 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3729 void **ppv)
3731 struct d3d_device *device = impl_from_ID3D10Device(iface);
3732 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3735 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3737 struct d3d_device *device = impl_from_ID3D10Device(iface);
3738 return IUnknown_AddRef(device->outer_unk);
3741 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3743 struct d3d_device *device = impl_from_ID3D10Device(iface);
3744 return IUnknown_Release(device->outer_unk);
3747 /* ID3D10Device methods */
3749 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3750 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3752 struct d3d_device *device = impl_from_ID3D10Device(iface);
3753 unsigned int i;
3755 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3756 iface, start_slot, buffer_count, buffers);
3758 wined3d_mutex_lock();
3759 for (i = 0; i < buffer_count; ++i)
3761 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3763 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3764 buffer ? buffer->wined3d_buffer : NULL);
3766 wined3d_mutex_unlock();
3769 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3770 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3772 struct d3d_device *device = impl_from_ID3D10Device(iface);
3773 unsigned int i;
3775 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3776 iface, start_slot, view_count, views);
3778 wined3d_mutex_lock();
3779 for (i = 0; i < view_count; ++i)
3781 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3783 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3784 view ? view->wined3d_view : NULL);
3786 wined3d_mutex_unlock();
3789 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3790 ID3D10PixelShader *shader)
3792 struct d3d_device *device = impl_from_ID3D10Device(iface);
3793 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3795 TRACE("iface %p, shader %p\n", iface, shader);
3797 wined3d_mutex_lock();
3798 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3799 wined3d_mutex_unlock();
3802 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3803 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3805 struct d3d_device *device = impl_from_ID3D10Device(iface);
3806 unsigned int i;
3808 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3809 iface, start_slot, sampler_count, samplers);
3811 wined3d_mutex_lock();
3812 for (i = 0; i < sampler_count; ++i)
3814 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3816 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3817 sampler ? sampler->wined3d_sampler : NULL);
3819 wined3d_mutex_unlock();
3822 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3823 ID3D10VertexShader *shader)
3825 struct d3d_device *device = impl_from_ID3D10Device(iface);
3826 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3828 TRACE("iface %p, shader %p\n", iface, shader);
3830 wined3d_mutex_lock();
3831 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3832 wined3d_mutex_unlock();
3835 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3836 UINT start_index_location, INT base_vertex_location)
3838 struct d3d_device *device = impl_from_ID3D10Device(iface);
3840 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3841 iface, index_count, start_index_location, base_vertex_location);
3843 wined3d_mutex_lock();
3844 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3845 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3846 wined3d_mutex_unlock();
3849 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3850 UINT start_vertex_location)
3852 struct d3d_device *device = impl_from_ID3D10Device(iface);
3854 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3855 iface, vertex_count, start_vertex_location);
3857 wined3d_mutex_lock();
3858 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3859 wined3d_mutex_unlock();
3862 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
3863 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3865 struct d3d_device *device = impl_from_ID3D10Device(iface);
3866 unsigned int i;
3868 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3869 iface, start_slot, buffer_count, buffers);
3871 wined3d_mutex_lock();
3872 for (i = 0; i < buffer_count; ++i)
3874 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3876 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
3877 buffer ? buffer->wined3d_buffer : NULL);
3879 wined3d_mutex_unlock();
3882 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3883 ID3D10InputLayout *input_layout)
3885 struct d3d_device *device = impl_from_ID3D10Device(iface);
3886 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3888 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3890 wined3d_mutex_lock();
3891 wined3d_device_set_vertex_declaration(device->wined3d_device,
3892 layout ? layout->wined3d_decl : NULL);
3893 wined3d_mutex_unlock();
3896 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3897 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3899 struct d3d_device *device = impl_from_ID3D10Device(iface);
3900 unsigned int i;
3902 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3903 iface, start_slot, buffer_count, buffers, strides, offsets);
3905 wined3d_mutex_lock();
3906 for (i = 0; i < buffer_count; ++i)
3908 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3910 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3911 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3913 wined3d_mutex_unlock();
3916 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3917 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3919 struct d3d_device *device = impl_from_ID3D10Device(iface);
3920 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3922 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3923 iface, buffer, debug_dxgi_format(format), offset);
3925 wined3d_mutex_lock();
3926 wined3d_device_set_index_buffer(device->wined3d_device,
3927 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3928 wined3dformat_from_dxgi_format(format), offset);
3929 wined3d_mutex_unlock();
3932 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3933 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3934 INT base_vertex_location, UINT start_instance_location)
3936 struct d3d_device *device = impl_from_ID3D10Device(iface);
3938 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3939 "base_vertex_location %d, start_instance_location %u.\n",
3940 iface, instance_index_count, instance_count, start_index_location,
3941 base_vertex_location, start_instance_location);
3943 wined3d_mutex_lock();
3944 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3945 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3946 instance_index_count, start_instance_location, instance_count);
3947 wined3d_mutex_unlock();
3950 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3951 UINT instance_vertex_count, UINT instance_count,
3952 UINT start_vertex_location, UINT start_instance_location)
3954 struct d3d_device *device = impl_from_ID3D10Device(iface);
3956 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3957 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3958 start_vertex_location, start_instance_location);
3960 wined3d_mutex_lock();
3961 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3962 instance_vertex_count, start_instance_location, instance_count);
3963 wined3d_mutex_unlock();
3966 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3967 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3969 struct d3d_device *device = impl_from_ID3D10Device(iface);
3970 unsigned int i;
3972 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3973 iface, start_slot, buffer_count, buffers);
3975 wined3d_mutex_lock();
3976 for (i = 0; i < buffer_count; ++i)
3978 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3980 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3981 buffer ? buffer->wined3d_buffer : NULL);
3983 wined3d_mutex_unlock();
3986 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3988 struct d3d_device *device = impl_from_ID3D10Device(iface);
3989 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3991 TRACE("iface %p, shader %p.\n", iface, shader);
3993 wined3d_mutex_lock();
3994 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3995 wined3d_mutex_unlock();
3998 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3999 D3D10_PRIMITIVE_TOPOLOGY topology)
4001 struct d3d_device *device = impl_from_ID3D10Device(iface);
4003 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
4005 wined3d_mutex_lock();
4006 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology, 0);
4007 wined3d_mutex_unlock();
4010 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
4011 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4013 struct d3d_device *device = impl_from_ID3D10Device(iface);
4014 unsigned int i;
4016 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4017 iface, start_slot, view_count, views);
4019 wined3d_mutex_lock();
4020 for (i = 0; i < view_count; ++i)
4022 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4024 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
4025 view ? view->wined3d_view : NULL);
4027 wined3d_mutex_unlock();
4030 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
4031 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4033 struct d3d_device *device = impl_from_ID3D10Device(iface);
4034 unsigned int i;
4036 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4037 iface, start_slot, sampler_count, samplers);
4039 wined3d_mutex_lock();
4040 for (i = 0; i < sampler_count; ++i)
4042 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4044 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
4045 sampler ? sampler->wined3d_sampler : NULL);
4047 wined3d_mutex_unlock();
4050 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
4052 struct d3d_device *device = impl_from_ID3D10Device(iface);
4053 struct d3d_query *query;
4055 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
4057 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
4058 wined3d_mutex_lock();
4059 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
4060 wined3d_mutex_unlock();
4063 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4064 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4066 struct d3d_device *device = impl_from_ID3D10Device(iface);
4067 unsigned int i;
4069 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4070 iface, start_slot, view_count, views);
4072 wined3d_mutex_lock();
4073 for (i = 0; i < view_count; ++i)
4075 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4077 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
4078 view ? view->wined3d_view : NULL);
4080 wined3d_mutex_unlock();
4083 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4084 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4086 struct d3d_device *device = impl_from_ID3D10Device(iface);
4087 unsigned int i;
4089 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4090 iface, start_slot, sampler_count, samplers);
4092 wined3d_mutex_lock();
4093 for (i = 0; i < sampler_count; ++i)
4095 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4097 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
4098 sampler ? sampler->wined3d_sampler : NULL);
4100 wined3d_mutex_unlock();
4103 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4104 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4105 ID3D10DepthStencilView *depth_stencil_view)
4107 struct d3d_device *device = impl_from_ID3D10Device(iface);
4108 struct d3d_depthstencil_view *dsv;
4109 unsigned int i;
4111 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4112 iface, render_target_view_count, render_target_views, depth_stencil_view);
4114 wined3d_mutex_lock();
4115 for (i = 0; i < render_target_view_count; ++i)
4117 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4119 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
4120 rtv ? rtv->wined3d_view : NULL, FALSE);
4122 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4124 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4127 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4128 wined3d_device_set_depth_stencil_view(device->wined3d_device,
4129 dsv ? dsv->wined3d_view : NULL);
4130 wined3d_mutex_unlock();
4133 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4134 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4136 struct d3d_device *device = impl_from_ID3D10Device(iface);
4137 struct d3d_blend_state *blend_state_object;
4139 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4140 iface, blend_state, debug_float4(blend_factor), sample_mask);
4142 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4143 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4144 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4147 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4148 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4150 struct d3d_device *device = impl_from_ID3D10Device(iface);
4151 struct d3d_depthstencil_state *ds_state_object;
4153 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4154 iface, depth_stencil_state, stencil_ref);
4156 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4157 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4158 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4161 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4162 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4164 struct d3d_device *device = impl_from_ID3D10Device(iface);
4165 unsigned int count, i;
4167 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4169 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4170 wined3d_mutex_lock();
4171 for (i = 0; i < count; ++i)
4173 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4175 wined3d_device_set_stream_output(device->wined3d_device, i,
4176 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4179 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4181 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4183 wined3d_mutex_unlock();
4186 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4188 FIXME("iface %p stub!\n", iface);
4191 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4193 struct d3d_device *device = impl_from_ID3D10Device(iface);
4194 struct d3d_rasterizer_state *rasterizer_state_object;
4196 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4198 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4199 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
4200 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4203 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4204 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4206 struct d3d_device *device = impl_from_ID3D10Device(iface);
4207 struct wined3d_viewport wined3d_vp;
4209 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4211 if (viewport_count > 1)
4212 FIXME("Multiple viewports not implemented.\n");
4214 if (!viewport_count)
4215 return;
4217 wined3d_vp.x = viewports[0].TopLeftX;
4218 wined3d_vp.y = viewports[0].TopLeftY;
4219 wined3d_vp.width = viewports[0].Width;
4220 wined3d_vp.height = viewports[0].Height;
4221 wined3d_vp.min_z = viewports[0].MinDepth;
4222 wined3d_vp.max_z = viewports[0].MaxDepth;
4224 wined3d_mutex_lock();
4225 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
4226 wined3d_mutex_unlock();
4229 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4230 UINT rect_count, const D3D10_RECT *rects)
4232 struct d3d_device *device = impl_from_ID3D10Device(iface);
4234 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4236 if (rect_count > 1)
4237 FIXME("Multiple scissor rects not implemented.\n");
4239 if (!rect_count)
4240 return;
4242 wined3d_mutex_lock();
4243 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
4244 wined3d_mutex_unlock();
4247 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4248 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4249 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4251 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4252 struct d3d_device *device = impl_from_ID3D10Device(iface);
4253 struct wined3d_box wined3d_src_box;
4255 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4256 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4257 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4258 src_resource, src_subresource_idx, src_box);
4260 if (src_box)
4261 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4262 src_box->right, src_box->bottom, src_box->front, src_box->back);
4264 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4265 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4266 wined3d_mutex_lock();
4267 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
4268 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
4269 wined3d_mutex_unlock();
4272 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4273 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4275 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4276 struct d3d_device *device = impl_from_ID3D10Device(iface);
4278 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4280 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4281 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4282 wined3d_mutex_lock();
4283 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
4284 wined3d_mutex_unlock();
4287 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4288 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4289 const void *data, UINT row_pitch, UINT depth_pitch)
4291 struct d3d_device *device = impl_from_ID3D10Device(iface);
4292 ID3D11Resource *d3d11_resource;
4294 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4295 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4297 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4298 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
4299 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4300 ID3D11Resource_Release(d3d11_resource);
4303 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4304 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4306 struct d3d_device *device = impl_from_ID3D10Device(iface);
4307 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4308 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4309 HRESULT hr;
4311 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4312 iface, render_target_view, debug_float4(color_rgba));
4314 if (!view)
4315 return;
4317 wined3d_mutex_lock();
4318 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4319 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4320 ERR("Failed to clear view, hr %#x.\n", hr);
4321 wined3d_mutex_unlock();
4324 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4325 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4327 struct d3d_device *device = impl_from_ID3D10Device(iface);
4328 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4329 DWORD wined3d_flags;
4330 HRESULT hr;
4332 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4333 iface, depth_stencil_view, flags, depth, stencil);
4335 if (!view)
4336 return;
4338 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4340 wined3d_mutex_lock();
4341 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4342 wined3d_flags, NULL, depth, stencil)))
4343 ERR("Failed to clear view, hr %#x.\n", hr);
4344 wined3d_mutex_unlock();
4347 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4348 ID3D10ShaderResourceView *shader_resource_view)
4350 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
4353 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4354 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4355 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4357 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
4358 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
4359 iface, dst_resource, dst_subresource_idx,
4360 src_resource, src_subresource_idx, debug_dxgi_format(format));
4363 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
4364 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4366 struct d3d_device *device = impl_from_ID3D10Device(iface);
4367 unsigned int i;
4369 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4370 iface, start_slot, buffer_count, buffers);
4372 wined3d_mutex_lock();
4373 for (i = 0; i < buffer_count; ++i)
4375 struct wined3d_buffer *wined3d_buffer;
4376 struct d3d_buffer *buffer_impl;
4378 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
4380 buffers[i] = NULL;
4381 continue;
4384 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4385 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4386 ID3D10Buffer_AddRef(buffers[i]);
4388 wined3d_mutex_unlock();
4391 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
4392 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4394 struct d3d_device *device = impl_from_ID3D10Device(iface);
4395 unsigned int i;
4397 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4398 iface, start_slot, view_count, views);
4400 wined3d_mutex_lock();
4401 for (i = 0; i < view_count; ++i)
4403 struct wined3d_shader_resource_view *wined3d_view;
4404 struct d3d_shader_resource_view *view_impl;
4406 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
4408 views[i] = NULL;
4409 continue;
4412 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4413 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4414 ID3D10ShaderResourceView_AddRef(views[i]);
4416 wined3d_mutex_unlock();
4419 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
4421 struct d3d_device *device = impl_from_ID3D10Device(iface);
4422 struct d3d_pixel_shader *shader_impl;
4423 struct wined3d_shader *wined3d_shader;
4425 TRACE("iface %p, shader %p.\n", iface, shader);
4427 wined3d_mutex_lock();
4428 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
4430 wined3d_mutex_unlock();
4431 *shader = NULL;
4432 return;
4435 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4436 wined3d_mutex_unlock();
4437 *shader = &shader_impl->ID3D10PixelShader_iface;
4438 ID3D10PixelShader_AddRef(*shader);
4441 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
4442 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4444 struct d3d_device *device = impl_from_ID3D10Device(iface);
4445 unsigned int i;
4447 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4448 iface, start_slot, sampler_count, samplers);
4450 wined3d_mutex_lock();
4451 for (i = 0; i < sampler_count; ++i)
4453 struct d3d_sampler_state *sampler_impl;
4454 struct wined3d_sampler *wined3d_sampler;
4456 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
4458 samplers[i] = NULL;
4459 continue;
4462 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4463 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4464 ID3D10SamplerState_AddRef(samplers[i]);
4466 wined3d_mutex_unlock();
4469 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
4471 struct d3d_device *device = impl_from_ID3D10Device(iface);
4472 struct d3d_vertex_shader *shader_impl;
4473 struct wined3d_shader *wined3d_shader;
4475 TRACE("iface %p, shader %p.\n", iface, shader);
4477 wined3d_mutex_lock();
4478 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
4480 wined3d_mutex_unlock();
4481 *shader = NULL;
4482 return;
4485 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4486 wined3d_mutex_unlock();
4487 *shader = &shader_impl->ID3D10VertexShader_iface;
4488 ID3D10VertexShader_AddRef(*shader);
4491 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
4492 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4494 struct d3d_device *device = impl_from_ID3D10Device(iface);
4495 unsigned int i;
4497 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4498 iface, start_slot, buffer_count, buffers);
4500 wined3d_mutex_lock();
4501 for (i = 0; i < buffer_count; ++i)
4503 struct wined3d_buffer *wined3d_buffer;
4504 struct d3d_buffer *buffer_impl;
4506 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
4508 buffers[i] = NULL;
4509 continue;
4512 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4513 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4514 ID3D10Buffer_AddRef(buffers[i]);
4516 wined3d_mutex_unlock();
4519 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
4521 struct d3d_device *device = impl_from_ID3D10Device(iface);
4522 struct wined3d_vertex_declaration *wined3d_declaration;
4523 struct d3d_input_layout *input_layout_impl;
4525 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
4527 wined3d_mutex_lock();
4528 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
4530 wined3d_mutex_unlock();
4531 *input_layout = NULL;
4532 return;
4535 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
4536 wined3d_mutex_unlock();
4537 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
4538 ID3D10InputLayout_AddRef(*input_layout);
4541 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
4542 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
4544 struct d3d_device *device = impl_from_ID3D10Device(iface);
4545 unsigned int i;
4547 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
4548 iface, start_slot, buffer_count, buffers, strides, offsets);
4550 wined3d_mutex_lock();
4551 for (i = 0; i < buffer_count; ++i)
4553 struct wined3d_buffer *wined3d_buffer = NULL;
4554 struct d3d_buffer *buffer_impl;
4556 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
4557 &wined3d_buffer, &offsets[i], &strides[i])))
4558 ERR("Failed to get vertex buffer.\n");
4560 if (!wined3d_buffer)
4562 buffers[i] = NULL;
4563 continue;
4566 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4567 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4568 ID3D10Buffer_AddRef(buffers[i]);
4570 wined3d_mutex_unlock();
4573 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
4574 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
4576 struct d3d_device *device = impl_from_ID3D10Device(iface);
4577 enum wined3d_format_id wined3d_format;
4578 struct wined3d_buffer *wined3d_buffer;
4579 struct d3d_buffer *buffer_impl;
4581 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
4583 wined3d_mutex_lock();
4584 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
4585 *format = dxgi_format_from_wined3dformat(wined3d_format);
4586 if (!wined3d_buffer)
4588 wined3d_mutex_unlock();
4589 *buffer = NULL;
4590 return;
4593 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4594 wined3d_mutex_unlock();
4595 *buffer = &buffer_impl->ID3D10Buffer_iface;
4596 ID3D10Buffer_AddRef(*buffer);
4599 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
4600 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4602 struct d3d_device *device = impl_from_ID3D10Device(iface);
4603 unsigned int i;
4605 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4606 iface, start_slot, buffer_count, buffers);
4608 wined3d_mutex_lock();
4609 for (i = 0; i < buffer_count; ++i)
4611 struct wined3d_buffer *wined3d_buffer;
4612 struct d3d_buffer *buffer_impl;
4614 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
4616 buffers[i] = NULL;
4617 continue;
4620 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4621 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4622 ID3D10Buffer_AddRef(buffers[i]);
4624 wined3d_mutex_unlock();
4627 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
4629 struct d3d_device *device = impl_from_ID3D10Device(iface);
4630 struct d3d_geometry_shader *shader_impl;
4631 struct wined3d_shader *wined3d_shader;
4633 TRACE("iface %p, shader %p.\n", iface, shader);
4635 wined3d_mutex_lock();
4636 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
4638 wined3d_mutex_unlock();
4639 *shader = NULL;
4640 return;
4643 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4644 wined3d_mutex_unlock();
4645 *shader = &shader_impl->ID3D10GeometryShader_iface;
4646 ID3D10GeometryShader_AddRef(*shader);
4649 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
4650 D3D10_PRIMITIVE_TOPOLOGY *topology)
4652 struct d3d_device *device = impl_from_ID3D10Device(iface);
4654 TRACE("iface %p, topology %p.\n", iface, topology);
4656 wined3d_mutex_lock();
4657 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology, NULL);
4658 wined3d_mutex_unlock();
4661 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
4662 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4664 struct d3d_device *device = impl_from_ID3D10Device(iface);
4665 unsigned int i;
4667 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4668 iface, start_slot, view_count, views);
4670 wined3d_mutex_lock();
4671 for (i = 0; i < view_count; ++i)
4673 struct wined3d_shader_resource_view *wined3d_view;
4674 struct d3d_shader_resource_view *view_impl;
4676 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
4678 views[i] = NULL;
4679 continue;
4682 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4683 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4684 ID3D10ShaderResourceView_AddRef(views[i]);
4686 wined3d_mutex_unlock();
4689 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
4690 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4692 struct d3d_device *device = impl_from_ID3D10Device(iface);
4693 unsigned int i;
4695 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4696 iface, start_slot, sampler_count, samplers);
4698 wined3d_mutex_lock();
4699 for (i = 0; i < sampler_count; ++i)
4701 struct d3d_sampler_state *sampler_impl;
4702 struct wined3d_sampler *wined3d_sampler;
4704 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4706 samplers[i] = NULL;
4707 continue;
4710 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4711 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4712 ID3D10SamplerState_AddRef(samplers[i]);
4714 wined3d_mutex_unlock();
4717 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4718 ID3D10Predicate **predicate, BOOL *value)
4720 struct d3d_device *device = impl_from_ID3D10Device(iface);
4721 struct wined3d_query *wined3d_predicate;
4722 struct d3d_query *predicate_impl;
4724 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4726 wined3d_mutex_lock();
4727 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4729 wined3d_mutex_unlock();
4730 *predicate = NULL;
4731 return;
4734 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4735 wined3d_mutex_unlock();
4736 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4737 ID3D10Predicate_AddRef(*predicate);
4740 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4741 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4743 struct d3d_device *device = impl_from_ID3D10Device(iface);
4744 unsigned int i;
4746 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4747 iface, start_slot, view_count, views);
4749 wined3d_mutex_lock();
4750 for (i = 0; i < view_count; ++i)
4752 struct wined3d_shader_resource_view *wined3d_view;
4753 struct d3d_shader_resource_view *view_impl;
4755 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4757 views[i] = NULL;
4758 continue;
4761 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4762 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4763 ID3D10ShaderResourceView_AddRef(views[i]);
4765 wined3d_mutex_unlock();
4768 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4769 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4771 struct d3d_device *device = impl_from_ID3D10Device(iface);
4772 unsigned int i;
4774 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4775 iface, start_slot, sampler_count, samplers);
4777 wined3d_mutex_lock();
4778 for (i = 0; i < sampler_count; ++i)
4780 struct d3d_sampler_state *sampler_impl;
4781 struct wined3d_sampler *wined3d_sampler;
4783 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4785 samplers[i] = NULL;
4786 continue;
4789 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4790 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4791 ID3D10SamplerState_AddRef(samplers[i]);
4793 wined3d_mutex_unlock();
4796 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4797 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4799 struct d3d_device *device = impl_from_ID3D10Device(iface);
4800 struct wined3d_rendertarget_view *wined3d_view;
4802 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4803 iface, view_count, render_target_views, depth_stencil_view);
4805 wined3d_mutex_lock();
4806 if (render_target_views)
4808 struct d3d_rendertarget_view *view_impl;
4809 unsigned int i;
4811 for (i = 0; i < view_count; ++i)
4813 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4814 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4816 render_target_views[i] = NULL;
4817 continue;
4820 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4821 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4825 if (depth_stencil_view)
4827 struct d3d_depthstencil_view *view_impl;
4829 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4830 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4832 *depth_stencil_view = NULL;
4834 else
4836 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4837 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4840 wined3d_mutex_unlock();
4843 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4844 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4846 struct d3d_device *device = impl_from_ID3D10Device(iface);
4847 ID3D11BlendState *d3d11_blend_state;
4849 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4850 iface, blend_state, blend_factor, sample_mask);
4852 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4853 &d3d11_blend_state, blend_factor, sample_mask);
4855 if (d3d11_blend_state)
4856 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4857 else
4858 *blend_state = NULL;
4861 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4862 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4864 struct d3d_device *device = impl_from_ID3D10Device(iface);
4865 ID3D11DepthStencilState *d3d11_iface;
4867 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4868 iface, depth_stencil_state, stencil_ref);
4870 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4871 &d3d11_iface, stencil_ref);
4873 if (d3d11_iface)
4874 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4875 else
4876 *depth_stencil_state = NULL;
4879 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4880 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4882 struct d3d_device *device = impl_from_ID3D10Device(iface);
4883 unsigned int i;
4885 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4886 iface, buffer_count, buffers, offsets);
4888 wined3d_mutex_lock();
4889 for (i = 0; i < buffer_count; ++i)
4891 struct wined3d_buffer *wined3d_buffer;
4892 struct d3d_buffer *buffer_impl;
4894 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4896 buffers[i] = NULL;
4897 continue;
4900 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4901 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4902 ID3D10Buffer_AddRef(buffers[i]);
4904 wined3d_mutex_unlock();
4907 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4909 struct d3d_device *device = impl_from_ID3D10Device(iface);
4910 struct d3d_rasterizer_state *rasterizer_state_impl;
4911 struct wined3d_rasterizer_state *wined3d_state;
4913 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4915 wined3d_mutex_lock();
4916 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
4918 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
4919 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
4921 else
4923 *rasterizer_state = NULL;
4925 wined3d_mutex_unlock();
4928 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4929 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4931 struct d3d_device *device = impl_from_ID3D10Device(iface);
4932 struct wined3d_viewport wined3d_vp;
4934 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4936 if (!viewports)
4938 *viewport_count = 1;
4939 return;
4942 if (!*viewport_count)
4943 return;
4945 wined3d_mutex_lock();
4946 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4947 wined3d_mutex_unlock();
4949 viewports[0].TopLeftX = wined3d_vp.x;
4950 viewports[0].TopLeftY = wined3d_vp.y;
4951 viewports[0].Width = wined3d_vp.width;
4952 viewports[0].Height = wined3d_vp.height;
4953 viewports[0].MinDepth = wined3d_vp.min_z;
4954 viewports[0].MaxDepth = wined3d_vp.max_z;
4956 if (*viewport_count > 1)
4957 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4960 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4962 struct d3d_device *device = impl_from_ID3D10Device(iface);
4964 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4966 if (!rects)
4968 *rect_count = 1;
4969 return;
4972 if (!*rect_count)
4973 return;
4975 wined3d_mutex_lock();
4976 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4977 wined3d_mutex_unlock();
4978 if (*rect_count > 1)
4979 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4982 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4984 TRACE("iface %p.\n", iface);
4986 /* In the current implementation the device is never removed, so we can
4987 * just return S_OK here. */
4989 return S_OK;
4992 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4994 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4996 return E_NOTIMPL;
4999 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
5001 FIXME("iface %p stub!\n", iface);
5003 return 0;
5006 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
5007 REFGUID guid, UINT *data_size, void *data)
5009 struct d3d_device *device = impl_from_ID3D10Device(iface);
5011 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5013 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
5016 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
5017 REFGUID guid, UINT data_size, const void *data)
5019 struct d3d_device *device = impl_from_ID3D10Device(iface);
5021 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
5023 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
5026 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
5027 REFGUID guid, const IUnknown *data)
5029 struct d3d_device *device = impl_from_ID3D10Device(iface);
5031 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
5033 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
5036 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
5038 struct d3d_device *device = impl_from_ID3D10Device(iface);
5040 TRACE("iface %p.\n", iface);
5042 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext_iface);
5045 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
5047 FIXME("iface %p stub!\n", iface);
5050 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
5051 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
5053 struct d3d_device *device = impl_from_ID3D10Device(iface);
5054 D3D11_BUFFER_DESC d3d11_desc;
5055 struct d3d_buffer *object;
5056 HRESULT hr;
5058 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5060 d3d11_desc.ByteWidth = desc->ByteWidth;
5061 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5062 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5063 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5064 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5065 d3d11_desc.StructureByteStride = 0;
5067 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5068 return hr;
5070 *buffer = &object->ID3D10Buffer_iface;
5072 return S_OK;
5075 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5076 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5078 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
5080 return E_NOTIMPL;
5083 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5084 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5085 ID3D10Texture2D **texture)
5087 struct d3d_device *device = impl_from_ID3D10Device(iface);
5088 D3D11_TEXTURE2D_DESC d3d11_desc;
5089 struct d3d_texture2d *object;
5090 HRESULT hr;
5092 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5094 d3d11_desc.Width = desc->Width;
5095 d3d11_desc.Height = desc->Height;
5096 d3d11_desc.MipLevels = desc->MipLevels;
5097 d3d11_desc.ArraySize = desc->ArraySize;
5098 d3d11_desc.Format = desc->Format;
5099 d3d11_desc.SampleDesc = desc->SampleDesc;
5100 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5101 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5102 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5103 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5105 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5106 return hr;
5108 *texture = &object->ID3D10Texture2D_iface;
5110 return S_OK;
5113 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5114 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5115 ID3D10Texture3D **texture)
5117 struct d3d_device *device = impl_from_ID3D10Device(iface);
5118 D3D11_TEXTURE3D_DESC d3d11_desc;
5119 struct d3d_texture3d *object;
5120 HRESULT hr;
5122 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5124 d3d11_desc.Width = desc->Width;
5125 d3d11_desc.Height = desc->Height;
5126 d3d11_desc.Depth = desc->Depth;
5127 d3d11_desc.MipLevels = desc->MipLevels;
5128 d3d11_desc.Format = desc->Format;
5129 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5130 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5131 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5132 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5134 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5135 return hr;
5137 *texture = &object->ID3D10Texture3D_iface;
5139 return S_OK;
5142 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5143 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5145 struct d3d_device *device = impl_from_ID3D10Device(iface);
5146 struct d3d_shader_resource_view *object;
5147 ID3D11Resource *d3d11_resource;
5148 HRESULT hr;
5150 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5152 if (!resource)
5153 return E_INVALIDARG;
5155 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5157 ERR("Resource does not implement ID3D11Resource.\n");
5158 return E_FAIL;
5161 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5162 &object);
5163 ID3D11Resource_Release(d3d11_resource);
5164 if (FAILED(hr))
5165 return hr;
5167 *view = &object->ID3D10ShaderResourceView1_iface;
5169 return S_OK;
5172 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5173 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5175 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5177 return d3d10_device_CreateShaderResourceView1(iface, resource,
5178 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5181 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5182 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5184 struct d3d_device *device = impl_from_ID3D10Device(iface);
5185 struct d3d_rendertarget_view *object;
5186 ID3D11Resource *d3d11_resource;
5187 HRESULT hr;
5189 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5191 if (!resource)
5192 return E_INVALIDARG;
5194 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5196 ERR("Resource does not implement ID3D11Resource.\n");
5197 return E_FAIL;
5200 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5201 ID3D11Resource_Release(d3d11_resource);
5202 if (FAILED(hr))
5203 return hr;
5205 *view = &object->ID3D10RenderTargetView_iface;
5207 return S_OK;
5210 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5211 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5213 struct d3d_device *device = impl_from_ID3D10Device(iface);
5214 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5215 struct d3d_depthstencil_view *object;
5216 ID3D11Resource *d3d11_resource;
5217 HRESULT hr;
5219 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5221 if (desc)
5223 d3d11_desc.Format = desc->Format;
5224 d3d11_desc.ViewDimension = desc->ViewDimension;
5225 d3d11_desc.Flags = 0;
5226 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5229 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5231 ERR("Resource does not implement ID3D11Resource.\n");
5232 return E_FAIL;
5235 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5236 ID3D11Resource_Release(d3d11_resource);
5237 if (FAILED(hr))
5238 return hr;
5240 *view = &object->ID3D10DepthStencilView_iface;
5242 return S_OK;
5245 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5246 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5247 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5248 ID3D10InputLayout **input_layout)
5250 struct d3d_device *device = impl_from_ID3D10Device(iface);
5251 struct d3d_input_layout *object;
5252 HRESULT hr;
5254 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5255 "shader_byte_code_length %lu, input_layout %p\n",
5256 iface, element_descs, element_count, shader_byte_code,
5257 shader_byte_code_length, input_layout);
5259 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5260 shader_byte_code, shader_byte_code_length, &object)))
5261 return hr;
5263 *input_layout = &object->ID3D10InputLayout_iface;
5265 return S_OK;
5268 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5269 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5271 struct d3d_device *device = impl_from_ID3D10Device(iface);
5272 struct d3d_vertex_shader *object;
5273 HRESULT hr;
5275 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5276 iface, byte_code, byte_code_length, shader);
5278 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5279 return hr;
5281 *shader = &object->ID3D10VertexShader_iface;
5283 return S_OK;
5286 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5287 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5289 struct d3d_device *device = impl_from_ID3D10Device(iface);
5290 struct d3d_geometry_shader *object;
5291 HRESULT hr;
5293 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5294 iface, byte_code, byte_code_length, shader);
5296 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5297 NULL, 0, NULL, 0, 0, &object)))
5298 return hr;
5300 *shader = &object->ID3D10GeometryShader_iface;
5302 return S_OK;
5305 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5306 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5307 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5309 struct d3d_device *device = impl_from_ID3D10Device(iface);
5310 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5311 struct d3d_geometry_shader *object;
5312 unsigned int i, stride_count = 1;
5313 HRESULT hr;
5315 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5316 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5317 iface, byte_code, byte_code_length, output_stream_decls,
5318 output_stream_decl_count, output_stream_stride, shader);
5320 if (!output_stream_decl_count && output_stream_stride)
5322 WARN("Stride must be 0 when declaration entry count is 0.\n");
5323 *shader = NULL;
5324 return E_INVALIDARG;
5327 if (output_stream_decl_count
5328 && !(so_entries = d3d11_calloc(output_stream_decl_count, sizeof(*so_entries))))
5330 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5331 *shader = NULL;
5332 return E_OUTOFMEMORY;
5335 for (i = 0; i < output_stream_decl_count; ++i)
5337 so_entries[i].Stream = 0;
5338 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5339 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5340 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5341 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5342 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5344 if (output_stream_decls[i].OutputSlot)
5346 stride_count = 0;
5347 if (output_stream_stride)
5349 WARN("Stride must be 0 when multiple output slots are used.\n");
5350 HeapFree(GetProcessHeap(), 0, so_entries);
5351 *shader = NULL;
5352 return E_INVALIDARG;
5357 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5358 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5359 HeapFree(GetProcessHeap(), 0, so_entries);
5360 if (FAILED(hr))
5362 *shader = NULL;
5363 return hr;
5366 *shader = &object->ID3D10GeometryShader_iface;
5368 return hr;
5371 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5372 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5374 struct d3d_device *device = impl_from_ID3D10Device(iface);
5375 struct d3d_pixel_shader *object;
5376 HRESULT hr;
5378 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5379 iface, byte_code, byte_code_length, shader);
5381 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
5382 return hr;
5384 *shader = &object->ID3D10PixelShader_iface;
5386 return S_OK;
5389 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
5390 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
5392 struct d3d_device *device = impl_from_ID3D10Device(iface);
5393 ID3D11BlendState *d3d11_blend_state;
5394 HRESULT hr;
5396 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5398 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
5399 &d3d11_blend_state)))
5400 return hr;
5402 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
5403 ID3D11BlendState_Release(d3d11_blend_state);
5404 return hr;
5407 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
5408 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
5410 D3D10_BLEND_DESC1 d3d10_1_desc;
5411 unsigned int i;
5413 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5415 if (!desc)
5416 return E_INVALIDARG;
5418 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
5419 d3d10_1_desc.IndependentBlendEnable = FALSE;
5420 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
5422 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
5423 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
5424 d3d10_1_desc.IndependentBlendEnable = TRUE;
5427 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5429 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
5430 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
5431 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
5432 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
5433 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
5434 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
5435 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
5436 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
5439 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
5442 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
5443 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
5445 struct d3d_device *device = impl_from_ID3D10Device(iface);
5446 ID3D11DepthStencilState *d3d11_depth_stencil_state;
5447 HRESULT hr;
5449 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
5451 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
5452 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
5453 return hr;
5455 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
5456 (void **)depth_stencil_state);
5457 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
5458 return hr;
5461 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
5462 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
5464 struct d3d_device *device = impl_from_ID3D10Device(iface);
5465 ID3D11RasterizerState *d3d11_rasterizer_state;
5466 HRESULT hr;
5468 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
5470 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
5471 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
5472 return hr;
5474 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
5475 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
5476 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
5477 return hr;
5480 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
5481 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
5483 struct d3d_device *device = impl_from_ID3D10Device(iface);
5484 ID3D11SamplerState *d3d11_sampler_state;
5485 HRESULT hr;
5487 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
5489 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
5490 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
5491 return hr;
5493 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
5494 ID3D11SamplerState_Release(d3d11_sampler_state);
5495 return hr;
5498 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
5499 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
5501 struct d3d_device *device = impl_from_ID3D10Device(iface);
5502 struct d3d_query *object;
5503 HRESULT hr;
5505 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
5507 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
5508 return hr;
5510 if (query)
5512 *query = &object->ID3D10Query_iface;
5513 return S_OK;
5516 ID3D10Query_Release(&object->ID3D10Query_iface);
5517 return S_FALSE;
5520 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
5521 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
5523 struct d3d_device *device = impl_from_ID3D10Device(iface);
5524 struct d3d_query *object;
5525 HRESULT hr;
5527 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
5529 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
5530 return hr;
5532 if (predicate)
5534 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
5535 return S_OK;
5538 ID3D10Query_Release(&object->ID3D10Query_iface);
5539 return S_FALSE;
5542 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
5543 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
5545 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
5547 return E_NOTIMPL;
5550 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
5551 DXGI_FORMAT format, UINT *format_support)
5553 FIXME("iface %p, format %s, format_support %p stub!\n",
5554 iface, debug_dxgi_format(format), format_support);
5556 return E_NOTIMPL;
5559 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
5560 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
5562 struct d3d_device *device = impl_from_ID3D10Device(iface);
5564 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
5565 iface, debug_dxgi_format(format), sample_count, quality_level_count);
5567 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
5568 sample_count, quality_level_count);
5571 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
5573 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
5576 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
5577 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
5578 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
5580 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
5581 "units %p, units_length %p, description %p, description_length %p stub!\n",
5582 iface, desc, type, active_counters, name, name_length,
5583 units, units_length, description, description_length);
5585 return E_NOTIMPL;
5588 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
5590 FIXME("iface %p stub!\n", iface);
5592 return 0;
5595 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
5596 HANDLE resource_handle, REFIID guid, void **resource)
5598 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
5599 iface, resource_handle, debugstr_guid(guid), resource);
5601 return E_NOTIMPL;
5604 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
5606 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
5609 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
5611 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
5614 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
5616 struct d3d_device *device = impl_from_ID3D10Device(iface);
5618 TRACE("iface %p.\n", iface);
5620 return device->feature_level;
5623 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
5625 /* IUnknown methods */
5626 d3d10_device_QueryInterface,
5627 d3d10_device_AddRef,
5628 d3d10_device_Release,
5629 /* ID3D10Device methods */
5630 d3d10_device_VSSetConstantBuffers,
5631 d3d10_device_PSSetShaderResources,
5632 d3d10_device_PSSetShader,
5633 d3d10_device_PSSetSamplers,
5634 d3d10_device_VSSetShader,
5635 d3d10_device_DrawIndexed,
5636 d3d10_device_Draw,
5637 d3d10_device_PSSetConstantBuffers,
5638 d3d10_device_IASetInputLayout,
5639 d3d10_device_IASetVertexBuffers,
5640 d3d10_device_IASetIndexBuffer,
5641 d3d10_device_DrawIndexedInstanced,
5642 d3d10_device_DrawInstanced,
5643 d3d10_device_GSSetConstantBuffers,
5644 d3d10_device_GSSetShader,
5645 d3d10_device_IASetPrimitiveTopology,
5646 d3d10_device_VSSetShaderResources,
5647 d3d10_device_VSSetSamplers,
5648 d3d10_device_SetPredication,
5649 d3d10_device_GSSetShaderResources,
5650 d3d10_device_GSSetSamplers,
5651 d3d10_device_OMSetRenderTargets,
5652 d3d10_device_OMSetBlendState,
5653 d3d10_device_OMSetDepthStencilState,
5654 d3d10_device_SOSetTargets,
5655 d3d10_device_DrawAuto,
5656 d3d10_device_RSSetState,
5657 d3d10_device_RSSetViewports,
5658 d3d10_device_RSSetScissorRects,
5659 d3d10_device_CopySubresourceRegion,
5660 d3d10_device_CopyResource,
5661 d3d10_device_UpdateSubresource,
5662 d3d10_device_ClearRenderTargetView,
5663 d3d10_device_ClearDepthStencilView,
5664 d3d10_device_GenerateMips,
5665 d3d10_device_ResolveSubresource,
5666 d3d10_device_VSGetConstantBuffers,
5667 d3d10_device_PSGetShaderResources,
5668 d3d10_device_PSGetShader,
5669 d3d10_device_PSGetSamplers,
5670 d3d10_device_VSGetShader,
5671 d3d10_device_PSGetConstantBuffers,
5672 d3d10_device_IAGetInputLayout,
5673 d3d10_device_IAGetVertexBuffers,
5674 d3d10_device_IAGetIndexBuffer,
5675 d3d10_device_GSGetConstantBuffers,
5676 d3d10_device_GSGetShader,
5677 d3d10_device_IAGetPrimitiveTopology,
5678 d3d10_device_VSGetShaderResources,
5679 d3d10_device_VSGetSamplers,
5680 d3d10_device_GetPredication,
5681 d3d10_device_GSGetShaderResources,
5682 d3d10_device_GSGetSamplers,
5683 d3d10_device_OMGetRenderTargets,
5684 d3d10_device_OMGetBlendState,
5685 d3d10_device_OMGetDepthStencilState,
5686 d3d10_device_SOGetTargets,
5687 d3d10_device_RSGetState,
5688 d3d10_device_RSGetViewports,
5689 d3d10_device_RSGetScissorRects,
5690 d3d10_device_GetDeviceRemovedReason,
5691 d3d10_device_SetExceptionMode,
5692 d3d10_device_GetExceptionMode,
5693 d3d10_device_GetPrivateData,
5694 d3d10_device_SetPrivateData,
5695 d3d10_device_SetPrivateDataInterface,
5696 d3d10_device_ClearState,
5697 d3d10_device_Flush,
5698 d3d10_device_CreateBuffer,
5699 d3d10_device_CreateTexture1D,
5700 d3d10_device_CreateTexture2D,
5701 d3d10_device_CreateTexture3D,
5702 d3d10_device_CreateShaderResourceView,
5703 d3d10_device_CreateRenderTargetView,
5704 d3d10_device_CreateDepthStencilView,
5705 d3d10_device_CreateInputLayout,
5706 d3d10_device_CreateVertexShader,
5707 d3d10_device_CreateGeometryShader,
5708 d3d10_device_CreateGeometryShaderWithStreamOutput,
5709 d3d10_device_CreatePixelShader,
5710 d3d10_device_CreateBlendState,
5711 d3d10_device_CreateDepthStencilState,
5712 d3d10_device_CreateRasterizerState,
5713 d3d10_device_CreateSamplerState,
5714 d3d10_device_CreateQuery,
5715 d3d10_device_CreatePredicate,
5716 d3d10_device_CreateCounter,
5717 d3d10_device_CheckFormatSupport,
5718 d3d10_device_CheckMultisampleQualityLevels,
5719 d3d10_device_CheckCounterInfo,
5720 d3d10_device_CheckCounter,
5721 d3d10_device_GetCreationFlags,
5722 d3d10_device_OpenSharedResource,
5723 d3d10_device_SetTextFilterSize,
5724 d3d10_device_GetTextFilterSize,
5725 d3d10_device_CreateShaderResourceView1,
5726 d3d10_device_CreateBlendState1,
5727 d3d10_device_GetFeatureLevel,
5730 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5732 /* IUnknown methods */
5733 d3d_device_inner_QueryInterface,
5734 d3d_device_inner_AddRef,
5735 d3d_device_inner_Release,
5738 /* ID3D10Multithread methods */
5740 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5742 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5745 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5747 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5749 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5751 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5754 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5756 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5758 TRACE("iface %p.\n", iface);
5760 return IUnknown_AddRef(device->outer_unk);
5763 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5765 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5767 TRACE("iface %p.\n", iface);
5769 return IUnknown_Release(device->outer_unk);
5772 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5774 TRACE("iface %p.\n", iface);
5776 wined3d_mutex_lock();
5779 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5781 TRACE("iface %p.\n", iface);
5783 wined3d_mutex_unlock();
5786 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5788 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5790 return TRUE;
5793 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5795 FIXME("iface %p stub!\n", iface);
5797 return TRUE;
5800 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5802 d3d10_multithread_QueryInterface,
5803 d3d10_multithread_AddRef,
5804 d3d10_multithread_Release,
5805 d3d10_multithread_Enter,
5806 d3d10_multithread_Leave,
5807 d3d10_multithread_SetMultithreadProtected,
5808 d3d10_multithread_GetMultithreadProtected,
5811 /* IWineDXGIDeviceParent IUnknown methods */
5813 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5815 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5818 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5819 REFIID riid, void **ppv)
5821 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5822 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5825 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5827 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5828 return IUnknown_AddRef(device->outer_unk);
5831 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5833 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5834 return IUnknown_Release(device->outer_unk);
5837 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5838 IWineDXGIDeviceParent *iface)
5840 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5841 return &device->device_parent;
5844 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5846 /* IUnknown methods */
5847 dxgi_device_parent_QueryInterface,
5848 dxgi_device_parent_AddRef,
5849 dxgi_device_parent_Release,
5850 /* IWineDXGIDeviceParent methods */
5851 dxgi_device_parent_get_wined3d_device_parent,
5854 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5856 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5859 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5860 struct wined3d_device *wined3d_device)
5862 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5864 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5866 wined3d_device_incref(wined3d_device);
5867 device->wined3d_device = wined3d_device;
5870 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5872 TRACE("device_parent %p.\n", device_parent);
5875 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5877 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5880 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5881 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5882 const struct wined3d_parent_ops **parent_ops)
5884 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5885 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5887 *parent = NULL;
5888 *parent_ops = &d3d_null_wined3d_parent_ops;
5890 return S_OK;
5893 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5894 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
5895 struct wined3d_texture **wined3d_texture)
5897 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5898 struct d3d_texture2d *texture;
5899 ID3D10Texture2D *texture_iface;
5900 D3D10_TEXTURE2D_DESC desc;
5901 HRESULT hr;
5903 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, texture flags %#x, "
5904 "wined3d_texture %p partial stub!\n", device_parent, container_parent,
5905 wined3d_desc, texture_flags, wined3d_texture);
5907 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5909 desc.Width = wined3d_desc->width;
5910 desc.Height = wined3d_desc->height;
5911 desc.MipLevels = 1;
5912 desc.ArraySize = 1;
5913 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5914 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5915 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5916 desc.Usage = D3D10_USAGE_DEFAULT;
5917 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5918 desc.CPUAccessFlags = 0;
5919 desc.MiscFlags = 0;
5921 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
5923 desc.MiscFlags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
5924 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
5927 if (texture_flags)
5928 FIXME("Unhandled flags %#x.\n", texture_flags);
5930 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5931 &desc, NULL, &texture_iface)))
5933 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5934 return hr;
5937 texture = impl_from_ID3D10Texture2D(texture_iface);
5939 *wined3d_texture = texture->wined3d_texture;
5940 wined3d_texture_incref(*wined3d_texture);
5941 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5943 return S_OK;
5946 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5947 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5949 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5950 IWineDXGIDevice *wine_device;
5951 HRESULT hr;
5953 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5955 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5956 &IID_IWineDXGIDevice, (void **)&wine_device)))
5958 ERR("Device should implement IWineDXGIDevice.\n");
5959 return E_FAIL;
5962 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5963 IWineDXGIDevice_Release(wine_device);
5964 if (FAILED(hr))
5966 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5967 return hr;
5970 return S_OK;
5973 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5975 device_parent_wined3d_device_created,
5976 device_parent_mode_changed,
5977 device_parent_activate,
5978 device_parent_sub_resource_created,
5979 device_parent_sub_resource_created,
5980 device_parent_create_swapchain_texture,
5981 device_parent_create_swapchain,
5984 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5986 const D3D11_SAMPLER_DESC *ka = key;
5987 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5989 return memcmp(ka, kb, sizeof(*ka));
5992 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5994 const D3D11_BLEND_DESC *ka = key;
5995 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5997 return memcmp(ka, kb, sizeof(*ka));
6000 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
6002 const D3D11_DEPTH_STENCIL_DESC *ka = key;
6003 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
6004 const struct d3d_depthstencil_state, entry)->desc;
6006 return memcmp(ka, kb, sizeof(*ka));
6009 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
6011 const D3D11_RASTERIZER_DESC *ka = key;
6012 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
6014 return memcmp(ka, kb, sizeof(*ka));
6017 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
6019 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
6020 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
6021 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
6022 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
6023 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
6024 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
6025 device->refcount = 1;
6026 /* COM aggregation always takes place */
6027 device->outer_unk = outer_unknown;
6029 d3d11_immediate_context_init(&device->immediate_context, device);
6030 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
6032 device->blend_factor[0] = 1.0f;
6033 device->blend_factor[1] = 1.0f;
6034 device->blend_factor[2] = 1.0f;
6035 device->blend_factor[3] = 1.0f;
6037 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
6038 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
6039 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
6040 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);