ddraw/tests: Rewrite LimitTest().
[wine.git] / dlls / d3d11 / device.c
blobb2a40b3c6d31e22d004d607f7b47076ba8cab7bc
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, ~0u);
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 wined3d_device_set_unordered_access_view(device->wined3d_device,
672 unordered_access_view_start_slot + i,
673 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
675 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
677 wined3d_device_set_unordered_access_view(device->wined3d_device,
678 unordered_access_view_start_slot + i, NULL, ~0u);
680 wined3d_mutex_unlock();
684 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
685 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
687 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
688 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
689 const D3D11_BLEND_DESC *desc;
691 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
692 iface, blend_state, debug_float4(blend_factor), sample_mask);
694 if (!blend_factor)
695 blend_factor = default_blend_factor;
697 wined3d_mutex_lock();
698 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
699 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
700 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
702 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
703 wined3d_device_set_render_state(device->wined3d_device,
704 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
705 wined3d_device_set_render_state(device->wined3d_device,
706 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
707 wined3d_device_set_render_state(device->wined3d_device,
708 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
709 wined3d_device_set_render_state(device->wined3d_device,
710 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
711 wined3d_mutex_unlock();
712 return;
715 desc = &device->blend_state->desc;
716 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
717 desc->RenderTarget[0].BlendEnable);
718 if (desc->RenderTarget[0].BlendEnable)
720 const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0];
722 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, d->SrcBlend);
723 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, d->DestBlend);
724 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, d->BlendOp);
725 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
726 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, d->SrcBlendAlpha);
727 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, d->DestBlendAlpha);
728 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, d->BlendOpAlpha);
730 if (memcmp(blend_factor, default_blend_factor, sizeof(default_blend_factor))
731 && (d->SrcBlend == D3D11_BLEND_BLEND_FACTOR || d->SrcBlend == D3D11_BLEND_INV_BLEND_FACTOR
732 || d->DestBlend == D3D11_BLEND_BLEND_FACTOR || d->DestBlend == D3D11_BLEND_INV_BLEND_FACTOR
733 || d->SrcBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->SrcBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR
734 || d->DestBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->DestBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR))
735 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
737 wined3d_device_set_render_state(device->wined3d_device,
738 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
739 wined3d_device_set_render_state(device->wined3d_device,
740 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
741 wined3d_device_set_render_state(device->wined3d_device,
742 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
743 wined3d_device_set_render_state(device->wined3d_device,
744 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
745 wined3d_mutex_unlock();
748 static void set_default_depth_stencil_state(struct wined3d_device *wined3d_device)
750 wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZENABLE, TRUE);
751 wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
752 wined3d_device_set_render_state(wined3d_device, WINED3D_RS_ZFUNC, WINED3D_CMP_LESS);
753 wined3d_device_set_render_state(wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
756 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
757 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
759 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
760 const D3D11_DEPTH_STENCILOP_DESC *front, *back;
761 const D3D11_DEPTH_STENCIL_DESC *desc;
763 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
764 iface, depth_stencil_state, stencil_ref);
766 wined3d_mutex_lock();
767 device->stencil_ref = stencil_ref;
768 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
770 set_default_depth_stencil_state(device->wined3d_device);
771 wined3d_mutex_unlock();
772 return;
775 desc = &device->depth_stencil_state->desc;
777 front = &desc->FrontFace;
778 back = &desc->BackFace;
780 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
781 if (desc->DepthEnable)
783 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
784 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
787 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
788 if (desc->StencilEnable)
790 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
791 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
792 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
794 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, front->StencilFailOp);
795 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL, front->StencilDepthFailOp);
796 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, front->StencilPassOp);
797 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, front->StencilFunc);
798 if (front->StencilFailOp != back->StencilFailOp
799 || front->StencilDepthFailOp != back->StencilDepthFailOp
800 || front->StencilPassOp != back->StencilPassOp
801 || front->StencilFunc != back->StencilFunc)
803 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, TRUE);
804 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFAIL, back->StencilFailOp);
805 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILZFAIL,
806 back->StencilDepthFailOp);
807 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILPASS, back->StencilPassOp);
808 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFUNC, back->StencilFunc);
810 else
812 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, FALSE);
815 wined3d_mutex_unlock();
818 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
819 ID3D11Buffer *const *buffers, const UINT *offsets)
821 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
822 unsigned int count, i;
824 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
826 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
827 wined3d_mutex_lock();
828 for (i = 0; i < count; ++i)
830 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
832 wined3d_device_set_stream_output(device->wined3d_device, i,
833 buffer ? buffer->wined3d_buffer : NULL, offsets ? offsets[i] : 0);
835 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
837 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
839 wined3d_mutex_unlock();
842 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
844 FIXME("iface %p stub!\n", iface);
847 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
848 ID3D11Buffer *buffer, UINT offset)
850 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
851 struct d3d_buffer *d3d_buffer;
853 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
855 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
857 wined3d_mutex_lock();
858 wined3d_device_draw_indexed_primitive_instanced_indirect(device->wined3d_device,
859 d3d_buffer->wined3d_buffer, offset);
860 wined3d_mutex_unlock();
863 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
864 ID3D11Buffer *buffer, UINT offset)
866 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
867 struct d3d_buffer *d3d_buffer;
869 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
871 d3d_buffer = unsafe_impl_from_ID3D11Buffer(buffer);
873 wined3d_mutex_lock();
874 wined3d_device_draw_primitive_instanced_indirect(device->wined3d_device,
875 d3d_buffer->wined3d_buffer, offset);
876 wined3d_mutex_unlock();
879 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
880 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
882 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
884 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
885 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
887 wined3d_mutex_lock();
888 wined3d_device_dispatch_compute(device->wined3d_device,
889 thread_group_count_x, thread_group_count_y, thread_group_count_z);
890 wined3d_mutex_unlock();
893 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
894 ID3D11Buffer *buffer, UINT offset)
896 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
897 struct d3d_buffer *buffer_impl;
899 TRACE("iface %p, buffer %p, offset %u.\n", iface, buffer, offset);
901 buffer_impl = unsafe_impl_from_ID3D11Buffer(buffer);
903 wined3d_mutex_lock();
904 wined3d_device_dispatch_compute_indirect(device->wined3d_device,
905 buffer_impl->wined3d_buffer, offset);
906 wined3d_mutex_unlock();
909 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
910 ID3D11RasterizerState *rasterizer_state)
912 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
913 struct d3d_rasterizer_state *rasterizer_state_impl;
914 const D3D11_RASTERIZER_DESC *desc;
915 union
917 DWORD d;
918 float f;
919 } scale_bias, const_bias;
921 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
923 wined3d_mutex_lock();
924 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
926 wined3d_device_set_rasterizer_state(device->wined3d_device, NULL);
927 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
928 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_BACK);
929 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SLOPESCALEDEPTHBIAS, 0);
930 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, 0);
931 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
932 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
933 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
934 wined3d_mutex_unlock();
935 return;
938 wined3d_device_set_rasterizer_state(device->wined3d_device, rasterizer_state_impl->wined3d_state);
940 desc = &rasterizer_state_impl->desc;
941 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
942 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
943 scale_bias.f = desc->SlopeScaledDepthBias;
944 const_bias.f = desc->DepthBias;
945 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SLOPESCALEDEPTHBIAS, scale_bias.d);
946 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, const_bias.d);
947 /* GL_DEPTH_CLAMP */
948 if (!desc->DepthClipEnable)
949 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
950 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
951 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
952 wined3d_device_set_render_state(device->wined3d_device,
953 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
954 wined3d_mutex_unlock();
957 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
958 UINT viewport_count, const D3D11_VIEWPORT *viewports)
960 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
961 struct wined3d_viewport wined3d_vp;
963 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
965 if (viewport_count > 1)
966 FIXME("Multiple viewports not implemented.\n");
968 if (!viewport_count)
969 return;
971 wined3d_vp.x = viewports[0].TopLeftX;
972 wined3d_vp.y = viewports[0].TopLeftY;
973 wined3d_vp.width = viewports[0].Width;
974 wined3d_vp.height = viewports[0].Height;
975 wined3d_vp.min_z = viewports[0].MinDepth;
976 wined3d_vp.max_z = viewports[0].MaxDepth;
978 wined3d_mutex_lock();
979 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
980 wined3d_mutex_unlock();
983 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
984 UINT rect_count, const D3D11_RECT *rects)
986 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
988 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
990 if (rect_count > 1)
991 FIXME("Multiple scissor rects not implemented.\n");
993 if (!rect_count)
994 return;
996 wined3d_mutex_lock();
997 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
998 wined3d_mutex_unlock();
1001 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
1002 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1003 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
1005 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1006 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1007 struct wined3d_box wined3d_src_box;
1009 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1010 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1011 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1012 src_resource, src_subresource_idx, src_box);
1014 if (src_box)
1015 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
1016 src_box->right, src_box->bottom, src_box->front, src_box->back);
1018 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1019 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1020 wined3d_mutex_lock();
1021 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
1022 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
1023 wined3d_mutex_unlock();
1026 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
1027 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
1029 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1030 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1032 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1034 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1035 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1036 wined3d_mutex_lock();
1037 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1038 wined3d_mutex_unlock();
1041 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
1042 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1043 const void *data, UINT row_pitch, UINT depth_pitch)
1045 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1046 struct wined3d_resource *wined3d_resource;
1047 struct wined3d_box wined3d_box;
1049 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1050 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1052 if (box)
1053 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1055 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1056 wined3d_mutex_lock();
1057 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1058 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1059 wined3d_mutex_unlock();
1062 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
1063 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1065 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1066 struct d3d11_unordered_access_view *uav;
1067 struct d3d_buffer *buffer_impl;
1069 TRACE("iface %p, dst_buffer %p, dst_offset %u, src_view %p.\n",
1070 iface, dst_buffer, dst_offset, src_view);
1072 buffer_impl = unsafe_impl_from_ID3D11Buffer(dst_buffer);
1073 uav = unsafe_impl_from_ID3D11UnorderedAccessView(src_view);
1075 wined3d_mutex_lock();
1076 wined3d_device_copy_uav_counter(device->wined3d_device,
1077 buffer_impl->wined3d_buffer, dst_offset, uav->wined3d_view);
1078 wined3d_mutex_unlock();
1081 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
1082 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1084 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1085 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1086 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1087 HRESULT hr;
1089 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1090 iface, render_target_view, debug_float4(color_rgba));
1092 if (!view)
1093 return;
1095 wined3d_mutex_lock();
1096 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1097 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1098 ERR("Failed to clear view, hr %#x.\n", hr);
1099 wined3d_mutex_unlock();
1102 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1103 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1105 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1106 struct d3d11_unordered_access_view *view;
1108 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1109 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1111 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1112 wined3d_mutex_lock();
1113 wined3d_device_clear_unordered_access_view_uint(device->wined3d_device,
1114 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1115 wined3d_mutex_unlock();
1118 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1119 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1121 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1122 iface, unordered_access_view, debug_float4(values));
1125 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1126 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1128 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1129 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1130 DWORD wined3d_flags;
1131 HRESULT hr;
1133 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1134 iface, depth_stencil_view, flags, depth, stencil);
1136 if (!view)
1137 return;
1139 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1141 wined3d_mutex_lock();
1142 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1143 wined3d_flags, NULL, depth, stencil)))
1144 ERR("Failed to clear view, hr %#x.\n", hr);
1145 wined3d_mutex_unlock();
1148 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1149 ID3D11ShaderResourceView *view)
1151 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D11ShaderResourceView(view);
1153 TRACE("iface %p, view %p.\n", iface, view);
1155 wined3d_mutex_lock();
1156 wined3d_shader_resource_view_generate_mipmaps(srv->wined3d_view);
1157 wined3d_mutex_unlock();
1160 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1161 ID3D11Resource *resource, FLOAT min_lod)
1163 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1166 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1167 ID3D11Resource *resource)
1169 FIXME("iface %p, resource %p stub!\n", iface, resource);
1171 return 0.0f;
1174 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1175 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1176 ID3D11Resource *src_resource, UINT src_subresource_idx,
1177 DXGI_FORMAT format)
1179 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1180 "format %s stub!\n",
1181 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1182 debug_dxgi_format(format));
1185 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1186 ID3D11CommandList *command_list, BOOL restore_state)
1188 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1191 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1192 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1194 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1195 unsigned int i;
1197 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1198 iface, start_slot, view_count, views);
1200 wined3d_mutex_lock();
1201 for (i = 0; i < view_count; ++i)
1203 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1205 wined3d_device_set_hs_resource_view(device->wined3d_device, start_slot + i,
1206 view ? view->wined3d_view : NULL);
1208 wined3d_mutex_unlock();
1211 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1212 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1214 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1215 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1217 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1218 iface, shader, class_instances, class_instance_count);
1220 if (class_instances)
1221 FIXME("Dynamic linking is not implemented yet.\n");
1223 wined3d_mutex_lock();
1224 wined3d_device_set_hull_shader(device->wined3d_device, hs ? hs->wined3d_shader : NULL);
1225 wined3d_mutex_unlock();
1228 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1229 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1231 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1232 unsigned int i;
1234 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1235 iface, start_slot, sampler_count, samplers);
1237 wined3d_mutex_lock();
1238 for (i = 0; i < sampler_count; ++i)
1240 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1242 wined3d_device_set_hs_sampler(device->wined3d_device, start_slot + i,
1243 sampler ? sampler->wined3d_sampler : NULL);
1245 wined3d_mutex_unlock();
1248 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1249 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1251 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1252 unsigned int i;
1254 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1255 iface, start_slot, buffer_count, buffers);
1257 wined3d_mutex_lock();
1258 for (i = 0; i < buffer_count; ++i)
1260 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1262 wined3d_device_set_hs_cb(device->wined3d_device, start_slot + i,
1263 buffer ? buffer->wined3d_buffer : NULL);
1265 wined3d_mutex_unlock();
1268 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1269 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1271 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1272 unsigned int i;
1274 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1275 iface, start_slot, view_count, views);
1277 wined3d_mutex_lock();
1278 for (i = 0; i < view_count; ++i)
1280 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1282 wined3d_device_set_ds_resource_view(device->wined3d_device, start_slot + i,
1283 view ? view->wined3d_view : NULL);
1285 wined3d_mutex_unlock();
1288 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1289 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1291 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1292 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1294 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1295 iface, shader, class_instances, class_instance_count);
1297 if (class_instances)
1298 FIXME("Dynamic linking is not implemented yet.\n");
1300 wined3d_mutex_lock();
1301 wined3d_device_set_domain_shader(device->wined3d_device, ds ? ds->wined3d_shader : NULL);
1302 wined3d_mutex_unlock();
1305 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1306 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1308 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1309 unsigned int i;
1311 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1312 iface, start_slot, sampler_count, samplers);
1314 wined3d_mutex_lock();
1315 for (i = 0; i < sampler_count; ++i)
1317 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1319 wined3d_device_set_ds_sampler(device->wined3d_device, start_slot + i,
1320 sampler ? sampler->wined3d_sampler : NULL);
1322 wined3d_mutex_unlock();
1325 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1326 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1328 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1329 unsigned int i;
1331 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1332 iface, start_slot, buffer_count, buffers);
1334 wined3d_mutex_lock();
1335 for (i = 0; i < buffer_count; ++i)
1337 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1339 wined3d_device_set_ds_cb(device->wined3d_device, start_slot + i,
1340 buffer ? buffer->wined3d_buffer : NULL);
1342 wined3d_mutex_unlock();
1345 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1346 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1348 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1349 unsigned int i;
1351 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1352 iface, start_slot, view_count, views);
1354 wined3d_mutex_lock();
1355 for (i = 0; i < view_count; ++i)
1357 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1359 wined3d_device_set_cs_resource_view(device->wined3d_device, start_slot + i,
1360 view ? view->wined3d_view : NULL);
1362 wined3d_mutex_unlock();
1365 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1366 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1368 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1369 unsigned int i;
1371 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1372 iface, start_slot, view_count, views, initial_counts);
1374 wined3d_mutex_lock();
1375 for (i = 0; i < view_count; ++i)
1377 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1379 wined3d_device_set_cs_uav(device->wined3d_device, start_slot + i,
1380 view ? view->wined3d_view : NULL, initial_counts ? initial_counts[i] : ~0u);
1382 wined3d_mutex_unlock();
1385 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1386 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1388 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1389 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1391 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1392 iface, shader, class_instances, class_instance_count);
1394 if (class_instances)
1395 FIXME("Dynamic linking is not implemented yet.\n");
1397 wined3d_mutex_lock();
1398 wined3d_device_set_compute_shader(device->wined3d_device, cs ? cs->wined3d_shader : NULL);
1399 wined3d_mutex_unlock();
1402 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1403 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1405 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1406 unsigned int i;
1408 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1409 iface, start_slot, sampler_count, samplers);
1411 wined3d_mutex_lock();
1412 for (i = 0; i < sampler_count; ++i)
1414 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1416 wined3d_device_set_cs_sampler(device->wined3d_device, start_slot + i,
1417 sampler ? sampler->wined3d_sampler : NULL);
1419 wined3d_mutex_unlock();
1422 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1423 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1425 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1426 unsigned int i;
1428 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1429 iface, start_slot, buffer_count, buffers);
1431 wined3d_mutex_lock();
1432 for (i = 0; i < buffer_count; ++i)
1434 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1436 wined3d_device_set_cs_cb(device->wined3d_device, start_slot + i,
1437 buffer ? buffer->wined3d_buffer : NULL);
1439 wined3d_mutex_unlock();
1442 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1443 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1445 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1446 unsigned int i;
1448 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1449 iface, start_slot, buffer_count, buffers);
1451 wined3d_mutex_lock();
1452 for (i = 0; i < buffer_count; ++i)
1454 struct wined3d_buffer *wined3d_buffer;
1455 struct d3d_buffer *buffer_impl;
1457 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1459 buffers[i] = NULL;
1460 continue;
1463 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1464 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1465 ID3D11Buffer_AddRef(buffers[i]);
1467 wined3d_mutex_unlock();
1470 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1471 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1473 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1474 unsigned int i;
1476 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1477 iface, start_slot, view_count, views);
1479 wined3d_mutex_lock();
1480 for (i = 0; i < view_count; ++i)
1482 struct wined3d_shader_resource_view *wined3d_view;
1483 struct d3d_shader_resource_view *view_impl;
1485 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1487 views[i] = NULL;
1488 continue;
1491 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1492 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1493 ID3D11ShaderResourceView_AddRef(views[i]);
1495 wined3d_mutex_unlock();
1498 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1499 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1501 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1502 struct wined3d_shader *wined3d_shader;
1503 struct d3d_pixel_shader *shader_impl;
1505 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1506 iface, shader, class_instances, class_instance_count);
1508 if (class_instances || class_instance_count)
1509 FIXME("Dynamic linking not implemented yet.\n");
1511 wined3d_mutex_lock();
1512 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1514 wined3d_mutex_unlock();
1515 *shader = NULL;
1516 return;
1519 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1520 wined3d_mutex_unlock();
1521 *shader = &shader_impl->ID3D11PixelShader_iface;
1522 ID3D11PixelShader_AddRef(*shader);
1525 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1526 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1528 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1529 unsigned int i;
1531 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1532 iface, start_slot, sampler_count, samplers);
1534 wined3d_mutex_lock();
1535 for (i = 0; i < sampler_count; ++i)
1537 struct wined3d_sampler *wined3d_sampler;
1538 struct d3d_sampler_state *sampler_impl;
1540 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1542 samplers[i] = NULL;
1543 continue;
1546 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1547 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1548 ID3D11SamplerState_AddRef(samplers[i]);
1550 wined3d_mutex_unlock();
1553 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1554 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1556 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1557 struct d3d_vertex_shader *shader_impl;
1558 struct wined3d_shader *wined3d_shader;
1560 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1561 iface, shader, class_instances, class_instance_count);
1563 if (class_instances || class_instance_count)
1564 FIXME("Dynamic linking not implemented yet.\n");
1566 wined3d_mutex_lock();
1567 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1569 wined3d_mutex_unlock();
1570 *shader = NULL;
1571 return;
1574 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1575 wined3d_mutex_unlock();
1576 *shader = &shader_impl->ID3D11VertexShader_iface;
1577 ID3D11VertexShader_AddRef(*shader);
1580 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1581 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1583 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1584 unsigned int i;
1586 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1587 iface, start_slot, buffer_count, buffers);
1589 wined3d_mutex_lock();
1590 for (i = 0; i < buffer_count; ++i)
1592 struct wined3d_buffer *wined3d_buffer;
1593 struct d3d_buffer *buffer_impl;
1595 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1597 buffers[i] = NULL;
1598 continue;
1601 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1602 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1603 ID3D11Buffer_AddRef(buffers[i]);
1605 wined3d_mutex_unlock();
1608 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1609 ID3D11InputLayout **input_layout)
1611 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1612 struct wined3d_vertex_declaration *wined3d_declaration;
1613 struct d3d_input_layout *input_layout_impl;
1615 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1617 wined3d_mutex_lock();
1618 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1620 wined3d_mutex_unlock();
1621 *input_layout = NULL;
1622 return;
1625 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1626 wined3d_mutex_unlock();
1627 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1628 ID3D11InputLayout_AddRef(*input_layout);
1631 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1632 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1634 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1635 unsigned int i;
1637 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1638 iface, start_slot, buffer_count, buffers, strides, offsets);
1640 wined3d_mutex_lock();
1641 for (i = 0; i < buffer_count; ++i)
1643 struct wined3d_buffer *wined3d_buffer = NULL;
1644 struct d3d_buffer *buffer_impl;
1646 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1647 &wined3d_buffer, &offsets[i], &strides[i])))
1649 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1650 if (strides)
1651 strides[i] = 0;
1652 if (offsets)
1653 offsets[i] = 0;
1656 if (!wined3d_buffer)
1658 buffers[i] = NULL;
1659 continue;
1662 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1663 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1665 wined3d_mutex_unlock();
1668 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1669 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1671 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1672 enum wined3d_format_id wined3d_format;
1673 struct wined3d_buffer *wined3d_buffer;
1674 struct d3d_buffer *buffer_impl;
1676 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1678 wined3d_mutex_lock();
1679 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1680 *format = dxgi_format_from_wined3dformat(wined3d_format);
1681 if (!wined3d_buffer)
1683 wined3d_mutex_unlock();
1684 *buffer = NULL;
1685 return;
1688 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1689 wined3d_mutex_unlock();
1690 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1693 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1694 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1696 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1697 unsigned int i;
1699 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1700 iface, start_slot, buffer_count, buffers);
1702 wined3d_mutex_lock();
1703 for (i = 0; i < buffer_count; ++i)
1705 struct wined3d_buffer *wined3d_buffer;
1706 struct d3d_buffer *buffer_impl;
1708 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1710 buffers[i] = NULL;
1711 continue;
1714 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1715 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1716 ID3D11Buffer_AddRef(buffers[i]);
1718 wined3d_mutex_unlock();
1721 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1722 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1724 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1725 struct d3d_geometry_shader *shader_impl;
1726 struct wined3d_shader *wined3d_shader;
1728 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1729 iface, shader, class_instances, class_instance_count);
1731 if (class_instances || class_instance_count)
1732 FIXME("Dynamic linking not implemented yet.\n");
1734 wined3d_mutex_lock();
1735 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1737 wined3d_mutex_unlock();
1738 *shader = NULL;
1739 return;
1742 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1743 wined3d_mutex_unlock();
1744 *shader = &shader_impl->ID3D11GeometryShader_iface;
1745 ID3D11GeometryShader_AddRef(*shader);
1748 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1749 D3D11_PRIMITIVE_TOPOLOGY *topology)
1751 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1752 enum wined3d_primitive_type primitive_type;
1753 unsigned int patch_vertex_count;
1755 TRACE("iface %p, topology %p.\n", iface, topology);
1757 wined3d_mutex_lock();
1758 wined3d_device_get_primitive_type(device->wined3d_device, &primitive_type, &patch_vertex_count);
1759 wined3d_mutex_unlock();
1761 d3d11_primitive_topology_from_wined3d_primitive_type(primitive_type, patch_vertex_count, topology);
1764 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1765 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1767 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1768 unsigned int i;
1770 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1772 wined3d_mutex_lock();
1773 for (i = 0; i < view_count; ++i)
1775 struct wined3d_shader_resource_view *wined3d_view;
1776 struct d3d_shader_resource_view *view_impl;
1778 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1780 views[i] = NULL;
1781 continue;
1784 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1785 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1786 ID3D11ShaderResourceView_AddRef(views[i]);
1788 wined3d_mutex_unlock();
1791 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1792 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1794 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1795 unsigned int i;
1797 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1798 iface, start_slot, sampler_count, samplers);
1800 wined3d_mutex_lock();
1801 for (i = 0; i < sampler_count; ++i)
1803 struct wined3d_sampler *wined3d_sampler;
1804 struct d3d_sampler_state *sampler_impl;
1806 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1808 samplers[i] = NULL;
1809 continue;
1812 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1813 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1814 ID3D11SamplerState_AddRef(samplers[i]);
1816 wined3d_mutex_unlock();
1819 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1820 ID3D11Predicate **predicate, BOOL *value)
1822 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1823 struct wined3d_query *wined3d_predicate;
1824 struct d3d_query *predicate_impl;
1826 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1828 wined3d_mutex_lock();
1829 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1831 wined3d_mutex_unlock();
1832 *predicate = NULL;
1833 return;
1836 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1837 wined3d_mutex_unlock();
1838 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1839 ID3D11Predicate_AddRef(*predicate);
1842 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1843 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1845 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1846 unsigned int i;
1848 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1850 wined3d_mutex_lock();
1851 for (i = 0; i < view_count; ++i)
1853 struct wined3d_shader_resource_view *wined3d_view;
1854 struct d3d_shader_resource_view *view_impl;
1856 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1858 views[i] = NULL;
1859 continue;
1862 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1863 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1864 ID3D11ShaderResourceView_AddRef(views[i]);
1866 wined3d_mutex_unlock();
1869 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1870 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1872 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1873 unsigned int i;
1875 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1876 iface, start_slot, sampler_count, samplers);
1878 wined3d_mutex_lock();
1879 for (i = 0; i < sampler_count; ++i)
1881 struct d3d_sampler_state *sampler_impl;
1882 struct wined3d_sampler *wined3d_sampler;
1884 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1886 samplers[i] = NULL;
1887 continue;
1890 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1891 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1892 ID3D11SamplerState_AddRef(samplers[i]);
1894 wined3d_mutex_unlock();
1897 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1898 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1899 ID3D11DepthStencilView **depth_stencil_view)
1901 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1902 struct wined3d_rendertarget_view *wined3d_view;
1904 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1905 iface, render_target_view_count, render_target_views, depth_stencil_view);
1907 wined3d_mutex_lock();
1908 if (render_target_views)
1910 struct d3d_rendertarget_view *view_impl;
1911 unsigned int i;
1913 for (i = 0; i < render_target_view_count; ++i)
1915 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1916 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1918 render_target_views[i] = NULL;
1919 continue;
1922 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1923 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1927 if (depth_stencil_view)
1929 struct d3d_depthstencil_view *view_impl;
1931 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1932 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1934 *depth_stencil_view = NULL;
1936 else
1938 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1939 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1942 wined3d_mutex_unlock();
1945 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1946 ID3D11DeviceContext *iface,
1947 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1948 ID3D11DepthStencilView **depth_stencil_view,
1949 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1950 ID3D11UnorderedAccessView **unordered_access_views)
1952 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1953 struct wined3d_unordered_access_view *wined3d_view;
1954 struct d3d11_unordered_access_view *view_impl;
1955 unsigned int i;
1957 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1958 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1959 "unordered_access_views %p.\n",
1960 iface, render_target_view_count, render_target_views, depth_stencil_view,
1961 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1963 if (render_target_views || depth_stencil_view)
1964 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
1965 render_target_views, depth_stencil_view);
1967 if (unordered_access_views)
1969 wined3d_mutex_lock();
1970 for (i = 0; i < unordered_access_view_count; ++i)
1972 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
1973 unordered_access_view_start_slot + i)))
1975 unordered_access_views[i] = NULL;
1976 continue;
1979 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
1980 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
1981 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
1983 wined3d_mutex_unlock();
1987 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1988 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1990 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1992 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1993 iface, blend_state, blend_factor, sample_mask);
1995 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1996 ID3D11BlendState_AddRef(*blend_state);
1997 wined3d_mutex_lock();
1998 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1999 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
2000 wined3d_mutex_unlock();
2003 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
2004 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
2006 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2008 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
2009 iface, depth_stencil_state, stencil_ref);
2011 if ((*depth_stencil_state = device->depth_stencil_state
2012 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
2013 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
2014 *stencil_ref = device->stencil_ref;
2017 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
2018 UINT buffer_count, ID3D11Buffer **buffers)
2020 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2021 unsigned int i;
2023 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
2025 wined3d_mutex_lock();
2026 for (i = 0; i < buffer_count; ++i)
2028 struct wined3d_buffer *wined3d_buffer;
2029 struct d3d_buffer *buffer_impl;
2031 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
2033 buffers[i] = NULL;
2034 continue;
2037 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2038 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
2039 ID3D11Buffer_AddRef(buffers[i]);
2041 wined3d_mutex_unlock();
2044 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
2045 ID3D11RasterizerState **rasterizer_state)
2047 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2048 struct d3d_rasterizer_state *rasterizer_state_impl;
2049 struct wined3d_rasterizer_state *wined3d_state;
2051 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
2053 wined3d_mutex_lock();
2054 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
2056 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
2057 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2059 else
2061 *rasterizer_state = NULL;
2063 wined3d_mutex_unlock();
2066 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
2067 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2069 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2070 struct wined3d_viewport wined3d_vp;
2072 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2074 if (!viewports)
2076 *viewport_count = 1;
2077 return;
2080 if (!*viewport_count)
2081 return;
2083 wined3d_mutex_lock();
2084 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
2085 wined3d_mutex_unlock();
2087 viewports[0].TopLeftX = wined3d_vp.x;
2088 viewports[0].TopLeftY = wined3d_vp.y;
2089 viewports[0].Width = wined3d_vp.width;
2090 viewports[0].Height = wined3d_vp.height;
2091 viewports[0].MinDepth = wined3d_vp.min_z;
2092 viewports[0].MaxDepth = wined3d_vp.max_z;
2094 if (*viewport_count > 1)
2095 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
2098 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
2099 UINT *rect_count, D3D11_RECT *rects)
2101 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2103 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2105 if (!rects)
2107 *rect_count = 1;
2108 return;
2111 if (!*rect_count)
2112 return;
2114 wined3d_mutex_lock();
2115 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
2116 wined3d_mutex_unlock();
2117 if (*rect_count > 1)
2118 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
2121 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
2122 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2124 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2125 unsigned int i;
2127 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2129 wined3d_mutex_lock();
2130 for (i = 0; i < view_count; ++i)
2132 struct wined3d_shader_resource_view *wined3d_view;
2133 struct d3d_shader_resource_view *view_impl;
2135 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2137 views[i] = NULL;
2138 continue;
2141 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2142 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2144 wined3d_mutex_unlock();
2147 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
2148 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2150 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2151 struct d3d11_hull_shader *shader_impl;
2152 struct wined3d_shader *wined3d_shader;
2154 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2155 iface, shader, class_instances, class_instance_count);
2157 if (class_instances || class_instance_count)
2158 FIXME("Dynamic linking not implemented yet.\n");
2160 wined3d_mutex_lock();
2161 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2163 wined3d_mutex_unlock();
2164 *shader = NULL;
2165 return;
2168 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2169 wined3d_mutex_unlock();
2170 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2173 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
2174 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2176 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2177 unsigned int i;
2179 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2180 iface, start_slot, sampler_count, samplers);
2182 wined3d_mutex_lock();
2183 for (i = 0; i < sampler_count; ++i)
2185 struct wined3d_sampler *wined3d_sampler;
2186 struct d3d_sampler_state *sampler_impl;
2188 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2190 samplers[i] = NULL;
2191 continue;
2194 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2195 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2197 wined3d_mutex_unlock();
2200 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
2201 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2203 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2204 unsigned int i;
2206 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2207 iface, start_slot, buffer_count, buffers);
2209 wined3d_mutex_lock();
2210 for (i = 0; i < buffer_count; ++i)
2212 struct wined3d_buffer *wined3d_buffer;
2213 struct d3d_buffer *buffer_impl;
2215 if (!(wined3d_buffer = wined3d_device_get_hs_cb(device->wined3d_device, start_slot + i)))
2217 buffers[i] = NULL;
2218 continue;
2221 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2222 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2224 wined3d_mutex_unlock();
2227 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
2228 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2230 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2231 unsigned int i;
2233 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2234 iface, start_slot, view_count, views);
2236 wined3d_mutex_lock();
2237 for (i = 0; i < view_count; ++i)
2239 struct wined3d_shader_resource_view *wined3d_view;
2240 struct d3d_shader_resource_view *view_impl;
2242 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2244 views[i] = NULL;
2245 continue;
2248 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2249 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2251 wined3d_mutex_unlock();
2254 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
2255 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2257 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2258 struct d3d11_domain_shader *shader_impl;
2259 struct wined3d_shader *wined3d_shader;
2261 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2262 iface, shader, class_instances, class_instance_count);
2264 if (class_instances || class_instance_count)
2265 FIXME("Dynamic linking not implemented yet.\n");
2267 wined3d_mutex_lock();
2268 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2270 wined3d_mutex_unlock();
2271 *shader = NULL;
2272 return;
2275 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2276 wined3d_mutex_unlock();
2277 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2280 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
2281 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2283 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2284 unsigned int i;
2286 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2287 iface, start_slot, sampler_count, samplers);
2289 wined3d_mutex_lock();
2290 for (i = 0; i < sampler_count; ++i)
2292 struct wined3d_sampler *wined3d_sampler;
2293 struct d3d_sampler_state *sampler_impl;
2295 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2297 samplers[i] = NULL;
2298 continue;
2301 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2302 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2304 wined3d_mutex_unlock();
2307 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
2308 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2310 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2311 unsigned int i;
2313 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2314 iface, start_slot, buffer_count, buffers);
2316 wined3d_mutex_lock();
2317 for (i = 0; i < buffer_count; ++i)
2319 struct wined3d_buffer *wined3d_buffer;
2320 struct d3d_buffer *buffer_impl;
2322 if (!(wined3d_buffer = wined3d_device_get_ds_cb(device->wined3d_device, start_slot + i)))
2324 buffers[i] = NULL;
2325 continue;
2328 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2329 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2331 wined3d_mutex_unlock();
2334 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
2335 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2337 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2338 unsigned int i;
2340 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2342 wined3d_mutex_lock();
2343 for (i = 0; i < view_count; ++i)
2345 struct wined3d_shader_resource_view *wined3d_view;
2346 struct d3d_shader_resource_view *view_impl;
2348 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2350 views[i] = NULL;
2351 continue;
2354 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2355 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2357 wined3d_mutex_unlock();
2360 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
2361 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2363 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2364 unsigned int i;
2366 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2368 wined3d_mutex_lock();
2369 for (i = 0; i < view_count; ++i)
2371 struct wined3d_unordered_access_view *wined3d_view;
2372 struct d3d11_unordered_access_view *view_impl;
2374 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2376 views[i] = NULL;
2377 continue;
2380 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2381 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2383 wined3d_mutex_unlock();
2386 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
2387 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2389 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2390 struct d3d11_compute_shader *shader_impl;
2391 struct wined3d_shader *wined3d_shader;
2393 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2394 iface, shader, class_instances, class_instance_count);
2396 if (class_instances || class_instance_count)
2397 FIXME("Dynamic linking not implemented yet.\n");
2399 wined3d_mutex_lock();
2400 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2402 wined3d_mutex_unlock();
2403 *shader = NULL;
2404 return;
2407 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2408 wined3d_mutex_unlock();
2409 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2412 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
2413 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2415 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2416 unsigned int i;
2418 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2419 iface, start_slot, sampler_count, samplers);
2421 wined3d_mutex_lock();
2422 for (i = 0; i < sampler_count; ++i)
2424 struct wined3d_sampler *wined3d_sampler;
2425 struct d3d_sampler_state *sampler_impl;
2427 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2429 samplers[i] = NULL;
2430 continue;
2433 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2434 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2436 wined3d_mutex_unlock();
2439 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
2440 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2442 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2443 unsigned int i;
2445 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2446 iface, start_slot, buffer_count, buffers);
2448 wined3d_mutex_lock();
2449 for (i = 0; i < buffer_count; ++i)
2451 struct wined3d_buffer *wined3d_buffer;
2452 struct d3d_buffer *buffer_impl;
2454 if (!(wined3d_buffer = wined3d_device_get_cs_cb(device->wined3d_device, start_slot + i)))
2456 buffers[i] = NULL;
2457 continue;
2460 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2461 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2463 wined3d_mutex_unlock();
2466 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
2468 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2469 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2470 unsigned int i;
2472 TRACE("iface %p.\n", iface);
2474 wined3d_mutex_lock();
2475 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2476 wined3d_device_set_hull_shader(device->wined3d_device, NULL);
2477 wined3d_device_set_domain_shader(device->wined3d_device, NULL);
2478 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
2479 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2480 wined3d_device_set_compute_shader(device->wined3d_device, NULL);
2481 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2483 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
2484 wined3d_device_set_hs_sampler(device->wined3d_device, i, NULL);
2485 wined3d_device_set_ds_sampler(device->wined3d_device, i, NULL);
2486 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
2487 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
2488 wined3d_device_set_cs_sampler(device->wined3d_device, i, NULL);
2490 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2492 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
2493 wined3d_device_set_hs_resource_view(device->wined3d_device, i, NULL);
2494 wined3d_device_set_ds_resource_view(device->wined3d_device, i, NULL);
2495 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
2496 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
2497 wined3d_device_set_cs_resource_view(device->wined3d_device, i, NULL);
2499 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2501 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
2502 wined3d_device_set_hs_cb(device->wined3d_device, i, NULL);
2503 wined3d_device_set_ds_cb(device->wined3d_device, i, NULL);
2504 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
2505 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
2506 wined3d_device_set_cs_cb(device->wined3d_device, i, NULL);
2508 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2510 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
2512 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
2513 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
2514 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED, 0);
2515 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2517 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
2519 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
2520 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
2522 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL, ~0u);
2523 wined3d_device_set_cs_uav(device->wined3d_device, i, NULL, ~0u);
2525 ID3D11DeviceContext_OMSetDepthStencilState(iface, NULL, 0);
2526 ID3D11DeviceContext_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2527 ID3D11DeviceContext_RSSetViewports(iface, 0, NULL);
2528 ID3D11DeviceContext_RSSetScissorRects(iface, 0, NULL);
2529 ID3D11DeviceContext_RSSetState(iface, NULL);
2530 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2532 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2534 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
2535 wined3d_mutex_unlock();
2538 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
2540 FIXME("iface %p stub!\n", iface);
2543 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
2545 TRACE("iface %p.\n", iface);
2547 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2550 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
2552 FIXME("iface %p stub!\n", iface);
2554 return 0;
2557 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
2558 BOOL restore, ID3D11CommandList **command_list)
2560 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
2562 return E_NOTIMPL;
2565 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
2567 /* IUnknown methods */
2568 d3d11_immediate_context_QueryInterface,
2569 d3d11_immediate_context_AddRef,
2570 d3d11_immediate_context_Release,
2571 /* ID3D11DeviceChild methods */
2572 d3d11_immediate_context_GetDevice,
2573 d3d11_immediate_context_GetPrivateData,
2574 d3d11_immediate_context_SetPrivateData,
2575 d3d11_immediate_context_SetPrivateDataInterface,
2576 /* ID3D11DeviceContext methods */
2577 d3d11_immediate_context_VSSetConstantBuffers,
2578 d3d11_immediate_context_PSSetShaderResources,
2579 d3d11_immediate_context_PSSetShader,
2580 d3d11_immediate_context_PSSetSamplers,
2581 d3d11_immediate_context_VSSetShader,
2582 d3d11_immediate_context_DrawIndexed,
2583 d3d11_immediate_context_Draw,
2584 d3d11_immediate_context_Map,
2585 d3d11_immediate_context_Unmap,
2586 d3d11_immediate_context_PSSetConstantBuffers,
2587 d3d11_immediate_context_IASetInputLayout,
2588 d3d11_immediate_context_IASetVertexBuffers,
2589 d3d11_immediate_context_IASetIndexBuffer,
2590 d3d11_immediate_context_DrawIndexedInstanced,
2591 d3d11_immediate_context_DrawInstanced,
2592 d3d11_immediate_context_GSSetConstantBuffers,
2593 d3d11_immediate_context_GSSetShader,
2594 d3d11_immediate_context_IASetPrimitiveTopology,
2595 d3d11_immediate_context_VSSetShaderResources,
2596 d3d11_immediate_context_VSSetSamplers,
2597 d3d11_immediate_context_Begin,
2598 d3d11_immediate_context_End,
2599 d3d11_immediate_context_GetData,
2600 d3d11_immediate_context_SetPredication,
2601 d3d11_immediate_context_GSSetShaderResources,
2602 d3d11_immediate_context_GSSetSamplers,
2603 d3d11_immediate_context_OMSetRenderTargets,
2604 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2605 d3d11_immediate_context_OMSetBlendState,
2606 d3d11_immediate_context_OMSetDepthStencilState,
2607 d3d11_immediate_context_SOSetTargets,
2608 d3d11_immediate_context_DrawAuto,
2609 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2610 d3d11_immediate_context_DrawInstancedIndirect,
2611 d3d11_immediate_context_Dispatch,
2612 d3d11_immediate_context_DispatchIndirect,
2613 d3d11_immediate_context_RSSetState,
2614 d3d11_immediate_context_RSSetViewports,
2615 d3d11_immediate_context_RSSetScissorRects,
2616 d3d11_immediate_context_CopySubresourceRegion,
2617 d3d11_immediate_context_CopyResource,
2618 d3d11_immediate_context_UpdateSubresource,
2619 d3d11_immediate_context_CopyStructureCount,
2620 d3d11_immediate_context_ClearRenderTargetView,
2621 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2622 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2623 d3d11_immediate_context_ClearDepthStencilView,
2624 d3d11_immediate_context_GenerateMips,
2625 d3d11_immediate_context_SetResourceMinLOD,
2626 d3d11_immediate_context_GetResourceMinLOD,
2627 d3d11_immediate_context_ResolveSubresource,
2628 d3d11_immediate_context_ExecuteCommandList,
2629 d3d11_immediate_context_HSSetShaderResources,
2630 d3d11_immediate_context_HSSetShader,
2631 d3d11_immediate_context_HSSetSamplers,
2632 d3d11_immediate_context_HSSetConstantBuffers,
2633 d3d11_immediate_context_DSSetShaderResources,
2634 d3d11_immediate_context_DSSetShader,
2635 d3d11_immediate_context_DSSetSamplers,
2636 d3d11_immediate_context_DSSetConstantBuffers,
2637 d3d11_immediate_context_CSSetShaderResources,
2638 d3d11_immediate_context_CSSetUnorderedAccessViews,
2639 d3d11_immediate_context_CSSetShader,
2640 d3d11_immediate_context_CSSetSamplers,
2641 d3d11_immediate_context_CSSetConstantBuffers,
2642 d3d11_immediate_context_VSGetConstantBuffers,
2643 d3d11_immediate_context_PSGetShaderResources,
2644 d3d11_immediate_context_PSGetShader,
2645 d3d11_immediate_context_PSGetSamplers,
2646 d3d11_immediate_context_VSGetShader,
2647 d3d11_immediate_context_PSGetConstantBuffers,
2648 d3d11_immediate_context_IAGetInputLayout,
2649 d3d11_immediate_context_IAGetVertexBuffers,
2650 d3d11_immediate_context_IAGetIndexBuffer,
2651 d3d11_immediate_context_GSGetConstantBuffers,
2652 d3d11_immediate_context_GSGetShader,
2653 d3d11_immediate_context_IAGetPrimitiveTopology,
2654 d3d11_immediate_context_VSGetShaderResources,
2655 d3d11_immediate_context_VSGetSamplers,
2656 d3d11_immediate_context_GetPredication,
2657 d3d11_immediate_context_GSGetShaderResources,
2658 d3d11_immediate_context_GSGetSamplers,
2659 d3d11_immediate_context_OMGetRenderTargets,
2660 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2661 d3d11_immediate_context_OMGetBlendState,
2662 d3d11_immediate_context_OMGetDepthStencilState,
2663 d3d11_immediate_context_SOGetTargets,
2664 d3d11_immediate_context_RSGetState,
2665 d3d11_immediate_context_RSGetViewports,
2666 d3d11_immediate_context_RSGetScissorRects,
2667 d3d11_immediate_context_HSGetShaderResources,
2668 d3d11_immediate_context_HSGetShader,
2669 d3d11_immediate_context_HSGetSamplers,
2670 d3d11_immediate_context_HSGetConstantBuffers,
2671 d3d11_immediate_context_DSGetShaderResources,
2672 d3d11_immediate_context_DSGetShader,
2673 d3d11_immediate_context_DSGetSamplers,
2674 d3d11_immediate_context_DSGetConstantBuffers,
2675 d3d11_immediate_context_CSGetShaderResources,
2676 d3d11_immediate_context_CSGetUnorderedAccessViews,
2677 d3d11_immediate_context_CSGetShader,
2678 d3d11_immediate_context_CSGetSamplers,
2679 d3d11_immediate_context_CSGetConstantBuffers,
2680 d3d11_immediate_context_ClearState,
2681 d3d11_immediate_context_Flush,
2682 d3d11_immediate_context_GetType,
2683 d3d11_immediate_context_GetContextFlags,
2684 d3d11_immediate_context_FinishCommandList,
2687 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2689 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2690 context->refcount = 1;
2692 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2694 wined3d_private_store_init(&context->private_store);
2697 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2699 wined3d_private_store_cleanup(&context->private_store);
2702 /* ID3D11Device methods */
2704 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2706 struct d3d_device *device = impl_from_ID3D11Device(iface);
2707 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2710 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2712 struct d3d_device *device = impl_from_ID3D11Device(iface);
2713 return IUnknown_AddRef(device->outer_unk);
2716 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2718 struct d3d_device *device = impl_from_ID3D11Device(iface);
2719 return IUnknown_Release(device->outer_unk);
2722 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2723 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2725 struct d3d_device *device = impl_from_ID3D11Device(iface);
2726 struct d3d_buffer *object;
2727 HRESULT hr;
2729 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2731 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2732 return hr;
2734 *buffer = &object->ID3D11Buffer_iface;
2736 return S_OK;
2739 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2740 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2742 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2744 return E_NOTIMPL;
2747 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2748 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2750 struct d3d_device *device = impl_from_ID3D11Device(iface);
2751 struct d3d_texture2d *object;
2752 HRESULT hr;
2754 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2756 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2757 return hr;
2759 *texture = &object->ID3D11Texture2D_iface;
2761 return S_OK;
2764 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2765 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2767 struct d3d_device *device = impl_from_ID3D11Device(iface);
2768 struct d3d_texture3d *object;
2769 HRESULT hr;
2771 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2773 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2774 return hr;
2776 *texture = &object->ID3D11Texture3D_iface;
2778 return S_OK;
2781 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2782 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2784 struct d3d_device *device = impl_from_ID3D11Device(iface);
2785 struct d3d_shader_resource_view *object;
2786 HRESULT hr;
2788 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2790 if (!resource)
2791 return E_INVALIDARG;
2793 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2794 return hr;
2796 *view = &object->ID3D11ShaderResourceView_iface;
2798 return S_OK;
2801 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2802 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2804 struct d3d_device *device = impl_from_ID3D11Device(iface);
2805 struct d3d11_unordered_access_view *object;
2806 HRESULT hr;
2808 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2810 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2811 return hr;
2813 *view = &object->ID3D11UnorderedAccessView_iface;
2815 return S_OK;
2818 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2819 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2821 struct d3d_device *device = impl_from_ID3D11Device(iface);
2822 struct d3d_rendertarget_view *object;
2823 HRESULT hr;
2825 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2827 if (!resource)
2828 return E_INVALIDARG;
2830 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2831 return hr;
2833 *view = &object->ID3D11RenderTargetView_iface;
2835 return S_OK;
2838 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2839 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2841 struct d3d_device *device = impl_from_ID3D11Device(iface);
2842 struct d3d_depthstencil_view *object;
2843 HRESULT hr;
2845 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2847 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2848 return hr;
2850 *view = &object->ID3D11DepthStencilView_iface;
2852 return S_OK;
2855 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2856 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2857 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2859 struct d3d_device *device = impl_from_ID3D11Device(iface);
2860 struct d3d_input_layout *object;
2861 HRESULT hr;
2863 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2864 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2865 shader_byte_code_length, input_layout);
2867 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2868 shader_byte_code, shader_byte_code_length, &object)))
2869 return hr;
2871 *input_layout = &object->ID3D11InputLayout_iface;
2873 return S_OK;
2876 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2877 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2879 struct d3d_device *device = impl_from_ID3D11Device(iface);
2880 struct d3d_vertex_shader *object;
2881 HRESULT hr;
2883 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2884 iface, byte_code, byte_code_length, class_linkage, shader);
2886 if (class_linkage)
2887 FIXME("Class linkage is not implemented yet.\n");
2889 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2890 return hr;
2892 *shader = &object->ID3D11VertexShader_iface;
2894 return S_OK;
2897 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2898 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2900 struct d3d_device *device = impl_from_ID3D11Device(iface);
2901 struct d3d_geometry_shader *object;
2902 HRESULT hr;
2904 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2905 iface, byte_code, byte_code_length, class_linkage, shader);
2907 if (class_linkage)
2908 FIXME("Class linkage is not implemented yet.\n");
2910 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2911 NULL, 0, NULL, 0, 0, &object)))
2912 return hr;
2914 *shader = &object->ID3D11GeometryShader_iface;
2916 return S_OK;
2919 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2920 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2921 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
2922 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2924 struct d3d_device *device = impl_from_ID3D11Device(iface);
2925 struct d3d_geometry_shader *object;
2926 HRESULT hr;
2928 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2929 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
2930 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2931 rasterizer_stream, class_linkage, shader);
2933 if (class_linkage)
2934 FIXME("Class linkage is not implemented yet.\n");
2936 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2937 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
2939 *shader = NULL;
2940 return hr;
2943 *shader = &object->ID3D11GeometryShader_iface;
2945 return hr;
2948 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2949 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2951 struct d3d_device *device = impl_from_ID3D11Device(iface);
2952 struct d3d_pixel_shader *object;
2953 HRESULT hr;
2955 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2956 iface, byte_code, byte_code_length, class_linkage, shader);
2958 if (class_linkage)
2959 FIXME("Class linkage is not implemented yet.\n");
2961 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2962 return hr;
2964 *shader = &object->ID3D11PixelShader_iface;
2966 return S_OK;
2969 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2970 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2972 struct d3d_device *device = impl_from_ID3D11Device(iface);
2973 struct d3d11_hull_shader *object;
2974 HRESULT hr;
2976 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2977 iface, byte_code, byte_code_length, class_linkage, shader);
2979 if (class_linkage)
2980 FIXME("Class linkage is not implemented yet.\n");
2982 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2983 return hr;
2985 *shader = &object->ID3D11HullShader_iface;
2987 return S_OK;
2990 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2991 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2993 struct d3d_device *device = impl_from_ID3D11Device(iface);
2994 struct d3d11_domain_shader *object;
2995 HRESULT hr;
2997 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2998 iface, byte_code, byte_code_length, class_linkage, shader);
3000 if (class_linkage)
3001 FIXME("Class linkage is not implemented yet.\n");
3003 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
3004 return hr;
3006 *shader = &object->ID3D11DomainShader_iface;
3008 return S_OK;
3011 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
3012 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
3014 struct d3d_device *device = impl_from_ID3D11Device(iface);
3015 struct d3d11_compute_shader *object;
3016 HRESULT hr;
3018 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
3019 iface, byte_code, byte_code_length, class_linkage, shader);
3021 if (class_linkage)
3022 FIXME("Class linkage is not implemented yet.\n");
3024 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
3025 return hr;
3027 *shader = &object->ID3D11ComputeShader_iface;
3029 return S_OK;
3032 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
3033 ID3D11ClassLinkage **class_linkage)
3035 struct d3d_device *device = impl_from_ID3D11Device(iface);
3036 struct d3d11_class_linkage *object;
3037 HRESULT hr;
3039 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
3041 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
3042 return hr;
3044 *class_linkage = &object->ID3D11ClassLinkage_iface;
3046 return S_OK;
3049 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
3050 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
3052 struct d3d_device *device = impl_from_ID3D11Device(iface);
3053 struct d3d_blend_state *object;
3054 HRESULT hr;
3056 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3058 if (FAILED(hr = d3d_blend_state_create(device, desc, &object)))
3059 return hr;
3061 *blend_state = &object->ID3D11BlendState_iface;
3063 return S_OK;
3066 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
3067 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3069 struct d3d_device *device = impl_from_ID3D11Device(iface);
3070 struct d3d_depthstencil_state *object;
3071 HRESULT hr;
3073 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3075 if (FAILED(hr = d3d_depthstencil_state_create(device, desc, &object)))
3076 return hr;
3078 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3080 return S_OK;
3083 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
3084 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3086 struct d3d_device *device = impl_from_ID3D11Device(iface);
3087 struct d3d_rasterizer_state *object;
3088 HRESULT hr;
3090 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3092 if (FAILED(hr = d3d_rasterizer_state_create(device, desc, &object)))
3093 return hr;
3095 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3097 return S_OK;
3100 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
3101 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3103 struct d3d_device *device = impl_from_ID3D11Device(iface);
3104 struct d3d_sampler_state *object;
3105 HRESULT hr;
3107 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3109 if (FAILED(hr = d3d_sampler_state_create(device, desc, &object)))
3110 return hr;
3112 *sampler_state = &object->ID3D11SamplerState_iface;
3114 return S_OK;
3117 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
3118 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3120 struct d3d_device *device = impl_from_ID3D11Device(iface);
3121 struct d3d_query *object;
3122 HRESULT hr;
3124 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3126 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3127 return hr;
3129 if (query)
3131 *query = &object->ID3D11Query_iface;
3132 return S_OK;
3135 ID3D11Query_Release(&object->ID3D11Query_iface);
3136 return S_FALSE;
3139 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
3140 ID3D11Predicate **predicate)
3142 struct d3d_device *device = impl_from_ID3D11Device(iface);
3143 struct d3d_query *object;
3144 HRESULT hr;
3146 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3148 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3149 return hr;
3151 if (predicate)
3153 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3154 return S_OK;
3157 ID3D11Query_Release(&object->ID3D11Query_iface);
3158 return S_FALSE;
3161 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3162 ID3D11Counter **counter)
3164 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3166 return E_NOTIMPL;
3169 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
3170 ID3D11DeviceContext **context)
3172 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3174 return E_NOTIMPL;
3177 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
3178 void **out)
3180 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
3182 return E_NOTIMPL;
3185 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
3186 UINT *format_support)
3188 struct d3d_device *device = impl_from_ID3D11Device(iface);
3189 struct wined3d_device_creation_parameters params;
3190 enum wined3d_format_id wined3d_format;
3191 struct wined3d *wined3d;
3192 unsigned int i;
3194 static const struct
3196 enum wined3d_resource_type rtype;
3197 unsigned int usage;
3198 D3D11_FORMAT_SUPPORT flag;
3200 flag_mapping[] =
3202 {WINED3D_RTYPE_TEXTURE_2D, WINED3DUSAGE_TEXTURE, D3D11_FORMAT_SUPPORT_TEXTURE2D},
3203 {WINED3D_RTYPE_TEXTURE_3D, WINED3DUSAGE_TEXTURE, D3D11_FORMAT_SUPPORT_TEXTURE3D},
3204 {WINED3D_RTYPE_NONE, WINED3DUSAGE_RENDERTARGET, D3D11_FORMAT_SUPPORT_RENDER_TARGET},
3205 {WINED3D_RTYPE_NONE, WINED3DUSAGE_DEPTHSTENCIL, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL},
3207 HRESULT hr;
3209 FIXME("iface %p, format %u, format_support %p partial-stub!\n", iface, format, format_support);
3211 wined3d_format = wined3dformat_from_dxgi_format(format);
3212 if (format && !wined3d_format)
3214 WARN("Invalid format %#x.\n", format);
3215 *format_support = 0;
3216 return E_FAIL;
3219 *format_support = 0;
3221 wined3d_mutex_lock();
3222 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3223 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3224 for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
3226 hr = wined3d_check_device_format(wined3d, params.adapter_idx, params.device_type,
3227 WINED3DFMT_UNKNOWN, flag_mapping[i].usage, flag_mapping[i].rtype, wined3d_format);
3228 if (hr == WINED3DERR_NOTAVAILABLE || hr == WINED3DOK_NOAUTOGEN)
3229 continue;
3230 if (hr != WINED3D_OK)
3232 WARN("Failed to check device format support, hr %#x.\n", hr);
3233 wined3d_mutex_unlock();
3234 return E_FAIL;
3237 *format_support |= flag_mapping[i].flag;
3239 wined3d_mutex_unlock();
3241 return S_OK;
3244 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
3245 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3247 struct d3d_device *device = impl_from_ID3D11Device(iface);
3248 struct wined3d_device_creation_parameters params;
3249 struct wined3d *wined3d;
3250 HRESULT hr;
3252 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3253 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3255 if (!quality_level_count)
3256 return E_INVALIDARG;
3258 *quality_level_count = 0;
3260 if (!sample_count)
3261 return E_FAIL;
3262 if (sample_count == 1)
3264 *quality_level_count = 1;
3265 return S_OK;
3267 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3268 return E_FAIL;
3270 wined3d_mutex_lock();
3271 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3272 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3273 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
3274 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3275 wined3d_mutex_unlock();
3277 if (hr == WINED3DERR_INVALIDCALL)
3278 return E_INVALIDARG;
3279 if (hr == WINED3DERR_NOTAVAILABLE)
3280 return S_OK;
3281 return hr;
3284 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
3286 FIXME("iface %p, info %p stub!\n", iface, info);
3289 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3290 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3291 char *units, UINT *units_length, char *description, UINT *description_length)
3293 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3294 "units %p, units_length %p, description %p, description_length %p stub!\n",
3295 iface, desc, type, active_counter_count, name, name_length,
3296 units, units_length, description, description_length);
3298 return E_NOTIMPL;
3301 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
3302 void *feature_support_data, UINT feature_support_data_size)
3304 struct d3d_device *device = impl_from_ID3D11Device(iface);
3305 WINED3DCAPS wined3d_caps;
3306 HRESULT hr;
3308 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3309 iface, feature, feature_support_data, feature_support_data_size);
3311 switch (feature)
3313 case D3D11_FEATURE_THREADING:
3315 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3316 if (feature_support_data_size != sizeof(*threading_data))
3318 WARN("Invalid data size.\n");
3319 return E_INVALIDARG;
3322 /* We lie about the threading support to make Tomb Raider 2013 and
3323 * Deus Ex: Human Revolution happy. */
3324 FIXME("Returning fake threading support data.\n");
3325 threading_data->DriverConcurrentCreates = TRUE;
3326 threading_data->DriverCommandLists = TRUE;
3327 return S_OK;
3330 case D3D11_FEATURE_DOUBLES:
3332 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3333 if (feature_support_data_size != sizeof(*doubles_data))
3335 WARN("Invalid data size.\n");
3336 return E_INVALIDARG;
3339 wined3d_mutex_lock();
3340 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3341 wined3d_mutex_unlock();
3342 if (FAILED(hr))
3344 WARN("Failed to get device caps, hr %#x.\n", hr);
3345 return hr;
3348 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3349 return S_OK;
3352 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3354 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3355 if (feature_support_data_size != sizeof(*options))
3357 WARN("Invalid data size.\n");
3358 return E_INVALIDARG;
3361 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
3362 return S_OK;
3365 default:
3366 FIXME("Unhandled feature %#x.\n", feature);
3367 return E_NOTIMPL;
3371 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
3372 UINT *data_size, void *data)
3374 IDXGIDevice *dxgi_device;
3375 HRESULT hr;
3377 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3379 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3380 return hr;
3381 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3382 IDXGIDevice_Release(dxgi_device);
3384 return hr;
3387 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
3388 UINT data_size, const void *data)
3390 IDXGIDevice *dxgi_device;
3391 HRESULT hr;
3393 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3395 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3396 return hr;
3397 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3398 IDXGIDevice_Release(dxgi_device);
3400 return hr;
3403 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
3404 const IUnknown *data)
3406 IDXGIDevice *dxgi_device;
3407 HRESULT hr;
3409 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3411 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3412 return hr;
3413 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3414 IDXGIDevice_Release(dxgi_device);
3416 return hr;
3419 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
3421 struct d3d_device *device = impl_from_ID3D11Device(iface);
3423 TRACE("iface %p.\n", iface);
3425 return device->feature_level;
3428 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
3430 FIXME("iface %p stub!\n", iface);
3432 return 0;
3435 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
3437 FIXME("iface %p stub!\n", iface);
3439 return S_OK;
3442 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
3443 ID3D11DeviceContext **immediate_context)
3445 struct d3d_device *device = impl_from_ID3D11Device(iface);
3447 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
3449 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
3450 ID3D11DeviceContext_AddRef(*immediate_context);
3453 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
3455 FIXME("iface %p, flags %#x stub!\n", iface, flags);
3457 return E_NOTIMPL;
3460 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
3462 FIXME("iface %p stub!\n", iface);
3464 return 0;
3467 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
3469 /* IUnknown methods */
3470 d3d11_device_QueryInterface,
3471 d3d11_device_AddRef,
3472 d3d11_device_Release,
3473 /* ID3D11Device methods */
3474 d3d11_device_CreateBuffer,
3475 d3d11_device_CreateTexture1D,
3476 d3d11_device_CreateTexture2D,
3477 d3d11_device_CreateTexture3D,
3478 d3d11_device_CreateShaderResourceView,
3479 d3d11_device_CreateUnorderedAccessView,
3480 d3d11_device_CreateRenderTargetView,
3481 d3d11_device_CreateDepthStencilView,
3482 d3d11_device_CreateInputLayout,
3483 d3d11_device_CreateVertexShader,
3484 d3d11_device_CreateGeometryShader,
3485 d3d11_device_CreateGeometryShaderWithStreamOutput,
3486 d3d11_device_CreatePixelShader,
3487 d3d11_device_CreateHullShader,
3488 d3d11_device_CreateDomainShader,
3489 d3d11_device_CreateComputeShader,
3490 d3d11_device_CreateClassLinkage,
3491 d3d11_device_CreateBlendState,
3492 d3d11_device_CreateDepthStencilState,
3493 d3d11_device_CreateRasterizerState,
3494 d3d11_device_CreateSamplerState,
3495 d3d11_device_CreateQuery,
3496 d3d11_device_CreatePredicate,
3497 d3d11_device_CreateCounter,
3498 d3d11_device_CreateDeferredContext,
3499 d3d11_device_OpenSharedResource,
3500 d3d11_device_CheckFormatSupport,
3501 d3d11_device_CheckMultisampleQualityLevels,
3502 d3d11_device_CheckCounterInfo,
3503 d3d11_device_CheckCounter,
3504 d3d11_device_CheckFeatureSupport,
3505 d3d11_device_GetPrivateData,
3506 d3d11_device_SetPrivateData,
3507 d3d11_device_SetPrivateDataInterface,
3508 d3d11_device_GetFeatureLevel,
3509 d3d11_device_GetCreationFlags,
3510 d3d11_device_GetDeviceRemovedReason,
3511 d3d11_device_GetImmediateContext,
3512 d3d11_device_SetExceptionMode,
3513 d3d11_device_GetExceptionMode,
3516 /* Inner IUnknown methods */
3518 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
3520 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
3523 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3525 struct d3d_device *device = impl_from_IUnknown(iface);
3527 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
3529 if (IsEqualGUID(riid, &IID_ID3D11Device)
3530 || IsEqualGUID(riid, &IID_IUnknown))
3532 *out = &device->ID3D11Device_iface;
3534 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
3535 || IsEqualGUID(riid, &IID_ID3D10Device))
3537 *out = &device->ID3D10Device1_iface;
3539 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
3541 *out = &device->ID3D10Multithread_iface;
3543 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
3545 *out = &device->IWineDXGIDeviceParent_iface;
3547 else
3549 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
3550 *out = NULL;
3551 return E_NOINTERFACE;
3554 IUnknown_AddRef((IUnknown *)*out);
3555 return S_OK;
3558 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
3560 struct d3d_device *device = impl_from_IUnknown(iface);
3561 ULONG refcount = InterlockedIncrement(&device->refcount);
3563 TRACE("%p increasing refcount to %u.\n", device, refcount);
3565 return refcount;
3568 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
3570 struct d3d_device *device = impl_from_IUnknown(iface);
3571 ULONG refcount = InterlockedDecrement(&device->refcount);
3573 TRACE("%p decreasing refcount to %u.\n", device, refcount);
3575 if (!refcount)
3577 d3d11_immediate_context_destroy(&device->immediate_context);
3578 if (device->wined3d_device)
3580 wined3d_mutex_lock();
3581 wined3d_device_decref(device->wined3d_device);
3582 wined3d_mutex_unlock();
3584 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3585 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3586 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3587 wine_rb_destroy(&device->blend_states, NULL, NULL);
3590 return refcount;
3593 /* IUnknown methods */
3595 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3596 void **ppv)
3598 struct d3d_device *device = impl_from_ID3D10Device(iface);
3599 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3602 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3604 struct d3d_device *device = impl_from_ID3D10Device(iface);
3605 return IUnknown_AddRef(device->outer_unk);
3608 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3610 struct d3d_device *device = impl_from_ID3D10Device(iface);
3611 return IUnknown_Release(device->outer_unk);
3614 /* ID3D10Device methods */
3616 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3617 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3619 struct d3d_device *device = impl_from_ID3D10Device(iface);
3620 unsigned int i;
3622 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3623 iface, start_slot, buffer_count, buffers);
3625 wined3d_mutex_lock();
3626 for (i = 0; i < buffer_count; ++i)
3628 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3630 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3631 buffer ? buffer->wined3d_buffer : NULL);
3633 wined3d_mutex_unlock();
3636 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3637 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3639 struct d3d_device *device = impl_from_ID3D10Device(iface);
3640 unsigned int i;
3642 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3643 iface, start_slot, view_count, views);
3645 wined3d_mutex_lock();
3646 for (i = 0; i < view_count; ++i)
3648 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3650 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3651 view ? view->wined3d_view : NULL);
3653 wined3d_mutex_unlock();
3656 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3657 ID3D10PixelShader *shader)
3659 struct d3d_device *device = impl_from_ID3D10Device(iface);
3660 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3662 TRACE("iface %p, shader %p\n", iface, shader);
3664 wined3d_mutex_lock();
3665 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3666 wined3d_mutex_unlock();
3669 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3670 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3672 struct d3d_device *device = impl_from_ID3D10Device(iface);
3673 unsigned int i;
3675 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3676 iface, start_slot, sampler_count, samplers);
3678 wined3d_mutex_lock();
3679 for (i = 0; i < sampler_count; ++i)
3681 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3683 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3684 sampler ? sampler->wined3d_sampler : NULL);
3686 wined3d_mutex_unlock();
3689 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3690 ID3D10VertexShader *shader)
3692 struct d3d_device *device = impl_from_ID3D10Device(iface);
3693 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3695 TRACE("iface %p, shader %p\n", iface, shader);
3697 wined3d_mutex_lock();
3698 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3699 wined3d_mutex_unlock();
3702 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3703 UINT start_index_location, INT base_vertex_location)
3705 struct d3d_device *device = impl_from_ID3D10Device(iface);
3707 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3708 iface, index_count, start_index_location, base_vertex_location);
3710 wined3d_mutex_lock();
3711 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3712 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3713 wined3d_mutex_unlock();
3716 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3717 UINT start_vertex_location)
3719 struct d3d_device *device = impl_from_ID3D10Device(iface);
3721 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3722 iface, vertex_count, start_vertex_location);
3724 wined3d_mutex_lock();
3725 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3726 wined3d_mutex_unlock();
3729 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
3730 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3732 struct d3d_device *device = impl_from_ID3D10Device(iface);
3733 unsigned int i;
3735 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3736 iface, start_slot, buffer_count, buffers);
3738 wined3d_mutex_lock();
3739 for (i = 0; i < buffer_count; ++i)
3741 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3743 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
3744 buffer ? buffer->wined3d_buffer : NULL);
3746 wined3d_mutex_unlock();
3749 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3750 ID3D10InputLayout *input_layout)
3752 struct d3d_device *device = impl_from_ID3D10Device(iface);
3753 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3755 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3757 wined3d_mutex_lock();
3758 wined3d_device_set_vertex_declaration(device->wined3d_device,
3759 layout ? layout->wined3d_decl : NULL);
3760 wined3d_mutex_unlock();
3763 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3764 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3766 struct d3d_device *device = impl_from_ID3D10Device(iface);
3767 unsigned int i;
3769 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3770 iface, start_slot, buffer_count, buffers, strides, offsets);
3772 wined3d_mutex_lock();
3773 for (i = 0; i < buffer_count; ++i)
3775 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3777 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3778 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3780 wined3d_mutex_unlock();
3783 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3784 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3786 struct d3d_device *device = impl_from_ID3D10Device(iface);
3787 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3789 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3790 iface, buffer, debug_dxgi_format(format), offset);
3792 wined3d_mutex_lock();
3793 wined3d_device_set_index_buffer(device->wined3d_device,
3794 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3795 wined3dformat_from_dxgi_format(format), offset);
3796 wined3d_mutex_unlock();
3799 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3800 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3801 INT base_vertex_location, UINT start_instance_location)
3803 struct d3d_device *device = impl_from_ID3D10Device(iface);
3805 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3806 "base_vertex_location %d, start_instance_location %u.\n",
3807 iface, instance_index_count, instance_count, start_index_location,
3808 base_vertex_location, start_instance_location);
3810 wined3d_mutex_lock();
3811 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3812 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3813 instance_index_count, start_instance_location, instance_count);
3814 wined3d_mutex_unlock();
3817 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3818 UINT instance_vertex_count, UINT instance_count,
3819 UINT start_vertex_location, UINT start_instance_location)
3821 struct d3d_device *device = impl_from_ID3D10Device(iface);
3823 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3824 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3825 start_vertex_location, start_instance_location);
3827 wined3d_mutex_lock();
3828 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3829 instance_vertex_count, start_instance_location, instance_count);
3830 wined3d_mutex_unlock();
3833 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3834 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3836 struct d3d_device *device = impl_from_ID3D10Device(iface);
3837 unsigned int i;
3839 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3840 iface, start_slot, buffer_count, buffers);
3842 wined3d_mutex_lock();
3843 for (i = 0; i < buffer_count; ++i)
3845 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3847 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3848 buffer ? buffer->wined3d_buffer : NULL);
3850 wined3d_mutex_unlock();
3853 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3855 struct d3d_device *device = impl_from_ID3D10Device(iface);
3856 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3858 TRACE("iface %p, shader %p.\n", iface, shader);
3860 wined3d_mutex_lock();
3861 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3862 wined3d_mutex_unlock();
3865 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3866 D3D10_PRIMITIVE_TOPOLOGY topology)
3868 struct d3d_device *device = impl_from_ID3D10Device(iface);
3870 TRACE("iface %p, topology %s.\n", iface, debug_d3d10_primitive_topology(topology));
3872 wined3d_mutex_lock();
3873 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology, 0);
3874 wined3d_mutex_unlock();
3877 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
3878 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3880 struct d3d_device *device = impl_from_ID3D10Device(iface);
3881 unsigned int i;
3883 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3884 iface, start_slot, view_count, views);
3886 wined3d_mutex_lock();
3887 for (i = 0; i < view_count; ++i)
3889 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3891 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
3892 view ? view->wined3d_view : NULL);
3894 wined3d_mutex_unlock();
3897 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
3898 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3900 struct d3d_device *device = impl_from_ID3D10Device(iface);
3901 unsigned int i;
3903 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3904 iface, start_slot, sampler_count, samplers);
3906 wined3d_mutex_lock();
3907 for (i = 0; i < sampler_count; ++i)
3909 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3911 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
3912 sampler ? sampler->wined3d_sampler : NULL);
3914 wined3d_mutex_unlock();
3917 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3919 struct d3d_device *device = impl_from_ID3D10Device(iface);
3920 struct d3d_query *query;
3922 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3924 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3925 wined3d_mutex_lock();
3926 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
3927 wined3d_mutex_unlock();
3930 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
3931 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3933 struct d3d_device *device = impl_from_ID3D10Device(iface);
3934 unsigned int i;
3936 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3937 iface, start_slot, view_count, views);
3939 wined3d_mutex_lock();
3940 for (i = 0; i < view_count; ++i)
3942 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3944 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
3945 view ? view->wined3d_view : NULL);
3947 wined3d_mutex_unlock();
3950 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
3951 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3953 struct d3d_device *device = impl_from_ID3D10Device(iface);
3954 unsigned int i;
3956 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3957 iface, start_slot, sampler_count, samplers);
3959 wined3d_mutex_lock();
3960 for (i = 0; i < sampler_count; ++i)
3962 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3964 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
3965 sampler ? sampler->wined3d_sampler : NULL);
3967 wined3d_mutex_unlock();
3970 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
3971 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
3972 ID3D10DepthStencilView *depth_stencil_view)
3974 struct d3d_device *device = impl_from_ID3D10Device(iface);
3975 struct d3d_depthstencil_view *dsv;
3976 unsigned int i;
3978 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3979 iface, render_target_view_count, render_target_views, depth_stencil_view);
3981 wined3d_mutex_lock();
3982 for (i = 0; i < render_target_view_count; ++i)
3984 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
3986 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
3987 rtv ? rtv->wined3d_view : NULL, FALSE);
3989 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3991 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
3994 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3995 wined3d_device_set_depth_stencil_view(device->wined3d_device,
3996 dsv ? dsv->wined3d_view : NULL);
3997 wined3d_mutex_unlock();
4000 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4001 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4003 struct d3d_device *device = impl_from_ID3D10Device(iface);
4004 struct d3d_blend_state *blend_state_object;
4006 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4007 iface, blend_state, debug_float4(blend_factor), sample_mask);
4009 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4010 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4011 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4014 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4015 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4017 struct d3d_device *device = impl_from_ID3D10Device(iface);
4018 struct d3d_depthstencil_state *ds_state_object;
4020 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4021 iface, depth_stencil_state, stencil_ref);
4023 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4024 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4025 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4028 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4029 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4031 struct d3d_device *device = impl_from_ID3D10Device(iface);
4032 unsigned int count, i;
4034 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4036 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4037 wined3d_mutex_lock();
4038 for (i = 0; i < count; ++i)
4040 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4042 wined3d_device_set_stream_output(device->wined3d_device, i,
4043 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4046 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4048 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4050 wined3d_mutex_unlock();
4053 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4055 FIXME("iface %p stub!\n", iface);
4058 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4060 struct d3d_device *device = impl_from_ID3D10Device(iface);
4061 struct d3d_rasterizer_state *rasterizer_state_object;
4063 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4065 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4066 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
4067 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4070 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4071 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4073 struct d3d_device *device = impl_from_ID3D10Device(iface);
4074 struct wined3d_viewport wined3d_vp;
4076 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4078 if (viewport_count > 1)
4079 FIXME("Multiple viewports not implemented.\n");
4081 if (!viewport_count)
4082 return;
4084 wined3d_vp.x = viewports[0].TopLeftX;
4085 wined3d_vp.y = viewports[0].TopLeftY;
4086 wined3d_vp.width = viewports[0].Width;
4087 wined3d_vp.height = viewports[0].Height;
4088 wined3d_vp.min_z = viewports[0].MinDepth;
4089 wined3d_vp.max_z = viewports[0].MaxDepth;
4091 wined3d_mutex_lock();
4092 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
4093 wined3d_mutex_unlock();
4096 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4097 UINT rect_count, const D3D10_RECT *rects)
4099 struct d3d_device *device = impl_from_ID3D10Device(iface);
4101 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4103 if (rect_count > 1)
4104 FIXME("Multiple scissor rects not implemented.\n");
4106 if (!rect_count)
4107 return;
4109 wined3d_mutex_lock();
4110 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
4111 wined3d_mutex_unlock();
4114 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4115 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4116 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4118 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4119 struct d3d_device *device = impl_from_ID3D10Device(iface);
4120 struct wined3d_box wined3d_src_box;
4122 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4123 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4124 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4125 src_resource, src_subresource_idx, src_box);
4127 if (src_box)
4128 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4129 src_box->right, src_box->bottom, src_box->front, src_box->back);
4131 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4132 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4133 wined3d_mutex_lock();
4134 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
4135 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
4136 wined3d_mutex_unlock();
4139 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4140 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4142 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4143 struct d3d_device *device = impl_from_ID3D10Device(iface);
4145 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4147 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4148 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4149 wined3d_mutex_lock();
4150 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
4151 wined3d_mutex_unlock();
4154 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4155 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4156 const void *data, UINT row_pitch, UINT depth_pitch)
4158 struct d3d_device *device = impl_from_ID3D10Device(iface);
4159 ID3D11Resource *d3d11_resource;
4161 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4162 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4164 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4165 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
4166 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4167 ID3D11Resource_Release(d3d11_resource);
4170 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4171 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4173 struct d3d_device *device = impl_from_ID3D10Device(iface);
4174 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4175 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4176 HRESULT hr;
4178 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4179 iface, render_target_view, debug_float4(color_rgba));
4181 if (!view)
4182 return;
4184 wined3d_mutex_lock();
4185 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4186 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4187 ERR("Failed to clear view, hr %#x.\n", hr);
4188 wined3d_mutex_unlock();
4191 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4192 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4194 struct d3d_device *device = impl_from_ID3D10Device(iface);
4195 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4196 DWORD wined3d_flags;
4197 HRESULT hr;
4199 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4200 iface, depth_stencil_view, flags, depth, stencil);
4202 if (!view)
4203 return;
4205 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4207 wined3d_mutex_lock();
4208 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4209 wined3d_flags, NULL, depth, stencil)))
4210 ERR("Failed to clear view, hr %#x.\n", hr);
4211 wined3d_mutex_unlock();
4214 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4215 ID3D10ShaderResourceView *view)
4217 struct d3d_shader_resource_view *srv = unsafe_impl_from_ID3D10ShaderResourceView(view);
4219 TRACE("iface %p, view %p.\n", iface, view);
4221 wined3d_mutex_lock();
4222 wined3d_shader_resource_view_generate_mipmaps(srv->wined3d_view);
4223 wined3d_mutex_unlock();
4226 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4227 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4228 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4230 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
4231 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
4232 iface, dst_resource, dst_subresource_idx,
4233 src_resource, src_subresource_idx, debug_dxgi_format(format));
4236 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
4237 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4239 struct d3d_device *device = impl_from_ID3D10Device(iface);
4240 unsigned int i;
4242 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4243 iface, start_slot, buffer_count, buffers);
4245 wined3d_mutex_lock();
4246 for (i = 0; i < buffer_count; ++i)
4248 struct wined3d_buffer *wined3d_buffer;
4249 struct d3d_buffer *buffer_impl;
4251 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
4253 buffers[i] = NULL;
4254 continue;
4257 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4258 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4259 ID3D10Buffer_AddRef(buffers[i]);
4261 wined3d_mutex_unlock();
4264 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
4265 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4267 struct d3d_device *device = impl_from_ID3D10Device(iface);
4268 unsigned int i;
4270 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4271 iface, start_slot, view_count, views);
4273 wined3d_mutex_lock();
4274 for (i = 0; i < view_count; ++i)
4276 struct wined3d_shader_resource_view *wined3d_view;
4277 struct d3d_shader_resource_view *view_impl;
4279 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
4281 views[i] = NULL;
4282 continue;
4285 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4286 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4287 ID3D10ShaderResourceView_AddRef(views[i]);
4289 wined3d_mutex_unlock();
4292 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
4294 struct d3d_device *device = impl_from_ID3D10Device(iface);
4295 struct d3d_pixel_shader *shader_impl;
4296 struct wined3d_shader *wined3d_shader;
4298 TRACE("iface %p, shader %p.\n", iface, shader);
4300 wined3d_mutex_lock();
4301 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
4303 wined3d_mutex_unlock();
4304 *shader = NULL;
4305 return;
4308 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4309 wined3d_mutex_unlock();
4310 *shader = &shader_impl->ID3D10PixelShader_iface;
4311 ID3D10PixelShader_AddRef(*shader);
4314 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
4315 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4317 struct d3d_device *device = impl_from_ID3D10Device(iface);
4318 unsigned int i;
4320 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4321 iface, start_slot, sampler_count, samplers);
4323 wined3d_mutex_lock();
4324 for (i = 0; i < sampler_count; ++i)
4326 struct d3d_sampler_state *sampler_impl;
4327 struct wined3d_sampler *wined3d_sampler;
4329 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
4331 samplers[i] = NULL;
4332 continue;
4335 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4336 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4337 ID3D10SamplerState_AddRef(samplers[i]);
4339 wined3d_mutex_unlock();
4342 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
4344 struct d3d_device *device = impl_from_ID3D10Device(iface);
4345 struct d3d_vertex_shader *shader_impl;
4346 struct wined3d_shader *wined3d_shader;
4348 TRACE("iface %p, shader %p.\n", iface, shader);
4350 wined3d_mutex_lock();
4351 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
4353 wined3d_mutex_unlock();
4354 *shader = NULL;
4355 return;
4358 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4359 wined3d_mutex_unlock();
4360 *shader = &shader_impl->ID3D10VertexShader_iface;
4361 ID3D10VertexShader_AddRef(*shader);
4364 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
4365 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4367 struct d3d_device *device = impl_from_ID3D10Device(iface);
4368 unsigned int i;
4370 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4371 iface, start_slot, buffer_count, buffers);
4373 wined3d_mutex_lock();
4374 for (i = 0; i < buffer_count; ++i)
4376 struct wined3d_buffer *wined3d_buffer;
4377 struct d3d_buffer *buffer_impl;
4379 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
4381 buffers[i] = NULL;
4382 continue;
4385 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4386 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4387 ID3D10Buffer_AddRef(buffers[i]);
4389 wined3d_mutex_unlock();
4392 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
4394 struct d3d_device *device = impl_from_ID3D10Device(iface);
4395 struct wined3d_vertex_declaration *wined3d_declaration;
4396 struct d3d_input_layout *input_layout_impl;
4398 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
4400 wined3d_mutex_lock();
4401 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
4403 wined3d_mutex_unlock();
4404 *input_layout = NULL;
4405 return;
4408 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
4409 wined3d_mutex_unlock();
4410 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
4411 ID3D10InputLayout_AddRef(*input_layout);
4414 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
4415 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
4417 struct d3d_device *device = impl_from_ID3D10Device(iface);
4418 unsigned int i;
4420 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
4421 iface, start_slot, buffer_count, buffers, strides, offsets);
4423 wined3d_mutex_lock();
4424 for (i = 0; i < buffer_count; ++i)
4426 struct wined3d_buffer *wined3d_buffer = NULL;
4427 struct d3d_buffer *buffer_impl;
4429 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
4430 &wined3d_buffer, &offsets[i], &strides[i])))
4431 ERR("Failed to get vertex buffer.\n");
4433 if (!wined3d_buffer)
4435 buffers[i] = NULL;
4436 continue;
4439 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4440 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4441 ID3D10Buffer_AddRef(buffers[i]);
4443 wined3d_mutex_unlock();
4446 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
4447 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
4449 struct d3d_device *device = impl_from_ID3D10Device(iface);
4450 enum wined3d_format_id wined3d_format;
4451 struct wined3d_buffer *wined3d_buffer;
4452 struct d3d_buffer *buffer_impl;
4454 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
4456 wined3d_mutex_lock();
4457 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
4458 *format = dxgi_format_from_wined3dformat(wined3d_format);
4459 if (!wined3d_buffer)
4461 wined3d_mutex_unlock();
4462 *buffer = NULL;
4463 return;
4466 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4467 wined3d_mutex_unlock();
4468 *buffer = &buffer_impl->ID3D10Buffer_iface;
4469 ID3D10Buffer_AddRef(*buffer);
4472 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
4473 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4475 struct d3d_device *device = impl_from_ID3D10Device(iface);
4476 unsigned int i;
4478 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4479 iface, start_slot, buffer_count, buffers);
4481 wined3d_mutex_lock();
4482 for (i = 0; i < buffer_count; ++i)
4484 struct wined3d_buffer *wined3d_buffer;
4485 struct d3d_buffer *buffer_impl;
4487 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
4489 buffers[i] = NULL;
4490 continue;
4493 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4494 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4495 ID3D10Buffer_AddRef(buffers[i]);
4497 wined3d_mutex_unlock();
4500 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
4502 struct d3d_device *device = impl_from_ID3D10Device(iface);
4503 struct d3d_geometry_shader *shader_impl;
4504 struct wined3d_shader *wined3d_shader;
4506 TRACE("iface %p, shader %p.\n", iface, shader);
4508 wined3d_mutex_lock();
4509 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
4511 wined3d_mutex_unlock();
4512 *shader = NULL;
4513 return;
4516 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4517 wined3d_mutex_unlock();
4518 *shader = &shader_impl->ID3D10GeometryShader_iface;
4519 ID3D10GeometryShader_AddRef(*shader);
4522 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
4523 D3D10_PRIMITIVE_TOPOLOGY *topology)
4525 struct d3d_device *device = impl_from_ID3D10Device(iface);
4527 TRACE("iface %p, topology %p.\n", iface, topology);
4529 wined3d_mutex_lock();
4530 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology, NULL);
4531 wined3d_mutex_unlock();
4534 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
4535 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4537 struct d3d_device *device = impl_from_ID3D10Device(iface);
4538 unsigned int i;
4540 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4541 iface, start_slot, view_count, views);
4543 wined3d_mutex_lock();
4544 for (i = 0; i < view_count; ++i)
4546 struct wined3d_shader_resource_view *wined3d_view;
4547 struct d3d_shader_resource_view *view_impl;
4549 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
4551 views[i] = NULL;
4552 continue;
4555 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4556 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4557 ID3D10ShaderResourceView_AddRef(views[i]);
4559 wined3d_mutex_unlock();
4562 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
4563 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4565 struct d3d_device *device = impl_from_ID3D10Device(iface);
4566 unsigned int i;
4568 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4569 iface, start_slot, sampler_count, samplers);
4571 wined3d_mutex_lock();
4572 for (i = 0; i < sampler_count; ++i)
4574 struct d3d_sampler_state *sampler_impl;
4575 struct wined3d_sampler *wined3d_sampler;
4577 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4579 samplers[i] = NULL;
4580 continue;
4583 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4584 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4585 ID3D10SamplerState_AddRef(samplers[i]);
4587 wined3d_mutex_unlock();
4590 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4591 ID3D10Predicate **predicate, BOOL *value)
4593 struct d3d_device *device = impl_from_ID3D10Device(iface);
4594 struct wined3d_query *wined3d_predicate;
4595 struct d3d_query *predicate_impl;
4597 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4599 wined3d_mutex_lock();
4600 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4602 wined3d_mutex_unlock();
4603 *predicate = NULL;
4604 return;
4607 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4608 wined3d_mutex_unlock();
4609 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4610 ID3D10Predicate_AddRef(*predicate);
4613 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4614 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4616 struct d3d_device *device = impl_from_ID3D10Device(iface);
4617 unsigned int i;
4619 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4620 iface, start_slot, view_count, views);
4622 wined3d_mutex_lock();
4623 for (i = 0; i < view_count; ++i)
4625 struct wined3d_shader_resource_view *wined3d_view;
4626 struct d3d_shader_resource_view *view_impl;
4628 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4630 views[i] = NULL;
4631 continue;
4634 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4635 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4636 ID3D10ShaderResourceView_AddRef(views[i]);
4638 wined3d_mutex_unlock();
4641 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4642 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4644 struct d3d_device *device = impl_from_ID3D10Device(iface);
4645 unsigned int i;
4647 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4648 iface, start_slot, sampler_count, samplers);
4650 wined3d_mutex_lock();
4651 for (i = 0; i < sampler_count; ++i)
4653 struct d3d_sampler_state *sampler_impl;
4654 struct wined3d_sampler *wined3d_sampler;
4656 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4658 samplers[i] = NULL;
4659 continue;
4662 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4663 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4664 ID3D10SamplerState_AddRef(samplers[i]);
4666 wined3d_mutex_unlock();
4669 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4670 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4672 struct d3d_device *device = impl_from_ID3D10Device(iface);
4673 struct wined3d_rendertarget_view *wined3d_view;
4675 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4676 iface, view_count, render_target_views, depth_stencil_view);
4678 wined3d_mutex_lock();
4679 if (render_target_views)
4681 struct d3d_rendertarget_view *view_impl;
4682 unsigned int i;
4684 for (i = 0; i < view_count; ++i)
4686 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4687 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4689 render_target_views[i] = NULL;
4690 continue;
4693 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4694 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4698 if (depth_stencil_view)
4700 struct d3d_depthstencil_view *view_impl;
4702 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4703 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4705 *depth_stencil_view = NULL;
4707 else
4709 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4710 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4713 wined3d_mutex_unlock();
4716 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4717 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4719 struct d3d_device *device = impl_from_ID3D10Device(iface);
4720 ID3D11BlendState *d3d11_blend_state;
4722 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4723 iface, blend_state, blend_factor, sample_mask);
4725 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4726 &d3d11_blend_state, blend_factor, sample_mask);
4728 if (d3d11_blend_state)
4729 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4730 else
4731 *blend_state = NULL;
4734 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4735 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4737 struct d3d_device *device = impl_from_ID3D10Device(iface);
4738 ID3D11DepthStencilState *d3d11_iface;
4740 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4741 iface, depth_stencil_state, stencil_ref);
4743 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4744 &d3d11_iface, stencil_ref);
4746 if (d3d11_iface)
4747 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4748 else
4749 *depth_stencil_state = NULL;
4752 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4753 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4755 struct d3d_device *device = impl_from_ID3D10Device(iface);
4756 unsigned int i;
4758 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4759 iface, buffer_count, buffers, offsets);
4761 wined3d_mutex_lock();
4762 for (i = 0; i < buffer_count; ++i)
4764 struct wined3d_buffer *wined3d_buffer;
4765 struct d3d_buffer *buffer_impl;
4767 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4769 buffers[i] = NULL;
4770 continue;
4773 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4774 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4775 ID3D10Buffer_AddRef(buffers[i]);
4777 wined3d_mutex_unlock();
4780 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4782 struct d3d_device *device = impl_from_ID3D10Device(iface);
4783 struct d3d_rasterizer_state *rasterizer_state_impl;
4784 struct wined3d_rasterizer_state *wined3d_state;
4786 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4788 wined3d_mutex_lock();
4789 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
4791 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
4792 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
4794 else
4796 *rasterizer_state = NULL;
4798 wined3d_mutex_unlock();
4801 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4802 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4804 struct d3d_device *device = impl_from_ID3D10Device(iface);
4805 struct wined3d_viewport wined3d_vp;
4807 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4809 if (!viewports)
4811 *viewport_count = 1;
4812 return;
4815 if (!*viewport_count)
4816 return;
4818 wined3d_mutex_lock();
4819 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4820 wined3d_mutex_unlock();
4822 viewports[0].TopLeftX = wined3d_vp.x;
4823 viewports[0].TopLeftY = wined3d_vp.y;
4824 viewports[0].Width = wined3d_vp.width;
4825 viewports[0].Height = wined3d_vp.height;
4826 viewports[0].MinDepth = wined3d_vp.min_z;
4827 viewports[0].MaxDepth = wined3d_vp.max_z;
4829 if (*viewport_count > 1)
4830 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4833 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4835 struct d3d_device *device = impl_from_ID3D10Device(iface);
4837 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4839 if (!rects)
4841 *rect_count = 1;
4842 return;
4845 if (!*rect_count)
4846 return;
4848 wined3d_mutex_lock();
4849 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4850 wined3d_mutex_unlock();
4851 if (*rect_count > 1)
4852 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4855 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4857 TRACE("iface %p.\n", iface);
4859 /* In the current implementation the device is never removed, so we can
4860 * just return S_OK here. */
4862 return S_OK;
4865 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4867 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4869 return E_NOTIMPL;
4872 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4874 FIXME("iface %p stub!\n", iface);
4876 return 0;
4879 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4880 REFGUID guid, UINT *data_size, void *data)
4882 struct d3d_device *device = impl_from_ID3D10Device(iface);
4884 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4886 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4889 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4890 REFGUID guid, UINT data_size, const void *data)
4892 struct d3d_device *device = impl_from_ID3D10Device(iface);
4894 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4896 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4899 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4900 REFGUID guid, const IUnknown *data)
4902 struct d3d_device *device = impl_from_ID3D10Device(iface);
4904 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4906 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4909 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4911 struct d3d_device *device = impl_from_ID3D10Device(iface);
4913 TRACE("iface %p.\n", iface);
4915 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext_iface);
4918 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4920 FIXME("iface %p stub!\n", iface);
4923 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4924 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4926 struct d3d_device *device = impl_from_ID3D10Device(iface);
4927 D3D11_BUFFER_DESC d3d11_desc;
4928 struct d3d_buffer *object;
4929 HRESULT hr;
4931 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
4933 d3d11_desc.ByteWidth = desc->ByteWidth;
4934 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4935 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4936 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4937 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4938 d3d11_desc.StructureByteStride = 0;
4940 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4941 return hr;
4943 *buffer = &object->ID3D10Buffer_iface;
4945 return S_OK;
4948 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
4949 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
4951 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
4953 return E_NOTIMPL;
4956 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
4957 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4958 ID3D10Texture2D **texture)
4960 struct d3d_device *device = impl_from_ID3D10Device(iface);
4961 D3D11_TEXTURE2D_DESC d3d11_desc;
4962 struct d3d_texture2d *object;
4963 HRESULT hr;
4965 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4967 d3d11_desc.Width = desc->Width;
4968 d3d11_desc.Height = desc->Height;
4969 d3d11_desc.MipLevels = desc->MipLevels;
4970 d3d11_desc.ArraySize = desc->ArraySize;
4971 d3d11_desc.Format = desc->Format;
4972 d3d11_desc.SampleDesc = desc->SampleDesc;
4973 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4974 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4975 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4976 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4978 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4979 return hr;
4981 *texture = &object->ID3D10Texture2D_iface;
4983 return S_OK;
4986 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
4987 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4988 ID3D10Texture3D **texture)
4990 struct d3d_device *device = impl_from_ID3D10Device(iface);
4991 D3D11_TEXTURE3D_DESC d3d11_desc;
4992 struct d3d_texture3d *object;
4993 HRESULT hr;
4995 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4997 d3d11_desc.Width = desc->Width;
4998 d3d11_desc.Height = desc->Height;
4999 d3d11_desc.Depth = desc->Depth;
5000 d3d11_desc.MipLevels = desc->MipLevels;
5001 d3d11_desc.Format = desc->Format;
5002 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5003 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5004 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5005 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5007 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5008 return hr;
5010 *texture = &object->ID3D10Texture3D_iface;
5012 return S_OK;
5015 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5016 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5018 struct d3d_device *device = impl_from_ID3D10Device(iface);
5019 struct d3d_shader_resource_view *object;
5020 ID3D11Resource *d3d11_resource;
5021 HRESULT hr;
5023 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5025 if (!resource)
5026 return E_INVALIDARG;
5028 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5030 ERR("Resource does not implement ID3D11Resource.\n");
5031 return E_FAIL;
5034 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5035 &object);
5036 ID3D11Resource_Release(d3d11_resource);
5037 if (FAILED(hr))
5038 return hr;
5040 *view = &object->ID3D10ShaderResourceView1_iface;
5042 return S_OK;
5045 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5046 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5048 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5050 return d3d10_device_CreateShaderResourceView1(iface, resource,
5051 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5054 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5055 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5057 struct d3d_device *device = impl_from_ID3D10Device(iface);
5058 struct d3d_rendertarget_view *object;
5059 ID3D11Resource *d3d11_resource;
5060 HRESULT hr;
5062 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5064 if (!resource)
5065 return E_INVALIDARG;
5067 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5069 ERR("Resource does not implement ID3D11Resource.\n");
5070 return E_FAIL;
5073 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5074 ID3D11Resource_Release(d3d11_resource);
5075 if (FAILED(hr))
5076 return hr;
5078 *view = &object->ID3D10RenderTargetView_iface;
5080 return S_OK;
5083 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5084 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5086 struct d3d_device *device = impl_from_ID3D10Device(iface);
5087 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5088 struct d3d_depthstencil_view *object;
5089 ID3D11Resource *d3d11_resource;
5090 HRESULT hr;
5092 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5094 if (desc)
5096 d3d11_desc.Format = desc->Format;
5097 d3d11_desc.ViewDimension = desc->ViewDimension;
5098 d3d11_desc.Flags = 0;
5099 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5102 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5104 ERR("Resource does not implement ID3D11Resource.\n");
5105 return E_FAIL;
5108 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5109 ID3D11Resource_Release(d3d11_resource);
5110 if (FAILED(hr))
5111 return hr;
5113 *view = &object->ID3D10DepthStencilView_iface;
5115 return S_OK;
5118 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5119 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5120 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5121 ID3D10InputLayout **input_layout)
5123 struct d3d_device *device = impl_from_ID3D10Device(iface);
5124 struct d3d_input_layout *object;
5125 HRESULT hr;
5127 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5128 "shader_byte_code_length %lu, input_layout %p\n",
5129 iface, element_descs, element_count, shader_byte_code,
5130 shader_byte_code_length, input_layout);
5132 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5133 shader_byte_code, shader_byte_code_length, &object)))
5134 return hr;
5136 *input_layout = &object->ID3D10InputLayout_iface;
5138 return S_OK;
5141 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5142 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5144 struct d3d_device *device = impl_from_ID3D10Device(iface);
5145 struct d3d_vertex_shader *object;
5146 HRESULT hr;
5148 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5149 iface, byte_code, byte_code_length, shader);
5151 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5152 return hr;
5154 *shader = &object->ID3D10VertexShader_iface;
5156 return S_OK;
5159 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5160 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5162 struct d3d_device *device = impl_from_ID3D10Device(iface);
5163 struct d3d_geometry_shader *object;
5164 HRESULT hr;
5166 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5167 iface, byte_code, byte_code_length, shader);
5169 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5170 NULL, 0, NULL, 0, 0, &object)))
5171 return hr;
5173 *shader = &object->ID3D10GeometryShader_iface;
5175 return S_OK;
5178 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5179 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5180 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5182 struct d3d_device *device = impl_from_ID3D10Device(iface);
5183 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5184 struct d3d_geometry_shader *object;
5185 unsigned int i, stride_count = 1;
5186 HRESULT hr;
5188 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5189 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5190 iface, byte_code, byte_code_length, output_stream_decls,
5191 output_stream_decl_count, output_stream_stride, shader);
5193 if (!output_stream_decl_count && output_stream_stride)
5195 WARN("Stride must be 0 when declaration entry count is 0.\n");
5196 *shader = NULL;
5197 return E_INVALIDARG;
5200 if (output_stream_decl_count
5201 && !(so_entries = d3d11_calloc(output_stream_decl_count, sizeof(*so_entries))))
5203 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5204 *shader = NULL;
5205 return E_OUTOFMEMORY;
5208 for (i = 0; i < output_stream_decl_count; ++i)
5210 so_entries[i].Stream = 0;
5211 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5212 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5213 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5214 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5215 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5217 if (output_stream_decls[i].OutputSlot)
5219 stride_count = 0;
5220 if (output_stream_stride)
5222 WARN("Stride must be 0 when multiple output slots are used.\n");
5223 HeapFree(GetProcessHeap(), 0, so_entries);
5224 *shader = NULL;
5225 return E_INVALIDARG;
5230 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5231 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5232 HeapFree(GetProcessHeap(), 0, so_entries);
5233 if (FAILED(hr))
5235 *shader = NULL;
5236 return hr;
5239 *shader = &object->ID3D10GeometryShader_iface;
5241 return hr;
5244 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5245 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5247 struct d3d_device *device = impl_from_ID3D10Device(iface);
5248 struct d3d_pixel_shader *object;
5249 HRESULT hr;
5251 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5252 iface, byte_code, byte_code_length, shader);
5254 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
5255 return hr;
5257 *shader = &object->ID3D10PixelShader_iface;
5259 return S_OK;
5262 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
5263 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
5265 struct d3d_device *device = impl_from_ID3D10Device(iface);
5266 struct d3d_blend_state *object;
5267 HRESULT hr;
5269 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5271 if (FAILED(hr = d3d_blend_state_create(device, (const D3D11_BLEND_DESC *)desc, &object)))
5272 return hr;
5274 *blend_state = &object->ID3D10BlendState1_iface;
5276 return S_OK;
5279 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
5280 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
5282 D3D10_BLEND_DESC1 d3d10_1_desc;
5283 unsigned int i;
5285 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5287 if (!desc)
5288 return E_INVALIDARG;
5290 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
5291 d3d10_1_desc.IndependentBlendEnable = FALSE;
5292 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
5294 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
5295 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
5296 d3d10_1_desc.IndependentBlendEnable = TRUE;
5299 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5301 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
5302 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
5303 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
5304 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
5305 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
5306 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
5307 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
5308 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
5311 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
5314 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
5315 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
5317 struct d3d_device *device = impl_from_ID3D10Device(iface);
5318 struct d3d_depthstencil_state *object;
5319 HRESULT hr;
5321 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
5323 if (FAILED(hr = d3d_depthstencil_state_create(device, (const D3D11_DEPTH_STENCIL_DESC *)desc, &object)))
5324 return hr;
5326 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
5328 return S_OK;
5331 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
5332 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
5334 struct d3d_device *device = impl_from_ID3D10Device(iface);
5335 struct d3d_rasterizer_state *object;
5336 HRESULT hr;
5338 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
5340 if (FAILED(hr = d3d_rasterizer_state_create(device, (const D3D11_RASTERIZER_DESC *)desc, &object)))
5341 return hr;
5343 *rasterizer_state = &object->ID3D10RasterizerState_iface;
5345 return S_OK;
5348 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
5349 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
5351 struct d3d_device *device = impl_from_ID3D10Device(iface);
5352 struct d3d_sampler_state *object;
5353 HRESULT hr;
5355 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
5357 if (FAILED(hr = d3d_sampler_state_create(device, (const D3D11_SAMPLER_DESC *)desc, &object)))
5358 return hr;
5360 *sampler_state = &object->ID3D10SamplerState_iface;
5362 return S_OK;
5365 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
5366 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
5368 struct d3d_device *device = impl_from_ID3D10Device(iface);
5369 struct d3d_query *object;
5370 HRESULT hr;
5372 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
5374 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
5375 return hr;
5377 if (query)
5379 *query = &object->ID3D10Query_iface;
5380 return S_OK;
5383 ID3D10Query_Release(&object->ID3D10Query_iface);
5384 return S_FALSE;
5387 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
5388 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
5390 struct d3d_device *device = impl_from_ID3D10Device(iface);
5391 struct d3d_query *object;
5392 HRESULT hr;
5394 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
5396 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
5397 return hr;
5399 if (predicate)
5401 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
5402 return S_OK;
5405 ID3D10Query_Release(&object->ID3D10Query_iface);
5406 return S_FALSE;
5409 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
5410 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
5412 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
5414 return E_NOTIMPL;
5417 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
5418 DXGI_FORMAT format, UINT *format_support)
5420 struct d3d_device *device = impl_from_ID3D10Device(iface);
5422 TRACE("iface %p, format %s, format_support %p.\n",
5423 iface, debug_dxgi_format(format), format_support);
5425 return d3d11_device_CheckFormatSupport(&device->ID3D11Device_iface, format, format_support);
5428 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
5429 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
5431 struct d3d_device *device = impl_from_ID3D10Device(iface);
5433 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
5434 iface, debug_dxgi_format(format), sample_count, quality_level_count);
5436 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
5437 sample_count, quality_level_count);
5440 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
5442 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
5445 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
5446 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
5447 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
5449 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
5450 "units %p, units_length %p, description %p, description_length %p stub!\n",
5451 iface, desc, type, active_counters, name, name_length,
5452 units, units_length, description, description_length);
5454 return E_NOTIMPL;
5457 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
5459 FIXME("iface %p stub!\n", iface);
5461 return 0;
5464 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
5465 HANDLE resource_handle, REFIID guid, void **resource)
5467 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
5468 iface, resource_handle, debugstr_guid(guid), resource);
5470 return E_NOTIMPL;
5473 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
5475 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
5478 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
5480 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
5483 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
5485 struct d3d_device *device = impl_from_ID3D10Device(iface);
5487 TRACE("iface %p.\n", iface);
5489 return device->feature_level;
5492 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
5494 /* IUnknown methods */
5495 d3d10_device_QueryInterface,
5496 d3d10_device_AddRef,
5497 d3d10_device_Release,
5498 /* ID3D10Device methods */
5499 d3d10_device_VSSetConstantBuffers,
5500 d3d10_device_PSSetShaderResources,
5501 d3d10_device_PSSetShader,
5502 d3d10_device_PSSetSamplers,
5503 d3d10_device_VSSetShader,
5504 d3d10_device_DrawIndexed,
5505 d3d10_device_Draw,
5506 d3d10_device_PSSetConstantBuffers,
5507 d3d10_device_IASetInputLayout,
5508 d3d10_device_IASetVertexBuffers,
5509 d3d10_device_IASetIndexBuffer,
5510 d3d10_device_DrawIndexedInstanced,
5511 d3d10_device_DrawInstanced,
5512 d3d10_device_GSSetConstantBuffers,
5513 d3d10_device_GSSetShader,
5514 d3d10_device_IASetPrimitiveTopology,
5515 d3d10_device_VSSetShaderResources,
5516 d3d10_device_VSSetSamplers,
5517 d3d10_device_SetPredication,
5518 d3d10_device_GSSetShaderResources,
5519 d3d10_device_GSSetSamplers,
5520 d3d10_device_OMSetRenderTargets,
5521 d3d10_device_OMSetBlendState,
5522 d3d10_device_OMSetDepthStencilState,
5523 d3d10_device_SOSetTargets,
5524 d3d10_device_DrawAuto,
5525 d3d10_device_RSSetState,
5526 d3d10_device_RSSetViewports,
5527 d3d10_device_RSSetScissorRects,
5528 d3d10_device_CopySubresourceRegion,
5529 d3d10_device_CopyResource,
5530 d3d10_device_UpdateSubresource,
5531 d3d10_device_ClearRenderTargetView,
5532 d3d10_device_ClearDepthStencilView,
5533 d3d10_device_GenerateMips,
5534 d3d10_device_ResolveSubresource,
5535 d3d10_device_VSGetConstantBuffers,
5536 d3d10_device_PSGetShaderResources,
5537 d3d10_device_PSGetShader,
5538 d3d10_device_PSGetSamplers,
5539 d3d10_device_VSGetShader,
5540 d3d10_device_PSGetConstantBuffers,
5541 d3d10_device_IAGetInputLayout,
5542 d3d10_device_IAGetVertexBuffers,
5543 d3d10_device_IAGetIndexBuffer,
5544 d3d10_device_GSGetConstantBuffers,
5545 d3d10_device_GSGetShader,
5546 d3d10_device_IAGetPrimitiveTopology,
5547 d3d10_device_VSGetShaderResources,
5548 d3d10_device_VSGetSamplers,
5549 d3d10_device_GetPredication,
5550 d3d10_device_GSGetShaderResources,
5551 d3d10_device_GSGetSamplers,
5552 d3d10_device_OMGetRenderTargets,
5553 d3d10_device_OMGetBlendState,
5554 d3d10_device_OMGetDepthStencilState,
5555 d3d10_device_SOGetTargets,
5556 d3d10_device_RSGetState,
5557 d3d10_device_RSGetViewports,
5558 d3d10_device_RSGetScissorRects,
5559 d3d10_device_GetDeviceRemovedReason,
5560 d3d10_device_SetExceptionMode,
5561 d3d10_device_GetExceptionMode,
5562 d3d10_device_GetPrivateData,
5563 d3d10_device_SetPrivateData,
5564 d3d10_device_SetPrivateDataInterface,
5565 d3d10_device_ClearState,
5566 d3d10_device_Flush,
5567 d3d10_device_CreateBuffer,
5568 d3d10_device_CreateTexture1D,
5569 d3d10_device_CreateTexture2D,
5570 d3d10_device_CreateTexture3D,
5571 d3d10_device_CreateShaderResourceView,
5572 d3d10_device_CreateRenderTargetView,
5573 d3d10_device_CreateDepthStencilView,
5574 d3d10_device_CreateInputLayout,
5575 d3d10_device_CreateVertexShader,
5576 d3d10_device_CreateGeometryShader,
5577 d3d10_device_CreateGeometryShaderWithStreamOutput,
5578 d3d10_device_CreatePixelShader,
5579 d3d10_device_CreateBlendState,
5580 d3d10_device_CreateDepthStencilState,
5581 d3d10_device_CreateRasterizerState,
5582 d3d10_device_CreateSamplerState,
5583 d3d10_device_CreateQuery,
5584 d3d10_device_CreatePredicate,
5585 d3d10_device_CreateCounter,
5586 d3d10_device_CheckFormatSupport,
5587 d3d10_device_CheckMultisampleQualityLevels,
5588 d3d10_device_CheckCounterInfo,
5589 d3d10_device_CheckCounter,
5590 d3d10_device_GetCreationFlags,
5591 d3d10_device_OpenSharedResource,
5592 d3d10_device_SetTextFilterSize,
5593 d3d10_device_GetTextFilterSize,
5594 d3d10_device_CreateShaderResourceView1,
5595 d3d10_device_CreateBlendState1,
5596 d3d10_device_GetFeatureLevel,
5599 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5601 /* IUnknown methods */
5602 d3d_device_inner_QueryInterface,
5603 d3d_device_inner_AddRef,
5604 d3d_device_inner_Release,
5607 /* ID3D10Multithread methods */
5609 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5611 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5614 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5616 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5618 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5620 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5623 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5625 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5627 TRACE("iface %p.\n", iface);
5629 return IUnknown_AddRef(device->outer_unk);
5632 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5634 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5636 TRACE("iface %p.\n", iface);
5638 return IUnknown_Release(device->outer_unk);
5641 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5643 TRACE("iface %p.\n", iface);
5645 wined3d_mutex_lock();
5648 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5650 TRACE("iface %p.\n", iface);
5652 wined3d_mutex_unlock();
5655 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5657 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5659 return TRUE;
5662 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5664 FIXME("iface %p stub!\n", iface);
5666 return TRUE;
5669 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5671 d3d10_multithread_QueryInterface,
5672 d3d10_multithread_AddRef,
5673 d3d10_multithread_Release,
5674 d3d10_multithread_Enter,
5675 d3d10_multithread_Leave,
5676 d3d10_multithread_SetMultithreadProtected,
5677 d3d10_multithread_GetMultithreadProtected,
5680 /* IWineDXGIDeviceParent IUnknown methods */
5682 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5684 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5687 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5688 REFIID riid, void **ppv)
5690 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5691 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5694 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5696 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5697 return IUnknown_AddRef(device->outer_unk);
5700 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5702 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5703 return IUnknown_Release(device->outer_unk);
5706 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5707 IWineDXGIDeviceParent *iface)
5709 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5710 return &device->device_parent;
5713 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5715 /* IUnknown methods */
5716 dxgi_device_parent_QueryInterface,
5717 dxgi_device_parent_AddRef,
5718 dxgi_device_parent_Release,
5719 /* IWineDXGIDeviceParent methods */
5720 dxgi_device_parent_get_wined3d_device_parent,
5723 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5725 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5728 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5729 struct wined3d_device *wined3d_device)
5731 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5733 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5735 wined3d_device_incref(wined3d_device);
5736 device->wined3d_device = wined3d_device;
5738 set_default_depth_stencil_state(wined3d_device);
5741 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5743 TRACE("device_parent %p.\n", device_parent);
5746 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5748 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5751 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5752 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5753 const struct wined3d_parent_ops **parent_ops)
5755 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5756 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5758 *parent = NULL;
5759 *parent_ops = &d3d_null_wined3d_parent_ops;
5761 return S_OK;
5764 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5765 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
5766 struct wined3d_texture **wined3d_texture)
5768 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5769 struct d3d_texture2d *texture;
5770 ID3D10Texture2D *texture_iface;
5771 D3D10_TEXTURE2D_DESC desc;
5772 HRESULT hr;
5774 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, texture flags %#x, "
5775 "wined3d_texture %p partial stub!\n", device_parent, container_parent,
5776 wined3d_desc, texture_flags, wined3d_texture);
5778 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5780 desc.Width = wined3d_desc->width;
5781 desc.Height = wined3d_desc->height;
5782 desc.MipLevels = 1;
5783 desc.ArraySize = 1;
5784 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5785 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5786 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5787 desc.Usage = D3D10_USAGE_DEFAULT;
5788 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5789 desc.CPUAccessFlags = 0;
5790 desc.MiscFlags = 0;
5792 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
5794 desc.MiscFlags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
5795 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
5798 if (texture_flags)
5799 FIXME("Unhandled flags %#x.\n", texture_flags);
5801 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5802 &desc, NULL, &texture_iface)))
5804 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5805 return hr;
5808 texture = impl_from_ID3D10Texture2D(texture_iface);
5810 *wined3d_texture = texture->wined3d_texture;
5811 wined3d_texture_incref(*wined3d_texture);
5812 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5814 return S_OK;
5817 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5818 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5820 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5821 IWineDXGIDevice *wine_device;
5822 HRESULT hr;
5824 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5826 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5827 &IID_IWineDXGIDevice, (void **)&wine_device)))
5829 ERR("Device should implement IWineDXGIDevice.\n");
5830 return E_FAIL;
5833 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5834 IWineDXGIDevice_Release(wine_device);
5835 if (FAILED(hr))
5837 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5838 return hr;
5841 return S_OK;
5844 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5846 device_parent_wined3d_device_created,
5847 device_parent_mode_changed,
5848 device_parent_activate,
5849 device_parent_sub_resource_created,
5850 device_parent_sub_resource_created,
5851 device_parent_create_swapchain_texture,
5852 device_parent_create_swapchain,
5855 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5857 const D3D11_SAMPLER_DESC *ka = key;
5858 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5860 return memcmp(ka, kb, sizeof(*ka));
5863 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5865 const D3D11_BLEND_DESC *ka = key;
5866 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5868 return memcmp(ka, kb, sizeof(*ka));
5871 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5873 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5874 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5875 const struct d3d_depthstencil_state, entry)->desc;
5877 return memcmp(ka, kb, sizeof(*ka));
5880 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5882 const D3D11_RASTERIZER_DESC *ka = key;
5883 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5885 return memcmp(ka, kb, sizeof(*ka));
5888 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
5890 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5891 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5892 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5893 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5894 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5895 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5896 device->refcount = 1;
5897 /* COM aggregation always takes place */
5898 device->outer_unk = outer_unknown;
5900 d3d11_immediate_context_init(&device->immediate_context, device);
5901 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5903 device->blend_factor[0] = 1.0f;
5904 device->blend_factor[1] = 1.0f;
5905 device->blend_factor[2] = 1.0f;
5906 device->blend_factor[3] = 1.0f;
5908 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
5909 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
5910 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
5911 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);