d3d11: Allow to pass NULL as "predicate" to d3d11_device_CreatePredicate().
[wine.git] / dlls / d3d11 / device.c
blob5a5eeae09fcb4e96ddb1784b65e577051ff11cc1
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 if (offset)
364 FIXME("offset %u not supported.\n", offset);
366 wined3d_mutex_lock();
367 wined3d_device_set_index_buffer(device->wined3d_device,
368 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
369 wined3dformat_from_dxgi_format(format));
370 wined3d_mutex_unlock();
373 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstanced(ID3D11DeviceContext *iface,
374 UINT instance_index_count, UINT instance_count, UINT start_index_location, INT base_vertex_location,
375 UINT start_instance_location)
377 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
379 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
380 "base_vertex_location %d, start_instance_location %u.\n",
381 iface, instance_index_count, instance_count, start_index_location,
382 base_vertex_location, start_instance_location);
384 wined3d_mutex_lock();
385 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
386 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
387 instance_index_count, start_instance_location, instance_count);
388 wined3d_mutex_unlock();
391 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstanced(ID3D11DeviceContext *iface,
392 UINT instance_vertex_count, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
394 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
396 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
397 "start_instance_location %u.\n",
398 iface, instance_vertex_count, instance_count, start_vertex_location,
399 start_instance_location);
401 wined3d_mutex_lock();
402 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
403 instance_vertex_count, start_instance_location, instance_count);
404 wined3d_mutex_unlock();
407 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetConstantBuffers(ID3D11DeviceContext *iface,
408 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
410 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
411 unsigned int i;
413 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
414 iface, start_slot, buffer_count, buffers);
416 wined3d_mutex_lock();
417 for (i = 0; i < buffer_count; ++i)
419 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
421 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
422 buffer ? buffer->wined3d_buffer : NULL);
424 wined3d_mutex_unlock();
427 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShader(ID3D11DeviceContext *iface,
428 ID3D11GeometryShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
430 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
431 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D11GeometryShader(shader);
433 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %u.\n",
434 iface, shader, class_instances, class_instance_count);
436 if (class_instances)
437 FIXME("Dynamic linking is not implemented yet.\n");
439 wined3d_mutex_lock();
440 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
441 wined3d_mutex_unlock();
444 static void STDMETHODCALLTYPE d3d11_immediate_context_IASetPrimitiveTopology(ID3D11DeviceContext *iface,
445 D3D11_PRIMITIVE_TOPOLOGY topology)
447 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
449 TRACE("iface %p, topology %u.\n", iface, topology);
451 wined3d_mutex_lock();
452 wined3d_device_set_primitive_type(device->wined3d_device, (enum wined3d_primitive_type)topology);
453 wined3d_mutex_unlock();
456 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetShaderResources(ID3D11DeviceContext *iface,
457 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
459 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
460 unsigned int i;
462 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
464 wined3d_mutex_lock();
465 for (i = 0; i < view_count; ++i)
467 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
469 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
470 view ? view->wined3d_view : NULL);
472 wined3d_mutex_unlock();
475 static void STDMETHODCALLTYPE d3d11_immediate_context_VSSetSamplers(ID3D11DeviceContext *iface,
476 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
478 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
479 unsigned int i;
481 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
482 iface, start_slot, sampler_count, samplers);
484 wined3d_mutex_lock();
485 for (i = 0; i < sampler_count; ++i)
487 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
489 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
490 sampler ? sampler->wined3d_sampler : NULL);
492 wined3d_mutex_unlock();
495 static void STDMETHODCALLTYPE d3d11_immediate_context_Begin(ID3D11DeviceContext *iface,
496 ID3D11Asynchronous *asynchronous)
498 FIXME("iface %p, asynchronous %p stub!\n", iface, asynchronous);
501 static void STDMETHODCALLTYPE d3d11_immediate_context_End(ID3D11DeviceContext *iface,
502 ID3D11Asynchronous *asynchronous)
504 FIXME("iface %p, asynchronous %p stub!\n", iface, asynchronous);
507 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_GetData(ID3D11DeviceContext *iface,
508 ID3D11Asynchronous *asynchronous, void *data, UINT data_size, UINT data_flags)
510 FIXME("iface %p, asynchronous %p, data %p, data_size %u, data_flags %#x stub!\n",
511 iface, asynchronous, data, data_size, data_flags);
513 return E_NOTIMPL;
516 static void STDMETHODCALLTYPE d3d11_immediate_context_SetPredication(ID3D11DeviceContext *iface,
517 ID3D11Predicate *predicate, BOOL value)
519 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
520 struct d3d_query *query;
522 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
524 query = unsafe_impl_from_ID3D11Query((ID3D11Query *)predicate);
526 wined3d_mutex_lock();
527 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
528 wined3d_mutex_unlock();
531 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetShaderResources(ID3D11DeviceContext *iface,
532 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
534 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
535 unsigned int i;
537 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
539 wined3d_mutex_lock();
540 for (i = 0; i < view_count; ++i)
542 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D11ShaderResourceView(views[i]);
544 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
545 view ? view->wined3d_view : NULL);
547 wined3d_mutex_unlock();
550 static void STDMETHODCALLTYPE d3d11_immediate_context_GSSetSamplers(ID3D11DeviceContext *iface,
551 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
553 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
554 unsigned int i;
556 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
557 iface, start_slot, sampler_count, samplers);
559 wined3d_mutex_lock();
560 for (i = 0; i < sampler_count; ++i)
562 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D11SamplerState(samplers[i]);
564 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
565 sampler ? sampler->wined3d_sampler : NULL);
567 wined3d_mutex_unlock();
570 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargets(ID3D11DeviceContext *iface,
571 UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
572 ID3D11DepthStencilView *depth_stencil_view)
574 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
575 struct d3d_depthstencil_view *dsv;
576 unsigned int i;
578 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
579 iface, render_target_view_count, render_target_views, depth_stencil_view);
581 wined3d_mutex_lock();
582 for (i = 0; i < render_target_view_count; ++i)
584 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
585 wined3d_device_set_rendertarget_view(device->wined3d_device, i, rtv ? rtv->wined3d_view : NULL, FALSE);
587 for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
589 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
592 dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
593 wined3d_device_set_depth_stencil_view(device->wined3d_device, dsv ? dsv->wined3d_view : NULL);
594 wined3d_mutex_unlock();
597 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews(
598 ID3D11DeviceContext *iface, UINT render_target_view_count,
599 ID3D11RenderTargetView *const *render_target_views, ID3D11DepthStencilView *depth_stencil_view,
600 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
601 ID3D11UnorderedAccessView *const *unordered_access_views, const UINT *initial_counts)
603 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
604 "unordered_access_view_start_slot %u, unordered_access_view_count %u, unordered_access_views %p, "
605 "initial_counts %p stub!\n",
606 iface, render_target_view_count, render_target_views, depth_stencil_view,
607 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views,
608 initial_counts);
611 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11DeviceContext *iface,
612 ID3D11BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
614 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
615 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
616 const D3D11_BLEND_DESC *desc;
618 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
619 iface, blend_state, debug_float4(blend_factor), sample_mask);
621 if (!blend_factor)
622 blend_factor = default_blend_factor;
624 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
625 FIXME("Ignoring blend factor %s.\n", debug_float4(blend_factor));
627 wined3d_mutex_lock();
628 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
629 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
630 if (!(device->blend_state = unsafe_impl_from_ID3D11BlendState(blend_state)))
632 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
633 wined3d_device_set_render_state(device->wined3d_device,
634 WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
635 wined3d_device_set_render_state(device->wined3d_device,
636 WINED3D_RS_COLORWRITEENABLE1, D3D11_COLOR_WRITE_ENABLE_ALL);
637 wined3d_device_set_render_state(device->wined3d_device,
638 WINED3D_RS_COLORWRITEENABLE2, D3D11_COLOR_WRITE_ENABLE_ALL);
639 wined3d_device_set_render_state(device->wined3d_device,
640 WINED3D_RS_COLORWRITEENABLE3, D3D11_COLOR_WRITE_ENABLE_ALL);
641 wined3d_mutex_unlock();
642 return;
645 desc = &device->blend_state->desc;
646 /* glSampleCoverage() */
647 if (desc->AlphaToCoverageEnable)
648 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
649 /* glEnableIndexedEXT(GL_BLEND, ...) */
650 FIXME("Per-rendertarget blend not implemented.\n");
651 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
652 desc->RenderTarget[0].BlendEnable);
653 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->RenderTarget[0].SrcBlend);
654 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->RenderTarget[0].DestBlend);
655 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->RenderTarget[0].BlendOp);
656 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
657 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA,
658 desc->RenderTarget[0].SrcBlendAlpha);
659 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA,
660 desc->RenderTarget[0].DestBlendAlpha);
661 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA,
662 desc->RenderTarget[0].BlendOpAlpha);
663 FIXME("Color mask > 3 not implemented.\n");
664 wined3d_device_set_render_state(device->wined3d_device,
665 WINED3D_RS_COLORWRITEENABLE, desc->RenderTarget[0].RenderTargetWriteMask);
666 wined3d_device_set_render_state(device->wined3d_device,
667 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTarget[1].RenderTargetWriteMask);
668 wined3d_device_set_render_state(device->wined3d_device,
669 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTarget[2].RenderTargetWriteMask);
670 wined3d_device_set_render_state(device->wined3d_device,
671 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTarget[3].RenderTargetWriteMask);
672 wined3d_mutex_unlock();
675 static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetDepthStencilState(ID3D11DeviceContext *iface,
676 ID3D11DepthStencilState *depth_stencil_state, UINT stencil_ref)
678 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
679 const D3D11_DEPTH_STENCILOP_DESC *stencil_desc;
680 const D3D11_DEPTH_STENCIL_DESC *desc;
682 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
683 iface, depth_stencil_state, stencil_ref);
685 wined3d_mutex_lock();
686 device->stencil_ref = stencil_ref;
687 if (!(device->depth_stencil_state = unsafe_impl_from_ID3D11DepthStencilState(depth_stencil_state)))
689 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, TRUE);
690 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, D3D11_DEPTH_WRITE_MASK_ALL);
691 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, D3D11_COMPARISON_LESS);
692 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, FALSE);
693 wined3d_mutex_unlock();
694 return;
697 desc = &device->depth_stencil_state->desc;
699 if (desc->FrontFace.StencilFailOp != desc->BackFace.StencilFailOp
700 || desc->FrontFace.StencilDepthFailOp != desc->BackFace.StencilDepthFailOp
701 || desc->FrontFace.StencilPassOp != desc->BackFace.StencilPassOp
702 || desc->FrontFace.StencilFunc != desc->BackFace.StencilFunc)
703 FIXME("Two-sided stencil testing not supported.\n");
705 stencil_desc = &desc->FrontFace;
707 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZENABLE, desc->DepthEnable);
708 if (desc->DepthEnable)
710 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZWRITEENABLE, desc->DepthWriteMask);
711 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ZFUNC, desc->DepthFunc);
714 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILENABLE, desc->StencilEnable);
715 if (desc->StencilEnable)
717 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILMASK, desc->StencilReadMask);
718 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILWRITEMASK, desc->StencilWriteMask);
719 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFAIL, stencil_desc->StencilFailOp);
720 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILZFAIL,
721 stencil_desc->StencilDepthFailOp);
722 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILPASS, stencil_desc->StencilPassOp);
723 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILFUNC, stencil_desc->StencilFunc);
724 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_STENCILREF, stencil_ref);
726 wined3d_mutex_unlock();
729 static void STDMETHODCALLTYPE d3d11_immediate_context_SOSetTargets(ID3D11DeviceContext *iface, UINT buffer_count,
730 ID3D11Buffer *const *buffers, const UINT *offsets)
732 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
733 unsigned int count, i;
735 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n", iface, buffer_count, buffers, offsets);
737 count = min(buffer_count, D3D11_SO_BUFFER_SLOT_COUNT);
738 wined3d_mutex_lock();
739 for (i = 0; i < count; ++i)
741 struct d3d_buffer *buffer = unsafe_impl_from_ID3D11Buffer(buffers[i]);
743 wined3d_device_set_stream_output(device->wined3d_device, i,
744 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
746 for (; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
748 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
750 wined3d_mutex_unlock();
753 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawAuto(ID3D11DeviceContext *iface)
755 FIXME("iface %p stub!\n", iface);
758 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawIndexedInstancedIndirect(ID3D11DeviceContext *iface,
759 ID3D11Buffer *buffer, UINT offset)
761 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
764 static void STDMETHODCALLTYPE d3d11_immediate_context_DrawInstancedIndirect(ID3D11DeviceContext *iface,
765 ID3D11Buffer *buffer, UINT offset)
767 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
770 static void STDMETHODCALLTYPE d3d11_immediate_context_Dispatch(ID3D11DeviceContext *iface,
771 UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
773 FIXME("iface %p, thread_group_count_x %u, thread_group_count_y %u, thread_group_count_z %u stub!\n",
774 iface, thread_group_count_x, thread_group_count_y, thread_group_count_z);
777 static void STDMETHODCALLTYPE d3d11_immediate_context_DispatchIndirect(ID3D11DeviceContext *iface,
778 ID3D11Buffer *buffer, UINT offset)
780 FIXME("iface %p, buffer %p, offset %u stub!\n", iface, buffer, offset);
783 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceContext *iface,
784 ID3D11RasterizerState *rasterizer_state)
786 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
787 const D3D11_RASTERIZER_DESC *desc;
789 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
791 wined3d_mutex_lock();
792 if (!(device->rasterizer_state = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
794 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
795 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
796 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
797 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
798 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
799 wined3d_mutex_unlock();
800 return;
803 desc = &device->rasterizer_state->desc;
804 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
805 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
806 /* glFrontFace() */
807 if (desc->FrontCounterClockwise)
808 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
809 /* OpenGL style depth bias. */
810 if (desc->DepthBias || desc->SlopeScaledDepthBias)
811 FIXME("Ignoring depth bias.\n");
812 /* GL_DEPTH_CLAMP */
813 if (!desc->DepthClipEnable)
814 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
815 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
816 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
817 wined3d_device_set_render_state(device->wined3d_device,
818 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
819 wined3d_mutex_unlock();
822 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetViewports(ID3D11DeviceContext *iface,
823 UINT viewport_count, const D3D11_VIEWPORT *viewports)
825 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
826 struct wined3d_viewport wined3d_vp;
828 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
830 if (viewport_count > 1)
831 FIXME("Multiple viewports not implemented.\n");
833 if (!viewport_count)
834 return;
836 if (viewports[0].TopLeftX != (UINT)viewports[0].TopLeftX
837 || viewports[0].TopLeftY != (UINT)viewports[0].TopLeftY
838 || viewports[0].Width != (UINT)viewports[0].Width
839 || viewports[0].Height != (UINT)viewports[0].Height)
840 FIXME("Floating-point viewports not implemented.\n");
842 wined3d_vp.x = viewports[0].TopLeftX;
843 wined3d_vp.y = viewports[0].TopLeftY;
844 wined3d_vp.width = viewports[0].Width;
845 wined3d_vp.height = viewports[0].Height;
846 wined3d_vp.min_z = viewports[0].MinDepth;
847 wined3d_vp.max_z = viewports[0].MaxDepth;
849 wined3d_mutex_lock();
850 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
851 wined3d_mutex_unlock();
854 static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetScissorRects(ID3D11DeviceContext *iface,
855 UINT rect_count, const D3D11_RECT *rects)
857 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
859 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
861 if (rect_count > 1)
862 FIXME("Multiple scissor rects not implemented.\n");
864 if (!rect_count)
865 return;
867 wined3d_mutex_lock();
868 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
869 wined3d_mutex_unlock();
872 static void STDMETHODCALLTYPE d3d11_immediate_context_CopySubresourceRegion(ID3D11DeviceContext *iface,
873 ID3D11Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
874 ID3D11Resource *src_resource, UINT src_subresource_idx, const D3D11_BOX *src_box)
876 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
877 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
878 struct wined3d_box wined3d_src_box;
880 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
881 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
882 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
883 src_resource, src_subresource_idx, src_box);
885 if (src_box)
887 wined3d_src_box.left = src_box->left;
888 wined3d_src_box.top = src_box->top;
889 wined3d_src_box.front = src_box->front;
890 wined3d_src_box.right = src_box->right;
891 wined3d_src_box.bottom = src_box->bottom;
892 wined3d_src_box.back = src_box->back;
895 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
896 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
897 wined3d_mutex_lock();
898 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
899 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
900 wined3d_mutex_unlock();
903 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyResource(ID3D11DeviceContext *iface,
904 ID3D11Resource *dst_resource, ID3D11Resource *src_resource)
906 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
907 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
909 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
911 wined3d_dst_resource = wined3d_resource_from_d3d11_resource(dst_resource);
912 wined3d_src_resource = wined3d_resource_from_d3d11_resource(src_resource);
913 wined3d_mutex_lock();
914 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
915 wined3d_mutex_unlock();
918 static void STDMETHODCALLTYPE d3d11_immediate_context_UpdateSubresource(ID3D11DeviceContext *iface,
919 ID3D11Resource *resource, UINT subresource_idx, const D3D11_BOX *box,
920 const void *data, UINT row_pitch, UINT depth_pitch)
922 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
923 struct wined3d_resource *wined3d_resource;
924 struct wined3d_box wined3d_box;
926 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
927 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
929 if (box)
931 wined3d_box.left = box->left;
932 wined3d_box.top = box->top;
933 wined3d_box.front = box->front;
934 wined3d_box.right = box->right;
935 wined3d_box.bottom = box->bottom;
936 wined3d_box.back = box->back;
939 wined3d_resource = wined3d_resource_from_d3d11_resource(resource);
940 wined3d_mutex_lock();
941 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
942 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
943 wined3d_mutex_unlock();
946 static void STDMETHODCALLTYPE d3d11_immediate_context_CopyStructureCount(ID3D11DeviceContext *iface,
947 ID3D11Buffer *dst_buffer, UINT dst_offset, ID3D11UnorderedAccessView *src_view)
949 FIXME("iface %p, dst_buffer %p, dst_offset %u, src_view %p stub!\n",
950 iface, dst_buffer, dst_offset, src_view);
953 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearRenderTargetView(ID3D11DeviceContext *iface,
954 ID3D11RenderTargetView *render_target_view, const float color_rgba[4])
956 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
957 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D11RenderTargetView(render_target_view);
958 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
959 HRESULT hr;
961 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
962 iface, render_target_view, debug_float4(color_rgba));
964 wined3d_mutex_lock();
965 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
966 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
967 ERR("Failed to clear view, hr %#x.\n", hr);
968 wined3d_mutex_unlock();
971 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewUint(ID3D11DeviceContext *iface,
972 ID3D11UnorderedAccessView *unordered_access_view, const UINT values[4])
974 FIXME("iface %p, unordered_access_view %p, values {%u %u %u %u} stub!\n",
975 iface, unordered_access_view, values[0], values[1], values[2], values[3]);
978 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearUnorderedAccessViewFloat(ID3D11DeviceContext *iface,
979 ID3D11UnorderedAccessView *unordered_access_view, const float values[4])
981 FIXME("iface %p, unordered_access_view %p, values %s stub!\n",
982 iface, unordered_access_view, debug_float4(values));
985 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearDepthStencilView(ID3D11DeviceContext *iface,
986 ID3D11DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
988 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
989 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
990 DWORD wined3d_flags;
991 HRESULT hr;
993 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
994 iface, depth_stencil_view, flags, depth, stencil);
996 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
998 wined3d_mutex_lock();
999 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
1000 wined3d_flags, NULL, depth, stencil)))
1001 ERR("Failed to clear view, hr %#x.\n", hr);
1002 wined3d_mutex_unlock();
1005 static void STDMETHODCALLTYPE d3d11_immediate_context_GenerateMips(ID3D11DeviceContext *iface,
1006 ID3D11ShaderResourceView *view)
1008 FIXME("iface %p, view %p stub!\n", iface, view);
1011 static void STDMETHODCALLTYPE d3d11_immediate_context_SetResourceMinLOD(ID3D11DeviceContext *iface,
1012 ID3D11Resource *resource, FLOAT min_lod)
1014 FIXME("iface %p, resource %p, min_lod %f stub!\n", iface, resource, min_lod);
1017 static FLOAT STDMETHODCALLTYPE d3d11_immediate_context_GetResourceMinLOD(ID3D11DeviceContext *iface,
1018 ID3D11Resource *resource)
1020 FIXME("iface %p, resource %p stub!\n", iface, resource);
1022 return 0.0f;
1025 static void STDMETHODCALLTYPE d3d11_immediate_context_ResolveSubresource(ID3D11DeviceContext *iface,
1026 ID3D11Resource *dst_resource, UINT dst_subresource_idx,
1027 ID3D11Resource *src_resource, UINT src_subresource_idx,
1028 DXGI_FORMAT format)
1030 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, src_resource %p, src_subresource_idx %u, "
1031 "format %s stub!\n",
1032 iface, dst_resource, dst_subresource_idx, src_resource, src_subresource_idx,
1033 debug_dxgi_format(format));
1036 static void STDMETHODCALLTYPE d3d11_immediate_context_ExecuteCommandList(ID3D11DeviceContext *iface,
1037 ID3D11CommandList *command_list, BOOL restore_state)
1039 FIXME("iface %p, command_list %p, restore_state %#x stub!\n", iface, command_list, restore_state);
1042 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShaderResources(ID3D11DeviceContext *iface,
1043 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1045 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1046 iface, start_slot, view_count, views);
1049 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetShader(ID3D11DeviceContext *iface,
1050 ID3D11HullShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1052 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1053 iface, shader, class_instances, class_instance_count);
1056 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetSamplers(ID3D11DeviceContext *iface,
1057 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1059 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1060 iface, start_slot, sampler_count, samplers);
1063 static void STDMETHODCALLTYPE d3d11_immediate_context_HSSetConstantBuffers(ID3D11DeviceContext *iface,
1064 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1066 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1067 iface, start_slot, buffer_count, buffers);
1070 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShaderResources(ID3D11DeviceContext *iface,
1071 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1073 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1074 iface, start_slot, view_count, views);
1077 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetShader(ID3D11DeviceContext *iface,
1078 ID3D11DomainShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1080 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1081 iface, shader, class_instances, class_instance_count);
1084 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetSamplers(ID3D11DeviceContext *iface,
1085 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1087 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1088 iface, start_slot, sampler_count, samplers);
1091 static void STDMETHODCALLTYPE d3d11_immediate_context_DSSetConstantBuffers(ID3D11DeviceContext *iface,
1092 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1094 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1095 iface, start_slot, buffer_count, buffers);
1098 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShaderResources(ID3D11DeviceContext *iface,
1099 UINT start_slot, UINT view_count, ID3D11ShaderResourceView *const *views)
1101 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1102 iface, start_slot, view_count, views);
1105 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetUnorderedAccessViews(ID3D11DeviceContext *iface,
1106 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView *const *views, const UINT *initial_counts)
1108 FIXME("iface %p, start_slot %u, view_count %u, views %p, initial_counts %p stub!\n",
1109 iface, start_slot, view_count, views, initial_counts);
1112 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetShader(ID3D11DeviceContext *iface,
1113 ID3D11ComputeShader *shader, ID3D11ClassInstance *const *class_instances, UINT class_instance_count)
1115 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %u stub!\n",
1116 iface, shader, class_instances, class_instance_count);
1119 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetSamplers(ID3D11DeviceContext *iface,
1120 UINT start_slot, UINT sampler_count, ID3D11SamplerState *const *samplers)
1122 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1123 iface, start_slot, sampler_count, samplers);
1126 static void STDMETHODCALLTYPE d3d11_immediate_context_CSSetConstantBuffers(ID3D11DeviceContext *iface,
1127 UINT start_slot, UINT buffer_count, ID3D11Buffer *const *buffers)
1129 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1130 iface, start_slot, buffer_count, buffers);
1133 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetConstantBuffers(ID3D11DeviceContext *iface,
1134 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1136 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1137 unsigned int i;
1139 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1140 iface, start_slot, buffer_count, buffers);
1142 wined3d_mutex_lock();
1143 for (i = 0; i < buffer_count; ++i)
1145 struct wined3d_buffer *wined3d_buffer;
1146 struct d3d_buffer *buffer_impl;
1148 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1150 buffers[i] = NULL;
1151 continue;
1154 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1155 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1156 ID3D11Buffer_AddRef(buffers[i]);
1158 wined3d_mutex_unlock();
1161 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShaderResources(ID3D11DeviceContext *iface,
1162 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1164 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1165 unsigned int i;
1167 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1168 iface, start_slot, view_count, views);
1170 wined3d_mutex_lock();
1171 for (i = 0; i < view_count; ++i)
1173 struct wined3d_shader_resource_view *wined3d_view;
1174 struct d3d_shader_resource_view *view_impl;
1176 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1178 views[i] = NULL;
1179 continue;
1182 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1183 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1184 ID3D11ShaderResourceView_AddRef(views[i]);
1186 wined3d_mutex_unlock();
1189 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetShader(ID3D11DeviceContext *iface,
1190 ID3D11PixelShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1192 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1193 struct wined3d_shader *wined3d_shader;
1194 struct d3d_pixel_shader *shader_impl;
1196 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1197 iface, shader, class_instances, class_instance_count);
1199 if (class_instances || class_instance_count)
1200 FIXME("Dynamic linking not implemented yet.\n");
1202 wined3d_mutex_lock();
1203 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1205 wined3d_mutex_unlock();
1206 *shader = NULL;
1207 return;
1210 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1211 wined3d_mutex_unlock();
1212 *shader = &shader_impl->ID3D11PixelShader_iface;
1213 ID3D11PixelShader_AddRef(*shader);
1216 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetSamplers(ID3D11DeviceContext *iface,
1217 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1219 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1220 unsigned int i;
1222 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1223 iface, start_slot, sampler_count, samplers);
1225 wined3d_mutex_lock();
1226 for (i = 0; i < sampler_count; ++i)
1228 struct wined3d_sampler *wined3d_sampler;
1229 struct d3d_sampler_state *sampler_impl;
1231 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1233 samplers[i] = NULL;
1234 continue;
1237 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1238 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1239 ID3D11SamplerState_AddRef(samplers[i]);
1241 wined3d_mutex_unlock();
1244 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShader(ID3D11DeviceContext *iface,
1245 ID3D11VertexShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1247 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1248 struct d3d_vertex_shader *shader_impl;
1249 struct wined3d_shader *wined3d_shader;
1251 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1252 iface, shader, class_instances, class_instance_count);
1254 if (class_instances || class_instance_count)
1255 FIXME("Dynamic linking not implemented yet.\n");
1257 wined3d_mutex_lock();
1258 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1260 wined3d_mutex_unlock();
1261 *shader = NULL;
1262 return;
1265 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1266 wined3d_mutex_unlock();
1267 *shader = &shader_impl->ID3D11VertexShader_iface;
1268 ID3D11VertexShader_AddRef(*shader);
1271 static void STDMETHODCALLTYPE d3d11_immediate_context_PSGetConstantBuffers(ID3D11DeviceContext *iface,
1272 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1274 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1275 unsigned int i;
1277 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1278 iface, start_slot, buffer_count, buffers);
1280 wined3d_mutex_lock();
1281 for (i = 0; i < buffer_count; ++i)
1283 struct wined3d_buffer *wined3d_buffer;
1284 struct d3d_buffer *buffer_impl;
1286 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1288 buffers[i] = NULL;
1289 continue;
1292 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1293 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1294 ID3D11Buffer_AddRef(buffers[i]);
1296 wined3d_mutex_unlock();
1299 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetInputLayout(ID3D11DeviceContext *iface,
1300 ID3D11InputLayout **input_layout)
1302 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1303 struct wined3d_vertex_declaration *wined3d_declaration;
1304 struct d3d_input_layout *input_layout_impl;
1306 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1308 wined3d_mutex_lock();
1309 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1311 wined3d_mutex_unlock();
1312 *input_layout = NULL;
1313 return;
1316 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1317 wined3d_mutex_unlock();
1318 *input_layout = &input_layout_impl->ID3D11InputLayout_iface;
1319 ID3D11InputLayout_AddRef(*input_layout);
1322 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetVertexBuffers(ID3D11DeviceContext *iface,
1323 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers, UINT *strides, UINT *offsets)
1325 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p stub!\n",
1326 iface, start_slot, buffer_count, buffers, strides, offsets);
1329 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetIndexBuffer(ID3D11DeviceContext *iface,
1330 ID3D11Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1332 FIXME("iface %p, buffer %p, format %p, offset %p stub!\n", iface, buffer, format, offset);
1335 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetConstantBuffers(ID3D11DeviceContext *iface,
1336 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1338 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1339 unsigned int i;
1341 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1342 iface, start_slot, buffer_count, buffers);
1344 wined3d_mutex_lock();
1345 for (i = 0; i < buffer_count; ++i)
1347 struct wined3d_buffer *wined3d_buffer;
1348 struct d3d_buffer *buffer_impl;
1350 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1352 buffers[i] = NULL;
1353 continue;
1356 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1357 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1358 ID3D11Buffer_AddRef(buffers[i]);
1360 wined3d_mutex_unlock();
1363 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShader(ID3D11DeviceContext *iface,
1364 ID3D11GeometryShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1366 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1367 struct d3d_geometry_shader *shader_impl;
1368 struct wined3d_shader *wined3d_shader;
1370 TRACE("iface %p, shader %p, class_instances %p, class_instance_count %p.\n",
1371 iface, shader, class_instances, class_instance_count);
1373 if (class_instances || class_instance_count)
1374 FIXME("Dynamic linking not implemented yet.\n");
1376 wined3d_mutex_lock();
1377 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1379 wined3d_mutex_unlock();
1380 *shader = NULL;
1381 return;
1384 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1385 wined3d_mutex_unlock();
1386 *shader = &shader_impl->ID3D11GeometryShader_iface;
1387 ID3D11GeometryShader_AddRef(*shader);
1390 static void STDMETHODCALLTYPE d3d11_immediate_context_IAGetPrimitiveTopology(ID3D11DeviceContext *iface,
1391 D3D11_PRIMITIVE_TOPOLOGY *topology)
1393 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1395 TRACE("iface %p, topology %p.\n", iface, topology);
1397 wined3d_mutex_lock();
1398 wined3d_device_get_primitive_type(device->wined3d_device, (enum wined3d_primitive_type *)topology);
1399 wined3d_mutex_unlock();
1402 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetShaderResources(ID3D11DeviceContext *iface,
1403 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1405 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1406 unsigned int i;
1408 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1410 wined3d_mutex_lock();
1411 for (i = 0; i < view_count; ++i)
1413 struct wined3d_shader_resource_view *wined3d_view;
1414 struct d3d_shader_resource_view *view_impl;
1416 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1418 views[i] = NULL;
1419 continue;
1422 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1423 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1424 ID3D11ShaderResourceView_AddRef(views[i]);
1426 wined3d_mutex_unlock();
1429 static void STDMETHODCALLTYPE d3d11_immediate_context_VSGetSamplers(ID3D11DeviceContext *iface,
1430 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1432 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1433 unsigned int i;
1435 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1436 iface, start_slot, sampler_count, samplers);
1438 wined3d_mutex_lock();
1439 for (i = 0; i < sampler_count; ++i)
1441 struct wined3d_sampler *wined3d_sampler;
1442 struct d3d_sampler_state *sampler_impl;
1444 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1446 samplers[i] = NULL;
1447 continue;
1450 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1451 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1452 ID3D11SamplerState_AddRef(samplers[i]);
1454 wined3d_mutex_unlock();
1457 static void STDMETHODCALLTYPE d3d11_immediate_context_GetPredication(ID3D11DeviceContext *iface,
1458 ID3D11Predicate **predicate, BOOL *value)
1460 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1461 struct wined3d_query *wined3d_predicate;
1462 struct d3d_query *predicate_impl;
1464 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1466 wined3d_mutex_lock();
1467 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1469 wined3d_mutex_unlock();
1470 *predicate = NULL;
1471 return;
1474 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1475 wined3d_mutex_unlock();
1476 *predicate = (ID3D11Predicate *)&predicate_impl->ID3D11Query_iface;
1477 ID3D11Predicate_AddRef(*predicate);
1480 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetShaderResources(ID3D11DeviceContext *iface,
1481 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1483 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1484 unsigned int i;
1486 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views);
1488 wined3d_mutex_lock();
1489 for (i = 0; i < view_count; ++i)
1491 struct wined3d_shader_resource_view *wined3d_view;
1492 struct d3d_shader_resource_view *view_impl;
1494 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1496 views[i] = NULL;
1497 continue;
1500 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1501 views[i] = &view_impl->ID3D11ShaderResourceView_iface;
1502 ID3D11ShaderResourceView_AddRef(views[i]);
1504 wined3d_mutex_unlock();
1507 static void STDMETHODCALLTYPE d3d11_immediate_context_GSGetSamplers(ID3D11DeviceContext *iface,
1508 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1510 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1511 unsigned int i;
1513 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1514 iface, start_slot, sampler_count, samplers);
1516 wined3d_mutex_lock();
1517 for (i = 0; i < sampler_count; ++i)
1519 struct d3d_sampler_state *sampler_impl;
1520 struct wined3d_sampler *wined3d_sampler;
1522 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1524 samplers[i] = NULL;
1525 continue;
1528 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1529 samplers[i] = &sampler_impl->ID3D11SamplerState_iface;
1530 ID3D11SamplerState_AddRef(samplers[i]);
1532 wined3d_mutex_unlock();
1535 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargets(ID3D11DeviceContext *iface,
1536 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1537 ID3D11DepthStencilView **depth_stencil_view)
1539 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1540 struct wined3d_rendertarget_view *wined3d_view;
1542 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1543 iface, render_target_view_count, render_target_views, depth_stencil_view);
1545 wined3d_mutex_lock();
1546 if (render_target_views)
1548 struct d3d_rendertarget_view *view_impl;
1549 unsigned int i;
1551 for (i = 0; i < render_target_view_count; ++i)
1553 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1554 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1556 render_target_views[i] = NULL;
1557 continue;
1560 render_target_views[i] = &view_impl->ID3D11RenderTargetView_iface;
1561 ID3D11RenderTargetView_AddRef(render_target_views[i]);
1565 if (depth_stencil_view)
1567 struct d3d_depthstencil_view *view_impl;
1569 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1570 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1572 *depth_stencil_view = NULL;
1574 else
1576 *depth_stencil_view = &view_impl->ID3D11DepthStencilView_iface;
1577 ID3D11DepthStencilView_AddRef(*depth_stencil_view);
1580 wined3d_mutex_unlock();
1583 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews(
1584 ID3D11DeviceContext *iface,
1585 UINT render_target_view_count, ID3D11RenderTargetView **render_target_views,
1586 ID3D11DepthStencilView **depth_stencil_view,
1587 UINT unordered_access_view_start_slot, UINT unordered_access_view_count,
1588 ID3D11UnorderedAccessView **unordered_access_views)
1590 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p, "
1591 "unordered_access_view_start_slot %u, unordered_access_view_count %u, "
1592 "unordered_access_views %p stub!\n",
1593 iface, render_target_view_count, render_target_views, depth_stencil_view,
1594 unordered_access_view_start_slot, unordered_access_view_count, unordered_access_views);
1597 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetBlendState(ID3D11DeviceContext *iface,
1598 ID3D11BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1600 FIXME("iface %p, blend_state %p, blend_factor %p, sample_mask %p stub!\n",
1601 iface, blend_state, blend_factor, sample_mask);
1604 static void STDMETHODCALLTYPE d3d11_immediate_context_OMGetDepthStencilState(ID3D11DeviceContext *iface,
1605 ID3D11DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1607 FIXME("iface %p, depth_stencil_state %p, stencil_ref %p stub!\n", iface, depth_stencil_state, stencil_ref);
1610 static void STDMETHODCALLTYPE d3d11_immediate_context_SOGetTargets(ID3D11DeviceContext *iface,
1611 UINT buffer_count, ID3D11Buffer **buffers)
1613 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1614 unsigned int i;
1616 TRACE("iface %p, buffer_count %u, buffers %p.\n", iface, buffer_count, buffers);
1618 wined3d_mutex_lock();
1619 for (i = 0; i < buffer_count; ++i)
1621 struct wined3d_buffer *wined3d_buffer;
1622 struct d3d_buffer *buffer_impl;
1624 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, NULL)))
1626 buffers[i] = NULL;
1627 continue;
1630 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1631 buffers[i] = &buffer_impl->ID3D11Buffer_iface;
1632 ID3D11Buffer_AddRef(buffers[i]);
1634 wined3d_mutex_unlock();
1637 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetState(ID3D11DeviceContext *iface,
1638 ID3D11RasterizerState **rasterizer_state)
1640 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1642 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1644 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D11RasterizerState_iface : NULL))
1645 ID3D11RasterizerState_AddRef(*rasterizer_state);
1648 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetViewports(ID3D11DeviceContext *iface,
1649 UINT *viewport_count, D3D11_VIEWPORT *viewports)
1651 struct d3d_device *device = device_from_immediate_ID3D11DeviceContext(iface);
1652 struct wined3d_viewport wined3d_vp;
1654 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1656 if (!viewports)
1658 *viewport_count = 1;
1659 return;
1662 if (!*viewport_count)
1663 return;
1665 wined3d_mutex_lock();
1666 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1667 wined3d_mutex_unlock();
1669 viewports[0].TopLeftX = wined3d_vp.x;
1670 viewports[0].TopLeftY = wined3d_vp.y;
1671 viewports[0].Width = wined3d_vp.width;
1672 viewports[0].Height = wined3d_vp.height;
1673 viewports[0].MinDepth = wined3d_vp.min_z;
1674 viewports[0].MaxDepth = wined3d_vp.max_z;
1676 if (*viewport_count > 1)
1677 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1680 static void STDMETHODCALLTYPE d3d11_immediate_context_RSGetScissorRects(ID3D11DeviceContext *iface,
1681 UINT *rect_count, D3D11_RECT *rects)
1683 FIXME("iface %p, rect_count %p, rects %p stub!\n", iface, rect_count, rects);
1686 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShaderResources(ID3D11DeviceContext *iface,
1687 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1689 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1692 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetShader(ID3D11DeviceContext *iface,
1693 ID3D11HullShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1695 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1696 iface, shader, class_instances, class_instance_count);
1699 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetSamplers(ID3D11DeviceContext *iface,
1700 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1702 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1703 iface, start_slot, sampler_count, samplers);
1706 static void STDMETHODCALLTYPE d3d11_immediate_context_HSGetConstantBuffers(ID3D11DeviceContext *iface,
1707 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1709 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1710 iface, start_slot, buffer_count, buffers);
1713 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShaderResources(ID3D11DeviceContext *iface,
1714 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1716 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
1717 iface, start_slot, view_count, views);
1720 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetShader(ID3D11DeviceContext *iface,
1721 ID3D11DomainShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1723 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1724 iface, shader, class_instances, class_instance_count);
1727 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetSamplers(ID3D11DeviceContext *iface,
1728 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1730 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1731 iface, start_slot, sampler_count, samplers);
1734 static void STDMETHODCALLTYPE d3d11_immediate_context_DSGetConstantBuffers(ID3D11DeviceContext *iface,
1735 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1737 FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
1738 iface, start_slot, buffer_count, buffers);
1741 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShaderResources(ID3D11DeviceContext *iface,
1742 UINT start_slot, UINT view_count, ID3D11ShaderResourceView **views)
1744 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1747 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetUnorderedAccessViews(ID3D11DeviceContext *iface,
1748 UINT start_slot, UINT view_count, ID3D11UnorderedAccessView **views)
1750 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", iface, start_slot, view_count, views);
1753 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetShader(ID3D11DeviceContext *iface,
1754 ID3D11ComputeShader **shader, ID3D11ClassInstance **class_instances, UINT *class_instance_count)
1756 FIXME("iface %p, shader %p, class_instances %p, class_instance_count %p stub!\n",
1757 iface, shader, class_instances, class_instance_count);
1760 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetSamplers(ID3D11DeviceContext *iface,
1761 UINT start_slot, UINT sampler_count, ID3D11SamplerState **samplers)
1763 FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
1764 iface, start_slot, sampler_count, samplers);
1767 static void STDMETHODCALLTYPE d3d11_immediate_context_CSGetConstantBuffers(ID3D11DeviceContext *iface,
1768 UINT start_slot, UINT buffer_count, ID3D11Buffer **buffers)
1770 FIXME("iface %p, start_slot %u, buffer_count %u, buffer %p stub!\n",
1771 iface, start_slot, buffer_count, buffers);
1774 static void STDMETHODCALLTYPE d3d11_immediate_context_ClearState(ID3D11DeviceContext *iface)
1776 FIXME("iface %p stub!\n", iface);
1779 static void STDMETHODCALLTYPE d3d11_immediate_context_Flush(ID3D11DeviceContext *iface)
1781 FIXME("iface %p stub!\n", iface);
1784 static D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE d3d11_immediate_context_GetType(ID3D11DeviceContext *iface)
1786 TRACE("iface %p.\n", iface);
1788 return D3D11_DEVICE_CONTEXT_IMMEDIATE;
1791 static UINT STDMETHODCALLTYPE d3d11_immediate_context_GetContextFlags(ID3D11DeviceContext *iface)
1793 FIXME("iface %p stub!\n", iface);
1795 return 0;
1798 static HRESULT STDMETHODCALLTYPE d3d11_immediate_context_FinishCommandList(ID3D11DeviceContext *iface,
1799 BOOL restore, ID3D11CommandList **command_list)
1801 FIXME("iface %p, restore %#x, command_list %p stub!\n", iface, restore, command_list);
1803 return E_NOTIMPL;
1806 static const struct ID3D11DeviceContextVtbl d3d11_immediate_context_vtbl =
1808 /* IUnknown methods */
1809 d3d11_immediate_context_QueryInterface,
1810 d3d11_immediate_context_AddRef,
1811 d3d11_immediate_context_Release,
1812 /* ID3D11DeviceChild methods */
1813 d3d11_immediate_context_GetDevice,
1814 d3d11_immediate_context_GetPrivateData,
1815 d3d11_immediate_context_SetPrivateData,
1816 d3d11_immediate_context_SetPrivateDataInterface,
1817 /* ID3D11DeviceContext methods */
1818 d3d11_immediate_context_VSSetConstantBuffers,
1819 d3d11_immediate_context_PSSetShaderResources,
1820 d3d11_immediate_context_PSSetShader,
1821 d3d11_immediate_context_PSSetSamplers,
1822 d3d11_immediate_context_VSSetShader,
1823 d3d11_immediate_context_DrawIndexed,
1824 d3d11_immediate_context_Draw,
1825 d3d11_immediate_context_Map,
1826 d3d11_immediate_context_Unmap,
1827 d3d11_immediate_context_PSSetConstantBuffers,
1828 d3d11_immediate_context_IASetInputLayout,
1829 d3d11_immediate_context_IASetVertexBuffers,
1830 d3d11_immediate_context_IASetIndexBuffer,
1831 d3d11_immediate_context_DrawIndexedInstanced,
1832 d3d11_immediate_context_DrawInstanced,
1833 d3d11_immediate_context_GSSetConstantBuffers,
1834 d3d11_immediate_context_GSSetShader,
1835 d3d11_immediate_context_IASetPrimitiveTopology,
1836 d3d11_immediate_context_VSSetShaderResources,
1837 d3d11_immediate_context_VSSetSamplers,
1838 d3d11_immediate_context_Begin,
1839 d3d11_immediate_context_End,
1840 d3d11_immediate_context_GetData,
1841 d3d11_immediate_context_SetPredication,
1842 d3d11_immediate_context_GSSetShaderResources,
1843 d3d11_immediate_context_GSSetSamplers,
1844 d3d11_immediate_context_OMSetRenderTargets,
1845 d3d11_immediate_context_OMSetRenderTargetsAndUnorderedAccessViews,
1846 d3d11_immediate_context_OMSetBlendState,
1847 d3d11_immediate_context_OMSetDepthStencilState,
1848 d3d11_immediate_context_SOSetTargets,
1849 d3d11_immediate_context_DrawAuto,
1850 d3d11_immediate_context_DrawIndexedInstancedIndirect,
1851 d3d11_immediate_context_DrawInstancedIndirect,
1852 d3d11_immediate_context_Dispatch,
1853 d3d11_immediate_context_DispatchIndirect,
1854 d3d11_immediate_context_RSSetState,
1855 d3d11_immediate_context_RSSetViewports,
1856 d3d11_immediate_context_RSSetScissorRects,
1857 d3d11_immediate_context_CopySubresourceRegion,
1858 d3d11_immediate_context_CopyResource,
1859 d3d11_immediate_context_UpdateSubresource,
1860 d3d11_immediate_context_CopyStructureCount,
1861 d3d11_immediate_context_ClearRenderTargetView,
1862 d3d11_immediate_context_ClearUnorderedAccessViewUint,
1863 d3d11_immediate_context_ClearUnorderedAccessViewFloat,
1864 d3d11_immediate_context_ClearDepthStencilView,
1865 d3d11_immediate_context_GenerateMips,
1866 d3d11_immediate_context_SetResourceMinLOD,
1867 d3d11_immediate_context_GetResourceMinLOD,
1868 d3d11_immediate_context_ResolveSubresource,
1869 d3d11_immediate_context_ExecuteCommandList,
1870 d3d11_immediate_context_HSSetShaderResources,
1871 d3d11_immediate_context_HSSetShader,
1872 d3d11_immediate_context_HSSetSamplers,
1873 d3d11_immediate_context_HSSetConstantBuffers,
1874 d3d11_immediate_context_DSSetShaderResources,
1875 d3d11_immediate_context_DSSetShader,
1876 d3d11_immediate_context_DSSetSamplers,
1877 d3d11_immediate_context_DSSetConstantBuffers,
1878 d3d11_immediate_context_CSSetShaderResources,
1879 d3d11_immediate_context_CSSetUnorderedAccessViews,
1880 d3d11_immediate_context_CSSetShader,
1881 d3d11_immediate_context_CSSetSamplers,
1882 d3d11_immediate_context_CSSetConstantBuffers,
1883 d3d11_immediate_context_VSGetConstantBuffers,
1884 d3d11_immediate_context_PSGetShaderResources,
1885 d3d11_immediate_context_PSGetShader,
1886 d3d11_immediate_context_PSGetSamplers,
1887 d3d11_immediate_context_VSGetShader,
1888 d3d11_immediate_context_PSGetConstantBuffers,
1889 d3d11_immediate_context_IAGetInputLayout,
1890 d3d11_immediate_context_IAGetVertexBuffers,
1891 d3d11_immediate_context_IAGetIndexBuffer,
1892 d3d11_immediate_context_GSGetConstantBuffers,
1893 d3d11_immediate_context_GSGetShader,
1894 d3d11_immediate_context_IAGetPrimitiveTopology,
1895 d3d11_immediate_context_VSGetShaderResources,
1896 d3d11_immediate_context_VSGetSamplers,
1897 d3d11_immediate_context_GetPredication,
1898 d3d11_immediate_context_GSGetShaderResources,
1899 d3d11_immediate_context_GSGetSamplers,
1900 d3d11_immediate_context_OMGetRenderTargets,
1901 d3d11_immediate_context_OMGetRenderTargetsAndUnorderedAccessViews,
1902 d3d11_immediate_context_OMGetBlendState,
1903 d3d11_immediate_context_OMGetDepthStencilState,
1904 d3d11_immediate_context_SOGetTargets,
1905 d3d11_immediate_context_RSGetState,
1906 d3d11_immediate_context_RSGetViewports,
1907 d3d11_immediate_context_RSGetScissorRects,
1908 d3d11_immediate_context_HSGetShaderResources,
1909 d3d11_immediate_context_HSGetShader,
1910 d3d11_immediate_context_HSGetSamplers,
1911 d3d11_immediate_context_HSGetConstantBuffers,
1912 d3d11_immediate_context_DSGetShaderResources,
1913 d3d11_immediate_context_DSGetShader,
1914 d3d11_immediate_context_DSGetSamplers,
1915 d3d11_immediate_context_DSGetConstantBuffers,
1916 d3d11_immediate_context_CSGetShaderResources,
1917 d3d11_immediate_context_CSGetUnorderedAccessViews,
1918 d3d11_immediate_context_CSGetShader,
1919 d3d11_immediate_context_CSGetSamplers,
1920 d3d11_immediate_context_CSGetConstantBuffers,
1921 d3d11_immediate_context_ClearState,
1922 d3d11_immediate_context_Flush,
1923 d3d11_immediate_context_GetType,
1924 d3d11_immediate_context_GetContextFlags,
1925 d3d11_immediate_context_FinishCommandList,
1928 static void d3d11_immediate_context_init(struct d3d11_immediate_context *context, struct d3d_device *device)
1930 context->ID3D11DeviceContext_iface.lpVtbl = &d3d11_immediate_context_vtbl;
1931 context->refcount = 1;
1933 ID3D11Device_AddRef(&device->ID3D11Device_iface);
1935 wined3d_private_store_init(&context->private_store);
1938 static void d3d11_immediate_context_destroy(struct d3d11_immediate_context *context)
1940 wined3d_private_store_cleanup(&context->private_store);
1943 /* ID3D11Device methods */
1945 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
1947 struct d3d_device *device = impl_from_ID3D11Device(iface);
1948 return IUnknown_QueryInterface(device->outer_unk, riid, out);
1951 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
1953 struct d3d_device *device = impl_from_ID3D11Device(iface);
1954 return IUnknown_AddRef(device->outer_unk);
1957 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
1959 struct d3d_device *device = impl_from_ID3D11Device(iface);
1960 return IUnknown_Release(device->outer_unk);
1963 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
1964 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
1966 struct d3d_device *device = impl_from_ID3D11Device(iface);
1967 struct d3d_buffer *object;
1968 HRESULT hr;
1970 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
1972 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
1973 return hr;
1975 *buffer = &object->ID3D11Buffer_iface;
1977 return S_OK;
1980 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
1981 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
1983 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1985 return E_NOTIMPL;
1988 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
1989 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
1991 struct d3d_device *device = impl_from_ID3D11Device(iface);
1992 struct d3d_texture2d *object;
1993 HRESULT hr;
1995 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1997 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
1998 return hr;
2000 *texture = &object->ID3D11Texture2D_iface;
2002 return S_OK;
2005 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
2006 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
2008 struct d3d_device *device = impl_from_ID3D11Device(iface);
2009 struct d3d_texture3d *object;
2010 HRESULT hr;
2012 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2014 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
2015 return hr;
2017 *texture = &object->ID3D11Texture3D_iface;
2019 return S_OK;
2022 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
2023 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
2025 struct d3d_device *device = impl_from_ID3D11Device(iface);
2026 struct d3d_shader_resource_view *object;
2027 HRESULT hr;
2029 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2031 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
2032 return hr;
2034 *view = &object->ID3D11ShaderResourceView_iface;
2036 return S_OK;
2039 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
2040 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
2042 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
2044 return E_NOTIMPL;
2047 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
2048 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
2050 struct d3d_device *device = impl_from_ID3D11Device(iface);
2051 struct d3d_rendertarget_view *object;
2052 HRESULT hr;
2054 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2056 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
2057 return hr;
2059 *view = &object->ID3D11RenderTargetView_iface;
2061 return S_OK;
2064 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
2065 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
2067 struct d3d_device *device = impl_from_ID3D11Device(iface);
2068 struct d3d_depthstencil_view *object;
2069 HRESULT hr;
2071 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2073 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
2074 return hr;
2076 *view = &object->ID3D11DepthStencilView_iface;
2078 return S_OK;
2081 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
2082 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
2083 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
2085 struct d3d_device *device = impl_from_ID3D11Device(iface);
2086 struct d3d_input_layout *object;
2087 HRESULT hr;
2089 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
2090 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
2091 shader_byte_code_length, input_layout);
2093 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
2094 shader_byte_code, shader_byte_code_length, &object)))
2095 return hr;
2097 *input_layout = &object->ID3D11InputLayout_iface;
2099 return S_OK;
2102 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
2103 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
2105 struct d3d_device *device = impl_from_ID3D11Device(iface);
2106 struct d3d_vertex_shader *object;
2107 HRESULT hr;
2109 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2110 iface, byte_code, byte_code_length, class_linkage, shader);
2112 if (class_linkage)
2113 FIXME("Class linkage is not implemented yet.\n");
2115 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2116 return hr;
2118 *shader = &object->ID3D11VertexShader_iface;
2120 return S_OK;
2123 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
2124 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2126 struct d3d_device *device = impl_from_ID3D11Device(iface);
2127 struct d3d_geometry_shader *object;
2128 HRESULT hr;
2130 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2131 iface, byte_code, byte_code_length, class_linkage, shader);
2133 if (class_linkage)
2134 FIXME("Class linkage is not implemented yet.\n");
2136 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
2137 return hr;
2139 *shader = &object->ID3D11GeometryShader_iface;
2141 return S_OK;
2144 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
2145 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
2146 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
2147 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
2149 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
2150 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
2151 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
2152 rasterized_stream, class_linkage, shader);
2154 return E_NOTIMPL;
2157 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
2158 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
2160 struct d3d_device *device = impl_from_ID3D11Device(iface);
2161 struct d3d_pixel_shader *object;
2162 HRESULT hr;
2164 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2165 iface, byte_code, byte_code_length, class_linkage, shader);
2167 if (class_linkage)
2168 FIXME("Class linkage is not implemented yet.\n");
2170 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2171 return hr;
2173 *shader = &object->ID3D11PixelShader_iface;
2175 return S_OK;
2178 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
2179 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
2181 struct d3d_device *device = impl_from_ID3D11Device(iface);
2182 struct d3d11_hull_shader *object;
2183 HRESULT hr;
2185 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2186 iface, byte_code, byte_code_length, class_linkage, shader);
2188 if (class_linkage)
2189 FIXME("Class linkage is not implemented yet.\n");
2191 if (FAILED(hr = d3d11_hull_shader_create(device, byte_code, byte_code_length, &object)))
2192 return hr;
2194 *shader = &object->ID3D11HullShader_iface;
2196 return S_OK;
2199 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
2200 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
2202 struct d3d_device *device = impl_from_ID3D11Device(iface);
2203 struct d3d11_domain_shader *object;
2204 HRESULT hr;
2206 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
2207 iface, byte_code, byte_code_length, class_linkage, shader);
2209 if (class_linkage)
2210 FIXME("Class linkage is not implemented yet.\n");
2212 if (FAILED(hr = d3d11_domain_shader_create(device, byte_code, byte_code_length, &object)))
2213 return hr;
2215 *shader = &object->ID3D11DomainShader_iface;
2217 return S_OK;
2220 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
2221 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
2223 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
2224 iface, byte_code, byte_code_length, class_linkage, shader);
2226 return E_NOTIMPL;
2229 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
2230 ID3D11ClassLinkage **class_linkage)
2232 FIXME("iface %p, class_linkage %p stub!\n", iface, class_linkage);
2234 return E_NOTIMPL;
2237 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
2238 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
2240 struct d3d_device *device = impl_from_ID3D11Device(iface);
2241 struct d3d_blend_state *object;
2242 struct wine_rb_entry *entry;
2243 D3D11_BLEND_DESC tmp_desc;
2244 unsigned int i, j;
2245 HRESULT hr;
2247 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2249 if (!desc)
2250 return E_INVALIDARG;
2252 /* D3D11_RENDER_TARGET_BLEND_DESC has a hole, which is a problem because we use
2253 * D3D11_BLEND_DESC as a key in the rbtree. */
2254 memset(&tmp_desc, 0, sizeof(tmp_desc));
2255 tmp_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
2256 tmp_desc.IndependentBlendEnable = desc->IndependentBlendEnable;
2257 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2259 j = desc->IndependentBlendEnable ? i : 0;
2260 tmp_desc.RenderTarget[i].BlendEnable = desc->RenderTarget[j].BlendEnable;
2261 tmp_desc.RenderTarget[i].SrcBlend = desc->RenderTarget[j].SrcBlend;
2262 tmp_desc.RenderTarget[i].DestBlend = desc->RenderTarget[j].DestBlend;
2263 tmp_desc.RenderTarget[i].BlendOp = desc->RenderTarget[j].BlendOp;
2264 tmp_desc.RenderTarget[i].SrcBlendAlpha = desc->RenderTarget[j].SrcBlendAlpha;
2265 tmp_desc.RenderTarget[i].DestBlendAlpha = desc->RenderTarget[j].DestBlendAlpha;
2266 tmp_desc.RenderTarget[i].BlendOpAlpha = desc->RenderTarget[j].BlendOpAlpha;
2267 tmp_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTarget[j].RenderTargetWriteMask;
2270 wined3d_mutex_lock();
2271 if ((entry = wine_rb_get(&device->blend_states, &tmp_desc)))
2273 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_blend_state, entry);
2275 TRACE("Returning existing blend state %p.\n", object);
2276 *blend_state = &object->ID3D11BlendState_iface;
2277 ID3D11BlendState_AddRef(*blend_state);
2278 wined3d_mutex_unlock();
2280 return S_OK;
2282 wined3d_mutex_unlock();
2284 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2285 return E_OUTOFMEMORY;
2287 if (FAILED(hr = d3d_blend_state_init(object, device, &tmp_desc)))
2289 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2290 HeapFree(GetProcessHeap(), 0, object);
2291 return hr;
2294 TRACE("Created blend state %p.\n", object);
2295 *blend_state = &object->ID3D11BlendState_iface;
2297 return S_OK;
2300 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
2301 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
2303 struct d3d_device *device = impl_from_ID3D11Device(iface);
2304 struct d3d_depthstencil_state *object;
2305 D3D11_DEPTH_STENCIL_DESC tmp_desc;
2306 struct wine_rb_entry *entry;
2307 HRESULT hr;
2309 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2311 if (!desc)
2312 return E_INVALIDARG;
2314 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2315 * it as a key in the rbtree. */
2316 memset(&tmp_desc, 0, sizeof(tmp_desc));
2317 tmp_desc.DepthEnable = desc->DepthEnable;
2318 if (desc->DepthEnable)
2320 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2321 tmp_desc.DepthFunc = desc->DepthFunc;
2323 else
2325 tmp_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2326 tmp_desc.DepthFunc = D3D11_COMPARISON_LESS;
2328 tmp_desc.StencilEnable = desc->StencilEnable;
2329 if (desc->StencilEnable)
2331 tmp_desc.StencilReadMask = desc->StencilReadMask;
2332 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2333 tmp_desc.FrontFace = desc->FrontFace;
2334 tmp_desc.BackFace = desc->BackFace;
2336 else
2338 tmp_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2339 tmp_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2340 tmp_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2341 tmp_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2342 tmp_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2343 tmp_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2344 tmp_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2345 tmp_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2346 tmp_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2347 tmp_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2350 wined3d_mutex_lock();
2351 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
2353 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
2355 TRACE("Returning existing depthstencil state %p.\n", object);
2356 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2357 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
2358 wined3d_mutex_unlock();
2360 return S_OK;
2362 wined3d_mutex_unlock();
2364 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2365 return E_OUTOFMEMORY;
2367 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
2369 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
2370 HeapFree(GetProcessHeap(), 0, object);
2371 return hr;
2374 TRACE("Created depthstencil state %p.\n", object);
2375 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
2377 return S_OK;
2380 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
2381 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
2383 struct d3d_device *device = impl_from_ID3D11Device(iface);
2384 struct d3d_rasterizer_state *object;
2385 struct wine_rb_entry *entry;
2386 HRESULT hr;
2388 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2390 if (!desc)
2391 return E_INVALIDARG;
2393 wined3d_mutex_lock();
2394 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
2396 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
2398 TRACE("Returning existing rasterizer state %p.\n", object);
2399 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2400 ID3D11RasterizerState_AddRef(*rasterizer_state);
2401 wined3d_mutex_unlock();
2403 return S_OK;
2405 wined3d_mutex_unlock();
2407 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2408 return E_OUTOFMEMORY;
2410 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
2412 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
2413 HeapFree(GetProcessHeap(), 0, object);
2414 return hr;
2417 TRACE("Created rasterizer state %p.\n", object);
2418 *rasterizer_state = &object->ID3D11RasterizerState_iface;
2420 return S_OK;
2423 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
2424 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
2426 struct d3d_device *device = impl_from_ID3D11Device(iface);
2427 D3D11_SAMPLER_DESC normalized_desc;
2428 struct d3d_sampler_state *object;
2429 struct wine_rb_entry *entry;
2430 HRESULT hr;
2432 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2434 if (!desc)
2435 return E_INVALIDARG;
2437 normalized_desc = *desc;
2438 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(normalized_desc.Filter))
2439 normalized_desc.MaxAnisotropy = 0;
2440 if (!D3D11_DECODE_IS_COMPARISON_FILTER(normalized_desc.Filter))
2441 normalized_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
2442 if (normalized_desc.AddressU != D3D11_TEXTURE_ADDRESS_BORDER
2443 && normalized_desc.AddressV != D3D11_TEXTURE_ADDRESS_BORDER
2444 && normalized_desc.AddressW != D3D11_TEXTURE_ADDRESS_BORDER)
2445 memset(&normalized_desc.BorderColor, 0, sizeof(normalized_desc.BorderColor));
2447 wined3d_mutex_lock();
2448 if ((entry = wine_rb_get(&device->sampler_states, &normalized_desc)))
2450 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_sampler_state, entry);
2452 TRACE("Returning existing sampler state %p.\n", object);
2453 *sampler_state = &object->ID3D11SamplerState_iface;
2454 ID3D11SamplerState_AddRef(*sampler_state);
2455 wined3d_mutex_unlock();
2457 return S_OK;
2459 wined3d_mutex_unlock();
2461 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2462 return E_OUTOFMEMORY;
2464 if (FAILED(hr = d3d_sampler_state_init(object, device, &normalized_desc)))
2466 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2467 HeapFree(GetProcessHeap(), 0, object);
2468 return hr;
2471 TRACE("Created sampler state %p.\n", object);
2472 *sampler_state = &object->ID3D11SamplerState_iface;
2474 return S_OK;
2477 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
2478 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
2480 struct d3d_device *device = impl_from_ID3D11Device(iface);
2481 struct d3d_query *object;
2482 HRESULT hr;
2484 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2486 if (FAILED(hr = d3d_query_create(device, desc, FALSE, &object)))
2487 return hr;
2489 if (query)
2491 *query = &object->ID3D11Query_iface;
2492 return S_OK;
2495 ID3D11Query_Release(&object->ID3D11Query_iface);
2496 return S_FALSE;
2499 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
2500 ID3D11Predicate **predicate)
2502 struct d3d_device *device = impl_from_ID3D11Device(iface);
2503 struct d3d_query *object;
2504 HRESULT hr;
2506 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2508 if (FAILED(hr = d3d_query_create(device, desc, TRUE, &object)))
2509 return hr;
2511 if (predicate)
2513 *predicate = (ID3D11Predicate *)&object->ID3D11Query_iface;
2514 return S_OK;
2517 ID3D11Query_Release(&object->ID3D11Query_iface);
2518 return S_FALSE;
2521 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2522 ID3D11Counter **counter)
2524 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2526 return E_NOTIMPL;
2529 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
2530 ID3D11DeviceContext **context)
2532 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
2534 return E_NOTIMPL;
2537 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
2538 void **out)
2540 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
2542 return E_NOTIMPL;
2545 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
2546 UINT *format_support)
2548 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
2550 return E_NOTIMPL;
2553 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
2554 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2556 struct d3d_device *device = impl_from_ID3D11Device(iface);
2557 struct wined3d_device_creation_parameters params;
2558 struct wined3d *wined3d;
2559 HRESULT hr;
2561 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
2562 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2564 if (!quality_level_count)
2565 return E_INVALIDARG;
2567 *quality_level_count = 0;
2569 if (!sample_count)
2570 return E_FAIL;
2571 if (sample_count == 1)
2573 *quality_level_count = 1;
2574 return S_OK;
2576 if (sample_count > D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT)
2577 return E_FAIL;
2579 wined3d_mutex_lock();
2580 wined3d = wined3d_device_get_wined3d(device->wined3d_device);
2581 wined3d_device_get_creation_parameters(device->wined3d_device, &params);
2582 hr = wined3d_check_device_multisample_type(wined3d, params.adapter_idx, params.device_type,
2583 wined3dformat_from_dxgi_format(format), TRUE, sample_count, quality_level_count);
2584 wined3d_mutex_unlock();
2586 if (hr == WINED3DERR_INVALIDCALL)
2587 return E_INVALIDARG;
2588 if (hr == WINED3DERR_NOTAVAILABLE)
2589 return S_OK;
2590 return hr;
2593 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
2595 FIXME("iface %p, info %p stub!\n", iface, info);
2598 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
2599 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
2600 char *units, UINT *units_length, char *description, UINT *description_length)
2602 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
2603 "units %p, units_length %p, description %p, description_length %p stub!\n",
2604 iface, desc, type, active_counter_count, name, name_length,
2605 units, units_length, description, description_length);
2607 return E_NOTIMPL;
2610 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
2611 void *feature_support_data, UINT feature_support_data_size)
2613 FIXME("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u stub!\n",
2614 iface, feature, feature_support_data, feature_support_data_size);
2616 return E_NOTIMPL;
2619 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
2620 UINT *data_size, void *data)
2622 IDXGIDevice *dxgi_device;
2623 HRESULT hr;
2625 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2627 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2628 return hr;
2629 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
2630 IDXGIDevice_Release(dxgi_device);
2632 return hr;
2635 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
2636 UINT data_size, const void *data)
2638 IDXGIDevice *dxgi_device;
2639 HRESULT hr;
2641 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
2643 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2644 return hr;
2645 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
2646 IDXGIDevice_Release(dxgi_device);
2648 return hr;
2651 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
2652 const IUnknown *data)
2654 IDXGIDevice *dxgi_device;
2655 HRESULT hr;
2657 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
2659 if (FAILED(hr = ID3D11Device_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2660 return hr;
2661 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
2662 IDXGIDevice_Release(dxgi_device);
2664 return hr;
2667 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
2669 struct d3d_device *device = impl_from_ID3D11Device(iface);
2671 TRACE("iface %p.\n", iface);
2673 return device->feature_level;
2676 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
2678 FIXME("iface %p stub!\n", iface);
2680 return 0;
2683 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
2685 FIXME("iface %p stub!\n", iface);
2687 return S_OK;
2690 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
2691 ID3D11DeviceContext **immediate_context)
2693 struct d3d_device *device = impl_from_ID3D11Device(iface);
2695 TRACE("iface %p, immediate_context %p.\n", iface, immediate_context);
2697 *immediate_context = &device->immediate_context.ID3D11DeviceContext_iface;
2698 ID3D11DeviceContext_AddRef(*immediate_context);
2701 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
2703 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2705 return E_NOTIMPL;
2708 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
2710 FIXME("iface %p stub!\n", iface);
2712 return 0;
2715 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
2717 /* IUnknown methods */
2718 d3d11_device_QueryInterface,
2719 d3d11_device_AddRef,
2720 d3d11_device_Release,
2721 /* ID3D11Device methods */
2722 d3d11_device_CreateBuffer,
2723 d3d11_device_CreateTexture1D,
2724 d3d11_device_CreateTexture2D,
2725 d3d11_device_CreateTexture3D,
2726 d3d11_device_CreateShaderResourceView,
2727 d3d11_device_CreateUnorderedAccessView,
2728 d3d11_device_CreateRenderTargetView,
2729 d3d11_device_CreateDepthStencilView,
2730 d3d11_device_CreateInputLayout,
2731 d3d11_device_CreateVertexShader,
2732 d3d11_device_CreateGeometryShader,
2733 d3d11_device_CreateGeometryShaderWithStreamOutput,
2734 d3d11_device_CreatePixelShader,
2735 d3d11_device_CreateHullShader,
2736 d3d11_device_CreateDomainShader,
2737 d3d11_device_CreateComputeShader,
2738 d3d11_device_CreateClassLinkage,
2739 d3d11_device_CreateBlendState,
2740 d3d11_device_CreateDepthStencilState,
2741 d3d11_device_CreateRasterizerState,
2742 d3d11_device_CreateSamplerState,
2743 d3d11_device_CreateQuery,
2744 d3d11_device_CreatePredicate,
2745 d3d11_device_CreateCounter,
2746 d3d11_device_CreateDeferredContext,
2747 d3d11_device_OpenSharedResource,
2748 d3d11_device_CheckFormatSupport,
2749 d3d11_device_CheckMultisampleQualityLevels,
2750 d3d11_device_CheckCounterInfo,
2751 d3d11_device_CheckCounter,
2752 d3d11_device_CheckFeatureSupport,
2753 d3d11_device_GetPrivateData,
2754 d3d11_device_SetPrivateData,
2755 d3d11_device_SetPrivateDataInterface,
2756 d3d11_device_GetFeatureLevel,
2757 d3d11_device_GetCreationFlags,
2758 d3d11_device_GetDeviceRemovedReason,
2759 d3d11_device_GetImmediateContext,
2760 d3d11_device_SetExceptionMode,
2761 d3d11_device_GetExceptionMode,
2764 /* Inner IUnknown methods */
2766 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
2768 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
2771 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
2773 struct d3d_device *device = impl_from_IUnknown(iface);
2775 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
2777 if (IsEqualGUID(riid, &IID_ID3D11Device)
2778 || IsEqualGUID(riid, &IID_IUnknown))
2780 *out = &device->ID3D11Device_iface;
2782 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
2783 || IsEqualGUID(riid, &IID_ID3D10Device))
2785 *out = &device->ID3D10Device1_iface;
2787 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
2789 *out = &device->ID3D10Multithread_iface;
2791 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
2793 *out = &device->IWineDXGIDeviceParent_iface;
2795 else
2797 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
2798 *out = NULL;
2799 return E_NOINTERFACE;
2802 IUnknown_AddRef((IUnknown *)*out);
2803 return S_OK;
2806 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
2808 struct d3d_device *device = impl_from_IUnknown(iface);
2809 ULONG refcount = InterlockedIncrement(&device->refcount);
2811 TRACE("%p increasing refcount to %u.\n", device, refcount);
2813 return refcount;
2816 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
2818 struct d3d_device *device = impl_from_IUnknown(iface);
2819 ULONG refcount = InterlockedDecrement(&device->refcount);
2821 TRACE("%p decreasing refcount to %u.\n", device, refcount);
2823 if (!refcount)
2825 d3d11_immediate_context_destroy(&device->immediate_context);
2826 if (device->wined3d_device)
2828 wined3d_mutex_lock();
2829 wined3d_device_decref(device->wined3d_device);
2830 wined3d_mutex_unlock();
2832 wine_rb_destroy(&device->sampler_states, NULL, NULL);
2833 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2834 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2835 wine_rb_destroy(&device->blend_states, NULL, NULL);
2838 return refcount;
2841 /* IUnknown methods */
2843 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
2844 void **ppv)
2846 struct d3d_device *This = impl_from_ID3D10Device(iface);
2847 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
2850 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
2852 struct d3d_device *This = impl_from_ID3D10Device(iface);
2853 return IUnknown_AddRef(This->outer_unk);
2856 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
2858 struct d3d_device *This = impl_from_ID3D10Device(iface);
2859 return IUnknown_Release(This->outer_unk);
2862 /* ID3D10Device methods */
2864 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
2865 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
2867 struct d3d_device *device = impl_from_ID3D10Device(iface);
2868 unsigned int i;
2870 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2871 iface, start_slot, buffer_count, buffers);
2873 wined3d_mutex_lock();
2874 for (i = 0; i < buffer_count; ++i)
2876 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
2878 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
2879 buffer ? buffer->wined3d_buffer : NULL);
2881 wined3d_mutex_unlock();
2884 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
2885 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
2887 struct d3d_device *device = impl_from_ID3D10Device(iface);
2888 unsigned int i;
2890 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
2891 iface, start_slot, view_count, views);
2893 wined3d_mutex_lock();
2894 for (i = 0; i < view_count; ++i)
2896 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
2898 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
2899 view ? view->wined3d_view : NULL);
2901 wined3d_mutex_unlock();
2904 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
2905 ID3D10PixelShader *shader)
2907 struct d3d_device *This = impl_from_ID3D10Device(iface);
2908 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
2910 TRACE("iface %p, shader %p\n", iface, shader);
2912 wined3d_mutex_lock();
2913 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
2914 wined3d_mutex_unlock();
2917 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
2918 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
2920 struct d3d_device *device = impl_from_ID3D10Device(iface);
2921 unsigned int i;
2923 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
2924 iface, start_slot, sampler_count, samplers);
2926 wined3d_mutex_lock();
2927 for (i = 0; i < sampler_count; ++i)
2929 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
2931 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
2932 sampler ? sampler->wined3d_sampler : NULL);
2934 wined3d_mutex_unlock();
2937 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
2938 ID3D10VertexShader *shader)
2940 struct d3d_device *This = impl_from_ID3D10Device(iface);
2941 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
2943 TRACE("iface %p, shader %p\n", iface, shader);
2945 wined3d_mutex_lock();
2946 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
2947 wined3d_mutex_unlock();
2950 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
2951 UINT start_index_location, INT base_vertex_location)
2953 struct d3d_device *This = impl_from_ID3D10Device(iface);
2955 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
2956 iface, index_count, start_index_location, base_vertex_location);
2958 wined3d_mutex_lock();
2959 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
2960 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
2961 wined3d_mutex_unlock();
2964 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
2965 UINT start_vertex_location)
2967 struct d3d_device *This = impl_from_ID3D10Device(iface);
2969 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
2970 iface, vertex_count, start_vertex_location);
2972 wined3d_mutex_lock();
2973 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
2974 wined3d_mutex_unlock();
2977 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
2978 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
2980 struct d3d_device *device = impl_from_ID3D10Device(iface);
2981 unsigned int i;
2983 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
2984 iface, start_slot, buffer_count, buffers);
2986 wined3d_mutex_lock();
2987 for (i = 0; i < buffer_count; ++i)
2989 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
2991 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
2992 buffer ? buffer->wined3d_buffer : NULL);
2994 wined3d_mutex_unlock();
2997 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
2998 ID3D10InputLayout *input_layout)
3000 struct d3d_device *This = impl_from_ID3D10Device(iface);
3001 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
3003 TRACE("iface %p, input_layout %p\n", iface, input_layout);
3005 wined3d_mutex_lock();
3006 wined3d_device_set_vertex_declaration(This->wined3d_device,
3007 layout ? layout->wined3d_decl : NULL);
3008 wined3d_mutex_unlock();
3011 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
3012 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
3014 struct d3d_device *This = impl_from_ID3D10Device(iface);
3015 unsigned int i;
3017 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
3018 iface, start_slot, buffer_count, buffers, strides, offsets);
3020 wined3d_mutex_lock();
3021 for (i = 0; i < buffer_count; ++i)
3023 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3025 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
3026 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
3028 wined3d_mutex_unlock();
3031 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
3032 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
3034 struct d3d_device *This = impl_from_ID3D10Device(iface);
3035 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
3037 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
3038 iface, buffer, debug_dxgi_format(format), offset);
3040 wined3d_mutex_lock();
3041 wined3d_device_set_index_buffer(This->wined3d_device,
3042 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
3043 wined3dformat_from_dxgi_format(format));
3044 wined3d_mutex_unlock();
3045 if (offset) FIXME("offset %u not supported.\n", offset);
3048 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
3049 UINT instance_index_count, UINT instance_count, UINT start_index_location,
3050 INT base_vertex_location, UINT start_instance_location)
3052 struct d3d_device *device = impl_from_ID3D10Device(iface);
3054 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
3055 "base_vertex_location %d, start_instance_location %u.\n",
3056 iface, instance_index_count, instance_count, start_index_location,
3057 base_vertex_location, start_instance_location);
3059 wined3d_mutex_lock();
3060 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
3061 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
3062 instance_index_count, start_instance_location, instance_count);
3063 wined3d_mutex_unlock();
3066 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
3067 UINT instance_vertex_count, UINT instance_count,
3068 UINT start_vertex_location, UINT start_instance_location)
3070 struct d3d_device *device = impl_from_ID3D10Device(iface);
3072 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
3073 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
3074 start_vertex_location, start_instance_location);
3076 wined3d_mutex_lock();
3077 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
3078 instance_vertex_count, start_instance_location, instance_count);
3079 wined3d_mutex_unlock();
3082 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
3083 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
3085 struct d3d_device *device = impl_from_ID3D10Device(iface);
3086 unsigned int i;
3088 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3089 iface, start_slot, buffer_count, buffers);
3091 wined3d_mutex_lock();
3092 for (i = 0; i < buffer_count; ++i)
3094 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
3096 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
3097 buffer ? buffer->wined3d_buffer : NULL);
3099 wined3d_mutex_unlock();
3102 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
3104 struct d3d_device *device = impl_from_ID3D10Device(iface);
3105 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
3107 TRACE("iface %p, shader %p.\n", iface, shader);
3109 wined3d_mutex_lock();
3110 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
3111 wined3d_mutex_unlock();
3114 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
3115 D3D10_PRIMITIVE_TOPOLOGY topology)
3117 struct d3d_device *This = impl_from_ID3D10Device(iface);
3119 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
3121 wined3d_mutex_lock();
3122 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
3123 wined3d_mutex_unlock();
3126 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
3127 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3129 struct d3d_device *device = impl_from_ID3D10Device(iface);
3130 unsigned int i;
3132 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3133 iface, start_slot, view_count, views);
3135 wined3d_mutex_lock();
3136 for (i = 0; i < view_count; ++i)
3138 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3140 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
3141 view ? view->wined3d_view : NULL);
3143 wined3d_mutex_unlock();
3146 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
3147 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3149 struct d3d_device *device = impl_from_ID3D10Device(iface);
3150 unsigned int i;
3152 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3153 iface, start_slot, sampler_count, samplers);
3155 wined3d_mutex_lock();
3156 for (i = 0; i < sampler_count; ++i)
3158 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3160 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
3161 sampler ? sampler->wined3d_sampler : NULL);
3163 wined3d_mutex_unlock();
3166 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
3168 struct d3d_device *device = impl_from_ID3D10Device(iface);
3169 struct d3d_query *query;
3171 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
3173 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
3174 wined3d_mutex_lock();
3175 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
3176 wined3d_mutex_unlock();
3179 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
3180 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
3182 struct d3d_device *device = impl_from_ID3D10Device(iface);
3183 unsigned int i;
3185 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3186 iface, start_slot, view_count, views);
3188 wined3d_mutex_lock();
3189 for (i = 0; i < view_count; ++i)
3191 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
3193 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
3194 view ? view->wined3d_view : NULL);
3196 wined3d_mutex_unlock();
3199 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
3200 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
3202 struct d3d_device *device = impl_from_ID3D10Device(iface);
3203 unsigned int i;
3205 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3206 iface, start_slot, sampler_count, samplers);
3208 wined3d_mutex_lock();
3209 for (i = 0; i < sampler_count; ++i)
3211 struct d3d_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
3213 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
3214 sampler ? sampler->wined3d_sampler : NULL);
3216 wined3d_mutex_unlock();
3219 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
3220 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
3221 ID3D10DepthStencilView *depth_stencil_view)
3223 struct d3d_device *device = impl_from_ID3D10Device(iface);
3224 struct d3d_depthstencil_view *dsv;
3225 unsigned int i;
3227 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3228 iface, render_target_view_count, render_target_views, depth_stencil_view);
3230 wined3d_mutex_lock();
3231 for (i = 0; i < render_target_view_count; ++i)
3233 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
3235 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
3236 rtv ? rtv->wined3d_view : NULL, FALSE);
3238 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
3240 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
3243 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3244 wined3d_device_set_depth_stencil_view(device->wined3d_device,
3245 dsv ? dsv->wined3d_view : NULL);
3246 wined3d_mutex_unlock();
3249 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
3250 ID3D10BlendState *blend_state, const float blend_factor[4], UINT sample_mask)
3252 struct d3d_device *device = impl_from_ID3D10Device(iface);
3253 struct d3d_blend_state *blend_state_object;
3255 TRACE("iface %p, blend_state %p, blend_factor %s, sample_mask 0x%08x.\n",
3256 iface, blend_state, debug_float4(blend_factor), sample_mask);
3258 blend_state_object = unsafe_impl_from_ID3D10BlendState(blend_state);
3259 d3d11_immediate_context_OMSetBlendState(&device->immediate_context.ID3D11DeviceContext_iface,
3260 blend_state_object ? &blend_state_object->ID3D11BlendState_iface : NULL, blend_factor, sample_mask);
3263 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
3264 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
3266 struct d3d_device *device = impl_from_ID3D10Device(iface);
3267 struct d3d_depthstencil_state *ds_state_object;
3269 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
3270 iface, depth_stencil_state, stencil_ref);
3272 ds_state_object = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
3273 d3d11_immediate_context_OMSetDepthStencilState(&device->immediate_context.ID3D11DeviceContext_iface,
3274 ds_state_object ? &ds_state_object->ID3D11DepthStencilState_iface : NULL, stencil_ref);
3277 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
3278 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
3280 struct d3d_device *device = impl_from_ID3D10Device(iface);
3281 unsigned int count, i;
3283 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
3285 count = min(target_count, 4);
3286 wined3d_mutex_lock();
3287 for (i = 0; i < count; ++i)
3289 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
3291 wined3d_device_set_stream_output(device->wined3d_device, i,
3292 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
3295 for (i = count; i < 4; ++i)
3297 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
3299 wined3d_mutex_unlock();
3302 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
3304 FIXME("iface %p stub!\n", iface);
3307 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
3309 struct d3d_device *device = impl_from_ID3D10Device(iface);
3310 struct d3d_rasterizer_state *rasterizer_state_object;
3312 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
3314 rasterizer_state_object = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
3315 d3d11_immediate_context_RSSetState(&device->immediate_context.ID3D11DeviceContext_iface,
3316 rasterizer_state_object ? &rasterizer_state_object->ID3D11RasterizerState_iface : NULL);
3319 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
3320 UINT viewport_count, const D3D10_VIEWPORT *viewports)
3322 struct d3d_device *device = impl_from_ID3D10Device(iface);
3323 struct wined3d_viewport wined3d_vp;
3325 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
3327 if (viewport_count > 1)
3328 FIXME("Multiple viewports not implemented.\n");
3330 if (!viewport_count)
3331 return;
3333 wined3d_vp.x = viewports[0].TopLeftX;
3334 wined3d_vp.y = viewports[0].TopLeftY;
3335 wined3d_vp.width = viewports[0].Width;
3336 wined3d_vp.height = viewports[0].Height;
3337 wined3d_vp.min_z = viewports[0].MinDepth;
3338 wined3d_vp.max_z = viewports[0].MaxDepth;
3340 wined3d_mutex_lock();
3341 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
3342 wined3d_mutex_unlock();
3345 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
3346 UINT rect_count, const D3D10_RECT *rects)
3348 struct d3d_device *device = impl_from_ID3D10Device(iface);
3350 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
3352 if (rect_count > 1)
3353 FIXME("Multiple scissor rects not implemented.\n");
3355 if (!rect_count)
3356 return;
3358 wined3d_mutex_lock();
3359 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
3360 wined3d_mutex_unlock();
3363 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
3364 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
3365 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
3367 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3368 struct d3d_device *device = impl_from_ID3D10Device(iface);
3369 struct wined3d_box wined3d_src_box;
3371 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
3372 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
3373 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
3374 src_resource, src_subresource_idx, src_box);
3376 if (src_box)
3378 wined3d_src_box.left = src_box->left;
3379 wined3d_src_box.top = src_box->top;
3380 wined3d_src_box.front = src_box->front;
3381 wined3d_src_box.right = src_box->right;
3382 wined3d_src_box.bottom = src_box->bottom;
3383 wined3d_src_box.back = src_box->back;
3386 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3387 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3388 wined3d_mutex_lock();
3389 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
3390 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, src_box ? &wined3d_src_box : NULL);
3391 wined3d_mutex_unlock();
3394 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
3395 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
3397 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
3398 struct d3d_device *device = impl_from_ID3D10Device(iface);
3400 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
3402 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
3403 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
3404 wined3d_mutex_lock();
3405 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
3406 wined3d_mutex_unlock();
3409 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
3410 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
3411 const void *data, UINT row_pitch, UINT depth_pitch)
3413 struct d3d_device *device = impl_from_ID3D10Device(iface);
3414 ID3D11Resource *d3d11_resource;
3416 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
3417 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
3419 ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource);
3420 d3d11_immediate_context_UpdateSubresource(&device->immediate_context.ID3D11DeviceContext_iface,
3421 d3d11_resource, subresource_idx, (const D3D11_BOX *)box, data, row_pitch, depth_pitch);
3422 ID3D11Resource_Release(d3d11_resource);
3425 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
3426 ID3D10RenderTargetView *render_target_view, const float color_rgba[4])
3428 struct d3d_device *device = impl_from_ID3D10Device(iface);
3429 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
3430 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
3431 HRESULT hr;
3433 TRACE("iface %p, render_target_view %p, color_rgba %s.\n",
3434 iface, render_target_view, debug_float4(color_rgba));
3436 wined3d_mutex_lock();
3437 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3438 WINED3DCLEAR_TARGET, &color, 0.0f, 0)))
3439 ERR("Failed to clear view, hr %#x.\n", hr);
3440 wined3d_mutex_unlock();
3443 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
3444 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
3446 struct d3d_device *device = impl_from_ID3D10Device(iface);
3447 struct d3d_depthstencil_view *view = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
3448 DWORD wined3d_flags;
3449 HRESULT hr;
3451 TRACE("iface %p, depth_stencil_view %p, flags %#x, depth %.8e, stencil %u.\n",
3452 iface, depth_stencil_view, flags, depth, stencil);
3454 wined3d_flags = wined3d_clear_flags_from_d3d11_clear_flags(flags);
3456 wined3d_mutex_lock();
3457 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL,
3458 wined3d_flags, NULL, depth, stencil)))
3459 ERR("Failed to clear view, hr %#x.\n", hr);
3460 wined3d_mutex_unlock();
3463 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
3464 ID3D10ShaderResourceView *shader_resource_view)
3466 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
3469 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
3470 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
3471 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
3473 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
3474 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
3475 iface, dst_resource, dst_subresource_idx,
3476 src_resource, src_subresource_idx, debug_dxgi_format(format));
3479 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
3480 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3482 struct d3d_device *device = impl_from_ID3D10Device(iface);
3483 unsigned int i;
3485 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3486 iface, start_slot, buffer_count, buffers);
3488 wined3d_mutex_lock();
3489 for (i = 0; i < buffer_count; ++i)
3491 struct wined3d_buffer *wined3d_buffer;
3492 struct d3d_buffer *buffer_impl;
3494 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
3496 buffers[i] = NULL;
3497 continue;
3500 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3501 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3502 ID3D10Buffer_AddRef(buffers[i]);
3504 wined3d_mutex_unlock();
3507 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
3508 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3510 struct d3d_device *device = impl_from_ID3D10Device(iface);
3511 unsigned int i;
3513 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3514 iface, start_slot, view_count, views);
3516 wined3d_mutex_lock();
3517 for (i = 0; i < view_count; ++i)
3519 struct wined3d_shader_resource_view *wined3d_view;
3520 struct d3d_shader_resource_view *view_impl;
3522 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
3524 views[i] = NULL;
3525 continue;
3528 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3529 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3530 ID3D10ShaderResourceView_AddRef(views[i]);
3532 wined3d_mutex_unlock();
3535 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
3537 struct d3d_device *device = impl_from_ID3D10Device(iface);
3538 struct d3d_pixel_shader *shader_impl;
3539 struct wined3d_shader *wined3d_shader;
3541 TRACE("iface %p, shader %p.\n", iface, shader);
3543 wined3d_mutex_lock();
3544 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
3546 wined3d_mutex_unlock();
3547 *shader = NULL;
3548 return;
3551 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3552 wined3d_mutex_unlock();
3553 *shader = &shader_impl->ID3D10PixelShader_iface;
3554 ID3D10PixelShader_AddRef(*shader);
3557 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
3558 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3560 struct d3d_device *device = impl_from_ID3D10Device(iface);
3561 unsigned int i;
3563 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3564 iface, start_slot, sampler_count, samplers);
3566 wined3d_mutex_lock();
3567 for (i = 0; i < sampler_count; ++i)
3569 struct d3d_sampler_state *sampler_impl;
3570 struct wined3d_sampler *wined3d_sampler;
3572 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
3574 samplers[i] = NULL;
3575 continue;
3578 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
3579 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
3580 ID3D10SamplerState_AddRef(samplers[i]);
3582 wined3d_mutex_unlock();
3585 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
3587 struct d3d_device *device = impl_from_ID3D10Device(iface);
3588 struct d3d_vertex_shader *shader_impl;
3589 struct wined3d_shader *wined3d_shader;
3591 TRACE("iface %p, shader %p.\n", iface, shader);
3593 wined3d_mutex_lock();
3594 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
3596 wined3d_mutex_unlock();
3597 *shader = NULL;
3598 return;
3601 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3602 wined3d_mutex_unlock();
3603 *shader = &shader_impl->ID3D10VertexShader_iface;
3604 ID3D10VertexShader_AddRef(*shader);
3607 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
3608 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3610 struct d3d_device *device = impl_from_ID3D10Device(iface);
3611 unsigned int i;
3613 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3614 iface, start_slot, buffer_count, buffers);
3616 wined3d_mutex_lock();
3617 for (i = 0; i < buffer_count; ++i)
3619 struct wined3d_buffer *wined3d_buffer;
3620 struct d3d_buffer *buffer_impl;
3622 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
3624 buffers[i] = NULL;
3625 continue;
3628 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3629 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3630 ID3D10Buffer_AddRef(buffers[i]);
3632 wined3d_mutex_unlock();
3635 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
3637 struct d3d_device *device = impl_from_ID3D10Device(iface);
3638 struct wined3d_vertex_declaration *wined3d_declaration;
3639 struct d3d_input_layout *input_layout_impl;
3641 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
3643 wined3d_mutex_lock();
3644 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
3646 wined3d_mutex_unlock();
3647 *input_layout = NULL;
3648 return;
3651 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
3652 wined3d_mutex_unlock();
3653 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
3654 ID3D10InputLayout_AddRef(*input_layout);
3657 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
3658 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
3660 struct d3d_device *device = impl_from_ID3D10Device(iface);
3661 unsigned int i;
3663 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
3664 iface, start_slot, buffer_count, buffers, strides, offsets);
3666 wined3d_mutex_lock();
3667 for (i = 0; i < buffer_count; ++i)
3669 struct wined3d_buffer *wined3d_buffer;
3670 struct d3d_buffer *buffer_impl;
3672 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
3673 &wined3d_buffer, &offsets[i], &strides[i])))
3674 ERR("Failed to get vertex buffer.\n");
3676 if (!wined3d_buffer)
3678 buffers[i] = NULL;
3679 continue;
3682 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3683 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3684 ID3D10Buffer_AddRef(buffers[i]);
3686 wined3d_mutex_unlock();
3689 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
3690 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
3692 struct d3d_device *device = impl_from_ID3D10Device(iface);
3693 enum wined3d_format_id wined3d_format;
3694 struct wined3d_buffer *wined3d_buffer;
3695 struct d3d_buffer *buffer_impl;
3697 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
3699 wined3d_mutex_lock();
3700 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
3701 *format = dxgi_format_from_wined3dformat(wined3d_format);
3702 *offset = 0; /* FIXME */
3703 if (!wined3d_buffer)
3705 wined3d_mutex_unlock();
3706 *buffer = NULL;
3707 return;
3710 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3711 wined3d_mutex_unlock();
3712 *buffer = &buffer_impl->ID3D10Buffer_iface;
3713 ID3D10Buffer_AddRef(*buffer);
3716 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
3717 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
3719 struct d3d_device *device = impl_from_ID3D10Device(iface);
3720 unsigned int i;
3722 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
3723 iface, start_slot, buffer_count, buffers);
3725 wined3d_mutex_lock();
3726 for (i = 0; i < buffer_count; ++i)
3728 struct wined3d_buffer *wined3d_buffer;
3729 struct d3d_buffer *buffer_impl;
3731 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
3733 buffers[i] = NULL;
3734 continue;
3737 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
3738 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
3739 ID3D10Buffer_AddRef(buffers[i]);
3741 wined3d_mutex_unlock();
3744 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
3746 struct d3d_device *device = impl_from_ID3D10Device(iface);
3747 struct d3d_geometry_shader *shader_impl;
3748 struct wined3d_shader *wined3d_shader;
3750 TRACE("iface %p, shader %p.\n", iface, shader);
3752 wined3d_mutex_lock();
3753 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
3755 wined3d_mutex_unlock();
3756 *shader = NULL;
3757 return;
3760 shader_impl = wined3d_shader_get_parent(wined3d_shader);
3761 wined3d_mutex_unlock();
3762 *shader = &shader_impl->ID3D10GeometryShader_iface;
3763 ID3D10GeometryShader_AddRef(*shader);
3766 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
3767 D3D10_PRIMITIVE_TOPOLOGY *topology)
3769 struct d3d_device *This = impl_from_ID3D10Device(iface);
3771 TRACE("iface %p, topology %p\n", iface, topology);
3773 wined3d_mutex_lock();
3774 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
3775 wined3d_mutex_unlock();
3778 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
3779 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3781 struct d3d_device *device = impl_from_ID3D10Device(iface);
3782 unsigned int i;
3784 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3785 iface, start_slot, view_count, views);
3787 wined3d_mutex_lock();
3788 for (i = 0; i < view_count; ++i)
3790 struct wined3d_shader_resource_view *wined3d_view;
3791 struct d3d_shader_resource_view *view_impl;
3793 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
3795 views[i] = NULL;
3796 continue;
3799 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3800 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3801 ID3D10ShaderResourceView_AddRef(views[i]);
3803 wined3d_mutex_unlock();
3806 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
3807 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3809 struct d3d_device *device = impl_from_ID3D10Device(iface);
3810 unsigned int i;
3812 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3813 iface, start_slot, sampler_count, samplers);
3815 wined3d_mutex_lock();
3816 for (i = 0; i < sampler_count; ++i)
3818 struct d3d_sampler_state *sampler_impl;
3819 struct wined3d_sampler *wined3d_sampler;
3821 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
3823 samplers[i] = NULL;
3824 continue;
3827 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
3828 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
3829 ID3D10SamplerState_AddRef(samplers[i]);
3831 wined3d_mutex_unlock();
3834 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
3835 ID3D10Predicate **predicate, BOOL *value)
3837 struct d3d_device *device = impl_from_ID3D10Device(iface);
3838 struct wined3d_query *wined3d_predicate;
3839 struct d3d_query *predicate_impl;
3841 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
3843 wined3d_mutex_lock();
3844 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
3846 wined3d_mutex_unlock();
3847 *predicate = NULL;
3848 return;
3851 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
3852 wined3d_mutex_unlock();
3853 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
3854 ID3D10Predicate_AddRef(*predicate);
3857 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
3858 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
3860 struct d3d_device *device = impl_from_ID3D10Device(iface);
3861 unsigned int i;
3863 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
3864 iface, start_slot, view_count, views);
3866 wined3d_mutex_lock();
3867 for (i = 0; i < view_count; ++i)
3869 struct wined3d_shader_resource_view *wined3d_view;
3870 struct d3d_shader_resource_view *view_impl;
3872 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
3874 views[i] = NULL;
3875 continue;
3878 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
3879 views[i] = (ID3D10ShaderResourceView *)&view_impl->ID3D10ShaderResourceView1_iface;
3880 ID3D10ShaderResourceView_AddRef(views[i]);
3882 wined3d_mutex_unlock();
3885 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
3886 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
3888 struct d3d_device *device = impl_from_ID3D10Device(iface);
3889 unsigned int i;
3891 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
3892 iface, start_slot, sampler_count, samplers);
3894 wined3d_mutex_lock();
3895 for (i = 0; i < sampler_count; ++i)
3897 struct d3d_sampler_state *sampler_impl;
3898 struct wined3d_sampler *wined3d_sampler;
3900 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
3902 samplers[i] = NULL;
3903 continue;
3906 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
3907 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
3908 ID3D10SamplerState_AddRef(samplers[i]);
3910 wined3d_mutex_unlock();
3913 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
3914 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
3916 struct d3d_device *device = impl_from_ID3D10Device(iface);
3917 struct wined3d_rendertarget_view *wined3d_view;
3919 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
3920 iface, view_count, render_target_views, depth_stencil_view);
3922 wined3d_mutex_lock();
3923 if (render_target_views)
3925 struct d3d_rendertarget_view *view_impl;
3926 unsigned int i;
3928 for (i = 0; i < view_count; ++i)
3930 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
3931 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
3933 render_target_views[i] = NULL;
3934 continue;
3937 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
3938 ID3D10RenderTargetView_AddRef(render_target_views[i]);
3942 if (depth_stencil_view)
3944 struct d3d_depthstencil_view *view_impl;
3946 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
3947 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
3949 *depth_stencil_view = NULL;
3951 else
3953 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
3954 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
3957 wined3d_mutex_unlock();
3960 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
3961 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
3963 struct d3d_device *device = impl_from_ID3D10Device(iface);
3965 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
3966 iface, blend_state, blend_factor, sample_mask);
3968 if ((*blend_state = device->blend_state ? (ID3D10BlendState *)&device->blend_state->ID3D10BlendState1_iface : NULL))
3969 ID3D10BlendState_AddRef(*blend_state);
3970 wined3d_mutex_lock();
3971 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
3972 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
3973 wined3d_mutex_unlock();
3976 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
3977 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
3979 struct d3d_device *device = impl_from_ID3D10Device(iface);
3981 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
3982 iface, depth_stencil_state, stencil_ref);
3984 if ((*depth_stencil_state = device->depth_stencil_state
3985 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
3986 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
3987 *stencil_ref = device->stencil_ref;
3990 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
3991 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
3993 struct d3d_device *device = impl_from_ID3D10Device(iface);
3994 unsigned int i;
3996 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
3997 iface, buffer_count, buffers, offsets);
3999 wined3d_mutex_lock();
4000 for (i = 0; i < buffer_count; ++i)
4002 struct wined3d_buffer *wined3d_buffer;
4003 struct d3d_buffer *buffer_impl;
4005 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
4007 buffers[i] = NULL;
4008 continue;
4011 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
4012 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
4013 ID3D10Buffer_AddRef(buffers[i]);
4015 wined3d_mutex_unlock();
4018 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
4020 struct d3d_device *device = impl_from_ID3D10Device(iface);
4022 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
4024 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
4025 ID3D10RasterizerState_AddRef(*rasterizer_state);
4028 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
4029 UINT *viewport_count, D3D10_VIEWPORT *viewports)
4031 struct d3d_device *device = impl_from_ID3D10Device(iface);
4032 struct wined3d_viewport wined3d_vp;
4034 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
4036 if (!viewports)
4038 *viewport_count = 1;
4039 return;
4042 if (!*viewport_count)
4043 return;
4045 wined3d_mutex_lock();
4046 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
4047 wined3d_mutex_unlock();
4049 viewports[0].TopLeftX = wined3d_vp.x;
4050 viewports[0].TopLeftY = wined3d_vp.y;
4051 viewports[0].Width = wined3d_vp.width;
4052 viewports[0].Height = wined3d_vp.height;
4053 viewports[0].MinDepth = wined3d_vp.min_z;
4054 viewports[0].MaxDepth = wined3d_vp.max_z;
4056 if (*viewport_count > 1)
4057 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
4060 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
4062 struct d3d_device *device = impl_from_ID3D10Device(iface);
4064 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
4066 if (!rects)
4068 *rect_count = 1;
4069 return;
4072 if (!*rect_count)
4073 return;
4075 wined3d_mutex_lock();
4076 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
4077 wined3d_mutex_unlock();
4078 if (*rect_count > 1)
4079 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
4082 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
4084 TRACE("iface %p.\n", iface);
4086 /* In the current implementation the device is never removed, so we can
4087 * just return S_OK here. */
4089 return S_OK;
4092 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
4094 FIXME("iface %p, flags %#x stub!\n", iface, flags);
4096 return E_NOTIMPL;
4099 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
4101 FIXME("iface %p stub!\n", iface);
4103 return 0;
4106 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
4107 REFGUID guid, UINT *data_size, void *data)
4109 struct d3d_device *device = impl_from_ID3D10Device(iface);
4111 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4113 return d3d11_device_GetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4116 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
4117 REFGUID guid, UINT data_size, const void *data)
4119 struct d3d_device *device = impl_from_ID3D10Device(iface);
4121 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
4123 return d3d11_device_SetPrivateData(&device->ID3D11Device_iface, guid, data_size, data);
4126 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
4127 REFGUID guid, const IUnknown *data)
4129 struct d3d_device *device = impl_from_ID3D10Device(iface);
4131 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
4133 return d3d11_device_SetPrivateDataInterface(&device->ID3D11Device_iface, guid, data);
4136 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
4138 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
4139 struct d3d_device *device = impl_from_ID3D10Device(iface);
4140 unsigned int i;
4142 TRACE("iface %p.\n", iface);
4144 wined3d_mutex_lock();
4145 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
4146 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4148 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
4150 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4152 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
4154 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4156 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
4158 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
4159 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4161 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
4163 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4165 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
4167 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4169 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
4171 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
4172 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
4174 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
4176 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
4178 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
4180 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
4182 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
4184 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
4186 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
4188 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
4189 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
4190 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
4191 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4193 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
4195 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
4196 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
4197 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
4198 ID3D10Device1_RSSetViewports(iface, 0, NULL);
4199 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
4200 ID3D10Device1_RSSetState(iface, NULL);
4201 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
4203 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
4205 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
4206 wined3d_mutex_unlock();
4209 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
4211 FIXME("iface %p stub!\n", iface);
4214 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
4215 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
4217 struct d3d_device *device = impl_from_ID3D10Device(iface);
4218 D3D11_BUFFER_DESC d3d11_desc;
4219 struct d3d_buffer *object;
4220 HRESULT hr;
4222 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
4224 d3d11_desc.ByteWidth = desc->ByteWidth;
4225 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4226 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4227 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4228 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4229 d3d11_desc.StructureByteStride = 0;
4231 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4232 return hr;
4234 *buffer = &object->ID3D10Buffer_iface;
4236 return S_OK;
4239 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
4240 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
4242 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
4244 return E_NOTIMPL;
4247 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
4248 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4249 ID3D10Texture2D **texture)
4251 struct d3d_device *device = impl_from_ID3D10Device(iface);
4252 D3D11_TEXTURE2D_DESC d3d11_desc;
4253 struct d3d_texture2d *object;
4254 HRESULT hr;
4256 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4258 d3d11_desc.Width = desc->Width;
4259 d3d11_desc.Height = desc->Height;
4260 d3d11_desc.MipLevels = desc->MipLevels;
4261 d3d11_desc.ArraySize = desc->ArraySize;
4262 d3d11_desc.Format = desc->Format;
4263 d3d11_desc.SampleDesc = desc->SampleDesc;
4264 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4265 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4266 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4267 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4269 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4270 return hr;
4272 *texture = &object->ID3D10Texture2D_iface;
4274 return S_OK;
4277 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
4278 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
4279 ID3D10Texture3D **texture)
4281 struct d3d_device *device = impl_from_ID3D10Device(iface);
4282 D3D11_TEXTURE3D_DESC d3d11_desc;
4283 struct d3d_texture3d *object;
4284 HRESULT hr;
4286 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
4288 d3d11_desc.Width = desc->Width;
4289 d3d11_desc.Height = desc->Height;
4290 d3d11_desc.Depth = desc->Depth;
4291 d3d11_desc.MipLevels = desc->MipLevels;
4292 d3d11_desc.Format = desc->Format;
4293 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
4294 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
4295 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
4296 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
4298 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
4299 return hr;
4301 *texture = &object->ID3D10Texture3D_iface;
4303 return S_OK;
4306 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
4307 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
4309 struct d3d_device *device = impl_from_ID3D10Device(iface);
4310 struct d3d_shader_resource_view *object;
4311 ID3D11Resource *d3d11_resource;
4312 HRESULT hr;
4314 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4316 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4318 ERR("Resource does not implement ID3D11Resource.\n");
4319 return E_FAIL;
4322 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
4323 &object);
4324 ID3D11Resource_Release(d3d11_resource);
4325 if (FAILED(hr))
4326 return hr;
4328 *view = &object->ID3D10ShaderResourceView1_iface;
4330 return S_OK;
4333 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
4334 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
4336 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4338 return d3d10_device_CreateShaderResourceView1(iface, resource,
4339 (const D3D10_SHADER_RESOURCE_VIEW_DESC1 *)desc, (ID3D10ShaderResourceView1 **)view);
4342 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
4343 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
4345 struct d3d_device *device = impl_from_ID3D10Device(iface);
4346 struct d3d_rendertarget_view *object;
4347 ID3D11Resource *d3d11_resource;
4348 HRESULT hr;
4350 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4352 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4354 ERR("Resource does not implement ID3D11Resource.\n");
4355 return E_FAIL;
4358 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
4359 ID3D11Resource_Release(d3d11_resource);
4360 if (FAILED(hr))
4361 return hr;
4363 *view = &object->ID3D10RenderTargetView_iface;
4365 return S_OK;
4368 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
4369 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
4371 struct d3d_device *device = impl_from_ID3D10Device(iface);
4372 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
4373 struct d3d_depthstencil_view *object;
4374 ID3D11Resource *d3d11_resource;
4375 HRESULT hr;
4377 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
4379 if (desc)
4381 d3d11_desc.Format = desc->Format;
4382 d3d11_desc.ViewDimension = desc->ViewDimension;
4383 d3d11_desc.Flags = 0;
4384 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
4387 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
4389 ERR("Resource does not implement ID3D11Resource.\n");
4390 return E_FAIL;
4393 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
4394 ID3D11Resource_Release(d3d11_resource);
4395 if (FAILED(hr))
4396 return hr;
4398 *view = &object->ID3D10DepthStencilView_iface;
4400 return S_OK;
4403 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
4404 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
4405 const void *shader_byte_code, SIZE_T shader_byte_code_length,
4406 ID3D10InputLayout **input_layout)
4408 struct d3d_device *device = impl_from_ID3D10Device(iface);
4409 struct d3d_input_layout *object;
4410 HRESULT hr;
4412 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
4413 "shader_byte_code_length %lu, input_layout %p\n",
4414 iface, element_descs, element_count, shader_byte_code,
4415 shader_byte_code_length, input_layout);
4417 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
4418 shader_byte_code, shader_byte_code_length, &object)))
4419 return hr;
4421 *input_layout = &object->ID3D10InputLayout_iface;
4423 return S_OK;
4426 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
4427 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
4429 struct d3d_device *device = impl_from_ID3D10Device(iface);
4430 struct d3d_vertex_shader *object;
4431 HRESULT hr;
4433 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4434 iface, byte_code, byte_code_length, shader);
4436 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
4437 return hr;
4439 *shader = &object->ID3D10VertexShader_iface;
4441 return S_OK;
4444 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
4445 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
4447 struct d3d_device *device = impl_from_ID3D10Device(iface);
4448 struct d3d_geometry_shader *object;
4449 HRESULT hr;
4451 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4452 iface, byte_code, byte_code_length, shader);
4454 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
4455 return hr;
4457 *shader = &object->ID3D10GeometryShader_iface;
4459 return S_OK;
4462 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
4463 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
4464 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
4466 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
4467 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
4468 iface, byte_code, byte_code_length, output_stream_decls,
4469 output_stream_decl_count, output_stream_stride, shader);
4471 return E_NOTIMPL;
4474 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
4475 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
4477 struct d3d_device *device = impl_from_ID3D10Device(iface);
4478 struct d3d_pixel_shader *object;
4479 HRESULT hr;
4481 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
4482 iface, byte_code, byte_code_length, shader);
4484 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
4485 return hr;
4487 *shader = &object->ID3D10PixelShader_iface;
4489 return S_OK;
4492 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
4493 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
4495 struct d3d_device *device = impl_from_ID3D10Device(iface);
4496 ID3D11BlendState *d3d11_blend_state;
4497 HRESULT hr;
4499 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4501 if (FAILED(hr = d3d11_device_CreateBlendState(&device->ID3D11Device_iface, (D3D11_BLEND_DESC *)desc,
4502 &d3d11_blend_state)))
4503 return hr;
4505 hr = ID3D11BlendState_QueryInterface(d3d11_blend_state, &IID_ID3D10BlendState1, (void **)blend_state);
4506 ID3D11BlendState_Release(d3d11_blend_state);
4507 return hr;
4510 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
4511 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
4513 D3D10_BLEND_DESC1 d3d10_1_desc;
4514 unsigned int i;
4516 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
4518 if (!desc)
4519 return E_INVALIDARG;
4521 d3d10_1_desc.AlphaToCoverageEnable = desc->AlphaToCoverageEnable;
4522 d3d10_1_desc.IndependentBlendEnable = FALSE;
4523 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
4525 if (desc->BlendEnable[i] != desc->BlendEnable[i + 1]
4526 || desc->RenderTargetWriteMask[i] != desc->RenderTargetWriteMask[i + 1])
4527 d3d10_1_desc.IndependentBlendEnable = TRUE;
4530 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
4532 d3d10_1_desc.RenderTarget[i].BlendEnable = desc->BlendEnable[i];
4533 d3d10_1_desc.RenderTarget[i].SrcBlend = desc->SrcBlend;
4534 d3d10_1_desc.RenderTarget[i].DestBlend = desc->DestBlend;
4535 d3d10_1_desc.RenderTarget[i].BlendOp = desc->BlendOp;
4536 d3d10_1_desc.RenderTarget[i].SrcBlendAlpha = desc->SrcBlendAlpha;
4537 d3d10_1_desc.RenderTarget[i].DestBlendAlpha = desc->DestBlendAlpha;
4538 d3d10_1_desc.RenderTarget[i].BlendOpAlpha = desc->BlendOpAlpha;
4539 d3d10_1_desc.RenderTarget[i].RenderTargetWriteMask = desc->RenderTargetWriteMask[i];
4542 return d3d10_device_CreateBlendState1(iface, &d3d10_1_desc, (ID3D10BlendState1 **)blend_state);
4545 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
4546 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
4548 struct d3d_device *device = impl_from_ID3D10Device(iface);
4549 ID3D11DepthStencilState *d3d11_depth_stencil_state;
4550 HRESULT hr;
4552 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
4554 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
4555 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
4556 return hr;
4558 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
4559 (void **)depth_stencil_state);
4560 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
4561 return hr;
4564 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
4565 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
4567 struct d3d_device *device = impl_from_ID3D10Device(iface);
4568 ID3D11RasterizerState *d3d11_rasterizer_state;
4569 HRESULT hr;
4571 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
4573 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
4574 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
4575 return hr;
4577 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
4578 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
4579 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
4580 return hr;
4583 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
4584 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
4586 struct d3d_device *device = impl_from_ID3D10Device(iface);
4587 ID3D11SamplerState *d3d11_sampler_state;
4588 HRESULT hr;
4590 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
4592 if (FAILED(hr = d3d11_device_CreateSamplerState(&device->ID3D11Device_iface,
4593 (const D3D11_SAMPLER_DESC *)desc, &d3d11_sampler_state)))
4594 return hr;
4596 hr = ID3D11SamplerState_QueryInterface(d3d11_sampler_state, &IID_ID3D10SamplerState, (void **)sampler_state);
4597 ID3D11SamplerState_Release(d3d11_sampler_state);
4598 return hr;
4601 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
4602 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
4604 struct d3d_device *device = impl_from_ID3D10Device(iface);
4605 struct d3d_query *object;
4606 HRESULT hr;
4608 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
4610 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, FALSE, &object)))
4611 return hr;
4613 *query = &object->ID3D10Query_iface;
4615 return S_OK;
4618 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
4619 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
4621 struct d3d_device *device = impl_from_ID3D10Device(iface);
4622 struct d3d_query *object;
4623 HRESULT hr;
4625 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
4627 if (FAILED(hr = d3d_query_create(device, (const D3D11_QUERY_DESC *)desc, TRUE, &object)))
4628 return hr;
4630 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
4632 return S_OK;
4635 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
4636 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
4638 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
4640 return E_NOTIMPL;
4643 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
4644 DXGI_FORMAT format, UINT *format_support)
4646 FIXME("iface %p, format %s, format_support %p stub!\n",
4647 iface, debug_dxgi_format(format), format_support);
4649 return E_NOTIMPL;
4652 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
4653 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
4655 struct d3d_device *device = impl_from_ID3D10Device(iface);
4657 TRACE("iface %p, format %s, sample_count %u, quality_level_count %p.\n",
4658 iface, debug_dxgi_format(format), sample_count, quality_level_count);
4660 return d3d11_device_CheckMultisampleQualityLevels(&device->ID3D11Device_iface, format,
4661 sample_count, quality_level_count);
4664 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
4666 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
4669 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
4670 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
4671 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
4673 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
4674 "units %p, units_length %p, description %p, description_length %p stub!\n",
4675 iface, desc, type, active_counters, name, name_length,
4676 units, units_length, description, description_length);
4678 return E_NOTIMPL;
4681 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
4683 FIXME("iface %p stub!\n", iface);
4685 return 0;
4688 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
4689 HANDLE resource_handle, REFIID guid, void **resource)
4691 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
4692 iface, resource_handle, debugstr_guid(guid), resource);
4694 return E_NOTIMPL;
4697 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
4699 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
4702 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
4704 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
4707 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
4709 struct d3d_device *device = impl_from_ID3D10Device(iface);
4711 TRACE("iface %p.\n", iface);
4713 return device->feature_level;
4716 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
4718 /* IUnknown methods */
4719 d3d10_device_QueryInterface,
4720 d3d10_device_AddRef,
4721 d3d10_device_Release,
4722 /* ID3D10Device methods */
4723 d3d10_device_VSSetConstantBuffers,
4724 d3d10_device_PSSetShaderResources,
4725 d3d10_device_PSSetShader,
4726 d3d10_device_PSSetSamplers,
4727 d3d10_device_VSSetShader,
4728 d3d10_device_DrawIndexed,
4729 d3d10_device_Draw,
4730 d3d10_device_PSSetConstantBuffers,
4731 d3d10_device_IASetInputLayout,
4732 d3d10_device_IASetVertexBuffers,
4733 d3d10_device_IASetIndexBuffer,
4734 d3d10_device_DrawIndexedInstanced,
4735 d3d10_device_DrawInstanced,
4736 d3d10_device_GSSetConstantBuffers,
4737 d3d10_device_GSSetShader,
4738 d3d10_device_IASetPrimitiveTopology,
4739 d3d10_device_VSSetShaderResources,
4740 d3d10_device_VSSetSamplers,
4741 d3d10_device_SetPredication,
4742 d3d10_device_GSSetShaderResources,
4743 d3d10_device_GSSetSamplers,
4744 d3d10_device_OMSetRenderTargets,
4745 d3d10_device_OMSetBlendState,
4746 d3d10_device_OMSetDepthStencilState,
4747 d3d10_device_SOSetTargets,
4748 d3d10_device_DrawAuto,
4749 d3d10_device_RSSetState,
4750 d3d10_device_RSSetViewports,
4751 d3d10_device_RSSetScissorRects,
4752 d3d10_device_CopySubresourceRegion,
4753 d3d10_device_CopyResource,
4754 d3d10_device_UpdateSubresource,
4755 d3d10_device_ClearRenderTargetView,
4756 d3d10_device_ClearDepthStencilView,
4757 d3d10_device_GenerateMips,
4758 d3d10_device_ResolveSubresource,
4759 d3d10_device_VSGetConstantBuffers,
4760 d3d10_device_PSGetShaderResources,
4761 d3d10_device_PSGetShader,
4762 d3d10_device_PSGetSamplers,
4763 d3d10_device_VSGetShader,
4764 d3d10_device_PSGetConstantBuffers,
4765 d3d10_device_IAGetInputLayout,
4766 d3d10_device_IAGetVertexBuffers,
4767 d3d10_device_IAGetIndexBuffer,
4768 d3d10_device_GSGetConstantBuffers,
4769 d3d10_device_GSGetShader,
4770 d3d10_device_IAGetPrimitiveTopology,
4771 d3d10_device_VSGetShaderResources,
4772 d3d10_device_VSGetSamplers,
4773 d3d10_device_GetPredication,
4774 d3d10_device_GSGetShaderResources,
4775 d3d10_device_GSGetSamplers,
4776 d3d10_device_OMGetRenderTargets,
4777 d3d10_device_OMGetBlendState,
4778 d3d10_device_OMGetDepthStencilState,
4779 d3d10_device_SOGetTargets,
4780 d3d10_device_RSGetState,
4781 d3d10_device_RSGetViewports,
4782 d3d10_device_RSGetScissorRects,
4783 d3d10_device_GetDeviceRemovedReason,
4784 d3d10_device_SetExceptionMode,
4785 d3d10_device_GetExceptionMode,
4786 d3d10_device_GetPrivateData,
4787 d3d10_device_SetPrivateData,
4788 d3d10_device_SetPrivateDataInterface,
4789 d3d10_device_ClearState,
4790 d3d10_device_Flush,
4791 d3d10_device_CreateBuffer,
4792 d3d10_device_CreateTexture1D,
4793 d3d10_device_CreateTexture2D,
4794 d3d10_device_CreateTexture3D,
4795 d3d10_device_CreateShaderResourceView,
4796 d3d10_device_CreateRenderTargetView,
4797 d3d10_device_CreateDepthStencilView,
4798 d3d10_device_CreateInputLayout,
4799 d3d10_device_CreateVertexShader,
4800 d3d10_device_CreateGeometryShader,
4801 d3d10_device_CreateGeometryShaderWithStreamOutput,
4802 d3d10_device_CreatePixelShader,
4803 d3d10_device_CreateBlendState,
4804 d3d10_device_CreateDepthStencilState,
4805 d3d10_device_CreateRasterizerState,
4806 d3d10_device_CreateSamplerState,
4807 d3d10_device_CreateQuery,
4808 d3d10_device_CreatePredicate,
4809 d3d10_device_CreateCounter,
4810 d3d10_device_CheckFormatSupport,
4811 d3d10_device_CheckMultisampleQualityLevels,
4812 d3d10_device_CheckCounterInfo,
4813 d3d10_device_CheckCounter,
4814 d3d10_device_GetCreationFlags,
4815 d3d10_device_OpenSharedResource,
4816 d3d10_device_SetTextFilterSize,
4817 d3d10_device_GetTextFilterSize,
4818 d3d10_device_CreateShaderResourceView1,
4819 d3d10_device_CreateBlendState1,
4820 d3d10_device_GetFeatureLevel,
4823 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
4825 /* IUnknown methods */
4826 d3d_device_inner_QueryInterface,
4827 d3d_device_inner_AddRef,
4828 d3d_device_inner_Release,
4831 /* ID3D10Multithread methods */
4833 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
4835 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
4838 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
4840 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
4842 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
4844 return IUnknown_QueryInterface(device->outer_unk, iid, out);
4847 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
4849 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
4851 TRACE("iface %p.\n", iface);
4853 return IUnknown_AddRef(device->outer_unk);
4856 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
4858 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
4860 TRACE("iface %p.\n", iface);
4862 return IUnknown_Release(device->outer_unk);
4865 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
4867 TRACE("iface %p.\n", iface);
4869 wined3d_mutex_lock();
4872 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
4874 TRACE("iface %p.\n", iface);
4876 wined3d_mutex_unlock();
4879 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
4881 FIXME("iface %p, protect %#x stub!\n", iface, protect);
4883 return TRUE;
4886 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
4888 FIXME("iface %p stub!\n", iface);
4890 return TRUE;
4893 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
4895 d3d10_multithread_QueryInterface,
4896 d3d10_multithread_AddRef,
4897 d3d10_multithread_Release,
4898 d3d10_multithread_Enter,
4899 d3d10_multithread_Leave,
4900 d3d10_multithread_SetMultithreadProtected,
4901 d3d10_multithread_GetMultithreadProtected,
4904 /* IWineDXGIDeviceParent IUnknown methods */
4906 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
4908 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
4911 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
4912 REFIID riid, void **ppv)
4914 struct d3d_device *device = device_from_dxgi_device_parent(iface);
4915 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
4918 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
4920 struct d3d_device *device = device_from_dxgi_device_parent(iface);
4921 return IUnknown_AddRef(device->outer_unk);
4924 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
4926 struct d3d_device *device = device_from_dxgi_device_parent(iface);
4927 return IUnknown_Release(device->outer_unk);
4930 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
4931 IWineDXGIDeviceParent *iface)
4933 struct d3d_device *device = device_from_dxgi_device_parent(iface);
4934 return &device->device_parent;
4937 static const struct IWineDXGIDeviceParentVtbl d3d_dxgi_device_parent_vtbl =
4939 /* IUnknown methods */
4940 dxgi_device_parent_QueryInterface,
4941 dxgi_device_parent_AddRef,
4942 dxgi_device_parent_Release,
4943 /* IWineDXGIDeviceParent methods */
4944 dxgi_device_parent_get_wined3d_device_parent,
4947 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
4949 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
4952 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
4953 struct wined3d_device *wined3d_device)
4955 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
4957 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
4959 wined3d_device_incref(wined3d_device);
4960 device->wined3d_device = wined3d_device;
4963 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
4965 TRACE("device_parent %p.\n", device_parent);
4968 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
4970 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
4973 static HRESULT CDECL device_parent_sub_resource_created(struct wined3d_device_parent *device_parent,
4974 struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, void **parent,
4975 const struct wined3d_parent_ops **parent_ops)
4977 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4978 device_parent, wined3d_texture, sub_resource_idx, parent, parent_ops);
4980 *parent = NULL;
4981 *parent_ops = &d3d_null_wined3d_parent_ops;
4983 return S_OK;
4986 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
4987 void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
4988 struct wined3d_texture **wined3d_texture)
4990 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
4991 struct d3d_texture2d *texture;
4992 ID3D10Texture2D *texture_iface;
4993 D3D10_TEXTURE2D_DESC desc;
4994 HRESULT hr;
4996 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
4997 device_parent, container_parent, wined3d_desc, wined3d_texture);
4999 FIXME("Implement DXGI<->wined3d usage conversion.\n");
5001 desc.Width = wined3d_desc->width;
5002 desc.Height = wined3d_desc->height;
5003 desc.MipLevels = 1;
5004 desc.ArraySize = 1;
5005 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
5006 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
5007 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
5008 desc.Usage = D3D10_USAGE_DEFAULT;
5009 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
5010 desc.CPUAccessFlags = 0;
5011 desc.MiscFlags = 0;
5013 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
5014 &desc, NULL, &texture_iface)))
5016 WARN("CreateTexture2D failed, returning %#x.\n", hr);
5017 return hr;
5020 texture = impl_from_ID3D10Texture2D(texture_iface);
5022 *wined3d_texture = texture->wined3d_texture;
5023 wined3d_texture_incref(*wined3d_texture);
5024 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
5026 return S_OK;
5029 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
5030 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
5032 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
5033 IWineDXGIDevice *wine_device;
5034 HRESULT hr;
5036 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
5038 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
5039 &IID_IWineDXGIDevice, (void **)&wine_device)))
5041 ERR("Device should implement IWineDXGIDevice.\n");
5042 return E_FAIL;
5045 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
5046 IWineDXGIDevice_Release(wine_device);
5047 if (FAILED(hr))
5049 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
5050 return hr;
5053 return S_OK;
5056 static const struct wined3d_device_parent_ops d3d_wined3d_device_parent_ops =
5058 device_parent_wined3d_device_created,
5059 device_parent_mode_changed,
5060 device_parent_activate,
5061 device_parent_sub_resource_created,
5062 device_parent_sub_resource_created,
5063 device_parent_create_swapchain_texture,
5064 device_parent_create_swapchain,
5067 static void *d3d_rb_alloc(size_t size)
5069 return HeapAlloc(GetProcessHeap(), 0, size);
5072 static void *d3d_rb_realloc(void *ptr, size_t size)
5074 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
5077 static void d3d_rb_free(void *ptr)
5079 HeapFree(GetProcessHeap(), 0, ptr);
5082 static int d3d_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
5084 const D3D11_SAMPLER_DESC *ka = key;
5085 const D3D11_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_sampler_state, entry)->desc;
5087 return memcmp(ka, kb, sizeof(*ka));
5090 static const struct wine_rb_functions d3d_sampler_state_rb_ops =
5092 d3d_rb_alloc,
5093 d3d_rb_realloc,
5094 d3d_rb_free,
5095 d3d_sampler_state_compare,
5098 static int d3d_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
5100 const D3D11_BLEND_DESC *ka = key;
5101 const D3D11_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_blend_state, entry)->desc;
5103 return memcmp(ka, kb, sizeof(*ka));
5106 static const struct wine_rb_functions d3d_blend_state_rb_ops =
5108 d3d_rb_alloc,
5109 d3d_rb_realloc,
5110 d3d_rb_free,
5111 d3d_blend_state_compare,
5114 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
5116 const D3D11_DEPTH_STENCIL_DESC *ka = key;
5117 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
5118 const struct d3d_depthstencil_state, entry)->desc;
5120 return memcmp(ka, kb, sizeof(*ka));
5123 static const struct wine_rb_functions d3d_depthstencil_state_rb_ops =
5125 d3d_rb_alloc,
5126 d3d_rb_realloc,
5127 d3d_rb_free,
5128 d3d_depthstencil_state_compare,
5131 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
5133 const D3D11_RASTERIZER_DESC *ka = key;
5134 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
5136 return memcmp(ka, kb, sizeof(*ka));
5139 static const struct wine_rb_functions d3d_rasterizer_state_rb_ops =
5141 d3d_rb_alloc,
5142 d3d_rb_realloc,
5143 d3d_rb_free,
5144 d3d_rasterizer_state_compare,
5147 HRESULT d3d_device_init(struct d3d_device *device, void *outer_unknown)
5149 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
5150 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
5151 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
5152 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
5153 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d_dxgi_device_parent_vtbl;
5154 device->device_parent.ops = &d3d_wined3d_device_parent_ops;
5155 device->refcount = 1;
5156 /* COM aggregation always takes place */
5157 device->outer_unk = outer_unknown;
5159 d3d11_immediate_context_init(&device->immediate_context, device);
5160 ID3D11DeviceContext_Release(&device->immediate_context.ID3D11DeviceContext_iface);
5162 if (wine_rb_init(&device->blend_states, &d3d_blend_state_rb_ops) == -1)
5164 WARN("Failed to initialize blend state rbtree.\n");
5165 return E_FAIL;
5167 device->blend_factor[0] = 1.0f;
5168 device->blend_factor[1] = 1.0f;
5169 device->blend_factor[2] = 1.0f;
5170 device->blend_factor[3] = 1.0f;
5172 if (wine_rb_init(&device->depthstencil_states, &d3d_depthstencil_state_rb_ops) == -1)
5174 WARN("Failed to initialize depthstencil state rbtree.\n");
5175 wine_rb_destroy(&device->blend_states, NULL, NULL);
5176 return E_FAIL;
5179 if (wine_rb_init(&device->rasterizer_states, &d3d_rasterizer_state_rb_ops) == -1)
5181 WARN("Failed to initialize rasterizer state rbtree.\n");
5182 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
5183 wine_rb_destroy(&device->blend_states, NULL, NULL);
5184 return E_FAIL;
5187 if (wine_rb_init(&device->sampler_states, &d3d_sampler_state_rb_ops) == -1)
5189 WARN("Failed to initialize sampler state rbtree.\n");
5190 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
5191 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
5192 wine_rb_destroy(&device->blend_states, NULL, NULL);
5193 return E_FAIL;
5196 return S_OK;