d3d11: Implement d3d11_immediate_context_DSGetSamplers().
[wine.git] / dlls / d3d11 / device.c
blob136917b458cd938d96700462f5942633e40df713
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);
446 TRACE("iface %p, topology %u.\n", iface, topology);
448 wined3d_mutex_lock();
449 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
450 wined3d_mutex_unlock();
453 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShaderResources(ID3D11DeviceContext *iface,
454 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
456 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
457 unsigned int i;
459 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
461 wined3d_mutex_lock();
462 for (i = 0; i < view_count; ++i)
464 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
466 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
467 view ? view->wined3d_view : NULL);
469 wined3d_mutex_unlock();
472 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetSamplers(ID3D11DeviceContext *iface,
473 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
475 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
476 unsigned int i;
478 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
479 iface, start_slot, sampler_count, samplers);
481 wined3d_mutex_lock();
482 for (i = 0; i < sampler_count; ++i)
484 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
486 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
487 sampler ? sampler->wined3d_sampler : NULL);
489 wined3d_mutex_unlock();
492 static void STDMETHODCALLTYPE d3d11_immediate_context_Begin(ID3D11DeviceContext *iface,
493 ID3D11Asynchronous *asynchronous)
495 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
496 HRESULT hr;
498 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
500 wined3d_mutex_lock();
501 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_BEGIN)))
502 ERR("Failed to issue query, hr %#x.\n", hr);
503 wined3d_mutex_unlock();
506 static void STDMETHODCALLTYPE d3d11_immediate_context_End(ID3D11DeviceContext *iface,
507 ID3D11Asynchronous *asynchronous)
509 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
510 HRESULT hr;
512 TRACE("iface %p, asynchronous %p.\n", iface, asynchronous);
514 wined3d_mutex_lock();
515 if (FAILED(hr = wined3d_query_issue(query->wined3d_query, WINED3DISSUE_END)))
516 ERR("Failed to issue query, hr %#x.\n", hr);
517 wined3d_mutex_unlock();
520 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetData(ID3D11DeviceContext *iface,
521 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
523 struct d3d_query *query = unsafe_impl_from_ID3D11Asynchronous(asynchronous);
524 unsigned int wined3d_flags;
525 HRESULT hr;
527 TRACE("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x.\n",
528 iface, asynchronous, data, data_size, data_flags);
530 if (!data && data_size)
531 return E_INVALIDARG;
533 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
535 wined3d_mutex_lock();
536 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
538 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
539 if (hr == WINED3DERR_INVALIDCALL)
540 hr = DXGI_ERROR_INVALID_CALL;
542 else
544 WARN("Invalid data size %u.\n", data_size);
545 hr = E_INVALIDARG;
547 wined3d_mutex_unlock();
549 return hr;
552 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext *iface,
553 ID3D11Predicate *predicate, BOOL value)
555 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
556 struct d3d_query *query;
558 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
560 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
562 wined3d_mutex_lock();
563 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
564 wined3d_mutex_unlock();
567 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext *iface,
568 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
570 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
571 unsigned int i;
573 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
575 wined3d_mutex_lock();
576 for (i = 0; i < view_count; ++i)
578 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
580 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
581 view ? view->wined3d_view : NULL);
583 wined3d_mutex_unlock();
586 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext *iface,
587 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
589 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
590 unsigned int i;
592 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
593 iface, start_slot, sampler_count, samplers);
595 wined3d_mutex_lock();
596 for (i = 0; i < sampler_count; ++i)
598 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
600 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
601 sampler ? sampler->wined3d_sampler : NULL);
603 wined3d_mutex_unlock();
606 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext *iface,
607 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
608 ID3D11DepthStencilView *depth_stencil_view)
610 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
611 struct d3d_depthstencil_view *dsv;
612 unsigned int i;
614 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
615 iface, render_target_view_count, render_target_views, depth_stencil_view);
617 wined3d_mutex_lock();
618 for (i = 0; i < render_target_view_count; ++i)
620 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
621 wined3d_device_set_rendertarget_view(device->wined3d_device, i, rtv ? rtv->wined3d_view : NULL, FALSE);
623 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
625 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
628 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
629 wined3d_device_set_depth_stencil_view(device->wined3d_device, dsv ? dsv->wined3d_view : NULL);
630 wined3d_mutex_unlock();
633 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
634 ID3D11DeviceContext *iface, UINT render_target_view_count,
635 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
636 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
637 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
639 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
640 unsigned int i;
642 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
643 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
644 "initial_counts %p.\n",
645 iface, render_target_view_count, render_target_views, depth_stencil_view,
646 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
647 initial_counts);
649 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
651 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
652 depth_stencil_view);
655 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
657 wined3d_mutex_lock();
658 for (i = 0; i < unordered_access_view_start_slot; ++i)
660 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
662 for (i = 0; i < unordered_access_view_count; ++i)
664 struct d3d11_unordered_access_view *view
665 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
667 if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
668 && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
669 && initial_counts[i] != ~(UINT)0)
670 FIXME("Ignoring initial count %u for slot %u.\n",
671 initial_counts[i], unordered_access_view_start_slot + i);
673 wined3d_device_set_unordered_access_view(device->wined3d_device,
674 unordered_access_view_start_slot + i,
675 view ? view->wined3d_view : NULL);
677 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
679 wined3d_device_set_unordered_access_view(device->wined3d_device,
680 unordered_access_view_start_slot + i, NULL);
682 wined3d_mutex_unlock();
686 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
687 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
689 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
690 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
691 const D3D11_BLEND_DESC *desc;
693 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
694 iface, blend_state, debug_float4(blend_factor), sample_mask);
696 if (!blend_factor)
697 blend_factor = default_blend_factor;
699 wined3d_mutex_lock();
700 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
701 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
702 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
704 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
705 wined3d_device_set_render_state(device->wined3d_device,
706 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
707 wined3d_device_set_render_state(device->wined3d_device,
708 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
709 wined3d_device_set_render_state(device->wined3d_device,
710 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
711 wined3d_device_set_render_state(device->wined3d_device,
712 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
713 wined3d_mutex_unlock();
714 return;
717 desc = &device->blend_state->desc;
718 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
719 desc->RenderTarget[0].BlendEnable);
720 if (desc->RenderTarget[0].BlendEnable)
722 const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0];
724 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, d->SrcBlend);
725 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, d->DestBlend);
726 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, d->BlendOp);
727 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
728 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, d->SrcBlendAlpha);
729 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, d->DestBlendAlpha);
730 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, d->BlendOpAlpha);
732 if (memcmp(blend_factor, default_blend_factor, sizeof(default_blend_factor))
733 && (d->SrcBlend == D3D11_BLEND_BLEND_FACTOR || d->SrcBlend == D3D11_BLEND_INV_BLEND_FACTOR
734 || d->DestBlend == D3D11_BLEND_BLEND_FACTOR || d->DestBlend == D3D11_BLEND_INV_BLEND_FACTOR
735 || d->SrcBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->SrcBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR
736 || d->DestBlendAlpha == D3D11_BLEND_BLEND_FACTOR || d->DestBlendAlpha == D3D11_BLEND_INV_BLEND_FACTOR))
737 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
739 wined3d_device_set_render_state(device->wined3d_device,
740 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
741 wined3d_device_set_render_state(device->wined3d_device,
742 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
743 wined3d_device_set_render_state(device->wined3d_device,
744 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
745 wined3d_device_set_render_state(device->wined3d_device,
746 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
747 wined3d_mutex_unlock();
750 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
751 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
753 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
754 const D3D11_DEPTH_STENCILOP_DESC *front, *back;
755 const D3D11_DEPTH_STENCIL_DESC *desc;
757 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
758 iface, depth_stencil_state, stencil_ref);
760 wined3d_mutex_lock();
761 device->stencil_ref = stencil_ref;
762 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
764 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE);
765 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
766 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS);
767 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
768 wined3d_mutex_unlock();
769 return;
772 desc = &device->depth_stencil_state->desc;
774 front = &desc->FrontFace;
775 back = &desc->BackFace;
777 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
778 if (desc->DepthEnable)
780 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
781 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
784 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
785 if (desc->StencilEnable)
787 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
788 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
789 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
791 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, front->StencilFailOp);
792 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL, front->StencilDepthFailOp);
793 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, front->StencilPassOp);
794 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, front->StencilFunc);
795 if (front->StencilFailOp != back->StencilFailOp
796 || front->StencilDepthFailOp != back->StencilDepthFailOp
797 || front->StencilPassOp != back->StencilPassOp
798 || front->StencilFunc != back->StencilFunc)
800 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, TRUE);
801 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFAIL, back->StencilFailOp);
802 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILZFAIL,
803 back->StencilDepthFailOp);
804 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILPASS, back->StencilPassOp);
805 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BACK_STENCILFUNC, back->StencilFunc);
807 else
809 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_TWOSIDEDSTENCILMODE, FALSE);
812 wined3d_mutex_unlock();
815 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
816 ID3D11Buffer *const *buffers, const UINT *offsets)
818 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
819 unsigned int count, i;
821 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
823 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
824 wined3d_mutex_lock();
825 for (i = 0; i < count; ++i)
827 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
829 wined3d_device_set_stream_output(device->wined3d_device, i,
830 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
832 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
834 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
836 wined3d_mutex_unlock();
839 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
841 FIXME("iface %p stub!\n", iface);
844 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
845 ID3D11Buffer *buffer, UINT offset)
847 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
850 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
851 ID3D11Buffer *buffer, UINT offset)
853 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
856 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
857 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
859 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
861 TRACE("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u.\n",
862 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
864 wined3d_mutex_lock();
865 wined3d_device_dispatch_compute(device->wined3d_device,
866 thread_group_count_x, thread_group_count_y, thread_group_count_z);
867 wined3d_mutex_unlock();
870 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
871 ID3D11Buffer *buffer, UINT offset)
873 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
876 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
877 ID3D11RasterizerState *rasterizer_state)
879 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
880 struct d3d_rasterizer_state *rasterizer_state_impl;
881 const D3D11_RASTERIZER_DESC *desc;
883 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
885 wined3d_mutex_lock();
886 if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
888 wined3d_device_set_rasterizer_state(device->wined3d_device, NULL);
889 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
890 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_BACK);
891 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
892 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
893 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
894 wined3d_mutex_unlock();
895 return;
898 wined3d_device_set_rasterizer_state(device->wined3d_device, rasterizer_state_impl->wined3d_state);
900 desc = &rasterizer_state_impl->desc;
901 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
902 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
903 /* OpenGL style depth bias. */
904 if (desc->DepthBias || desc->SlopeScaledDepthBias)
905 FIXME("Ignoring depth bias.\n");
906 /* GL_DEPTH_CLAMP */
907 if (!desc->DepthClipEnable)
908 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
909 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
910 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
911 wined3d_device_set_render_state(device->wined3d_device,
912 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
913 wined3d_mutex_unlock();
916 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
917 UINT viewport_count, const D3D11_VIEWPORT *viewports)
919 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
920 struct wined3d_viewport wined3d_vp;
922 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
924 if (viewport_count > 1)
925 FIXME("Multiple viewports not implemented.\n");
927 if (!viewport_count)
928 return;
930 if (viewports[0].TopLeftX != (UINT)viewports[0].TopLeftX
931 || viewports[0].TopLeftY != (UINT)viewports[0].TopLeftY
932 || viewports[0].Width != (UINT)viewports[0].Width
933 || viewports[0].Height != (UINT)viewports[0].Height)
934 FIXME("Floating-point viewports not implemented.\n");
936 wined3d_vp.x = viewports[0].TopLeftX;
937 wined3d_vp.y = viewports[0].TopLeftY;
938 wined3d_vp.width = viewports[0].Width;
939 wined3d_vp.height = viewports[0].Height;
940 wined3d_vp.min_z = viewports[0].MinDepth;
941 wined3d_vp.max_z = viewports[0].MaxDepth;
943 wined3d_mutex_lock();
944 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
945 wined3d_mutex_unlock();
948 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
949 UINT rect_count, const D3D11_RECT *rects)
951 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
953 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
955 if (rect_count > 1)
956 FIXME("Multiple scissor rects not implemented.\n");
958 if (!rect_count)
959 return;
961 wined3d_mutex_lock();
962 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
963 wined3d_mutex_unlock();
966 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
967 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
968 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
970 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
971 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
972 struct wined3d_box wined3d_src_box;
974 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
975 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
976 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
977 src_resource, src_subresource_idx, src_box);
979 if (src_box)
980 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
981 src_box->right, src_box->bottom, src_box->front, src_box->back);
983 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
984 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
985 wined3d_mutex_lock();
986 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
987 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
988 wined3d_mutex_unlock();
991 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
992 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
994 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
995 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
997 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
999 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
1000 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
1001 wined3d_mutex_lock();
1002 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1003 wined3d_mutex_unlock();
1006 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
1007 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1008 const void *data, UINT row_pitch, UINT depth_pitch)
1010 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1011 struct wined3d_resource *wined3d_resource;
1012 struct wined3d_box wined3d_box;
1014 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1015 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1017 if (box)
1018 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1020 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1021 wined3d_mutex_lock();
1022 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1023 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1024 wined3d_mutex_unlock();
1027 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
1028 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1030 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
1031 iface, dst_buffer, dst_offset, src_view);
1034 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
1035 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1037 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1038 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1039 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1040 HRESULT hr;
1042 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1043 iface, render_target_view, debug_float4(color_rgba));
1045 if (!view)
1046 return;
1048 wined3d_mutex_lock();
1049 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1050 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1051 ERR("Failed to clear view, hr %#x.\n", hr);
1052 wined3d_mutex_unlock();
1055 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1056 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1058 FIXME("iface %p, unordered_access_view %p, values {%u %u %u %u} stub!\n",
1059 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1062 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1063 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1065 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1066 iface, unordered_access_view, debug_float4(values));
1069 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1070 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1072 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1073 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1074 DWORD wined3d_flags;
1075 HRESULT hr;
1077 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1078 iface, depth_stencil_view, flags, depth, stencil);
1080 if (!view)
1081 return;
1083 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1085 wined3d_mutex_lock();
1086 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1087 wined3d_flags, NULL, depth, stencil)))
1088 ERR("Failed to clear view, hr %#x.\n", hr);
1089 wined3d_mutex_unlock();
1092 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1093 ID3D11ShaderResourceView *view)
1095 FIXME("iface %p, view %p stub!\n", iface, view);
1098 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1099 ID3D11Resource *resource, FLOAT min_lod)
1101 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1104 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1105 ID3D11Resource *resource)
1107 FIXME("iface %p, resource %p stub!\n", iface, resource);
1109 return 0.0f;
1112 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1113 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1114 ID3D11Resource *src_resource, UINT src_subresource_idx,
1115 DXGI_FORMAT format)
1117 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1118 "format %s stub!\n",
1119 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1120 debug_dxgi_format(format));
1123 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1124 ID3D11CommandList *command_list, BOOL restore_state)
1126 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1129 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1130 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1132 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1133 unsigned int i;
1135 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1136 iface, start_slot, view_count, views);
1138 wined3d_mutex_lock();
1139 for (i = 0; i < view_count; ++i)
1141 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1143 wined3d_device_set_hs_resource_view(device->wined3d_device, start_slot + i,
1144 view ? view->wined3d_view : NULL);
1146 wined3d_mutex_unlock();
1149 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1150 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1152 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1153 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1155 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1156 iface, shader, class_instances, class_instance_count);
1158 if (class_instances)
1159 FIXME("Dynamic linking is not implemented yet.\n");
1161 wined3d_mutex_lock();
1162 wined3d_device_set_hull_shader(device->wined3d_device, hs ? hs->wined3d_shader : NULL);
1163 wined3d_mutex_unlock();
1166 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1167 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1169 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1170 unsigned int i;
1172 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1173 iface, start_slot, sampler_count, samplers);
1175 wined3d_mutex_lock();
1176 for (i = 0; i < sampler_count; ++i)
1178 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1180 wined3d_device_set_hs_sampler(device->wined3d_device, start_slot + i,
1181 sampler ? sampler->wined3d_sampler : NULL);
1183 wined3d_mutex_unlock();
1186 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1187 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1189 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1190 unsigned int i;
1192 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1193 iface, start_slot, buffer_count, buffers);
1195 wined3d_mutex_lock();
1196 for (i = 0; i < buffer_count; ++i)
1198 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1200 wined3d_device_set_hs_cb(device->wined3d_device, start_slot + i,
1201 buffer ? buffer->wined3d_buffer : NULL);
1203 wined3d_mutex_unlock();
1206 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1207 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1209 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1210 unsigned int i;
1212 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1213 iface, start_slot, view_count, views);
1215 wined3d_mutex_lock();
1216 for (i = 0; i < view_count; ++i)
1218 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1220 wined3d_device_set_ds_resource_view(device->wined3d_device, start_slot + i,
1221 view ? view->wined3d_view : NULL);
1223 wined3d_mutex_unlock();
1226 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1227 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1229 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1230 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1232 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1233 iface, shader, class_instances, class_instance_count);
1235 if (class_instances)
1236 FIXME("Dynamic linking is not implemented yet.\n");
1238 wined3d_mutex_lock();
1239 wined3d_device_set_domain_shader(device->wined3d_device, ds ? ds->wined3d_shader : NULL);
1240 wined3d_mutex_unlock();
1243 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1244 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1246 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1247 unsigned int i;
1249 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1250 iface, start_slot, sampler_count, samplers);
1252 wined3d_mutex_lock();
1253 for (i = 0; i < sampler_count; ++i)
1255 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1257 wined3d_device_set_ds_sampler(device->wined3d_device, start_slot + i,
1258 sampler ? sampler->wined3d_sampler : NULL);
1260 wined3d_mutex_unlock();
1263 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1264 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1266 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1267 unsigned int i;
1269 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1270 iface, start_slot, buffer_count, buffers);
1272 wined3d_mutex_lock();
1273 for (i = 0; i < buffer_count; ++i)
1275 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1277 wined3d_device_set_ds_cb(device->wined3d_device, start_slot + i,
1278 buffer ? buffer->wined3d_buffer : NULL);
1280 wined3d_mutex_unlock();
1283 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1284 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1286 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1287 unsigned int i;
1289 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1290 iface, start_slot, view_count, views);
1292 wined3d_mutex_lock();
1293 for (i = 0; i < view_count; ++i)
1295 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1297 wined3d_device_set_cs_resource_view(device->wined3d_device, start_slot + i,
1298 view ? view->wined3d_view : NULL);
1300 wined3d_mutex_unlock();
1303 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1304 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1306 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1307 unsigned int i;
1309 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1310 iface, start_slot, view_count, views, initial_counts);
1312 wined3d_mutex_lock();
1313 for (i = 0; i < view_count; ++i)
1315 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1317 if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
1318 && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
1319 && initial_counts[i] != ~(UINT)0)
1320 FIXME("Ignoring initial count %u for slot %u.\n", initial_counts[i], start_slot + i);
1322 wined3d_device_set_cs_uav(device->wined3d_device, start_slot + i,
1323 view ? view->wined3d_view : NULL);
1325 wined3d_mutex_unlock();
1328 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1329 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1331 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1332 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1334 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1335 iface, shader, class_instances, class_instance_count);
1337 if (class_instances)
1338 FIXME("Dynamic linking is not implemented yet.\n");
1340 wined3d_mutex_lock();
1341 wined3d_device_set_compute_shader(device->wined3d_device, cs ? cs->wined3d_shader : NULL);
1342 wined3d_mutex_unlock();
1345 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1346 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1348 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1349 unsigned int i;
1351 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1352 iface, start_slot, sampler_count, samplers);
1354 wined3d_mutex_lock();
1355 for (i = 0; i < sampler_count; ++i)
1357 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1359 wined3d_device_set_cs_sampler(device->wined3d_device, start_slot + i,
1360 sampler ? sampler->wined3d_sampler : NULL);
1362 wined3d_mutex_unlock();
1365 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1366 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1368 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1369 unsigned int i;
1371 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1372 iface, start_slot, buffer_count, buffers);
1374 wined3d_mutex_lock();
1375 for (i = 0; i < buffer_count; ++i)
1377 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1379 wined3d_device_set_cs_cb(device->wined3d_device, start_slot + i,
1380 buffer ? buffer->wined3d_buffer : NULL);
1382 wined3d_mutex_unlock();
1385 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1386 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1388 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1389 unsigned int i;
1391 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1392 iface, start_slot, buffer_count, buffers);
1394 wined3d_mutex_lock();
1395 for (i = 0; i < buffer_count; ++i)
1397 struct wined3d_buffer *wined3d_buffer;
1398 struct d3d_buffer *buffer_impl;
1400 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1402 buffers[i] = NULL;
1403 continue;
1406 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1407 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1408 ID3D11Buffer_AddRef(buffers[i]);
1410 wined3d_mutex_unlock();
1413 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1414 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1416 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1417 unsigned int i;
1419 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1420 iface, start_slot, view_count, views);
1422 wined3d_mutex_lock();
1423 for (i = 0; i < view_count; ++i)
1425 struct wined3d_shader_resource_view *wined3d_view;
1426 struct d3d_shader_resource_view *view_impl;
1428 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1430 views[i] = NULL;
1431 continue;
1434 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1435 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1436 ID3D11ShaderResourceView_AddRef(views[i]);
1438 wined3d_mutex_unlock();
1441 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1442 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1444 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1445 struct wined3d_shader *wined3d_shader;
1446 struct d3d_pixel_shader *shader_impl;
1448 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1449 iface, shader, class_instances, class_instance_count);
1451 if (class_instances || class_instance_count)
1452 FIXME("Dynamic linking not implemented yet.\n");
1454 wined3d_mutex_lock();
1455 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1457 wined3d_mutex_unlock();
1458 *shader = NULL;
1459 return;
1462 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1463 wined3d_mutex_unlock();
1464 *shader = &shader_impl->ID3D11PixelShader_iface;
1465 ID3D11PixelShader_AddRef(*shader);
1468 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1469 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1471 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1472 unsigned int i;
1474 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1475 iface, start_slot, sampler_count, samplers);
1477 wined3d_mutex_lock();
1478 for (i = 0; i < sampler_count; ++i)
1480 struct wined3d_sampler *wined3d_sampler;
1481 struct d3d_sampler_state *sampler_impl;
1483 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1485 samplers[i] = NULL;
1486 continue;
1489 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1490 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1491 ID3D11SamplerState_AddRef(samplers[i]);
1493 wined3d_mutex_unlock();
1496 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1497 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1499 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1500 struct d3d_vertex_shader *shader_impl;
1501 struct wined3d_shader *wined3d_shader;
1503 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1504 iface, shader, class_instances, class_instance_count);
1506 if (class_instances || class_instance_count)
1507 FIXME("Dynamic linking not implemented yet.\n");
1509 wined3d_mutex_lock();
1510 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1512 wined3d_mutex_unlock();
1513 *shader = NULL;
1514 return;
1517 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1518 wined3d_mutex_unlock();
1519 *shader = &shader_impl->ID3D11VertexShader_iface;
1520 ID3D11VertexShader_AddRef(*shader);
1523 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1524 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1526 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1527 unsigned int i;
1529 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1530 iface, start_slot, buffer_count, buffers);
1532 wined3d_mutex_lock();
1533 for (i = 0; i < buffer_count; ++i)
1535 struct wined3d_buffer *wined3d_buffer;
1536 struct d3d_buffer *buffer_impl;
1538 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1540 buffers[i] = NULL;
1541 continue;
1544 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1545 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1546 ID3D11Buffer_AddRef(buffers[i]);
1548 wined3d_mutex_unlock();
1551 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1552 ID3D11InputLayout **input_layout)
1554 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1555 struct wined3d_vertex_declaration *wined3d_declaration;
1556 struct d3d_input_layout *input_layout_impl;
1558 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1560 wined3d_mutex_lock();
1561 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1563 wined3d_mutex_unlock();
1564 *input_layout = NULL;
1565 return;
1568 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1569 wined3d_mutex_unlock();
1570 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1571 ID3D11InputLayout_AddRef(*input_layout);
1574 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1575 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1577 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1578 unsigned int i;
1580 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1581 iface, start_slot, buffer_count, buffers, strides, offsets);
1583 wined3d_mutex_lock();
1584 for (i = 0; i < buffer_count; ++i)
1586 struct wined3d_buffer *wined3d_buffer;
1587 struct d3d_buffer *buffer_impl;
1589 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1590 &wined3d_buffer, &offsets[i], &strides[i])))
1591 ERR("Failed to get vertex buffer %u.\n", start_slot + i);
1593 if (!wined3d_buffer)
1595 buffers[i] = NULL;
1596 continue;
1599 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1600 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1602 wined3d_mutex_unlock();
1605 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1606 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1608 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1609 enum wined3d_format_id wined3d_format;
1610 struct wined3d_buffer *wined3d_buffer;
1611 struct d3d_buffer *buffer_impl;
1613 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1615 wined3d_mutex_lock();
1616 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1617 *format = dxgi_format_from_wined3dformat(wined3d_format);
1618 if (!wined3d_buffer)
1620 wined3d_mutex_unlock();
1621 *buffer = NULL;
1622 return;
1625 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1626 wined3d_mutex_unlock();
1627 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1630 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1631 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1633 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1634 unsigned int i;
1636 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1637 iface, start_slot, buffer_count, buffers);
1639 wined3d_mutex_lock();
1640 for (i = 0; i < buffer_count; ++i)
1642 struct wined3d_buffer *wined3d_buffer;
1643 struct d3d_buffer *buffer_impl;
1645 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1647 buffers[i] = NULL;
1648 continue;
1651 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1652 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1653 ID3D11Buffer_AddRef(buffers[i]);
1655 wined3d_mutex_unlock();
1658 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1659 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1661 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1662 struct d3d_geometry_shader *shader_impl;
1663 struct wined3d_shader *wined3d_shader;
1665 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1666 iface, shader, class_instances, class_instance_count);
1668 if (class_instances || class_instance_count)
1669 FIXME("Dynamic linking not implemented yet.\n");
1671 wined3d_mutex_lock();
1672 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1674 wined3d_mutex_unlock();
1675 *shader = NULL;
1676 return;
1679 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1680 wined3d_mutex_unlock();
1681 *shader = &shader_impl->ID3D11GeometryShader_iface;
1682 ID3D11GeometryShader_AddRef(*shader);
1685 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1686 D3D11_PRIMITIVE_TOPOLOGY *topology)
1688 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1690 TRACE("iface %p, topology %p.\n", iface, topology);
1692 wined3d_mutex_lock();
1693 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
1694 wined3d_mutex_unlock();
1697 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1698 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1700 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1701 unsigned int i;
1703 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1705 wined3d_mutex_lock();
1706 for (i = 0; i < view_count; ++i)
1708 struct wined3d_shader_resource_view *wined3d_view;
1709 struct d3d_shader_resource_view *view_impl;
1711 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1713 views[i] = NULL;
1714 continue;
1717 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1718 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1719 ID3D11ShaderResourceView_AddRef(views[i]);
1721 wined3d_mutex_unlock();
1724 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1725 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1727 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1728 unsigned int i;
1730 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1731 iface, start_slot, sampler_count, samplers);
1733 wined3d_mutex_lock();
1734 for (i = 0; i < sampler_count; ++i)
1736 struct wined3d_sampler *wined3d_sampler;
1737 struct d3d_sampler_state *sampler_impl;
1739 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1741 samplers[i] = NULL;
1742 continue;
1745 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1746 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1747 ID3D11SamplerState_AddRef(samplers[i]);
1749 wined3d_mutex_unlock();
1752 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1753 ID3D11Predicate **predicate, BOOL *value)
1755 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1756 struct wined3d_query *wined3d_predicate;
1757 struct d3d_query *predicate_impl;
1759 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1761 wined3d_mutex_lock();
1762 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1764 wined3d_mutex_unlock();
1765 *predicate = NULL;
1766 return;
1769 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1770 wined3d_mutex_unlock();
1771 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1772 ID3D11Predicate_AddRef(*predicate);
1775 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1776 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1778 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1779 unsigned int i;
1781 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1783 wined3d_mutex_lock();
1784 for (i = 0; i < view_count; ++i)
1786 struct wined3d_shader_resource_view *wined3d_view;
1787 struct d3d_shader_resource_view *view_impl;
1789 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1791 views[i] = NULL;
1792 continue;
1795 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1796 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1797 ID3D11ShaderResourceView_AddRef(views[i]);
1799 wined3d_mutex_unlock();
1802 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1803 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1805 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1806 unsigned int i;
1808 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1809 iface, start_slot, sampler_count, samplers);
1811 wined3d_mutex_lock();
1812 for (i = 0; i < sampler_count; ++i)
1814 struct d3d_sampler_state *sampler_impl;
1815 struct wined3d_sampler *wined3d_sampler;
1817 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1819 samplers[i] = NULL;
1820 continue;
1823 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1824 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1825 ID3D11SamplerState_AddRef(samplers[i]);
1827 wined3d_mutex_unlock();
1830 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1831 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1832 ID3D11DepthStencilView **depth_stencil_view)
1834 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1835 struct wined3d_rendertarget_view *wined3d_view;
1837 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1838 iface, render_target_view_count, render_target_views, depth_stencil_view);
1840 wined3d_mutex_lock();
1841 if (render_target_views)
1843 struct d3d_rendertarget_view *view_impl;
1844 unsigned int i;
1846 for (i = 0; i < render_target_view_count; ++i)
1848 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1849 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1851 render_target_views[i] = NULL;
1852 continue;
1855 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1856 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1860 if (depth_stencil_view)
1862 struct d3d_depthstencil_view *view_impl;
1864 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1865 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1867 *depth_stencil_view = NULL;
1869 else
1871 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1872 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1875 wined3d_mutex_unlock();
1878 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1879 ID3D11DeviceContext *iface,
1880 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1881 ID3D11DepthStencilView **depth_stencil_view,
1882 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1883 ID3D11UnorderedAccessView **unordered_access_views)
1885 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1886 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1887 "unordered_access_views %p stub!\n",
1888 iface, render_target_view_count, render_target_views, depth_stencil_view,
1889 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1892 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1893 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1895 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1897 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1898 iface, blend_state, blend_factor, sample_mask);
1900 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1901 ID3D11BlendState_AddRef(*blend_state);
1902 wined3d_mutex_lock();
1903 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1904 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1905 wined3d_mutex_unlock();
1908 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1909 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1911 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1913 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1914 iface, depth_stencil_state, stencil_ref);
1916 if ((*depth_stencil_state = device->depth_stencil_state
1917 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
1918 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
1919 *stencil_ref = device->stencil_ref;
1922 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1923 UINT buffer_count, ID3D11Buffer **buffers)
1925 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1926 unsigned int i;
1928 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1930 wined3d_mutex_lock();
1931 for (i = 0; i < buffer_count; ++i)
1933 struct wined3d_buffer *wined3d_buffer;
1934 struct d3d_buffer *buffer_impl;
1936 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1938 buffers[i] = NULL;
1939 continue;
1942 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1943 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1944 ID3D11Buffer_AddRef(buffers[i]);
1946 wined3d_mutex_unlock();
1949 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1950 ID3D11RasterizerState **rasterizer_state)
1952 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1953 struct d3d_rasterizer_state *rasterizer_state_impl;
1954 struct wined3d_rasterizer_state *wined3d_state;
1956 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1958 wined3d_mutex_lock();
1959 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
1961 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
1962 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
1964 else
1966 *rasterizer_state = NULL;
1968 wined3d_mutex_unlock();
1971 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
1972 UINT *viewport_count, D3D11_VIEWPORT *viewports)
1974 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1975 struct wined3d_viewport wined3d_vp;
1977 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1979 if (!viewports)
1981 *viewport_count = 1;
1982 return;
1985 if (!*viewport_count)
1986 return;
1988 wined3d_mutex_lock();
1989 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1990 wined3d_mutex_unlock();
1992 viewports[0].TopLeftX = wined3d_vp.x;
1993 viewports[0].TopLeftY = wined3d_vp.y;
1994 viewports[0].Width = wined3d_vp.width;
1995 viewports[0].Height = wined3d_vp.height;
1996 viewports[0].MinDepth = wined3d_vp.min_z;
1997 viewports[0].MaxDepth = wined3d_vp.max_z;
1999 if (*viewport_count > 1)
2000 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
2003 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
2004 UINT *rect_count, D3D11_RECT *rects)
2006 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2008 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2010 if (!rects)
2012 *rect_count = 1;
2013 return;
2016 if (!*rect_count)
2017 return;
2019 wined3d_mutex_lock();
2020 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
2021 wined3d_mutex_unlock();
2022 if (*rect_count > 1)
2023 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
2026 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
2027 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2029 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2030 unsigned int i;
2032 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2034 wined3d_mutex_lock();
2035 for (i = 0; i < view_count; ++i)
2037 struct wined3d_shader_resource_view *wined3d_view;
2038 struct d3d_shader_resource_view *view_impl;
2040 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2042 views[i] = NULL;
2043 continue;
2046 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2047 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2049 wined3d_mutex_unlock();
2052 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
2053 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2055 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2056 struct d3d11_hull_shader *shader_impl;
2057 struct wined3d_shader *wined3d_shader;
2059 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2060 iface, shader, class_instances, class_instance_count);
2062 if (class_instances || class_instance_count)
2063 FIXME("Dynamic linking not implemented yet.\n");
2065 wined3d_mutex_lock();
2066 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2068 wined3d_mutex_unlock();
2069 *shader = NULL;
2070 return;
2073 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2074 wined3d_mutex_unlock();
2075 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2078 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
2079 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2081 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2082 unsigned int i;
2084 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2085 iface, start_slot, sampler_count, samplers);
2087 wined3d_mutex_lock();
2088 for (i = 0; i < sampler_count; ++i)
2090 struct wined3d_sampler *wined3d_sampler;
2091 struct d3d_sampler_state *sampler_impl;
2093 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2095 samplers[i] = NULL;
2096 continue;
2099 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2100 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2102 wined3d_mutex_unlock();
2105 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
2106 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2108 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2109 unsigned int i;
2111 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2112 iface, start_slot, buffer_count, buffers);
2114 wined3d_mutex_lock();
2115 for (i = 0; i < buffer_count; ++i)
2117 struct wined3d_buffer *wined3d_buffer;
2118 struct d3d_buffer *buffer_impl;
2120 if (!(wined3d_buffer = wined3d_device_get_hs_cb(device->wined3d_device, start_slot + i)))
2122 buffers[i] = NULL;
2123 continue;
2126 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2127 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2129 wined3d_mutex_unlock();
2132 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
2133 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2135 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2136 unsigned int i;
2138 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2139 iface, start_slot, view_count, views);
2141 wined3d_mutex_lock();
2142 for (i = 0; i < view_count; ++i)
2144 struct wined3d_shader_resource_view *wined3d_view;
2145 struct d3d_shader_resource_view *view_impl;
2147 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2149 views[i] = NULL;
2150 continue;
2153 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2154 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2156 wined3d_mutex_unlock();
2159 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
2160 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2162 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2163 struct d3d11_domain_shader *shader_impl;
2164 struct wined3d_shader *wined3d_shader;
2166 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2167 iface, shader, class_instances, class_instance_count);
2169 if (class_instances || class_instance_count)
2170 FIXME("Dynamic linking not implemented yet.\n");
2172 wined3d_mutex_lock();
2173 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2175 wined3d_mutex_unlock();
2176 *shader = NULL;
2177 return;
2180 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2181 wined3d_mutex_unlock();
2182 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2185 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
2186 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2188 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2189 unsigned int i;
2191 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2192 iface, start_slot, sampler_count, samplers);
2194 wined3d_mutex_lock();
2195 for (i = 0; i < sampler_count; ++i)
2197 struct wined3d_sampler *wined3d_sampler;
2198 struct d3d_sampler_state *sampler_impl;
2200 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2202 samplers[i] = NULL;
2203 continue;
2206 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2207 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2209 wined3d_mutex_unlock();
2212 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
2213 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2215 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2216 unsigned int i;
2218 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2219 iface, start_slot, buffer_count, buffers);
2221 wined3d_mutex_lock();
2222 for (i = 0; i < buffer_count; ++i)
2224 struct wined3d_buffer *wined3d_buffer;
2225 struct d3d_buffer *buffer_impl;
2227 if (!(wined3d_buffer = wined3d_device_get_ds_cb(device->wined3d_device, start_slot + i)))
2229 buffers[i] = NULL;
2230 continue;
2233 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2234 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2236 wined3d_mutex_unlock();
2239 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
2240 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2242 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2243 unsigned int i;
2245 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2247 wined3d_mutex_lock();
2248 for (i = 0; i < view_count; ++i)
2250 struct wined3d_shader_resource_view *wined3d_view;
2251 struct d3d_shader_resource_view *view_impl;
2253 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2255 views[i] = NULL;
2256 continue;
2259 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2260 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2262 wined3d_mutex_unlock();
2265 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
2266 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2268 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2269 unsigned int i;
2271 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2273 wined3d_mutex_lock();
2274 for (i = 0; i < view_count; ++i)
2276 struct wined3d_unordered_access_view *wined3d_view;
2277 struct d3d11_unordered_access_view *view_impl;
2279 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2281 views[i] = NULL;
2282 continue;
2285 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2286 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2288 wined3d_mutex_unlock();
2291 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
2292 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2294 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2295 struct d3d11_compute_shader *shader_impl;
2296 struct wined3d_shader *wined3d_shader;
2298 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2299 iface, shader, class_instances, class_instance_count);
2301 if (class_instances || class_instance_count)
2302 FIXME("Dynamic linking not implemented yet.\n");
2304 wined3d_mutex_lock();
2305 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2307 wined3d_mutex_unlock();
2308 *shader = NULL;
2309 return;
2312 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2313 wined3d_mutex_unlock();
2314 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2317 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
2318 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2320 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2321 unsigned int i;
2323 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2324 iface, start_slot, sampler_count, samplers);
2326 wined3d_mutex_lock();
2327 for (i = 0; i < sampler_count; ++i)
2329 struct wined3d_sampler *wined3d_sampler;
2330 struct d3d_sampler_state *sampler_impl;
2332 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2334 samplers[i] = NULL;
2335 continue;
2338 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2339 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2341 wined3d_mutex_unlock();
2344 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
2345 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2347 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2348 unsigned int i;
2350 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2351 iface, start_slot, buffer_count, buffers);
2353 wined3d_mutex_lock();
2354 for (i = 0; i < buffer_count; ++i)
2356 struct wined3d_buffer *wined3d_buffer;
2357 struct d3d_buffer *buffer_impl;
2359 if (!(wined3d_buffer = wined3d_device_get_cs_cb(device->wined3d_device, start_slot + i)))
2361 buffers[i] = NULL;
2362 continue;
2365 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2366 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2368 wined3d_mutex_unlock();
2371 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
2373 FIXME("iface %p stub!\n", iface);
2376 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
2378 FIXME("iface %p stub!\n", iface);
2381 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
2383 TRACE("iface %p.\n", iface);
2385 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2388 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
2390 FIXME("iface %p stub!\n", iface);
2392 return 0;
2395 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
2396 BOOL restore, ID3D11CommandList **command_list)
2398 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
2400 return E_NOTIMPL;
2403 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
2405 /* IUnknown methods */
2406 d3d11_immediate_context_QueryInterface,
2407 d3d11_immediate_context_AddRef,
2408 d3d11_immediate_context_Release,
2409 /* ID3D11DeviceChild methods */
2410 d3d11_immediate_context_GetDevice,
2411 d3d11_immediate_context_GetPrivateData,
2412 d3d11_immediate_context_SetPrivateData,
2413 d3d11_immediate_context_SetPrivateDataInterface,
2414 /* ID3D11DeviceContext methods */
2415 d3d11_immediate_context_VSSetConstantBuffers,
2416 d3d11_immediate_context_PSSetShaderResources,
2417 d3d11_immediate_context_PSSetShader,
2418 d3d11_immediate_context_PSSetSamplers,
2419 d3d11_immediate_context_VSSetShader,
2420 d3d11_immediate_context_DrawIndexed,
2421 d3d11_immediate_context_Draw,
2422 d3d11_immediate_context_Map,
2423 d3d11_immediate_context_Unmap,
2424 d3d11_immediate_context_PSSetConstantBuffers,
2425 d3d11_immediate_context_IASetInputLayout,
2426 d3d11_immediate_context_IASetVertexBuffers,
2427 d3d11_immediate_context_IASetIndexBuffer,
2428 d3d11_immediate_context_DrawIndexedInstanced,
2429 d3d11_immediate_context_DrawInstanced,
2430 d3d11_immediate_context_GSSetConstantBuffers,
2431 d3d11_immediate_context_GSSetShader,
2432 d3d11_immediate_context_IASetPrimitiveTopology,
2433 d3d11_immediate_context_VSSetShaderResources,
2434 d3d11_immediate_context_VSSetSamplers,
2435 d3d11_immediate_context_Begin,
2436 d3d11_immediate_context_End,
2437 d3d11_immediate_context_GetData,
2438 d3d11_immediate_context_SetPredication,
2439 d3d11_immediate_context_GSSetShaderResources,
2440 d3d11_immediate_context_GSSetSamplers,
2441 d3d11_immediate_context_OMSetRenderTargets,
2442 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2443 d3d11_immediate_context_OMSetBlendState,
2444 d3d11_immediate_context_OMSetDepthStencilState,
2445 d3d11_immediate_context_SOSetTargets,
2446 d3d11_immediate_context_DrawAuto,
2447 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2448 d3d11_immediate_context_DrawInstancedIndirect,
2449 d3d11_immediate_context_Dispatch,
2450 d3d11_immediate_context_DispatchIndirect,
2451 d3d11_immediate_context_RSSetState,
2452 d3d11_immediate_context_RSSetViewports,
2453 d3d11_immediate_context_RSSetScissorRects,
2454 d3d11_immediate_context_CopySubresourceRegion,
2455 d3d11_immediate_context_CopyResource,
2456 d3d11_immediate_context_UpdateSubresource,
2457 d3d11_immediate_context_CopyStructureCount,
2458 d3d11_immediate_context_ClearRenderTargetView,
2459 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2460 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2461 d3d11_immediate_context_ClearDepthStencilView,
2462 d3d11_immediate_context_GenerateMips,
2463 d3d11_immediate_context_SetResourceMinLOD,
2464 d3d11_immediate_context_GetResourceMinLOD,
2465 d3d11_immediate_context_ResolveSubresource,
2466 d3d11_immediate_context_ExecuteCommandList,
2467 d3d11_immediate_context_HSSetShaderResources,
2468 d3d11_immediate_context_HSSetShader,
2469 d3d11_immediate_context_HSSetSamplers,
2470 d3d11_immediate_context_HSSetConstantBuffers,
2471 d3d11_immediate_context_DSSetShaderResources,
2472 d3d11_immediate_context_DSSetShader,
2473 d3d11_immediate_context_DSSetSamplers,
2474 d3d11_immediate_context_DSSetConstantBuffers,
2475 d3d11_immediate_context_CSSetShaderResources,
2476 d3d11_immediate_context_CSSetUnorderedAccessViews,
2477 d3d11_immediate_context_CSSetShader,
2478 d3d11_immediate_context_CSSetSamplers,
2479 d3d11_immediate_context_CSSetConstantBuffers,
2480 d3d11_immediate_context_VSGetConstantBuffers,
2481 d3d11_immediate_context_PSGetShaderResources,
2482 d3d11_immediate_context_PSGetShader,
2483 d3d11_immediate_context_PSGetSamplers,
2484 d3d11_immediate_context_VSGetShader,
2485 d3d11_immediate_context_PSGetConstantBuffers,
2486 d3d11_immediate_context_IAGetInputLayout,
2487 d3d11_immediate_context_IAGetVertexBuffers,
2488 d3d11_immediate_context_IAGetIndexBuffer,
2489 d3d11_immediate_context_GSGetConstantBuffers,
2490 d3d11_immediate_context_GSGetShader,
2491 d3d11_immediate_context_IAGetPrimitiveTopology,
2492 d3d11_immediate_context_VSGetShaderResources,
2493 d3d11_immediate_context_VSGetSamplers,
2494 d3d11_immediate_context_GetPredication,
2495 d3d11_immediate_context_GSGetShaderResources,
2496 d3d11_immediate_context_GSGetSamplers,
2497 d3d11_immediate_context_OMGetRenderTargets,
2498 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2499 d3d11_immediate_context_OMGetBlendState,
2500 d3d11_immediate_context_OMGetDepthStencilState,
2501 d3d11_immediate_context_SOGetTargets,
2502 d3d11_immediate_context_RSGetState,
2503 d3d11_immediate_context_RSGetViewports,
2504 d3d11_immediate_context_RSGetScissorRects,
2505 d3d11_immediate_context_HSGetShaderResources,
2506 d3d11_immediate_context_HSGetShader,
2507 d3d11_immediate_context_HSGetSamplers,
2508 d3d11_immediate_context_HSGetConstantBuffers,
2509 d3d11_immediate_context_DSGetShaderResources,
2510 d3d11_immediate_context_DSGetShader,
2511 d3d11_immediate_context_DSGetSamplers,
2512 d3d11_immediate_context_DSGetConstantBuffers,
2513 d3d11_immediate_context_CSGetShaderResources,
2514 d3d11_immediate_context_CSGetUnorderedAccessViews,
2515 d3d11_immediate_context_CSGetShader,
2516 d3d11_immediate_context_CSGetSamplers,
2517 d3d11_immediate_context_CSGetConstantBuffers,
2518 d3d11_immediate_context_ClearState,
2519 d3d11_immediate_context_Flush,
2520 d3d11_immediate_context_GetType,
2521 d3d11_immediate_context_GetContextFlags,
2522 d3d11_immediate_context_FinishCommandList,
2525 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2527 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2528 context->refcount = 1;
2530 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2532 wined3d_private_store_init(&context->private_store);
2535 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2537 wined3d_private_store_cleanup(&context->private_store);
2540 /* ID3D11Device methods */
2542 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2544 struct d3d_device *device = impl_from_ID3D11Device(iface);
2545 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2548 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2550 struct d3d_device *device = impl_from_ID3D11Device(iface);
2551 return IUnknown_AddRef(device->outer_unk);
2554 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2556 struct d3d_device *device = impl_from_ID3D11Device(iface);
2557 return IUnknown_Release(device->outer_unk);
2560 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2561 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2563 struct d3d_device *device = impl_from_ID3D11Device(iface);
2564 struct d3d_buffer *object;
2565 HRESULT hr;
2567 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2569 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2570 return hr;
2572 *buffer = &object->ID3D11Buffer_iface;
2574 return S_OK;
2577 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2578 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2580 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2582 return E_NOTIMPL;
2585 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2586 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2588 struct d3d_device *device = impl_from_ID3D11Device(iface);
2589 struct d3d_texture2d *object;
2590 HRESULT hr;
2592 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2594 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2595 return hr;
2597 *texture = &object->ID3D11Texture2D_iface;
2599 return S_OK;
2602 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2603 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2605 struct d3d_device *device = impl_from_ID3D11Device(iface);
2606 struct d3d_texture3d *object;
2607 HRESULT hr;
2609 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2611 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2612 return hr;
2614 *texture = &object->ID3D11Texture3D_iface;
2616 return S_OK;
2619 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2620 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2622 struct d3d_device *device = impl_from_ID3D11Device(iface);
2623 struct d3d_shader_resource_view *object;
2624 HRESULT hr;
2626 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2628 if (!resource)
2629 return E_INVALIDARG;
2631 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2632 return hr;
2634 *view = &object->ID3D11ShaderResourceView_iface;
2636 return S_OK;
2639 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2640 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2642 struct d3d_device *device = impl_from_ID3D11Device(iface);
2643 struct d3d11_unordered_access_view *object;
2644 HRESULT hr;
2646 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2648 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2649 return hr;
2651 *view = &object->ID3D11UnorderedAccessView_iface;
2653 return S_OK;
2656 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2657 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2659 struct d3d_device *device = impl_from_ID3D11Device(iface);
2660 struct d3d_rendertarget_view *object;
2661 HRESULT hr;
2663 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2665 if (!resource)
2666 return E_INVALIDARG;
2668 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2669 return hr;
2671 *view = &object->ID3D11RenderTargetView_iface;
2673 return S_OK;
2676 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2677 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2679 struct d3d_device *device = impl_from_ID3D11Device(iface);
2680 struct d3d_depthstencil_view *object;
2681 HRESULT hr;
2683 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2685 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2686 return hr;
2688 *view = &object->ID3D11DepthStencilView_iface;
2690 return S_OK;
2693 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2694 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2695 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2697 struct d3d_device *device = impl_from_ID3D11Device(iface);
2698 struct d3d_input_layout *object;
2699 HRESULT hr;
2701 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2702 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2703 shader_byte_code_length, input_layout);
2705 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2706 shader_byte_code, shader_byte_code_length, &object)))
2707 return hr;
2709 *input_layout = &object->ID3D11InputLayout_iface;
2711 return S_OK;
2714 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2715 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2717 struct d3d_device *device = impl_from_ID3D11Device(iface);
2718 struct d3d_vertex_shader *object;
2719 HRESULT hr;
2721 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2722 iface, byte_code, byte_code_length, class_linkage, shader);
2724 if (class_linkage)
2725 FIXME("Class linkage is not implemented yet.\n");
2727 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2728 return hr;
2730 *shader = &object->ID3D11VertexShader_iface;
2732 return S_OK;
2735 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2736 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2738 struct d3d_device *device = impl_from_ID3D11Device(iface);
2739 struct d3d_geometry_shader *object;
2740 HRESULT hr;
2742 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2743 iface, byte_code, byte_code_length, class_linkage, shader);
2745 if (class_linkage)
2746 FIXME("Class linkage is not implemented yet.\n");
2748 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2749 NULL, 0, NULL, 0, 0, &object)))
2750 return hr;
2752 *shader = &object->ID3D11GeometryShader_iface;
2754 return S_OK;
2757 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2758 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2759 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
2760 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2762 struct d3d_device *device = impl_from_ID3D11Device(iface);
2763 struct d3d_geometry_shader *object;
2764 HRESULT hr;
2766 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2767 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
2768 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2769 rasterizer_stream, class_linkage, shader);
2771 if (class_linkage)
2772 FIXME("Class linkage is not implemented yet.\n");
2774 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2775 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
2777 *shader = NULL;
2778 return hr;
2781 *shader = &object->ID3D11GeometryShader_iface;
2783 return hr;
2786 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2787 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2789 struct d3d_device *device = impl_from_ID3D11Device(iface);
2790 struct d3d_pixel_shader *object;
2791 HRESULT hr;
2793 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2794 iface, byte_code, byte_code_length, class_linkage, shader);
2796 if (class_linkage)
2797 FIXME("Class linkage is not implemented yet.\n");
2799 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2800 return hr;
2802 *shader = &object->ID3D11PixelShader_iface;
2804 return S_OK;
2807 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2808 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2810 struct d3d_device *device = impl_from_ID3D11Device(iface);
2811 struct d3d11_hull_shader *object;
2812 HRESULT hr;
2814 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2815 iface, byte_code, byte_code_length, class_linkage, shader);
2817 if (class_linkage)
2818 FIXME("Class linkage is not implemented yet.\n");
2820 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2821 return hr;
2823 *shader = &object->ID3D11HullShader_iface;
2825 return S_OK;
2828 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2829 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2831 struct d3d_device *device = impl_from_ID3D11Device(iface);
2832 struct d3d11_domain_shader *object;
2833 HRESULT hr;
2835 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2836 iface, byte_code, byte_code_length, class_linkage, shader);
2838 if (class_linkage)
2839 FIXME("Class linkage is not implemented yet.\n");
2841 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2842 return hr;
2844 *shader = &object->ID3D11DomainShader_iface;
2846 return S_OK;
2849 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2850 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2852 struct d3d_device *device = impl_from_ID3D11Device(iface);
2853 struct d3d11_compute_shader *object;
2854 HRESULT hr;
2856 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2857 iface, byte_code, byte_code_length, class_linkage, shader);
2859 if (class_linkage)
2860 FIXME("Class linkage is not implemented yet.\n");
2862 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
2863 return hr;
2865 *shader = &object->ID3D11ComputeShader_iface;
2867 return S_OK;
2870 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2871 ID3D11ClassLinkage **class_linkage)
2873 struct d3d_device *device = impl_from_ID3D11Device(iface);
2874 struct d3d11_class_linkage *object;
2875 HRESULT hr;
2877 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
2879 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
2880 return hr;
2882 *class_linkage = &object->ID3D11ClassLinkage_iface;
2884 return S_OK;
2887 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
2888 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
2890 struct d3d_device *device = impl_from_ID3D11Device(iface);
2891 struct d3d_blend_state *object;
2892 struct wine_rb_entry *entry;
2893 D3D11_BLEND_DESC tmp_desc;
2894 unsigned int i, j;
2895 HRESULT hr;
2897 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2899 if (!desc)
2900 return E_INVALIDARG;
2902 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
2903 * D3D11_BLEND_DESC as a key in the rbtree. */
2904 memset(&tmp_desc, 0, sizeof(tmp_desc));
2905 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
2906 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
2907 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2909 j = desc->IndependentBlendEnable ? i : 0;
2910 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
2911 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
2912 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
2913 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
2914 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
2915 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
2916 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
2917 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
2919 if (i > 3 && tmp_desc.RenderTarget[i].RenderTargetWriteMask != D3D11_COLOR_WRITE_ENABLE_ALL)
2920 FIXME("Color mask %#x not supported for render target %u.\n",
2921 tmp_desc.RenderTarget[i].RenderTargetWriteMask, i);
2924 /* glSampleCoverage() */
2925 if (tmp_desc.AlphaToCoverageEnable)
2926 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", tmp_desc.AlphaToCoverageEnable);
2927 /* glEnableIndexedEXT(GL_BLEND, ...) */
2928 if (tmp_desc.IndependentBlendEnable)
2929 FIXME("Per-rendertarget blend not implemented.\n");
2931 wined3d_mutex_lock();
2932 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
2934 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
2936 TRACE("Returning existing blend state %p.\n", object);
2937 *blend_state = &object->ID3D11BlendState_iface;
2938 ID3D11BlendState_AddRef(*blend_state);
2939 wined3d_mutex_unlock();
2941 return S_OK;
2943 wined3d_mutex_unlock();
2945 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2946 return E_OUTOFMEMORY;
2948 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
2950 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2951 HeapFree(GetProcessHeap(), 0, object);
2952 return hr;
2955 TRACE("Created blend state %p.\n", object);
2956 *blend_state = &object->ID3D11BlendState_iface;
2958 return S_OK;
2961 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
2962 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
2964 struct d3d_device *device = impl_from_ID3D11Device(iface);
2965 struct d3d_depthstencil_state *object;
2966 D3D11_DEPTH_STENCIL_DESC tmp_desc;
2967 struct wine_rb_entry *entry;
2968 HRESULT hr;
2970 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2972 if (!desc)
2973 return E_INVALIDARG;
2975 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2976 * it as a key in the rbtree. */
2977 memset(&tmp_desc, 0, sizeof(tmp_desc));
2978 tmp_desc.DepthEnable = desc->DepthEnable;
2979 if (desc->DepthEnable)
2981 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2982 tmp_desc.DepthFunc = desc->DepthFunc;
2984 else
2986 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2987 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
2989 tmp_desc.StencilEnable = desc->StencilEnable;
2990 if (desc->StencilEnable)
2992 tmp_desc.StencilReadMask = desc->StencilReadMask;
2993 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2994 tmp_desc.FrontFace = desc->FrontFace;
2995 tmp_desc.BackFace = desc->BackFace;
2997 else
2999 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
3000 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
3001 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3002 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3003 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3004 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3005 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3006 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3007 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3008 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3011 wined3d_mutex_lock();
3012 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
3014 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
3016 TRACE("Returning existing depthstencil state %p.\n", object);
3017 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3018 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
3019 wined3d_mutex_unlock();
3021 return S_OK;
3023 wined3d_mutex_unlock();
3025 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3026 return E_OUTOFMEMORY;
3028 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
3030 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
3031 HeapFree(GetProcessHeap(), 0, object);
3032 return hr;
3035 TRACE("Created depthstencil state %p.\n", object);
3036 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3038 return S_OK;
3041 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
3042 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3044 struct d3d_device *device = impl_from_ID3D11Device(iface);
3045 struct d3d_rasterizer_state *object;
3046 struct wine_rb_entry *entry;
3047 HRESULT hr;
3049 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3051 if (!desc)
3052 return E_INVALIDARG;
3054 wined3d_mutex_lock();
3055 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
3057 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
3059 TRACE("Returning existing rasterizer state %p.\n", object);
3060 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3061 ID3D11RasterizerState_AddRef(*rasterizer_state);
3062 wined3d_mutex_unlock();
3064 return S_OK;
3066 wined3d_mutex_unlock();
3068 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3069 return E_OUTOFMEMORY;
3071 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
3073 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
3074 HeapFree(GetProcessHeap(), 0, object);
3075 return hr;
3078 TRACE("Created rasterizer state %p.\n", object);
3079 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3081 return S_OK;
3084 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
3085 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3087 struct d3d_device *device = impl_from_ID3D11Device(iface);
3088 D3D11_SAMPLER_DESC normalized_desc;
3089 struct d3d_sampler_state *object;
3090 struct wine_rb_entry *entry;
3091 HRESULT hr;
3093 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3095 if (!desc)
3096 return E_INVALIDARG;
3098 normalized_desc = *desc;
3099 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
3100 normalized_desc.MaxAnisotropy = 0;
3101 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
3102 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3103 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
3104 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
3105 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
3106 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
3108 wined3d_mutex_lock();
3109 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
3111 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
3113 TRACE("Returning existing sampler state %p.\n", object);
3114 *sampler_state = &object->ID3D11SamplerState_iface;
3115 ID3D11SamplerState_AddRef(*sampler_state);
3116 wined3d_mutex_unlock();
3118 return S_OK;
3120 wined3d_mutex_unlock();
3122 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3123 return E_OUTOFMEMORY;
3125 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
3127 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
3128 HeapFree(GetProcessHeap(), 0, object);
3129 return hr;
3132 TRACE("Created sampler state %p.\n", object);
3133 *sampler_state = &object->ID3D11SamplerState_iface;
3135 return S_OK;
3138 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
3139 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3141 struct d3d_device *device = impl_from_ID3D11Device(iface);
3142 struct d3d_query *object;
3143 HRESULT hr;
3145 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3147 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3148 return hr;
3150 if (query)
3152 *query = &object->ID3D11Query_iface;
3153 return S_OK;
3156 ID3D11Query_Release(&object->ID3D11Query_iface);
3157 return S_FALSE;
3160 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
3161 ID3D11Predicate **predicate)
3163 struct d3d_device *device = impl_from_ID3D11Device(iface);
3164 struct d3d_query *object;
3165 HRESULT hr;
3167 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3169 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3170 return hr;
3172 if (predicate)
3174 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3175 return S_OK;
3178 ID3D11Query_Release(&object->ID3D11Query_iface);
3179 return S_FALSE;
3182 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3183 ID3D11Counter **counter)
3185 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3187 return E_NOTIMPL;
3190 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
3191 ID3D11DeviceContext **context)
3193 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3195 return E_NOTIMPL;
3198 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
3199 void **out)
3201 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
3203 return E_NOTIMPL;
3206 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
3207 UINT *format_support)
3209 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
3211 return E_NOTIMPL;
3214 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
3215 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3217 struct d3d_device *device = impl_from_ID3D11Device(iface);
3218 struct wined3d_device_creation_parameters params;
3219 struct wined3d *wined3d;
3220 HRESULT hr;
3222 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3223 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3225 if (!quality_level_count)
3226 return E_INVALIDARG;
3228 *quality_level_count = 0;
3230 if (!sample_count)
3231 return E_FAIL;
3232 if (sample_count == 1)
3234 *quality_level_count = 1;
3235 return S_OK;
3237 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3238 return E_FAIL;
3240 wined3d_mutex_lock();
3241 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3242 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3243 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
3244 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3245 wined3d_mutex_unlock();
3247 if (hr == WINED3DERR_INVALIDCALL)
3248 return E_INVALIDARG;
3249 if (hr == WINED3DERR_NOTAVAILABLE)
3250 return S_OK;
3251 return hr;
3254 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
3256 FIXME("iface %p, info %p stub!\n", iface, info);
3259 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3260 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3261 char *units, UINT *units_length, char *description, UINT *description_length)
3263 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3264 "units %p, units_length %p, description %p, description_length %p stub!\n",
3265 iface, desc, type, active_counter_count, name, name_length,
3266 units, units_length, description, description_length);
3268 return E_NOTIMPL;
3271 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
3272 void *feature_support_data, UINT feature_support_data_size)
3274 struct d3d_device *device = impl_from_ID3D11Device(iface);
3275 WINED3DCAPS wined3d_caps;
3276 HRESULT hr;
3278 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3279 iface, feature, feature_support_data, feature_support_data_size);
3281 switch (feature)
3283 case D3D11_FEATURE_THREADING:
3285 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3286 if (feature_support_data_size != sizeof(*threading_data))
3288 WARN("Invalid data size.\n");
3289 return E_INVALIDARG;
3292 /* We lie about the threading support to make Tomb Raider 2013 and
3293 * Deus Ex: Human Revolution happy. */
3294 FIXME("Returning fake threading support data.\n");
3295 threading_data->DriverConcurrentCreates = TRUE;
3296 threading_data->DriverCommandLists = TRUE;
3297 return S_OK;
3300 case D3D11_FEATURE_DOUBLES:
3302 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3303 if (feature_support_data_size != sizeof(*doubles_data))
3305 WARN("Invalid data size.\n");
3306 return E_INVALIDARG;
3309 wined3d_mutex_lock();
3310 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3311 wined3d_mutex_unlock();
3312 if (FAILED(hr))
3314 WARN("Failed to get device caps, hr %#x.\n", hr);
3315 return hr;
3318 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3319 return S_OK;
3322 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3324 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3325 if (feature_support_data_size != sizeof(*options))
3327 WARN("Invalid data size.\n");
3328 return E_INVALIDARG;
3331 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
3332 return S_OK;
3335 default:
3336 FIXME("Unhandled feature %#x.\n", feature);
3337 return E_NOTIMPL;
3341 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
3342 UINT *data_size, void *data)
3344 IDXGIDevice *dxgi_device;
3345 HRESULT hr;
3347 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3349 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3350 return hr;
3351 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3352 IDXGIDevice_Release(dxgi_device);
3354 return hr;
3357 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
3358 UINT data_size, const void *data)
3360 IDXGIDevice *dxgi_device;
3361 HRESULT hr;
3363 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3365 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3366 return hr;
3367 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3368 IDXGIDevice_Release(dxgi_device);
3370 return hr;
3373 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
3374 const IUnknown *data)
3376 IDXGIDevice *dxgi_device;
3377 HRESULT hr;
3379 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3381 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3382 return hr;
3383 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3384 IDXGIDevice_Release(dxgi_device);
3386 return hr;
3389 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
3391 struct d3d_device *device = impl_from_ID3D11Device(iface);
3393 TRACE("iface %p.\n", iface);
3395 return device->feature_level;
3398 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
3400 FIXME("iface %p stub!\n", iface);
3402 return 0;
3405 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
3407 FIXME("iface %p stub!\n", iface);
3409 return S_OK;
3412 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
3413 ID3D11DeviceContext **immediate_context)
3415 struct d3d_device *device = impl_from_ID3D11Device(iface);
3417 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
3419 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
3420 ID3D11DeviceContext_AddRef(*immediate_context);
3423 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
3425 FIXME("iface %p, flags %#x stub!\n", iface, flags);
3427 return E_NOTIMPL;
3430 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
3432 FIXME("iface %p stub!\n", iface);
3434 return 0;
3437 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
3439 /* IUnknown methods */
3440 d3d11_device_QueryInterface,
3441 d3d11_device_AddRef,
3442 d3d11_device_Release,
3443 /* ID3D11Device methods */
3444 d3d11_device_CreateBuffer,
3445 d3d11_device_CreateTexture1D,
3446 d3d11_device_CreateTexture2D,
3447 d3d11_device_CreateTexture3D,
3448 d3d11_device_CreateShaderResourceView,
3449 d3d11_device_CreateUnorderedAccessView,
3450 d3d11_device_CreateRenderTargetView,
3451 d3d11_device_CreateDepthStencilView,
3452 d3d11_device_CreateInputLayout,
3453 d3d11_device_CreateVertexShader,
3454 d3d11_device_CreateGeometryShader,
3455 d3d11_device_CreateGeometryShaderWithStreamOutput,
3456 d3d11_device_CreatePixelShader,
3457 d3d11_device_CreateHullShader,
3458 d3d11_device_CreateDomainShader,
3459 d3d11_device_CreateComputeShader,
3460 d3d11_device_CreateClassLinkage,
3461 d3d11_device_CreateBlendState,
3462 d3d11_device_CreateDepthStencilState,
3463 d3d11_device_CreateRasterizerState,
3464 d3d11_device_CreateSamplerState,
3465 d3d11_device_CreateQuery,
3466 d3d11_device_CreatePredicate,
3467 d3d11_device_CreateCounter,
3468 d3d11_device_CreateDeferredContext,
3469 d3d11_device_OpenSharedResource,
3470 d3d11_device_CheckFormatSupport,
3471 d3d11_device_CheckMultisampleQualityLevels,
3472 d3d11_device_CheckCounterInfo,
3473 d3d11_device_CheckCounter,
3474 d3d11_device_CheckFeatureSupport,
3475 d3d11_device_GetPrivateData,
3476 d3d11_device_SetPrivateData,
3477 d3d11_device_SetPrivateDataInterface,
3478 d3d11_device_GetFeatureLevel,
3479 d3d11_device_GetCreationFlags,
3480 d3d11_device_GetDeviceRemovedReason,
3481 d3d11_device_GetImmediateContext,
3482 d3d11_device_SetExceptionMode,
3483 d3d11_device_GetExceptionMode,
3486 /* Inner IUnknown methods */
3488 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
3490 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
3493 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3495 struct d3d_device *device = impl_from_IUnknown(iface);
3497 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
3499 if (IsEqualGUID(riid, &IID_ID3D11Device)
3500 || IsEqualGUID(riid, &IID_IUnknown))
3502 *out = &device->ID3D11Device_iface;
3504 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
3505 || IsEqualGUID(riid, &IID_ID3D10Device))
3507 *out = &device->ID3D10Device1_iface;
3509 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
3511 *out = &device->ID3D10Multithread_iface;
3513 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
3515 *out = &device->IWineDXGIDeviceParent_iface;
3517 else
3519 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
3520 *out = NULL;
3521 return E_NOINTERFACE;
3524 IUnknown_AddRef((IUnknown *)*out);
3525 return S_OK;
3528 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
3530 struct d3d_device *device = impl_from_IUnknown(iface);
3531 ULONG refcount = InterlockedIncrement(&device->refcount);
3533 TRACE("%p increasing refcount to %u.\n", device, refcount);
3535 return refcount;
3538 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
3540 struct d3d_device *device = impl_from_IUnknown(iface);
3541 ULONG refcount = InterlockedDecrement(&device->refcount);
3543 TRACE("%p decreasing refcount to %u.\n", device, refcount);
3545 if (!refcount)
3547 d3d11_immediate_context_destroy(&device->immediate_context);
3548 if (device->wined3d_device)
3550 wined3d_mutex_lock();
3551 wined3d_device_decref(device->wined3d_device);
3552 wined3d_mutex_unlock();
3554 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3555 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3556 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3557 wine_rb_destroy(&device->blend_states, NULL, NULL);
3560 return refcount;
3563 /* IUnknown methods */
3565 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3566 void **ppv)
3568 struct d3d_device *device = impl_from_ID3D10Device(iface);
3569 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3572 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3574 struct d3d_device *device = impl_from_ID3D10Device(iface);
3575 return IUnknown_AddRef(device->outer_unk);
3578 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3580 struct d3d_device *device = impl_from_ID3D10Device(iface);
3581 return IUnknown_Release(device->outer_unk);
3584 /* ID3D10Device methods */
3586 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3587 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3589 struct d3d_device *device = impl_from_ID3D10Device(iface);
3590 unsigned int i;
3592 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3593 iface, start_slot, buffer_count, buffers);
3595 wined3d_mutex_lock();
3596 for (i = 0; i < buffer_count; ++i)
3598 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3600 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3601 buffer ? buffer->wined3d_buffer : NULL);
3603 wined3d_mutex_unlock();
3606 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3607 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3609 struct d3d_device *device = impl_from_ID3D10Device(iface);
3610 unsigned int i;
3612 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3613 iface, start_slot, view_count, views);
3615 wined3d_mutex_lock();
3616 for (i = 0; i < view_count; ++i)
3618 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3620 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3621 view ? view->wined3d_view : NULL);
3623 wined3d_mutex_unlock();
3626 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3627 ID3D10PixelShader *shader)
3629 struct d3d_device *device = impl_from_ID3D10Device(iface);
3630 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3632 TRACE("iface %p, shader %p\n", iface, shader);
3634 wined3d_mutex_lock();
3635 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3636 wined3d_mutex_unlock();
3639 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3640 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3642 struct d3d_device *device = impl_from_ID3D10Device(iface);
3643 unsigned int i;
3645 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3646 iface, start_slot, sampler_count, samplers);
3648 wined3d_mutex_lock();
3649 for (i = 0; i < sampler_count; ++i)
3651 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3653 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3654 sampler ? sampler->wined3d_sampler : NULL);
3656 wined3d_mutex_unlock();
3659 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3660 ID3D10VertexShader *shader)
3662 struct d3d_device *device = impl_from_ID3D10Device(iface);
3663 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3665 TRACE("iface %p, shader %p\n", iface, shader);
3667 wined3d_mutex_lock();
3668 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3669 wined3d_mutex_unlock();
3672 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3673 UINT start_index_location, INT base_vertex_location)
3675 struct d3d_device *device = impl_from_ID3D10Device(iface);
3677 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3678 iface, index_count, start_index_location, base_vertex_location);
3680 wined3d_mutex_lock();
3681 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3682 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3683 wined3d_mutex_unlock();
3686 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3687 UINT start_vertex_location)
3689 struct d3d_device *device = impl_from_ID3D10Device(iface);
3691 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3692 iface, vertex_count, start_vertex_location);
3694 wined3d_mutex_lock();
3695 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3696 wined3d_mutex_unlock();
3699 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
3700 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3702 struct d3d_device *device = impl_from_ID3D10Device(iface);
3703 unsigned int i;
3705 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3706 iface, start_slot, buffer_count, buffers);
3708 wined3d_mutex_lock();
3709 for (i = 0; i < buffer_count; ++i)
3711 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3713 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
3714 buffer ? buffer->wined3d_buffer : NULL);
3716 wined3d_mutex_unlock();
3719 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3720 ID3D10InputLayout *input_layout)
3722 struct d3d_device *device = impl_from_ID3D10Device(iface);
3723 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3725 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3727 wined3d_mutex_lock();
3728 wined3d_device_set_vertex_declaration(device->wined3d_device,
3729 layout ? layout->wined3d_decl : NULL);
3730 wined3d_mutex_unlock();
3733 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3734 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3736 struct d3d_device *device = impl_from_ID3D10Device(iface);
3737 unsigned int i;
3739 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3740 iface, start_slot, buffer_count, buffers, strides, offsets);
3742 wined3d_mutex_lock();
3743 for (i = 0; i < buffer_count; ++i)
3745 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3747 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3748 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3750 wined3d_mutex_unlock();
3753 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3754 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3756 struct d3d_device *device = impl_from_ID3D10Device(iface);
3757 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3759 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3760 iface, buffer, debug_dxgi_format(format), offset);
3762 wined3d_mutex_lock();
3763 wined3d_device_set_index_buffer(device->wined3d_device,
3764 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3765 wined3dformat_from_dxgi_format(format), offset);
3766 wined3d_mutex_unlock();
3769 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3770 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3771 INT base_vertex_location, UINT start_instance_location)
3773 struct d3d_device *device = impl_from_ID3D10Device(iface);
3775 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3776 "base_vertex_location %d, start_instance_location %u.\n",
3777 iface, instance_index_count, instance_count, start_index_location,
3778 base_vertex_location, start_instance_location);
3780 wined3d_mutex_lock();
3781 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3782 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3783 instance_index_count, start_instance_location, instance_count);
3784 wined3d_mutex_unlock();
3787 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3788 UINT instance_vertex_count, UINT instance_count,
3789 UINT start_vertex_location, UINT start_instance_location)
3791 struct d3d_device *device = impl_from_ID3D10Device(iface);
3793 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3794 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3795 start_vertex_location, start_instance_location);
3797 wined3d_mutex_lock();
3798 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3799 instance_vertex_count, start_instance_location, instance_count);
3800 wined3d_mutex_unlock();
3803 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3804 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3806 struct d3d_device *device = impl_from_ID3D10Device(iface);
3807 unsigned int i;
3809 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3810 iface, start_slot, buffer_count, buffers);
3812 wined3d_mutex_lock();
3813 for (i = 0; i < buffer_count; ++i)
3815 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3817 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3818 buffer ? buffer->wined3d_buffer : NULL);
3820 wined3d_mutex_unlock();
3823 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3825 struct d3d_device *device = impl_from_ID3D10Device(iface);
3826 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3828 TRACE("iface %p, shader %p.\n", iface, shader);
3830 wined3d_mutex_lock();
3831 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3832 wined3d_mutex_unlock();
3835 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3836 D3D10_PRIMITIVE_TOPOLOGY topology)
3838 struct d3d_device *device = impl_from_ID3D10Device(iface);
3840 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
3842 wined3d_mutex_lock();
3843 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
3844 wined3d_mutex_unlock();
3847 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
3848 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3850 struct d3d_device *device = impl_from_ID3D10Device(iface);
3851 unsigned int i;
3853 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3854 iface, start_slot, view_count, views);
3856 wined3d_mutex_lock();
3857 for (i = 0; i < view_count; ++i)
3859 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3861 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
3862 view ? view->wined3d_view : NULL);
3864 wined3d_mutex_unlock();
3867 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
3868 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3870 struct d3d_device *device = impl_from_ID3D10Device(iface);
3871 unsigned int i;
3873 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3874 iface, start_slot, sampler_count, samplers);
3876 wined3d_mutex_lock();
3877 for (i = 0; i < sampler_count; ++i)
3879 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3881 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
3882 sampler ? sampler->wined3d_sampler : NULL);
3884 wined3d_mutex_unlock();
3887 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3889 struct d3d_device *device = impl_from_ID3D10Device(iface);
3890 struct d3d_query *query;
3892 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3894 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3895 wined3d_mutex_lock();
3896 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
3897 wined3d_mutex_unlock();
3900 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
3901 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3903 struct d3d_device *device = impl_from_ID3D10Device(iface);
3904 unsigned int i;
3906 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3907 iface, start_slot, view_count, views);
3909 wined3d_mutex_lock();
3910 for (i = 0; i < view_count; ++i)
3912 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3914 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
3915 view ? view->wined3d_view : NULL);
3917 wined3d_mutex_unlock();
3920 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
3921 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3923 struct d3d_device *device = impl_from_ID3D10Device(iface);
3924 unsigned int i;
3926 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3927 iface, start_slot, sampler_count, samplers);
3929 wined3d_mutex_lock();
3930 for (i = 0; i < sampler_count; ++i)
3932 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3934 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
3935 sampler ? sampler->wined3d_sampler : NULL);
3937 wined3d_mutex_unlock();
3940 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
3941 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
3942 ID3D10DepthStencilView *depth_stencil_view)
3944 struct d3d_device *device = impl_from_ID3D10Device(iface);
3945 struct d3d_depthstencil_view *dsv;
3946 unsigned int i;
3948 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3949 iface, render_target_view_count, render_target_views, depth_stencil_view);
3951 wined3d_mutex_lock();
3952 for (i = 0; i < render_target_view_count; ++i)
3954 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
3956 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
3957 rtv ? rtv->wined3d_view : NULL, FALSE);
3959 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3961 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
3964 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3965 wined3d_device_set_depth_stencil_view(device->wined3d_device,
3966 dsv ? dsv->wined3d_view : NULL);
3967 wined3d_mutex_unlock();
3970 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
3971 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
3973 struct d3d_device *device = impl_from_ID3D10Device(iface);
3974 struct d3d_blend_state *blend_state_object;
3976 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
3977 iface, blend_state, debug_float4(blend_factor), sample_mask);
3979 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
3980 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
3981 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
3984 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
3985 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
3987 struct d3d_device *device = impl_from_ID3D10Device(iface);
3988 struct d3d_depthstencil_state *ds_state_object;
3990 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
3991 iface, depth_stencil_state, stencil_ref);
3993 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
3994 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
3995 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
3998 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
3999 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4001 struct d3d_device *device = impl_from_ID3D10Device(iface);
4002 unsigned int count, i;
4004 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4006 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4007 wined3d_mutex_lock();
4008 for (i = 0; i < count; ++i)
4010 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4012 wined3d_device_set_stream_output(device->wined3d_device, i,
4013 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4016 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4018 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4020 wined3d_mutex_unlock();
4023 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4025 FIXME("iface %p stub!\n", iface);
4028 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4030 struct d3d_device *device = impl_from_ID3D10Device(iface);
4031 struct d3d_rasterizer_state *rasterizer_state_object;
4033 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4035 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4036 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
4037 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4040 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4041 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4043 struct d3d_device *device = impl_from_ID3D10Device(iface);
4044 struct wined3d_viewport wined3d_vp;
4046 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4048 if (viewport_count > 1)
4049 FIXME("Multiple viewports not implemented.\n");
4051 if (!viewport_count)
4052 return;
4054 wined3d_vp.x = viewports[0].TopLeftX;
4055 wined3d_vp.y = viewports[0].TopLeftY;
4056 wined3d_vp.width = viewports[0].Width;
4057 wined3d_vp.height = viewports[0].Height;
4058 wined3d_vp.min_z = viewports[0].MinDepth;
4059 wined3d_vp.max_z = viewports[0].MaxDepth;
4061 wined3d_mutex_lock();
4062 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
4063 wined3d_mutex_unlock();
4066 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4067 UINT rect_count, const D3D10_RECT *rects)
4069 struct d3d_device *device = impl_from_ID3D10Device(iface);
4071 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4073 if (rect_count > 1)
4074 FIXME("Multiple scissor rects not implemented.\n");
4076 if (!rect_count)
4077 return;
4079 wined3d_mutex_lock();
4080 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
4081 wined3d_mutex_unlock();
4084 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4085 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4086 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4088 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4089 struct d3d_device *device = impl_from_ID3D10Device(iface);
4090 struct wined3d_box wined3d_src_box;
4092 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4093 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4094 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4095 src_resource, src_subresource_idx, src_box);
4097 if (src_box)
4098 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4099 src_box->right, src_box->bottom, src_box->front, src_box->back);
4101 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4102 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4103 wined3d_mutex_lock();
4104 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
4105 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
4106 wined3d_mutex_unlock();
4109 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4110 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4112 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4113 struct d3d_device *device = impl_from_ID3D10Device(iface);
4115 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4117 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4118 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4119 wined3d_mutex_lock();
4120 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
4121 wined3d_mutex_unlock();
4124 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4125 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4126 const void *data, UINT row_pitch, UINT depth_pitch)
4128 struct d3d_device *device = impl_from_ID3D10Device(iface);
4129 ID3D11Resource *d3d11_resource;
4131 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4132 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4134 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4135 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
4136 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4137 ID3D11Resource_Release(d3d11_resource);
4140 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4141 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4143 struct d3d_device *device = impl_from_ID3D10Device(iface);
4144 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4145 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4146 HRESULT hr;
4148 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4149 iface, render_target_view, debug_float4(color_rgba));
4151 if (!view)
4152 return;
4154 wined3d_mutex_lock();
4155 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4156 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4157 ERR("Failed to clear view, hr %#x.\n", hr);
4158 wined3d_mutex_unlock();
4161 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4162 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4164 struct d3d_device *device = impl_from_ID3D10Device(iface);
4165 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4166 DWORD wined3d_flags;
4167 HRESULT hr;
4169 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4170 iface, depth_stencil_view, flags, depth, stencil);
4172 if (!view)
4173 return;
4175 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4177 wined3d_mutex_lock();
4178 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4179 wined3d_flags, NULL, depth, stencil)))
4180 ERR("Failed to clear view, hr %#x.\n", hr);
4181 wined3d_mutex_unlock();
4184 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4185 ID3D10ShaderResourceView *shader_resource_view)
4187 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
4190 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4191 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4192 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4194 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
4195 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
4196 iface, dst_resource, dst_subresource_idx,
4197 src_resource, src_subresource_idx, debug_dxgi_format(format));
4200 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
4201 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4203 struct d3d_device *device = impl_from_ID3D10Device(iface);
4204 unsigned int i;
4206 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4207 iface, start_slot, buffer_count, buffers);
4209 wined3d_mutex_lock();
4210 for (i = 0; i < buffer_count; ++i)
4212 struct wined3d_buffer *wined3d_buffer;
4213 struct d3d_buffer *buffer_impl;
4215 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
4217 buffers[i] = NULL;
4218 continue;
4221 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4222 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4223 ID3D10Buffer_AddRef(buffers[i]);
4225 wined3d_mutex_unlock();
4228 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
4229 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4231 struct d3d_device *device = impl_from_ID3D10Device(iface);
4232 unsigned int i;
4234 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4235 iface, start_slot, view_count, views);
4237 wined3d_mutex_lock();
4238 for (i = 0; i < view_count; ++i)
4240 struct wined3d_shader_resource_view *wined3d_view;
4241 struct d3d_shader_resource_view *view_impl;
4243 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
4245 views[i] = NULL;
4246 continue;
4249 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4250 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4251 ID3D10ShaderResourceView_AddRef(views[i]);
4253 wined3d_mutex_unlock();
4256 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
4258 struct d3d_device *device = impl_from_ID3D10Device(iface);
4259 struct d3d_pixel_shader *shader_impl;
4260 struct wined3d_shader *wined3d_shader;
4262 TRACE("iface %p, shader %p.\n", iface, shader);
4264 wined3d_mutex_lock();
4265 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
4267 wined3d_mutex_unlock();
4268 *shader = NULL;
4269 return;
4272 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4273 wined3d_mutex_unlock();
4274 *shader = &shader_impl->ID3D10PixelShader_iface;
4275 ID3D10PixelShader_AddRef(*shader);
4278 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
4279 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4281 struct d3d_device *device = impl_from_ID3D10Device(iface);
4282 unsigned int i;
4284 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4285 iface, start_slot, sampler_count, samplers);
4287 wined3d_mutex_lock();
4288 for (i = 0; i < sampler_count; ++i)
4290 struct d3d_sampler_state *sampler_impl;
4291 struct wined3d_sampler *wined3d_sampler;
4293 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
4295 samplers[i] = NULL;
4296 continue;
4299 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4300 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4301 ID3D10SamplerState_AddRef(samplers[i]);
4303 wined3d_mutex_unlock();
4306 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
4308 struct d3d_device *device = impl_from_ID3D10Device(iface);
4309 struct d3d_vertex_shader *shader_impl;
4310 struct wined3d_shader *wined3d_shader;
4312 TRACE("iface %p, shader %p.\n", iface, shader);
4314 wined3d_mutex_lock();
4315 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
4317 wined3d_mutex_unlock();
4318 *shader = NULL;
4319 return;
4322 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4323 wined3d_mutex_unlock();
4324 *shader = &shader_impl->ID3D10VertexShader_iface;
4325 ID3D10VertexShader_AddRef(*shader);
4328 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
4329 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4331 struct d3d_device *device = impl_from_ID3D10Device(iface);
4332 unsigned int i;
4334 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4335 iface, start_slot, buffer_count, buffers);
4337 wined3d_mutex_lock();
4338 for (i = 0; i < buffer_count; ++i)
4340 struct wined3d_buffer *wined3d_buffer;
4341 struct d3d_buffer *buffer_impl;
4343 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
4345 buffers[i] = NULL;
4346 continue;
4349 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4350 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4351 ID3D10Buffer_AddRef(buffers[i]);
4353 wined3d_mutex_unlock();
4356 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
4358 struct d3d_device *device = impl_from_ID3D10Device(iface);
4359 struct wined3d_vertex_declaration *wined3d_declaration;
4360 struct d3d_input_layout *input_layout_impl;
4362 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
4364 wined3d_mutex_lock();
4365 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
4367 wined3d_mutex_unlock();
4368 *input_layout = NULL;
4369 return;
4372 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
4373 wined3d_mutex_unlock();
4374 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
4375 ID3D10InputLayout_AddRef(*input_layout);
4378 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
4379 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
4381 struct d3d_device *device = impl_from_ID3D10Device(iface);
4382 unsigned int i;
4384 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
4385 iface, start_slot, buffer_count, buffers, strides, offsets);
4387 wined3d_mutex_lock();
4388 for (i = 0; i < buffer_count; ++i)
4390 struct wined3d_buffer *wined3d_buffer;
4391 struct d3d_buffer *buffer_impl;
4393 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
4394 &wined3d_buffer, &offsets[i], &strides[i])))
4395 ERR("Failed to get vertex buffer.\n");
4397 if (!wined3d_buffer)
4399 buffers[i] = NULL;
4400 continue;
4403 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4404 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4405 ID3D10Buffer_AddRef(buffers[i]);
4407 wined3d_mutex_unlock();
4410 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
4411 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
4413 struct d3d_device *device = impl_from_ID3D10Device(iface);
4414 enum wined3d_format_id wined3d_format;
4415 struct wined3d_buffer *wined3d_buffer;
4416 struct d3d_buffer *buffer_impl;
4418 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
4420 wined3d_mutex_lock();
4421 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
4422 *format = dxgi_format_from_wined3dformat(wined3d_format);
4423 if (!wined3d_buffer)
4425 wined3d_mutex_unlock();
4426 *buffer = NULL;
4427 return;
4430 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4431 wined3d_mutex_unlock();
4432 *buffer = &buffer_impl->ID3D10Buffer_iface;
4433 ID3D10Buffer_AddRef(*buffer);
4436 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
4437 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4439 struct d3d_device *device = impl_from_ID3D10Device(iface);
4440 unsigned int i;
4442 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4443 iface, start_slot, buffer_count, buffers);
4445 wined3d_mutex_lock();
4446 for (i = 0; i < buffer_count; ++i)
4448 struct wined3d_buffer *wined3d_buffer;
4449 struct d3d_buffer *buffer_impl;
4451 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
4453 buffers[i] = NULL;
4454 continue;
4457 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4458 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4459 ID3D10Buffer_AddRef(buffers[i]);
4461 wined3d_mutex_unlock();
4464 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
4466 struct d3d_device *device = impl_from_ID3D10Device(iface);
4467 struct d3d_geometry_shader *shader_impl;
4468 struct wined3d_shader *wined3d_shader;
4470 TRACE("iface %p, shader %p.\n", iface, shader);
4472 wined3d_mutex_lock();
4473 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
4475 wined3d_mutex_unlock();
4476 *shader = NULL;
4477 return;
4480 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4481 wined3d_mutex_unlock();
4482 *shader = &shader_impl->ID3D10GeometryShader_iface;
4483 ID3D10GeometryShader_AddRef(*shader);
4486 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
4487 D3D10_PRIMITIVE_TOPOLOGY *topology)
4489 struct d3d_device *device = impl_from_ID3D10Device(iface);
4491 TRACE("iface %p, topology %p\n", iface, topology);
4493 wined3d_mutex_lock();
4494 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
4495 wined3d_mutex_unlock();
4498 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
4499 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4501 struct d3d_device *device = impl_from_ID3D10Device(iface);
4502 unsigned int i;
4504 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4505 iface, start_slot, view_count, views);
4507 wined3d_mutex_lock();
4508 for (i = 0; i < view_count; ++i)
4510 struct wined3d_shader_resource_view *wined3d_view;
4511 struct d3d_shader_resource_view *view_impl;
4513 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
4515 views[i] = NULL;
4516 continue;
4519 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4520 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4521 ID3D10ShaderResourceView_AddRef(views[i]);
4523 wined3d_mutex_unlock();
4526 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
4527 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4529 struct d3d_device *device = impl_from_ID3D10Device(iface);
4530 unsigned int i;
4532 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4533 iface, start_slot, sampler_count, samplers);
4535 wined3d_mutex_lock();
4536 for (i = 0; i < sampler_count; ++i)
4538 struct d3d_sampler_state *sampler_impl;
4539 struct wined3d_sampler *wined3d_sampler;
4541 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4543 samplers[i] = NULL;
4544 continue;
4547 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4548 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4549 ID3D10SamplerState_AddRef(samplers[i]);
4551 wined3d_mutex_unlock();
4554 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4555 ID3D10Predicate **predicate, BOOL *value)
4557 struct d3d_device *device = impl_from_ID3D10Device(iface);
4558 struct wined3d_query *wined3d_predicate;
4559 struct d3d_query *predicate_impl;
4561 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4563 wined3d_mutex_lock();
4564 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4566 wined3d_mutex_unlock();
4567 *predicate = NULL;
4568 return;
4571 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4572 wined3d_mutex_unlock();
4573 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4574 ID3D10Predicate_AddRef(*predicate);
4577 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4578 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4580 struct d3d_device *device = impl_from_ID3D10Device(iface);
4581 unsigned int i;
4583 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4584 iface, start_slot, view_count, views);
4586 wined3d_mutex_lock();
4587 for (i = 0; i < view_count; ++i)
4589 struct wined3d_shader_resource_view *wined3d_view;
4590 struct d3d_shader_resource_view *view_impl;
4592 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4594 views[i] = NULL;
4595 continue;
4598 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4599 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4600 ID3D10ShaderResourceView_AddRef(views[i]);
4602 wined3d_mutex_unlock();
4605 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4606 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4608 struct d3d_device *device = impl_from_ID3D10Device(iface);
4609 unsigned int i;
4611 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4612 iface, start_slot, sampler_count, samplers);
4614 wined3d_mutex_lock();
4615 for (i = 0; i < sampler_count; ++i)
4617 struct d3d_sampler_state *sampler_impl;
4618 struct wined3d_sampler *wined3d_sampler;
4620 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4622 samplers[i] = NULL;
4623 continue;
4626 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4627 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4628 ID3D10SamplerState_AddRef(samplers[i]);
4630 wined3d_mutex_unlock();
4633 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4634 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4636 struct d3d_device *device = impl_from_ID3D10Device(iface);
4637 struct wined3d_rendertarget_view *wined3d_view;
4639 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4640 iface, view_count, render_target_views, depth_stencil_view);
4642 wined3d_mutex_lock();
4643 if (render_target_views)
4645 struct d3d_rendertarget_view *view_impl;
4646 unsigned int i;
4648 for (i = 0; i < view_count; ++i)
4650 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4651 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4653 render_target_views[i] = NULL;
4654 continue;
4657 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4658 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4662 if (depth_stencil_view)
4664 struct d3d_depthstencil_view *view_impl;
4666 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4667 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4669 *depth_stencil_view = NULL;
4671 else
4673 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4674 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4677 wined3d_mutex_unlock();
4680 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4681 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4683 struct d3d_device *device = impl_from_ID3D10Device(iface);
4684 ID3D11BlendState *d3d11_blend_state;
4686 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4687 iface, blend_state, blend_factor, sample_mask);
4689 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4690 &d3d11_blend_state, blend_factor, sample_mask);
4692 if (d3d11_blend_state)
4693 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4694 else
4695 *blend_state = NULL;
4698 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4699 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4701 struct d3d_device *device = impl_from_ID3D10Device(iface);
4702 ID3D11DepthStencilState *d3d11_iface;
4704 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4705 iface, depth_stencil_state, stencil_ref);
4707 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4708 &d3d11_iface, stencil_ref);
4710 if (d3d11_iface)
4711 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4712 else
4713 *depth_stencil_state = NULL;
4716 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4717 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4719 struct d3d_device *device = impl_from_ID3D10Device(iface);
4720 unsigned int i;
4722 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4723 iface, buffer_count, buffers, offsets);
4725 wined3d_mutex_lock();
4726 for (i = 0; i < buffer_count; ++i)
4728 struct wined3d_buffer *wined3d_buffer;
4729 struct d3d_buffer *buffer_impl;
4731 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4733 buffers[i] = NULL;
4734 continue;
4737 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4738 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4739 ID3D10Buffer_AddRef(buffers[i]);
4741 wined3d_mutex_unlock();
4744 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4746 struct d3d_device *device = impl_from_ID3D10Device(iface);
4747 struct d3d_rasterizer_state *rasterizer_state_impl;
4748 struct wined3d_rasterizer_state *wined3d_state;
4750 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4752 wined3d_mutex_lock();
4753 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
4755 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
4756 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
4758 else
4760 *rasterizer_state = NULL;
4762 wined3d_mutex_unlock();
4765 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4766 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4768 struct d3d_device *device = impl_from_ID3D10Device(iface);
4769 struct wined3d_viewport wined3d_vp;
4771 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4773 if (!viewports)
4775 *viewport_count = 1;
4776 return;
4779 if (!*viewport_count)
4780 return;
4782 wined3d_mutex_lock();
4783 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4784 wined3d_mutex_unlock();
4786 viewports[0].TopLeftX = wined3d_vp.x;
4787 viewports[0].TopLeftY = wined3d_vp.y;
4788 viewports[0].Width = wined3d_vp.width;
4789 viewports[0].Height = wined3d_vp.height;
4790 viewports[0].MinDepth = wined3d_vp.min_z;
4791 viewports[0].MaxDepth = wined3d_vp.max_z;
4793 if (*viewport_count > 1)
4794 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4797 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4799 struct d3d_device *device = impl_from_ID3D10Device(iface);
4801 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4803 if (!rects)
4805 *rect_count = 1;
4806 return;
4809 if (!*rect_count)
4810 return;
4812 wined3d_mutex_lock();
4813 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4814 wined3d_mutex_unlock();
4815 if (*rect_count > 1)
4816 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4819 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4821 TRACE("iface %p.\n", iface);
4823 /* In the current implementation the device is never removed, so we can
4824 * just return S_OK here. */
4826 return S_OK;
4829 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4831 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4833 return E_NOTIMPL;
4836 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4838 FIXME("iface %p stub!\n", iface);
4840 return 0;
4843 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4844 REFGUID guid, UINT *data_size, void *data)
4846 struct d3d_device *device = impl_from_ID3D10Device(iface);
4848 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4850 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4853 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4854 REFGUID guid, UINT data_size, const void *data)
4856 struct d3d_device *device = impl_from_ID3D10Device(iface);
4858 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4860 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4863 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4864 REFGUID guid, const IUnknown *data)
4866 struct d3d_device *device = impl_from_ID3D10Device(iface);
4868 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4870 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4873 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4875 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
4876 struct d3d_device *device = impl_from_ID3D10Device(iface);
4877 unsigned int i;
4879 TRACE("iface %p.\n", iface);
4881 wined3d_mutex_lock();
4882 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
4883 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4885 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
4887 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4889 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
4891 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4893 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
4895 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
4896 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4898 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
4900 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4902 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
4904 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4906 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
4908 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
4909 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4911 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
4913 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4915 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
4917 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4919 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
4921 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4923 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
4925 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
4926 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
4927 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
4928 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4930 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4932 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
4933 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
4934 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4935 ID3D10Device1_RSSetViewports(iface, 0, NULL);
4936 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
4937 ID3D10Device1_RSSetState(iface, NULL);
4938 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4940 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4942 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
4943 wined3d_mutex_unlock();
4946 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4948 FIXME("iface %p stub!\n", iface);
4951 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4952 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4954 struct d3d_device *device = impl_from_ID3D10Device(iface);
4955 D3D11_BUFFER_DESC d3d11_desc;
4956 struct d3d_buffer *object;
4957 HRESULT hr;
4959 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
4961 d3d11_desc.ByteWidth = desc->ByteWidth;
4962 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4963 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4964 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4965 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4966 d3d11_desc.StructureByteStride = 0;
4968 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4969 return hr;
4971 *buffer = &object->ID3D10Buffer_iface;
4973 return S_OK;
4976 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
4977 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
4979 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
4981 return E_NOTIMPL;
4984 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
4985 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4986 ID3D10Texture2D **texture)
4988 struct d3d_device *device = impl_from_ID3D10Device(iface);
4989 D3D11_TEXTURE2D_DESC d3d11_desc;
4990 struct d3d_texture2d *object;
4991 HRESULT hr;
4993 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4995 d3d11_desc.Width = desc->Width;
4996 d3d11_desc.Height = desc->Height;
4997 d3d11_desc.MipLevels = desc->MipLevels;
4998 d3d11_desc.ArraySize = desc->ArraySize;
4999 d3d11_desc.Format = desc->Format;
5000 d3d11_desc.SampleDesc = desc->SampleDesc;
5001 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5002 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5003 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5004 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5006 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5007 return hr;
5009 *texture = &object->ID3D10Texture2D_iface;
5011 return S_OK;
5014 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5015 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5016 ID3D10Texture3D **texture)
5018 struct d3d_device *device = impl_from_ID3D10Device(iface);
5019 D3D11_TEXTURE3D_DESC d3d11_desc;
5020 struct d3d_texture3d *object;
5021 HRESULT hr;
5023 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5025 d3d11_desc.Width = desc->Width;
5026 d3d11_desc.Height = desc->Height;
5027 d3d11_desc.Depth = desc->Depth;
5028 d3d11_desc.MipLevels = desc->MipLevels;
5029 d3d11_desc.Format = desc->Format;
5030 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5031 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5032 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5033 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5035 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5036 return hr;
5038 *texture = &object->ID3D10Texture3D_iface;
5040 return S_OK;
5043 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5044 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5046 struct d3d_device *device = impl_from_ID3D10Device(iface);
5047 struct d3d_shader_resource_view *object;
5048 ID3D11Resource *d3d11_resource;
5049 HRESULT hr;
5051 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5053 if (!resource)
5054 return E_INVALIDARG;
5056 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5058 ERR("Resource does not implement ID3D11Resource.\n");
5059 return E_FAIL;
5062 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5063 &object);
5064 ID3D11Resource_Release(d3d11_resource);
5065 if (FAILED(hr))
5066 return hr;
5068 *view = &object->ID3D10ShaderResourceView1_iface;
5070 return S_OK;
5073 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5074 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5076 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5078 return d3d10_device_CreateShaderResourceView1(iface, resource,
5079 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5082 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5083 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5085 struct d3d_device *device = impl_from_ID3D10Device(iface);
5086 struct d3d_rendertarget_view *object;
5087 ID3D11Resource *d3d11_resource;
5088 HRESULT hr;
5090 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5092 if (!resource)
5093 return E_INVALIDARG;
5095 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5097 ERR("Resource does not implement ID3D11Resource.\n");
5098 return E_FAIL;
5101 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5102 ID3D11Resource_Release(d3d11_resource);
5103 if (FAILED(hr))
5104 return hr;
5106 *view = &object->ID3D10RenderTargetView_iface;
5108 return S_OK;
5111 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5112 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5114 struct d3d_device *device = impl_from_ID3D10Device(iface);
5115 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5116 struct d3d_depthstencil_view *object;
5117 ID3D11Resource *d3d11_resource;
5118 HRESULT hr;
5120 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5122 if (desc)
5124 d3d11_desc.Format = desc->Format;
5125 d3d11_desc.ViewDimension = desc->ViewDimension;
5126 d3d11_desc.Flags = 0;
5127 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5130 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5132 ERR("Resource does not implement ID3D11Resource.\n");
5133 return E_FAIL;
5136 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5137 ID3D11Resource_Release(d3d11_resource);
5138 if (FAILED(hr))
5139 return hr;
5141 *view = &object->ID3D10DepthStencilView_iface;
5143 return S_OK;
5146 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5147 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5148 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5149 ID3D10InputLayout **input_layout)
5151 struct d3d_device *device = impl_from_ID3D10Device(iface);
5152 struct d3d_input_layout *object;
5153 HRESULT hr;
5155 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5156 "shader_byte_code_length %lu, input_layout %p\n",
5157 iface, element_descs, element_count, shader_byte_code,
5158 shader_byte_code_length, input_layout);
5160 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5161 shader_byte_code, shader_byte_code_length, &object)))
5162 return hr;
5164 *input_layout = &object->ID3D10InputLayout_iface;
5166 return S_OK;
5169 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5170 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5172 struct d3d_device *device = impl_from_ID3D10Device(iface);
5173 struct d3d_vertex_shader *object;
5174 HRESULT hr;
5176 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5177 iface, byte_code, byte_code_length, shader);
5179 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5180 return hr;
5182 *shader = &object->ID3D10VertexShader_iface;
5184 return S_OK;
5187 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5188 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5190 struct d3d_device *device = impl_from_ID3D10Device(iface);
5191 struct d3d_geometry_shader *object;
5192 HRESULT hr;
5194 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5195 iface, byte_code, byte_code_length, shader);
5197 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5198 NULL, 0, NULL, 0, 0, &object)))
5199 return hr;
5201 *shader = &object->ID3D10GeometryShader_iface;
5203 return S_OK;
5206 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5207 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5208 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5210 struct d3d_device *device = impl_from_ID3D10Device(iface);
5211 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5212 struct d3d_geometry_shader *object;
5213 unsigned int i, stride_count = 1;
5214 HRESULT hr;
5216 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5217 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5218 iface, byte_code, byte_code_length, output_stream_decls,
5219 output_stream_decl_count, output_stream_stride, shader);
5221 if (!output_stream_decl_count && output_stream_stride)
5223 WARN("Stride must be 0 when declaration entry count is 0.\n");
5224 *shader = NULL;
5225 return E_INVALIDARG;
5228 if (output_stream_decl_count
5229 && !(so_entries = d3d11_calloc(output_stream_decl_count, sizeof(*so_entries))))
5231 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5232 *shader = NULL;
5233 return E_OUTOFMEMORY;
5236 for (i = 0; i < output_stream_decl_count; ++i)
5238 so_entries[i].Stream = 0;
5239 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5240 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5241 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5242 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5243 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5245 if (output_stream_decls[i].OutputSlot)
5247 stride_count = 0;
5248 if (output_stream_stride)
5250 WARN("Stride must be 0 when multiple output slots are used.\n");
5251 HeapFree(GetProcessHeap(), 0, so_entries);
5252 *shader = NULL;
5253 return E_INVALIDARG;
5258 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5259 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5260 HeapFree(GetProcessHeap(), 0, so_entries);
5261 if (FAILED(hr))
5263 *shader = NULL;
5264 return hr;
5267 *shader = &object->ID3D10GeometryShader_iface;
5269 return hr;
5272 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5273 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5275 struct d3d_device *device = impl_from_ID3D10Device(iface);
5276 struct d3d_pixel_shader *object;
5277 HRESULT hr;
5279 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5280 iface, byte_code, byte_code_length, shader);
5282 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
5283 return hr;
5285 *shader = &object->ID3D10PixelShader_iface;
5287 return S_OK;
5290 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
5291 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
5293 struct d3d_device *device = impl_from_ID3D10Device(iface);
5294 ID3D11BlendState *d3d11_blend_state;
5295 HRESULT hr;
5297 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5299 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
5300 &d3d11_blend_state)))
5301 return hr;
5303 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
5304 ID3D11BlendState_Release(d3d11_blend_state);
5305 return hr;
5308 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
5309 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
5311 D3D10_BLEND_DESC1 d3d10_1_desc;
5312 unsigned int i;
5314 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5316 if (!desc)
5317 return E_INVALIDARG;
5319 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
5320 d3d10_1_desc.IndependentBlendEnable = FALSE;
5321 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
5323 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
5324 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
5325 d3d10_1_desc.IndependentBlendEnable = TRUE;
5328 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5330 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
5331 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
5332 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
5333 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
5334 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
5335 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
5336 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
5337 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
5340 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
5343 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
5344 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
5346 struct d3d_device *device = impl_from_ID3D10Device(iface);
5347 ID3D11DepthStencilState *d3d11_depth_stencil_state;
5348 HRESULT hr;
5350 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
5352 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
5353 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
5354 return hr;
5356 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
5357 (void **)depth_stencil_state);
5358 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
5359 return hr;
5362 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
5363 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
5365 struct d3d_device *device = impl_from_ID3D10Device(iface);
5366 ID3D11RasterizerState *d3d11_rasterizer_state;
5367 HRESULT hr;
5369 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
5371 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
5372 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
5373 return hr;
5375 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
5376 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
5377 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
5378 return hr;
5381 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
5382 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
5384 struct d3d_device *device = impl_from_ID3D10Device(iface);
5385 ID3D11SamplerState *d3d11_sampler_state;
5386 HRESULT hr;
5388 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
5390 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
5391 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
5392 return hr;
5394 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
5395 ID3D11SamplerState_Release(d3d11_sampler_state);
5396 return hr;
5399 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
5400 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
5402 struct d3d_device *device = impl_from_ID3D10Device(iface);
5403 struct d3d_query *object;
5404 HRESULT hr;
5406 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
5408 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
5409 return hr;
5411 if (query)
5413 *query = &object->ID3D10Query_iface;
5414 return S_OK;
5417 ID3D10Query_Release(&object->ID3D10Query_iface);
5418 return S_FALSE;
5421 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
5422 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
5424 struct d3d_device *device = impl_from_ID3D10Device(iface);
5425 struct d3d_query *object;
5426 HRESULT hr;
5428 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
5430 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
5431 return hr;
5433 if (predicate)
5435 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
5436 return S_OK;
5439 ID3D10Query_Release(&object->ID3D10Query_iface);
5440 return S_FALSE;
5443 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
5444 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
5446 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
5448 return E_NOTIMPL;
5451 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
5452 DXGI_FORMAT format, UINT *format_support)
5454 FIXME("iface %p, format %s, format_support %p stub!\n",
5455 iface, debug_dxgi_format(format), format_support);
5457 return E_NOTIMPL;
5460 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
5461 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
5463 struct d3d_device *device = impl_from_ID3D10Device(iface);
5465 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
5466 iface, debug_dxgi_format(format), sample_count, quality_level_count);
5468 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
5469 sample_count, quality_level_count);
5472 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
5474 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
5477 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
5478 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
5479 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
5481 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
5482 "units %p, units_length %p, description %p, description_length %p stub!\n",
5483 iface, desc, type, active_counters, name, name_length,
5484 units, units_length, description, description_length);
5486 return E_NOTIMPL;
5489 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
5491 FIXME("iface %p stub!\n", iface);
5493 return 0;
5496 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
5497 HANDLE resource_handle, REFIID guid, void **resource)
5499 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
5500 iface, resource_handle, debugstr_guid(guid), resource);
5502 return E_NOTIMPL;
5505 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
5507 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
5510 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
5512 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
5515 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
5517 struct d3d_device *device = impl_from_ID3D10Device(iface);
5519 TRACE("iface %p.\n", iface);
5521 return device->feature_level;
5524 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
5526 /* IUnknown methods */
5527 d3d10_device_QueryInterface,
5528 d3d10_device_AddRef,
5529 d3d10_device_Release,
5530 /* ID3D10Device methods */
5531 d3d10_device_VSSetConstantBuffers,
5532 d3d10_device_PSSetShaderResources,
5533 d3d10_device_PSSetShader,
5534 d3d10_device_PSSetSamplers,
5535 d3d10_device_VSSetShader,
5536 d3d10_device_DrawIndexed,
5537 d3d10_device_Draw,
5538 d3d10_device_PSSetConstantBuffers,
5539 d3d10_device_IASetInputLayout,
5540 d3d10_device_IASetVertexBuffers,
5541 d3d10_device_IASetIndexBuffer,
5542 d3d10_device_DrawIndexedInstanced,
5543 d3d10_device_DrawInstanced,
5544 d3d10_device_GSSetConstantBuffers,
5545 d3d10_device_GSSetShader,
5546 d3d10_device_IASetPrimitiveTopology,
5547 d3d10_device_VSSetShaderResources,
5548 d3d10_device_VSSetSamplers,
5549 d3d10_device_SetPredication,
5550 d3d10_device_GSSetShaderResources,
5551 d3d10_device_GSSetSamplers,
5552 d3d10_device_OMSetRenderTargets,
5553 d3d10_device_OMSetBlendState,
5554 d3d10_device_OMSetDepthStencilState,
5555 d3d10_device_SOSetTargets,
5556 d3d10_device_DrawAuto,
5557 d3d10_device_RSSetState,
5558 d3d10_device_RSSetViewports,
5559 d3d10_device_RSSetScissorRects,
5560 d3d10_device_CopySubresourceRegion,
5561 d3d10_device_CopyResource,
5562 d3d10_device_UpdateSubresource,
5563 d3d10_device_ClearRenderTargetView,
5564 d3d10_device_ClearDepthStencilView,
5565 d3d10_device_GenerateMips,
5566 d3d10_device_ResolveSubresource,
5567 d3d10_device_VSGetConstantBuffers,
5568 d3d10_device_PSGetShaderResources,
5569 d3d10_device_PSGetShader,
5570 d3d10_device_PSGetSamplers,
5571 d3d10_device_VSGetShader,
5572 d3d10_device_PSGetConstantBuffers,
5573 d3d10_device_IAGetInputLayout,
5574 d3d10_device_IAGetVertexBuffers,
5575 d3d10_device_IAGetIndexBuffer,
5576 d3d10_device_GSGetConstantBuffers,
5577 d3d10_device_GSGetShader,
5578 d3d10_device_IAGetPrimitiveTopology,
5579 d3d10_device_VSGetShaderResources,
5580 d3d10_device_VSGetSamplers,
5581 d3d10_device_GetPredication,
5582 d3d10_device_GSGetShaderResources,
5583 d3d10_device_GSGetSamplers,
5584 d3d10_device_OMGetRenderTargets,
5585 d3d10_device_OMGetBlendState,
5586 d3d10_device_OMGetDepthStencilState,
5587 d3d10_device_SOGetTargets,
5588 d3d10_device_RSGetState,
5589 d3d10_device_RSGetViewports,
5590 d3d10_device_RSGetScissorRects,
5591 d3d10_device_GetDeviceRemovedReason,
5592 d3d10_device_SetExceptionMode,
5593 d3d10_device_GetExceptionMode,
5594 d3d10_device_GetPrivateData,
5595 d3d10_device_SetPrivateData,
5596 d3d10_device_SetPrivateDataInterface,
5597 d3d10_device_ClearState,
5598 d3d10_device_Flush,
5599 d3d10_device_CreateBuffer,
5600 d3d10_device_CreateTexture1D,
5601 d3d10_device_CreateTexture2D,
5602 d3d10_device_CreateTexture3D,
5603 d3d10_device_CreateShaderResourceView,
5604 d3d10_device_CreateRenderTargetView,
5605 d3d10_device_CreateDepthStencilView,
5606 d3d10_device_CreateInputLayout,
5607 d3d10_device_CreateVertexShader,
5608 d3d10_device_CreateGeometryShader,
5609 d3d10_device_CreateGeometryShaderWithStreamOutput,
5610 d3d10_device_CreatePixelShader,
5611 d3d10_device_CreateBlendState,
5612 d3d10_device_CreateDepthStencilState,
5613 d3d10_device_CreateRasterizerState,
5614 d3d10_device_CreateSamplerState,
5615 d3d10_device_CreateQuery,
5616 d3d10_device_CreatePredicate,
5617 d3d10_device_CreateCounter,
5618 d3d10_device_CheckFormatSupport,
5619 d3d10_device_CheckMultisampleQualityLevels,
5620 d3d10_device_CheckCounterInfo,
5621 d3d10_device_CheckCounter,
5622 d3d10_device_GetCreationFlags,
5623 d3d10_device_OpenSharedResource,
5624 d3d10_device_SetTextFilterSize,
5625 d3d10_device_GetTextFilterSize,
5626 d3d10_device_CreateShaderResourceView1,
5627 d3d10_device_CreateBlendState1,
5628 d3d10_device_GetFeatureLevel,
5631 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5633 /* IUnknown methods */
5634 d3d_device_inner_QueryInterface,
5635 d3d_device_inner_AddRef,
5636 d3d_device_inner_Release,
5639 /* ID3D10Multithread methods */
5641 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5643 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5646 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5648 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5650 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5652 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5655 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5657 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5659 TRACE("iface %p.\n", iface);
5661 return IUnknown_AddRef(device->outer_unk);
5664 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5666 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5668 TRACE("iface %p.\n", iface);
5670 return IUnknown_Release(device->outer_unk);
5673 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5675 TRACE("iface %p.\n", iface);
5677 wined3d_mutex_lock();
5680 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5682 TRACE("iface %p.\n", iface);
5684 wined3d_mutex_unlock();
5687 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5689 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5691 return TRUE;
5694 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5696 FIXME("iface %p stub!\n", iface);
5698 return TRUE;
5701 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5703 d3d10_multithread_QueryInterface,
5704 d3d10_multithread_AddRef,
5705 d3d10_multithread_Release,
5706 d3d10_multithread_Enter,
5707 d3d10_multithread_Leave,
5708 d3d10_multithread_SetMultithreadProtected,
5709 d3d10_multithread_GetMultithreadProtected,
5712 /* IWineDXGIDeviceParent IUnknown methods */
5714 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5716 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5719 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5720 REFIID riid, void **ppv)
5722 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5723 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5726 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5728 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5729 return IUnknown_AddRef(device->outer_unk);
5732 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5734 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5735 return IUnknown_Release(device->outer_unk);
5738 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5739 IWineDXGIDeviceParent *iface)
5741 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5742 return &device->device_parent;
5745 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5747 /* IUnknown methods */
5748 dxgi_device_parent_QueryInterface,
5749 dxgi_device_parent_AddRef,
5750 dxgi_device_parent_Release,
5751 /* IWineDXGIDeviceParent methods */
5752 dxgi_device_parent_get_wined3d_device_parent,
5755 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5757 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5760 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5761 struct wined3d_device *wined3d_device)
5763 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5765 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5767 wined3d_device_incref(wined3d_device);
5768 device->wined3d_device = wined3d_device;
5771 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5773 TRACE("device_parent %p.\n", device_parent);
5776 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5778 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5781 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5782 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5783 const struct wined3d_parent_ops **parent_ops)
5785 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5786 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5788 *parent = NULL;
5789 *parent_ops = &d3d_null_wined3d_parent_ops;
5791 return S_OK;
5794 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5795 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
5796 struct wined3d_texture **wined3d_texture)
5798 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5799 struct d3d_texture2d *texture;
5800 ID3D10Texture2D *texture_iface;
5801 D3D10_TEXTURE2D_DESC desc;
5802 HRESULT hr;
5804 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, texture flags %#x, "
5805 "wined3d_texture %p partial stub!\n", device_parent, container_parent,
5806 wined3d_desc, texture_flags, wined3d_texture);
5808 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5810 desc.Width = wined3d_desc->width;
5811 desc.Height = wined3d_desc->height;
5812 desc.MipLevels = 1;
5813 desc.ArraySize = 1;
5814 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5815 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5816 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5817 desc.Usage = D3D10_USAGE_DEFAULT;
5818 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5819 desc.CPUAccessFlags = 0;
5820 desc.MiscFlags = 0;
5822 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
5824 desc.MiscFlags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
5825 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
5828 if (texture_flags)
5829 FIXME("Unhandled flags %#x.\n", texture_flags);
5831 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5832 &desc, NULL, &texture_iface)))
5834 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5835 return hr;
5838 texture = impl_from_ID3D10Texture2D(texture_iface);
5840 *wined3d_texture = texture->wined3d_texture;
5841 wined3d_texture_incref(*wined3d_texture);
5842 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5844 return S_OK;
5847 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5848 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5850 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5851 IWineDXGIDevice *wine_device;
5852 HRESULT hr;
5854 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5856 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5857 &IID_IWineDXGIDevice, (void **)&wine_device)))
5859 ERR("Device should implement IWineDXGIDevice.\n");
5860 return E_FAIL;
5863 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5864 IWineDXGIDevice_Release(wine_device);
5865 if (FAILED(hr))
5867 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5868 return hr;
5871 return S_OK;
5874 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5876 device_parent_wined3d_device_created,
5877 device_parent_mode_changed,
5878 device_parent_activate,
5879 device_parent_sub_resource_created,
5880 device_parent_sub_resource_created,
5881 device_parent_create_swapchain_texture,
5882 device_parent_create_swapchain,
5885 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5887 const D3D11_SAMPLER_DESC *ka = key;
5888 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5890 return memcmp(ka, kb, sizeof(*ka));
5893 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5895 const D3D11_BLEND_DESC *ka = key;
5896 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5898 return memcmp(ka, kb, sizeof(*ka));
5901 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5903 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5904 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5905 const struct d3d_depthstencil_state, entry)->desc;
5907 return memcmp(ka, kb, sizeof(*ka));
5910 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5912 const D3D11_RASTERIZER_DESC *ka = key;
5913 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5915 return memcmp(ka, kb, sizeof(*ka));
5918 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
5920 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5921 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5922 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5923 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5924 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5925 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5926 device->refcount = 1;
5927 /* COM aggregation always takes place */
5928 device->outer_unk = outer_unknown;
5930 d3d11_immediate_context_init(&device->immediate_context, device);
5931 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5933 device->blend_factor[0] = 1.0f;
5934 device->blend_factor[1] = 1.0f;
5935 device->blend_factor[2] = 1.0f;
5936 device->blend_factor[3] = 1.0f;
5938 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
5939 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
5940 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
5941 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);