wined3d: Introduce R10G10B10X2 vertex formats for D3D8/9.
[wine.git] / dlls / d3d11 / device.c
blob7f819db80897761aac564694d3c7fdf401843375
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 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 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
532 wined3d_mutex_lock();
533 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
535 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
537 else
539 WARN("Invalid data size %u.\n", data_size);
540 hr = E_INVALIDARG;
542 wined3d_mutex_unlock();
544 return hr;
547 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext *iface,
548 ID3D11Predicate *predicate, BOOL value)
550 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
551 struct d3d_query *query;
553 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
555 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
557 wined3d_mutex_lock();
558 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
559 wined3d_mutex_unlock();
562 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext *iface,
563 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
565 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
566 unsigned int i;
568 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
570 wined3d_mutex_lock();
571 for (i = 0; i < view_count; ++i)
573 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
575 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
576 view ? view->wined3d_view : NULL);
578 wined3d_mutex_unlock();
581 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext *iface,
582 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
584 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
585 unsigned int i;
587 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
588 iface, start_slot, sampler_count, samplers);
590 wined3d_mutex_lock();
591 for (i = 0; i < sampler_count; ++i)
593 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
595 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
596 sampler ? sampler->wined3d_sampler : NULL);
598 wined3d_mutex_unlock();
601 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext *iface,
602 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
603 ID3D11DepthStencilView *depth_stencil_view)
605 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
606 struct d3d_depthstencil_view *dsv;
607 unsigned int i;
609 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
610 iface, render_target_view_count, render_target_views, depth_stencil_view);
612 wined3d_mutex_lock();
613 for (i = 0; i < render_target_view_count; ++i)
615 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
616 wined3d_device_set_rendertarget_view(device->wined3d_device, i, rtv ? rtv->wined3d_view : NULL, FALSE);
618 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
620 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
623 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
624 wined3d_device_set_depth_stencil_view(device->wined3d_device, dsv ? dsv->wined3d_view : NULL);
625 wined3d_mutex_unlock();
628 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
629 ID3D11DeviceContext *iface, UINT render_target_view_count,
630 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
631 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
632 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
634 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
635 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
636 "initial_counts %p partial-stub!\n",
637 iface, render_target_view_count, render_target_views, depth_stencil_view,
638 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
639 initial_counts);
641 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
643 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
644 depth_stencil_view);
648 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
649 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
651 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
652 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
653 const D3D11_BLEND_DESC *desc;
655 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
656 iface, blend_state, debug_float4(blend_factor), sample_mask);
658 if (!blend_factor)
659 blend_factor = default_blend_factor;
661 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
662 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
664 wined3d_mutex_lock();
665 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
666 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
667 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
669 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
670 wined3d_device_set_render_state(device->wined3d_device,
671 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
672 wined3d_device_set_render_state(device->wined3d_device,
673 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
674 wined3d_device_set_render_state(device->wined3d_device,
675 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
676 wined3d_device_set_render_state(device->wined3d_device,
677 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
678 wined3d_mutex_unlock();
679 return;
682 desc = &device->blend_state->desc;
683 /* glSampleCoverage() */
684 if (desc->AlphaToCoverageEnable)
685 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
686 /* glEnableIndexedEXT(GL_BLEND, ...) */
687 FIXME("Per-rendertarget blend not implemented.\n");
688 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
689 desc->RenderTarget[0].BlendEnable);
690 if (desc->RenderTarget[0].BlendEnable)
692 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND,
693 desc->RenderTarget[0].SrcBlend);
694 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND,
695 desc->RenderTarget[0].DestBlend);
696 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP,
697 desc->RenderTarget[0].BlendOp);
698 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
699 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA,
700 desc->RenderTarget[0].SrcBlendAlpha);
701 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA,
702 desc->RenderTarget[0].DestBlendAlpha);
703 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA,
704 desc->RenderTarget[0].BlendOpAlpha);
706 FIXME("Color mask > 3 not implemented.\n");
707 wined3d_device_set_render_state(device->wined3d_device,
708 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
709 wined3d_device_set_render_state(device->wined3d_device,
710 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
711 wined3d_device_set_render_state(device->wined3d_device,
712 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
713 wined3d_device_set_render_state(device->wined3d_device,
714 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
715 wined3d_mutex_unlock();
718 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
719 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
721 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
722 const D3D11_DEPTH_STENCILOP_DESC *stencil_desc;
723 const D3D11_DEPTH_STENCIL_DESC *desc;
725 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
726 iface, depth_stencil_state, stencil_ref);
728 wined3d_mutex_lock();
729 device->stencil_ref = stencil_ref;
730 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
732 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE);
733 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
734 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS);
735 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
736 wined3d_mutex_unlock();
737 return;
740 desc = &device->depth_stencil_state->desc;
742 if (desc->FrontFace.StencilFailOp != desc->BackFace.StencilFailOp
743 || desc->FrontFace.StencilDepthFailOp != desc->BackFace.StencilDepthFailOp
744 || desc->FrontFace.StencilPassOp != desc->BackFace.StencilPassOp
745 || desc->FrontFace.StencilFunc != desc->BackFace.StencilFunc)
746 FIXME("Two-sided stencil testing not supported.\n");
748 stencil_desc = &desc->FrontFace;
750 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
751 if (desc->DepthEnable)
753 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
754 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
757 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
758 if (desc->StencilEnable)
760 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
761 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
762 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, stencil_desc->StencilFailOp);
763 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL,
764 stencil_desc->StencilDepthFailOp);
765 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, stencil_desc->StencilPassOp);
766 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, stencil_desc->StencilFunc);
767 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
769 wined3d_mutex_unlock();
772 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
773 ID3D11Buffer *const *buffers, const UINT *offsets)
775 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
776 unsigned int count, i;
778 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
780 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
781 wined3d_mutex_lock();
782 for (i = 0; i < count; ++i)
784 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
786 wined3d_device_set_stream_output(device->wined3d_device, i,
787 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
789 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
791 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
793 wined3d_mutex_unlock();
796 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
798 FIXME("iface %p stub!\n", iface);
801 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
802 ID3D11Buffer *buffer, UINT offset)
804 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
807 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
808 ID3D11Buffer *buffer, UINT offset)
810 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
813 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
814 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
816 FIXME("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u stub!\n",
817 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
820 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
821 ID3D11Buffer *buffer, UINT offset)
823 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
826 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
827 ID3D11RasterizerState *rasterizer_state)
829 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
830 const D3D11_RASTERIZER_DESC *desc;
832 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
834 wined3d_mutex_lock();
835 if (!(device->rasterizer_state = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
837 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
838 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
839 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
840 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
841 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
842 wined3d_mutex_unlock();
843 return;
846 desc = &device->rasterizer_state->desc;
847 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
848 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
849 /* glFrontFace() */
850 if (desc->FrontCounterClockwise)
851 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
852 /* OpenGL style depth bias. */
853 if (desc->DepthBias || desc->SlopeScaledDepthBias)
854 FIXME("Ignoring depth bias.\n");
855 /* GL_DEPTH_CLAMP */
856 if (!desc->DepthClipEnable)
857 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
858 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
859 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
860 wined3d_device_set_render_state(device->wined3d_device,
861 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
862 wined3d_mutex_unlock();
865 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
866 UINT viewport_count, const D3D11_VIEWPORT *viewports)
868 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
869 struct wined3d_viewport wined3d_vp;
871 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
873 if (viewport_count > 1)
874 FIXME("Multiple viewports not implemented.\n");
876 if (!viewport_count)
877 return;
879 if (viewports[0].TopLeftX != (UINT)viewports[0].TopLeftX
880 || viewports[0].TopLeftY != (UINT)viewports[0].TopLeftY
881 || viewports[0].Width != (UINT)viewports[0].Width
882 || viewports[0].Height != (UINT)viewports[0].Height)
883 FIXME("Floating-point viewports not implemented.\n");
885 wined3d_vp.x = viewports[0].TopLeftX;
886 wined3d_vp.y = viewports[0].TopLeftY;
887 wined3d_vp.width = viewports[0].Width;
888 wined3d_vp.height = viewports[0].Height;
889 wined3d_vp.min_z = viewports[0].MinDepth;
890 wined3d_vp.max_z = viewports[0].MaxDepth;
892 wined3d_mutex_lock();
893 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
894 wined3d_mutex_unlock();
897 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
898 UINT rect_count, const D3D11_RECT *rects)
900 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
902 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
904 if (rect_count > 1)
905 FIXME("Multiple scissor rects not implemented.\n");
907 if (!rect_count)
908 return;
910 wined3d_mutex_lock();
911 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
912 wined3d_mutex_unlock();
915 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
916 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
917 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
919 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
920 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
921 struct wined3d_box wined3d_src_box;
923 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
924 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
925 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
926 src_resource, src_subresource_idx, src_box);
928 if (src_box)
930 wined3d_src_box.left = src_box->left;
931 wined3d_src_box.top = src_box->top;
932 wined3d_src_box.front = src_box->front;
933 wined3d_src_box.right = src_box->right;
934 wined3d_src_box.bottom = src_box->bottom;
935 wined3d_src_box.back = src_box->back;
938 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
939 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
940 wined3d_mutex_lock();
941 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
942 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
943 wined3d_mutex_unlock();
946 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
947 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
949 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
950 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
952 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
954 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
955 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
956 wined3d_mutex_lock();
957 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
958 wined3d_mutex_unlock();
961 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
962 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
963 const void *data, UINT row_pitch, UINT depth_pitch)
965 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
966 struct wined3d_resource *wined3d_resource;
967 struct wined3d_box wined3d_box;
969 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
970 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
972 if (box)
974 wined3d_box.left = box->left;
975 wined3d_box.top = box->top;
976 wined3d_box.front = box->front;
977 wined3d_box.right = box->right;
978 wined3d_box.bottom = box->bottom;
979 wined3d_box.back = box->back;
982 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
983 wined3d_mutex_lock();
984 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
985 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
986 wined3d_mutex_unlock();
989 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
990 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
992 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
993 iface, dst_buffer, dst_offset, src_view);
996 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
997 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
999 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1000 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1001 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1002 HRESULT hr;
1004 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1005 iface, render_target_view, debug_float4(color_rgba));
1007 if (!view)
1008 return;
1010 wined3d_mutex_lock();
1011 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1012 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1013 ERR("Failed to clear view, hr %#x.\n", hr);
1014 wined3d_mutex_unlock();
1017 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1018 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1020 FIXME("iface %p, unordered_access_view %p, values {%u %u %u %u} stub!\n",
1021 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1024 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1025 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1027 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1028 iface, unordered_access_view, debug_float4(values));
1031 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1032 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1034 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1035 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1036 DWORD wined3d_flags;
1037 HRESULT hr;
1039 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1040 iface, depth_stencil_view, flags, depth, stencil);
1042 if (!view)
1043 return;
1045 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1047 wined3d_mutex_lock();
1048 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1049 wined3d_flags, NULL, depth, stencil)))
1050 ERR("Failed to clear view, hr %#x.\n", hr);
1051 wined3d_mutex_unlock();
1054 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1055 ID3D11ShaderResourceView *view)
1057 FIXME("iface %p, view %p stub!\n", iface, view);
1060 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1061 ID3D11Resource *resource, FLOAT min_lod)
1063 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1066 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1067 ID3D11Resource *resource)
1069 FIXME("iface %p, resource %p stub!\n", iface, resource);
1071 return 0.0f;
1074 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1075 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1076 ID3D11Resource *src_resource, UINT src_subresource_idx,
1077 DXGI_FORMAT format)
1079 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1080 "format %s stub!\n",
1081 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1082 debug_dxgi_format(format));
1085 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1086 ID3D11CommandList *command_list, BOOL restore_state)
1088 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1091 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1092 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1094 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1095 iface, start_slot, view_count, views);
1098 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1099 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1101 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1102 iface, shader, class_instances, class_instance_count);
1105 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1106 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1108 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1109 iface, start_slot, sampler_count, samplers);
1112 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1113 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1115 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1116 iface, start_slot, buffer_count, buffers);
1119 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1120 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1122 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1123 iface, start_slot, view_count, views);
1126 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1127 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1129 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1130 iface, shader, class_instances, class_instance_count);
1133 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1134 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1136 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1137 iface, start_slot, sampler_count, samplers);
1140 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1141 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1143 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1144 iface, start_slot, buffer_count, buffers);
1147 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1148 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1150 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1151 iface, start_slot, view_count, views);
1154 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1155 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1157 FIXME("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p stub!\n",
1158 iface, start_slot, view_count, views, initial_counts);
1161 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1162 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1164 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1165 iface, shader, class_instances, class_instance_count);
1168 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1169 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1171 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1172 iface, start_slot, sampler_count, samplers);
1175 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1176 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1178 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1179 iface, start_slot, buffer_count, buffers);
1182 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1183 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1185 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1186 unsigned int i;
1188 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1189 iface, start_slot, buffer_count, buffers);
1191 wined3d_mutex_lock();
1192 for (i = 0; i < buffer_count; ++i)
1194 struct wined3d_buffer *wined3d_buffer;
1195 struct d3d_buffer *buffer_impl;
1197 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1199 buffers[i] = NULL;
1200 continue;
1203 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1204 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1205 ID3D11Buffer_AddRef(buffers[i]);
1207 wined3d_mutex_unlock();
1210 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1211 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1213 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1214 unsigned int i;
1216 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1217 iface, start_slot, view_count, views);
1219 wined3d_mutex_lock();
1220 for (i = 0; i < view_count; ++i)
1222 struct wined3d_shader_resource_view *wined3d_view;
1223 struct d3d_shader_resource_view *view_impl;
1225 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1227 views[i] = NULL;
1228 continue;
1231 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1232 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1233 ID3D11ShaderResourceView_AddRef(views[i]);
1235 wined3d_mutex_unlock();
1238 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1239 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1241 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1242 struct wined3d_shader *wined3d_shader;
1243 struct d3d_pixel_shader *shader_impl;
1245 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1246 iface, shader, class_instances, class_instance_count);
1248 if (class_instances || class_instance_count)
1249 FIXME("Dynamic linking not implemented yet.\n");
1251 wined3d_mutex_lock();
1252 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1254 wined3d_mutex_unlock();
1255 *shader = NULL;
1256 return;
1259 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1260 wined3d_mutex_unlock();
1261 *shader = &shader_impl->ID3D11PixelShader_iface;
1262 ID3D11PixelShader_AddRef(*shader);
1265 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1266 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1268 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1269 unsigned int i;
1271 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1272 iface, start_slot, sampler_count, samplers);
1274 wined3d_mutex_lock();
1275 for (i = 0; i < sampler_count; ++i)
1277 struct wined3d_sampler *wined3d_sampler;
1278 struct d3d_sampler_state *sampler_impl;
1280 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1282 samplers[i] = NULL;
1283 continue;
1286 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1287 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1288 ID3D11SamplerState_AddRef(samplers[i]);
1290 wined3d_mutex_unlock();
1293 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1294 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1296 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1297 struct d3d_vertex_shader *shader_impl;
1298 struct wined3d_shader *wined3d_shader;
1300 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1301 iface, shader, class_instances, class_instance_count);
1303 if (class_instances || class_instance_count)
1304 FIXME("Dynamic linking not implemented yet.\n");
1306 wined3d_mutex_lock();
1307 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1309 wined3d_mutex_unlock();
1310 *shader = NULL;
1311 return;
1314 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1315 wined3d_mutex_unlock();
1316 *shader = &shader_impl->ID3D11VertexShader_iface;
1317 ID3D11VertexShader_AddRef(*shader);
1320 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1321 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1323 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1324 unsigned int i;
1326 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1327 iface, start_slot, buffer_count, buffers);
1329 wined3d_mutex_lock();
1330 for (i = 0; i < buffer_count; ++i)
1332 struct wined3d_buffer *wined3d_buffer;
1333 struct d3d_buffer *buffer_impl;
1335 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1337 buffers[i] = NULL;
1338 continue;
1341 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1342 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1343 ID3D11Buffer_AddRef(buffers[i]);
1345 wined3d_mutex_unlock();
1348 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1349 ID3D11InputLayout **input_layout)
1351 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1352 struct wined3d_vertex_declaration *wined3d_declaration;
1353 struct d3d_input_layout *input_layout_impl;
1355 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1357 wined3d_mutex_lock();
1358 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1360 wined3d_mutex_unlock();
1361 *input_layout = NULL;
1362 return;
1365 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1366 wined3d_mutex_unlock();
1367 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1368 ID3D11InputLayout_AddRef(*input_layout);
1371 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1372 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1374 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1375 unsigned int i;
1377 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1378 iface, start_slot, buffer_count, buffers, strides, offsets);
1380 wined3d_mutex_lock();
1381 for (i = 0; i < buffer_count; ++i)
1383 struct wined3d_buffer *wined3d_buffer;
1384 struct d3d_buffer *buffer_impl;
1386 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1387 &wined3d_buffer, &offsets[i], &strides[i])))
1388 ERR("Failed to get vertex buffer %u.\n", start_slot + i);
1390 if (!wined3d_buffer)
1392 buffers[i] = NULL;
1393 continue;
1396 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1397 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1399 wined3d_mutex_unlock();
1402 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1403 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1405 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1406 enum wined3d_format_id wined3d_format;
1407 struct wined3d_buffer *wined3d_buffer;
1408 struct d3d_buffer *buffer_impl;
1410 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1412 wined3d_mutex_lock();
1413 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1414 *format = dxgi_format_from_wined3dformat(wined3d_format);
1415 if (!wined3d_buffer)
1417 wined3d_mutex_unlock();
1418 *buffer = NULL;
1419 return;
1422 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1423 wined3d_mutex_unlock();
1424 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1427 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1428 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1430 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1431 unsigned int i;
1433 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1434 iface, start_slot, buffer_count, buffers);
1436 wined3d_mutex_lock();
1437 for (i = 0; i < buffer_count; ++i)
1439 struct wined3d_buffer *wined3d_buffer;
1440 struct d3d_buffer *buffer_impl;
1442 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1444 buffers[i] = NULL;
1445 continue;
1448 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1449 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1450 ID3D11Buffer_AddRef(buffers[i]);
1452 wined3d_mutex_unlock();
1455 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1456 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1458 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1459 struct d3d_geometry_shader *shader_impl;
1460 struct wined3d_shader *wined3d_shader;
1462 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1463 iface, shader, class_instances, class_instance_count);
1465 if (class_instances || class_instance_count)
1466 FIXME("Dynamic linking not implemented yet.\n");
1468 wined3d_mutex_lock();
1469 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1471 wined3d_mutex_unlock();
1472 *shader = NULL;
1473 return;
1476 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1477 wined3d_mutex_unlock();
1478 *shader = &shader_impl->ID3D11GeometryShader_iface;
1479 ID3D11GeometryShader_AddRef(*shader);
1482 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1483 D3D11_PRIMITIVE_TOPOLOGY *topology)
1485 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1487 TRACE("iface %p, topology %p.\n", iface, topology);
1489 wined3d_mutex_lock();
1490 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
1491 wined3d_mutex_unlock();
1494 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1495 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1497 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1498 unsigned int i;
1500 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1502 wined3d_mutex_lock();
1503 for (i = 0; i < view_count; ++i)
1505 struct wined3d_shader_resource_view *wined3d_view;
1506 struct d3d_shader_resource_view *view_impl;
1508 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1510 views[i] = NULL;
1511 continue;
1514 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1515 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1516 ID3D11ShaderResourceView_AddRef(views[i]);
1518 wined3d_mutex_unlock();
1521 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1522 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1524 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1525 unsigned int i;
1527 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1528 iface, start_slot, sampler_count, samplers);
1530 wined3d_mutex_lock();
1531 for (i = 0; i < sampler_count; ++i)
1533 struct wined3d_sampler *wined3d_sampler;
1534 struct d3d_sampler_state *sampler_impl;
1536 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1538 samplers[i] = NULL;
1539 continue;
1542 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1543 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1544 ID3D11SamplerState_AddRef(samplers[i]);
1546 wined3d_mutex_unlock();
1549 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1550 ID3D11Predicate **predicate, BOOL *value)
1552 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1553 struct wined3d_query *wined3d_predicate;
1554 struct d3d_query *predicate_impl;
1556 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1558 wined3d_mutex_lock();
1559 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1561 wined3d_mutex_unlock();
1562 *predicate = NULL;
1563 return;
1566 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1567 wined3d_mutex_unlock();
1568 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1569 ID3D11Predicate_AddRef(*predicate);
1572 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1573 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1575 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1576 unsigned int i;
1578 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1580 wined3d_mutex_lock();
1581 for (i = 0; i < view_count; ++i)
1583 struct wined3d_shader_resource_view *wined3d_view;
1584 struct d3d_shader_resource_view *view_impl;
1586 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1588 views[i] = NULL;
1589 continue;
1592 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1593 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1594 ID3D11ShaderResourceView_AddRef(views[i]);
1596 wined3d_mutex_unlock();
1599 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1600 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1602 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1603 unsigned int i;
1605 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1606 iface, start_slot, sampler_count, samplers);
1608 wined3d_mutex_lock();
1609 for (i = 0; i < sampler_count; ++i)
1611 struct d3d_sampler_state *sampler_impl;
1612 struct wined3d_sampler *wined3d_sampler;
1614 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1616 samplers[i] = NULL;
1617 continue;
1620 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1621 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1622 ID3D11SamplerState_AddRef(samplers[i]);
1624 wined3d_mutex_unlock();
1627 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1628 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1629 ID3D11DepthStencilView **depth_stencil_view)
1631 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1632 struct wined3d_rendertarget_view *wined3d_view;
1634 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1635 iface, render_target_view_count, render_target_views, depth_stencil_view);
1637 wined3d_mutex_lock();
1638 if (render_target_views)
1640 struct d3d_rendertarget_view *view_impl;
1641 unsigned int i;
1643 for (i = 0; i < render_target_view_count; ++i)
1645 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1646 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1648 render_target_views[i] = NULL;
1649 continue;
1652 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1653 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1657 if (depth_stencil_view)
1659 struct d3d_depthstencil_view *view_impl;
1661 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1662 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1664 *depth_stencil_view = NULL;
1666 else
1668 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1669 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1672 wined3d_mutex_unlock();
1675 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1676 ID3D11DeviceContext *iface,
1677 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1678 ID3D11DepthStencilView **depth_stencil_view,
1679 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1680 ID3D11UnorderedAccessView **unordered_access_views)
1682 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1683 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1684 "unordered_access_views %p stub!\n",
1685 iface, render_target_view_count, render_target_views, depth_stencil_view,
1686 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1689 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1690 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1692 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1694 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1695 iface, blend_state, blend_factor, sample_mask);
1697 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1698 ID3D11BlendState_AddRef(*blend_state);
1699 wined3d_mutex_lock();
1700 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1701 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1702 wined3d_mutex_unlock();
1705 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1706 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1708 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1710 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1711 iface, depth_stencil_state, stencil_ref);
1713 if ((*depth_stencil_state = device->depth_stencil_state
1714 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
1715 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
1716 *stencil_ref = device->stencil_ref;
1719 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1720 UINT buffer_count, ID3D11Buffer **buffers)
1722 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1723 unsigned int i;
1725 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1727 wined3d_mutex_lock();
1728 for (i = 0; i < buffer_count; ++i)
1730 struct wined3d_buffer *wined3d_buffer;
1731 struct d3d_buffer *buffer_impl;
1733 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1735 buffers[i] = NULL;
1736 continue;
1739 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1740 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1741 ID3D11Buffer_AddRef(buffers[i]);
1743 wined3d_mutex_unlock();
1746 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1747 ID3D11RasterizerState **rasterizer_state)
1749 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1751 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1753 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D11RasterizerState_iface : NULL))
1754 ID3D11RasterizerState_AddRef(*rasterizer_state);
1757 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
1758 UINT *viewport_count, D3D11_VIEWPORT *viewports)
1760 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1761 struct wined3d_viewport wined3d_vp;
1763 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1765 if (!viewports)
1767 *viewport_count = 1;
1768 return;
1771 if (!*viewport_count)
1772 return;
1774 wined3d_mutex_lock();
1775 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1776 wined3d_mutex_unlock();
1778 viewports[0].TopLeftX = wined3d_vp.x;
1779 viewports[0].TopLeftY = wined3d_vp.y;
1780 viewports[0].Width = wined3d_vp.width;
1781 viewports[0].Height = wined3d_vp.height;
1782 viewports[0].MinDepth = wined3d_vp.min_z;
1783 viewports[0].MaxDepth = wined3d_vp.max_z;
1785 if (*viewport_count > 1)
1786 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1789 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
1790 UINT *rect_count, D3D11_RECT *rects)
1792 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1794 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1796 if (!rects)
1798 *rect_count = 1;
1799 return;
1802 if (!*rect_count)
1803 return;
1805 wined3d_mutex_lock();
1806 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1807 wined3d_mutex_unlock();
1808 if (*rect_count > 1)
1809 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1812 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
1813 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1815 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1818 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
1819 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1821 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1822 iface, shader, class_instances, class_instance_count);
1825 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
1826 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1828 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1829 iface, start_slot, sampler_count, samplers);
1832 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
1833 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1835 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1836 iface, start_slot, buffer_count, buffers);
1839 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
1840 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1842 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1843 iface, start_slot, view_count, views);
1846 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
1847 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1849 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1850 iface, shader, class_instances, class_instance_count);
1853 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
1854 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1856 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1857 iface, start_slot, sampler_count, samplers);
1860 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
1861 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1863 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1864 iface, start_slot, buffer_count, buffers);
1867 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
1868 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1870 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1873 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
1874 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
1876 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1879 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
1880 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1882 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1883 iface, shader, class_instances, class_instance_count);
1886 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
1887 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1889 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1890 iface, start_slot, sampler_count, samplers);
1893 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
1894 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1896 FIXME("iface %p, start_slot %u, buffer_count %u, buffer %p stub!\n",
1897 iface, start_slot, buffer_count, buffers);
1900 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
1902 FIXME("iface %p stub!\n", iface);
1905 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
1907 FIXME("iface %p stub!\n", iface);
1910 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
1912 TRACE("iface %p.\n", iface);
1914 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
1917 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
1919 FIXME("iface %p stub!\n", iface);
1921 return 0;
1924 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
1925 BOOL restore, ID3D11CommandList **command_list)
1927 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
1929 return E_NOTIMPL;
1932 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
1934 /* IUnknown methods */
1935 d3d11_immediate_context_QueryInterface,
1936 d3d11_immediate_context_AddRef,
1937 d3d11_immediate_context_Release,
1938 /* ID3D11DeviceChild methods */
1939 d3d11_immediate_context_GetDevice,
1940 d3d11_immediate_context_GetPrivateData,
1941 d3d11_immediate_context_SetPrivateData,
1942 d3d11_immediate_context_SetPrivateDataInterface,
1943 /* ID3D11DeviceContext methods */
1944 d3d11_immediate_context_VSSetConstantBuffers,
1945 d3d11_immediate_context_PSSetShaderResources,
1946 d3d11_immediate_context_PSSetShader,
1947 d3d11_immediate_context_PSSetSamplers,
1948 d3d11_immediate_context_VSSetShader,
1949 d3d11_immediate_context_DrawIndexed,
1950 d3d11_immediate_context_Draw,
1951 d3d11_immediate_context_Map,
1952 d3d11_immediate_context_Unmap,
1953 d3d11_immediate_context_PSSetConstantBuffers,
1954 d3d11_immediate_context_IASetInputLayout,
1955 d3d11_immediate_context_IASetVertexBuffers,
1956 d3d11_immediate_context_IASetIndexBuffer,
1957 d3d11_immediate_context_DrawIndexedInstanced,
1958 d3d11_immediate_context_DrawInstanced,
1959 d3d11_immediate_context_GSSetConstantBuffers,
1960 d3d11_immediate_context_GSSetShader,
1961 d3d11_immediate_context_IASetPrimitiveTopology,
1962 d3d11_immediate_context_VSSetShaderResources,
1963 d3d11_immediate_context_VSSetSamplers,
1964 d3d11_immediate_context_Begin,
1965 d3d11_immediate_context_End,
1966 d3d11_immediate_context_GetData,
1967 d3d11_immediate_context_SetPredication,
1968 d3d11_immediate_context_GSSetShaderResources,
1969 d3d11_immediate_context_GSSetSamplers,
1970 d3d11_immediate_context_OMSetRenderTargets,
1971 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
1972 d3d11_immediate_context_OMSetBlendState,
1973 d3d11_immediate_context_OMSetDepthStencilState,
1974 d3d11_immediate_context_SOSetTargets,
1975 d3d11_immediate_context_DrawAuto,
1976 d3d11_immediate_context_DrawIndexedInstancedIndirect,
1977 d3d11_immediate_context_DrawInstancedIndirect,
1978 d3d11_immediate_context_Dispatch,
1979 d3d11_immediate_context_DispatchIndirect,
1980 d3d11_immediate_context_RSSetState,
1981 d3d11_immediate_context_RSSetViewports,
1982 d3d11_immediate_context_RSSetScissorRects,
1983 d3d11_immediate_context_CopySubresourceRegion,
1984 d3d11_immediate_context_CopyResource,
1985 d3d11_immediate_context_UpdateSubresource,
1986 d3d11_immediate_context_CopyStructureCount,
1987 d3d11_immediate_context_ClearRenderTargetView,
1988 d3d11_immediate_context_ClearUnorderedAccessViewUint,
1989 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
1990 d3d11_immediate_context_ClearDepthStencilView,
1991 d3d11_immediate_context_GenerateMips,
1992 d3d11_immediate_context_SetResourceMinLOD,
1993 d3d11_immediate_context_GetResourceMinLOD,
1994 d3d11_immediate_context_ResolveSubresource,
1995 d3d11_immediate_context_ExecuteCommandList,
1996 d3d11_immediate_context_HSSetShaderResources,
1997 d3d11_immediate_context_HSSetShader,
1998 d3d11_immediate_context_HSSetSamplers,
1999 d3d11_immediate_context_HSSetConstantBuffers,
2000 d3d11_immediate_context_DSSetShaderResources,
2001 d3d11_immediate_context_DSSetShader,
2002 d3d11_immediate_context_DSSetSamplers,
2003 d3d11_immediate_context_DSSetConstantBuffers,
2004 d3d11_immediate_context_CSSetShaderResources,
2005 d3d11_immediate_context_CSSetUnorderedAccessViews,
2006 d3d11_immediate_context_CSSetShader,
2007 d3d11_immediate_context_CSSetSamplers,
2008 d3d11_immediate_context_CSSetConstantBuffers,
2009 d3d11_immediate_context_VSGetConstantBuffers,
2010 d3d11_immediate_context_PSGetShaderResources,
2011 d3d11_immediate_context_PSGetShader,
2012 d3d11_immediate_context_PSGetSamplers,
2013 d3d11_immediate_context_VSGetShader,
2014 d3d11_immediate_context_PSGetConstantBuffers,
2015 d3d11_immediate_context_IAGetInputLayout,
2016 d3d11_immediate_context_IAGetVertexBuffers,
2017 d3d11_immediate_context_IAGetIndexBuffer,
2018 d3d11_immediate_context_GSGetConstantBuffers,
2019 d3d11_immediate_context_GSGetShader,
2020 d3d11_immediate_context_IAGetPrimitiveTopology,
2021 d3d11_immediate_context_VSGetShaderResources,
2022 d3d11_immediate_context_VSGetSamplers,
2023 d3d11_immediate_context_GetPredication,
2024 d3d11_immediate_context_GSGetShaderResources,
2025 d3d11_immediate_context_GSGetSamplers,
2026 d3d11_immediate_context_OMGetRenderTargets,
2027 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2028 d3d11_immediate_context_OMGetBlendState,
2029 d3d11_immediate_context_OMGetDepthStencilState,
2030 d3d11_immediate_context_SOGetTargets,
2031 d3d11_immediate_context_RSGetState,
2032 d3d11_immediate_context_RSGetViewports,
2033 d3d11_immediate_context_RSGetScissorRects,
2034 d3d11_immediate_context_HSGetShaderResources,
2035 d3d11_immediate_context_HSGetShader,
2036 d3d11_immediate_context_HSGetSamplers,
2037 d3d11_immediate_context_HSGetConstantBuffers,
2038 d3d11_immediate_context_DSGetShaderResources,
2039 d3d11_immediate_context_DSGetShader,
2040 d3d11_immediate_context_DSGetSamplers,
2041 d3d11_immediate_context_DSGetConstantBuffers,
2042 d3d11_immediate_context_CSGetShaderResources,
2043 d3d11_immediate_context_CSGetUnorderedAccessViews,
2044 d3d11_immediate_context_CSGetShader,
2045 d3d11_immediate_context_CSGetSamplers,
2046 d3d11_immediate_context_CSGetConstantBuffers,
2047 d3d11_immediate_context_ClearState,
2048 d3d11_immediate_context_Flush,
2049 d3d11_immediate_context_GetType,
2050 d3d11_immediate_context_GetContextFlags,
2051 d3d11_immediate_context_FinishCommandList,
2054 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2056 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2057 context->refcount = 1;
2059 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2061 wined3d_private_store_init(&context->private_store);
2064 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2066 wined3d_private_store_cleanup(&context->private_store);
2069 /* ID3D11Device methods */
2071 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2073 struct d3d_device *device = impl_from_ID3D11Device(iface);
2074 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2077 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2079 struct d3d_device *device = impl_from_ID3D11Device(iface);
2080 return IUnknown_AddRef(device->outer_unk);
2083 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2085 struct d3d_device *device = impl_from_ID3D11Device(iface);
2086 return IUnknown_Release(device->outer_unk);
2089 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2090 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2092 struct d3d_device *device = impl_from_ID3D11Device(iface);
2093 struct d3d_buffer *object;
2094 HRESULT hr;
2096 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2098 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2099 return hr;
2101 *buffer = &object->ID3D11Buffer_iface;
2103 return S_OK;
2106 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2107 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2109 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2111 return E_NOTIMPL;
2114 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2115 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2117 struct d3d_device *device = impl_from_ID3D11Device(iface);
2118 struct d3d_texture2d *object;
2119 HRESULT hr;
2121 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2123 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2124 return hr;
2126 *texture = &object->ID3D11Texture2D_iface;
2128 return S_OK;
2131 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2132 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2134 struct d3d_device *device = impl_from_ID3D11Device(iface);
2135 struct d3d_texture3d *object;
2136 HRESULT hr;
2138 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2140 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2141 return hr;
2143 *texture = &object->ID3D11Texture3D_iface;
2145 return S_OK;
2148 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2149 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2151 struct d3d_device *device = impl_from_ID3D11Device(iface);
2152 struct d3d_shader_resource_view *object;
2153 HRESULT hr;
2155 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2157 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2158 return hr;
2160 *view = &object->ID3D11ShaderResourceView_iface;
2162 return S_OK;
2165 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2166 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2168 struct d3d_device *device = impl_from_ID3D11Device(iface);
2169 struct d3d11_unordered_access_view *object;
2170 HRESULT hr;
2172 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2174 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2175 return hr;
2177 *view = &object->ID3D11UnorderedAccessView_iface;
2179 return S_OK;
2182 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2183 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2185 struct d3d_device *device = impl_from_ID3D11Device(iface);
2186 struct d3d_rendertarget_view *object;
2187 HRESULT hr;
2189 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2191 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2192 return hr;
2194 *view = &object->ID3D11RenderTargetView_iface;
2196 return S_OK;
2199 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2200 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2202 struct d3d_device *device = impl_from_ID3D11Device(iface);
2203 struct d3d_depthstencil_view *object;
2204 HRESULT hr;
2206 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2208 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2209 return hr;
2211 *view = &object->ID3D11DepthStencilView_iface;
2213 return S_OK;
2216 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2217 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2218 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2220 struct d3d_device *device = impl_from_ID3D11Device(iface);
2221 struct d3d_input_layout *object;
2222 HRESULT hr;
2224 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2225 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2226 shader_byte_code_length, input_layout);
2228 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2229 shader_byte_code, shader_byte_code_length, &object)))
2230 return hr;
2232 *input_layout = &object->ID3D11InputLayout_iface;
2234 return S_OK;
2237 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2238 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2240 struct d3d_device *device = impl_from_ID3D11Device(iface);
2241 struct d3d_vertex_shader *object;
2242 HRESULT hr;
2244 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2245 iface, byte_code, byte_code_length, class_linkage, shader);
2247 if (class_linkage)
2248 FIXME("Class linkage is not implemented yet.\n");
2250 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2251 return hr;
2253 *shader = &object->ID3D11VertexShader_iface;
2255 return S_OK;
2258 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2259 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2261 struct d3d_device *device = impl_from_ID3D11Device(iface);
2262 struct d3d_geometry_shader *object;
2263 HRESULT hr;
2265 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2266 iface, byte_code, byte_code_length, class_linkage, shader);
2268 if (class_linkage)
2269 FIXME("Class linkage is not implemented yet.\n");
2271 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
2272 return hr;
2274 *shader = &object->ID3D11GeometryShader_iface;
2276 return S_OK;
2279 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2280 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2281 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
2282 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2284 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2285 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
2286 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2287 rasterized_stream, class_linkage, shader);
2289 return E_NOTIMPL;
2292 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2293 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2295 struct d3d_device *device = impl_from_ID3D11Device(iface);
2296 struct d3d_pixel_shader *object;
2297 HRESULT hr;
2299 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2300 iface, byte_code, byte_code_length, class_linkage, shader);
2302 if (class_linkage)
2303 FIXME("Class linkage is not implemented yet.\n");
2305 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2306 return hr;
2308 *shader = &object->ID3D11PixelShader_iface;
2310 return S_OK;
2313 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2314 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2316 struct d3d_device *device = impl_from_ID3D11Device(iface);
2317 struct d3d11_hull_shader *object;
2318 HRESULT hr;
2320 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2321 iface, byte_code, byte_code_length, class_linkage, shader);
2323 if (class_linkage)
2324 FIXME("Class linkage is not implemented yet.\n");
2326 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2327 return hr;
2329 *shader = &object->ID3D11HullShader_iface;
2331 return S_OK;
2334 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2335 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2337 struct d3d_device *device = impl_from_ID3D11Device(iface);
2338 struct d3d11_domain_shader *object;
2339 HRESULT hr;
2341 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2342 iface, byte_code, byte_code_length, class_linkage, shader);
2344 if (class_linkage)
2345 FIXME("Class linkage is not implemented yet.\n");
2347 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2348 return hr;
2350 *shader = &object->ID3D11DomainShader_iface;
2352 return S_OK;
2355 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2356 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2358 struct d3d_device *device = impl_from_ID3D11Device(iface);
2359 struct d3d11_compute_shader *object;
2360 HRESULT hr;
2362 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2363 iface, byte_code, byte_code_length, class_linkage, shader);
2365 if (class_linkage)
2366 FIXME("Class linkage is not implemented yet.\n");
2368 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
2369 return hr;
2371 *shader = &object->ID3D11ComputeShader_iface;
2373 return S_OK;
2376 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2377 ID3D11ClassLinkage **class_linkage)
2379 struct d3d_device *device = impl_from_ID3D11Device(iface);
2380 struct d3d11_class_linkage *object;
2381 HRESULT hr;
2383 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
2385 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
2386 return hr;
2388 *class_linkage = &object->ID3D11ClassLinkage_iface;
2390 return S_OK;
2393 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
2394 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
2396 struct d3d_device *device = impl_from_ID3D11Device(iface);
2397 struct d3d_blend_state *object;
2398 struct wine_rb_entry *entry;
2399 D3D11_BLEND_DESC tmp_desc;
2400 unsigned int i, j;
2401 HRESULT hr;
2403 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2405 if (!desc)
2406 return E_INVALIDARG;
2408 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
2409 * D3D11_BLEND_DESC as a key in the rbtree. */
2410 memset(&tmp_desc, 0, sizeof(tmp_desc));
2411 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
2412 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
2413 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2415 j = desc->IndependentBlendEnable ? i : 0;
2416 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
2417 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
2418 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
2419 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
2420 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
2421 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
2422 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
2423 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
2426 wined3d_mutex_lock();
2427 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
2429 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
2431 TRACE("Returning existing blend state %p.\n", object);
2432 *blend_state = &object->ID3D11BlendState_iface;
2433 ID3D11BlendState_AddRef(*blend_state);
2434 wined3d_mutex_unlock();
2436 return S_OK;
2438 wined3d_mutex_unlock();
2440 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2441 return E_OUTOFMEMORY;
2443 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
2445 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2446 HeapFree(GetProcessHeap(), 0, object);
2447 return hr;
2450 TRACE("Created blend state %p.\n", object);
2451 *blend_state = &object->ID3D11BlendState_iface;
2453 return S_OK;
2456 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
2457 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
2459 struct d3d_device *device = impl_from_ID3D11Device(iface);
2460 struct d3d_depthstencil_state *object;
2461 D3D11_DEPTH_STENCIL_DESC tmp_desc;
2462 struct wine_rb_entry *entry;
2463 HRESULT hr;
2465 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2467 if (!desc)
2468 return E_INVALIDARG;
2470 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2471 * it as a key in the rbtree. */
2472 memset(&tmp_desc, 0, sizeof(tmp_desc));
2473 tmp_desc.DepthEnable = desc->DepthEnable;
2474 if (desc->DepthEnable)
2476 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2477 tmp_desc.DepthFunc = desc->DepthFunc;
2479 else
2481 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2482 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
2484 tmp_desc.StencilEnable = desc->StencilEnable;
2485 if (desc->StencilEnable)
2487 tmp_desc.StencilReadMask = desc->StencilReadMask;
2488 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2489 tmp_desc.FrontFace = desc->FrontFace;
2490 tmp_desc.BackFace = desc->BackFace;
2492 else
2494 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2495 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2496 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2497 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2498 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2499 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2500 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2501 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2502 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2503 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2506 wined3d_mutex_lock();
2507 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
2509 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
2511 TRACE("Returning existing depthstencil state %p.\n", object);
2512 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2513 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
2514 wined3d_mutex_unlock();
2516 return S_OK;
2518 wined3d_mutex_unlock();
2520 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2521 return E_OUTOFMEMORY;
2523 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
2525 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
2526 HeapFree(GetProcessHeap(), 0, object);
2527 return hr;
2530 TRACE("Created depthstencil state %p.\n", object);
2531 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2533 return S_OK;
2536 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
2537 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
2539 struct d3d_device *device = impl_from_ID3D11Device(iface);
2540 struct d3d_rasterizer_state *object;
2541 struct wine_rb_entry *entry;
2542 HRESULT hr;
2544 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2546 if (!desc)
2547 return E_INVALIDARG;
2549 wined3d_mutex_lock();
2550 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
2552 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
2554 TRACE("Returning existing rasterizer state %p.\n", object);
2555 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2556 ID3D11RasterizerState_AddRef(*rasterizer_state);
2557 wined3d_mutex_unlock();
2559 return S_OK;
2561 wined3d_mutex_unlock();
2563 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2564 return E_OUTOFMEMORY;
2566 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
2568 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
2569 HeapFree(GetProcessHeap(), 0, object);
2570 return hr;
2573 TRACE("Created rasterizer state %p.\n", object);
2574 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2576 return S_OK;
2579 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
2580 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
2582 struct d3d_device *device = impl_from_ID3D11Device(iface);
2583 D3D11_SAMPLER_DESC normalized_desc;
2584 struct d3d_sampler_state *object;
2585 struct wine_rb_entry *entry;
2586 HRESULT hr;
2588 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2590 if (!desc)
2591 return E_INVALIDARG;
2593 normalized_desc = *desc;
2594 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
2595 normalized_desc.MaxAnisotropy = 0;
2596 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
2597 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
2598 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
2599 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
2600 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
2601 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
2603 wined3d_mutex_lock();
2604 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
2606 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
2608 TRACE("Returning existing sampler state %p.\n", object);
2609 *sampler_state = &object->ID3D11SamplerState_iface;
2610 ID3D11SamplerState_AddRef(*sampler_state);
2611 wined3d_mutex_unlock();
2613 return S_OK;
2615 wined3d_mutex_unlock();
2617 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2618 return E_OUTOFMEMORY;
2620 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
2622 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2623 HeapFree(GetProcessHeap(), 0, object);
2624 return hr;
2627 TRACE("Created sampler state %p.\n", object);
2628 *sampler_state = &object->ID3D11SamplerState_iface;
2630 return S_OK;
2633 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
2634 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
2636 struct d3d_device *device = impl_from_ID3D11Device(iface);
2637 struct d3d_query *object;
2638 HRESULT hr;
2640 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2642 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
2643 return hr;
2645 if (query)
2647 *query = &object->ID3D11Query_iface;
2648 return S_OK;
2651 ID3D11Query_Release(&object->ID3D11Query_iface);
2652 return S_FALSE;
2655 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
2656 ID3D11Predicate **predicate)
2658 struct d3d_device *device = impl_from_ID3D11Device(iface);
2659 struct d3d_query *object;
2660 HRESULT hr;
2662 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2664 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
2665 return hr;
2667 if (predicate)
2669 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
2670 return S_OK;
2673 ID3D11Query_Release(&object->ID3D11Query_iface);
2674 return S_FALSE;
2677 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2678 ID3D11Counter **counter)
2680 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2682 return E_NOTIMPL;
2685 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
2686 ID3D11DeviceContext **context)
2688 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
2690 return E_NOTIMPL;
2693 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
2694 void **out)
2696 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
2698 return E_NOTIMPL;
2701 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
2702 UINT *format_support)
2704 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
2706 return E_NOTIMPL;
2709 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
2710 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2712 struct d3d_device *device = impl_from_ID3D11Device(iface);
2713 struct wined3d_device_creation_parameters params;
2714 struct wined3d *wined3d;
2715 HRESULT hr;
2717 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
2718 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2720 if (!quality_level_count)
2721 return E_INVALIDARG;
2723 *quality_level_count = 0;
2725 if (!sample_count)
2726 return E_FAIL;
2727 if (sample_count == 1)
2729 *quality_level_count = 1;
2730 return S_OK;
2732 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
2733 return E_FAIL;
2735 wined3d_mutex_lock();
2736 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
2737 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
2738 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
2739 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
2740 wined3d_mutex_unlock();
2742 if (hr == WINED3DERR_INVALIDCALL)
2743 return E_INVALIDARG;
2744 if (hr == WINED3DERR_NOTAVAILABLE)
2745 return S_OK;
2746 return hr;
2749 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
2751 FIXME("iface %p, info %p stub!\n", iface, info);
2754 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2755 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
2756 char *units, UINT *units_length, char *description, UINT *description_length)
2758 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
2759 "units %p, units_length %p, description %p, description_length %p stub!\n",
2760 iface, desc, type, active_counter_count, name, name_length,
2761 units, units_length, description, description_length);
2763 return E_NOTIMPL;
2766 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
2767 void *feature_support_data, UINT feature_support_data_size)
2769 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
2770 iface, feature, feature_support_data, feature_support_data_size);
2772 switch (feature)
2774 case D3D11_FEATURE_THREADING:
2776 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
2777 if (feature_support_data_size != sizeof(*threading_data))
2779 WARN("Invalid data size.\n");
2780 return E_INVALIDARG;
2783 threading_data->DriverConcurrentCreates = FALSE;
2784 threading_data->DriverCommandLists = FALSE;
2785 return S_OK;
2788 default:
2789 FIXME("Unhandled feature %#x.\n", feature);
2790 return E_NOTIMPL;
2794 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
2795 UINT *data_size, void *data)
2797 IDXGIDevice *dxgi_device;
2798 HRESULT hr;
2800 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2802 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2803 return hr;
2804 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
2805 IDXGIDevice_Release(dxgi_device);
2807 return hr;
2810 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
2811 UINT data_size, const void *data)
2813 IDXGIDevice *dxgi_device;
2814 HRESULT hr;
2816 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2818 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2819 return hr;
2820 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
2821 IDXGIDevice_Release(dxgi_device);
2823 return hr;
2826 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
2827 const IUnknown *data)
2829 IDXGIDevice *dxgi_device;
2830 HRESULT hr;
2832 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
2834 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2835 return hr;
2836 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
2837 IDXGIDevice_Release(dxgi_device);
2839 return hr;
2842 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
2844 struct d3d_device *device = impl_from_ID3D11Device(iface);
2846 TRACE("iface %p.\n", iface);
2848 return device->feature_level;
2851 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
2853 FIXME("iface %p stub!\n", iface);
2855 return 0;
2858 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
2860 FIXME("iface %p stub!\n", iface);
2862 return S_OK;
2865 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
2866 ID3D11DeviceContext **immediate_context)
2868 struct d3d_device *device = impl_from_ID3D11Device(iface);
2870 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
2872 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
2873 ID3D11DeviceContext_AddRef(*immediate_context);
2876 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
2878 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2880 return E_NOTIMPL;
2883 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
2885 FIXME("iface %p stub!\n", iface);
2887 return 0;
2890 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
2892 /* IUnknown methods */
2893 d3d11_device_QueryInterface,
2894 d3d11_device_AddRef,
2895 d3d11_device_Release,
2896 /* ID3D11Device methods */
2897 d3d11_device_CreateBuffer,
2898 d3d11_device_CreateTexture1D,
2899 d3d11_device_CreateTexture2D,
2900 d3d11_device_CreateTexture3D,
2901 d3d11_device_CreateShaderResourceView,
2902 d3d11_device_CreateUnorderedAccessView,
2903 d3d11_device_CreateRenderTargetView,
2904 d3d11_device_CreateDepthStencilView,
2905 d3d11_device_CreateInputLayout,
2906 d3d11_device_CreateVertexShader,
2907 d3d11_device_CreateGeometryShader,
2908 d3d11_device_CreateGeometryShaderWithStreamOutput,
2909 d3d11_device_CreatePixelShader,
2910 d3d11_device_CreateHullShader,
2911 d3d11_device_CreateDomainShader,
2912 d3d11_device_CreateComputeShader,
2913 d3d11_device_CreateClassLinkage,
2914 d3d11_device_CreateBlendState,
2915 d3d11_device_CreateDepthStencilState,
2916 d3d11_device_CreateRasterizerState,
2917 d3d11_device_CreateSamplerState,
2918 d3d11_device_CreateQuery,
2919 d3d11_device_CreatePredicate,
2920 d3d11_device_CreateCounter,
2921 d3d11_device_CreateDeferredContext,
2922 d3d11_device_OpenSharedResource,
2923 d3d11_device_CheckFormatSupport,
2924 d3d11_device_CheckMultisampleQualityLevels,
2925 d3d11_device_CheckCounterInfo,
2926 d3d11_device_CheckCounter,
2927 d3d11_device_CheckFeatureSupport,
2928 d3d11_device_GetPrivateData,
2929 d3d11_device_SetPrivateData,
2930 d3d11_device_SetPrivateDataInterface,
2931 d3d11_device_GetFeatureLevel,
2932 d3d11_device_GetCreationFlags,
2933 d3d11_device_GetDeviceRemovedReason,
2934 d3d11_device_GetImmediateContext,
2935 d3d11_device_SetExceptionMode,
2936 d3d11_device_GetExceptionMode,
2939 /* Inner IUnknown methods */
2941 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
2943 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
2946 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
2948 struct d3d_device *device = impl_from_IUnknown(iface);
2950 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
2952 if (IsEqualGUID(riid, &IID_ID3D11Device)
2953 || IsEqualGUID(riid, &IID_IUnknown))
2955 *out = &device->ID3D11Device_iface;
2957 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
2958 || IsEqualGUID(riid, &IID_ID3D10Device))
2960 *out = &device->ID3D10Device1_iface;
2962 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
2964 *out = &device->ID3D10Multithread_iface;
2966 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
2968 *out = &device->IWineDXGIDeviceParent_iface;
2970 else
2972 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
2973 *out = NULL;
2974 return E_NOINTERFACE;
2977 IUnknown_AddRef((IUnknown *)*out);
2978 return S_OK;
2981 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
2983 struct d3d_device *device = impl_from_IUnknown(iface);
2984 ULONG refcount = InterlockedIncrement(&device->refcount);
2986 TRACE("%p increasing refcount to %u.\n", device, refcount);
2988 return refcount;
2991 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
2993 struct d3d_device *device = impl_from_IUnknown(iface);
2994 ULONG refcount = InterlockedDecrement(&device->refcount);
2996 TRACE("%p decreasing refcount to %u.\n", device, refcount);
2998 if (!refcount)
3000 d3d11_immediate_context_destroy(&device->immediate_context);
3001 if (device->wined3d_device)
3003 wined3d_mutex_lock();
3004 wined3d_device_decref(device->wined3d_device);
3005 wined3d_mutex_unlock();
3007 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3008 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3009 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3010 wine_rb_destroy(&device->blend_states, NULL, NULL);
3013 return refcount;
3016 /* IUnknown methods */
3018 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3019 void **ppv)
3021 struct d3d_device *device = impl_from_ID3D10Device(iface);
3022 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3025 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3027 struct d3d_device *device = impl_from_ID3D10Device(iface);
3028 return IUnknown_AddRef(device->outer_unk);
3031 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3033 struct d3d_device *device = impl_from_ID3D10Device(iface);
3034 return IUnknown_Release(device->outer_unk);
3037 /* ID3D10Device methods */
3039 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3040 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3042 struct d3d_device *device = impl_from_ID3D10Device(iface);
3043 unsigned int i;
3045 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3046 iface, start_slot, buffer_count, buffers);
3048 wined3d_mutex_lock();
3049 for (i = 0; i < buffer_count; ++i)
3051 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3053 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3054 buffer ? buffer->wined3d_buffer : NULL);
3056 wined3d_mutex_unlock();
3059 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3060 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3062 struct d3d_device *device = impl_from_ID3D10Device(iface);
3063 unsigned int i;
3065 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3066 iface, start_slot, view_count, views);
3068 wined3d_mutex_lock();
3069 for (i = 0; i < view_count; ++i)
3071 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3073 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3074 view ? view->wined3d_view : NULL);
3076 wined3d_mutex_unlock();
3079 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3080 ID3D10PixelShader *shader)
3082 struct d3d_device *device = impl_from_ID3D10Device(iface);
3083 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3085 TRACE("iface %p, shader %p\n", iface, shader);
3087 wined3d_mutex_lock();
3088 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3089 wined3d_mutex_unlock();
3092 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3093 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3095 struct d3d_device *device = impl_from_ID3D10Device(iface);
3096 unsigned int i;
3098 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3099 iface, start_slot, sampler_count, samplers);
3101 wined3d_mutex_lock();
3102 for (i = 0; i < sampler_count; ++i)
3104 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3106 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3107 sampler ? sampler->wined3d_sampler : NULL);
3109 wined3d_mutex_unlock();
3112 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3113 ID3D10VertexShader *shader)
3115 struct d3d_device *device = impl_from_ID3D10Device(iface);
3116 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3118 TRACE("iface %p, shader %p\n", iface, shader);
3120 wined3d_mutex_lock();
3121 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3122 wined3d_mutex_unlock();
3125 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3126 UINT start_index_location, INT base_vertex_location)
3128 struct d3d_device *device = impl_from_ID3D10Device(iface);
3130 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3131 iface, index_count, start_index_location, base_vertex_location);
3133 wined3d_mutex_lock();
3134 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3135 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3136 wined3d_mutex_unlock();
3139 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3140 UINT start_vertex_location)
3142 struct d3d_device *device = impl_from_ID3D10Device(iface);
3144 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3145 iface, vertex_count, start_vertex_location);
3147 wined3d_mutex_lock();
3148 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3149 wined3d_mutex_unlock();
3152 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
3153 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3155 struct d3d_device *device = impl_from_ID3D10Device(iface);
3156 unsigned int i;
3158 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3159 iface, start_slot, buffer_count, buffers);
3161 wined3d_mutex_lock();
3162 for (i = 0; i < buffer_count; ++i)
3164 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3166 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
3167 buffer ? buffer->wined3d_buffer : NULL);
3169 wined3d_mutex_unlock();
3172 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3173 ID3D10InputLayout *input_layout)
3175 struct d3d_device *device = impl_from_ID3D10Device(iface);
3176 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3178 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3180 wined3d_mutex_lock();
3181 wined3d_device_set_vertex_declaration(device->wined3d_device,
3182 layout ? layout->wined3d_decl : NULL);
3183 wined3d_mutex_unlock();
3186 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3187 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3189 struct d3d_device *device = impl_from_ID3D10Device(iface);
3190 unsigned int i;
3192 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3193 iface, start_slot, buffer_count, buffers, strides, offsets);
3195 wined3d_mutex_lock();
3196 for (i = 0; i < buffer_count; ++i)
3198 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3200 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3201 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3203 wined3d_mutex_unlock();
3206 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3207 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3209 struct d3d_device *device = impl_from_ID3D10Device(iface);
3210 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3212 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3213 iface, buffer, debug_dxgi_format(format), offset);
3215 wined3d_mutex_lock();
3216 wined3d_device_set_index_buffer(device->wined3d_device,
3217 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3218 wined3dformat_from_dxgi_format(format), offset);
3219 wined3d_mutex_unlock();
3222 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3223 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3224 INT base_vertex_location, UINT start_instance_location)
3226 struct d3d_device *device = impl_from_ID3D10Device(iface);
3228 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3229 "base_vertex_location %d, start_instance_location %u.\n",
3230 iface, instance_index_count, instance_count, start_index_location,
3231 base_vertex_location, start_instance_location);
3233 wined3d_mutex_lock();
3234 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3235 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3236 instance_index_count, start_instance_location, instance_count);
3237 wined3d_mutex_unlock();
3240 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3241 UINT instance_vertex_count, UINT instance_count,
3242 UINT start_vertex_location, UINT start_instance_location)
3244 struct d3d_device *device = impl_from_ID3D10Device(iface);
3246 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3247 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3248 start_vertex_location, start_instance_location);
3250 wined3d_mutex_lock();
3251 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3252 instance_vertex_count, start_instance_location, instance_count);
3253 wined3d_mutex_unlock();
3256 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3257 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3259 struct d3d_device *device = impl_from_ID3D10Device(iface);
3260 unsigned int i;
3262 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3263 iface, start_slot, buffer_count, buffers);
3265 wined3d_mutex_lock();
3266 for (i = 0; i < buffer_count; ++i)
3268 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3270 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3271 buffer ? buffer->wined3d_buffer : NULL);
3273 wined3d_mutex_unlock();
3276 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3278 struct d3d_device *device = impl_from_ID3D10Device(iface);
3279 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3281 TRACE("iface %p, shader %p.\n", iface, shader);
3283 wined3d_mutex_lock();
3284 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3285 wined3d_mutex_unlock();
3288 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3289 D3D10_PRIMITIVE_TOPOLOGY topology)
3291 struct d3d_device *device = impl_from_ID3D10Device(iface);
3293 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
3295 wined3d_mutex_lock();
3296 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
3297 wined3d_mutex_unlock();
3300 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
3301 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3303 struct d3d_device *device = impl_from_ID3D10Device(iface);
3304 unsigned int i;
3306 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3307 iface, start_slot, view_count, views);
3309 wined3d_mutex_lock();
3310 for (i = 0; i < view_count; ++i)
3312 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3314 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
3315 view ? view->wined3d_view : NULL);
3317 wined3d_mutex_unlock();
3320 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
3321 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3323 struct d3d_device *device = impl_from_ID3D10Device(iface);
3324 unsigned int i;
3326 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3327 iface, start_slot, sampler_count, samplers);
3329 wined3d_mutex_lock();
3330 for (i = 0; i < sampler_count; ++i)
3332 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3334 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
3335 sampler ? sampler->wined3d_sampler : NULL);
3337 wined3d_mutex_unlock();
3340 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3342 struct d3d_device *device = impl_from_ID3D10Device(iface);
3343 struct d3d_query *query;
3345 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3347 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3348 wined3d_mutex_lock();
3349 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
3350 wined3d_mutex_unlock();
3353 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
3354 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3356 struct d3d_device *device = impl_from_ID3D10Device(iface);
3357 unsigned int i;
3359 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3360 iface, start_slot, view_count, views);
3362 wined3d_mutex_lock();
3363 for (i = 0; i < view_count; ++i)
3365 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3367 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
3368 view ? view->wined3d_view : NULL);
3370 wined3d_mutex_unlock();
3373 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
3374 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3376 struct d3d_device *device = impl_from_ID3D10Device(iface);
3377 unsigned int i;
3379 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3380 iface, start_slot, sampler_count, samplers);
3382 wined3d_mutex_lock();
3383 for (i = 0; i < sampler_count; ++i)
3385 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3387 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
3388 sampler ? sampler->wined3d_sampler : NULL);
3390 wined3d_mutex_unlock();
3393 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
3394 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
3395 ID3D10DepthStencilView *depth_stencil_view)
3397 struct d3d_device *device = impl_from_ID3D10Device(iface);
3398 struct d3d_depthstencil_view *dsv;
3399 unsigned int i;
3401 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3402 iface, render_target_view_count, render_target_views, depth_stencil_view);
3404 wined3d_mutex_lock();
3405 for (i = 0; i < render_target_view_count; ++i)
3407 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
3409 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
3410 rtv ? rtv->wined3d_view : NULL, FALSE);
3412 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3414 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
3417 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3418 wined3d_device_set_depth_stencil_view(device->wined3d_device,
3419 dsv ? dsv->wined3d_view : NULL);
3420 wined3d_mutex_unlock();
3423 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
3424 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
3426 struct d3d_device *device = impl_from_ID3D10Device(iface);
3427 struct d3d_blend_state *blend_state_object;
3429 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
3430 iface, blend_state, debug_float4(blend_factor), sample_mask);
3432 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
3433 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
3434 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
3437 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
3438 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
3440 struct d3d_device *device = impl_from_ID3D10Device(iface);
3441 struct d3d_depthstencil_state *ds_state_object;
3443 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
3444 iface, depth_stencil_state, stencil_ref);
3446 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
3447 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
3448 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
3451 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
3452 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
3454 struct d3d_device *device = impl_from_ID3D10Device(iface);
3455 unsigned int count, i;
3457 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
3459 count = min(target_count, 4);
3460 wined3d_mutex_lock();
3461 for (i = 0; i < count; ++i)
3463 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
3465 wined3d_device_set_stream_output(device->wined3d_device, i,
3466 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
3469 for (i = count; i < 4; ++i)
3471 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
3473 wined3d_mutex_unlock();
3476 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
3478 FIXME("iface %p stub!\n", iface);
3481 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
3483 struct d3d_device *device = impl_from_ID3D10Device(iface);
3484 struct d3d_rasterizer_state *rasterizer_state_object;
3486 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
3488 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
3489 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
3490 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
3493 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
3494 UINT viewport_count, const D3D10_VIEWPORT *viewports)
3496 struct d3d_device *device = impl_from_ID3D10Device(iface);
3497 struct wined3d_viewport wined3d_vp;
3499 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
3501 if (viewport_count > 1)
3502 FIXME("Multiple viewports not implemented.\n");
3504 if (!viewport_count)
3505 return;
3507 wined3d_vp.x = viewports[0].TopLeftX;
3508 wined3d_vp.y = viewports[0].TopLeftY;
3509 wined3d_vp.width = viewports[0].Width;
3510 wined3d_vp.height = viewports[0].Height;
3511 wined3d_vp.min_z = viewports[0].MinDepth;
3512 wined3d_vp.max_z = viewports[0].MaxDepth;
3514 wined3d_mutex_lock();
3515 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
3516 wined3d_mutex_unlock();
3519 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
3520 UINT rect_count, const D3D10_RECT *rects)
3522 struct d3d_device *device = impl_from_ID3D10Device(iface);
3524 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
3526 if (rect_count > 1)
3527 FIXME("Multiple scissor rects not implemented.\n");
3529 if (!rect_count)
3530 return;
3532 wined3d_mutex_lock();
3533 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
3534 wined3d_mutex_unlock();
3537 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
3538 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
3539 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
3541 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3542 struct d3d_device *device = impl_from_ID3D10Device(iface);
3543 struct wined3d_box wined3d_src_box;
3545 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
3546 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
3547 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
3548 src_resource, src_subresource_idx, src_box);
3550 if (src_box)
3552 wined3d_src_box.left = src_box->left;
3553 wined3d_src_box.top = src_box->top;
3554 wined3d_src_box.front = src_box->front;
3555 wined3d_src_box.right = src_box->right;
3556 wined3d_src_box.bottom = src_box->bottom;
3557 wined3d_src_box.back = src_box->back;
3560 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3561 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3562 wined3d_mutex_lock();
3563 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
3564 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
3565 wined3d_mutex_unlock();
3568 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
3569 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
3571 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3572 struct d3d_device *device = impl_from_ID3D10Device(iface);
3574 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
3576 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3577 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3578 wined3d_mutex_lock();
3579 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
3580 wined3d_mutex_unlock();
3583 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
3584 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
3585 const void *data, UINT row_pitch, UINT depth_pitch)
3587 struct d3d_device *device = impl_from_ID3D10Device(iface);
3588 ID3D11Resource *d3d11_resource;
3590 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
3591 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
3593 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
3594 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
3595 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
3596 ID3D11Resource_Release(d3d11_resource);
3599 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
3600 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
3602 struct d3d_device *device = impl_from_ID3D10Device(iface);
3603 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
3604 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
3605 HRESULT hr;
3607 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
3608 iface, render_target_view, debug_float4(color_rgba));
3610 if (!view)
3611 return;
3613 wined3d_mutex_lock();
3614 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3615 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
3616 ERR("Failed to clear view, hr %#x.\n", hr);
3617 wined3d_mutex_unlock();
3620 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
3621 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
3623 struct d3d_device *device = impl_from_ID3D10Device(iface);
3624 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3625 DWORD wined3d_flags;
3626 HRESULT hr;
3628 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
3629 iface, depth_stencil_view, flags, depth, stencil);
3631 if (!view)
3632 return;
3634 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
3636 wined3d_mutex_lock();
3637 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3638 wined3d_flags, NULL, depth, stencil)))
3639 ERR("Failed to clear view, hr %#x.\n", hr);
3640 wined3d_mutex_unlock();
3643 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
3644 ID3D10ShaderResourceView *shader_resource_view)
3646 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
3649 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
3650 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
3651 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
3653 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
3654 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
3655 iface, dst_resource, dst_subresource_idx,
3656 src_resource, src_subresource_idx, debug_dxgi_format(format));
3659 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
3660 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3662 struct d3d_device *device = impl_from_ID3D10Device(iface);
3663 unsigned int i;
3665 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3666 iface, start_slot, buffer_count, buffers);
3668 wined3d_mutex_lock();
3669 for (i = 0; i < buffer_count; ++i)
3671 struct wined3d_buffer *wined3d_buffer;
3672 struct d3d_buffer *buffer_impl;
3674 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
3676 buffers[i] = NULL;
3677 continue;
3680 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3681 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3682 ID3D10Buffer_AddRef(buffers[i]);
3684 wined3d_mutex_unlock();
3687 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
3688 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3690 struct d3d_device *device = impl_from_ID3D10Device(iface);
3691 unsigned int i;
3693 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3694 iface, start_slot, view_count, views);
3696 wined3d_mutex_lock();
3697 for (i = 0; i < view_count; ++i)
3699 struct wined3d_shader_resource_view *wined3d_view;
3700 struct d3d_shader_resource_view *view_impl;
3702 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
3704 views[i] = NULL;
3705 continue;
3708 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3709 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3710 ID3D10ShaderResourceView_AddRef(views[i]);
3712 wined3d_mutex_unlock();
3715 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
3717 struct d3d_device *device = impl_from_ID3D10Device(iface);
3718 struct d3d_pixel_shader *shader_impl;
3719 struct wined3d_shader *wined3d_shader;
3721 TRACE("iface %p, shader %p.\n", iface, shader);
3723 wined3d_mutex_lock();
3724 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
3726 wined3d_mutex_unlock();
3727 *shader = NULL;
3728 return;
3731 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3732 wined3d_mutex_unlock();
3733 *shader = &shader_impl->ID3D10PixelShader_iface;
3734 ID3D10PixelShader_AddRef(*shader);
3737 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
3738 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3740 struct d3d_device *device = impl_from_ID3D10Device(iface);
3741 unsigned int i;
3743 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3744 iface, start_slot, sampler_count, samplers);
3746 wined3d_mutex_lock();
3747 for (i = 0; i < sampler_count; ++i)
3749 struct d3d_sampler_state *sampler_impl;
3750 struct wined3d_sampler *wined3d_sampler;
3752 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
3754 samplers[i] = NULL;
3755 continue;
3758 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
3759 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
3760 ID3D10SamplerState_AddRef(samplers[i]);
3762 wined3d_mutex_unlock();
3765 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
3767 struct d3d_device *device = impl_from_ID3D10Device(iface);
3768 struct d3d_vertex_shader *shader_impl;
3769 struct wined3d_shader *wined3d_shader;
3771 TRACE("iface %p, shader %p.\n", iface, shader);
3773 wined3d_mutex_lock();
3774 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
3776 wined3d_mutex_unlock();
3777 *shader = NULL;
3778 return;
3781 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3782 wined3d_mutex_unlock();
3783 *shader = &shader_impl->ID3D10VertexShader_iface;
3784 ID3D10VertexShader_AddRef(*shader);
3787 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
3788 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3790 struct d3d_device *device = impl_from_ID3D10Device(iface);
3791 unsigned int i;
3793 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3794 iface, start_slot, buffer_count, buffers);
3796 wined3d_mutex_lock();
3797 for (i = 0; i < buffer_count; ++i)
3799 struct wined3d_buffer *wined3d_buffer;
3800 struct d3d_buffer *buffer_impl;
3802 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
3804 buffers[i] = NULL;
3805 continue;
3808 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3809 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3810 ID3D10Buffer_AddRef(buffers[i]);
3812 wined3d_mutex_unlock();
3815 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
3817 struct d3d_device *device = impl_from_ID3D10Device(iface);
3818 struct wined3d_vertex_declaration *wined3d_declaration;
3819 struct d3d_input_layout *input_layout_impl;
3821 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
3823 wined3d_mutex_lock();
3824 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
3826 wined3d_mutex_unlock();
3827 *input_layout = NULL;
3828 return;
3831 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
3832 wined3d_mutex_unlock();
3833 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
3834 ID3D10InputLayout_AddRef(*input_layout);
3837 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
3838 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, 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 wined3d_buffer *wined3d_buffer;
3850 struct d3d_buffer *buffer_impl;
3852 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
3853 &wined3d_buffer, &offsets[i], &strides[i])))
3854 ERR("Failed to get vertex buffer.\n");
3856 if (!wined3d_buffer)
3858 buffers[i] = NULL;
3859 continue;
3862 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3863 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3864 ID3D10Buffer_AddRef(buffers[i]);
3866 wined3d_mutex_unlock();
3869 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
3870 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
3872 struct d3d_device *device = impl_from_ID3D10Device(iface);
3873 enum wined3d_format_id wined3d_format;
3874 struct wined3d_buffer *wined3d_buffer;
3875 struct d3d_buffer *buffer_impl;
3877 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
3879 wined3d_mutex_lock();
3880 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
3881 *format = dxgi_format_from_wined3dformat(wined3d_format);
3882 if (!wined3d_buffer)
3884 wined3d_mutex_unlock();
3885 *buffer = NULL;
3886 return;
3889 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3890 wined3d_mutex_unlock();
3891 *buffer = &buffer_impl->ID3D10Buffer_iface;
3892 ID3D10Buffer_AddRef(*buffer);
3895 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
3896 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3898 struct d3d_device *device = impl_from_ID3D10Device(iface);
3899 unsigned int i;
3901 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3902 iface, start_slot, buffer_count, buffers);
3904 wined3d_mutex_lock();
3905 for (i = 0; i < buffer_count; ++i)
3907 struct wined3d_buffer *wined3d_buffer;
3908 struct d3d_buffer *buffer_impl;
3910 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
3912 buffers[i] = NULL;
3913 continue;
3916 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3917 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3918 ID3D10Buffer_AddRef(buffers[i]);
3920 wined3d_mutex_unlock();
3923 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
3925 struct d3d_device *device = impl_from_ID3D10Device(iface);
3926 struct d3d_geometry_shader *shader_impl;
3927 struct wined3d_shader *wined3d_shader;
3929 TRACE("iface %p, shader %p.\n", iface, shader);
3931 wined3d_mutex_lock();
3932 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
3934 wined3d_mutex_unlock();
3935 *shader = NULL;
3936 return;
3939 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3940 wined3d_mutex_unlock();
3941 *shader = &shader_impl->ID3D10GeometryShader_iface;
3942 ID3D10GeometryShader_AddRef(*shader);
3945 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
3946 D3D10_PRIMITIVE_TOPOLOGY *topology)
3948 struct d3d_device *device = impl_from_ID3D10Device(iface);
3950 TRACE("iface %p, topology %p\n", iface, topology);
3952 wined3d_mutex_lock();
3953 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
3954 wined3d_mutex_unlock();
3957 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
3958 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3960 struct d3d_device *device = impl_from_ID3D10Device(iface);
3961 unsigned int i;
3963 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3964 iface, start_slot, view_count, views);
3966 wined3d_mutex_lock();
3967 for (i = 0; i < view_count; ++i)
3969 struct wined3d_shader_resource_view *wined3d_view;
3970 struct d3d_shader_resource_view *view_impl;
3972 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
3974 views[i] = NULL;
3975 continue;
3978 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3979 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3980 ID3D10ShaderResourceView_AddRef(views[i]);
3982 wined3d_mutex_unlock();
3985 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
3986 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3988 struct d3d_device *device = impl_from_ID3D10Device(iface);
3989 unsigned int i;
3991 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3992 iface, start_slot, sampler_count, samplers);
3994 wined3d_mutex_lock();
3995 for (i = 0; i < sampler_count; ++i)
3997 struct d3d_sampler_state *sampler_impl;
3998 struct wined3d_sampler *wined3d_sampler;
4000 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4002 samplers[i] = NULL;
4003 continue;
4006 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4007 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4008 ID3D10SamplerState_AddRef(samplers[i]);
4010 wined3d_mutex_unlock();
4013 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4014 ID3D10Predicate **predicate, BOOL *value)
4016 struct d3d_device *device = impl_from_ID3D10Device(iface);
4017 struct wined3d_query *wined3d_predicate;
4018 struct d3d_query *predicate_impl;
4020 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4022 wined3d_mutex_lock();
4023 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4025 wined3d_mutex_unlock();
4026 *predicate = NULL;
4027 return;
4030 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4031 wined3d_mutex_unlock();
4032 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4033 ID3D10Predicate_AddRef(*predicate);
4036 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4037 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4039 struct d3d_device *device = impl_from_ID3D10Device(iface);
4040 unsigned int i;
4042 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4043 iface, start_slot, view_count, views);
4045 wined3d_mutex_lock();
4046 for (i = 0; i < view_count; ++i)
4048 struct wined3d_shader_resource_view *wined3d_view;
4049 struct d3d_shader_resource_view *view_impl;
4051 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4053 views[i] = NULL;
4054 continue;
4057 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4058 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4059 ID3D10ShaderResourceView_AddRef(views[i]);
4061 wined3d_mutex_unlock();
4064 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4065 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4067 struct d3d_device *device = impl_from_ID3D10Device(iface);
4068 unsigned int i;
4070 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4071 iface, start_slot, sampler_count, samplers);
4073 wined3d_mutex_lock();
4074 for (i = 0; i < sampler_count; ++i)
4076 struct d3d_sampler_state *sampler_impl;
4077 struct wined3d_sampler *wined3d_sampler;
4079 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4081 samplers[i] = NULL;
4082 continue;
4085 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4086 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4087 ID3D10SamplerState_AddRef(samplers[i]);
4089 wined3d_mutex_unlock();
4092 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4093 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4095 struct d3d_device *device = impl_from_ID3D10Device(iface);
4096 struct wined3d_rendertarget_view *wined3d_view;
4098 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4099 iface, view_count, render_target_views, depth_stencil_view);
4101 wined3d_mutex_lock();
4102 if (render_target_views)
4104 struct d3d_rendertarget_view *view_impl;
4105 unsigned int i;
4107 for (i = 0; i < view_count; ++i)
4109 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4110 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4112 render_target_views[i] = NULL;
4113 continue;
4116 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4117 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4121 if (depth_stencil_view)
4123 struct d3d_depthstencil_view *view_impl;
4125 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4126 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4128 *depth_stencil_view = NULL;
4130 else
4132 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4133 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4136 wined3d_mutex_unlock();
4139 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4140 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4142 struct d3d_device *device = impl_from_ID3D10Device(iface);
4143 ID3D11BlendState *d3d11_blend_state;
4145 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4146 iface, blend_state, blend_factor, sample_mask);
4148 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4149 &d3d11_blend_state, blend_factor, sample_mask);
4151 if (d3d11_blend_state)
4152 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4153 else
4154 *blend_state = NULL;
4157 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4158 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4160 struct d3d_device *device = impl_from_ID3D10Device(iface);
4161 ID3D11DepthStencilState *d3d11_iface;
4163 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4164 iface, depth_stencil_state, stencil_ref);
4166 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4167 &d3d11_iface, stencil_ref);
4169 if (d3d11_iface)
4170 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4171 else
4172 *depth_stencil_state = NULL;
4175 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4176 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4178 struct d3d_device *device = impl_from_ID3D10Device(iface);
4179 unsigned int i;
4181 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4182 iface, buffer_count, buffers, offsets);
4184 wined3d_mutex_lock();
4185 for (i = 0; i < buffer_count; ++i)
4187 struct wined3d_buffer *wined3d_buffer;
4188 struct d3d_buffer *buffer_impl;
4190 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4192 buffers[i] = NULL;
4193 continue;
4196 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4197 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4198 ID3D10Buffer_AddRef(buffers[i]);
4200 wined3d_mutex_unlock();
4203 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4205 struct d3d_device *device = impl_from_ID3D10Device(iface);
4207 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4209 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
4210 ID3D10RasterizerState_AddRef(*rasterizer_state);
4213 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4214 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4216 struct d3d_device *device = impl_from_ID3D10Device(iface);
4217 struct wined3d_viewport wined3d_vp;
4219 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4221 if (!viewports)
4223 *viewport_count = 1;
4224 return;
4227 if (!*viewport_count)
4228 return;
4230 wined3d_mutex_lock();
4231 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4232 wined3d_mutex_unlock();
4234 viewports[0].TopLeftX = wined3d_vp.x;
4235 viewports[0].TopLeftY = wined3d_vp.y;
4236 viewports[0].Width = wined3d_vp.width;
4237 viewports[0].Height = wined3d_vp.height;
4238 viewports[0].MinDepth = wined3d_vp.min_z;
4239 viewports[0].MaxDepth = wined3d_vp.max_z;
4241 if (*viewport_count > 1)
4242 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4245 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4247 struct d3d_device *device = impl_from_ID3D10Device(iface);
4249 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4251 if (!rects)
4253 *rect_count = 1;
4254 return;
4257 if (!*rect_count)
4258 return;
4260 wined3d_mutex_lock();
4261 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4262 wined3d_mutex_unlock();
4263 if (*rect_count > 1)
4264 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4267 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4269 TRACE("iface %p.\n", iface);
4271 /* In the current implementation the device is never removed, so we can
4272 * just return S_OK here. */
4274 return S_OK;
4277 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4279 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4281 return E_NOTIMPL;
4284 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4286 FIXME("iface %p stub!\n", iface);
4288 return 0;
4291 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4292 REFGUID guid, UINT *data_size, void *data)
4294 struct d3d_device *device = impl_from_ID3D10Device(iface);
4296 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4298 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4301 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4302 REFGUID guid, UINT data_size, const void *data)
4304 struct d3d_device *device = impl_from_ID3D10Device(iface);
4306 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4308 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4311 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4312 REFGUID guid, const IUnknown *data)
4314 struct d3d_device *device = impl_from_ID3D10Device(iface);
4316 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4318 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4321 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4323 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
4324 struct d3d_device *device = impl_from_ID3D10Device(iface);
4325 unsigned int i;
4327 TRACE("iface %p.\n", iface);
4329 wined3d_mutex_lock();
4330 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
4331 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4333 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
4335 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4337 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
4339 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4341 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
4343 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
4344 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4346 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
4348 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4350 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
4352 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4354 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
4356 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
4357 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4359 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
4361 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4363 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
4365 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4367 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
4369 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4371 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
4373 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
4374 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
4375 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
4376 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4378 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4380 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
4381 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
4382 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4383 ID3D10Device1_RSSetViewports(iface, 0, NULL);
4384 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
4385 ID3D10Device1_RSSetState(iface, NULL);
4386 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4388 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4390 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
4391 wined3d_mutex_unlock();
4394 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4396 FIXME("iface %p stub!\n", iface);
4399 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4400 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4402 struct d3d_device *device = impl_from_ID3D10Device(iface);
4403 D3D11_BUFFER_DESC d3d11_desc;
4404 struct d3d_buffer *object;
4405 HRESULT hr;
4407 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
4409 d3d11_desc.ByteWidth = desc->ByteWidth;
4410 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4411 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4412 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4413 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4414 d3d11_desc.StructureByteStride = 0;
4416 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4417 return hr;
4419 *buffer = &object->ID3D10Buffer_iface;
4421 return S_OK;
4424 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
4425 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
4427 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
4429 return E_NOTIMPL;
4432 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
4433 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4434 ID3D10Texture2D **texture)
4436 struct d3d_device *device = impl_from_ID3D10Device(iface);
4437 D3D11_TEXTURE2D_DESC d3d11_desc;
4438 struct d3d_texture2d *object;
4439 HRESULT hr;
4441 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4443 d3d11_desc.Width = desc->Width;
4444 d3d11_desc.Height = desc->Height;
4445 d3d11_desc.MipLevels = desc->MipLevels;
4446 d3d11_desc.ArraySize = desc->ArraySize;
4447 d3d11_desc.Format = desc->Format;
4448 d3d11_desc.SampleDesc = desc->SampleDesc;
4449 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4450 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4451 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4452 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4454 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4455 return hr;
4457 *texture = &object->ID3D10Texture2D_iface;
4459 return S_OK;
4462 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
4463 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4464 ID3D10Texture3D **texture)
4466 struct d3d_device *device = impl_from_ID3D10Device(iface);
4467 D3D11_TEXTURE3D_DESC d3d11_desc;
4468 struct d3d_texture3d *object;
4469 HRESULT hr;
4471 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4473 d3d11_desc.Width = desc->Width;
4474 d3d11_desc.Height = desc->Height;
4475 d3d11_desc.Depth = desc->Depth;
4476 d3d11_desc.MipLevels = desc->MipLevels;
4477 d3d11_desc.Format = desc->Format;
4478 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4479 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4480 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4481 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4483 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4484 return hr;
4486 *texture = &object->ID3D10Texture3D_iface;
4488 return S_OK;
4491 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
4492 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
4494 struct d3d_device *device = impl_from_ID3D10Device(iface);
4495 struct d3d_shader_resource_view *object;
4496 ID3D11Resource *d3d11_resource;
4497 HRESULT hr;
4499 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4501 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4503 ERR("Resource does not implement ID3D11Resource.\n");
4504 return E_FAIL;
4507 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
4508 &object);
4509 ID3D11Resource_Release(d3d11_resource);
4510 if (FAILED(hr))
4511 return hr;
4513 *view = &object->ID3D10ShaderResourceView1_iface;
4515 return S_OK;
4518 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
4519 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
4521 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4523 return d3d10_device_CreateShaderResourceView1(iface, resource,
4524 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
4527 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
4528 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
4530 struct d3d_device *device = impl_from_ID3D10Device(iface);
4531 struct d3d_rendertarget_view *object;
4532 ID3D11Resource *d3d11_resource;
4533 HRESULT hr;
4535 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4537 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4539 ERR("Resource does not implement ID3D11Resource.\n");
4540 return E_FAIL;
4543 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
4544 ID3D11Resource_Release(d3d11_resource);
4545 if (FAILED(hr))
4546 return hr;
4548 *view = &object->ID3D10RenderTargetView_iface;
4550 return S_OK;
4553 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
4554 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
4556 struct d3d_device *device = impl_from_ID3D10Device(iface);
4557 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
4558 struct d3d_depthstencil_view *object;
4559 ID3D11Resource *d3d11_resource;
4560 HRESULT hr;
4562 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4564 if (desc)
4566 d3d11_desc.Format = desc->Format;
4567 d3d11_desc.ViewDimension = desc->ViewDimension;
4568 d3d11_desc.Flags = 0;
4569 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
4572 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4574 ERR("Resource does not implement ID3D11Resource.\n");
4575 return E_FAIL;
4578 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
4579 ID3D11Resource_Release(d3d11_resource);
4580 if (FAILED(hr))
4581 return hr;
4583 *view = &object->ID3D10DepthStencilView_iface;
4585 return S_OK;
4588 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
4589 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
4590 const void *shader_byte_code, SIZE_T shader_byte_code_length,
4591 ID3D10InputLayout **input_layout)
4593 struct d3d_device *device = impl_from_ID3D10Device(iface);
4594 struct d3d_input_layout *object;
4595 HRESULT hr;
4597 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
4598 "shader_byte_code_length %lu, input_layout %p\n",
4599 iface, element_descs, element_count, shader_byte_code,
4600 shader_byte_code_length, input_layout);
4602 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
4603 shader_byte_code, shader_byte_code_length, &object)))
4604 return hr;
4606 *input_layout = &object->ID3D10InputLayout_iface;
4608 return S_OK;
4611 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
4612 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
4614 struct d3d_device *device = impl_from_ID3D10Device(iface);
4615 struct d3d_vertex_shader *object;
4616 HRESULT hr;
4618 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4619 iface, byte_code, byte_code_length, shader);
4621 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
4622 return hr;
4624 *shader = &object->ID3D10VertexShader_iface;
4626 return S_OK;
4629 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
4630 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
4632 struct d3d_device *device = impl_from_ID3D10Device(iface);
4633 struct d3d_geometry_shader *object;
4634 HRESULT hr;
4636 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4637 iface, byte_code, byte_code_length, shader);
4639 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
4640 return hr;
4642 *shader = &object->ID3D10GeometryShader_iface;
4644 return S_OK;
4647 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
4648 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
4649 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
4651 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
4652 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
4653 iface, byte_code, byte_code_length, output_stream_decls,
4654 output_stream_decl_count, output_stream_stride, shader);
4656 return E_NOTIMPL;
4659 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
4660 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
4662 struct d3d_device *device = impl_from_ID3D10Device(iface);
4663 struct d3d_pixel_shader *object;
4664 HRESULT hr;
4666 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4667 iface, byte_code, byte_code_length, shader);
4669 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
4670 return hr;
4672 *shader = &object->ID3D10PixelShader_iface;
4674 return S_OK;
4677 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
4678 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
4680 struct d3d_device *device = impl_from_ID3D10Device(iface);
4681 ID3D11BlendState *d3d11_blend_state;
4682 HRESULT hr;
4684 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4686 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
4687 &d3d11_blend_state)))
4688 return hr;
4690 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
4691 ID3D11BlendState_Release(d3d11_blend_state);
4692 return hr;
4695 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
4696 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
4698 D3D10_BLEND_DESC1 d3d10_1_desc;
4699 unsigned int i;
4701 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4703 if (!desc)
4704 return E_INVALIDARG;
4706 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
4707 d3d10_1_desc.IndependentBlendEnable = FALSE;
4708 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
4710 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
4711 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
4712 d3d10_1_desc.IndependentBlendEnable = TRUE;
4715 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4717 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
4718 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
4719 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
4720 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
4721 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
4722 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
4723 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
4724 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
4727 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
4730 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
4731 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
4733 struct d3d_device *device = impl_from_ID3D10Device(iface);
4734 ID3D11DepthStencilState *d3d11_depth_stencil_state;
4735 HRESULT hr;
4737 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
4739 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
4740 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
4741 return hr;
4743 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
4744 (void **)depth_stencil_state);
4745 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
4746 return hr;
4749 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
4750 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
4752 struct d3d_device *device = impl_from_ID3D10Device(iface);
4753 ID3D11RasterizerState *d3d11_rasterizer_state;
4754 HRESULT hr;
4756 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
4758 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
4759 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
4760 return hr;
4762 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
4763 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
4764 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
4765 return hr;
4768 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
4769 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
4771 struct d3d_device *device = impl_from_ID3D10Device(iface);
4772 ID3D11SamplerState *d3d11_sampler_state;
4773 HRESULT hr;
4775 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
4777 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
4778 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
4779 return hr;
4781 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
4782 ID3D11SamplerState_Release(d3d11_sampler_state);
4783 return hr;
4786 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
4787 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
4789 struct d3d_device *device = impl_from_ID3D10Device(iface);
4790 struct d3d_query *object;
4791 HRESULT hr;
4793 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
4795 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
4796 return hr;
4798 if (query)
4800 *query = &object->ID3D10Query_iface;
4801 return S_OK;
4804 ID3D10Query_Release(&object->ID3D10Query_iface);
4805 return S_FALSE;
4808 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
4809 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
4811 struct d3d_device *device = impl_from_ID3D10Device(iface);
4812 struct d3d_query *object;
4813 HRESULT hr;
4815 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
4817 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
4818 return hr;
4820 if (predicate)
4822 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
4823 return S_OK;
4826 ID3D10Query_Release(&object->ID3D10Query_iface);
4827 return S_FALSE;
4830 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
4831 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
4833 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
4835 return E_NOTIMPL;
4838 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
4839 DXGI_FORMAT format, UINT *format_support)
4841 FIXME("iface %p, format %s, format_support %p stub!\n",
4842 iface, debug_dxgi_format(format), format_support);
4844 return E_NOTIMPL;
4847 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
4848 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
4850 struct d3d_device *device = impl_from_ID3D10Device(iface);
4852 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
4853 iface, debug_dxgi_format(format), sample_count, quality_level_count);
4855 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
4856 sample_count, quality_level_count);
4859 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
4861 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
4864 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
4865 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
4866 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
4868 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
4869 "units %p, units_length %p, description %p, description_length %p stub!\n",
4870 iface, desc, type, active_counters, name, name_length,
4871 units, units_length, description, description_length);
4873 return E_NOTIMPL;
4876 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
4878 FIXME("iface %p stub!\n", iface);
4880 return 0;
4883 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
4884 HANDLE resource_handle, REFIID guid, void **resource)
4886 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
4887 iface, resource_handle, debugstr_guid(guid), resource);
4889 return E_NOTIMPL;
4892 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
4894 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
4897 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
4899 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
4902 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
4904 struct d3d_device *device = impl_from_ID3D10Device(iface);
4906 TRACE("iface %p.\n", iface);
4908 return device->feature_level;
4911 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
4913 /* IUnknown methods */
4914 d3d10_device_QueryInterface,
4915 d3d10_device_AddRef,
4916 d3d10_device_Release,
4917 /* ID3D10Device methods */
4918 d3d10_device_VSSetConstantBuffers,
4919 d3d10_device_PSSetShaderResources,
4920 d3d10_device_PSSetShader,
4921 d3d10_device_PSSetSamplers,
4922 d3d10_device_VSSetShader,
4923 d3d10_device_DrawIndexed,
4924 d3d10_device_Draw,
4925 d3d10_device_PSSetConstantBuffers,
4926 d3d10_device_IASetInputLayout,
4927 d3d10_device_IASetVertexBuffers,
4928 d3d10_device_IASetIndexBuffer,
4929 d3d10_device_DrawIndexedInstanced,
4930 d3d10_device_DrawInstanced,
4931 d3d10_device_GSSetConstantBuffers,
4932 d3d10_device_GSSetShader,
4933 d3d10_device_IASetPrimitiveTopology,
4934 d3d10_device_VSSetShaderResources,
4935 d3d10_device_VSSetSamplers,
4936 d3d10_device_SetPredication,
4937 d3d10_device_GSSetShaderResources,
4938 d3d10_device_GSSetSamplers,
4939 d3d10_device_OMSetRenderTargets,
4940 d3d10_device_OMSetBlendState,
4941 d3d10_device_OMSetDepthStencilState,
4942 d3d10_device_SOSetTargets,
4943 d3d10_device_DrawAuto,
4944 d3d10_device_RSSetState,
4945 d3d10_device_RSSetViewports,
4946 d3d10_device_RSSetScissorRects,
4947 d3d10_device_CopySubresourceRegion,
4948 d3d10_device_CopyResource,
4949 d3d10_device_UpdateSubresource,
4950 d3d10_device_ClearRenderTargetView,
4951 d3d10_device_ClearDepthStencilView,
4952 d3d10_device_GenerateMips,
4953 d3d10_device_ResolveSubresource,
4954 d3d10_device_VSGetConstantBuffers,
4955 d3d10_device_PSGetShaderResources,
4956 d3d10_device_PSGetShader,
4957 d3d10_device_PSGetSamplers,
4958 d3d10_device_VSGetShader,
4959 d3d10_device_PSGetConstantBuffers,
4960 d3d10_device_IAGetInputLayout,
4961 d3d10_device_IAGetVertexBuffers,
4962 d3d10_device_IAGetIndexBuffer,
4963 d3d10_device_GSGetConstantBuffers,
4964 d3d10_device_GSGetShader,
4965 d3d10_device_IAGetPrimitiveTopology,
4966 d3d10_device_VSGetShaderResources,
4967 d3d10_device_VSGetSamplers,
4968 d3d10_device_GetPredication,
4969 d3d10_device_GSGetShaderResources,
4970 d3d10_device_GSGetSamplers,
4971 d3d10_device_OMGetRenderTargets,
4972 d3d10_device_OMGetBlendState,
4973 d3d10_device_OMGetDepthStencilState,
4974 d3d10_device_SOGetTargets,
4975 d3d10_device_RSGetState,
4976 d3d10_device_RSGetViewports,
4977 d3d10_device_RSGetScissorRects,
4978 d3d10_device_GetDeviceRemovedReason,
4979 d3d10_device_SetExceptionMode,
4980 d3d10_device_GetExceptionMode,
4981 d3d10_device_GetPrivateData,
4982 d3d10_device_SetPrivateData,
4983 d3d10_device_SetPrivateDataInterface,
4984 d3d10_device_ClearState,
4985 d3d10_device_Flush,
4986 d3d10_device_CreateBuffer,
4987 d3d10_device_CreateTexture1D,
4988 d3d10_device_CreateTexture2D,
4989 d3d10_device_CreateTexture3D,
4990 d3d10_device_CreateShaderResourceView,
4991 d3d10_device_CreateRenderTargetView,
4992 d3d10_device_CreateDepthStencilView,
4993 d3d10_device_CreateInputLayout,
4994 d3d10_device_CreateVertexShader,
4995 d3d10_device_CreateGeometryShader,
4996 d3d10_device_CreateGeometryShaderWithStreamOutput,
4997 d3d10_device_CreatePixelShader,
4998 d3d10_device_CreateBlendState,
4999 d3d10_device_CreateDepthStencilState,
5000 d3d10_device_CreateRasterizerState,
5001 d3d10_device_CreateSamplerState,
5002 d3d10_device_CreateQuery,
5003 d3d10_device_CreatePredicate,
5004 d3d10_device_CreateCounter,
5005 d3d10_device_CheckFormatSupport,
5006 d3d10_device_CheckMultisampleQualityLevels,
5007 d3d10_device_CheckCounterInfo,
5008 d3d10_device_CheckCounter,
5009 d3d10_device_GetCreationFlags,
5010 d3d10_device_OpenSharedResource,
5011 d3d10_device_SetTextFilterSize,
5012 d3d10_device_GetTextFilterSize,
5013 d3d10_device_CreateShaderResourceView1,
5014 d3d10_device_CreateBlendState1,
5015 d3d10_device_GetFeatureLevel,
5018 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5020 /* IUnknown methods */
5021 d3d_device_inner_QueryInterface,
5022 d3d_device_inner_AddRef,
5023 d3d_device_inner_Release,
5026 /* ID3D10Multithread methods */
5028 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5030 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5033 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5035 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5037 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5039 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5042 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5044 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5046 TRACE("iface %p.\n", iface);
5048 return IUnknown_AddRef(device->outer_unk);
5051 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5053 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5055 TRACE("iface %p.\n", iface);
5057 return IUnknown_Release(device->outer_unk);
5060 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5062 TRACE("iface %p.\n", iface);
5064 wined3d_mutex_lock();
5067 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5069 TRACE("iface %p.\n", iface);
5071 wined3d_mutex_unlock();
5074 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5076 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5078 return TRUE;
5081 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5083 FIXME("iface %p stub!\n", iface);
5085 return TRUE;
5088 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5090 d3d10_multithread_QueryInterface,
5091 d3d10_multithread_AddRef,
5092 d3d10_multithread_Release,
5093 d3d10_multithread_Enter,
5094 d3d10_multithread_Leave,
5095 d3d10_multithread_SetMultithreadProtected,
5096 d3d10_multithread_GetMultithreadProtected,
5099 /* IWineDXGIDeviceParent IUnknown methods */
5101 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5103 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5106 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5107 REFIID riid, void **ppv)
5109 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5110 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5113 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5115 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5116 return IUnknown_AddRef(device->outer_unk);
5119 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5121 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5122 return IUnknown_Release(device->outer_unk);
5125 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5126 IWineDXGIDeviceParent *iface)
5128 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5129 return &device->device_parent;
5132 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5134 /* IUnknown methods */
5135 dxgi_device_parent_QueryInterface,
5136 dxgi_device_parent_AddRef,
5137 dxgi_device_parent_Release,
5138 /* IWineDXGIDeviceParent methods */
5139 dxgi_device_parent_get_wined3d_device_parent,
5142 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5144 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5147 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5148 struct wined3d_device *wined3d_device)
5150 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5152 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5154 wined3d_device_incref(wined3d_device);
5155 device->wined3d_device = wined3d_device;
5158 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5160 TRACE("device_parent %p.\n", device_parent);
5163 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5165 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5168 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5169 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5170 const struct wined3d_parent_ops **parent_ops)
5172 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5173 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5175 *parent = NULL;
5176 *parent_ops = &d3d_null_wined3d_parent_ops;
5178 return S_OK;
5181 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5182 void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
5183 struct wined3d_texture **wined3d_texture)
5185 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5186 struct d3d_texture2d *texture;
5187 ID3D10Texture2D *texture_iface;
5188 D3D10_TEXTURE2D_DESC desc;
5189 HRESULT hr;
5191 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
5192 device_parent, container_parent, wined3d_desc, wined3d_texture);
5194 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5196 desc.Width = wined3d_desc->width;
5197 desc.Height = wined3d_desc->height;
5198 desc.MipLevels = 1;
5199 desc.ArraySize = 1;
5200 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5201 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5202 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5203 desc.Usage = D3D10_USAGE_DEFAULT;
5204 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5205 desc.CPUAccessFlags = 0;
5206 desc.MiscFlags = 0;
5208 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5209 &desc, NULL, &texture_iface)))
5211 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5212 return hr;
5215 texture = impl_from_ID3D10Texture2D(texture_iface);
5217 *wined3d_texture = texture->wined3d_texture;
5218 wined3d_texture_incref(*wined3d_texture);
5219 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5221 return S_OK;
5224 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5225 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5227 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5228 IWineDXGIDevice *wine_device;
5229 HRESULT hr;
5231 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5233 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5234 &IID_IWineDXGIDevice, (void **)&wine_device)))
5236 ERR("Device should implement IWineDXGIDevice.\n");
5237 return E_FAIL;
5240 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5241 IWineDXGIDevice_Release(wine_device);
5242 if (FAILED(hr))
5244 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5245 return hr;
5248 return S_OK;
5251 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5253 device_parent_wined3d_device_created,
5254 device_parent_mode_changed,
5255 device_parent_activate,
5256 device_parent_sub_resource_created,
5257 device_parent_sub_resource_created,
5258 device_parent_create_swapchain_texture,
5259 device_parent_create_swapchain,
5262 static void *d3d_rb_alloc(size_t size)
5264 return HeapAlloc(GetProcessHeap(), 0, size);
5267 static void *d3d_rb_realloc(void *ptr, size_t size)
5269 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
5272 static void d3d_rb_free(void *ptr)
5274 HeapFree(GetProcessHeap(), 0, ptr);
5277 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5279 const D3D11_SAMPLER_DESC *ka = key;
5280 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5282 return memcmp(ka, kb, sizeof(*ka));
5285 static const struct wine_rb_functions d3d_sampler_state_rb_ops =
5287 d3d_rb_alloc,
5288 d3d_rb_realloc,
5289 d3d_rb_free,
5290 d3d_sampler_state_compare,
5293 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5295 const D3D11_BLEND_DESC *ka = key;
5296 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5298 return memcmp(ka, kb, sizeof(*ka));
5301 static const struct wine_rb_functions d3d_blend_state_rb_ops =
5303 d3d_rb_alloc,
5304 d3d_rb_realloc,
5305 d3d_rb_free,
5306 d3d_blend_state_compare,
5309 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5311 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5312 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5313 const struct d3d_depthstencil_state, entry)->desc;
5315 return memcmp(ka, kb, sizeof(*ka));
5318 static const struct wine_rb_functions d3d_depthstencil_state_rb_ops =
5320 d3d_rb_alloc,
5321 d3d_rb_realloc,
5322 d3d_rb_free,
5323 d3d_depthstencil_state_compare,
5326 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5328 const D3D11_RASTERIZER_DESC *ka = key;
5329 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5331 return memcmp(ka, kb, sizeof(*ka));
5334 static const struct wine_rb_functions d3d_rasterizer_state_rb_ops =
5336 d3d_rb_alloc,
5337 d3d_rb_realloc,
5338 d3d_rb_free,
5339 d3d_rasterizer_state_compare,
5342 HRESULT d3d_device_init(struct d3d_device *device, void *outer_unknown)
5344 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5345 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5346 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5347 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5348 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5349 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5350 device->refcount = 1;
5351 /* COM aggregation always takes place */
5352 device->outer_unk = outer_unknown;
5354 d3d11_immediate_context_init(&device->immediate_context, device);
5355 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5357 if (wine_rb_init(&device->blend_states, &d3d_blend_state_rb_ops) == -1)
5359 WARN("Failed to initialize blend state rbtree.\n");
5360 return E_FAIL;
5362 device->blend_factor[0] = 1.0f;
5363 device->blend_factor[1] = 1.0f;
5364 device->blend_factor[2] = 1.0f;
5365 device->blend_factor[3] = 1.0f;
5367 if (wine_rb_init(&device->depthstencil_states, &d3d_depthstencil_state_rb_ops) == -1)
5369 WARN("Failed to initialize depthstencil state rbtree.\n");
5370 wine_rb_destroy(&device->blend_states, NULL, NULL);
5371 return E_FAIL;
5374 if (wine_rb_init(&device->rasterizer_states, &d3d_rasterizer_state_rb_ops) == -1)
5376 WARN("Failed to initialize rasterizer state rbtree.\n");
5377 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
5378 wine_rb_destroy(&device->blend_states, NULL, NULL);
5379 return E_FAIL;
5382 if (wine_rb_init(&device->sampler_states, &d3d_sampler_state_rb_ops) == -1)
5384 WARN("Failed to initialize sampler state rbtree.\n");
5385 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
5386 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
5387 wine_rb_destroy(&device->blend_states, NULL, NULL);
5388 return E_FAIL;
5391 return S_OK;