d3d10core: Check parameter in ID3D10Device CreateRenderTargetView.
[wine.git] / dlls / d3d11 / device.c
blob17655912f8aa9ed812018213912bbb1a498e9dae
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 if (!data && data_size)
531 return E_INVALIDARG;
533 wined3d_flags = wined3d_getdata_flags_from_d3d11_async_getdata_flags(data_flags);
535 wined3d_mutex_lock();
536 if (!data_size || wined3d_query_get_data_size(query->wined3d_query) == data_size)
538 hr = wined3d_query_get_data(query->wined3d_query, data, data_size, wined3d_flags);
540 else
542 WARN("Invalid data size %u.\n", data_size);
543 hr = E_INVALIDARG;
545 wined3d_mutex_unlock();
547 return hr;
550 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext *iface,
551 ID3D11Predicate *predicate, BOOL value)
553 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
554 struct d3d_query *query;
556 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
558 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
560 wined3d_mutex_lock();
561 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
562 wined3d_mutex_unlock();
565 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext *iface,
566 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
568 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
569 unsigned int i;
571 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
573 wined3d_mutex_lock();
574 for (i = 0; i < view_count; ++i)
576 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
578 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
579 view ? view->wined3d_view : NULL);
581 wined3d_mutex_unlock();
584 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext *iface,
585 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
587 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
588 unsigned int i;
590 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
591 iface, start_slot, sampler_count, samplers);
593 wined3d_mutex_lock();
594 for (i = 0; i < sampler_count; ++i)
596 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
598 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
599 sampler ? sampler->wined3d_sampler : NULL);
601 wined3d_mutex_unlock();
604 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext *iface,
605 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
606 ID3D11DepthStencilView *depth_stencil_view)
608 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
609 struct d3d_depthstencil_view *dsv;
610 unsigned int i;
612 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
613 iface, render_target_view_count, render_target_views, depth_stencil_view);
615 wined3d_mutex_lock();
616 for (i = 0; i < render_target_view_count; ++i)
618 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
619 wined3d_device_set_rendertarget_view(device->wined3d_device, i, rtv ? rtv->wined3d_view : NULL, FALSE);
621 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
623 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
626 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
627 wined3d_device_set_depth_stencil_view(device->wined3d_device, dsv ? dsv->wined3d_view : NULL);
628 wined3d_mutex_unlock();
631 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
632 ID3D11DeviceContext *iface, UINT render_target_view_count,
633 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
634 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
635 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
637 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
638 unsigned int i;
640 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
641 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
642 "initial_counts %p.\n",
643 iface, render_target_view_count, render_target_views, depth_stencil_view,
644 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
645 initial_counts);
647 if (render_target_view_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
649 d3d11_immediate_context_OMSetRenderTargets(iface, render_target_view_count, render_target_views,
650 depth_stencil_view);
653 if (unordered_access_view_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
655 if (initial_counts)
656 FIXME("Ignoring initial counts.\n");
658 wined3d_mutex_lock();
659 for (i = 0; i < unordered_access_view_start_slot; ++i)
661 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
663 for (i = 0; i < unordered_access_view_count; ++i)
665 struct d3d11_unordered_access_view *view
666 = unsafe_impl_from_ID3D11UnorderedAccessView(unordered_access_views[i]);
668 wined3d_device_set_unordered_access_view(device->wined3d_device,
669 unordered_access_view_start_slot + i,
670 view ? view->wined3d_view : NULL);
672 for (; unordered_access_view_start_slot + i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
674 wined3d_device_set_unordered_access_view(device->wined3d_device, i, NULL);
676 wined3d_mutex_unlock();
680 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
681 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
683 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
684 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
685 const D3D11_BLEND_DESC *desc;
687 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
688 iface, blend_state, debug_float4(blend_factor), sample_mask);
690 if (!blend_factor)
691 blend_factor = default_blend_factor;
693 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
694 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
696 wined3d_mutex_lock();
697 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
698 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
699 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
701 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
702 wined3d_device_set_render_state(device->wined3d_device,
703 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
704 wined3d_device_set_render_state(device->wined3d_device,
705 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
706 wined3d_device_set_render_state(device->wined3d_device,
707 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
708 wined3d_device_set_render_state(device->wined3d_device,
709 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
710 wined3d_mutex_unlock();
711 return;
714 desc = &device->blend_state->desc;
715 /* glSampleCoverage() */
716 if (desc->AlphaToCoverageEnable)
717 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
718 /* glEnableIndexedEXT(GL_BLEND, ...) */
719 FIXME("Per-rendertarget blend not implemented.\n");
720 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
721 desc->RenderTarget[0].BlendEnable);
722 if (desc->RenderTarget[0].BlendEnable)
724 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND,
725 desc->RenderTarget[0].SrcBlend);
726 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND,
727 desc->RenderTarget[0].DestBlend);
728 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP,
729 desc->RenderTarget[0].BlendOp);
730 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
731 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA,
732 desc->RenderTarget[0].SrcBlendAlpha);
733 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA,
734 desc->RenderTarget[0].DestBlendAlpha);
735 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA,
736 desc->RenderTarget[0].BlendOpAlpha);
738 FIXME("Color mask > 3 not implemented.\n");
739 wined3d_device_set_render_state(device->wined3d_device,
740 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
741 wined3d_device_set_render_state(device->wined3d_device,
742 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
743 wined3d_device_set_render_state(device->wined3d_device,
744 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
745 wined3d_device_set_render_state(device->wined3d_device,
746 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
747 wined3d_mutex_unlock();
750 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
751 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
753 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
754 const D3D11_DEPTH_STENCILOP_DESC *stencil_desc;
755 const D3D11_DEPTH_STENCIL_DESC *desc;
757 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
758 iface, depth_stencil_state, stencil_ref);
760 wined3d_mutex_lock();
761 device->stencil_ref = stencil_ref;
762 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
764 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE);
765 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
766 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS);
767 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
768 wined3d_mutex_unlock();
769 return;
772 desc = &device->depth_stencil_state->desc;
774 if (desc->FrontFace.StencilFailOp != desc->BackFace.StencilFailOp
775 || desc->FrontFace.StencilDepthFailOp != desc->BackFace.StencilDepthFailOp
776 || desc->FrontFace.StencilPassOp != desc->BackFace.StencilPassOp
777 || desc->FrontFace.StencilFunc != desc->BackFace.StencilFunc)
778 FIXME("Two-sided stencil testing not supported.\n");
780 stencil_desc = &desc->FrontFace;
782 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
783 if (desc->DepthEnable)
785 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
786 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
789 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
790 if (desc->StencilEnable)
792 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
793 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
794 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, stencil_desc->StencilFailOp);
795 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL,
796 stencil_desc->StencilDepthFailOp);
797 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, stencil_desc->StencilPassOp);
798 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, stencil_desc->StencilFunc);
799 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
801 wined3d_mutex_unlock();
804 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
805 ID3D11Buffer *const *buffers, const UINT *offsets)
807 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
808 unsigned int count, i;
810 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
812 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
813 wined3d_mutex_lock();
814 for (i = 0; i < count; ++i)
816 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
818 wined3d_device_set_stream_output(device->wined3d_device, i,
819 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
821 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
823 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
825 wined3d_mutex_unlock();
828 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
830 FIXME("iface %p stub!\n", iface);
833 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
834 ID3D11Buffer *buffer, UINT offset)
836 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
839 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
840 ID3D11Buffer *buffer, UINT offset)
842 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
845 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
846 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
848 FIXME("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u stub!\n",
849 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
852 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
853 ID3D11Buffer *buffer, UINT offset)
855 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
858 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
859 ID3D11RasterizerState *rasterizer_state)
861 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
862 const D3D11_RASTERIZER_DESC *desc;
864 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
866 wined3d_mutex_lock();
867 if (!(device->rasterizer_state = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
869 wined3d_device_set_rasterizer_state(device->wined3d_device, NULL);
870 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
871 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_BACK);
872 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
873 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
874 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
875 wined3d_mutex_unlock();
876 return;
879 wined3d_device_set_rasterizer_state(device->wined3d_device, device->rasterizer_state->wined3d_state);
881 desc = &device->rasterizer_state->desc;
882 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
883 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
884 /* OpenGL style depth bias. */
885 if (desc->DepthBias || desc->SlopeScaledDepthBias)
886 FIXME("Ignoring depth bias.\n");
887 /* GL_DEPTH_CLAMP */
888 if (!desc->DepthClipEnable)
889 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
890 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
891 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
892 wined3d_device_set_render_state(device->wined3d_device,
893 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
894 wined3d_mutex_unlock();
897 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
898 UINT viewport_count, const D3D11_VIEWPORT *viewports)
900 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
901 struct wined3d_viewport wined3d_vp;
903 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
905 if (viewport_count > 1)
906 FIXME("Multiple viewports not implemented.\n");
908 if (!viewport_count)
909 return;
911 if (viewports[0].TopLeftX != (UINT)viewports[0].TopLeftX
912 || viewports[0].TopLeftY != (UINT)viewports[0].TopLeftY
913 || viewports[0].Width != (UINT)viewports[0].Width
914 || viewports[0].Height != (UINT)viewports[0].Height)
915 FIXME("Floating-point viewports not implemented.\n");
917 wined3d_vp.x = viewports[0].TopLeftX;
918 wined3d_vp.y = viewports[0].TopLeftY;
919 wined3d_vp.width = viewports[0].Width;
920 wined3d_vp.height = viewports[0].Height;
921 wined3d_vp.min_z = viewports[0].MinDepth;
922 wined3d_vp.max_z = viewports[0].MaxDepth;
924 wined3d_mutex_lock();
925 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
926 wined3d_mutex_unlock();
929 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
930 UINT rect_count, const D3D11_RECT *rects)
932 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
934 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
936 if (rect_count > 1)
937 FIXME("Multiple scissor rects not implemented.\n");
939 if (!rect_count)
940 return;
942 wined3d_mutex_lock();
943 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
944 wined3d_mutex_unlock();
947 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
948 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
949 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
951 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
952 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
953 struct wined3d_box wined3d_src_box;
955 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
956 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
957 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
958 src_resource, src_subresource_idx, src_box);
960 if (src_box)
962 wined3d_src_box.left = src_box->left;
963 wined3d_src_box.top = src_box->top;
964 wined3d_src_box.front = src_box->front;
965 wined3d_src_box.right = src_box->right;
966 wined3d_src_box.bottom = src_box->bottom;
967 wined3d_src_box.back = src_box->back;
970 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
971 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
972 wined3d_mutex_lock();
973 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
974 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
975 wined3d_mutex_unlock();
978 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
979 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
981 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
982 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
984 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
986 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
987 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
988 wined3d_mutex_lock();
989 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
990 wined3d_mutex_unlock();
993 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
994 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
995 const void *data, UINT row_pitch, UINT depth_pitch)
997 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
998 struct wined3d_resource *wined3d_resource;
999 struct wined3d_box wined3d_box;
1001 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1002 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1004 if (box)
1006 wined3d_box.left = box->left;
1007 wined3d_box.top = box->top;
1008 wined3d_box.front = box->front;
1009 wined3d_box.right = box->right;
1010 wined3d_box.bottom = box->bottom;
1011 wined3d_box.back = box->back;
1014 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
1015 wined3d_mutex_lock();
1016 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1017 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1018 wined3d_mutex_unlock();
1021 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
1022 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
1024 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
1025 iface, dst_buffer, dst_offset, src_view);
1028 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
1029 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
1031 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1032 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
1033 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1034 HRESULT hr;
1036 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
1037 iface, render_target_view, debug_float4(color_rgba));
1039 if (!view)
1040 return;
1042 wined3d_mutex_lock();
1043 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1044 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
1045 ERR("Failed to clear view, hr %#x.\n", hr);
1046 wined3d_mutex_unlock();
1049 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
1050 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
1052 FIXME("iface %p, unordered_access_view %p, values {%u %u %u %u} stub!\n",
1053 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
1056 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
1057 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
1059 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
1060 iface, unordered_access_view, debug_float4(values));
1063 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
1064 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1066 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1067 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
1068 DWORD wined3d_flags;
1069 HRESULT hr;
1071 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
1072 iface, depth_stencil_view, flags, depth, stencil);
1074 if (!view)
1075 return;
1077 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
1079 wined3d_mutex_lock();
1080 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1081 wined3d_flags, NULL, depth, stencil)))
1082 ERR("Failed to clear view, hr %#x.\n", hr);
1083 wined3d_mutex_unlock();
1086 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1087 ID3D11ShaderResourceView *view)
1089 FIXME("iface %p, view %p stub!\n", iface, view);
1092 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1093 ID3D11Resource *resource, FLOAT min_lod)
1095 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1098 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1099 ID3D11Resource *resource)
1101 FIXME("iface %p, resource %p stub!\n", iface, resource);
1103 return 0.0f;
1106 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1107 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1108 ID3D11Resource *src_resource, UINT src_subresource_idx,
1109 DXGI_FORMAT format)
1111 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1112 "format %s stub!\n",
1113 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1114 debug_dxgi_format(format));
1117 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1118 ID3D11CommandList *command_list, BOOL restore_state)
1120 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1123 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1124 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1126 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1127 iface, start_slot, view_count, views);
1130 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1131 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1133 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1134 iface, shader, class_instances, class_instance_count);
1137 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1138 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1140 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1141 iface, start_slot, sampler_count, samplers);
1144 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1145 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1147 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1148 iface, start_slot, buffer_count, buffers);
1151 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1152 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1154 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1155 iface, start_slot, view_count, views);
1158 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1159 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1161 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1162 iface, shader, class_instances, class_instance_count);
1165 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1166 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1168 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1169 iface, start_slot, sampler_count, samplers);
1172 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1173 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1175 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1176 iface, start_slot, buffer_count, buffers);
1179 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1180 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1182 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1183 iface, start_slot, view_count, views);
1186 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1187 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1189 FIXME("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p stub!\n",
1190 iface, start_slot, view_count, views, initial_counts);
1193 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1194 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1196 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1197 iface, shader, class_instances, class_instance_count);
1200 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1201 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1203 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1204 iface, start_slot, sampler_count, samplers);
1207 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1208 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1210 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1211 iface, start_slot, buffer_count, buffers);
1214 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1215 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1217 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1218 unsigned int i;
1220 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1221 iface, start_slot, buffer_count, buffers);
1223 wined3d_mutex_lock();
1224 for (i = 0; i < buffer_count; ++i)
1226 struct wined3d_buffer *wined3d_buffer;
1227 struct d3d_buffer *buffer_impl;
1229 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1231 buffers[i] = NULL;
1232 continue;
1235 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1236 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1237 ID3D11Buffer_AddRef(buffers[i]);
1239 wined3d_mutex_unlock();
1242 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1243 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1245 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1246 unsigned int i;
1248 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1249 iface, start_slot, view_count, views);
1251 wined3d_mutex_lock();
1252 for (i = 0; i < view_count; ++i)
1254 struct wined3d_shader_resource_view *wined3d_view;
1255 struct d3d_shader_resource_view *view_impl;
1257 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1259 views[i] = NULL;
1260 continue;
1263 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1264 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1265 ID3D11ShaderResourceView_AddRef(views[i]);
1267 wined3d_mutex_unlock();
1270 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1271 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1273 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1274 struct wined3d_shader *wined3d_shader;
1275 struct d3d_pixel_shader *shader_impl;
1277 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1278 iface, shader, class_instances, class_instance_count);
1280 if (class_instances || class_instance_count)
1281 FIXME("Dynamic linking not implemented yet.\n");
1283 wined3d_mutex_lock();
1284 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1286 wined3d_mutex_unlock();
1287 *shader = NULL;
1288 return;
1291 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1292 wined3d_mutex_unlock();
1293 *shader = &shader_impl->ID3D11PixelShader_iface;
1294 ID3D11PixelShader_AddRef(*shader);
1297 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1298 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1300 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1301 unsigned int i;
1303 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1304 iface, start_slot, sampler_count, samplers);
1306 wined3d_mutex_lock();
1307 for (i = 0; i < sampler_count; ++i)
1309 struct wined3d_sampler *wined3d_sampler;
1310 struct d3d_sampler_state *sampler_impl;
1312 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1314 samplers[i] = NULL;
1315 continue;
1318 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1319 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1320 ID3D11SamplerState_AddRef(samplers[i]);
1322 wined3d_mutex_unlock();
1325 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1326 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1328 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1329 struct d3d_vertex_shader *shader_impl;
1330 struct wined3d_shader *wined3d_shader;
1332 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1333 iface, shader, class_instances, class_instance_count);
1335 if (class_instances || class_instance_count)
1336 FIXME("Dynamic linking not implemented yet.\n");
1338 wined3d_mutex_lock();
1339 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1341 wined3d_mutex_unlock();
1342 *shader = NULL;
1343 return;
1346 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1347 wined3d_mutex_unlock();
1348 *shader = &shader_impl->ID3D11VertexShader_iface;
1349 ID3D11VertexShader_AddRef(*shader);
1352 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1353 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1355 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1356 unsigned int i;
1358 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1359 iface, start_slot, buffer_count, buffers);
1361 wined3d_mutex_lock();
1362 for (i = 0; i < buffer_count; ++i)
1364 struct wined3d_buffer *wined3d_buffer;
1365 struct d3d_buffer *buffer_impl;
1367 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1369 buffers[i] = NULL;
1370 continue;
1373 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1374 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1375 ID3D11Buffer_AddRef(buffers[i]);
1377 wined3d_mutex_unlock();
1380 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1381 ID3D11InputLayout **input_layout)
1383 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1384 struct wined3d_vertex_declaration *wined3d_declaration;
1385 struct d3d_input_layout *input_layout_impl;
1387 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1389 wined3d_mutex_lock();
1390 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1392 wined3d_mutex_unlock();
1393 *input_layout = NULL;
1394 return;
1397 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1398 wined3d_mutex_unlock();
1399 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1400 ID3D11InputLayout_AddRef(*input_layout);
1403 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1404 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1406 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1407 unsigned int i;
1409 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1410 iface, start_slot, buffer_count, buffers, strides, offsets);
1412 wined3d_mutex_lock();
1413 for (i = 0; i < buffer_count; ++i)
1415 struct wined3d_buffer *wined3d_buffer;
1416 struct d3d_buffer *buffer_impl;
1418 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1419 &wined3d_buffer, &offsets[i], &strides[i])))
1420 ERR("Failed to get vertex buffer %u.\n", start_slot + i);
1422 if (!wined3d_buffer)
1424 buffers[i] = NULL;
1425 continue;
1428 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1429 ID3D11Buffer_AddRef(buffers[i] = &buffer_impl->ID3D11Buffer_iface);
1431 wined3d_mutex_unlock();
1434 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1435 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1437 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1438 enum wined3d_format_id wined3d_format;
1439 struct wined3d_buffer *wined3d_buffer;
1440 struct d3d_buffer *buffer_impl;
1442 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1444 wined3d_mutex_lock();
1445 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
1446 *format = dxgi_format_from_wined3dformat(wined3d_format);
1447 if (!wined3d_buffer)
1449 wined3d_mutex_unlock();
1450 *buffer = NULL;
1451 return;
1454 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1455 wined3d_mutex_unlock();
1456 ID3D11Buffer_AddRef(*buffer = &buffer_impl->ID3D11Buffer_iface);
1459 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1460 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1462 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1463 unsigned int i;
1465 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1466 iface, start_slot, buffer_count, buffers);
1468 wined3d_mutex_lock();
1469 for (i = 0; i < buffer_count; ++i)
1471 struct wined3d_buffer *wined3d_buffer;
1472 struct d3d_buffer *buffer_impl;
1474 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1476 buffers[i] = NULL;
1477 continue;
1480 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1481 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1482 ID3D11Buffer_AddRef(buffers[i]);
1484 wined3d_mutex_unlock();
1487 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1488 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1490 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1491 struct d3d_geometry_shader *shader_impl;
1492 struct wined3d_shader *wined3d_shader;
1494 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1495 iface, shader, class_instances, class_instance_count);
1497 if (class_instances || class_instance_count)
1498 FIXME("Dynamic linking not implemented yet.\n");
1500 wined3d_mutex_lock();
1501 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1503 wined3d_mutex_unlock();
1504 *shader = NULL;
1505 return;
1508 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1509 wined3d_mutex_unlock();
1510 *shader = &shader_impl->ID3D11GeometryShader_iface;
1511 ID3D11GeometryShader_AddRef(*shader);
1514 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1515 D3D11_PRIMITIVE_TOPOLOGY *topology)
1517 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1519 TRACE("iface %p, topology %p.\n", iface, topology);
1521 wined3d_mutex_lock();
1522 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
1523 wined3d_mutex_unlock();
1526 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1527 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1529 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1530 unsigned int i;
1532 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1534 wined3d_mutex_lock();
1535 for (i = 0; i < view_count; ++i)
1537 struct wined3d_shader_resource_view *wined3d_view;
1538 struct d3d_shader_resource_view *view_impl;
1540 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1542 views[i] = NULL;
1543 continue;
1546 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1547 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1548 ID3D11ShaderResourceView_AddRef(views[i]);
1550 wined3d_mutex_unlock();
1553 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1554 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1556 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1557 unsigned int i;
1559 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1560 iface, start_slot, sampler_count, samplers);
1562 wined3d_mutex_lock();
1563 for (i = 0; i < sampler_count; ++i)
1565 struct wined3d_sampler *wined3d_sampler;
1566 struct d3d_sampler_state *sampler_impl;
1568 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1570 samplers[i] = NULL;
1571 continue;
1574 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1575 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1576 ID3D11SamplerState_AddRef(samplers[i]);
1578 wined3d_mutex_unlock();
1581 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1582 ID3D11Predicate **predicate, BOOL *value)
1584 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1585 struct wined3d_query *wined3d_predicate;
1586 struct d3d_query *predicate_impl;
1588 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1590 wined3d_mutex_lock();
1591 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1593 wined3d_mutex_unlock();
1594 *predicate = NULL;
1595 return;
1598 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1599 wined3d_mutex_unlock();
1600 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1601 ID3D11Predicate_AddRef(*predicate);
1604 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1605 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1607 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1608 unsigned int i;
1610 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1612 wined3d_mutex_lock();
1613 for (i = 0; i < view_count; ++i)
1615 struct wined3d_shader_resource_view *wined3d_view;
1616 struct d3d_shader_resource_view *view_impl;
1618 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1620 views[i] = NULL;
1621 continue;
1624 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1625 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1626 ID3D11ShaderResourceView_AddRef(views[i]);
1628 wined3d_mutex_unlock();
1631 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1632 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1634 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1635 unsigned int i;
1637 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1638 iface, start_slot, sampler_count, samplers);
1640 wined3d_mutex_lock();
1641 for (i = 0; i < sampler_count; ++i)
1643 struct d3d_sampler_state *sampler_impl;
1644 struct wined3d_sampler *wined3d_sampler;
1646 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1648 samplers[i] = NULL;
1649 continue;
1652 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1653 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1654 ID3D11SamplerState_AddRef(samplers[i]);
1656 wined3d_mutex_unlock();
1659 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1660 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1661 ID3D11DepthStencilView **depth_stencil_view)
1663 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1664 struct wined3d_rendertarget_view *wined3d_view;
1666 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1667 iface, render_target_view_count, render_target_views, depth_stencil_view);
1669 wined3d_mutex_lock();
1670 if (render_target_views)
1672 struct d3d_rendertarget_view *view_impl;
1673 unsigned int i;
1675 for (i = 0; i < render_target_view_count; ++i)
1677 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1678 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1680 render_target_views[i] = NULL;
1681 continue;
1684 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1685 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1689 if (depth_stencil_view)
1691 struct d3d_depthstencil_view *view_impl;
1693 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1694 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1696 *depth_stencil_view = NULL;
1698 else
1700 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1701 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1704 wined3d_mutex_unlock();
1707 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1708 ID3D11DeviceContext *iface,
1709 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1710 ID3D11DepthStencilView **depth_stencil_view,
1711 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1712 ID3D11UnorderedAccessView **unordered_access_views)
1714 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1715 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1716 "unordered_access_views %p stub!\n",
1717 iface, render_target_view_count, render_target_views, depth_stencil_view,
1718 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1721 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1722 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1724 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1726 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1727 iface, blend_state, blend_factor, sample_mask);
1729 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D11BlendState_iface : NULL))
1730 ID3D11BlendState_AddRef(*blend_state);
1731 wined3d_mutex_lock();
1732 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1733 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1734 wined3d_mutex_unlock();
1737 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1738 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1740 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1742 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1743 iface, depth_stencil_state, stencil_ref);
1745 if ((*depth_stencil_state = device->depth_stencil_state
1746 ? &device->depth_stencil_state->ID3D11DepthStencilState_iface : NULL))
1747 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
1748 *stencil_ref = device->stencil_ref;
1751 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1752 UINT buffer_count, ID3D11Buffer **buffers)
1754 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1755 unsigned int i;
1757 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1759 wined3d_mutex_lock();
1760 for (i = 0; i < buffer_count; ++i)
1762 struct wined3d_buffer *wined3d_buffer;
1763 struct d3d_buffer *buffer_impl;
1765 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1767 buffers[i] = NULL;
1768 continue;
1771 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1772 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1773 ID3D11Buffer_AddRef(buffers[i]);
1775 wined3d_mutex_unlock();
1778 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1779 ID3D11RasterizerState **rasterizer_state)
1781 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1783 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1785 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D11RasterizerState_iface : NULL))
1786 ID3D11RasterizerState_AddRef(*rasterizer_state);
1789 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
1790 UINT *viewport_count, D3D11_VIEWPORT *viewports)
1792 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1793 struct wined3d_viewport wined3d_vp;
1795 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1797 if (!viewports)
1799 *viewport_count = 1;
1800 return;
1803 if (!*viewport_count)
1804 return;
1806 wined3d_mutex_lock();
1807 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1808 wined3d_mutex_unlock();
1810 viewports[0].TopLeftX = wined3d_vp.x;
1811 viewports[0].TopLeftY = wined3d_vp.y;
1812 viewports[0].Width = wined3d_vp.width;
1813 viewports[0].Height = wined3d_vp.height;
1814 viewports[0].MinDepth = wined3d_vp.min_z;
1815 viewports[0].MaxDepth = wined3d_vp.max_z;
1817 if (*viewport_count > 1)
1818 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1821 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
1822 UINT *rect_count, D3D11_RECT *rects)
1824 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1826 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1828 if (!rects)
1830 *rect_count = 1;
1831 return;
1834 if (!*rect_count)
1835 return;
1837 wined3d_mutex_lock();
1838 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1839 wined3d_mutex_unlock();
1840 if (*rect_count > 1)
1841 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1844 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
1845 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1847 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1850 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
1851 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1853 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1854 iface, shader, class_instances, class_instance_count);
1857 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
1858 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1860 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1861 iface, start_slot, sampler_count, samplers);
1864 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
1865 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1867 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1868 iface, start_slot, buffer_count, buffers);
1871 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
1872 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1874 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1875 iface, start_slot, view_count, views);
1878 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
1879 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1881 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1882 iface, shader, class_instances, class_instance_count);
1885 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
1886 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1888 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1889 iface, start_slot, sampler_count, samplers);
1892 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
1893 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1895 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1896 iface, start_slot, buffer_count, buffers);
1899 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
1900 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1902 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1905 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
1906 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
1908 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1911 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
1912 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1914 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1915 iface, shader, class_instances, class_instance_count);
1918 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
1919 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1921 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1922 iface, start_slot, sampler_count, samplers);
1925 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
1926 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1928 FIXME("iface %p, start_slot %u, buffer_count %u, buffer %p stub!\n",
1929 iface, start_slot, buffer_count, buffers);
1932 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
1934 FIXME("iface %p stub!\n", iface);
1937 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
1939 FIXME("iface %p stub!\n", iface);
1942 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
1944 TRACE("iface %p.\n", iface);
1946 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
1949 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
1951 FIXME("iface %p stub!\n", iface);
1953 return 0;
1956 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
1957 BOOL restore, ID3D11CommandList **command_list)
1959 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
1961 return E_NOTIMPL;
1964 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
1966 /* IUnknown methods */
1967 d3d11_immediate_context_QueryInterface,
1968 d3d11_immediate_context_AddRef,
1969 d3d11_immediate_context_Release,
1970 /* ID3D11DeviceChild methods */
1971 d3d11_immediate_context_GetDevice,
1972 d3d11_immediate_context_GetPrivateData,
1973 d3d11_immediate_context_SetPrivateData,
1974 d3d11_immediate_context_SetPrivateDataInterface,
1975 /* ID3D11DeviceContext methods */
1976 d3d11_immediate_context_VSSetConstantBuffers,
1977 d3d11_immediate_context_PSSetShaderResources,
1978 d3d11_immediate_context_PSSetShader,
1979 d3d11_immediate_context_PSSetSamplers,
1980 d3d11_immediate_context_VSSetShader,
1981 d3d11_immediate_context_DrawIndexed,
1982 d3d11_immediate_context_Draw,
1983 d3d11_immediate_context_Map,
1984 d3d11_immediate_context_Unmap,
1985 d3d11_immediate_context_PSSetConstantBuffers,
1986 d3d11_immediate_context_IASetInputLayout,
1987 d3d11_immediate_context_IASetVertexBuffers,
1988 d3d11_immediate_context_IASetIndexBuffer,
1989 d3d11_immediate_context_DrawIndexedInstanced,
1990 d3d11_immediate_context_DrawInstanced,
1991 d3d11_immediate_context_GSSetConstantBuffers,
1992 d3d11_immediate_context_GSSetShader,
1993 d3d11_immediate_context_IASetPrimitiveTopology,
1994 d3d11_immediate_context_VSSetShaderResources,
1995 d3d11_immediate_context_VSSetSamplers,
1996 d3d11_immediate_context_Begin,
1997 d3d11_immediate_context_End,
1998 d3d11_immediate_context_GetData,
1999 d3d11_immediate_context_SetPredication,
2000 d3d11_immediate_context_GSSetShaderResources,
2001 d3d11_immediate_context_GSSetSamplers,
2002 d3d11_immediate_context_OMSetRenderTargets,
2003 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
2004 d3d11_immediate_context_OMSetBlendState,
2005 d3d11_immediate_context_OMSetDepthStencilState,
2006 d3d11_immediate_context_SOSetTargets,
2007 d3d11_immediate_context_DrawAuto,
2008 d3d11_immediate_context_DrawIndexedInstancedIndirect,
2009 d3d11_immediate_context_DrawInstancedIndirect,
2010 d3d11_immediate_context_Dispatch,
2011 d3d11_immediate_context_DispatchIndirect,
2012 d3d11_immediate_context_RSSetState,
2013 d3d11_immediate_context_RSSetViewports,
2014 d3d11_immediate_context_RSSetScissorRects,
2015 d3d11_immediate_context_CopySubresourceRegion,
2016 d3d11_immediate_context_CopyResource,
2017 d3d11_immediate_context_UpdateSubresource,
2018 d3d11_immediate_context_CopyStructureCount,
2019 d3d11_immediate_context_ClearRenderTargetView,
2020 d3d11_immediate_context_ClearUnorderedAccessViewUint,
2021 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
2022 d3d11_immediate_context_ClearDepthStencilView,
2023 d3d11_immediate_context_GenerateMips,
2024 d3d11_immediate_context_SetResourceMinLOD,
2025 d3d11_immediate_context_GetResourceMinLOD,
2026 d3d11_immediate_context_ResolveSubresource,
2027 d3d11_immediate_context_ExecuteCommandList,
2028 d3d11_immediate_context_HSSetShaderResources,
2029 d3d11_immediate_context_HSSetShader,
2030 d3d11_immediate_context_HSSetSamplers,
2031 d3d11_immediate_context_HSSetConstantBuffers,
2032 d3d11_immediate_context_DSSetShaderResources,
2033 d3d11_immediate_context_DSSetShader,
2034 d3d11_immediate_context_DSSetSamplers,
2035 d3d11_immediate_context_DSSetConstantBuffers,
2036 d3d11_immediate_context_CSSetShaderResources,
2037 d3d11_immediate_context_CSSetUnorderedAccessViews,
2038 d3d11_immediate_context_CSSetShader,
2039 d3d11_immediate_context_CSSetSamplers,
2040 d3d11_immediate_context_CSSetConstantBuffers,
2041 d3d11_immediate_context_VSGetConstantBuffers,
2042 d3d11_immediate_context_PSGetShaderResources,
2043 d3d11_immediate_context_PSGetShader,
2044 d3d11_immediate_context_PSGetSamplers,
2045 d3d11_immediate_context_VSGetShader,
2046 d3d11_immediate_context_PSGetConstantBuffers,
2047 d3d11_immediate_context_IAGetInputLayout,
2048 d3d11_immediate_context_IAGetVertexBuffers,
2049 d3d11_immediate_context_IAGetIndexBuffer,
2050 d3d11_immediate_context_GSGetConstantBuffers,
2051 d3d11_immediate_context_GSGetShader,
2052 d3d11_immediate_context_IAGetPrimitiveTopology,
2053 d3d11_immediate_context_VSGetShaderResources,
2054 d3d11_immediate_context_VSGetSamplers,
2055 d3d11_immediate_context_GetPredication,
2056 d3d11_immediate_context_GSGetShaderResources,
2057 d3d11_immediate_context_GSGetSamplers,
2058 d3d11_immediate_context_OMGetRenderTargets,
2059 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
2060 d3d11_immediate_context_OMGetBlendState,
2061 d3d11_immediate_context_OMGetDepthStencilState,
2062 d3d11_immediate_context_SOGetTargets,
2063 d3d11_immediate_context_RSGetState,
2064 d3d11_immediate_context_RSGetViewports,
2065 d3d11_immediate_context_RSGetScissorRects,
2066 d3d11_immediate_context_HSGetShaderResources,
2067 d3d11_immediate_context_HSGetShader,
2068 d3d11_immediate_context_HSGetSamplers,
2069 d3d11_immediate_context_HSGetConstantBuffers,
2070 d3d11_immediate_context_DSGetShaderResources,
2071 d3d11_immediate_context_DSGetShader,
2072 d3d11_immediate_context_DSGetSamplers,
2073 d3d11_immediate_context_DSGetConstantBuffers,
2074 d3d11_immediate_context_CSGetShaderResources,
2075 d3d11_immediate_context_CSGetUnorderedAccessViews,
2076 d3d11_immediate_context_CSGetShader,
2077 d3d11_immediate_context_CSGetSamplers,
2078 d3d11_immediate_context_CSGetConstantBuffers,
2079 d3d11_immediate_context_ClearState,
2080 d3d11_immediate_context_Flush,
2081 d3d11_immediate_context_GetType,
2082 d3d11_immediate_context_GetContextFlags,
2083 d3d11_immediate_context_FinishCommandList,
2086 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
2088 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
2089 context->refcount = 1;
2091 ID3D11Device_AddRef(&device->ID3D11Device_iface);
2093 wined3d_private_store_init(&context->private_store);
2096 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
2098 wined3d_private_store_cleanup(&context->private_store);
2101 /* ID3D11Device methods */
2103 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
2105 struct d3d_device *device = impl_from_ID3D11Device(iface);
2106 return IUnknown_QueryInterface(device->outer_unk, riid, out);
2109 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
2111 struct d3d_device *device = impl_from_ID3D11Device(iface);
2112 return IUnknown_AddRef(device->outer_unk);
2115 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
2117 struct d3d_device *device = impl_from_ID3D11Device(iface);
2118 return IUnknown_Release(device->outer_unk);
2121 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
2122 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
2124 struct d3d_device *device = impl_from_ID3D11Device(iface);
2125 struct d3d_buffer *object;
2126 HRESULT hr;
2128 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2130 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
2131 return hr;
2133 *buffer = &object->ID3D11Buffer_iface;
2135 return S_OK;
2138 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
2139 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
2141 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2143 return E_NOTIMPL;
2146 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
2147 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
2149 struct d3d_device *device = impl_from_ID3D11Device(iface);
2150 struct d3d_texture2d *object;
2151 HRESULT hr;
2153 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2155 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
2156 return hr;
2158 *texture = &object->ID3D11Texture2D_iface;
2160 return S_OK;
2163 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2164 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2166 struct d3d_device *device = impl_from_ID3D11Device(iface);
2167 struct d3d_texture3d *object;
2168 HRESULT hr;
2170 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2172 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2173 return hr;
2175 *texture = &object->ID3D11Texture3D_iface;
2177 return S_OK;
2180 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2181 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2183 struct d3d_device *device = impl_from_ID3D11Device(iface);
2184 struct d3d_shader_resource_view *object;
2185 HRESULT hr;
2187 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2189 if (!resource)
2190 return E_INVALIDARG;
2192 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2193 return hr;
2195 *view = &object->ID3D11ShaderResourceView_iface;
2197 return S_OK;
2200 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2201 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2203 struct d3d_device *device = impl_from_ID3D11Device(iface);
2204 struct d3d11_unordered_access_view *object;
2205 HRESULT hr;
2207 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2209 if (FAILED(hr = d3d11_unordered_access_view_create(device, resource, desc, &object)))
2210 return hr;
2212 *view = &object->ID3D11UnorderedAccessView_iface;
2214 return S_OK;
2217 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2218 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2220 struct d3d_device *device = impl_from_ID3D11Device(iface);
2221 struct d3d_rendertarget_view *object;
2222 HRESULT hr;
2224 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2226 if (!resource)
2227 return E_INVALIDARG;
2229 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2230 return hr;
2232 *view = &object->ID3D11RenderTargetView_iface;
2234 return S_OK;
2237 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2238 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2240 struct d3d_device *device = impl_from_ID3D11Device(iface);
2241 struct d3d_depthstencil_view *object;
2242 HRESULT hr;
2244 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2246 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2247 return hr;
2249 *view = &object->ID3D11DepthStencilView_iface;
2251 return S_OK;
2254 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2255 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2256 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2258 struct d3d_device *device = impl_from_ID3D11Device(iface);
2259 struct d3d_input_layout *object;
2260 HRESULT hr;
2262 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2263 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2264 shader_byte_code_length, input_layout);
2266 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2267 shader_byte_code, shader_byte_code_length, &object)))
2268 return hr;
2270 *input_layout = &object->ID3D11InputLayout_iface;
2272 return S_OK;
2275 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2276 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2278 struct d3d_device *device = impl_from_ID3D11Device(iface);
2279 struct d3d_vertex_shader *object;
2280 HRESULT hr;
2282 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2283 iface, byte_code, byte_code_length, class_linkage, shader);
2285 if (class_linkage)
2286 FIXME("Class linkage is not implemented yet.\n");
2288 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2289 return hr;
2291 *shader = &object->ID3D11VertexShader_iface;
2293 return S_OK;
2296 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2297 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2299 struct d3d_device *device = impl_from_ID3D11Device(iface);
2300 struct d3d_geometry_shader *object;
2301 HRESULT hr;
2303 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2304 iface, byte_code, byte_code_length, class_linkage, shader);
2306 if (class_linkage)
2307 FIXME("Class linkage is not implemented yet.\n");
2309 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
2310 return hr;
2312 *shader = &object->ID3D11GeometryShader_iface;
2314 return S_OK;
2317 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2318 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2319 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
2320 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2322 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2323 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
2324 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2325 rasterized_stream, class_linkage, shader);
2327 return E_NOTIMPL;
2330 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2331 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2333 struct d3d_device *device = impl_from_ID3D11Device(iface);
2334 struct d3d_pixel_shader *object;
2335 HRESULT hr;
2337 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2338 iface, byte_code, byte_code_length, class_linkage, shader);
2340 if (class_linkage)
2341 FIXME("Class linkage is not implemented yet.\n");
2343 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2344 return hr;
2346 *shader = &object->ID3D11PixelShader_iface;
2348 return S_OK;
2351 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2352 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2354 struct d3d_device *device = impl_from_ID3D11Device(iface);
2355 struct d3d11_hull_shader *object;
2356 HRESULT hr;
2358 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2359 iface, byte_code, byte_code_length, class_linkage, shader);
2361 if (class_linkage)
2362 FIXME("Class linkage is not implemented yet.\n");
2364 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2365 return hr;
2367 *shader = &object->ID3D11HullShader_iface;
2369 return S_OK;
2372 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2373 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2375 struct d3d_device *device = impl_from_ID3D11Device(iface);
2376 struct d3d11_domain_shader *object;
2377 HRESULT hr;
2379 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2380 iface, byte_code, byte_code_length, class_linkage, shader);
2382 if (class_linkage)
2383 FIXME("Class linkage is not implemented yet.\n");
2385 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2386 return hr;
2388 *shader = &object->ID3D11DomainShader_iface;
2390 return S_OK;
2393 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2394 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2396 struct d3d_device *device = impl_from_ID3D11Device(iface);
2397 struct d3d11_compute_shader *object;
2398 HRESULT hr;
2400 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2401 iface, byte_code, byte_code_length, class_linkage, shader);
2403 if (class_linkage)
2404 FIXME("Class linkage is not implemented yet.\n");
2406 if (FAILED(hr = d3d11_compute_shader_create(device, byte_code, byte_code_length, &object)))
2407 return hr;
2409 *shader = &object->ID3D11ComputeShader_iface;
2411 return S_OK;
2414 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2415 ID3D11ClassLinkage **class_linkage)
2417 struct d3d_device *device = impl_from_ID3D11Device(iface);
2418 struct d3d11_class_linkage *object;
2419 HRESULT hr;
2421 TRACE("iface %p, class_linkage %p.\n", iface, class_linkage);
2423 if (FAILED(hr = d3d11_class_linkage_create(device, &object)))
2424 return hr;
2426 *class_linkage = &object->ID3D11ClassLinkage_iface;
2428 return S_OK;
2431 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
2432 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
2434 struct d3d_device *device = impl_from_ID3D11Device(iface);
2435 struct d3d_blend_state *object;
2436 struct wine_rb_entry *entry;
2437 D3D11_BLEND_DESC tmp_desc;
2438 unsigned int i, j;
2439 HRESULT hr;
2441 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2443 if (!desc)
2444 return E_INVALIDARG;
2446 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
2447 * D3D11_BLEND_DESC as a key in the rbtree. */
2448 memset(&tmp_desc, 0, sizeof(tmp_desc));
2449 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
2450 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
2451 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2453 j = desc->IndependentBlendEnable ? i : 0;
2454 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
2455 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
2456 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
2457 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
2458 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
2459 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
2460 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
2461 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
2464 wined3d_mutex_lock();
2465 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
2467 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
2469 TRACE("Returning existing blend state %p.\n", object);
2470 *blend_state = &object->ID3D11BlendState_iface;
2471 ID3D11BlendState_AddRef(*blend_state);
2472 wined3d_mutex_unlock();
2474 return S_OK;
2476 wined3d_mutex_unlock();
2478 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2479 return E_OUTOFMEMORY;
2481 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
2483 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2484 HeapFree(GetProcessHeap(), 0, object);
2485 return hr;
2488 TRACE("Created blend state %p.\n", object);
2489 *blend_state = &object->ID3D11BlendState_iface;
2491 return S_OK;
2494 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
2495 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
2497 struct d3d_device *device = impl_from_ID3D11Device(iface);
2498 struct d3d_depthstencil_state *object;
2499 D3D11_DEPTH_STENCIL_DESC tmp_desc;
2500 struct wine_rb_entry *entry;
2501 HRESULT hr;
2503 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2505 if (!desc)
2506 return E_INVALIDARG;
2508 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2509 * it as a key in the rbtree. */
2510 memset(&tmp_desc, 0, sizeof(tmp_desc));
2511 tmp_desc.DepthEnable = desc->DepthEnable;
2512 if (desc->DepthEnable)
2514 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2515 tmp_desc.DepthFunc = desc->DepthFunc;
2517 else
2519 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2520 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
2522 tmp_desc.StencilEnable = desc->StencilEnable;
2523 if (desc->StencilEnable)
2525 tmp_desc.StencilReadMask = desc->StencilReadMask;
2526 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2527 tmp_desc.FrontFace = desc->FrontFace;
2528 tmp_desc.BackFace = desc->BackFace;
2530 else
2532 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2533 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2534 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2535 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2536 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2537 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2538 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2539 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2540 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2541 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2544 wined3d_mutex_lock();
2545 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
2547 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
2549 TRACE("Returning existing depthstencil state %p.\n", object);
2550 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2551 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
2552 wined3d_mutex_unlock();
2554 return S_OK;
2556 wined3d_mutex_unlock();
2558 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2559 return E_OUTOFMEMORY;
2561 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
2563 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
2564 HeapFree(GetProcessHeap(), 0, object);
2565 return hr;
2568 TRACE("Created depthstencil state %p.\n", object);
2569 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2571 return S_OK;
2574 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
2575 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
2577 struct d3d_device *device = impl_from_ID3D11Device(iface);
2578 struct d3d_rasterizer_state *object;
2579 struct wine_rb_entry *entry;
2580 HRESULT hr;
2582 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2584 if (!desc)
2585 return E_INVALIDARG;
2587 wined3d_mutex_lock();
2588 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
2590 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
2592 TRACE("Returning existing rasterizer state %p.\n", object);
2593 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2594 ID3D11RasterizerState_AddRef(*rasterizer_state);
2595 wined3d_mutex_unlock();
2597 return S_OK;
2599 wined3d_mutex_unlock();
2601 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2602 return E_OUTOFMEMORY;
2604 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
2606 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
2607 HeapFree(GetProcessHeap(), 0, object);
2608 return hr;
2611 TRACE("Created rasterizer state %p.\n", object);
2612 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2614 return S_OK;
2617 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
2618 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
2620 struct d3d_device *device = impl_from_ID3D11Device(iface);
2621 D3D11_SAMPLER_DESC normalized_desc;
2622 struct d3d_sampler_state *object;
2623 struct wine_rb_entry *entry;
2624 HRESULT hr;
2626 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2628 if (!desc)
2629 return E_INVALIDARG;
2631 normalized_desc = *desc;
2632 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
2633 normalized_desc.MaxAnisotropy = 0;
2634 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
2635 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
2636 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
2637 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
2638 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
2639 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
2641 wined3d_mutex_lock();
2642 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
2644 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
2646 TRACE("Returning existing sampler state %p.\n", object);
2647 *sampler_state = &object->ID3D11SamplerState_iface;
2648 ID3D11SamplerState_AddRef(*sampler_state);
2649 wined3d_mutex_unlock();
2651 return S_OK;
2653 wined3d_mutex_unlock();
2655 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2656 return E_OUTOFMEMORY;
2658 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
2660 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2661 HeapFree(GetProcessHeap(), 0, object);
2662 return hr;
2665 TRACE("Created sampler state %p.\n", object);
2666 *sampler_state = &object->ID3D11SamplerState_iface;
2668 return S_OK;
2671 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
2672 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
2674 struct d3d_device *device = impl_from_ID3D11Device(iface);
2675 struct d3d_query *object;
2676 HRESULT hr;
2678 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2680 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
2681 return hr;
2683 if (query)
2685 *query = &object->ID3D11Query_iface;
2686 return S_OK;
2689 ID3D11Query_Release(&object->ID3D11Query_iface);
2690 return S_FALSE;
2693 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
2694 ID3D11Predicate **predicate)
2696 struct d3d_device *device = impl_from_ID3D11Device(iface);
2697 struct d3d_query *object;
2698 HRESULT hr;
2700 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2702 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
2703 return hr;
2705 if (predicate)
2707 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
2708 return S_OK;
2711 ID3D11Query_Release(&object->ID3D11Query_iface);
2712 return S_FALSE;
2715 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2716 ID3D11Counter **counter)
2718 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2720 return E_NOTIMPL;
2723 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
2724 ID3D11DeviceContext **context)
2726 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
2728 return E_NOTIMPL;
2731 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
2732 void **out)
2734 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
2736 return E_NOTIMPL;
2739 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
2740 UINT *format_support)
2742 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
2744 return E_NOTIMPL;
2747 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
2748 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2750 struct d3d_device *device = impl_from_ID3D11Device(iface);
2751 struct wined3d_device_creation_parameters params;
2752 struct wined3d *wined3d;
2753 HRESULT hr;
2755 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
2756 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2758 if (!quality_level_count)
2759 return E_INVALIDARG;
2761 *quality_level_count = 0;
2763 if (!sample_count)
2764 return E_FAIL;
2765 if (sample_count == 1)
2767 *quality_level_count = 1;
2768 return S_OK;
2770 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
2771 return E_FAIL;
2773 wined3d_mutex_lock();
2774 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
2775 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
2776 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
2777 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
2778 wined3d_mutex_unlock();
2780 if (hr == WINED3DERR_INVALIDCALL)
2781 return E_INVALIDARG;
2782 if (hr == WINED3DERR_NOTAVAILABLE)
2783 return S_OK;
2784 return hr;
2787 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
2789 FIXME("iface %p, info %p stub!\n", iface, info);
2792 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2793 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
2794 char *units, UINT *units_length, char *description, UINT *description_length)
2796 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
2797 "units %p, units_length %p, description %p, description_length %p stub!\n",
2798 iface, desc, type, active_counter_count, name, name_length,
2799 units, units_length, description, description_length);
2801 return E_NOTIMPL;
2804 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
2805 void *feature_support_data, UINT feature_support_data_size)
2807 TRACE("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u.\n",
2808 iface, feature, feature_support_data, feature_support_data_size);
2810 switch (feature)
2812 case D3D11_FEATURE_THREADING:
2814 D3D11_FEATURE_DATA_THREADING *threading_data = feature_support_data;
2815 if (feature_support_data_size != sizeof(*threading_data))
2817 WARN("Invalid data size.\n");
2818 return E_INVALIDARG;
2821 /* We lie about the threading support to make Tomb Raider 2013 and
2822 * Deus Ex: Human Revolution happy. */
2823 FIXME("Returning fake threading support data.\n");
2824 threading_data->DriverConcurrentCreates = TRUE;
2825 threading_data->DriverCommandLists = TRUE;
2826 return S_OK;
2828 case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
2830 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS *options = feature_support_data;
2831 if (feature_support_data_size != sizeof(*options))
2833 WARN("Invalid data size.\n");
2834 return E_INVALIDARG;
2837 options->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
2838 return S_OK;
2841 default:
2842 FIXME("Unhandled feature %#x.\n", feature);
2843 return E_NOTIMPL;
2847 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
2848 UINT *data_size, void *data)
2850 IDXGIDevice *dxgi_device;
2851 HRESULT hr;
2853 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2855 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2856 return hr;
2857 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
2858 IDXGIDevice_Release(dxgi_device);
2860 return hr;
2863 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
2864 UINT data_size, const void *data)
2866 IDXGIDevice *dxgi_device;
2867 HRESULT hr;
2869 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2871 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2872 return hr;
2873 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
2874 IDXGIDevice_Release(dxgi_device);
2876 return hr;
2879 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
2880 const IUnknown *data)
2882 IDXGIDevice *dxgi_device;
2883 HRESULT hr;
2885 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
2887 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2888 return hr;
2889 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
2890 IDXGIDevice_Release(dxgi_device);
2892 return hr;
2895 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
2897 struct d3d_device *device = impl_from_ID3D11Device(iface);
2899 TRACE("iface %p.\n", iface);
2901 return device->feature_level;
2904 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
2906 FIXME("iface %p stub!\n", iface);
2908 return 0;
2911 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
2913 FIXME("iface %p stub!\n", iface);
2915 return S_OK;
2918 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
2919 ID3D11DeviceContext **immediate_context)
2921 struct d3d_device *device = impl_from_ID3D11Device(iface);
2923 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
2925 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
2926 ID3D11DeviceContext_AddRef(*immediate_context);
2929 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
2931 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2933 return E_NOTIMPL;
2936 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
2938 FIXME("iface %p stub!\n", iface);
2940 return 0;
2943 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
2945 /* IUnknown methods */
2946 d3d11_device_QueryInterface,
2947 d3d11_device_AddRef,
2948 d3d11_device_Release,
2949 /* ID3D11Device methods */
2950 d3d11_device_CreateBuffer,
2951 d3d11_device_CreateTexture1D,
2952 d3d11_device_CreateTexture2D,
2953 d3d11_device_CreateTexture3D,
2954 d3d11_device_CreateShaderResourceView,
2955 d3d11_device_CreateUnorderedAccessView,
2956 d3d11_device_CreateRenderTargetView,
2957 d3d11_device_CreateDepthStencilView,
2958 d3d11_device_CreateInputLayout,
2959 d3d11_device_CreateVertexShader,
2960 d3d11_device_CreateGeometryShader,
2961 d3d11_device_CreateGeometryShaderWithStreamOutput,
2962 d3d11_device_CreatePixelShader,
2963 d3d11_device_CreateHullShader,
2964 d3d11_device_CreateDomainShader,
2965 d3d11_device_CreateComputeShader,
2966 d3d11_device_CreateClassLinkage,
2967 d3d11_device_CreateBlendState,
2968 d3d11_device_CreateDepthStencilState,
2969 d3d11_device_CreateRasterizerState,
2970 d3d11_device_CreateSamplerState,
2971 d3d11_device_CreateQuery,
2972 d3d11_device_CreatePredicate,
2973 d3d11_device_CreateCounter,
2974 d3d11_device_CreateDeferredContext,
2975 d3d11_device_OpenSharedResource,
2976 d3d11_device_CheckFormatSupport,
2977 d3d11_device_CheckMultisampleQualityLevels,
2978 d3d11_device_CheckCounterInfo,
2979 d3d11_device_CheckCounter,
2980 d3d11_device_CheckFeatureSupport,
2981 d3d11_device_GetPrivateData,
2982 d3d11_device_SetPrivateData,
2983 d3d11_device_SetPrivateDataInterface,
2984 d3d11_device_GetFeatureLevel,
2985 d3d11_device_GetCreationFlags,
2986 d3d11_device_GetDeviceRemovedReason,
2987 d3d11_device_GetImmediateContext,
2988 d3d11_device_SetExceptionMode,
2989 d3d11_device_GetExceptionMode,
2992 /* Inner IUnknown methods */
2994 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
2996 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
2999 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3001 struct d3d_device *device = impl_from_IUnknown(iface);
3003 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
3005 if (IsEqualGUID(riid, &IID_ID3D11Device)
3006 || IsEqualGUID(riid, &IID_IUnknown))
3008 *out = &device->ID3D11Device_iface;
3010 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
3011 || IsEqualGUID(riid, &IID_ID3D10Device))
3013 *out = &device->ID3D10Device1_iface;
3015 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
3017 *out = &device->ID3D10Multithread_iface;
3019 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
3021 *out = &device->IWineDXGIDeviceParent_iface;
3023 else
3025 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
3026 *out = NULL;
3027 return E_NOINTERFACE;
3030 IUnknown_AddRef((IUnknown *)*out);
3031 return S_OK;
3034 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
3036 struct d3d_device *device = impl_from_IUnknown(iface);
3037 ULONG refcount = InterlockedIncrement(&device->refcount);
3039 TRACE("%p increasing refcount to %u.\n", device, refcount);
3041 return refcount;
3044 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
3046 struct d3d_device *device = impl_from_IUnknown(iface);
3047 ULONG refcount = InterlockedDecrement(&device->refcount);
3049 TRACE("%p decreasing refcount to %u.\n", device, refcount);
3051 if (!refcount)
3053 d3d11_immediate_context_destroy(&device->immediate_context);
3054 if (device->wined3d_device)
3056 wined3d_mutex_lock();
3057 wined3d_device_decref(device->wined3d_device);
3058 wined3d_mutex_unlock();
3060 wine_rb_destroy(&device->sampler_states, NULL, NULL);
3061 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3062 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3063 wine_rb_destroy(&device->blend_states, NULL, NULL);
3066 return refcount;
3069 /* IUnknown methods */
3071 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
3072 void **ppv)
3074 struct d3d_device *device = impl_from_ID3D10Device(iface);
3075 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
3078 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
3080 struct d3d_device *device = impl_from_ID3D10Device(iface);
3081 return IUnknown_AddRef(device->outer_unk);
3084 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
3086 struct d3d_device *device = impl_from_ID3D10Device(iface);
3087 return IUnknown_Release(device->outer_unk);
3090 /* ID3D10Device methods */
3092 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
3093 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3095 struct d3d_device *device = impl_from_ID3D10Device(iface);
3096 unsigned int i;
3098 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3099 iface, start_slot, buffer_count, buffers);
3101 wined3d_mutex_lock();
3102 for (i = 0; i < buffer_count; ++i)
3104 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3106 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
3107 buffer ? buffer->wined3d_buffer : NULL);
3109 wined3d_mutex_unlock();
3112 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
3113 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3115 struct d3d_device *device = impl_from_ID3D10Device(iface);
3116 unsigned int i;
3118 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3119 iface, start_slot, view_count, views);
3121 wined3d_mutex_lock();
3122 for (i = 0; i < view_count; ++i)
3124 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3126 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
3127 view ? view->wined3d_view : NULL);
3129 wined3d_mutex_unlock();
3132 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
3133 ID3D10PixelShader *shader)
3135 struct d3d_device *device = impl_from_ID3D10Device(iface);
3136 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
3138 TRACE("iface %p, shader %p\n", iface, shader);
3140 wined3d_mutex_lock();
3141 wined3d_device_set_pixel_shader(device->wined3d_device, ps ? ps->wined3d_shader : NULL);
3142 wined3d_mutex_unlock();
3145 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
3146 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3148 struct d3d_device *device = impl_from_ID3D10Device(iface);
3149 unsigned int i;
3151 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3152 iface, start_slot, sampler_count, samplers);
3154 wined3d_mutex_lock();
3155 for (i = 0; i < sampler_count; ++i)
3157 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3159 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
3160 sampler ? sampler->wined3d_sampler : NULL);
3162 wined3d_mutex_unlock();
3165 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
3166 ID3D10VertexShader *shader)
3168 struct d3d_device *device = impl_from_ID3D10Device(iface);
3169 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
3171 TRACE("iface %p, shader %p\n", iface, shader);
3173 wined3d_mutex_lock();
3174 wined3d_device_set_vertex_shader(device->wined3d_device, vs ? vs->wined3d_shader : NULL);
3175 wined3d_mutex_unlock();
3178 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
3179 UINT start_index_location, INT base_vertex_location)
3181 struct d3d_device *device = impl_from_ID3D10Device(iface);
3183 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
3184 iface, index_count, start_index_location, base_vertex_location);
3186 wined3d_mutex_lock();
3187 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3188 wined3d_device_draw_indexed_primitive(device->wined3d_device, start_index_location, index_count);
3189 wined3d_mutex_unlock();
3192 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
3193 UINT start_vertex_location)
3195 struct d3d_device *device = impl_from_ID3D10Device(iface);
3197 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
3198 iface, vertex_count, start_vertex_location);
3200 wined3d_mutex_lock();
3201 wined3d_device_draw_primitive(device->wined3d_device, start_vertex_location, vertex_count);
3202 wined3d_mutex_unlock();
3205 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
3206 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3208 struct d3d_device *device = impl_from_ID3D10Device(iface);
3209 unsigned int i;
3211 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3212 iface, start_slot, buffer_count, buffers);
3214 wined3d_mutex_lock();
3215 for (i = 0; i < buffer_count; ++i)
3217 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3219 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
3220 buffer ? buffer->wined3d_buffer : NULL);
3222 wined3d_mutex_unlock();
3225 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
3226 ID3D10InputLayout *input_layout)
3228 struct d3d_device *device = impl_from_ID3D10Device(iface);
3229 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3231 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3233 wined3d_mutex_lock();
3234 wined3d_device_set_vertex_declaration(device->wined3d_device,
3235 layout ? layout->wined3d_decl : NULL);
3236 wined3d_mutex_unlock();
3239 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3240 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3242 struct d3d_device *device = impl_from_ID3D10Device(iface);
3243 unsigned int i;
3245 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3246 iface, start_slot, buffer_count, buffers, strides, offsets);
3248 wined3d_mutex_lock();
3249 for (i = 0; i < buffer_count; ++i)
3251 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3253 wined3d_device_set_stream_source(device->wined3d_device, start_slot + i,
3254 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3256 wined3d_mutex_unlock();
3259 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3260 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3262 struct d3d_device *device = impl_from_ID3D10Device(iface);
3263 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3265 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3266 iface, buffer, debug_dxgi_format(format), offset);
3268 wined3d_mutex_lock();
3269 wined3d_device_set_index_buffer(device->wined3d_device,
3270 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3271 wined3dformat_from_dxgi_format(format), offset);
3272 wined3d_mutex_unlock();
3275 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3276 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3277 INT base_vertex_location, UINT start_instance_location)
3279 struct d3d_device *device = impl_from_ID3D10Device(iface);
3281 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3282 "base_vertex_location %d, start_instance_location %u.\n",
3283 iface, instance_index_count, instance_count, start_index_location,
3284 base_vertex_location, start_instance_location);
3286 wined3d_mutex_lock();
3287 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3288 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3289 instance_index_count, start_instance_location, instance_count);
3290 wined3d_mutex_unlock();
3293 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3294 UINT instance_vertex_count, UINT instance_count,
3295 UINT start_vertex_location, UINT start_instance_location)
3297 struct d3d_device *device = impl_from_ID3D10Device(iface);
3299 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3300 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3301 start_vertex_location, start_instance_location);
3303 wined3d_mutex_lock();
3304 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3305 instance_vertex_count, start_instance_location, instance_count);
3306 wined3d_mutex_unlock();
3309 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3310 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3312 struct d3d_device *device = impl_from_ID3D10Device(iface);
3313 unsigned int i;
3315 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3316 iface, start_slot, buffer_count, buffers);
3318 wined3d_mutex_lock();
3319 for (i = 0; i < buffer_count; ++i)
3321 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3323 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3324 buffer ? buffer->wined3d_buffer : NULL);
3326 wined3d_mutex_unlock();
3329 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3331 struct d3d_device *device = impl_from_ID3D10Device(iface);
3332 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3334 TRACE("iface %p, shader %p.\n", iface, shader);
3336 wined3d_mutex_lock();
3337 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3338 wined3d_mutex_unlock();
3341 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3342 D3D10_PRIMITIVE_TOPOLOGY topology)
3344 struct d3d_device *device = impl_from_ID3D10Device(iface);
3346 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
3348 wined3d_mutex_lock();
3349 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
3350 wined3d_mutex_unlock();
3353 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(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_vs_resource_view(device->wined3d_device, start_slot + i,
3368 view ? view->wined3d_view : NULL);
3370 wined3d_mutex_unlock();
3373 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(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_vs_sampler(device->wined3d_device, start_slot + i,
3388 sampler ? sampler->wined3d_sampler : NULL);
3390 wined3d_mutex_unlock();
3393 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3395 struct d3d_device *device = impl_from_ID3D10Device(iface);
3396 struct d3d_query *query;
3398 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3400 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3401 wined3d_mutex_lock();
3402 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
3403 wined3d_mutex_unlock();
3406 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
3407 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3409 struct d3d_device *device = impl_from_ID3D10Device(iface);
3410 unsigned int i;
3412 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3413 iface, start_slot, view_count, views);
3415 wined3d_mutex_lock();
3416 for (i = 0; i < view_count; ++i)
3418 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3420 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
3421 view ? view->wined3d_view : NULL);
3423 wined3d_mutex_unlock();
3426 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
3427 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3429 struct d3d_device *device = impl_from_ID3D10Device(iface);
3430 unsigned int i;
3432 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3433 iface, start_slot, sampler_count, samplers);
3435 wined3d_mutex_lock();
3436 for (i = 0; i < sampler_count; ++i)
3438 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3440 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
3441 sampler ? sampler->wined3d_sampler : NULL);
3443 wined3d_mutex_unlock();
3446 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
3447 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
3448 ID3D10DepthStencilView *depth_stencil_view)
3450 struct d3d_device *device = impl_from_ID3D10Device(iface);
3451 struct d3d_depthstencil_view *dsv;
3452 unsigned int i;
3454 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3455 iface, render_target_view_count, render_target_views, depth_stencil_view);
3457 wined3d_mutex_lock();
3458 for (i = 0; i < render_target_view_count; ++i)
3460 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
3462 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
3463 rtv ? rtv->wined3d_view : NULL, FALSE);
3465 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3467 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
3470 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3471 wined3d_device_set_depth_stencil_view(device->wined3d_device,
3472 dsv ? dsv->wined3d_view : NULL);
3473 wined3d_mutex_unlock();
3476 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
3477 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
3479 struct d3d_device *device = impl_from_ID3D10Device(iface);
3480 struct d3d_blend_state *blend_state_object;
3482 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
3483 iface, blend_state, debug_float4(blend_factor), sample_mask);
3485 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
3486 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
3487 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
3490 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
3491 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
3493 struct d3d_device *device = impl_from_ID3D10Device(iface);
3494 struct d3d_depthstencil_state *ds_state_object;
3496 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
3497 iface, depth_stencil_state, stencil_ref);
3499 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
3500 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
3501 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
3504 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
3505 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
3507 struct d3d_device *device = impl_from_ID3D10Device(iface);
3508 unsigned int count, i;
3510 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
3512 count = min(target_count, 4);
3513 wined3d_mutex_lock();
3514 for (i = 0; i < count; ++i)
3516 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
3518 wined3d_device_set_stream_output(device->wined3d_device, i,
3519 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
3522 for (i = count; i < 4; ++i)
3524 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
3526 wined3d_mutex_unlock();
3529 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
3531 FIXME("iface %p stub!\n", iface);
3534 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
3536 struct d3d_device *device = impl_from_ID3D10Device(iface);
3537 struct d3d_rasterizer_state *rasterizer_state_object;
3539 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
3541 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
3542 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
3543 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
3546 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
3547 UINT viewport_count, const D3D10_VIEWPORT *viewports)
3549 struct d3d_device *device = impl_from_ID3D10Device(iface);
3550 struct wined3d_viewport wined3d_vp;
3552 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
3554 if (viewport_count > 1)
3555 FIXME("Multiple viewports not implemented.\n");
3557 if (!viewport_count)
3558 return;
3560 wined3d_vp.x = viewports[0].TopLeftX;
3561 wined3d_vp.y = viewports[0].TopLeftY;
3562 wined3d_vp.width = viewports[0].Width;
3563 wined3d_vp.height = viewports[0].Height;
3564 wined3d_vp.min_z = viewports[0].MinDepth;
3565 wined3d_vp.max_z = viewports[0].MaxDepth;
3567 wined3d_mutex_lock();
3568 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
3569 wined3d_mutex_unlock();
3572 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
3573 UINT rect_count, const D3D10_RECT *rects)
3575 struct d3d_device *device = impl_from_ID3D10Device(iface);
3577 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
3579 if (rect_count > 1)
3580 FIXME("Multiple scissor rects not implemented.\n");
3582 if (!rect_count)
3583 return;
3585 wined3d_mutex_lock();
3586 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
3587 wined3d_mutex_unlock();
3590 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
3591 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
3592 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
3594 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3595 struct d3d_device *device = impl_from_ID3D10Device(iface);
3596 struct wined3d_box wined3d_src_box;
3598 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
3599 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
3600 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
3601 src_resource, src_subresource_idx, src_box);
3603 if (src_box)
3605 wined3d_src_box.left = src_box->left;
3606 wined3d_src_box.top = src_box->top;
3607 wined3d_src_box.front = src_box->front;
3608 wined3d_src_box.right = src_box->right;
3609 wined3d_src_box.bottom = src_box->bottom;
3610 wined3d_src_box.back = src_box->back;
3613 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3614 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3615 wined3d_mutex_lock();
3616 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
3617 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
3618 wined3d_mutex_unlock();
3621 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
3622 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
3624 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3625 struct d3d_device *device = impl_from_ID3D10Device(iface);
3627 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
3629 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3630 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3631 wined3d_mutex_lock();
3632 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
3633 wined3d_mutex_unlock();
3636 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
3637 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
3638 const void *data, UINT row_pitch, UINT depth_pitch)
3640 struct d3d_device *device = impl_from_ID3D10Device(iface);
3641 ID3D11Resource *d3d11_resource;
3643 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
3644 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
3646 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
3647 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
3648 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
3649 ID3D11Resource_Release(d3d11_resource);
3652 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
3653 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
3655 struct d3d_device *device = impl_from_ID3D10Device(iface);
3656 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
3657 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
3658 HRESULT hr;
3660 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
3661 iface, render_target_view, debug_float4(color_rgba));
3663 if (!view)
3664 return;
3666 wined3d_mutex_lock();
3667 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3668 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
3669 ERR("Failed to clear view, hr %#x.\n", hr);
3670 wined3d_mutex_unlock();
3673 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
3674 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
3676 struct d3d_device *device = impl_from_ID3D10Device(iface);
3677 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3678 DWORD wined3d_flags;
3679 HRESULT hr;
3681 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
3682 iface, depth_stencil_view, flags, depth, stencil);
3684 if (!view)
3685 return;
3687 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
3689 wined3d_mutex_lock();
3690 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3691 wined3d_flags, NULL, depth, stencil)))
3692 ERR("Failed to clear view, hr %#x.\n", hr);
3693 wined3d_mutex_unlock();
3696 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
3697 ID3D10ShaderResourceView *shader_resource_view)
3699 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
3702 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
3703 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
3704 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
3706 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
3707 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
3708 iface, dst_resource, dst_subresource_idx,
3709 src_resource, src_subresource_idx, debug_dxgi_format(format));
3712 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
3713 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3715 struct d3d_device *device = impl_from_ID3D10Device(iface);
3716 unsigned int i;
3718 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3719 iface, start_slot, buffer_count, buffers);
3721 wined3d_mutex_lock();
3722 for (i = 0; i < buffer_count; ++i)
3724 struct wined3d_buffer *wined3d_buffer;
3725 struct d3d_buffer *buffer_impl;
3727 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
3729 buffers[i] = NULL;
3730 continue;
3733 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3734 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3735 ID3D10Buffer_AddRef(buffers[i]);
3737 wined3d_mutex_unlock();
3740 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
3741 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3743 struct d3d_device *device = impl_from_ID3D10Device(iface);
3744 unsigned int i;
3746 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3747 iface, start_slot, view_count, views);
3749 wined3d_mutex_lock();
3750 for (i = 0; i < view_count; ++i)
3752 struct wined3d_shader_resource_view *wined3d_view;
3753 struct d3d_shader_resource_view *view_impl;
3755 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
3757 views[i] = NULL;
3758 continue;
3761 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3762 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3763 ID3D10ShaderResourceView_AddRef(views[i]);
3765 wined3d_mutex_unlock();
3768 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
3770 struct d3d_device *device = impl_from_ID3D10Device(iface);
3771 struct d3d_pixel_shader *shader_impl;
3772 struct wined3d_shader *wined3d_shader;
3774 TRACE("iface %p, shader %p.\n", iface, shader);
3776 wined3d_mutex_lock();
3777 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
3779 wined3d_mutex_unlock();
3780 *shader = NULL;
3781 return;
3784 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3785 wined3d_mutex_unlock();
3786 *shader = &shader_impl->ID3D10PixelShader_iface;
3787 ID3D10PixelShader_AddRef(*shader);
3790 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
3791 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3793 struct d3d_device *device = impl_from_ID3D10Device(iface);
3794 unsigned int i;
3796 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3797 iface, start_slot, sampler_count, samplers);
3799 wined3d_mutex_lock();
3800 for (i = 0; i < sampler_count; ++i)
3802 struct d3d_sampler_state *sampler_impl;
3803 struct wined3d_sampler *wined3d_sampler;
3805 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
3807 samplers[i] = NULL;
3808 continue;
3811 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
3812 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
3813 ID3D10SamplerState_AddRef(samplers[i]);
3815 wined3d_mutex_unlock();
3818 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
3820 struct d3d_device *device = impl_from_ID3D10Device(iface);
3821 struct d3d_vertex_shader *shader_impl;
3822 struct wined3d_shader *wined3d_shader;
3824 TRACE("iface %p, shader %p.\n", iface, shader);
3826 wined3d_mutex_lock();
3827 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
3829 wined3d_mutex_unlock();
3830 *shader = NULL;
3831 return;
3834 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3835 wined3d_mutex_unlock();
3836 *shader = &shader_impl->ID3D10VertexShader_iface;
3837 ID3D10VertexShader_AddRef(*shader);
3840 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
3841 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3843 struct d3d_device *device = impl_from_ID3D10Device(iface);
3844 unsigned int i;
3846 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3847 iface, start_slot, buffer_count, buffers);
3849 wined3d_mutex_lock();
3850 for (i = 0; i < buffer_count; ++i)
3852 struct wined3d_buffer *wined3d_buffer;
3853 struct d3d_buffer *buffer_impl;
3855 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
3857 buffers[i] = NULL;
3858 continue;
3861 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3862 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3863 ID3D10Buffer_AddRef(buffers[i]);
3865 wined3d_mutex_unlock();
3868 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
3870 struct d3d_device *device = impl_from_ID3D10Device(iface);
3871 struct wined3d_vertex_declaration *wined3d_declaration;
3872 struct d3d_input_layout *input_layout_impl;
3874 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
3876 wined3d_mutex_lock();
3877 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
3879 wined3d_mutex_unlock();
3880 *input_layout = NULL;
3881 return;
3884 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
3885 wined3d_mutex_unlock();
3886 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
3887 ID3D10InputLayout_AddRef(*input_layout);
3890 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
3891 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
3893 struct d3d_device *device = impl_from_ID3D10Device(iface);
3894 unsigned int i;
3896 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
3897 iface, start_slot, buffer_count, buffers, strides, offsets);
3899 wined3d_mutex_lock();
3900 for (i = 0; i < buffer_count; ++i)
3902 struct wined3d_buffer *wined3d_buffer;
3903 struct d3d_buffer *buffer_impl;
3905 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
3906 &wined3d_buffer, &offsets[i], &strides[i])))
3907 ERR("Failed to get vertex buffer.\n");
3909 if (!wined3d_buffer)
3911 buffers[i] = NULL;
3912 continue;
3915 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3916 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3917 ID3D10Buffer_AddRef(buffers[i]);
3919 wined3d_mutex_unlock();
3922 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
3923 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
3925 struct d3d_device *device = impl_from_ID3D10Device(iface);
3926 enum wined3d_format_id wined3d_format;
3927 struct wined3d_buffer *wined3d_buffer;
3928 struct d3d_buffer *buffer_impl;
3930 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
3932 wined3d_mutex_lock();
3933 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
3934 *format = dxgi_format_from_wined3dformat(wined3d_format);
3935 if (!wined3d_buffer)
3937 wined3d_mutex_unlock();
3938 *buffer = NULL;
3939 return;
3942 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3943 wined3d_mutex_unlock();
3944 *buffer = &buffer_impl->ID3D10Buffer_iface;
3945 ID3D10Buffer_AddRef(*buffer);
3948 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
3949 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3951 struct d3d_device *device = impl_from_ID3D10Device(iface);
3952 unsigned int i;
3954 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3955 iface, start_slot, buffer_count, buffers);
3957 wined3d_mutex_lock();
3958 for (i = 0; i < buffer_count; ++i)
3960 struct wined3d_buffer *wined3d_buffer;
3961 struct d3d_buffer *buffer_impl;
3963 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
3965 buffers[i] = NULL;
3966 continue;
3969 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3970 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3971 ID3D10Buffer_AddRef(buffers[i]);
3973 wined3d_mutex_unlock();
3976 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
3978 struct d3d_device *device = impl_from_ID3D10Device(iface);
3979 struct d3d_geometry_shader *shader_impl;
3980 struct wined3d_shader *wined3d_shader;
3982 TRACE("iface %p, shader %p.\n", iface, shader);
3984 wined3d_mutex_lock();
3985 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
3987 wined3d_mutex_unlock();
3988 *shader = NULL;
3989 return;
3992 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3993 wined3d_mutex_unlock();
3994 *shader = &shader_impl->ID3D10GeometryShader_iface;
3995 ID3D10GeometryShader_AddRef(*shader);
3998 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
3999 D3D10_PRIMITIVE_TOPOLOGY *topology)
4001 struct d3d_device *device = impl_from_ID3D10Device(iface);
4003 TRACE("iface %p, topology %p\n", iface, topology);
4005 wined3d_mutex_lock();
4006 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
4007 wined3d_mutex_unlock();
4010 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
4011 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4013 struct d3d_device *device = impl_from_ID3D10Device(iface);
4014 unsigned int i;
4016 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4017 iface, start_slot, view_count, views);
4019 wined3d_mutex_lock();
4020 for (i = 0; i < view_count; ++i)
4022 struct wined3d_shader_resource_view *wined3d_view;
4023 struct d3d_shader_resource_view *view_impl;
4025 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
4027 views[i] = NULL;
4028 continue;
4031 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4032 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4033 ID3D10ShaderResourceView_AddRef(views[i]);
4035 wined3d_mutex_unlock();
4038 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
4039 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4041 struct d3d_device *device = impl_from_ID3D10Device(iface);
4042 unsigned int i;
4044 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4045 iface, start_slot, sampler_count, samplers);
4047 wined3d_mutex_lock();
4048 for (i = 0; i < sampler_count; ++i)
4050 struct d3d_sampler_state *sampler_impl;
4051 struct wined3d_sampler *wined3d_sampler;
4053 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
4055 samplers[i] = NULL;
4056 continue;
4059 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4060 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4061 ID3D10SamplerState_AddRef(samplers[i]);
4063 wined3d_mutex_unlock();
4066 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
4067 ID3D10Predicate **predicate, BOOL *value)
4069 struct d3d_device *device = impl_from_ID3D10Device(iface);
4070 struct wined3d_query *wined3d_predicate;
4071 struct d3d_query *predicate_impl;
4073 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
4075 wined3d_mutex_lock();
4076 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
4078 wined3d_mutex_unlock();
4079 *predicate = NULL;
4080 return;
4083 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
4084 wined3d_mutex_unlock();
4085 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
4086 ID3D10Predicate_AddRef(*predicate);
4089 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
4090 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
4092 struct d3d_device *device = impl_from_ID3D10Device(iface);
4093 unsigned int i;
4095 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
4096 iface, start_slot, view_count, views);
4098 wined3d_mutex_lock();
4099 for (i = 0; i < view_count; ++i)
4101 struct wined3d_shader_resource_view *wined3d_view;
4102 struct d3d_shader_resource_view *view_impl;
4104 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
4106 views[i] = NULL;
4107 continue;
4110 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
4111 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
4112 ID3D10ShaderResourceView_AddRef(views[i]);
4114 wined3d_mutex_unlock();
4117 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
4118 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
4120 struct d3d_device *device = impl_from_ID3D10Device(iface);
4121 unsigned int i;
4123 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
4124 iface, start_slot, sampler_count, samplers);
4126 wined3d_mutex_lock();
4127 for (i = 0; i < sampler_count; ++i)
4129 struct d3d_sampler_state *sampler_impl;
4130 struct wined3d_sampler *wined3d_sampler;
4132 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
4134 samplers[i] = NULL;
4135 continue;
4138 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
4139 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
4140 ID3D10SamplerState_AddRef(samplers[i]);
4142 wined3d_mutex_unlock();
4145 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
4146 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
4148 struct d3d_device *device = impl_from_ID3D10Device(iface);
4149 struct wined3d_rendertarget_view *wined3d_view;
4151 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
4152 iface, view_count, render_target_views, depth_stencil_view);
4154 wined3d_mutex_lock();
4155 if (render_target_views)
4157 struct d3d_rendertarget_view *view_impl;
4158 unsigned int i;
4160 for (i = 0; i < view_count; ++i)
4162 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
4163 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4165 render_target_views[i] = NULL;
4166 continue;
4169 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
4170 ID3D10RenderTargetView_AddRef(render_target_views[i]);
4174 if (depth_stencil_view)
4176 struct d3d_depthstencil_view *view_impl;
4178 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
4179 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
4181 *depth_stencil_view = NULL;
4183 else
4185 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
4186 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
4189 wined3d_mutex_unlock();
4192 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
4193 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
4195 struct d3d_device *device = impl_from_ID3D10Device(iface);
4196 ID3D11BlendState *d3d11_blend_state;
4198 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
4199 iface, blend_state, blend_factor, sample_mask);
4201 d3d11_immediate_context_OMGetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
4202 &d3d11_blend_state, blend_factor, sample_mask);
4204 if (d3d11_blend_state)
4205 *blend_state = (ID3D10BlendState *)&impl_from_ID3D11BlendState(d3d11_blend_state)->ID3D10BlendState1_iface;
4206 else
4207 *blend_state = NULL;
4210 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
4211 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
4213 struct d3d_device *device = impl_from_ID3D10Device(iface);
4214 ID3D11DepthStencilState *d3d11_iface;
4216 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
4217 iface, depth_stencil_state, stencil_ref);
4219 d3d11_immediate_context_OMGetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
4220 &d3d11_iface, stencil_ref);
4222 if (d3d11_iface)
4223 *depth_stencil_state = &impl_from_ID3D11DepthStencilState(d3d11_iface)->ID3D10DepthStencilState_iface;
4224 else
4225 *depth_stencil_state = NULL;
4228 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
4229 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
4231 struct d3d_device *device = impl_from_ID3D10Device(iface);
4232 unsigned int i;
4234 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
4235 iface, buffer_count, buffers, offsets);
4237 wined3d_mutex_lock();
4238 for (i = 0; i < buffer_count; ++i)
4240 struct wined3d_buffer *wined3d_buffer;
4241 struct d3d_buffer *buffer_impl;
4243 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4245 buffers[i] = NULL;
4246 continue;
4249 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4250 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4251 ID3D10Buffer_AddRef(buffers[i]);
4253 wined3d_mutex_unlock();
4256 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4258 struct d3d_device *device = impl_from_ID3D10Device(iface);
4260 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4262 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
4263 ID3D10RasterizerState_AddRef(*rasterizer_state);
4266 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4267 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4269 struct d3d_device *device = impl_from_ID3D10Device(iface);
4270 struct wined3d_viewport wined3d_vp;
4272 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4274 if (!viewports)
4276 *viewport_count = 1;
4277 return;
4280 if (!*viewport_count)
4281 return;
4283 wined3d_mutex_lock();
4284 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4285 wined3d_mutex_unlock();
4287 viewports[0].TopLeftX = wined3d_vp.x;
4288 viewports[0].TopLeftY = wined3d_vp.y;
4289 viewports[0].Width = wined3d_vp.width;
4290 viewports[0].Height = wined3d_vp.height;
4291 viewports[0].MinDepth = wined3d_vp.min_z;
4292 viewports[0].MaxDepth = wined3d_vp.max_z;
4294 if (*viewport_count > 1)
4295 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4298 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4300 struct d3d_device *device = impl_from_ID3D10Device(iface);
4302 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4304 if (!rects)
4306 *rect_count = 1;
4307 return;
4310 if (!*rect_count)
4311 return;
4313 wined3d_mutex_lock();
4314 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4315 wined3d_mutex_unlock();
4316 if (*rect_count > 1)
4317 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4320 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4322 TRACE("iface %p.\n", iface);
4324 /* In the current implementation the device is never removed, so we can
4325 * just return S_OK here. */
4327 return S_OK;
4330 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4332 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4334 return E_NOTIMPL;
4337 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4339 FIXME("iface %p stub!\n", iface);
4341 return 0;
4344 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4345 REFGUID guid, UINT *data_size, void *data)
4347 struct d3d_device *device = impl_from_ID3D10Device(iface);
4349 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4351 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4354 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4355 REFGUID guid, UINT data_size, const void *data)
4357 struct d3d_device *device = impl_from_ID3D10Device(iface);
4359 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4361 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4364 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4365 REFGUID guid, const IUnknown *data)
4367 struct d3d_device *device = impl_from_ID3D10Device(iface);
4369 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4371 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4374 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4376 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
4377 struct d3d_device *device = impl_from_ID3D10Device(iface);
4378 unsigned int i;
4380 TRACE("iface %p.\n", iface);
4382 wined3d_mutex_lock();
4383 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
4384 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4386 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
4388 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4390 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
4392 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4394 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
4396 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
4397 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4399 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
4401 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4403 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
4405 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4407 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
4409 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
4410 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4412 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
4414 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4416 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
4418 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4420 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
4422 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4424 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
4426 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
4427 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
4428 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
4429 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4431 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4433 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
4434 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
4435 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4436 ID3D10Device1_RSSetViewports(iface, 0, NULL);
4437 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
4438 ID3D10Device1_RSSetState(iface, NULL);
4439 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4441 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4443 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
4444 wined3d_mutex_unlock();
4447 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4449 FIXME("iface %p stub!\n", iface);
4452 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4453 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4455 struct d3d_device *device = impl_from_ID3D10Device(iface);
4456 D3D11_BUFFER_DESC d3d11_desc;
4457 struct d3d_buffer *object;
4458 HRESULT hr;
4460 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
4462 d3d11_desc.ByteWidth = desc->ByteWidth;
4463 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4464 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4465 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4466 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4467 d3d11_desc.StructureByteStride = 0;
4469 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4470 return hr;
4472 *buffer = &object->ID3D10Buffer_iface;
4474 return S_OK;
4477 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
4478 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
4480 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
4482 return E_NOTIMPL;
4485 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
4486 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4487 ID3D10Texture2D **texture)
4489 struct d3d_device *device = impl_from_ID3D10Device(iface);
4490 D3D11_TEXTURE2D_DESC d3d11_desc;
4491 struct d3d_texture2d *object;
4492 HRESULT hr;
4494 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4496 d3d11_desc.Width = desc->Width;
4497 d3d11_desc.Height = desc->Height;
4498 d3d11_desc.MipLevels = desc->MipLevels;
4499 d3d11_desc.ArraySize = desc->ArraySize;
4500 d3d11_desc.Format = desc->Format;
4501 d3d11_desc.SampleDesc = desc->SampleDesc;
4502 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4503 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4504 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4505 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4507 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4508 return hr;
4510 *texture = &object->ID3D10Texture2D_iface;
4512 return S_OK;
4515 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
4516 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4517 ID3D10Texture3D **texture)
4519 struct d3d_device *device = impl_from_ID3D10Device(iface);
4520 D3D11_TEXTURE3D_DESC d3d11_desc;
4521 struct d3d_texture3d *object;
4522 HRESULT hr;
4524 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4526 d3d11_desc.Width = desc->Width;
4527 d3d11_desc.Height = desc->Height;
4528 d3d11_desc.Depth = desc->Depth;
4529 d3d11_desc.MipLevels = desc->MipLevels;
4530 d3d11_desc.Format = desc->Format;
4531 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4532 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4533 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4534 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4536 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4537 return hr;
4539 *texture = &object->ID3D10Texture3D_iface;
4541 return S_OK;
4544 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
4545 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
4547 struct d3d_device *device = impl_from_ID3D10Device(iface);
4548 struct d3d_shader_resource_view *object;
4549 ID3D11Resource *d3d11_resource;
4550 HRESULT hr;
4552 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4554 if (!resource)
4555 return E_INVALIDARG;
4557 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4559 ERR("Resource does not implement ID3D11Resource.\n");
4560 return E_FAIL;
4563 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
4564 &object);
4565 ID3D11Resource_Release(d3d11_resource);
4566 if (FAILED(hr))
4567 return hr;
4569 *view = &object->ID3D10ShaderResourceView1_iface;
4571 return S_OK;
4574 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
4575 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
4577 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4579 return d3d10_device_CreateShaderResourceView1(iface, resource,
4580 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
4583 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
4584 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
4586 struct d3d_device *device = impl_from_ID3D10Device(iface);
4587 struct d3d_rendertarget_view *object;
4588 ID3D11Resource *d3d11_resource;
4589 HRESULT hr;
4591 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4593 if (!resource)
4594 return E_INVALIDARG;
4596 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4598 ERR("Resource does not implement ID3D11Resource.\n");
4599 return E_FAIL;
4602 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
4603 ID3D11Resource_Release(d3d11_resource);
4604 if (FAILED(hr))
4605 return hr;
4607 *view = &object->ID3D10RenderTargetView_iface;
4609 return S_OK;
4612 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
4613 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
4615 struct d3d_device *device = impl_from_ID3D10Device(iface);
4616 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
4617 struct d3d_depthstencil_view *object;
4618 ID3D11Resource *d3d11_resource;
4619 HRESULT hr;
4621 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4623 if (desc)
4625 d3d11_desc.Format = desc->Format;
4626 d3d11_desc.ViewDimension = desc->ViewDimension;
4627 d3d11_desc.Flags = 0;
4628 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
4631 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4633 ERR("Resource does not implement ID3D11Resource.\n");
4634 return E_FAIL;
4637 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
4638 ID3D11Resource_Release(d3d11_resource);
4639 if (FAILED(hr))
4640 return hr;
4642 *view = &object->ID3D10DepthStencilView_iface;
4644 return S_OK;
4647 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
4648 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
4649 const void *shader_byte_code, SIZE_T shader_byte_code_length,
4650 ID3D10InputLayout **input_layout)
4652 struct d3d_device *device = impl_from_ID3D10Device(iface);
4653 struct d3d_input_layout *object;
4654 HRESULT hr;
4656 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
4657 "shader_byte_code_length %lu, input_layout %p\n",
4658 iface, element_descs, element_count, shader_byte_code,
4659 shader_byte_code_length, input_layout);
4661 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
4662 shader_byte_code, shader_byte_code_length, &object)))
4663 return hr;
4665 *input_layout = &object->ID3D10InputLayout_iface;
4667 return S_OK;
4670 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
4671 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
4673 struct d3d_device *device = impl_from_ID3D10Device(iface);
4674 struct d3d_vertex_shader *object;
4675 HRESULT hr;
4677 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4678 iface, byte_code, byte_code_length, shader);
4680 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
4681 return hr;
4683 *shader = &object->ID3D10VertexShader_iface;
4685 return S_OK;
4688 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
4689 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
4691 struct d3d_device *device = impl_from_ID3D10Device(iface);
4692 struct d3d_geometry_shader *object;
4693 HRESULT hr;
4695 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4696 iface, byte_code, byte_code_length, shader);
4698 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
4699 return hr;
4701 *shader = &object->ID3D10GeometryShader_iface;
4703 return S_OK;
4706 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
4707 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
4708 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
4710 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
4711 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
4712 iface, byte_code, byte_code_length, output_stream_decls,
4713 output_stream_decl_count, output_stream_stride, shader);
4715 return E_NOTIMPL;
4718 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
4719 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
4721 struct d3d_device *device = impl_from_ID3D10Device(iface);
4722 struct d3d_pixel_shader *object;
4723 HRESULT hr;
4725 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4726 iface, byte_code, byte_code_length, shader);
4728 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
4729 return hr;
4731 *shader = &object->ID3D10PixelShader_iface;
4733 return S_OK;
4736 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
4737 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
4739 struct d3d_device *device = impl_from_ID3D10Device(iface);
4740 ID3D11BlendState *d3d11_blend_state;
4741 HRESULT hr;
4743 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4745 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
4746 &d3d11_blend_state)))
4747 return hr;
4749 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
4750 ID3D11BlendState_Release(d3d11_blend_state);
4751 return hr;
4754 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
4755 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
4757 D3D10_BLEND_DESC1 d3d10_1_desc;
4758 unsigned int i;
4760 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4762 if (!desc)
4763 return E_INVALIDARG;
4765 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
4766 d3d10_1_desc.IndependentBlendEnable = FALSE;
4767 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
4769 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
4770 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
4771 d3d10_1_desc.IndependentBlendEnable = TRUE;
4774 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4776 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
4777 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
4778 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
4779 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
4780 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
4781 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
4782 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
4783 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
4786 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
4789 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
4790 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
4792 struct d3d_device *device = impl_from_ID3D10Device(iface);
4793 ID3D11DepthStencilState *d3d11_depth_stencil_state;
4794 HRESULT hr;
4796 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
4798 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
4799 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
4800 return hr;
4802 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
4803 (void **)depth_stencil_state);
4804 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
4805 return hr;
4808 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
4809 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
4811 struct d3d_device *device = impl_from_ID3D10Device(iface);
4812 ID3D11RasterizerState *d3d11_rasterizer_state;
4813 HRESULT hr;
4815 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
4817 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
4818 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
4819 return hr;
4821 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
4822 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
4823 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
4824 return hr;
4827 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
4828 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
4830 struct d3d_device *device = impl_from_ID3D10Device(iface);
4831 ID3D11SamplerState *d3d11_sampler_state;
4832 HRESULT hr;
4834 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
4836 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
4837 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
4838 return hr;
4840 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
4841 ID3D11SamplerState_Release(d3d11_sampler_state);
4842 return hr;
4845 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
4846 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
4848 struct d3d_device *device = impl_from_ID3D10Device(iface);
4849 struct d3d_query *object;
4850 HRESULT hr;
4852 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
4854 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
4855 return hr;
4857 if (query)
4859 *query = &object->ID3D10Query_iface;
4860 return S_OK;
4863 ID3D10Query_Release(&object->ID3D10Query_iface);
4864 return S_FALSE;
4867 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
4868 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
4870 struct d3d_device *device = impl_from_ID3D10Device(iface);
4871 struct d3d_query *object;
4872 HRESULT hr;
4874 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
4876 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
4877 return hr;
4879 if (predicate)
4881 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
4882 return S_OK;
4885 ID3D10Query_Release(&object->ID3D10Query_iface);
4886 return S_FALSE;
4889 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
4890 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
4892 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
4894 return E_NOTIMPL;
4897 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
4898 DXGI_FORMAT format, UINT *format_support)
4900 FIXME("iface %p, format %s, format_support %p stub!\n",
4901 iface, debug_dxgi_format(format), format_support);
4903 return E_NOTIMPL;
4906 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
4907 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
4909 struct d3d_device *device = impl_from_ID3D10Device(iface);
4911 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
4912 iface, debug_dxgi_format(format), sample_count, quality_level_count);
4914 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
4915 sample_count, quality_level_count);
4918 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
4920 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
4923 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
4924 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
4925 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
4927 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
4928 "units %p, units_length %p, description %p, description_length %p stub!\n",
4929 iface, desc, type, active_counters, name, name_length,
4930 units, units_length, description, description_length);
4932 return E_NOTIMPL;
4935 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
4937 FIXME("iface %p stub!\n", iface);
4939 return 0;
4942 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
4943 HANDLE resource_handle, REFIID guid, void **resource)
4945 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
4946 iface, resource_handle, debugstr_guid(guid), resource);
4948 return E_NOTIMPL;
4951 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
4953 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
4956 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
4958 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
4961 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
4963 struct d3d_device *device = impl_from_ID3D10Device(iface);
4965 TRACE("iface %p.\n", iface);
4967 return device->feature_level;
4970 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
4972 /* IUnknown methods */
4973 d3d10_device_QueryInterface,
4974 d3d10_device_AddRef,
4975 d3d10_device_Release,
4976 /* ID3D10Device methods */
4977 d3d10_device_VSSetConstantBuffers,
4978 d3d10_device_PSSetShaderResources,
4979 d3d10_device_PSSetShader,
4980 d3d10_device_PSSetSamplers,
4981 d3d10_device_VSSetShader,
4982 d3d10_device_DrawIndexed,
4983 d3d10_device_Draw,
4984 d3d10_device_PSSetConstantBuffers,
4985 d3d10_device_IASetInputLayout,
4986 d3d10_device_IASetVertexBuffers,
4987 d3d10_device_IASetIndexBuffer,
4988 d3d10_device_DrawIndexedInstanced,
4989 d3d10_device_DrawInstanced,
4990 d3d10_device_GSSetConstantBuffers,
4991 d3d10_device_GSSetShader,
4992 d3d10_device_IASetPrimitiveTopology,
4993 d3d10_device_VSSetShaderResources,
4994 d3d10_device_VSSetSamplers,
4995 d3d10_device_SetPredication,
4996 d3d10_device_GSSetShaderResources,
4997 d3d10_device_GSSetSamplers,
4998 d3d10_device_OMSetRenderTargets,
4999 d3d10_device_OMSetBlendState,
5000 d3d10_device_OMSetDepthStencilState,
5001 d3d10_device_SOSetTargets,
5002 d3d10_device_DrawAuto,
5003 d3d10_device_RSSetState,
5004 d3d10_device_RSSetViewports,
5005 d3d10_device_RSSetScissorRects,
5006 d3d10_device_CopySubresourceRegion,
5007 d3d10_device_CopyResource,
5008 d3d10_device_UpdateSubresource,
5009 d3d10_device_ClearRenderTargetView,
5010 d3d10_device_ClearDepthStencilView,
5011 d3d10_device_GenerateMips,
5012 d3d10_device_ResolveSubresource,
5013 d3d10_device_VSGetConstantBuffers,
5014 d3d10_device_PSGetShaderResources,
5015 d3d10_device_PSGetShader,
5016 d3d10_device_PSGetSamplers,
5017 d3d10_device_VSGetShader,
5018 d3d10_device_PSGetConstantBuffers,
5019 d3d10_device_IAGetInputLayout,
5020 d3d10_device_IAGetVertexBuffers,
5021 d3d10_device_IAGetIndexBuffer,
5022 d3d10_device_GSGetConstantBuffers,
5023 d3d10_device_GSGetShader,
5024 d3d10_device_IAGetPrimitiveTopology,
5025 d3d10_device_VSGetShaderResources,
5026 d3d10_device_VSGetSamplers,
5027 d3d10_device_GetPredication,
5028 d3d10_device_GSGetShaderResources,
5029 d3d10_device_GSGetSamplers,
5030 d3d10_device_OMGetRenderTargets,
5031 d3d10_device_OMGetBlendState,
5032 d3d10_device_OMGetDepthStencilState,
5033 d3d10_device_SOGetTargets,
5034 d3d10_device_RSGetState,
5035 d3d10_device_RSGetViewports,
5036 d3d10_device_RSGetScissorRects,
5037 d3d10_device_GetDeviceRemovedReason,
5038 d3d10_device_SetExceptionMode,
5039 d3d10_device_GetExceptionMode,
5040 d3d10_device_GetPrivateData,
5041 d3d10_device_SetPrivateData,
5042 d3d10_device_SetPrivateDataInterface,
5043 d3d10_device_ClearState,
5044 d3d10_device_Flush,
5045 d3d10_device_CreateBuffer,
5046 d3d10_device_CreateTexture1D,
5047 d3d10_device_CreateTexture2D,
5048 d3d10_device_CreateTexture3D,
5049 d3d10_device_CreateShaderResourceView,
5050 d3d10_device_CreateRenderTargetView,
5051 d3d10_device_CreateDepthStencilView,
5052 d3d10_device_CreateInputLayout,
5053 d3d10_device_CreateVertexShader,
5054 d3d10_device_CreateGeometryShader,
5055 d3d10_device_CreateGeometryShaderWithStreamOutput,
5056 d3d10_device_CreatePixelShader,
5057 d3d10_device_CreateBlendState,
5058 d3d10_device_CreateDepthStencilState,
5059 d3d10_device_CreateRasterizerState,
5060 d3d10_device_CreateSamplerState,
5061 d3d10_device_CreateQuery,
5062 d3d10_device_CreatePredicate,
5063 d3d10_device_CreateCounter,
5064 d3d10_device_CheckFormatSupport,
5065 d3d10_device_CheckMultisampleQualityLevels,
5066 d3d10_device_CheckCounterInfo,
5067 d3d10_device_CheckCounter,
5068 d3d10_device_GetCreationFlags,
5069 d3d10_device_OpenSharedResource,
5070 d3d10_device_SetTextFilterSize,
5071 d3d10_device_GetTextFilterSize,
5072 d3d10_device_CreateShaderResourceView1,
5073 d3d10_device_CreateBlendState1,
5074 d3d10_device_GetFeatureLevel,
5077 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
5079 /* IUnknown methods */
5080 d3d_device_inner_QueryInterface,
5081 d3d_device_inner_AddRef,
5082 d3d_device_inner_Release,
5085 /* ID3D10Multithread methods */
5087 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
5089 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
5092 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
5094 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5096 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
5098 return IUnknown_QueryInterface(device->outer_unk, iid, out);
5101 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
5103 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5105 TRACE("iface %p.\n", iface);
5107 return IUnknown_AddRef(device->outer_unk);
5110 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
5112 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
5114 TRACE("iface %p.\n", iface);
5116 return IUnknown_Release(device->outer_unk);
5119 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
5121 TRACE("iface %p.\n", iface);
5123 wined3d_mutex_lock();
5126 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
5128 TRACE("iface %p.\n", iface);
5130 wined3d_mutex_unlock();
5133 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
5135 FIXME("iface %p, protect %#x stub!\n", iface, protect);
5137 return TRUE;
5140 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
5142 FIXME("iface %p stub!\n", iface);
5144 return TRUE;
5147 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
5149 d3d10_multithread_QueryInterface,
5150 d3d10_multithread_AddRef,
5151 d3d10_multithread_Release,
5152 d3d10_multithread_Enter,
5153 d3d10_multithread_Leave,
5154 d3d10_multithread_SetMultithreadProtected,
5155 d3d10_multithread_GetMultithreadProtected,
5158 /* IWineDXGIDeviceParent IUnknown methods */
5160 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
5162 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
5165 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
5166 REFIID riid, void **ppv)
5168 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5169 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
5172 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
5174 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5175 return IUnknown_AddRef(device->outer_unk);
5178 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
5180 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5181 return IUnknown_Release(device->outer_unk);
5184 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
5185 IWineDXGIDeviceParent *iface)
5187 struct d3d_device *device = device_from_dxgi_device_parent(iface);
5188 return &device->device_parent;
5191 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
5193 /* IUnknown methods */
5194 dxgi_device_parent_QueryInterface,
5195 dxgi_device_parent_AddRef,
5196 dxgi_device_parent_Release,
5197 /* IWineDXGIDeviceParent methods */
5198 dxgi_device_parent_get_wined3d_device_parent,
5201 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
5203 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
5206 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
5207 struct wined3d_device *wined3d_device)
5209 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5211 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
5213 wined3d_device_incref(wined3d_device);
5214 device->wined3d_device = wined3d_device;
5217 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
5219 TRACE("device_parent %p.\n", device_parent);
5222 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
5224 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
5227 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
5228 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
5229 const struct wined3d_parent_ops **parent_ops)
5231 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5232 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
5234 *parent = NULL;
5235 *parent_ops = &d3d_null_wined3d_parent_ops;
5237 return S_OK;
5240 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
5241 void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
5242 struct wined3d_texture **wined3d_texture)
5244 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5245 struct d3d_texture2d *texture;
5246 ID3D10Texture2D *texture_iface;
5247 D3D10_TEXTURE2D_DESC desc;
5248 HRESULT hr;
5250 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
5251 device_parent, container_parent, wined3d_desc, wined3d_texture);
5253 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5255 desc.Width = wined3d_desc->width;
5256 desc.Height = wined3d_desc->height;
5257 desc.MipLevels = 1;
5258 desc.ArraySize = 1;
5259 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5260 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5261 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5262 desc.Usage = D3D10_USAGE_DEFAULT;
5263 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5264 desc.CPUAccessFlags = 0;
5265 desc.MiscFlags = 0;
5267 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5268 &desc, NULL, &texture_iface)))
5270 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5271 return hr;
5274 texture = impl_from_ID3D10Texture2D(texture_iface);
5276 *wined3d_texture = texture->wined3d_texture;
5277 wined3d_texture_incref(*wined3d_texture);
5278 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5280 return S_OK;
5283 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5284 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5286 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5287 IWineDXGIDevice *wine_device;
5288 HRESULT hr;
5290 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5292 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5293 &IID_IWineDXGIDevice, (void **)&wine_device)))
5295 ERR("Device should implement IWineDXGIDevice.\n");
5296 return E_FAIL;
5299 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, TRUE, swapchain);
5300 IWineDXGIDevice_Release(wine_device);
5301 if (FAILED(hr))
5303 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5304 return hr;
5307 return S_OK;
5310 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5312 device_parent_wined3d_device_created,
5313 device_parent_mode_changed,
5314 device_parent_activate,
5315 device_parent_sub_resource_created,
5316 device_parent_sub_resource_created,
5317 device_parent_create_swapchain_texture,
5318 device_parent_create_swapchain,
5321 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5323 const D3D11_SAMPLER_DESC *ka = key;
5324 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5326 return memcmp(ka, kb, sizeof(*ka));
5329 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5331 const D3D11_BLEND_DESC *ka = key;
5332 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5334 return memcmp(ka, kb, sizeof(*ka));
5337 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5339 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5340 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5341 const struct d3d_depthstencil_state, entry)->desc;
5343 return memcmp(ka, kb, sizeof(*ka));
5346 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5348 const D3D11_RASTERIZER_DESC *ka = key;
5349 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5351 return memcmp(ka, kb, sizeof(*ka));
5354 void d3d_device_init(struct d3d_device *device, void *outer_unknown)
5356 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5357 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5358 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5359 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5360 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5361 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5362 device->refcount = 1;
5363 /* COM aggregation always takes place */
5364 device->outer_unk = outer_unknown;
5366 d3d11_immediate_context_init(&device->immediate_context, device);
5367 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5369 device->blend_factor[0] = 1.0f;
5370 device->blend_factor[1] = 1.0f;
5371 device->blend_factor[2] = 1.0f;
5372 device->blend_factor[3] = 1.0f;
5374 wine_rb_init(&device->blend_states, d3d_blend_state_compare);
5375 wine_rb_init(&device->depthstencil_states, d3d_depthstencil_state_compare);
5376 wine_rb_init(&device->rasterizer_states, d3d_rasterizer_state_compare);
5377 wine_rb_init(&device->sampler_states, d3d_sampler_state_compare);