mountmgr: Name DosDevices constants consistently.
[wine.git] / dlls / d3d11 / device.c
blob81da77be0a6068649137ba6d88fa641306471daf
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 wined3d_vp.x = viewports[0].TopLeftX;
931 wined3d_vp.y = viewports[0].TopLeftY;
932 wined3d_vp.width = viewports[0].Width;
933 wined3d_vp.height = viewports[0].Height;
934 wined3d_vp.min_z = viewports[0].MinDepth;
935 wined3d_vp.max_z = viewports[0].MaxDepth;
937 wined3d_mutex_lock();
938 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
939 wined3d_mutex_unlock();
942 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
943 UINT rect_count, const D3D11_RECT *rects)
945 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
947 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
949 if (rect_count > 1)
950 FIXME("Multiple scissor rects not implemented.\n");
952 if (!rect_count)
953 return;
955 wined3d_mutex_lock();
956 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
957 wined3d_mutex_unlock();
960 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
961 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
962 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
964 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
965 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
966 struct wined3d_box wined3d_src_box;
968 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
969 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
970 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
971 src_resource, src_subresource_idx, src_box);
973 if (src_box)
974 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
975 src_box->right, src_box->bottom, src_box->front, src_box->back);
977 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
978 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
979 wined3d_mutex_lock();
980 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
981 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
982 wined3d_mutex_unlock();
985 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
986 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
988 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
989 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
991 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
993 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
994 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
995 wined3d_mutex_lock();
996 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
997 wined3d_mutex_unlock();
1000 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
1001 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
1002 const void *data, UINT row_pitch, UINT depth_pitch)
1004 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1005 struct wined3d_resource *wined3d_resource;
1006 struct wined3d_box wined3d_box;
1008 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1009 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1011 if (box)
1012 wined3d_box_set(&wined3d_box, box->left, box->top, box->right, box->bottom, box->front, box->back);
1014 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1015 wined3d_mutex_lock();
1016 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1017 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1018 wined3d_mutex_unlock();
1021 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
1022 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1024 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
1025 iface, dst_buffer, dst_offset, src_view);
1028 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
1029 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1031 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1032 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1033 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1034 HRESULT hr;
1036 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1037 iface, render_target_view, debug_float4(color_rgba));
1039 if (!view)
1040 return;
1042 wined3d_mutex_lock();
1043 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1044 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1045 ERR("Failed to clear view, hr %#x.\n", hr);
1046 wined3d_mutex_unlock();
1049 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1050 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1052 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1053 struct d3d11_unordered_access_view *view;
1055 TRACE("iface %p, unordered_access_view %p, values {%u, %u, %u, %u}.\n",
1056 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1058 view = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_view);
1059 wined3d_mutex_lock();
1060 wined3d_device_clear_unordered_access_view_uint(device->wined3d_device,
1061 view->wined3d_view, (const struct wined3d_uvec4 *)values);
1062 wined3d_mutex_unlock();
1065 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1066 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1068 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1069 iface, unordered_access_view, debug_float4(values));
1072 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1073 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1075 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1076 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1077 DWORD wined3d_flags;
1078 HRESULT hr;
1080 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1081 iface, depth_stencil_view, flags, depth, stencil);
1083 if (!view)
1084 return;
1086 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1088 wined3d_mutex_lock();
1089 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1090 wined3d_flags, NULL, depth, stencil)))
1091 ERR("Failed to clear view, hr %#x.\n", hr);
1092 wined3d_mutex_unlock();
1095 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1096 ID3D11ShaderResourceView *view)
1098 FIXME("iface %p, view %p stub!\n", iface, view);
1101 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1102 ID3D11Resource *resource, FLOAT min_lod)
1104 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1107 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1108 ID3D11Resource *resource)
1110 FIXME("iface %p, resource %p stub!\n", iface, resource);
1112 return 0.0f;
1115 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1116 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1117 ID3D11Resource *src_resource, UINT src_subresource_idx,
1118 DXGI_FORMAT format)
1120 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1121 "format %s stub!\n",
1122 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1123 debug_dxgi_format(format));
1126 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1127 ID3D11CommandList *command_list, BOOL restore_state)
1129 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1132 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1133 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1135 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1136 unsigned int i;
1138 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1139 iface, start_slot, view_count, views);
1141 wined3d_mutex_lock();
1142 for (i = 0; i < view_count; ++i)
1144 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1146 wined3d_device_set_hs_resource_view(device->wined3d_device, start_slot + i,
1147 view ? view->wined3d_view : NULL);
1149 wined3d_mutex_unlock();
1152 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1153 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1155 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1156 struct d3d11_hull_shader *hs = unsafe_impl_from_ID3D11HullShader(shader);
1158 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1159 iface, shader, class_instances, class_instance_count);
1161 if (class_instances)
1162 FIXME("Dynamic linking is not implemented yet.\n");
1164 wined3d_mutex_lock();
1165 wined3d_device_set_hull_shader(device->wined3d_device, hs ? hs->wined3d_shader : NULL);
1166 wined3d_mutex_unlock();
1169 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1170 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1172 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1173 unsigned int i;
1175 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1176 iface, start_slot, sampler_count, samplers);
1178 wined3d_mutex_lock();
1179 for (i = 0; i < sampler_count; ++i)
1181 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1183 wined3d_device_set_hs_sampler(device->wined3d_device, start_slot + i,
1184 sampler ? sampler->wined3d_sampler : NULL);
1186 wined3d_mutex_unlock();
1189 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1190 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1192 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1193 unsigned int i;
1195 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1196 iface, start_slot, buffer_count, buffers);
1198 wined3d_mutex_lock();
1199 for (i = 0; i < buffer_count; ++i)
1201 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1203 wined3d_device_set_hs_cb(device->wined3d_device, start_slot + i,
1204 buffer ? buffer->wined3d_buffer : NULL);
1206 wined3d_mutex_unlock();
1209 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1210 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1212 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1213 unsigned int i;
1215 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1216 iface, start_slot, view_count, views);
1218 wined3d_mutex_lock();
1219 for (i = 0; i < view_count; ++i)
1221 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1223 wined3d_device_set_ds_resource_view(device->wined3d_device, start_slot + i,
1224 view ? view->wined3d_view : NULL);
1226 wined3d_mutex_unlock();
1229 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1230 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1232 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1233 struct d3d11_domain_shader *ds = unsafe_impl_from_ID3D11DomainShader(shader);
1235 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1236 iface, shader, class_instances, class_instance_count);
1238 if (class_instances)
1239 FIXME("Dynamic linking is not implemented yet.\n");
1241 wined3d_mutex_lock();
1242 wined3d_device_set_domain_shader(device->wined3d_device, ds ? ds->wined3d_shader : NULL);
1243 wined3d_mutex_unlock();
1246 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1247 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1249 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1250 unsigned int i;
1252 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1253 iface, start_slot, sampler_count, samplers);
1255 wined3d_mutex_lock();
1256 for (i = 0; i < sampler_count; ++i)
1258 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1260 wined3d_device_set_ds_sampler(device->wined3d_device, start_slot + i,
1261 sampler ? sampler->wined3d_sampler : NULL);
1263 wined3d_mutex_unlock();
1266 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1267 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1269 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1270 unsigned int i;
1272 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1273 iface, start_slot, buffer_count, buffers);
1275 wined3d_mutex_lock();
1276 for (i = 0; i < buffer_count; ++i)
1278 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1280 wined3d_device_set_ds_cb(device->wined3d_device, start_slot + i,
1281 buffer ? buffer->wined3d_buffer : NULL);
1283 wined3d_mutex_unlock();
1286 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1287 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1289 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1290 unsigned int i;
1292 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1293 iface, start_slot, view_count, views);
1295 wined3d_mutex_lock();
1296 for (i = 0; i < view_count; ++i)
1298 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
1300 wined3d_device_set_cs_resource_view(device->wined3d_device, start_slot + i,
1301 view ? view->wined3d_view : NULL);
1303 wined3d_mutex_unlock();
1306 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1307 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1309 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1310 unsigned int i;
1312 TRACE("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p.\n",
1313 iface, start_slot, view_count, views, initial_counts);
1315 wined3d_mutex_lock();
1316 for (i = 0; i < view_count; ++i)
1318 struct d3d11_unordered_access_view *view = unsafe_impl_from_ID3D11UnorderedAccessView(views[i]);
1320 if (initial_counts && view && view->desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER
1321 && (view->desc.u.Buffer.Flags & (D3D11_BUFFER_UAV_FLAG_APPEND | D3D11_BUFFER_UAV_FLAG_COUNTER))
1322 && initial_counts[i] != ~(UINT)0)
1323 FIXME("Ignoring initial count %u for slot %u.\n", initial_counts[i], start_slot + i);
1325 wined3d_device_set_cs_uav(device->wined3d_device, start_slot + i,
1326 view ? view->wined3d_view : NULL);
1328 wined3d_mutex_unlock();
1331 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1332 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1334 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1335 struct d3d11_compute_shader *cs = unsafe_impl_from_ID3D11ComputeShader(shader);
1337 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
1338 iface, shader, class_instances, class_instance_count);
1340 if (class_instances)
1341 FIXME("Dynamic linking is not implemented yet.\n");
1343 wined3d_mutex_lock();
1344 wined3d_device_set_compute_shader(device->wined3d_device, cs ? cs->wined3d_shader : NULL);
1345 wined3d_mutex_unlock();
1348 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1349 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1351 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1352 unsigned int i;
1354 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1355 iface, start_slot, sampler_count, samplers);
1357 wined3d_mutex_lock();
1358 for (i = 0; i < sampler_count; ++i)
1360 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
1362 wined3d_device_set_cs_sampler(device->wined3d_device, start_slot + i,
1363 sampler ? sampler->wined3d_sampler : NULL);
1365 wined3d_mutex_unlock();
1368 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1369 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1371 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1372 unsigned int i;
1374 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1375 iface, start_slot, buffer_count, buffers);
1377 wined3d_mutex_lock();
1378 for (i = 0; i < buffer_count; ++i)
1380 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
1382 wined3d_device_set_cs_cb(device->wined3d_device, start_slot + i,
1383 buffer ? buffer->wined3d_buffer : NULL);
1385 wined3d_mutex_unlock();
1388 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1389 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1391 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1392 unsigned int i;
1394 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1395 iface, start_slot, buffer_count, buffers);
1397 wined3d_mutex_lock();
1398 for (i = 0; i < buffer_count; ++i)
1400 struct wined3d_buffer *wined3d_buffer;
1401 struct d3d_buffer *buffer_impl;
1403 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1405 buffers[i] = NULL;
1406 continue;
1409 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1410 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1411 ID3D11Buffer_AddRef(buffers[i]);
1413 wined3d_mutex_unlock();
1416 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1417 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1419 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1420 unsigned int i;
1422 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1423 iface, start_slot, view_count, views);
1425 wined3d_mutex_lock();
1426 for (i = 0; i < view_count; ++i)
1428 struct wined3d_shader_resource_view *wined3d_view;
1429 struct d3d_shader_resource_view *view_impl;
1431 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1433 views[i] = NULL;
1434 continue;
1437 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1438 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1439 ID3D11ShaderResourceView_AddRef(views[i]);
1441 wined3d_mutex_unlock();
1444 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1445 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1447 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1448 struct wined3d_shader *wined3d_shader;
1449 struct d3d_pixel_shader *shader_impl;
1451 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1452 iface, shader, class_instances, class_instance_count);
1454 if (class_instances || class_instance_count)
1455 FIXME("Dynamic linking not implemented yet.\n");
1457 wined3d_mutex_lock();
1458 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1460 wined3d_mutex_unlock();
1461 *shader = NULL;
1462 return;
1465 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1466 wined3d_mutex_unlock();
1467 *shader = &shader_impl->ID3D11PixelShader_iface;
1468 ID3D11PixelShader_AddRef(*shader);
1471 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1472 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1474 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1475 unsigned int i;
1477 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1478 iface, start_slot, sampler_count, samplers);
1480 wined3d_mutex_lock();
1481 for (i = 0; i < sampler_count; ++i)
1483 struct wined3d_sampler *wined3d_sampler;
1484 struct d3d_sampler_state *sampler_impl;
1486 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1488 samplers[i] = NULL;
1489 continue;
1492 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1493 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1494 ID3D11SamplerState_AddRef(samplers[i]);
1496 wined3d_mutex_unlock();
1499 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1500 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1502 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1503 struct d3d_vertex_shader *shader_impl;
1504 struct wined3d_shader *wined3d_shader;
1506 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1507 iface, shader, class_instances, class_instance_count);
1509 if (class_instances || class_instance_count)
1510 FIXME("Dynamic linking not implemented yet.\n");
1512 wined3d_mutex_lock();
1513 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1515 wined3d_mutex_unlock();
1516 *shader = NULL;
1517 return;
1520 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1521 wined3d_mutex_unlock();
1522 *shader = &shader_impl->ID3D11VertexShader_iface;
1523 ID3D11VertexShader_AddRef(*shader);
1526 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1527 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1529 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1530 unsigned int i;
1532 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1533 iface, start_slot, buffer_count, buffers);
1535 wined3d_mutex_lock();
1536 for (i = 0; i < buffer_count; ++i)
1538 struct wined3d_buffer *wined3d_buffer;
1539 struct d3d_buffer *buffer_impl;
1541 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1543 buffers[i] = NULL;
1544 continue;
1547 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1548 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1549 ID3D11Buffer_AddRef(buffers[i]);
1551 wined3d_mutex_unlock();
1554 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1555 ID3D11InputLayout **input_layout)
1557 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1558 struct wined3d_vertex_declaration *wined3d_declaration;
1559 struct d3d_input_layout *input_layout_impl;
1561 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1563 wined3d_mutex_lock();
1564 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1566 wined3d_mutex_unlock();
1567 *input_layout = NULL;
1568 return;
1571 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1572 wined3d_mutex_unlock();
1573 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1574 ID3D11InputLayout_AddRef(*input_layout);
1577 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1578 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1580 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1581 unsigned int i;
1583 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1584 iface, start_slot, buffer_count, buffers, strides, offsets);
1586 wined3d_mutex_lock();
1587 for (i = 0; i < buffer_count; ++i)
1589 struct wined3d_buffer *wined3d_buffer = NULL;
1590 struct d3d_buffer *buffer_impl;
1592 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1593 &wined3d_buffer, &offsets[i], &strides[i])))
1595 FIXME("Failed to get vertex buffer %u.\n", start_slot + i);
1596 if (strides)
1597 strides[i] = 0;
1598 if (offsets)
1599 offsets[i] = 0;
1602 if (!wined3d_buffer)
1604 buffers[i] = NULL;
1605 continue;
1608 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1609 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1611 wined3d_mutex_unlock();
1614 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1615 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1617 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1618 enum wined3d_format_id wined3d_format;
1619 struct wined3d_buffer *wined3d_buffer;
1620 struct d3d_buffer *buffer_impl;
1622 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1624 wined3d_mutex_lock();
1625 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1626 *format = dxgi_format_from_wined3dformat(wined3d_format);
1627 if (!wined3d_buffer)
1629 wined3d_mutex_unlock();
1630 *buffer = NULL;
1631 return;
1634 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1635 wined3d_mutex_unlock();
1636 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1639 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1640 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1642 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1643 unsigned int i;
1645 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1646 iface, start_slot, buffer_count, buffers);
1648 wined3d_mutex_lock();
1649 for (i = 0; i < buffer_count; ++i)
1651 struct wined3d_buffer *wined3d_buffer;
1652 struct d3d_buffer *buffer_impl;
1654 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1656 buffers[i] = NULL;
1657 continue;
1660 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1661 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1662 ID3D11Buffer_AddRef(buffers[i]);
1664 wined3d_mutex_unlock();
1667 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1668 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1670 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1671 struct d3d_geometry_shader *shader_impl;
1672 struct wined3d_shader *wined3d_shader;
1674 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1675 iface, shader, class_instances, class_instance_count);
1677 if (class_instances || class_instance_count)
1678 FIXME("Dynamic linking not implemented yet.\n");
1680 wined3d_mutex_lock();
1681 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1683 wined3d_mutex_unlock();
1684 *shader = NULL;
1685 return;
1688 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1689 wined3d_mutex_unlock();
1690 *shader = &shader_impl->ID3D11GeometryShader_iface;
1691 ID3D11GeometryShader_AddRef(*shader);
1694 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1695 D3D11_PRIMITIVE_TOPOLOGY *topology)
1697 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1699 TRACE("iface %p, topology %p.\n", iface, topology);
1701 wined3d_mutex_lock();
1702 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
1703 wined3d_mutex_unlock();
1706 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1707 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1709 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1710 unsigned int i;
1712 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1714 wined3d_mutex_lock();
1715 for (i = 0; i < view_count; ++i)
1717 struct wined3d_shader_resource_view *wined3d_view;
1718 struct d3d_shader_resource_view *view_impl;
1720 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1722 views[i] = NULL;
1723 continue;
1726 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1727 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1728 ID3D11ShaderResourceView_AddRef(views[i]);
1730 wined3d_mutex_unlock();
1733 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1734 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1736 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1737 unsigned int i;
1739 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1740 iface, start_slot, sampler_count, samplers);
1742 wined3d_mutex_lock();
1743 for (i = 0; i < sampler_count; ++i)
1745 struct wined3d_sampler *wined3d_sampler;
1746 struct d3d_sampler_state *sampler_impl;
1748 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1750 samplers[i] = NULL;
1751 continue;
1754 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1755 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1756 ID3D11SamplerState_AddRef(samplers[i]);
1758 wined3d_mutex_unlock();
1761 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1762 ID3D11Predicate **predicate, BOOL *value)
1764 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1765 struct wined3d_query *wined3d_predicate;
1766 struct d3d_query *predicate_impl;
1768 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1770 wined3d_mutex_lock();
1771 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1773 wined3d_mutex_unlock();
1774 *predicate = NULL;
1775 return;
1778 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1779 wined3d_mutex_unlock();
1780 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1781 ID3D11Predicate_AddRef(*predicate);
1784 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1785 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1787 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1788 unsigned int i;
1790 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1792 wined3d_mutex_lock();
1793 for (i = 0; i < view_count; ++i)
1795 struct wined3d_shader_resource_view *wined3d_view;
1796 struct d3d_shader_resource_view *view_impl;
1798 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1800 views[i] = NULL;
1801 continue;
1804 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1805 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1806 ID3D11ShaderResourceView_AddRef(views[i]);
1808 wined3d_mutex_unlock();
1811 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1812 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1814 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1815 unsigned int i;
1817 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1818 iface, start_slot, sampler_count, samplers);
1820 wined3d_mutex_lock();
1821 for (i = 0; i < sampler_count; ++i)
1823 struct d3d_sampler_state *sampler_impl;
1824 struct wined3d_sampler *wined3d_sampler;
1826 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1828 samplers[i] = NULL;
1829 continue;
1832 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1833 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1834 ID3D11SamplerState_AddRef(samplers[i]);
1836 wined3d_mutex_unlock();
1839 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1840 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1841 ID3D11DepthStencilView **depth_stencil_view)
1843 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1844 struct wined3d_rendertarget_view *wined3d_view;
1846 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1847 iface, render_target_view_count, render_target_views, depth_stencil_view);
1849 wined3d_mutex_lock();
1850 if (render_target_views)
1852 struct d3d_rendertarget_view *view_impl;
1853 unsigned int i;
1855 for (i = 0; i < render_target_view_count; ++i)
1857 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1858 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1860 render_target_views[i] = NULL;
1861 continue;
1864 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1865 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1869 if (depth_stencil_view)
1871 struct d3d_depthstencil_view *view_impl;
1873 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1874 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1876 *depth_stencil_view = NULL;
1878 else
1880 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1881 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1884 wined3d_mutex_unlock();
1887 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1888 ID3D11DeviceContext *iface,
1889 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1890 ID3D11DepthStencilView **depth_stencil_view,
1891 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1892 ID3D11UnorderedAccessView **unordered_access_views)
1894 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1895 struct wined3d_unordered_access_view *wined3d_view;
1896 struct d3d11_unordered_access_view *view_impl;
1897 unsigned int i;
1899 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1900 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1901 "unordered_access_views %p.\n",
1902 iface, render_target_view_count, render_target_views, depth_stencil_view,
1903 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1905 if (render_target_views || depth_stencil_view)
1906 d3d11_immediate_context_OMGetRenderTargets(iface, render_target_view_count,
1907 render_target_views, depth_stencil_view);
1909 if (unordered_access_views)
1911 wined3d_mutex_lock();
1912 for (i = 0; i < unordered_access_view_count; ++i)
1914 if (!(wined3d_view = wined3d_device_get_unordered_access_view(device->wined3d_device,
1915 unordered_access_view_start_slot + i)))
1917 unordered_access_views[i] = NULL;
1918 continue;
1921 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
1922 unordered_access_views[i] = &view_impl->ID3D11UnorderedAccessView_iface;
1923 ID3D11UnorderedAccessView_AddRef(unordered_access_views[i]);
1925 wined3d_mutex_unlock();
1929 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1930 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1932 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1934 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1935 iface, blend_state, blend_factor, sample_mask);
1937 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1938 ID3D11BlendState_AddRef(*blend_state);
1939 wined3d_mutex_lock();
1940 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1941 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1942 wined3d_mutex_unlock();
1945 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1946 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1948 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1950 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1951 iface, depth_stencil_state, stencil_ref);
1953 if ((*depth_stencil_state = device->depth_stencil_state
1954 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
1955 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
1956 *stencil_ref = device->stencil_ref;
1959 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1960 UINT buffer_count, ID3D11Buffer **buffers)
1962 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1963 unsigned int i;
1965 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1967 wined3d_mutex_lock();
1968 for (i = 0; i < buffer_count; ++i)
1970 struct wined3d_buffer *wined3d_buffer;
1971 struct d3d_buffer *buffer_impl;
1973 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1975 buffers[i] = NULL;
1976 continue;
1979 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1980 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1981 ID3D11Buffer_AddRef(buffers[i]);
1983 wined3d_mutex_unlock();
1986 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1987 ID3D11RasterizerState **rasterizer_state)
1989 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1990 struct d3d_rasterizer_state *rasterizer_state_impl;
1991 struct wined3d_rasterizer_state *wined3d_state;
1993 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1995 wined3d_mutex_lock();
1996 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
1998 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
1999 ID3D11RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D11RasterizerState_iface);
2001 else
2003 *rasterizer_state = NULL;
2005 wined3d_mutex_unlock();
2008 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
2009 UINT *viewport_count, D3D11_VIEWPORT *viewports)
2011 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2012 struct wined3d_viewport wined3d_vp;
2014 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
2016 if (!viewports)
2018 *viewport_count = 1;
2019 return;
2022 if (!*viewport_count)
2023 return;
2025 wined3d_mutex_lock();
2026 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
2027 wined3d_mutex_unlock();
2029 viewports[0].TopLeftX = wined3d_vp.x;
2030 viewports[0].TopLeftY = wined3d_vp.y;
2031 viewports[0].Width = wined3d_vp.width;
2032 viewports[0].Height = wined3d_vp.height;
2033 viewports[0].MinDepth = wined3d_vp.min_z;
2034 viewports[0].MaxDepth = wined3d_vp.max_z;
2036 if (*viewport_count > 1)
2037 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
2040 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
2041 UINT *rect_count, D3D11_RECT *rects)
2043 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2045 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
2047 if (!rects)
2049 *rect_count = 1;
2050 return;
2053 if (!*rect_count)
2054 return;
2056 wined3d_mutex_lock();
2057 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
2058 wined3d_mutex_unlock();
2059 if (*rect_count > 1)
2060 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
2063 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
2064 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2066 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2067 unsigned int i;
2069 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2071 wined3d_mutex_lock();
2072 for (i = 0; i < view_count; ++i)
2074 struct wined3d_shader_resource_view *wined3d_view;
2075 struct d3d_shader_resource_view *view_impl;
2077 if (!(wined3d_view = wined3d_device_get_hs_resource_view(device->wined3d_device, start_slot + i)))
2079 views[i] = NULL;
2080 continue;
2083 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2084 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2086 wined3d_mutex_unlock();
2089 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
2090 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2092 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2093 struct d3d11_hull_shader *shader_impl;
2094 struct wined3d_shader *wined3d_shader;
2096 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2097 iface, shader, class_instances, class_instance_count);
2099 if (class_instances || class_instance_count)
2100 FIXME("Dynamic linking not implemented yet.\n");
2102 wined3d_mutex_lock();
2103 if (!(wined3d_shader = wined3d_device_get_hull_shader(device->wined3d_device)))
2105 wined3d_mutex_unlock();
2106 *shader = NULL;
2107 return;
2110 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2111 wined3d_mutex_unlock();
2112 ID3D11HullShader_AddRef(*shader = &shader_impl->ID3D11HullShader_iface);
2115 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
2116 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2118 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2119 unsigned int i;
2121 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2122 iface, start_slot, sampler_count, samplers);
2124 wined3d_mutex_lock();
2125 for (i = 0; i < sampler_count; ++i)
2127 struct wined3d_sampler *wined3d_sampler;
2128 struct d3d_sampler_state *sampler_impl;
2130 if (!(wined3d_sampler = wined3d_device_get_hs_sampler(device->wined3d_device, start_slot + i)))
2132 samplers[i] = NULL;
2133 continue;
2136 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2137 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2139 wined3d_mutex_unlock();
2142 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
2143 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2145 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2146 unsigned int i;
2148 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2149 iface, start_slot, buffer_count, buffers);
2151 wined3d_mutex_lock();
2152 for (i = 0; i < buffer_count; ++i)
2154 struct wined3d_buffer *wined3d_buffer;
2155 struct d3d_buffer *buffer_impl;
2157 if (!(wined3d_buffer = wined3d_device_get_hs_cb(device->wined3d_device, start_slot + i)))
2159 buffers[i] = NULL;
2160 continue;
2163 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2164 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2166 wined3d_mutex_unlock();
2169 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
2170 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2172 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2173 unsigned int i;
2175 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2176 iface, start_slot, view_count, views);
2178 wined3d_mutex_lock();
2179 for (i = 0; i < view_count; ++i)
2181 struct wined3d_shader_resource_view *wined3d_view;
2182 struct d3d_shader_resource_view *view_impl;
2184 if (!(wined3d_view = wined3d_device_get_ds_resource_view(device->wined3d_device, start_slot + i)))
2186 views[i] = NULL;
2187 continue;
2190 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2191 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2193 wined3d_mutex_unlock();
2196 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
2197 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2199 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2200 struct d3d11_domain_shader *shader_impl;
2201 struct wined3d_shader *wined3d_shader;
2203 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2204 iface, shader, class_instances, class_instance_count);
2206 if (class_instances || class_instance_count)
2207 FIXME("Dynamic linking not implemented yet.\n");
2209 wined3d_mutex_lock();
2210 if (!(wined3d_shader = wined3d_device_get_domain_shader(device->wined3d_device)))
2212 wined3d_mutex_unlock();
2213 *shader = NULL;
2214 return;
2217 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2218 wined3d_mutex_unlock();
2219 ID3D11DomainShader_AddRef(*shader = &shader_impl->ID3D11DomainShader_iface);
2222 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
2223 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2225 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2226 unsigned int i;
2228 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2229 iface, start_slot, sampler_count, samplers);
2231 wined3d_mutex_lock();
2232 for (i = 0; i < sampler_count; ++i)
2234 struct wined3d_sampler *wined3d_sampler;
2235 struct d3d_sampler_state *sampler_impl;
2237 if (!(wined3d_sampler = wined3d_device_get_ds_sampler(device->wined3d_device, start_slot + i)))
2239 samplers[i] = NULL;
2240 continue;
2243 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2244 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2246 wined3d_mutex_unlock();
2249 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
2250 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2252 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2253 unsigned int i;
2255 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2256 iface, start_slot, buffer_count, buffers);
2258 wined3d_mutex_lock();
2259 for (i = 0; i < buffer_count; ++i)
2261 struct wined3d_buffer *wined3d_buffer;
2262 struct d3d_buffer *buffer_impl;
2264 if (!(wined3d_buffer = wined3d_device_get_ds_cb(device->wined3d_device, start_slot + i)))
2266 buffers[i] = NULL;
2267 continue;
2270 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2271 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2273 wined3d_mutex_unlock();
2276 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
2277 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
2279 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2280 unsigned int i;
2282 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2284 wined3d_mutex_lock();
2285 for (i = 0; i < view_count; ++i)
2287 struct wined3d_shader_resource_view *wined3d_view;
2288 struct d3d_shader_resource_view *view_impl;
2290 if (!(wined3d_view = wined3d_device_get_cs_resource_view(device->wined3d_device, start_slot + i)))
2292 views[i] = NULL;
2293 continue;
2296 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
2297 ID3D11ShaderResourceView_AddRef(views[i] = &view_impl->ID3D11ShaderResourceView_iface);
2299 wined3d_mutex_unlock();
2302 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
2303 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
2305 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2306 unsigned int i;
2308 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
2310 wined3d_mutex_lock();
2311 for (i = 0; i < view_count; ++i)
2313 struct wined3d_unordered_access_view *wined3d_view;
2314 struct d3d11_unordered_access_view *view_impl;
2316 if (!(wined3d_view = wined3d_device_get_cs_uav(device->wined3d_device, start_slot + i)))
2318 views[i] = NULL;
2319 continue;
2322 view_impl = wined3d_unordered_access_view_get_parent(wined3d_view);
2323 ID3D11UnorderedAccessView_AddRef(views[i] = &view_impl->ID3D11UnorderedAccessView_iface);
2325 wined3d_mutex_unlock();
2328 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
2329 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
2331 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2332 struct d3d11_compute_shader *shader_impl;
2333 struct wined3d_shader *wined3d_shader;
2335 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
2336 iface, shader, class_instances, class_instance_count);
2338 if (class_instances || class_instance_count)
2339 FIXME("Dynamic linking not implemented yet.\n");
2341 wined3d_mutex_lock();
2342 if (!(wined3d_shader = wined3d_device_get_compute_shader(device->wined3d_device)))
2344 wined3d_mutex_unlock();
2345 *shader = NULL;
2346 return;
2349 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2350 wined3d_mutex_unlock();
2351 ID3D11ComputeShader_AddRef(*shader = &shader_impl->ID3D11ComputeShader_iface);
2354 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
2355 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
2357 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2358 unsigned int i;
2360 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2361 iface, start_slot, sampler_count, samplers);
2363 wined3d_mutex_lock();
2364 for (i = 0; i < sampler_count; ++i)
2366 struct wined3d_sampler *wined3d_sampler;
2367 struct d3d_sampler_state *sampler_impl;
2369 if (!(wined3d_sampler = wined3d_device_get_cs_sampler(device->wined3d_device, start_slot + i)))
2371 samplers[i] = NULL;
2372 continue;
2375 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
2376 ID3D11SamplerState_AddRef(samplers[i] = &sampler_impl->ID3D11SamplerState_iface);
2378 wined3d_mutex_unlock();
2381 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
2382 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
2384 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2385 unsigned int i;
2387 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2388 iface, start_slot, buffer_count, buffers);
2390 wined3d_mutex_lock();
2391 for (i = 0; i < buffer_count; ++i)
2393 struct wined3d_buffer *wined3d_buffer;
2394 struct d3d_buffer *buffer_impl;
2396 if (!(wined3d_buffer = wined3d_device_get_cs_cb(device->wined3d_device, start_slot + i)))
2398 buffers[i] = NULL;
2399 continue;
2402 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2403 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
2405 wined3d_mutex_unlock();
2408 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
2410 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
2411 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2412 unsigned int i;
2414 TRACE("iface %p.\n", iface);
2416 wined3d_mutex_lock();
2417 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2418 wined3d_device_set_hull_shader(device->wined3d_device, NULL);
2419 wined3d_device_set_domain_shader(device->wined3d_device, NULL);
2420 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
2421 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2422 wined3d_device_set_compute_shader(device->wined3d_device, NULL);
2423 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2425 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
2426 wined3d_device_set_hs_sampler(device->wined3d_device, i, NULL);
2427 wined3d_device_set_ds_sampler(device->wined3d_device, i, NULL);
2428 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
2429 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
2430 wined3d_device_set_cs_sampler(device->wined3d_device, i, NULL);
2432 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2434 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
2435 wined3d_device_set_hs_resource_view(device->wined3d_device, i, NULL);
2436 wined3d_device_set_ds_resource_view(device->wined3d_device, i, NULL);
2437 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
2438 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
2439 wined3d_device_set_cs_resource_view(device->wined3d_device, i, NULL);
2441 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2443 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
2444 wined3d_device_set_hs_cb(device->wined3d_device, i, NULL);
2445 wined3d_device_set_ds_cb(device->wined3d_device, i, NULL);
2446 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
2447 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
2448 wined3d_device_set_cs_cb(device->wined3d_device, i, NULL);
2450 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2452 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
2454 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
2455 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
2456 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
2457 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2459 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
2461 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
2462 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
2464 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
2465 wined3d_device_set_cs_uav(device->wined3d_device, i, NULL);
2467 ID3D11DeviceContext_OMSetDepthStencilState(iface, NULL, 0);
2468 ID3D11DeviceContext_OMSetBlendState(iface, NULL, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
2469 ID3D11DeviceContext_RSSetViewports(iface, 0, NULL);
2470 ID3D11DeviceContext_RSSetScissorRects(iface, 0, NULL);
2471 ID3D11DeviceContext_RSSetState(iface, NULL);
2472 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
2474 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2476 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
2477 wined3d_mutex_unlock();
2480 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
2482 FIXME("iface %p stub!\n", iface);
2485 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
2487 TRACE("iface %p.\n", iface);
2489 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
2492 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
2494 FIXME("iface %p stub!\n", iface);
2496 return 0;
2499 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
2500 BOOL restore, ID3D11CommandList **command_list)
2502 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
2504 return E_NOTIMPL;
2507 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
2509 /* IUnknown methods */
2510 d3d11_immediate_context_QueryInterface,
2511 d3d11_immediate_context_AddRef,
2512 d3d11_immediate_context_Release,
2513 /* ID3D11DeviceChild methods */
2514 d3d11_immediate_context_GetDevice,
2515 d3d11_immediate_context_GetPrivateData,
2516 d3d11_immediate_context_SetPrivateData,
2517 d3d11_immediate_context_SetPrivateDataInterface,
2518 /* ID3D11DeviceContext methods */
2519 d3d11_immediate_context_VSSetConstantBuffers,
2520 d3d11_immediate_context_PSSetShaderResources,
2521 d3d11_immediate_context_PSSetShader,
2522 d3d11_immediate_context_PSSetSamplers,
2523 d3d11_immediate_context_VSSetShader,
2524 d3d11_immediate_context_DrawIndexed,
2525 d3d11_immediate_context_Draw,
2526 d3d11_immediate_context_Map,
2527 d3d11_immediate_context_Unmap,
2528 d3d11_immediate_context_PSSetConstantBuffers,
2529 d3d11_immediate_context_IASetInputLayout,
2530 d3d11_immediate_context_IASetVertexBuffers,
2531 d3d11_immediate_context_IASetIndexBuffer,
2532 d3d11_immediate_context_DrawIndexedInstanced,
2533 d3d11_immediate_context_DrawInstanced,
2534 d3d11_immediate_context_GSSetConstantBuffers,
2535 d3d11_immediate_context_GSSetShader,
2536 d3d11_immediate_context_IASetPrimitiveTopology,
2537 d3d11_immediate_context_VSSetShaderResources,
2538 d3d11_immediate_context_VSSetSamplers,
2539 d3d11_immediate_context_Begin,
2540 d3d11_immediate_context_End,
2541 d3d11_immediate_context_GetData,
2542 d3d11_immediate_context_SetPredication,
2543 d3d11_immediate_context_GSSetShaderResources,
2544 d3d11_immediate_context_GSSetSamplers,
2545 d3d11_immediate_context_OMSetRenderTargets,
2546 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2547 d3d11_immediate_context_OMSetBlendState,
2548 d3d11_immediate_context_OMSetDepthStencilState,
2549 d3d11_immediate_context_SOSetTargets,
2550 d3d11_immediate_context_DrawAuto,
2551 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2552 d3d11_immediate_context_DrawInstancedIndirect,
2553 d3d11_immediate_context_Dispatch,
2554 d3d11_immediate_context_DispatchIndirect,
2555 d3d11_immediate_context_RSSetState,
2556 d3d11_immediate_context_RSSetViewports,
2557 d3d11_immediate_context_RSSetScissorRects,
2558 d3d11_immediate_context_CopySubresourceRegion,
2559 d3d11_immediate_context_CopyResource,
2560 d3d11_immediate_context_UpdateSubresource,
2561 d3d11_immediate_context_CopyStructureCount,
2562 d3d11_immediate_context_ClearRenderTargetView,
2563 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2564 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2565 d3d11_immediate_context_ClearDepthStencilView,
2566 d3d11_immediate_context_GenerateMips,
2567 d3d11_immediate_context_SetResourceMinLOD,
2568 d3d11_immediate_context_GetResourceMinLOD,
2569 d3d11_immediate_context_ResolveSubresource,
2570 d3d11_immediate_context_ExecuteCommandList,
2571 d3d11_immediate_context_HSSetShaderResources,
2572 d3d11_immediate_context_HSSetShader,
2573 d3d11_immediate_context_HSSetSamplers,
2574 d3d11_immediate_context_HSSetConstantBuffers,
2575 d3d11_immediate_context_DSSetShaderResources,
2576 d3d11_immediate_context_DSSetShader,
2577 d3d11_immediate_context_DSSetSamplers,
2578 d3d11_immediate_context_DSSetConstantBuffers,
2579 d3d11_immediate_context_CSSetShaderResources,
2580 d3d11_immediate_context_CSSetUnorderedAccessViews,
2581 d3d11_immediate_context_CSSetShader,
2582 d3d11_immediate_context_CSSetSamplers,
2583 d3d11_immediate_context_CSSetConstantBuffers,
2584 d3d11_immediate_context_VSGetConstantBuffers,
2585 d3d11_immediate_context_PSGetShaderResources,
2586 d3d11_immediate_context_PSGetShader,
2587 d3d11_immediate_context_PSGetSamplers,
2588 d3d11_immediate_context_VSGetShader,
2589 d3d11_immediate_context_PSGetConstantBuffers,
2590 d3d11_immediate_context_IAGetInputLayout,
2591 d3d11_immediate_context_IAGetVertexBuffers,
2592 d3d11_immediate_context_IAGetIndexBuffer,
2593 d3d11_immediate_context_GSGetConstantBuffers,
2594 d3d11_immediate_context_GSGetShader,
2595 d3d11_immediate_context_IAGetPrimitiveTopology,
2596 d3d11_immediate_context_VSGetShaderResources,
2597 d3d11_immediate_context_VSGetSamplers,
2598 d3d11_immediate_context_GetPredication,
2599 d3d11_immediate_context_GSGetShaderResources,
2600 d3d11_immediate_context_GSGetSamplers,
2601 d3d11_immediate_context_OMGetRenderTargets,
2602 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2603 d3d11_immediate_context_OMGetBlendState,
2604 d3d11_immediate_context_OMGetDepthStencilState,
2605 d3d11_immediate_context_SOGetTargets,
2606 d3d11_immediate_context_RSGetState,
2607 d3d11_immediate_context_RSGetViewports,
2608 d3d11_immediate_context_RSGetScissorRects,
2609 d3d11_immediate_context_HSGetShaderResources,
2610 d3d11_immediate_context_HSGetShader,
2611 d3d11_immediate_context_HSGetSamplers,
2612 d3d11_immediate_context_HSGetConstantBuffers,
2613 d3d11_immediate_context_DSGetShaderResources,
2614 d3d11_immediate_context_DSGetShader,
2615 d3d11_immediate_context_DSGetSamplers,
2616 d3d11_immediate_context_DSGetConstantBuffers,
2617 d3d11_immediate_context_CSGetShaderResources,
2618 d3d11_immediate_context_CSGetUnorderedAccessViews,
2619 d3d11_immediate_context_CSGetShader,
2620 d3d11_immediate_context_CSGetSamplers,
2621 d3d11_immediate_context_CSGetConstantBuffers,
2622 d3d11_immediate_context_ClearState,
2623 d3d11_immediate_context_Flush,
2624 d3d11_immediate_context_GetType,
2625 d3d11_immediate_context_GetContextFlags,
2626 d3d11_immediate_context_FinishCommandList,
2629 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2631 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2632 context->refcount = 1;
2634 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2636 wined3d_private_store_init(&context->private_store);
2639 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2641 wined3d_private_store_cleanup(&context->private_store);
2644 /* ID3D11Device methods */
2646 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2648 struct d3d_device *device = impl_from_ID3D11Device(iface);
2649 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2652 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2654 struct d3d_device *device = impl_from_ID3D11Device(iface);
2655 return IUnknown_AddRef(device->outer_unk);
2658 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2660 struct d3d_device *device = impl_from_ID3D11Device(iface);
2661 return IUnknown_Release(device->outer_unk);
2664 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2665 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2667 struct d3d_device *device = impl_from_ID3D11Device(iface);
2668 struct d3d_buffer *object;
2669 HRESULT hr;
2671 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2673 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2674 return hr;
2676 *buffer = &object->ID3D11Buffer_iface;
2678 return S_OK;
2681 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2682 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2684 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2686 return E_NOTIMPL;
2689 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2690 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2692 struct d3d_device *device = impl_from_ID3D11Device(iface);
2693 struct d3d_texture2d *object;
2694 HRESULT hr;
2696 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2698 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2699 return hr;
2701 *texture = &object->ID3D11Texture2D_iface;
2703 return S_OK;
2706 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2707 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2709 struct d3d_device *device = impl_from_ID3D11Device(iface);
2710 struct d3d_texture3d *object;
2711 HRESULT hr;
2713 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2715 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2716 return hr;
2718 *texture = &object->ID3D11Texture3D_iface;
2720 return S_OK;
2723 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2724 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2726 struct d3d_device *device = impl_from_ID3D11Device(iface);
2727 struct d3d_shader_resource_view *object;
2728 HRESULT hr;
2730 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2732 if (!resource)
2733 return E_INVALIDARG;
2735 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2736 return hr;
2738 *view = &object->ID3D11ShaderResourceView_iface;
2740 return S_OK;
2743 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2744 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2746 struct d3d_device *device = impl_from_ID3D11Device(iface);
2747 struct d3d11_unordered_access_view *object;
2748 HRESULT hr;
2750 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2752 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2753 return hr;
2755 *view = &object->ID3D11UnorderedAccessView_iface;
2757 return S_OK;
2760 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2761 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2763 struct d3d_device *device = impl_from_ID3D11Device(iface);
2764 struct d3d_rendertarget_view *object;
2765 HRESULT hr;
2767 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2769 if (!resource)
2770 return E_INVALIDARG;
2772 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2773 return hr;
2775 *view = &object->ID3D11RenderTargetView_iface;
2777 return S_OK;
2780 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2781 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2783 struct d3d_device *device = impl_from_ID3D11Device(iface);
2784 struct d3d_depthstencil_view *object;
2785 HRESULT hr;
2787 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2789 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2790 return hr;
2792 *view = &object->ID3D11DepthStencilView_iface;
2794 return S_OK;
2797 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2798 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2799 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2801 struct d3d_device *device = impl_from_ID3D11Device(iface);
2802 struct d3d_input_layout *object;
2803 HRESULT hr;
2805 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2806 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2807 shader_byte_code_length, input_layout);
2809 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2810 shader_byte_code, shader_byte_code_length, &object)))
2811 return hr;
2813 *input_layout = &object->ID3D11InputLayout_iface;
2815 return S_OK;
2818 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2819 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2821 struct d3d_device *device = impl_from_ID3D11Device(iface);
2822 struct d3d_vertex_shader *object;
2823 HRESULT hr;
2825 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2826 iface, byte_code, byte_code_length, class_linkage, shader);
2828 if (class_linkage)
2829 FIXME("Class linkage is not implemented yet.\n");
2831 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2832 return hr;
2834 *shader = &object->ID3D11VertexShader_iface;
2836 return S_OK;
2839 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2840 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2842 struct d3d_device *device = impl_from_ID3D11Device(iface);
2843 struct d3d_geometry_shader *object;
2844 HRESULT hr;
2846 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2847 iface, byte_code, byte_code_length, class_linkage, shader);
2849 if (class_linkage)
2850 FIXME("Class linkage is not implemented yet.\n");
2852 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2853 NULL, 0, NULL, 0, 0, &object)))
2854 return hr;
2856 *shader = &object->ID3D11GeometryShader_iface;
2858 return S_OK;
2861 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2862 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2863 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterizer_stream,
2864 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2866 struct d3d_device *device = impl_from_ID3D11Device(iface);
2867 struct d3d_geometry_shader *object;
2868 HRESULT hr;
2870 TRACE("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2871 "buffer_strides %p, strides_count %u, rasterizer_stream %u, class_linkage %p, shader %p.\n",
2872 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2873 rasterizer_stream, class_linkage, shader);
2875 if (class_linkage)
2876 FIXME("Class linkage is not implemented yet.\n");
2878 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
2879 so_entries, entry_count, buffer_strides, strides_count, rasterizer_stream, &object)))
2881 *shader = NULL;
2882 return hr;
2885 *shader = &object->ID3D11GeometryShader_iface;
2887 return hr;
2890 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2891 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2893 struct d3d_device *device = impl_from_ID3D11Device(iface);
2894 struct d3d_pixel_shader *object;
2895 HRESULT hr;
2897 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2898 iface, byte_code, byte_code_length, class_linkage, shader);
2900 if (class_linkage)
2901 FIXME("Class linkage is not implemented yet.\n");
2903 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2904 return hr;
2906 *shader = &object->ID3D11PixelShader_iface;
2908 return S_OK;
2911 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2912 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2914 struct d3d_device *device = impl_from_ID3D11Device(iface);
2915 struct d3d11_hull_shader *object;
2916 HRESULT hr;
2918 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2919 iface, byte_code, byte_code_length, class_linkage, shader);
2921 if (class_linkage)
2922 FIXME("Class linkage is not implemented yet.\n");
2924 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2925 return hr;
2927 *shader = &object->ID3D11HullShader_iface;
2929 return S_OK;
2932 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2933 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2935 struct d3d_device *device = impl_from_ID3D11Device(iface);
2936 struct d3d11_domain_shader *object;
2937 HRESULT hr;
2939 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2940 iface, byte_code, byte_code_length, class_linkage, shader);
2942 if (class_linkage)
2943 FIXME("Class linkage is not implemented yet.\n");
2945 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2946 return hr;
2948 *shader = &object->ID3D11DomainShader_iface;
2950 return S_OK;
2953 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2954 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2956 struct d3d_device *device = impl_from_ID3D11Device(iface);
2957 struct d3d11_compute_shader *object;
2958 HRESULT hr;
2960 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2961 iface, byte_code, byte_code_length, class_linkage, shader);
2963 if (class_linkage)
2964 FIXME("Class linkage is not implemented yet.\n");
2966 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
2967 return hr;
2969 *shader = &object->ID3D11ComputeShader_iface;
2971 return S_OK;
2974 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2975 ID3D11ClassLinkage **class_linkage)
2977 struct d3d_device *device = impl_from_ID3D11Device(iface);
2978 struct d3d11_class_linkage *object;
2979 HRESULT hr;
2981 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
2983 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
2984 return hr;
2986 *class_linkage = &object->ID3D11ClassLinkage_iface;
2988 return S_OK;
2991 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
2992 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
2994 struct d3d_device *device = impl_from_ID3D11Device(iface);
2995 struct d3d_blend_state *object;
2996 struct wine_rb_entry *entry;
2997 D3D11_BLEND_DESC tmp_desc;
2998 unsigned int i, j;
2999 HRESULT hr;
3001 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
3003 if (!desc)
3004 return E_INVALIDARG;
3006 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
3007 * D3D11_BLEND_DESC as a key in the rbtree. */
3008 memset(&tmp_desc, 0, sizeof(tmp_desc));
3009 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
3010 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
3011 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3013 j = desc->IndependentBlendEnable ? i : 0;
3014 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
3015 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
3016 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
3017 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
3018 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
3019 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
3020 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
3021 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
3023 if (i > 3 && tmp_desc.RenderTarget[i].RenderTargetWriteMask != D3D11_COLOR_WRITE_ENABLE_ALL)
3024 FIXME("Color mask %#x not supported for render target %u.\n",
3025 tmp_desc.RenderTarget[i].RenderTargetWriteMask, i);
3028 /* glSampleCoverage() */
3029 if (tmp_desc.AlphaToCoverageEnable)
3030 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", tmp_desc.AlphaToCoverageEnable);
3031 /* glEnableIndexedEXT(GL_BLEND, ...) */
3032 if (tmp_desc.IndependentBlendEnable)
3033 FIXME("Per-rendertarget blend not implemented.\n");
3035 wined3d_mutex_lock();
3036 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
3038 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
3040 TRACE("Returning existing blend state %p.\n", object);
3041 *blend_state = &object->ID3D11BlendState_iface;
3042 ID3D11BlendState_AddRef(*blend_state);
3043 wined3d_mutex_unlock();
3045 return S_OK;
3047 wined3d_mutex_unlock();
3049 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3050 return E_OUTOFMEMORY;
3052 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
3054 WARN("Failed to initialize blend state, hr %#x.\n", hr);
3055 HeapFree(GetProcessHeap(), 0, object);
3056 return hr;
3059 TRACE("Created blend state %p.\n", object);
3060 *blend_state = &object->ID3D11BlendState_iface;
3062 return S_OK;
3065 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
3066 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
3068 struct d3d_device *device = impl_from_ID3D11Device(iface);
3069 struct d3d_depthstencil_state *object;
3070 D3D11_DEPTH_STENCIL_DESC tmp_desc;
3071 struct wine_rb_entry *entry;
3072 HRESULT hr;
3074 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
3076 if (!desc)
3077 return E_INVALIDARG;
3079 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
3080 * it as a key in the rbtree. */
3081 memset(&tmp_desc, 0, sizeof(tmp_desc));
3082 tmp_desc.DepthEnable = desc->DepthEnable;
3083 if (desc->DepthEnable)
3085 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
3086 tmp_desc.DepthFunc = desc->DepthFunc;
3088 else
3090 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
3091 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
3093 tmp_desc.StencilEnable = desc->StencilEnable;
3094 if (desc->StencilEnable)
3096 tmp_desc.StencilReadMask = desc->StencilReadMask;
3097 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
3098 tmp_desc.FrontFace = desc->FrontFace;
3099 tmp_desc.BackFace = desc->BackFace;
3101 else
3103 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
3104 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
3105 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3106 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3107 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3108 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3109 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
3110 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
3111 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
3112 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
3115 wined3d_mutex_lock();
3116 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
3118 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
3120 TRACE("Returning existing depthstencil state %p.\n", object);
3121 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3122 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
3123 wined3d_mutex_unlock();
3125 return S_OK;
3127 wined3d_mutex_unlock();
3129 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3130 return E_OUTOFMEMORY;
3132 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
3134 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
3135 HeapFree(GetProcessHeap(), 0, object);
3136 return hr;
3139 TRACE("Created depthstencil state %p.\n", object);
3140 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
3142 return S_OK;
3145 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
3146 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
3148 struct d3d_device *device = impl_from_ID3D11Device(iface);
3149 struct d3d_rasterizer_state *object;
3150 struct wine_rb_entry *entry;
3151 HRESULT hr;
3153 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
3155 if (!desc)
3156 return E_INVALIDARG;
3158 wined3d_mutex_lock();
3159 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
3161 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
3163 TRACE("Returning existing rasterizer state %p.\n", object);
3164 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3165 ID3D11RasterizerState_AddRef(*rasterizer_state);
3166 wined3d_mutex_unlock();
3168 return S_OK;
3170 wined3d_mutex_unlock();
3172 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3173 return E_OUTOFMEMORY;
3175 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
3177 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
3178 HeapFree(GetProcessHeap(), 0, object);
3179 return hr;
3182 TRACE("Created rasterizer state %p.\n", object);
3183 *rasterizer_state = &object->ID3D11RasterizerState_iface;
3185 return S_OK;
3188 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
3189 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
3191 struct d3d_device *device = impl_from_ID3D11Device(iface);
3192 D3D11_SAMPLER_DESC normalized_desc;
3193 struct d3d_sampler_state *object;
3194 struct wine_rb_entry *entry;
3195 HRESULT hr;
3197 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
3199 if (!desc)
3200 return E_INVALIDARG;
3202 normalized_desc = *desc;
3203 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
3204 normalized_desc.MaxAnisotropy = 0;
3205 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
3206 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
3207 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
3208 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
3209 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
3210 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
3212 wined3d_mutex_lock();
3213 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
3215 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
3217 TRACE("Returning existing sampler state %p.\n", object);
3218 *sampler_state = &object->ID3D11SamplerState_iface;
3219 ID3D11SamplerState_AddRef(*sampler_state);
3220 wined3d_mutex_unlock();
3222 return S_OK;
3224 wined3d_mutex_unlock();
3226 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
3227 return E_OUTOFMEMORY;
3229 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
3231 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
3232 HeapFree(GetProcessHeap(), 0, object);
3233 return hr;
3236 TRACE("Created sampler state %p.\n", object);
3237 *sampler_state = &object->ID3D11SamplerState_iface;
3239 return S_OK;
3242 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
3243 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
3245 struct d3d_device *device = impl_from_ID3D11Device(iface);
3246 struct d3d_query *object;
3247 HRESULT hr;
3249 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
3251 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
3252 return hr;
3254 if (query)
3256 *query = &object->ID3D11Query_iface;
3257 return S_OK;
3260 ID3D11Query_Release(&object->ID3D11Query_iface);
3261 return S_FALSE;
3264 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
3265 ID3D11Predicate **predicate)
3267 struct d3d_device *device = impl_from_ID3D11Device(iface);
3268 struct d3d_query *object;
3269 HRESULT hr;
3271 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
3273 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
3274 return hr;
3276 if (predicate)
3278 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
3279 return S_OK;
3282 ID3D11Query_Release(&object->ID3D11Query_iface);
3283 return S_FALSE;
3286 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3287 ID3D11Counter **counter)
3289 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
3291 return E_NOTIMPL;
3294 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
3295 ID3D11DeviceContext **context)
3297 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
3299 return E_NOTIMPL;
3302 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
3303 void **out)
3305 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
3307 return E_NOTIMPL;
3310 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
3311 UINT *format_support)
3313 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
3315 return E_NOTIMPL;
3318 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
3319 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
3321 struct d3d_device *device = impl_from_ID3D11Device(iface);
3322 struct wined3d_device_creation_parameters params;
3323 struct wined3d *wined3d;
3324 HRESULT hr;
3326 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
3327 iface, debug_dxgi_format(format), sample_count, quality_level_count);
3329 if (!quality_level_count)
3330 return E_INVALIDARG;
3332 *quality_level_count = 0;
3334 if (!sample_count)
3335 return E_FAIL;
3336 if (sample_count == 1)
3338 *quality_level_count = 1;
3339 return S_OK;
3341 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
3342 return E_FAIL;
3344 wined3d_mutex_lock();
3345 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
3346 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
3347 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
3348 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
3349 wined3d_mutex_unlock();
3351 if (hr == WINED3DERR_INVALIDCALL)
3352 return E_INVALIDARG;
3353 if (hr == WINED3DERR_NOTAVAILABLE)
3354 return S_OK;
3355 return hr;
3358 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
3360 FIXME("iface %p, info %p stub!\n", iface, info);
3363 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
3364 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
3365 char *units, UINT *units_length, char *description, UINT *description_length)
3367 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
3368 "units %p, units_length %p, description %p, description_length %p stub!\n",
3369 iface, desc, type, active_counter_count, name, name_length,
3370 units, units_length, description, description_length);
3372 return E_NOTIMPL;
3375 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
3376 void *feature_support_data, UINT feature_support_data_size)
3378 struct d3d_device *device = impl_from_ID3D11Device(iface);
3379 WINED3DCAPS wined3d_caps;
3380 HRESULT hr;
3382 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
3383 iface, feature, feature_support_data, feature_support_data_size);
3385 switch (feature)
3387 case D3D11_FEATURE_THREADING:
3389 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
3390 if (feature_support_data_size != sizeof(*threading_data))
3392 WARN("Invalid data size.\n");
3393 return E_INVALIDARG;
3396 /* We lie about the threading support to make Tomb Raider 2013 and
3397 * Deus Ex: Human Revolution happy. */
3398 FIXME("Returning fake threading support data.\n");
3399 threading_data->DriverConcurrentCreates = TRUE;
3400 threading_data->DriverCommandLists = TRUE;
3401 return S_OK;
3404 case D3D11_FEATURE_DOUBLES:
3406 D3D11_FEATURE_DATA_DOUBLES *doubles_data = feature_support_data;
3407 if (feature_support_data_size != sizeof(*doubles_data))
3409 WARN("Invalid data size.\n");
3410 return E_INVALIDARG;
3413 wined3d_mutex_lock();
3414 hr = wined3d_device_get_device_caps(device->wined3d_device, &wined3d_caps);
3415 wined3d_mutex_unlock();
3416 if (FAILED(hr))
3418 WARN("Failed to get device caps, hr %#x.\n", hr);
3419 return hr;
3422 doubles_data->DoublePrecisionFloatShaderOps = wined3d_caps.shader_double_precision;
3423 return S_OK;
3426 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
3428 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
3429 if (feature_support_data_size != sizeof(*options))
3431 WARN("Invalid data size.\n");
3432 return E_INVALIDARG;
3435 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
3436 return S_OK;
3439 default:
3440 FIXME("Unhandled feature %#x.\n", feature);
3441 return E_NOTIMPL;
3445 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
3446 UINT *data_size, void *data)
3448 IDXGIDevice *dxgi_device;
3449 HRESULT hr;
3451 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3453 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3454 return hr;
3455 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
3456 IDXGIDevice_Release(dxgi_device);
3458 return hr;
3461 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
3462 UINT data_size, const void *data)
3464 IDXGIDevice *dxgi_device;
3465 HRESULT hr;
3467 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
3469 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3470 return hr;
3471 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
3472 IDXGIDevice_Release(dxgi_device);
3474 return hr;
3477 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
3478 const IUnknown *data)
3480 IDXGIDevice *dxgi_device;
3481 HRESULT hr;
3483 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
3485 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
3486 return hr;
3487 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
3488 IDXGIDevice_Release(dxgi_device);
3490 return hr;
3493 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
3495 struct d3d_device *device = impl_from_ID3D11Device(iface);
3497 TRACE("iface %p.\n", iface);
3499 return device->feature_level;
3502 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
3504 FIXME("iface %p stub!\n", iface);
3506 return 0;
3509 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
3511 FIXME("iface %p stub!\n", iface);
3513 return S_OK;
3516 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
3517 ID3D11DeviceContext **immediate_context)
3519 struct d3d_device *device = impl_from_ID3D11Device(iface);
3521 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
3523 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
3524 ID3D11DeviceContext_AddRef(*immediate_context);
3527 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
3529 FIXME("iface %p, flags %#x stub!\n", iface, flags);
3531 return E_NOTIMPL;
3534 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
3536 FIXME("iface %p stub!\n", iface);
3538 return 0;
3541 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
3543 /* IUnknown methods */
3544 d3d11_device_QueryInterface,
3545 d3d11_device_AddRef,
3546 d3d11_device_Release,
3547 /* ID3D11Device methods */
3548 d3d11_device_CreateBuffer,
3549 d3d11_device_CreateTexture1D,
3550 d3d11_device_CreateTexture2D,
3551 d3d11_device_CreateTexture3D,
3552 d3d11_device_CreateShaderResourceView,
3553 d3d11_device_CreateUnorderedAccessView,
3554 d3d11_device_CreateRenderTargetView,
3555 d3d11_device_CreateDepthStencilView,
3556 d3d11_device_CreateInputLayout,
3557 d3d11_device_CreateVertexShader,
3558 d3d11_device_CreateGeometryShader,
3559 d3d11_device_CreateGeometryShaderWithStreamOutput,
3560 d3d11_device_CreatePixelShader,
3561 d3d11_device_CreateHullShader,
3562 d3d11_device_CreateDomainShader,
3563 d3d11_device_CreateComputeShader,
3564 d3d11_device_CreateClassLinkage,
3565 d3d11_device_CreateBlendState,
3566 d3d11_device_CreateDepthStencilState,
3567 d3d11_device_CreateRasterizerState,
3568 d3d11_device_CreateSamplerState,
3569 d3d11_device_CreateQuery,
3570 d3d11_device_CreatePredicate,
3571 d3d11_device_CreateCounter,
3572 d3d11_device_CreateDeferredContext,
3573 d3d11_device_OpenSharedResource,
3574 d3d11_device_CheckFormatSupport,
3575 d3d11_device_CheckMultisampleQualityLevels,
3576 d3d11_device_CheckCounterInfo,
3577 d3d11_device_CheckCounter,
3578 d3d11_device_CheckFeatureSupport,
3579 d3d11_device_GetPrivateData,
3580 d3d11_device_SetPrivateData,
3581 d3d11_device_SetPrivateDataInterface,
3582 d3d11_device_GetFeatureLevel,
3583 d3d11_device_GetCreationFlags,
3584 d3d11_device_GetDeviceRemovedReason,
3585 d3d11_device_GetImmediateContext,
3586 d3d11_device_SetExceptionMode,
3587 d3d11_device_GetExceptionMode,
3590 /* Inner IUnknown methods */
3592 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
3594 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
3597 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3599 struct d3d_device *device = impl_from_IUnknown(iface);
3601 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
3603 if (IsEqualGUID(riid, &IID_ID3D11Device)
3604 || IsEqualGUID(riid, &IID_IUnknown))
3606 *out = &device->ID3D11Device_iface;
3608 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
3609 || IsEqualGUID(riid, &IID_ID3D10Device))
3611 *out = &device->ID3D10Device1_iface;
3613 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
3615 *out = &device->ID3D10Multithread_iface;
3617 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
3619 *out = &device->IWineDXGIDeviceParent_iface;
3621 else
3623 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
3624 *out = NULL;
3625 return E_NOINTERFACE;
3628 IUnknown_AddRef((IUnknown *)*out);
3629 return S_OK;
3632 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
3634 struct d3d_device *device = impl_from_IUnknown(iface);
3635 ULONG refcount = InterlockedIncrement(&device->refcount);
3637 TRACE("%p increasing refcount to %u.\n", device, refcount);
3639 return refcount;
3642 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
3644 struct d3d_device *device = impl_from_IUnknown(iface);
3645 ULONG refcount = InterlockedDecrement(&device->refcount);
3647 TRACE("%p decreasing refcount to %u.\n", device, refcount);
3649 if (!refcount)
3651 d3d11_immediate_context_destroy(&device->immediate_context);
3652 if (device->wined3d_device)
3654 wined3d_mutex_lock();
3655 wined3d_device_decref(device->wined3d_device);
3656 wined3d_mutex_unlock();
3658 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3659 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3660 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3661 wine_rb_destroy(&device->blend_states, NULL, NULL);
3664 return refcount;
3667 /* IUnknown methods */
3669 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3670 void **ppv)
3672 struct d3d_device *device = impl_from_ID3D10Device(iface);
3673 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3676 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3678 struct d3d_device *device = impl_from_ID3D10Device(iface);
3679 return IUnknown_AddRef(device->outer_unk);
3682 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3684 struct d3d_device *device = impl_from_ID3D10Device(iface);
3685 return IUnknown_Release(device->outer_unk);
3688 /* ID3D10Device methods */
3690 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3691 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3693 struct d3d_device *device = impl_from_ID3D10Device(iface);
3694 unsigned int i;
3696 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3697 iface, start_slot, buffer_count, buffers);
3699 wined3d_mutex_lock();
3700 for (i = 0; i < buffer_count; ++i)
3702 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3704 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3705 buffer ? buffer->wined3d_buffer : NULL);
3707 wined3d_mutex_unlock();
3710 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3711 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3713 struct d3d_device *device = impl_from_ID3D10Device(iface);
3714 unsigned int i;
3716 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3717 iface, start_slot, view_count, views);
3719 wined3d_mutex_lock();
3720 for (i = 0; i < view_count; ++i)
3722 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3724 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3725 view ? view->wined3d_view : NULL);
3727 wined3d_mutex_unlock();
3730 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3731 ID3D10PixelShader *shader)
3733 struct d3d_device *device = impl_from_ID3D10Device(iface);
3734 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3736 TRACE("iface %p, shader %p\n", iface, shader);
3738 wined3d_mutex_lock();
3739 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3740 wined3d_mutex_unlock();
3743 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3744 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3746 struct d3d_device *device = impl_from_ID3D10Device(iface);
3747 unsigned int i;
3749 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3750 iface, start_slot, sampler_count, samplers);
3752 wined3d_mutex_lock();
3753 for (i = 0; i < sampler_count; ++i)
3755 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3757 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3758 sampler ? sampler->wined3d_sampler : NULL);
3760 wined3d_mutex_unlock();
3763 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3764 ID3D10VertexShader *shader)
3766 struct d3d_device *device = impl_from_ID3D10Device(iface);
3767 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3769 TRACE("iface %p, shader %p\n", iface, shader);
3771 wined3d_mutex_lock();
3772 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3773 wined3d_mutex_unlock();
3776 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3777 UINT start_index_location, INT base_vertex_location)
3779 struct d3d_device *device = impl_from_ID3D10Device(iface);
3781 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3782 iface, index_count, start_index_location, base_vertex_location);
3784 wined3d_mutex_lock();
3785 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3786 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3787 wined3d_mutex_unlock();
3790 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3791 UINT start_vertex_location)
3793 struct d3d_device *device = impl_from_ID3D10Device(iface);
3795 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3796 iface, vertex_count, start_vertex_location);
3798 wined3d_mutex_lock();
3799 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3800 wined3d_mutex_unlock();
3803 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(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_ps_cb(device->wined3d_device, start_slot + i,
3818 buffer ? buffer->wined3d_buffer : NULL);
3820 wined3d_mutex_unlock();
3823 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3824 ID3D10InputLayout *input_layout)
3826 struct d3d_device *device = impl_from_ID3D10Device(iface);
3827 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3829 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3831 wined3d_mutex_lock();
3832 wined3d_device_set_vertex_declaration(device->wined3d_device,
3833 layout ? layout->wined3d_decl : NULL);
3834 wined3d_mutex_unlock();
3837 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3838 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3840 struct d3d_device *device = impl_from_ID3D10Device(iface);
3841 unsigned int i;
3843 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3844 iface, start_slot, buffer_count, buffers, strides, offsets);
3846 wined3d_mutex_lock();
3847 for (i = 0; i < buffer_count; ++i)
3849 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3851 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3852 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3854 wined3d_mutex_unlock();
3857 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3858 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3860 struct d3d_device *device = impl_from_ID3D10Device(iface);
3861 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3863 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3864 iface, buffer, debug_dxgi_format(format), offset);
3866 wined3d_mutex_lock();
3867 wined3d_device_set_index_buffer(device->wined3d_device,
3868 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3869 wined3dformat_from_dxgi_format(format), offset);
3870 wined3d_mutex_unlock();
3873 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3874 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3875 INT base_vertex_location, UINT start_instance_location)
3877 struct d3d_device *device = impl_from_ID3D10Device(iface);
3879 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3880 "base_vertex_location %d, start_instance_location %u.\n",
3881 iface, instance_index_count, instance_count, start_index_location,
3882 base_vertex_location, start_instance_location);
3884 wined3d_mutex_lock();
3885 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3886 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3887 instance_index_count, start_instance_location, instance_count);
3888 wined3d_mutex_unlock();
3891 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3892 UINT instance_vertex_count, UINT instance_count,
3893 UINT start_vertex_location, UINT start_instance_location)
3895 struct d3d_device *device = impl_from_ID3D10Device(iface);
3897 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3898 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3899 start_vertex_location, start_instance_location);
3901 wined3d_mutex_lock();
3902 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3903 instance_vertex_count, start_instance_location, instance_count);
3904 wined3d_mutex_unlock();
3907 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3908 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3910 struct d3d_device *device = impl_from_ID3D10Device(iface);
3911 unsigned int i;
3913 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3914 iface, start_slot, buffer_count, buffers);
3916 wined3d_mutex_lock();
3917 for (i = 0; i < buffer_count; ++i)
3919 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3921 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3922 buffer ? buffer->wined3d_buffer : NULL);
3924 wined3d_mutex_unlock();
3927 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3929 struct d3d_device *device = impl_from_ID3D10Device(iface);
3930 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3932 TRACE("iface %p, shader %p.\n", iface, shader);
3934 wined3d_mutex_lock();
3935 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3936 wined3d_mutex_unlock();
3939 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3940 D3D10_PRIMITIVE_TOPOLOGY topology)
3942 struct d3d_device *device = impl_from_ID3D10Device(iface);
3944 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
3946 wined3d_mutex_lock();
3947 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
3948 wined3d_mutex_unlock();
3951 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
3952 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3954 struct d3d_device *device = impl_from_ID3D10Device(iface);
3955 unsigned int i;
3957 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3958 iface, start_slot, view_count, views);
3960 wined3d_mutex_lock();
3961 for (i = 0; i < view_count; ++i)
3963 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3965 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
3966 view ? view->wined3d_view : NULL);
3968 wined3d_mutex_unlock();
3971 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
3972 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3974 struct d3d_device *device = impl_from_ID3D10Device(iface);
3975 unsigned int i;
3977 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3978 iface, start_slot, sampler_count, samplers);
3980 wined3d_mutex_lock();
3981 for (i = 0; i < sampler_count; ++i)
3983 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3985 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
3986 sampler ? sampler->wined3d_sampler : NULL);
3988 wined3d_mutex_unlock();
3991 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3993 struct d3d_device *device = impl_from_ID3D10Device(iface);
3994 struct d3d_query *query;
3996 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3998 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3999 wined3d_mutex_lock();
4000 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
4001 wined3d_mutex_unlock();
4004 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
4005 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
4007 struct d3d_device *device = impl_from_ID3D10Device(iface);
4008 unsigned int i;
4010 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4011 iface, start_slot, view_count, views);
4013 wined3d_mutex_lock();
4014 for (i = 0; i < view_count; ++i)
4016 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
4018 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
4019 view ? view->wined3d_view : NULL);
4021 wined3d_mutex_unlock();
4024 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
4025 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
4027 struct d3d_device *device = impl_from_ID3D10Device(iface);
4028 unsigned int i;
4030 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4031 iface, start_slot, sampler_count, samplers);
4033 wined3d_mutex_lock();
4034 for (i = 0; i < sampler_count; ++i)
4036 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
4038 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
4039 sampler ? sampler->wined3d_sampler : NULL);
4041 wined3d_mutex_unlock();
4044 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
4045 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
4046 ID3D10DepthStencilView *depth_stencil_view)
4048 struct d3d_device *device = impl_from_ID3D10Device(iface);
4049 struct d3d_depthstencil_view *dsv;
4050 unsigned int i;
4052 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4053 iface, render_target_view_count, render_target_views, depth_stencil_view);
4055 wined3d_mutex_lock();
4056 for (i = 0; i < render_target_view_count; ++i)
4058 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
4060 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
4061 rtv ? rtv->wined3d_view : NULL, FALSE);
4063 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4065 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4068 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4069 wined3d_device_set_depth_stencil_view(device->wined3d_device,
4070 dsv ? dsv->wined3d_view : NULL);
4071 wined3d_mutex_unlock();
4074 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
4075 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
4077 struct d3d_device *device = impl_from_ID3D10Device(iface);
4078 struct d3d_blend_state *blend_state_object;
4080 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
4081 iface, blend_state, debug_float4(blend_factor), sample_mask);
4083 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
4084 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4085 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
4088 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
4089 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
4091 struct d3d_device *device = impl_from_ID3D10Device(iface);
4092 struct d3d_depthstencil_state *ds_state_object;
4094 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
4095 iface, depth_stencil_state, stencil_ref);
4097 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
4098 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4099 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
4102 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
4103 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
4105 struct d3d_device *device = impl_from_ID3D10Device(iface);
4106 unsigned int count, i;
4108 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
4110 count = min(target_count, D3D10_SO_BUFFER_SLOT_COUNT);
4111 wined3d_mutex_lock();
4112 for (i = 0; i < count; ++i)
4114 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
4116 wined3d_device_set_stream_output(device->wined3d_device, i,
4117 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
4120 for (i = count; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4122 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4124 wined3d_mutex_unlock();
4127 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
4129 FIXME("iface %p stub!\n", iface);
4132 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
4134 struct d3d_device *device = impl_from_ID3D10Device(iface);
4135 struct d3d_rasterizer_state *rasterizer_state_object;
4137 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4139 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
4140 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
4141 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
4144 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
4145 UINT viewport_count, const D3D10_VIEWPORT *viewports)
4147 struct d3d_device *device = impl_from_ID3D10Device(iface);
4148 struct wined3d_viewport wined3d_vp;
4150 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
4152 if (viewport_count > 1)
4153 FIXME("Multiple viewports not implemented.\n");
4155 if (!viewport_count)
4156 return;
4158 wined3d_vp.x = viewports[0].TopLeftX;
4159 wined3d_vp.y = viewports[0].TopLeftY;
4160 wined3d_vp.width = viewports[0].Width;
4161 wined3d_vp.height = viewports[0].Height;
4162 wined3d_vp.min_z = viewports[0].MinDepth;
4163 wined3d_vp.max_z = viewports[0].MaxDepth;
4165 wined3d_mutex_lock();
4166 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
4167 wined3d_mutex_unlock();
4170 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
4171 UINT rect_count, const D3D10_RECT *rects)
4173 struct d3d_device *device = impl_from_ID3D10Device(iface);
4175 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
4177 if (rect_count > 1)
4178 FIXME("Multiple scissor rects not implemented.\n");
4180 if (!rect_count)
4181 return;
4183 wined3d_mutex_lock();
4184 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
4185 wined3d_mutex_unlock();
4188 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
4189 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
4190 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
4192 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4193 struct d3d_device *device = impl_from_ID3D10Device(iface);
4194 struct wined3d_box wined3d_src_box;
4196 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4197 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
4198 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
4199 src_resource, src_subresource_idx, src_box);
4201 if (src_box)
4202 wined3d_box_set(&wined3d_src_box, src_box->left, src_box->top,
4203 src_box->right, src_box->bottom, src_box->front, src_box->back);
4205 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4206 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4207 wined3d_mutex_lock();
4208 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
4209 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
4210 wined3d_mutex_unlock();
4213 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
4214 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
4216 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
4217 struct d3d_device *device = impl_from_ID3D10Device(iface);
4219 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
4221 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
4222 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
4223 wined3d_mutex_lock();
4224 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
4225 wined3d_mutex_unlock();
4228 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
4229 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
4230 const void *data, UINT row_pitch, UINT depth_pitch)
4232 struct d3d_device *device = impl_from_ID3D10Device(iface);
4233 ID3D11Resource *d3d11_resource;
4235 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
4236 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
4238 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
4239 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
4240 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
4241 ID3D11Resource_Release(d3d11_resource);
4244 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
4245 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
4247 struct d3d_device *device = impl_from_ID3D10Device(iface);
4248 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
4249 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
4250 HRESULT hr;
4252 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
4253 iface, render_target_view, debug_float4(color_rgba));
4255 if (!view)
4256 return;
4258 wined3d_mutex_lock();
4259 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4260 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
4261 ERR("Failed to clear view, hr %#x.\n", hr);
4262 wined3d_mutex_unlock();
4265 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
4266 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
4268 struct d3d_device *device = impl_from_ID3D10Device(iface);
4269 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
4270 DWORD wined3d_flags;
4271 HRESULT hr;
4273 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
4274 iface, depth_stencil_view, flags, depth, stencil);
4276 if (!view)
4277 return;
4279 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
4281 wined3d_mutex_lock();
4282 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
4283 wined3d_flags, NULL, depth, stencil)))
4284 ERR("Failed to clear view, hr %#x.\n", hr);
4285 wined3d_mutex_unlock();
4288 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
4289 ID3D10ShaderResourceView *shader_resource_view)
4291 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
4294 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
4295 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
4296 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
4298 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
4299 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
4300 iface, dst_resource, dst_subresource_idx,
4301 src_resource, src_subresource_idx, debug_dxgi_format(format));
4304 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
4305 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4307 struct d3d_device *device = impl_from_ID3D10Device(iface);
4308 unsigned int i;
4310 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4311 iface, start_slot, buffer_count, buffers);
4313 wined3d_mutex_lock();
4314 for (i = 0; i < buffer_count; ++i)
4316 struct wined3d_buffer *wined3d_buffer;
4317 struct d3d_buffer *buffer_impl;
4319 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
4321 buffers[i] = NULL;
4322 continue;
4325 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4326 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4327 ID3D10Buffer_AddRef(buffers[i]);
4329 wined3d_mutex_unlock();
4332 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
4333 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4335 struct d3d_device *device = impl_from_ID3D10Device(iface);
4336 unsigned int i;
4338 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4339 iface, start_slot, view_count, views);
4341 wined3d_mutex_lock();
4342 for (i = 0; i < view_count; ++i)
4344 struct wined3d_shader_resource_view *wined3d_view;
4345 struct d3d_shader_resource_view *view_impl;
4347 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
4349 views[i] = NULL;
4350 continue;
4353 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4354 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4355 ID3D10ShaderResourceView_AddRef(views[i]);
4357 wined3d_mutex_unlock();
4360 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
4362 struct d3d_device *device = impl_from_ID3D10Device(iface);
4363 struct d3d_pixel_shader *shader_impl;
4364 struct wined3d_shader *wined3d_shader;
4366 TRACE("iface %p, shader %p.\n", iface, shader);
4368 wined3d_mutex_lock();
4369 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
4371 wined3d_mutex_unlock();
4372 *shader = NULL;
4373 return;
4376 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4377 wined3d_mutex_unlock();
4378 *shader = &shader_impl->ID3D10PixelShader_iface;
4379 ID3D10PixelShader_AddRef(*shader);
4382 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
4383 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4385 struct d3d_device *device = impl_from_ID3D10Device(iface);
4386 unsigned int i;
4388 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4389 iface, start_slot, sampler_count, samplers);
4391 wined3d_mutex_lock();
4392 for (i = 0; i < sampler_count; ++i)
4394 struct d3d_sampler_state *sampler_impl;
4395 struct wined3d_sampler *wined3d_sampler;
4397 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
4399 samplers[i] = NULL;
4400 continue;
4403 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4404 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4405 ID3D10SamplerState_AddRef(samplers[i]);
4407 wined3d_mutex_unlock();
4410 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
4412 struct d3d_device *device = impl_from_ID3D10Device(iface);
4413 struct d3d_vertex_shader *shader_impl;
4414 struct wined3d_shader *wined3d_shader;
4416 TRACE("iface %p, shader %p.\n", iface, shader);
4418 wined3d_mutex_lock();
4419 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
4421 wined3d_mutex_unlock();
4422 *shader = NULL;
4423 return;
4426 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4427 wined3d_mutex_unlock();
4428 *shader = &shader_impl->ID3D10VertexShader_iface;
4429 ID3D10VertexShader_AddRef(*shader);
4432 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
4433 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4435 struct d3d_device *device = impl_from_ID3D10Device(iface);
4436 unsigned int i;
4438 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4439 iface, start_slot, buffer_count, buffers);
4441 wined3d_mutex_lock();
4442 for (i = 0; i < buffer_count; ++i)
4444 struct wined3d_buffer *wined3d_buffer;
4445 struct d3d_buffer *buffer_impl;
4447 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
4449 buffers[i] = NULL;
4450 continue;
4453 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4454 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4455 ID3D10Buffer_AddRef(buffers[i]);
4457 wined3d_mutex_unlock();
4460 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
4462 struct d3d_device *device = impl_from_ID3D10Device(iface);
4463 struct wined3d_vertex_declaration *wined3d_declaration;
4464 struct d3d_input_layout *input_layout_impl;
4466 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
4468 wined3d_mutex_lock();
4469 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
4471 wined3d_mutex_unlock();
4472 *input_layout = NULL;
4473 return;
4476 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
4477 wined3d_mutex_unlock();
4478 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
4479 ID3D10InputLayout_AddRef(*input_layout);
4482 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
4483 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
4485 struct d3d_device *device = impl_from_ID3D10Device(iface);
4486 unsigned int i;
4488 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
4489 iface, start_slot, buffer_count, buffers, strides, offsets);
4491 wined3d_mutex_lock();
4492 for (i = 0; i < buffer_count; ++i)
4494 struct wined3d_buffer *wined3d_buffer = NULL;
4495 struct d3d_buffer *buffer_impl;
4497 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
4498 &wined3d_buffer, &offsets[i], &strides[i])))
4499 ERR("Failed to get vertex buffer.\n");
4501 if (!wined3d_buffer)
4503 buffers[i] = NULL;
4504 continue;
4507 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4508 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4509 ID3D10Buffer_AddRef(buffers[i]);
4511 wined3d_mutex_unlock();
4514 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
4515 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
4517 struct d3d_device *device = impl_from_ID3D10Device(iface);
4518 enum wined3d_format_id wined3d_format;
4519 struct wined3d_buffer *wined3d_buffer;
4520 struct d3d_buffer *buffer_impl;
4522 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
4524 wined3d_mutex_lock();
4525 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
4526 *format = dxgi_format_from_wined3dformat(wined3d_format);
4527 if (!wined3d_buffer)
4529 wined3d_mutex_unlock();
4530 *buffer = NULL;
4531 return;
4534 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4535 wined3d_mutex_unlock();
4536 *buffer = &buffer_impl->ID3D10Buffer_iface;
4537 ID3D10Buffer_AddRef(*buffer);
4540 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
4541 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
4543 struct d3d_device *device = impl_from_ID3D10Device(iface);
4544 unsigned int i;
4546 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
4547 iface, start_slot, buffer_count, buffers);
4549 wined3d_mutex_lock();
4550 for (i = 0; i < buffer_count; ++i)
4552 struct wined3d_buffer *wined3d_buffer;
4553 struct d3d_buffer *buffer_impl;
4555 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
4557 buffers[i] = NULL;
4558 continue;
4561 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4562 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4563 ID3D10Buffer_AddRef(buffers[i]);
4565 wined3d_mutex_unlock();
4568 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
4570 struct d3d_device *device = impl_from_ID3D10Device(iface);
4571 struct d3d_geometry_shader *shader_impl;
4572 struct wined3d_shader *wined3d_shader;
4574 TRACE("iface %p, shader %p.\n", iface, shader);
4576 wined3d_mutex_lock();
4577 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
4579 wined3d_mutex_unlock();
4580 *shader = NULL;
4581 return;
4584 shader_impl = wined3d_shader_get_parent(wined3d_shader);
4585 wined3d_mutex_unlock();
4586 *shader = &shader_impl->ID3D10GeometryShader_iface;
4587 ID3D10GeometryShader_AddRef(*shader);
4590 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
4591 D3D10_PRIMITIVE_TOPOLOGY *topology)
4593 struct d3d_device *device = impl_from_ID3D10Device(iface);
4595 TRACE("iface %p, topology %p\n", iface, topology);
4597 wined3d_mutex_lock();
4598 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
4599 wined3d_mutex_unlock();
4602 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
4603 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4605 struct d3d_device *device = impl_from_ID3D10Device(iface);
4606 unsigned int i;
4608 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4609 iface, start_slot, view_count, views);
4611 wined3d_mutex_lock();
4612 for (i = 0; i < view_count; ++i)
4614 struct wined3d_shader_resource_view *wined3d_view;
4615 struct d3d_shader_resource_view *view_impl;
4617 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
4619 views[i] = NULL;
4620 continue;
4623 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4624 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4625 ID3D10ShaderResourceView_AddRef(views[i]);
4627 wined3d_mutex_unlock();
4630 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
4631 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4633 struct d3d_device *device = impl_from_ID3D10Device(iface);
4634 unsigned int i;
4636 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4637 iface, start_slot, sampler_count, samplers);
4639 wined3d_mutex_lock();
4640 for (i = 0; i < sampler_count; ++i)
4642 struct d3d_sampler_state *sampler_impl;
4643 struct wined3d_sampler *wined3d_sampler;
4645 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4647 samplers[i] = NULL;
4648 continue;
4651 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4652 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4653 ID3D10SamplerState_AddRef(samplers[i]);
4655 wined3d_mutex_unlock();
4658 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4659 ID3D10Predicate **predicate, BOOL *value)
4661 struct d3d_device *device = impl_from_ID3D10Device(iface);
4662 struct wined3d_query *wined3d_predicate;
4663 struct d3d_query *predicate_impl;
4665 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4667 wined3d_mutex_lock();
4668 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4670 wined3d_mutex_unlock();
4671 *predicate = NULL;
4672 return;
4675 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4676 wined3d_mutex_unlock();
4677 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4678 ID3D10Predicate_AddRef(*predicate);
4681 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4682 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4684 struct d3d_device *device = impl_from_ID3D10Device(iface);
4685 unsigned int i;
4687 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4688 iface, start_slot, view_count, views);
4690 wined3d_mutex_lock();
4691 for (i = 0; i < view_count; ++i)
4693 struct wined3d_shader_resource_view *wined3d_view;
4694 struct d3d_shader_resource_view *view_impl;
4696 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4698 views[i] = NULL;
4699 continue;
4702 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4703 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4704 ID3D10ShaderResourceView_AddRef(views[i]);
4706 wined3d_mutex_unlock();
4709 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4710 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4712 struct d3d_device *device = impl_from_ID3D10Device(iface);
4713 unsigned int i;
4715 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4716 iface, start_slot, sampler_count, samplers);
4718 wined3d_mutex_lock();
4719 for (i = 0; i < sampler_count; ++i)
4721 struct d3d_sampler_state *sampler_impl;
4722 struct wined3d_sampler *wined3d_sampler;
4724 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4726 samplers[i] = NULL;
4727 continue;
4730 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4731 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4732 ID3D10SamplerState_AddRef(samplers[i]);
4734 wined3d_mutex_unlock();
4737 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4738 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4740 struct d3d_device *device = impl_from_ID3D10Device(iface);
4741 struct wined3d_rendertarget_view *wined3d_view;
4743 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4744 iface, view_count, render_target_views, depth_stencil_view);
4746 wined3d_mutex_lock();
4747 if (render_target_views)
4749 struct d3d_rendertarget_view *view_impl;
4750 unsigned int i;
4752 for (i = 0; i < view_count; ++i)
4754 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4755 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4757 render_target_views[i] = NULL;
4758 continue;
4761 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4762 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4766 if (depth_stencil_view)
4768 struct d3d_depthstencil_view *view_impl;
4770 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4771 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4773 *depth_stencil_view = NULL;
4775 else
4777 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4778 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4781 wined3d_mutex_unlock();
4784 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4785 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4787 struct d3d_device *device = impl_from_ID3D10Device(iface);
4788 ID3D11BlendState *d3d11_blend_state;
4790 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4791 iface, blend_state, blend_factor, sample_mask);
4793 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4794 &d3d11_blend_state, blend_factor, sample_mask);
4796 if (d3d11_blend_state)
4797 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4798 else
4799 *blend_state = NULL;
4802 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4803 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4805 struct d3d_device *device = impl_from_ID3D10Device(iface);
4806 ID3D11DepthStencilState *d3d11_iface;
4808 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4809 iface, depth_stencil_state, stencil_ref);
4811 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4812 &d3d11_iface, stencil_ref);
4814 if (d3d11_iface)
4815 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4816 else
4817 *depth_stencil_state = NULL;
4820 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4821 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4823 struct d3d_device *device = impl_from_ID3D10Device(iface);
4824 unsigned int i;
4826 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4827 iface, buffer_count, buffers, offsets);
4829 wined3d_mutex_lock();
4830 for (i = 0; i < buffer_count; ++i)
4832 struct wined3d_buffer *wined3d_buffer;
4833 struct d3d_buffer *buffer_impl;
4835 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4837 buffers[i] = NULL;
4838 continue;
4841 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4842 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4843 ID3D10Buffer_AddRef(buffers[i]);
4845 wined3d_mutex_unlock();
4848 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4850 struct d3d_device *device = impl_from_ID3D10Device(iface);
4851 struct d3d_rasterizer_state *rasterizer_state_impl;
4852 struct wined3d_rasterizer_state *wined3d_state;
4854 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4856 wined3d_mutex_lock();
4857 if ((wined3d_state = wined3d_device_get_rasterizer_state(device->wined3d_device)))
4859 rasterizer_state_impl = wined3d_rasterizer_state_get_parent(wined3d_state);
4860 ID3D10RasterizerState_AddRef(*rasterizer_state = &rasterizer_state_impl->ID3D10RasterizerState_iface);
4862 else
4864 *rasterizer_state = NULL;
4866 wined3d_mutex_unlock();
4869 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4870 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4872 struct d3d_device *device = impl_from_ID3D10Device(iface);
4873 struct wined3d_viewport wined3d_vp;
4875 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4877 if (!viewports)
4879 *viewport_count = 1;
4880 return;
4883 if (!*viewport_count)
4884 return;
4886 wined3d_mutex_lock();
4887 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4888 wined3d_mutex_unlock();
4890 viewports[0].TopLeftX = wined3d_vp.x;
4891 viewports[0].TopLeftY = wined3d_vp.y;
4892 viewports[0].Width = wined3d_vp.width;
4893 viewports[0].Height = wined3d_vp.height;
4894 viewports[0].MinDepth = wined3d_vp.min_z;
4895 viewports[0].MaxDepth = wined3d_vp.max_z;
4897 if (*viewport_count > 1)
4898 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4901 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4903 struct d3d_device *device = impl_from_ID3D10Device(iface);
4905 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4907 if (!rects)
4909 *rect_count = 1;
4910 return;
4913 if (!*rect_count)
4914 return;
4916 wined3d_mutex_lock();
4917 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4918 wined3d_mutex_unlock();
4919 if (*rect_count > 1)
4920 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4923 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4925 TRACE("iface %p.\n", iface);
4927 /* In the current implementation the device is never removed, so we can
4928 * just return S_OK here. */
4930 return S_OK;
4933 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4935 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4937 return E_NOTIMPL;
4940 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4942 FIXME("iface %p stub!\n", iface);
4944 return 0;
4947 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4948 REFGUID guid, UINT *data_size, void *data)
4950 struct d3d_device *device = impl_from_ID3D10Device(iface);
4952 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4954 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4957 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4958 REFGUID guid, UINT data_size, const void *data)
4960 struct d3d_device *device = impl_from_ID3D10Device(iface);
4962 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4964 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4967 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4968 REFGUID guid, const IUnknown *data)
4970 struct d3d_device *device = impl_from_ID3D10Device(iface);
4972 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4974 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4977 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4979 struct d3d_device *device = impl_from_ID3D10Device(iface);
4981 TRACE("iface %p.\n", iface);
4983 d3d11_immediate_context_ClearState(&device->immediate_context.ID3D11DeviceContext_iface);
4986 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4988 FIXME("iface %p stub!\n", iface);
4991 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4992 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4994 struct d3d_device *device = impl_from_ID3D10Device(iface);
4995 D3D11_BUFFER_DESC d3d11_desc;
4996 struct d3d_buffer *object;
4997 HRESULT hr;
4999 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
5001 d3d11_desc.ByteWidth = desc->ByteWidth;
5002 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5003 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5004 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5005 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5006 d3d11_desc.StructureByteStride = 0;
5008 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5009 return hr;
5011 *buffer = &object->ID3D10Buffer_iface;
5013 return S_OK;
5016 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
5017 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
5019 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
5021 return E_NOTIMPL;
5024 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
5025 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5026 ID3D10Texture2D **texture)
5028 struct d3d_device *device = impl_from_ID3D10Device(iface);
5029 D3D11_TEXTURE2D_DESC d3d11_desc;
5030 struct d3d_texture2d *object;
5031 HRESULT hr;
5033 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5035 d3d11_desc.Width = desc->Width;
5036 d3d11_desc.Height = desc->Height;
5037 d3d11_desc.MipLevels = desc->MipLevels;
5038 d3d11_desc.ArraySize = desc->ArraySize;
5039 d3d11_desc.Format = desc->Format;
5040 d3d11_desc.SampleDesc = desc->SampleDesc;
5041 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5042 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5043 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5044 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5046 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5047 return hr;
5049 *texture = &object->ID3D10Texture2D_iface;
5051 return S_OK;
5054 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
5055 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
5056 ID3D10Texture3D **texture)
5058 struct d3d_device *device = impl_from_ID3D10Device(iface);
5059 D3D11_TEXTURE3D_DESC d3d11_desc;
5060 struct d3d_texture3d *object;
5061 HRESULT hr;
5063 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
5065 d3d11_desc.Width = desc->Width;
5066 d3d11_desc.Height = desc->Height;
5067 d3d11_desc.Depth = desc->Depth;
5068 d3d11_desc.MipLevels = desc->MipLevels;
5069 d3d11_desc.Format = desc->Format;
5070 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
5071 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
5072 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
5073 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
5075 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
5076 return hr;
5078 *texture = &object->ID3D10Texture3D_iface;
5080 return S_OK;
5083 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
5084 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
5086 struct d3d_device *device = impl_from_ID3D10Device(iface);
5087 struct d3d_shader_resource_view *object;
5088 ID3D11Resource *d3d11_resource;
5089 HRESULT hr;
5091 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5093 if (!resource)
5094 return E_INVALIDARG;
5096 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5098 ERR("Resource does not implement ID3D11Resource.\n");
5099 return E_FAIL;
5102 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
5103 &object);
5104 ID3D11Resource_Release(d3d11_resource);
5105 if (FAILED(hr))
5106 return hr;
5108 *view = &object->ID3D10ShaderResourceView1_iface;
5110 return S_OK;
5113 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
5114 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
5116 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5118 return d3d10_device_CreateShaderResourceView1(iface, resource,
5119 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
5122 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
5123 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
5125 struct d3d_device *device = impl_from_ID3D10Device(iface);
5126 struct d3d_rendertarget_view *object;
5127 ID3D11Resource *d3d11_resource;
5128 HRESULT hr;
5130 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5132 if (!resource)
5133 return E_INVALIDARG;
5135 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5137 ERR("Resource does not implement ID3D11Resource.\n");
5138 return E_FAIL;
5141 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
5142 ID3D11Resource_Release(d3d11_resource);
5143 if (FAILED(hr))
5144 return hr;
5146 *view = &object->ID3D10RenderTargetView_iface;
5148 return S_OK;
5151 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
5152 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
5154 struct d3d_device *device = impl_from_ID3D10Device(iface);
5155 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
5156 struct d3d_depthstencil_view *object;
5157 ID3D11Resource *d3d11_resource;
5158 HRESULT hr;
5160 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
5162 if (desc)
5164 d3d11_desc.Format = desc->Format;
5165 d3d11_desc.ViewDimension = desc->ViewDimension;
5166 d3d11_desc.Flags = 0;
5167 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
5170 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
5172 ERR("Resource does not implement ID3D11Resource.\n");
5173 return E_FAIL;
5176 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
5177 ID3D11Resource_Release(d3d11_resource);
5178 if (FAILED(hr))
5179 return hr;
5181 *view = &object->ID3D10DepthStencilView_iface;
5183 return S_OK;
5186 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
5187 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
5188 const void *shader_byte_code, SIZE_T shader_byte_code_length,
5189 ID3D10InputLayout **input_layout)
5191 struct d3d_device *device = impl_from_ID3D10Device(iface);
5192 struct d3d_input_layout *object;
5193 HRESULT hr;
5195 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
5196 "shader_byte_code_length %lu, input_layout %p\n",
5197 iface, element_descs, element_count, shader_byte_code,
5198 shader_byte_code_length, input_layout);
5200 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
5201 shader_byte_code, shader_byte_code_length, &object)))
5202 return hr;
5204 *input_layout = &object->ID3D10InputLayout_iface;
5206 return S_OK;
5209 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
5210 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
5212 struct d3d_device *device = impl_from_ID3D10Device(iface);
5213 struct d3d_vertex_shader *object;
5214 HRESULT hr;
5216 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5217 iface, byte_code, byte_code_length, shader);
5219 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
5220 return hr;
5222 *shader = &object->ID3D10VertexShader_iface;
5224 return S_OK;
5227 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
5228 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
5230 struct d3d_device *device = impl_from_ID3D10Device(iface);
5231 struct d3d_geometry_shader *object;
5232 HRESULT hr;
5234 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5235 iface, byte_code, byte_code_length, shader);
5237 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5238 NULL, 0, NULL, 0, 0, &object)))
5239 return hr;
5241 *shader = &object->ID3D10GeometryShader_iface;
5243 return S_OK;
5246 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
5247 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
5248 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
5250 struct d3d_device *device = impl_from_ID3D10Device(iface);
5251 D3D11_SO_DECLARATION_ENTRY *so_entries = NULL;
5252 struct d3d_geometry_shader *object;
5253 unsigned int i, stride_count = 1;
5254 HRESULT hr;
5256 TRACE("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
5257 "output_stream_decl_count %u, output_stream_stride %u, shader %p.\n",
5258 iface, byte_code, byte_code_length, output_stream_decls,
5259 output_stream_decl_count, output_stream_stride, shader);
5261 if (!output_stream_decl_count && output_stream_stride)
5263 WARN("Stride must be 0 when declaration entry count is 0.\n");
5264 *shader = NULL;
5265 return E_INVALIDARG;
5268 if (output_stream_decl_count
5269 && !(so_entries = d3d11_calloc(output_stream_decl_count, sizeof(*so_entries))))
5271 ERR("Failed to allocate D3D11 SO declaration array memory.\n");
5272 *shader = NULL;
5273 return E_OUTOFMEMORY;
5276 for (i = 0; i < output_stream_decl_count; ++i)
5278 so_entries[i].Stream = 0;
5279 so_entries[i].SemanticName = output_stream_decls[i].SemanticName;
5280 so_entries[i].SemanticIndex = output_stream_decls[i].SemanticIndex;
5281 so_entries[i].StartComponent = output_stream_decls[i].StartComponent;
5282 so_entries[i].ComponentCount = output_stream_decls[i].ComponentCount;
5283 so_entries[i].OutputSlot = output_stream_decls[i].OutputSlot;
5285 if (output_stream_decls[i].OutputSlot)
5287 stride_count = 0;
5288 if (output_stream_stride)
5290 WARN("Stride must be 0 when multiple output slots are used.\n");
5291 HeapFree(GetProcessHeap(), 0, so_entries);
5292 *shader = NULL;
5293 return E_INVALIDARG;
5298 hr = d3d_geometry_shader_create(device, byte_code, byte_code_length,
5299 so_entries, output_stream_decl_count, &output_stream_stride, stride_count, 0, &object);
5300 HeapFree(GetProcessHeap(), 0, so_entries);
5301 if (FAILED(hr))
5303 *shader = NULL;
5304 return hr;
5307 *shader = &object->ID3D10GeometryShader_iface;
5309 return hr;
5312 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
5313 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
5315 struct d3d_device *device = impl_from_ID3D10Device(iface);
5316 struct d3d_pixel_shader *object;
5317 HRESULT hr;
5319 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
5320 iface, byte_code, byte_code_length, shader);
5322 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
5323 return hr;
5325 *shader = &object->ID3D10PixelShader_iface;
5327 return S_OK;
5330 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
5331 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
5333 struct d3d_device *device = impl_from_ID3D10Device(iface);
5334 ID3D11BlendState *d3d11_blend_state;
5335 HRESULT hr;
5337 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5339 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
5340 &d3d11_blend_state)))
5341 return hr;
5343 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
5344 ID3D11BlendState_Release(d3d11_blend_state);
5345 return hr;
5348 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
5349 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
5351 D3D10_BLEND_DESC1 d3d10_1_desc;
5352 unsigned int i;
5354 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
5356 if (!desc)
5357 return E_INVALIDARG;
5359 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
5360 d3d10_1_desc.IndependentBlendEnable = FALSE;
5361 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
5363 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
5364 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
5365 d3d10_1_desc.IndependentBlendEnable = TRUE;
5368 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5370 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
5371 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
5372 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
5373 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
5374 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
5375 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
5376 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
5377 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
5380 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
5383 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
5384 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
5386 struct d3d_device *device = impl_from_ID3D10Device(iface);
5387 ID3D11DepthStencilState *d3d11_depth_stencil_state;
5388 HRESULT hr;
5390 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
5392 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
5393 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
5394 return hr;
5396 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
5397 (void **)depth_stencil_state);
5398 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
5399 return hr;
5402 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
5403 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
5405 struct d3d_device *device = impl_from_ID3D10Device(iface);
5406 ID3D11RasterizerState *d3d11_rasterizer_state;
5407 HRESULT hr;
5409 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
5411 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
5412 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
5413 return hr;
5415 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
5416 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
5417 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
5418 return hr;
5421 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
5422 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
5424 struct d3d_device *device = impl_from_ID3D10Device(iface);
5425 ID3D11SamplerState *d3d11_sampler_state;
5426 HRESULT hr;
5428 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
5430 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
5431 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
5432 return hr;
5434 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
5435 ID3D11SamplerState_Release(d3d11_sampler_state);
5436 return hr;
5439 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
5440 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
5442 struct d3d_device *device = impl_from_ID3D10Device(iface);
5443 struct d3d_query *object;
5444 HRESULT hr;
5446 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
5448 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
5449 return hr;
5451 if (query)
5453 *query = &object->ID3D10Query_iface;
5454 return S_OK;
5457 ID3D10Query_Release(&object->ID3D10Query_iface);
5458 return S_FALSE;
5461 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
5462 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
5464 struct d3d_device *device = impl_from_ID3D10Device(iface);
5465 struct d3d_query *object;
5466 HRESULT hr;
5468 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
5470 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
5471 return hr;
5473 if (predicate)
5475 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
5476 return S_OK;
5479 ID3D10Query_Release(&object->ID3D10Query_iface);
5480 return S_FALSE;
5483 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
5484 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
5486 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
5488 return E_NOTIMPL;
5491 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
5492 DXGI_FORMAT format, UINT *format_support)
5494 FIXME("iface %p, format %s, format_support %p stub!\n",
5495 iface, debug_dxgi_format(format), format_support);
5497 return E_NOTIMPL;
5500 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
5501 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
5503 struct d3d_device *device = impl_from_ID3D10Device(iface);
5505 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
5506 iface, debug_dxgi_format(format), sample_count, quality_level_count);
5508 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
5509 sample_count, quality_level_count);
5512 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
5514 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
5517 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
5518 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
5519 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
5521 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
5522 "units %p, units_length %p, description %p, description_length %p stub!\n",
5523 iface, desc, type, active_counters, name, name_length,
5524 units, units_length, description, description_length);
5526 return E_NOTIMPL;
5529 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
5531 FIXME("iface %p stub!\n", iface);
5533 return 0;
5536 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
5537 HANDLE resource_handle, REFIID guid, void **resource)
5539 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
5540 iface, resource_handle, debugstr_guid(guid), resource);
5542 return E_NOTIMPL;
5545 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
5547 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
5550 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
5552 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
5555 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
5557 struct d3d_device *device = impl_from_ID3D10Device(iface);
5559 TRACE("iface %p.\n", iface);
5561 return device->feature_level;
5564 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
5566 /* IUnknown methods */
5567 d3d10_device_QueryInterface,
5568 d3d10_device_AddRef,
5569 d3d10_device_Release,
5570 /* ID3D10Device methods */
5571 d3d10_device_VSSetConstantBuffers,
5572 d3d10_device_PSSetShaderResources,
5573 d3d10_device_PSSetShader,
5574 d3d10_device_PSSetSamplers,
5575 d3d10_device_VSSetShader,
5576 d3d10_device_DrawIndexed,
5577 d3d10_device_Draw,
5578 d3d10_device_PSSetConstantBuffers,
5579 d3d10_device_IASetInputLayout,
5580 d3d10_device_IASetVertexBuffers,
5581 d3d10_device_IASetIndexBuffer,
5582 d3d10_device_DrawIndexedInstanced,
5583 d3d10_device_DrawInstanced,
5584 d3d10_device_GSSetConstantBuffers,
5585 d3d10_device_GSSetShader,
5586 d3d10_device_IASetPrimitiveTopology,
5587 d3d10_device_VSSetShaderResources,
5588 d3d10_device_VSSetSamplers,
5589 d3d10_device_SetPredication,
5590 d3d10_device_GSSetShaderResources,
5591 d3d10_device_GSSetSamplers,
5592 d3d10_device_OMSetRenderTargets,
5593 d3d10_device_OMSetBlendState,
5594 d3d10_device_OMSetDepthStencilState,
5595 d3d10_device_SOSetTargets,
5596 d3d10_device_DrawAuto,
5597 d3d10_device_RSSetState,
5598 d3d10_device_RSSetViewports,
5599 d3d10_device_RSSetScissorRects,
5600 d3d10_device_CopySubresourceRegion,
5601 d3d10_device_CopyResource,
5602 d3d10_device_UpdateSubresource,
5603 d3d10_device_ClearRenderTargetView,
5604 d3d10_device_ClearDepthStencilView,
5605 d3d10_device_GenerateMips,
5606 d3d10_device_ResolveSubresource,
5607 d3d10_device_VSGetConstantBuffers,
5608 d3d10_device_PSGetShaderResources,
5609 d3d10_device_PSGetShader,
5610 d3d10_device_PSGetSamplers,
5611 d3d10_device_VSGetShader,
5612 d3d10_device_PSGetConstantBuffers,
5613 d3d10_device_IAGetInputLayout,
5614 d3d10_device_IAGetVertexBuffers,
5615 d3d10_device_IAGetIndexBuffer,
5616 d3d10_device_GSGetConstantBuffers,
5617 d3d10_device_GSGetShader,
5618 d3d10_device_IAGetPrimitiveTopology,
5619 d3d10_device_VSGetShaderResources,
5620 d3d10_device_VSGetSamplers,
5621 d3d10_device_GetPredication,
5622 d3d10_device_GSGetShaderResources,
5623 d3d10_device_GSGetSamplers,
5624 d3d10_device_OMGetRenderTargets,
5625 d3d10_device_OMGetBlendState,
5626 d3d10_device_OMGetDepthStencilState,
5627 d3d10_device_SOGetTargets,
5628 d3d10_device_RSGetState,
5629 d3d10_device_RSGetViewports,
5630 d3d10_device_RSGetScissorRects,
5631 d3d10_device_GetDeviceRemovedReason,
5632 d3d10_device_SetExceptionMode,
5633 d3d10_device_GetExceptionMode,
5634 d3d10_device_GetPrivateData,
5635 d3d10_device_SetPrivateData,
5636 d3d10_device_SetPrivateDataInterface,
5637 d3d10_device_ClearState,
5638 d3d10_device_Flush,
5639 d3d10_device_CreateBuffer,
5640 d3d10_device_CreateTexture1D,
5641 d3d10_device_CreateTexture2D,
5642 d3d10_device_CreateTexture3D,
5643 d3d10_device_CreateShaderResourceView,
5644 d3d10_device_CreateRenderTargetView,
5645 d3d10_device_CreateDepthStencilView,
5646 d3d10_device_CreateInputLayout,
5647 d3d10_device_CreateVertexShader,
5648 d3d10_device_CreateGeometryShader,
5649 d3d10_device_CreateGeometryShaderWithStreamOutput,
5650 d3d10_device_CreatePixelShader,
5651 d3d10_device_CreateBlendState,
5652 d3d10_device_CreateDepthStencilState,
5653 d3d10_device_CreateRasterizerState,
5654 d3d10_device_CreateSamplerState,
5655 d3d10_device_CreateQuery,
5656 d3d10_device_CreatePredicate,
5657 d3d10_device_CreateCounter,
5658 d3d10_device_CheckFormatSupport,
5659 d3d10_device_CheckMultisampleQualityLevels,
5660 d3d10_device_CheckCounterInfo,
5661 d3d10_device_CheckCounter,
5662 d3d10_device_GetCreationFlags,
5663 d3d10_device_OpenSharedResource,
5664 d3d10_device_SetTextFilterSize,
5665 d3d10_device_GetTextFilterSize,
5666 d3d10_device_CreateShaderResourceView1,
5667 d3d10_device_CreateBlendState1,
5668 d3d10_device_GetFeatureLevel,
5671 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5673 /* IUnknown methods */
5674 d3d_device_inner_QueryInterface,
5675 d3d_device_inner_AddRef,
5676 d3d_device_inner_Release,
5679 /* ID3D10Multithread methods */
5681 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5683 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5686 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5688 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5690 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5692 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5695 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5697 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5699 TRACE("iface %p.\n", iface);
5701 return IUnknown_AddRef(device->outer_unk);
5704 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5706 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5708 TRACE("iface %p.\n", iface);
5710 return IUnknown_Release(device->outer_unk);
5713 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5715 TRACE("iface %p.\n", iface);
5717 wined3d_mutex_lock();
5720 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5722 TRACE("iface %p.\n", iface);
5724 wined3d_mutex_unlock();
5727 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5729 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5731 return TRUE;
5734 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5736 FIXME("iface %p stub!\n", iface);
5738 return TRUE;
5741 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5743 d3d10_multithread_QueryInterface,
5744 d3d10_multithread_AddRef,
5745 d3d10_multithread_Release,
5746 d3d10_multithread_Enter,
5747 d3d10_multithread_Leave,
5748 d3d10_multithread_SetMultithreadProtected,
5749 d3d10_multithread_GetMultithreadProtected,
5752 /* IWineDXGIDeviceParent IUnknown methods */
5754 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5756 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5759 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5760 REFIID riid, void **ppv)
5762 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5763 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5766 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5768 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5769 return IUnknown_AddRef(device->outer_unk);
5772 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5774 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5775 return IUnknown_Release(device->outer_unk);
5778 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5779 IWineDXGIDeviceParent *iface)
5781 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5782 return &device->device_parent;
5785 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5787 /* IUnknown methods */
5788 dxgi_device_parent_QueryInterface,
5789 dxgi_device_parent_AddRef,
5790 dxgi_device_parent_Release,
5791 /* IWineDXGIDeviceParent methods */
5792 dxgi_device_parent_get_wined3d_device_parent,
5795 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5797 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5800 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5801 struct wined3d_device *wined3d_device)
5803 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5805 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5807 wined3d_device_incref(wined3d_device);
5808 device->wined3d_device = wined3d_device;
5811 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5813 TRACE("device_parent %p.\n", device_parent);
5816 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5818 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5821 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5822 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5823 const struct wined3d_parent_ops **parent_ops)
5825 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5826 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5828 *parent = NULL;
5829 *parent_ops = &d3d_null_wined3d_parent_ops;
5831 return S_OK;
5834 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5835 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, DWORD texture_flags,
5836 struct wined3d_texture **wined3d_texture)
5838 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5839 struct d3d_texture2d *texture;
5840 ID3D10Texture2D *texture_iface;
5841 D3D10_TEXTURE2D_DESC desc;
5842 HRESULT hr;
5844 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, texture flags %#x, "
5845 "wined3d_texture %p partial stub!\n", device_parent, container_parent,
5846 wined3d_desc, texture_flags, wined3d_texture);
5848 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5850 desc.Width = wined3d_desc->width;
5851 desc.Height = wined3d_desc->height;
5852 desc.MipLevels = 1;
5853 desc.ArraySize = 1;
5854 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5855 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5856 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5857 desc.Usage = D3D10_USAGE_DEFAULT;
5858 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5859 desc.CPUAccessFlags = 0;
5860 desc.MiscFlags = 0;
5862 if (texture_flags & WINED3D_TEXTURE_CREATE_GET_DC)
5864 desc.MiscFlags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
5865 texture_flags &= ~WINED3D_TEXTURE_CREATE_GET_DC;
5868 if (texture_flags)
5869 FIXME("Unhandled flags %#x.\n", texture_flags);
5871 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5872 &desc, NULL, &texture_iface)))
5874 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5875 return hr;
5878 texture = impl_from_ID3D10Texture2D(texture_iface);
5880 *wined3d_texture = texture->wined3d_texture;
5881 wined3d_texture_incref(*wined3d_texture);
5882 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5884 return S_OK;
5887 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5888 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5890 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5891 IWineDXGIDevice *wine_device;
5892 HRESULT hr;
5894 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5896 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5897 &IID_IWineDXGIDevice, (void **)&wine_device)))
5899 ERR("Device should implement IWineDXGIDevice.\n");
5900 return E_FAIL;
5903 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5904 IWineDXGIDevice_Release(wine_device);
5905 if (FAILED(hr))
5907 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5908 return hr;
5911 return S_OK;
5914 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5916 device_parent_wined3d_device_created,
5917 device_parent_mode_changed,
5918 device_parent_activate,
5919 device_parent_sub_resource_created,
5920 device_parent_sub_resource_created,
5921 device_parent_create_swapchain_texture,
5922 device_parent_create_swapchain,
5925 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5927 const D3D11_SAMPLER_DESC *ka = key;
5928 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5930 return memcmp(ka, kb, sizeof(*ka));
5933 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5935 const D3D11_BLEND_DESC *ka = key;
5936 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5938 return memcmp(ka, kb, sizeof(*ka));
5941 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5943 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5944 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5945 const struct d3d_depthstencil_state, entry)->desc;
5947 return memcmp(ka, kb, sizeof(*ka));
5950 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5952 const D3D11_RASTERIZER_DESC *ka = key;
5953 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5955 return memcmp(ka, kb, sizeof(*ka));
5958 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
5960 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5961 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5962 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5963 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5964 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5965 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5966 device->refcount = 1;
5967 /* COM aggregation always takes place */
5968 device->outer_unk = outer_unknown;
5970 d3d11_immediate_context_init(&device->immediate_context, device);
5971 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5973 device->blend_factor[0] = 1.0f;
5974 device->blend_factor[1] = 1.0f;
5975 device->blend_factor[2] = 1.0f;
5976 device->blend_factor[3] = 1.0f;
5978 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
5979 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
5980 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
5981 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);