d3d11: Implement d3d11_shader_resource_view_GetDesc().
[wine.git] / dlls / d3d11 / device.c
blob4266a9808a23d74c19f1a8a7c9c467c8ff97851d
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 d3d10_null_wined3d_object_destroyed(void *parent) {}
30 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
32 d3d10_null_wined3d_object_destroyed,
35 /* ID3D11Device methods */
37 static inline struct d3d_device *impl_from_ID3D11Device(ID3D11Device *iface)
39 return CONTAINING_RECORD(iface, struct d3d_device, ID3D11Device_iface);
42 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
44 struct d3d_device *device = impl_from_ID3D11Device(iface);
45 return IUnknown_QueryInterface(device->outer_unk, riid, out);
48 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
50 struct d3d_device *device = impl_from_ID3D11Device(iface);
51 return IUnknown_AddRef(device->outer_unk);
54 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
56 struct d3d_device *device = impl_from_ID3D11Device(iface);
57 return IUnknown_Release(device->outer_unk);
60 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
61 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
63 struct d3d_device *device = impl_from_ID3D11Device(iface);
64 struct d3d_buffer *object;
65 HRESULT hr;
67 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
69 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
70 return hr;
72 *buffer = &object->ID3D11Buffer_iface;
74 return S_OK;
77 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
78 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
80 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
82 return E_NOTIMPL;
85 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
86 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
88 struct d3d_device *device = impl_from_ID3D11Device(iface);
89 struct d3d_texture2d *object;
90 HRESULT hr;
92 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
94 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
95 return hr;
97 *texture = &object->ID3D11Texture2D_iface;
99 return S_OK;
102 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
103 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
105 struct d3d_device *device = impl_from_ID3D11Device(iface);
106 struct d3d_texture3d *object;
107 HRESULT hr;
109 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
111 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
112 return hr;
114 *texture = &object->ID3D11Texture3D_iface;
116 return S_OK;
119 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
120 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
122 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
124 return E_NOTIMPL;
127 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
128 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
130 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
132 return E_NOTIMPL;
135 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
136 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
138 struct d3d_device *device = impl_from_ID3D11Device(iface);
139 struct d3d_rendertarget_view *object;
140 HRESULT hr;
142 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
144 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
145 return hr;
147 *view = &object->ID3D11RenderTargetView_iface;
149 return S_OK;
153 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
154 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
156 struct d3d_device *device = impl_from_ID3D11Device(iface);
157 struct d3d_depthstencil_view *object;
158 HRESULT hr;
160 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
162 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
163 return hr;
165 *view = &object->ID3D11DepthStencilView_iface;
167 return S_OK;
170 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
171 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
172 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
174 FIXME("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
175 "input_layout %p stub!\n", iface, element_descs, element_count, shader_byte_code,
176 shader_byte_code_length, input_layout);
178 return E_NOTIMPL;
181 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
182 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
184 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
185 iface, byte_code, byte_code_length, class_linkage, shader);
187 return E_NOTIMPL;
190 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
191 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
193 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
194 iface, byte_code, byte_code_length, class_linkage, shader);
196 return E_NOTIMPL;
199 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
200 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
201 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
202 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
204 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
205 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
206 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
207 rasterized_stream, class_linkage, shader);
209 return E_NOTIMPL;
212 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
213 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
215 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
216 iface, byte_code, byte_code_length, class_linkage, shader);
218 return E_NOTIMPL;
221 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
222 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
224 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
225 iface, byte_code, byte_code_length, class_linkage, shader);
227 return E_NOTIMPL;
230 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
231 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
233 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
234 iface, byte_code, byte_code_length, class_linkage, shader);
236 return E_NOTIMPL;
239 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
240 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
242 FIXME("iface %p, byte_code %p, byte_code_lenghth %lu, class_linkage %p, shader %p stub!\n",
243 iface, byte_code, byte_code_length, class_linkage, shader);
245 return E_NOTIMPL;
248 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
249 ID3D11ClassLinkage **class_linkage)
251 FIXME("iface %p, class_linkage %p stub!\n", iface, class_linkage);
253 return E_NOTIMPL;
256 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
257 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
259 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
261 return E_NOTIMPL;
264 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
265 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
267 FIXME("iface %p, desc %p, depth_stencil_state %p stub!\n", iface, desc, depth_stencil_state);
269 return E_NOTIMPL;
272 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
273 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
275 FIXME("iface %p, desc %p, rasterizer_state %p stub!\n", iface, desc, rasterizer_state);
277 return E_NOTIMPL;
280 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
281 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
283 FIXME("iface %p, desc %p, sampler_state %p stub!\n", iface, desc, sampler_state);
285 return E_NOTIMPL;
288 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
289 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
291 FIXME("iface %p, desc %p, query %p stub!\n", iface, desc, query);
293 return E_NOTIMPL;
296 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
297 ID3D11Predicate **predicate)
299 FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
301 return E_NOTIMPL;
304 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
305 ID3D11Counter **counter)
307 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
309 return E_NOTIMPL;
312 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
313 ID3D11DeviceContext **context)
315 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
317 return E_NOTIMPL;
320 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
321 void **out)
323 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
325 return E_NOTIMPL;
328 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
329 UINT *format_support)
331 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
333 return E_NOTIMPL;
336 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
337 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
339 FIXME("iface %p, format %u, sample_count %u, quality_level_count %p stub!\n",
340 iface, format, sample_count, quality_level_count);
342 return E_NOTIMPL;
345 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
347 FIXME("iface %p, info %p stub!\n", iface, info);
350 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
351 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
352 char *units, UINT *units_length, char *description, UINT *description_length)
354 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
355 "units %p, units_length %p, description %p, description_length %p stub!\n",
356 iface, desc, type, active_counter_count, name, name_length,
357 units, units_length, description, description_length);
359 return E_NOTIMPL;
362 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
363 void *feature_support_data, UINT feature_support_data_size)
365 FIXME("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u stub!\n",
366 iface, feature, feature_support_data, feature_support_data_size);
368 return E_NOTIMPL;
371 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
372 UINT *data_size, void *data)
374 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
376 return E_NOTIMPL;
379 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
380 UINT data_size, const void *data)
382 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
384 return E_NOTIMPL;
387 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
388 const IUnknown *data_iface)
390 FIXME("iface %p, guid %s, data_iface %p stub!\n", iface, debugstr_guid(guid), data_iface);
392 return E_NOTIMPL;
395 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
397 FIXME("iface %p stub!\n", iface);
399 return D3D_FEATURE_LEVEL_10_0;
402 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
404 FIXME("iface %p stub!\n", iface);
406 return 0;
409 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
411 FIXME("iface %p stub!\n", iface);
413 return S_OK;
416 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
417 ID3D11DeviceContext **immediate_context)
419 FIXME("iface %p, immediate_context %p stub!\n", iface, immediate_context);
422 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
424 FIXME("iface %p, flags %#x stub!\n", iface, flags);
426 return E_NOTIMPL;
429 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
431 FIXME("iface %p stub!\n", iface);
433 return 0;
436 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
438 /* IUnknown methods */
439 d3d11_device_QueryInterface,
440 d3d11_device_AddRef,
441 d3d11_device_Release,
442 /* ID3D11Device methods */
443 d3d11_device_CreateBuffer,
444 d3d11_device_CreateTexture1D,
445 d3d11_device_CreateTexture2D,
446 d3d11_device_CreateTexture3D,
447 d3d11_device_CreateShaderResourceView,
448 d3d11_device_CreateUnorderedAccessView,
449 d3d11_device_CreateRenderTargetView,
450 d3d11_device_CreateDepthStencilView,
451 d3d11_device_CreateInputLayout,
452 d3d11_device_CreateVertexShader,
453 d3d11_device_CreateGeometryShader,
454 d3d11_device_CreateGeometryShaderWithStreamOutput,
455 d3d11_device_CreatePixelShader,
456 d3d11_device_CreateHullShader,
457 d3d11_device_CreateDomainShader,
458 d3d11_device_CreateComputeShader,
459 d3d11_device_CreateClassLinkage,
460 d3d11_device_CreateBlendState,
461 d3d11_device_CreateDepthStencilState,
462 d3d11_device_CreateRasterizerState,
463 d3d11_device_CreateSamplerState,
464 d3d11_device_CreateQuery,
465 d3d11_device_CreatePredicate,
466 d3d11_device_CreateCounter,
467 d3d11_device_CreateDeferredContext,
468 d3d11_device_OpenSharedResource,
469 d3d11_device_CheckFormatSupport,
470 d3d11_device_CheckMultisampleQualityLevels,
471 d3d11_device_CheckCounterInfo,
472 d3d11_device_CheckCounter,
473 d3d11_device_CheckFeatureSupport,
474 d3d11_device_GetPrivateData,
475 d3d11_device_SetPrivateData,
476 d3d11_device_SetPrivateDataInterface,
477 d3d11_device_GetFeatureLevel,
478 d3d11_device_GetCreationFlags,
479 d3d11_device_GetDeviceRemovedReason,
480 d3d11_device_GetImmediateContext,
481 d3d11_device_SetExceptionMode,
482 d3d11_device_GetExceptionMode,
485 /* Inner IUnknown methods */
487 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
489 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
492 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
494 struct d3d_device *device = impl_from_IUnknown(iface);
496 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
498 if (IsEqualGUID(riid, &IID_ID3D11Device)
499 || IsEqualGUID(riid, &IID_IUnknown))
501 *out = &device->ID3D11Device_iface;
503 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
504 || IsEqualGUID(riid, &IID_ID3D10Device))
506 *out = &device->ID3D10Device1_iface;
508 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
510 *out = &device->ID3D10Multithread_iface;
512 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
514 *out = &device->IWineDXGIDeviceParent_iface;
516 else
518 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
519 *out = NULL;
520 return E_NOINTERFACE;
523 IUnknown_AddRef((IUnknown *)*out);
524 return S_OK;
527 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
529 struct d3d_device *This = impl_from_IUnknown(iface);
530 ULONG refcount = InterlockedIncrement(&This->refcount);
532 TRACE("%p increasing refcount to %u\n", This, refcount);
534 return refcount;
537 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
539 struct d3d_device *device = impl_from_IUnknown(iface);
540 ULONG refcount = InterlockedDecrement(&device->refcount);
542 TRACE("%p decreasing refcount to %u.\n", device, refcount);
544 if (!refcount)
546 if (device->wined3d_device)
548 wined3d_mutex_lock();
549 wined3d_device_decref(device->wined3d_device);
550 wined3d_mutex_unlock();
552 wine_rb_destroy(&device->sampler_states, NULL, NULL);
553 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
554 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
555 wine_rb_destroy(&device->blend_states, NULL, NULL);
558 return refcount;
561 /* IUnknown methods */
563 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
564 void **ppv)
566 struct d3d_device *This = impl_from_ID3D10Device(iface);
567 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
570 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
572 struct d3d_device *This = impl_from_ID3D10Device(iface);
573 return IUnknown_AddRef(This->outer_unk);
576 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
578 struct d3d_device *This = impl_from_ID3D10Device(iface);
579 return IUnknown_Release(This->outer_unk);
582 /* ID3D10Device methods */
584 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
585 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
587 struct d3d_device *device = impl_from_ID3D10Device(iface);
588 unsigned int i;
590 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
591 iface, start_slot, buffer_count, buffers);
593 wined3d_mutex_lock();
594 for (i = 0; i < buffer_count; ++i)
596 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
598 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
599 buffer ? buffer->wined3d_buffer : NULL);
601 wined3d_mutex_unlock();
604 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
605 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
607 struct d3d_device *device = impl_from_ID3D10Device(iface);
608 unsigned int i;
610 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
611 iface, start_slot, view_count, views);
613 wined3d_mutex_lock();
614 for (i = 0; i < view_count; ++i)
616 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
618 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
619 view ? view->wined3d_view : NULL);
621 wined3d_mutex_unlock();
624 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
625 ID3D10PixelShader *shader)
627 struct d3d_device *This = impl_from_ID3D10Device(iface);
628 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
630 TRACE("iface %p, shader %p\n", iface, shader);
632 wined3d_mutex_lock();
633 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
634 wined3d_mutex_unlock();
637 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
638 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
640 struct d3d_device *device = impl_from_ID3D10Device(iface);
641 unsigned int i;
643 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
644 iface, start_slot, sampler_count, samplers);
646 wined3d_mutex_lock();
647 for (i = 0; i < sampler_count; ++i)
649 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
651 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
652 sampler ? sampler->wined3d_sampler : NULL);
654 wined3d_mutex_unlock();
657 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
658 ID3D10VertexShader *shader)
660 struct d3d_device *This = impl_from_ID3D10Device(iface);
661 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
663 TRACE("iface %p, shader %p\n", iface, shader);
665 wined3d_mutex_lock();
666 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
667 wined3d_mutex_unlock();
670 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
671 UINT start_index_location, INT base_vertex_location)
673 struct d3d_device *This = impl_from_ID3D10Device(iface);
675 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
676 iface, index_count, start_index_location, base_vertex_location);
678 wined3d_mutex_lock();
679 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
680 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
681 wined3d_mutex_unlock();
684 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
685 UINT start_vertex_location)
687 struct d3d_device *This = impl_from_ID3D10Device(iface);
689 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
690 iface, vertex_count, start_vertex_location);
692 wined3d_mutex_lock();
693 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
694 wined3d_mutex_unlock();
697 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
698 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
700 struct d3d_device *device = impl_from_ID3D10Device(iface);
701 unsigned int i;
703 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
704 iface, start_slot, buffer_count, buffers);
706 wined3d_mutex_lock();
707 for (i = 0; i < buffer_count; ++i)
709 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
711 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
712 buffer ? buffer->wined3d_buffer : NULL);
714 wined3d_mutex_unlock();
717 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
718 ID3D10InputLayout *input_layout)
720 struct d3d_device *This = impl_from_ID3D10Device(iface);
721 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
723 TRACE("iface %p, input_layout %p\n", iface, input_layout);
725 wined3d_mutex_lock();
726 wined3d_device_set_vertex_declaration(This->wined3d_device,
727 layout ? layout->wined3d_decl : NULL);
728 wined3d_mutex_unlock();
731 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
732 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
734 struct d3d_device *This = impl_from_ID3D10Device(iface);
735 unsigned int i;
737 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
738 iface, start_slot, buffer_count, buffers, strides, offsets);
740 wined3d_mutex_lock();
741 for (i = 0; i < buffer_count; ++i)
743 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
745 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
746 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
748 wined3d_mutex_unlock();
751 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
752 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
754 struct d3d_device *This = impl_from_ID3D10Device(iface);
755 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
757 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
758 iface, buffer, debug_dxgi_format(format), offset);
760 wined3d_mutex_lock();
761 wined3d_device_set_index_buffer(This->wined3d_device,
762 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
763 wined3dformat_from_dxgi_format(format));
764 wined3d_mutex_unlock();
765 if (offset) FIXME("offset %u not supported.\n", offset);
768 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
769 UINT instance_index_count, UINT instance_count, UINT start_index_location,
770 INT base_vertex_location, UINT start_instance_location)
772 struct d3d_device *device = impl_from_ID3D10Device(iface);
774 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
775 "base_vertex_location %d, start_instance_location %u.\n",
776 iface, instance_index_count, instance_count, start_index_location,
777 base_vertex_location, start_instance_location);
779 wined3d_mutex_lock();
780 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
781 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
782 instance_index_count, start_instance_location, instance_count);
783 wined3d_mutex_unlock();
786 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
787 UINT instance_vertex_count, UINT instance_count,
788 UINT start_vertex_location, UINT start_instance_location)
790 struct d3d_device *device = impl_from_ID3D10Device(iface);
792 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
793 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
794 start_vertex_location, start_instance_location);
796 wined3d_mutex_lock();
797 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
798 instance_vertex_count, start_instance_location, instance_count);
799 wined3d_mutex_unlock();
802 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
803 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
805 struct d3d_device *device = impl_from_ID3D10Device(iface);
806 unsigned int i;
808 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
809 iface, start_slot, buffer_count, buffers);
811 wined3d_mutex_lock();
812 for (i = 0; i < buffer_count; ++i)
814 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
816 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
817 buffer ? buffer->wined3d_buffer : NULL);
819 wined3d_mutex_unlock();
822 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
824 struct d3d_device *device = impl_from_ID3D10Device(iface);
825 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
827 TRACE("iface %p, shader %p.\n", iface, shader);
829 wined3d_mutex_lock();
830 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
831 wined3d_mutex_unlock();
834 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
835 D3D10_PRIMITIVE_TOPOLOGY topology)
837 struct d3d_device *This = impl_from_ID3D10Device(iface);
839 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
841 wined3d_mutex_lock();
842 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
843 wined3d_mutex_unlock();
846 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
847 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
849 struct d3d_device *device = impl_from_ID3D10Device(iface);
850 unsigned int i;
852 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
853 iface, start_slot, view_count, views);
855 wined3d_mutex_lock();
856 for (i = 0; i < view_count; ++i)
858 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
860 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
861 view ? view->wined3d_view : NULL);
863 wined3d_mutex_unlock();
866 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
867 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
869 struct d3d_device *device = impl_from_ID3D10Device(iface);
870 unsigned int i;
872 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
873 iface, start_slot, sampler_count, samplers);
875 wined3d_mutex_lock();
876 for (i = 0; i < sampler_count; ++i)
878 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
880 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
881 sampler ? sampler->wined3d_sampler : NULL);
883 wined3d_mutex_unlock();
886 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
888 struct d3d_device *device = impl_from_ID3D10Device(iface);
889 struct d3d10_query *query;
891 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
893 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
894 wined3d_mutex_lock();
895 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
896 wined3d_mutex_unlock();
899 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
900 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
902 struct d3d_device *device = impl_from_ID3D10Device(iface);
903 unsigned int i;
905 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
906 iface, start_slot, view_count, views);
908 wined3d_mutex_lock();
909 for (i = 0; i < view_count; ++i)
911 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
913 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
914 view ? view->wined3d_view : NULL);
916 wined3d_mutex_unlock();
919 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
920 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
922 struct d3d_device *device = impl_from_ID3D10Device(iface);
923 unsigned int i;
925 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
926 iface, start_slot, sampler_count, samplers);
928 wined3d_mutex_lock();
929 for (i = 0; i < sampler_count; ++i)
931 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
933 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
934 sampler ? sampler->wined3d_sampler : NULL);
936 wined3d_mutex_unlock();
939 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
940 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
941 ID3D10DepthStencilView *depth_stencil_view)
943 struct d3d_device *device = impl_from_ID3D10Device(iface);
944 struct d3d_depthstencil_view *dsv;
945 unsigned int i;
947 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
948 iface, render_target_view_count, render_target_views, depth_stencil_view);
950 wined3d_mutex_lock();
951 for (i = 0; i < render_target_view_count; ++i)
953 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
955 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
956 rtv ? rtv->wined3d_view : NULL, FALSE);
958 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
960 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
963 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
964 wined3d_device_set_depth_stencil_view(device->wined3d_device,
965 dsv ? dsv->wined3d_view : NULL);
966 wined3d_mutex_unlock();
969 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
970 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
972 struct d3d_device *device = impl_from_ID3D10Device(iface);
973 const D3D10_BLEND_DESC *desc;
975 TRACE("iface %p, blend_state %p, blend_factor {%.8e %.8e %.8e %.8e}, sample_mask 0x%08x.\n",
976 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
978 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
979 FIXME("Ignoring blend factor {%.8e %.8e %.8e %.8e}.\n",
980 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
981 wined3d_mutex_lock();
982 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
983 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
984 if (!(device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state)))
986 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
987 wined3d_device_set_render_state(device->wined3d_device,
988 WINED3D_RS_COLORWRITEENABLE, D3D10_COLOR_WRITE_ENABLE_ALL);
989 wined3d_device_set_render_state(device->wined3d_device,
990 WINED3D_RS_COLORWRITEENABLE1, D3D10_COLOR_WRITE_ENABLE_ALL);
991 wined3d_device_set_render_state(device->wined3d_device,
992 WINED3D_RS_COLORWRITEENABLE2, D3D10_COLOR_WRITE_ENABLE_ALL);
993 wined3d_device_set_render_state(device->wined3d_device,
994 WINED3D_RS_COLORWRITEENABLE3, D3D10_COLOR_WRITE_ENABLE_ALL);
995 wined3d_mutex_unlock();
996 return;
999 desc = &device->blend_state->desc;
1000 /* glSampleCoverage() */
1001 if (desc->AlphaToCoverageEnable)
1002 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
1003 /* glEnableIndexedEXT(GL_BLEND, ...) */
1004 FIXME("Per-rendertarget blend enable not implemented.\n");
1005 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, desc->BlendEnable[0]);
1006 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->SrcBlend);
1007 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->DestBlend);
1008 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->BlendOp);
1009 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
1010 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, desc->SrcBlendAlpha);
1011 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, desc->DestBlendAlpha);
1012 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, desc->BlendOpAlpha);
1013 FIXME("Color mask > 3 not implemented.\n");
1014 wined3d_device_set_render_state(device->wined3d_device,
1015 WINED3D_RS_COLORWRITEENABLE, desc->RenderTargetWriteMask[0]);
1016 wined3d_device_set_render_state(device->wined3d_device,
1017 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTargetWriteMask[1]);
1018 wined3d_device_set_render_state(device->wined3d_device,
1019 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTargetWriteMask[2]);
1020 wined3d_device_set_render_state(device->wined3d_device,
1021 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTargetWriteMask[3]);
1022 wined3d_mutex_unlock();
1025 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
1026 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
1028 struct d3d_device *device = impl_from_ID3D10Device(iface);
1030 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1031 iface, depth_stencil_state, stencil_ref);
1033 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
1034 device->stencil_ref = stencil_ref;
1037 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
1038 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
1040 struct d3d_device *device = impl_from_ID3D10Device(iface);
1041 unsigned int count, i;
1043 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
1045 count = min(target_count, 4);
1046 wined3d_mutex_lock();
1047 for (i = 0; i < count; ++i)
1049 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
1051 wined3d_device_set_stream_output(device->wined3d_device, i,
1052 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
1055 for (i = count; i < 4; ++i)
1057 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1059 wined3d_mutex_unlock();
1062 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
1064 FIXME("iface %p stub!\n", iface);
1067 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
1069 struct d3d_device *device = impl_from_ID3D10Device(iface);
1070 const D3D10_RASTERIZER_DESC *desc;
1072 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1074 wined3d_mutex_lock();
1075 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
1077 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
1078 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
1079 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
1080 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1081 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
1082 wined3d_mutex_unlock();
1083 return;
1086 desc = &device->rasterizer_state->desc;
1087 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
1088 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
1089 /* glFrontFace() */
1090 if (desc->FrontCounterClockwise)
1091 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
1092 /* OpenGL style depth bias. */
1093 if (desc->DepthBias || desc->SlopeScaledDepthBias)
1094 FIXME("Ignoring depth bias.\n");
1095 /* GL_DEPTH_CLAMP */
1096 if (!desc->DepthClipEnable)
1097 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
1098 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
1099 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1100 wined3d_device_set_render_state(device->wined3d_device,
1101 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
1102 wined3d_mutex_unlock();
1105 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
1106 UINT viewport_count, const D3D10_VIEWPORT *viewports)
1108 struct d3d_device *device = impl_from_ID3D10Device(iface);
1109 struct wined3d_viewport wined3d_vp;
1111 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1113 if (viewport_count > 1)
1114 FIXME("Multiple viewports not implemented.\n");
1116 if (!viewport_count)
1117 return;
1119 wined3d_vp.x = viewports[0].TopLeftX;
1120 wined3d_vp.y = viewports[0].TopLeftY;
1121 wined3d_vp.width = viewports[0].Width;
1122 wined3d_vp.height = viewports[0].Height;
1123 wined3d_vp.min_z = viewports[0].MinDepth;
1124 wined3d_vp.max_z = viewports[0].MaxDepth;
1126 wined3d_mutex_lock();
1127 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
1128 wined3d_mutex_unlock();
1131 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
1132 UINT rect_count, const D3D10_RECT *rects)
1134 struct d3d_device *device = impl_from_ID3D10Device(iface);
1136 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1138 if (rect_count > 1)
1139 FIXME("Multiple scissor rects not implemented.\n");
1141 if (!rect_count)
1142 return;
1144 wined3d_mutex_lock();
1145 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
1146 wined3d_mutex_unlock();
1149 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
1150 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1151 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
1153 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1154 struct d3d_device *device = impl_from_ID3D10Device(iface);
1155 struct wined3d_box wined3d_src_box;
1157 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1158 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1159 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1160 src_resource, src_subresource_idx, src_box);
1162 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
1163 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
1164 wined3d_src_box.left = src_box->left;
1165 wined3d_src_box.top = src_box->top;
1166 wined3d_src_box.front = src_box->front;
1167 wined3d_src_box.right = src_box->right;
1168 wined3d_src_box.bottom = src_box->bottom;
1169 wined3d_src_box.back = src_box->back;
1170 wined3d_mutex_lock();
1171 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
1172 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, &wined3d_src_box);
1173 wined3d_mutex_unlock();
1176 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
1177 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
1179 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1180 struct d3d_device *device = impl_from_ID3D10Device(iface);
1182 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1184 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
1185 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
1186 wined3d_mutex_lock();
1187 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1188 wined3d_mutex_unlock();
1191 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
1192 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
1193 const void *data, UINT row_pitch, UINT depth_pitch)
1195 struct d3d_device *device = impl_from_ID3D10Device(iface);
1196 struct wined3d_resource *wined3d_resource;
1197 struct wined3d_box wined3d_box;
1199 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1200 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1202 if (box)
1204 wined3d_box.left = box->left;
1205 wined3d_box.top = box->top;
1206 wined3d_box.front = box->front;
1207 wined3d_box.right = box->right;
1208 wined3d_box.bottom = box->bottom;
1209 wined3d_box.back = box->back;
1212 wined3d_resource = wined3d_resource_from_d3d10_resource(resource);
1213 wined3d_mutex_lock();
1214 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1215 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1216 wined3d_mutex_unlock();
1219 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
1220 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
1222 struct d3d_device *device = impl_from_ID3D10Device(iface);
1223 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
1224 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1225 HRESULT hr;
1227 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
1228 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
1230 wined3d_mutex_lock();
1231 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
1232 ERR("Failed to clear view, hr %#x.\n", hr);
1233 wined3d_mutex_unlock();
1236 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
1237 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1239 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
1240 iface, depth_stencil_view, flags, depth, stencil);
1243 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
1244 ID3D10ShaderResourceView *shader_resource_view)
1246 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
1249 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
1250 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
1251 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
1253 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
1254 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
1255 iface, dst_resource, dst_subresource_idx,
1256 src_resource, src_subresource_idx, debug_dxgi_format(format));
1259 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
1260 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1262 struct d3d_device *device = impl_from_ID3D10Device(iface);
1263 unsigned int i;
1265 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1266 iface, start_slot, buffer_count, buffers);
1268 wined3d_mutex_lock();
1269 for (i = 0; i < buffer_count; ++i)
1271 struct wined3d_buffer *wined3d_buffer;
1272 struct d3d_buffer *buffer_impl;
1274 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1276 buffers[i] = NULL;
1277 continue;
1280 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1281 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1282 ID3D10Buffer_AddRef(buffers[i]);
1284 wined3d_mutex_unlock();
1287 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
1288 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1290 struct d3d_device *device = impl_from_ID3D10Device(iface);
1291 unsigned int i;
1293 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1294 iface, start_slot, view_count, views);
1296 wined3d_mutex_lock();
1297 for (i = 0; i < view_count; ++i)
1299 struct wined3d_shader_resource_view *wined3d_view;
1300 struct d3d_shader_resource_view *view_impl;
1302 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1304 views[i] = NULL;
1305 continue;
1308 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1309 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1310 ID3D10ShaderResourceView_AddRef(views[i]);
1312 wined3d_mutex_unlock();
1315 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
1317 struct d3d_device *device = impl_from_ID3D10Device(iface);
1318 struct d3d10_pixel_shader *shader_impl;
1319 struct wined3d_shader *wined3d_shader;
1321 TRACE("iface %p, shader %p.\n", iface, shader);
1323 wined3d_mutex_lock();
1324 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1326 wined3d_mutex_unlock();
1327 *shader = NULL;
1328 return;
1331 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1332 wined3d_mutex_unlock();
1333 *shader = &shader_impl->ID3D10PixelShader_iface;
1334 ID3D10PixelShader_AddRef(*shader);
1337 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
1338 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1340 struct d3d_device *device = impl_from_ID3D10Device(iface);
1341 unsigned int i;
1343 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1344 iface, start_slot, sampler_count, samplers);
1346 wined3d_mutex_lock();
1347 for (i = 0; i < sampler_count; ++i)
1349 struct d3d10_sampler_state *sampler_impl;
1350 struct wined3d_sampler *wined3d_sampler;
1352 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1354 samplers[i] = NULL;
1355 continue;
1358 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1359 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1360 ID3D10SamplerState_AddRef(samplers[i]);
1362 wined3d_mutex_unlock();
1365 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
1367 struct d3d_device *device = impl_from_ID3D10Device(iface);
1368 struct d3d10_vertex_shader *shader_impl;
1369 struct wined3d_shader *wined3d_shader;
1371 TRACE("iface %p, shader %p.\n", iface, shader);
1373 wined3d_mutex_lock();
1374 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1376 wined3d_mutex_unlock();
1377 *shader = NULL;
1378 return;
1381 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1382 wined3d_mutex_unlock();
1383 *shader = &shader_impl->ID3D10VertexShader_iface;
1384 ID3D10VertexShader_AddRef(*shader);
1387 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
1388 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1390 struct d3d_device *device = impl_from_ID3D10Device(iface);
1391 unsigned int i;
1393 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1394 iface, start_slot, buffer_count, buffers);
1396 wined3d_mutex_lock();
1397 for (i = 0; i < buffer_count; ++i)
1399 struct wined3d_buffer *wined3d_buffer;
1400 struct d3d_buffer *buffer_impl;
1402 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1404 buffers[i] = NULL;
1405 continue;
1408 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1409 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1410 ID3D10Buffer_AddRef(buffers[i]);
1412 wined3d_mutex_unlock();
1415 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
1417 struct d3d_device *device = impl_from_ID3D10Device(iface);
1418 struct wined3d_vertex_declaration *wined3d_declaration;
1419 struct d3d10_input_layout *input_layout_impl;
1421 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1423 wined3d_mutex_lock();
1424 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1426 wined3d_mutex_unlock();
1427 *input_layout = NULL;
1428 return;
1431 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1432 wined3d_mutex_unlock();
1433 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
1434 ID3D10InputLayout_AddRef(*input_layout);
1437 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
1438 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
1440 struct d3d_device *device = impl_from_ID3D10Device(iface);
1441 unsigned int i;
1443 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1444 iface, start_slot, buffer_count, buffers, strides, offsets);
1446 wined3d_mutex_lock();
1447 for (i = 0; i < buffer_count; ++i)
1449 struct wined3d_buffer *wined3d_buffer;
1450 struct d3d_buffer *buffer_impl;
1452 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1453 &wined3d_buffer, &offsets[i], &strides[i])))
1454 ERR("Failed to get vertex buffer.\n");
1456 if (!wined3d_buffer)
1458 buffers[i] = NULL;
1459 continue;
1462 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1463 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1464 ID3D10Buffer_AddRef(buffers[i]);
1466 wined3d_mutex_unlock();
1469 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
1470 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1472 struct d3d_device *device = impl_from_ID3D10Device(iface);
1473 enum wined3d_format_id wined3d_format;
1474 struct wined3d_buffer *wined3d_buffer;
1475 struct d3d_buffer *buffer_impl;
1477 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1479 wined3d_mutex_lock();
1480 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
1481 *format = dxgi_format_from_wined3dformat(wined3d_format);
1482 *offset = 0; /* FIXME */
1483 if (!wined3d_buffer)
1485 wined3d_mutex_unlock();
1486 *buffer = NULL;
1487 return;
1490 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1491 wined3d_mutex_unlock();
1492 *buffer = &buffer_impl->ID3D10Buffer_iface;
1493 ID3D10Buffer_AddRef(*buffer);
1496 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
1497 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1499 struct d3d_device *device = impl_from_ID3D10Device(iface);
1500 unsigned int i;
1502 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1503 iface, start_slot, buffer_count, buffers);
1505 wined3d_mutex_lock();
1506 for (i = 0; i < buffer_count; ++i)
1508 struct wined3d_buffer *wined3d_buffer;
1509 struct d3d_buffer *buffer_impl;
1511 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1513 buffers[i] = NULL;
1514 continue;
1517 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1518 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1519 ID3D10Buffer_AddRef(buffers[i]);
1521 wined3d_mutex_unlock();
1524 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
1526 struct d3d_device *device = impl_from_ID3D10Device(iface);
1527 struct d3d10_geometry_shader *shader_impl;
1528 struct wined3d_shader *wined3d_shader;
1530 TRACE("iface %p, shader %p.\n", iface, shader);
1532 wined3d_mutex_lock();
1533 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1535 wined3d_mutex_unlock();
1536 *shader = NULL;
1537 return;
1540 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1541 wined3d_mutex_unlock();
1542 *shader = &shader_impl->ID3D10GeometryShader_iface;
1543 ID3D10GeometryShader_AddRef(*shader);
1546 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
1547 D3D10_PRIMITIVE_TOPOLOGY *topology)
1549 struct d3d_device *This = impl_from_ID3D10Device(iface);
1551 TRACE("iface %p, topology %p\n", iface, topology);
1553 wined3d_mutex_lock();
1554 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
1555 wined3d_mutex_unlock();
1558 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
1559 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1561 struct d3d_device *device = impl_from_ID3D10Device(iface);
1562 unsigned int i;
1564 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1565 iface, start_slot, view_count, views);
1567 wined3d_mutex_lock();
1568 for (i = 0; i < view_count; ++i)
1570 struct wined3d_shader_resource_view *wined3d_view;
1571 struct d3d_shader_resource_view *view_impl;
1573 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1575 views[i] = NULL;
1576 continue;
1579 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1580 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1581 ID3D10ShaderResourceView_AddRef(views[i]);
1583 wined3d_mutex_unlock();
1586 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
1587 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1589 struct d3d_device *device = impl_from_ID3D10Device(iface);
1590 unsigned int i;
1592 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1593 iface, start_slot, sampler_count, samplers);
1595 wined3d_mutex_lock();
1596 for (i = 0; i < sampler_count; ++i)
1598 struct d3d10_sampler_state *sampler_impl;
1599 struct wined3d_sampler *wined3d_sampler;
1601 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1603 samplers[i] = NULL;
1604 continue;
1607 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1608 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1609 ID3D10SamplerState_AddRef(samplers[i]);
1611 wined3d_mutex_unlock();
1614 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
1615 ID3D10Predicate **predicate, BOOL *value)
1617 struct d3d_device *device = impl_from_ID3D10Device(iface);
1618 struct wined3d_query *wined3d_predicate;
1619 struct d3d10_query *predicate_impl;
1621 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1623 wined3d_mutex_lock();
1624 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1626 wined3d_mutex_unlock();
1627 *predicate = NULL;
1628 return;
1631 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1632 wined3d_mutex_unlock();
1633 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
1634 ID3D10Predicate_AddRef(*predicate);
1637 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
1638 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1640 struct d3d_device *device = impl_from_ID3D10Device(iface);
1641 unsigned int i;
1643 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1644 iface, start_slot, view_count, views);
1646 wined3d_mutex_lock();
1647 for (i = 0; i < view_count; ++i)
1649 struct wined3d_shader_resource_view *wined3d_view;
1650 struct d3d_shader_resource_view *view_impl;
1652 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1654 views[i] = NULL;
1655 continue;
1658 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1659 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1660 ID3D10ShaderResourceView_AddRef(views[i]);
1662 wined3d_mutex_unlock();
1665 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1666 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1668 struct d3d_device *device = impl_from_ID3D10Device(iface);
1669 unsigned int i;
1671 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1672 iface, start_slot, sampler_count, samplers);
1674 wined3d_mutex_lock();
1675 for (i = 0; i < sampler_count; ++i)
1677 struct d3d10_sampler_state *sampler_impl;
1678 struct wined3d_sampler *wined3d_sampler;
1680 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1682 samplers[i] = NULL;
1683 continue;
1686 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1687 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1688 ID3D10SamplerState_AddRef(samplers[i]);
1690 wined3d_mutex_unlock();
1693 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1694 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1696 struct d3d_device *device = impl_from_ID3D10Device(iface);
1697 struct wined3d_rendertarget_view *wined3d_view;
1699 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1700 iface, view_count, render_target_views, depth_stencil_view);
1702 wined3d_mutex_lock();
1703 if (render_target_views)
1705 struct d3d_rendertarget_view *view_impl;
1706 unsigned int i;
1708 for (i = 0; i < view_count; ++i)
1710 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1711 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1713 render_target_views[i] = NULL;
1714 continue;
1717 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1718 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1722 if (depth_stencil_view)
1724 struct d3d_depthstencil_view *view_impl;
1726 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1727 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1729 *depth_stencil_view = NULL;
1731 else
1733 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1734 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1737 wined3d_mutex_unlock();
1740 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1741 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1743 struct d3d_device *device = impl_from_ID3D10Device(iface);
1745 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1746 iface, blend_state, blend_factor, sample_mask);
1748 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1749 ID3D10BlendState_AddRef(*blend_state);
1750 wined3d_mutex_lock();
1751 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1752 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1753 wined3d_mutex_unlock();
1756 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1757 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1759 struct d3d_device *device = impl_from_ID3D10Device(iface);
1761 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1762 iface, depth_stencil_state, stencil_ref);
1764 if ((*depth_stencil_state = device->depth_stencil_state
1765 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1766 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1767 *stencil_ref = device->stencil_ref;
1770 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1771 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1773 struct d3d_device *device = impl_from_ID3D10Device(iface);
1774 unsigned int i;
1776 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1777 iface, buffer_count, buffers, offsets);
1779 wined3d_mutex_lock();
1780 for (i = 0; i < buffer_count; ++i)
1782 struct wined3d_buffer *wined3d_buffer;
1783 struct d3d_buffer *buffer_impl;
1785 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1787 buffers[i] = NULL;
1788 continue;
1791 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1792 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1793 ID3D10Buffer_AddRef(buffers[i]);
1795 wined3d_mutex_unlock();
1798 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1800 struct d3d_device *device = impl_from_ID3D10Device(iface);
1802 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1804 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1805 ID3D10RasterizerState_AddRef(*rasterizer_state);
1808 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1809 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1811 struct d3d_device *device = impl_from_ID3D10Device(iface);
1812 struct wined3d_viewport wined3d_vp;
1814 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1816 if (!viewports)
1818 *viewport_count = 1;
1819 return;
1822 if (!*viewport_count)
1823 return;
1825 wined3d_mutex_lock();
1826 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1827 wined3d_mutex_unlock();
1829 viewports[0].TopLeftX = wined3d_vp.x;
1830 viewports[0].TopLeftY = wined3d_vp.y;
1831 viewports[0].Width = wined3d_vp.width;
1832 viewports[0].Height = wined3d_vp.height;
1833 viewports[0].MinDepth = wined3d_vp.min_z;
1834 viewports[0].MaxDepth = wined3d_vp.max_z;
1836 if (*viewport_count > 1)
1837 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1840 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1842 struct d3d_device *device = impl_from_ID3D10Device(iface);
1844 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1846 if (!rects)
1848 *rect_count = 1;
1849 return;
1852 if (!*rect_count)
1853 return;
1855 wined3d_mutex_lock();
1856 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1857 wined3d_mutex_unlock();
1858 if (*rect_count > 1)
1859 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1862 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1864 TRACE("iface %p.\n", iface);
1866 /* In the current implementation the device is never removed, so we can
1867 * just return S_OK here. */
1869 return S_OK;
1872 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1874 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1876 return E_NOTIMPL;
1879 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1881 FIXME("iface %p stub!\n", iface);
1883 return 0;
1886 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1887 REFGUID guid, UINT *data_size, void *data)
1889 IDXGIDevice *dxgi_device;
1890 HRESULT hr;
1892 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1893 iface, debugstr_guid(guid), data_size, data);
1895 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1896 return hr;
1897 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
1898 IDXGIDevice_Release(dxgi_device);
1900 return hr;
1903 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1904 REFGUID guid, UINT data_size, const void *data)
1906 IDXGIDevice *dxgi_device;
1907 HRESULT hr;
1909 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1910 iface, debugstr_guid(guid), data_size, data);
1912 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1913 return hr;
1914 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
1915 IDXGIDevice_Release(dxgi_device);
1917 return hr;
1920 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1921 REFGUID guid, const IUnknown *data)
1923 IDXGIDevice *dxgi_device;
1924 HRESULT hr;
1926 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1928 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1929 return hr;
1930 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
1931 IDXGIDevice_Release(dxgi_device);
1933 return hr;
1936 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1938 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1939 struct d3d_device *device = impl_from_ID3D10Device(iface);
1940 unsigned int i;
1942 TRACE("iface %p.\n", iface);
1944 wined3d_mutex_lock();
1945 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
1946 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1948 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
1950 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1952 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
1954 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1956 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
1958 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
1959 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1961 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
1963 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1965 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
1967 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1969 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
1971 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
1972 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1974 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
1976 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1978 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
1980 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1982 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
1984 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1986 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
1988 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
1989 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
1990 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
1991 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1993 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
1995 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
1996 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
1997 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
1998 ID3D10Device1_RSSetViewports(iface, 0, NULL);
1999 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
2000 ID3D10Device1_RSSetState(iface, NULL);
2001 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2003 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2005 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
2006 wined3d_mutex_unlock();
2009 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
2011 FIXME("iface %p stub!\n", iface);
2014 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
2015 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
2017 struct d3d_device *device = impl_from_ID3D10Device(iface);
2018 D3D11_BUFFER_DESC d3d11_desc;
2019 struct d3d_buffer *object;
2020 HRESULT hr;
2022 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2024 d3d11_desc.ByteWidth = desc->ByteWidth;
2025 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2026 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2027 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2028 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2029 d3d11_desc.StructureByteStride = 0;
2031 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2032 return hr;
2034 *buffer = &object->ID3D10Buffer_iface;
2036 return S_OK;
2039 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
2040 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
2042 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2044 return E_NOTIMPL;
2047 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
2048 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2049 ID3D10Texture2D **texture)
2051 struct d3d_device *device = impl_from_ID3D10Device(iface);
2052 D3D11_TEXTURE2D_DESC d3d11_desc;
2053 struct d3d_texture2d *object;
2054 HRESULT hr;
2056 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2058 d3d11_desc.Width = desc->Width;
2059 d3d11_desc.Height = desc->Height;
2060 d3d11_desc.MipLevels = desc->MipLevels;
2061 d3d11_desc.ArraySize = desc->ArraySize;
2062 d3d11_desc.Format = desc->Format;
2063 d3d11_desc.SampleDesc = desc->SampleDesc;
2064 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2065 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2066 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2067 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2069 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2070 return hr;
2072 *texture = &object->ID3D10Texture2D_iface;
2074 return S_OK;
2077 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
2078 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2079 ID3D10Texture3D **texture)
2081 struct d3d_device *device = impl_from_ID3D10Device(iface);
2082 D3D11_TEXTURE3D_DESC d3d11_desc;
2083 struct d3d_texture3d *object;
2084 HRESULT hr;
2086 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2088 d3d11_desc.Width = desc->Width;
2089 d3d11_desc.Height = desc->Height;
2090 d3d11_desc.Depth = desc->Depth;
2091 d3d11_desc.MipLevels = desc->MipLevels;
2092 d3d11_desc.Format = desc->Format;
2093 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2094 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2095 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2096 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2098 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2099 return hr;
2101 *texture = &object->ID3D10Texture3D_iface;
2103 return S_OK;
2106 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
2107 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
2109 struct d3d_device *device = impl_from_ID3D10Device(iface);
2110 struct d3d_shader_resource_view *object;
2111 HRESULT hr;
2113 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2115 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2116 return E_OUTOFMEMORY;
2118 if (FAILED(hr = d3d_shader_resource_view_init(object, device, resource,
2119 (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc)))
2121 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
2122 HeapFree(GetProcessHeap(), 0, object);
2123 return hr;
2126 TRACE("Created shader resource view %p.\n", object);
2127 *view = &object->ID3D10ShaderResourceView_iface;
2129 return S_OK;
2132 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
2133 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
2135 struct d3d_device *device = impl_from_ID3D10Device(iface);
2136 struct d3d_rendertarget_view *object;
2137 ID3D11Resource *d3d11_resource;
2138 HRESULT hr;
2140 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2142 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
2144 ERR("Resource does not implement ID3D11Resource.\n");
2145 return E_FAIL;
2148 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
2149 ID3D11Resource_Release(d3d11_resource);
2150 if (FAILED(hr))
2151 return hr;
2153 *view = &object->ID3D10RenderTargetView_iface;
2155 return S_OK;
2158 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
2159 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
2161 struct d3d_device *device = impl_from_ID3D10Device(iface);
2162 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
2163 struct d3d_depthstencil_view *object;
2164 ID3D11Resource *d3d11_resource;
2165 HRESULT hr;
2167 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2169 if (desc)
2171 d3d11_desc.Format = desc->Format;
2172 d3d11_desc.ViewDimension = desc->ViewDimension;
2173 d3d11_desc.Flags = 0;
2174 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
2177 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
2179 ERR("Resource does not implement ID3D11Resource.\n");
2180 return E_FAIL;
2183 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
2184 ID3D11Resource_Release(d3d11_resource);
2185 if (FAILED(hr))
2186 return hr;
2188 *view = &object->ID3D10DepthStencilView_iface;
2190 return S_OK;
2193 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
2194 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
2195 const void *shader_byte_code, SIZE_T shader_byte_code_length,
2196 ID3D10InputLayout **input_layout)
2198 struct d3d_device *This = impl_from_ID3D10Device(iface);
2199 struct d3d10_input_layout *object;
2200 HRESULT hr;
2202 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
2203 "shader_byte_code_length %lu, input_layout %p\n",
2204 iface, element_descs, element_count, shader_byte_code,
2205 shader_byte_code_length, input_layout);
2207 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2208 if (!object)
2209 return E_OUTOFMEMORY;
2211 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
2212 shader_byte_code, shader_byte_code_length);
2213 if (FAILED(hr))
2215 WARN("Failed to initialize input layout, hr %#x.\n", hr);
2216 HeapFree(GetProcessHeap(), 0, object);
2217 return hr;
2220 TRACE("Created input layout %p.\n", object);
2221 *input_layout = &object->ID3D10InputLayout_iface;
2223 return S_OK;
2226 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
2227 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
2229 struct d3d_device *This = impl_from_ID3D10Device(iface);
2230 struct d3d10_vertex_shader *object;
2231 HRESULT hr;
2233 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
2234 iface, byte_code, byte_code_length, shader);
2236 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2237 if (!object)
2238 return E_OUTOFMEMORY;
2240 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
2241 if (FAILED(hr))
2243 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2244 HeapFree(GetProcessHeap(), 0, object);
2245 return hr;
2248 TRACE("Created vertex shader %p.\n", object);
2249 *shader = &object->ID3D10VertexShader_iface;
2251 return S_OK;
2254 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
2255 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
2257 struct d3d_device *This = impl_from_ID3D10Device(iface);
2258 struct d3d10_geometry_shader *object;
2259 HRESULT hr;
2261 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
2262 iface, byte_code, byte_code_length, shader);
2264 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2265 if (!object)
2266 return E_OUTOFMEMORY;
2268 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
2269 if (FAILED(hr))
2271 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
2272 HeapFree(GetProcessHeap(), 0, object);
2273 return hr;
2276 TRACE("Created geometry shader %p.\n", object);
2277 *shader = &object->ID3D10GeometryShader_iface;
2279 return S_OK;
2282 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
2283 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
2284 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
2286 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
2287 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
2288 iface, byte_code, byte_code_length, output_stream_decls,
2289 output_stream_decl_count, output_stream_stride, shader);
2291 return E_NOTIMPL;
2294 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
2295 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
2297 struct d3d_device *This = impl_from_ID3D10Device(iface);
2298 struct d3d10_pixel_shader *object;
2299 HRESULT hr;
2301 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
2302 iface, byte_code, byte_code_length, shader);
2304 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2305 if (!object)
2306 return E_OUTOFMEMORY;
2308 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
2309 if (FAILED(hr))
2311 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2312 HeapFree(GetProcessHeap(), 0, object);
2313 return hr;
2316 TRACE("Created pixel shader %p.\n", object);
2317 *shader = &object->ID3D10PixelShader_iface;
2319 return S_OK;
2322 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
2323 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
2325 struct d3d_device *device = impl_from_ID3D10Device(iface);
2326 struct d3d10_blend_state *object;
2327 struct wine_rb_entry *entry;
2328 HRESULT hr;
2330 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2332 if (!desc)
2333 return E_INVALIDARG;
2335 wined3d_mutex_lock();
2336 if ((entry = wine_rb_get(&device->blend_states, desc)))
2338 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
2340 TRACE("Returning existing blend state %p.\n", object);
2341 *blend_state = &object->ID3D10BlendState_iface;
2342 ID3D10BlendState_AddRef(*blend_state);
2343 wined3d_mutex_unlock();
2345 return S_OK;
2347 wined3d_mutex_unlock();
2349 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2350 if (!object)
2351 return E_OUTOFMEMORY;
2353 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
2355 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2356 HeapFree(GetProcessHeap(), 0, object);
2357 return hr;
2360 TRACE("Created blend state %p.\n", object);
2361 *blend_state = &object->ID3D10BlendState_iface;
2363 return S_OK;
2366 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
2367 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
2369 struct d3d_device *device = impl_from_ID3D10Device(iface);
2370 struct d3d10_depthstencil_state *object;
2371 D3D10_DEPTH_STENCIL_DESC tmp_desc;
2372 struct wine_rb_entry *entry;
2373 HRESULT hr;
2375 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2377 if (!desc)
2378 return E_INVALIDARG;
2380 /* D3D10_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2381 * it as a key in the rbtree. */
2382 memset(&tmp_desc, 0, sizeof(tmp_desc));
2383 tmp_desc.DepthEnable = desc->DepthEnable;
2384 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2385 tmp_desc.DepthFunc = desc->DepthFunc;
2386 tmp_desc.StencilEnable = desc->StencilEnable;
2387 tmp_desc.StencilReadMask = desc->StencilReadMask;
2388 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2389 tmp_desc.FrontFace = desc->FrontFace;
2390 tmp_desc.BackFace = desc->BackFace;
2392 wined3d_mutex_lock();
2393 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
2395 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
2397 TRACE("Returning existing depthstencil state %p.\n", object);
2398 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
2399 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
2400 wined3d_mutex_unlock();
2402 return S_OK;
2404 wined3d_mutex_unlock();
2406 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2407 if (!object)
2408 return E_OUTOFMEMORY;
2410 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, &tmp_desc)))
2412 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
2413 HeapFree(GetProcessHeap(), 0, object);
2414 return hr;
2417 TRACE("Created depthstencil state %p.\n", object);
2418 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
2420 return S_OK;
2423 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
2424 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
2426 struct d3d_device *device = impl_from_ID3D10Device(iface);
2427 struct d3d10_rasterizer_state *object;
2428 struct wine_rb_entry *entry;
2429 HRESULT hr;
2431 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2433 if (!desc)
2434 return E_INVALIDARG;
2436 wined3d_mutex_lock();
2437 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
2439 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
2441 TRACE("Returning existing rasterizer state %p.\n", object);
2442 *rasterizer_state = &object->ID3D10RasterizerState_iface;
2443 ID3D10RasterizerState_AddRef(*rasterizer_state);
2444 wined3d_mutex_unlock();
2446 return S_OK;
2448 wined3d_mutex_unlock();
2450 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2451 if (!object)
2452 return E_OUTOFMEMORY;
2454 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
2456 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
2457 HeapFree(GetProcessHeap(), 0, object);
2458 return hr;
2461 TRACE("Created rasterizer state %p.\n", object);
2462 *rasterizer_state = &object->ID3D10RasterizerState_iface;
2464 return S_OK;
2467 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
2468 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
2470 struct d3d_device *device = impl_from_ID3D10Device(iface);
2471 struct d3d10_sampler_state *object;
2472 struct wine_rb_entry *entry;
2473 HRESULT hr;
2475 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2477 if (!desc)
2478 return E_INVALIDARG;
2480 wined3d_mutex_lock();
2481 if ((entry = wine_rb_get(&device->sampler_states, desc)))
2483 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
2485 TRACE("Returning existing sampler state %p.\n", object);
2486 *sampler_state = &object->ID3D10SamplerState_iface;
2487 ID3D10SamplerState_AddRef(*sampler_state);
2488 wined3d_mutex_unlock();
2490 return S_OK;
2492 wined3d_mutex_unlock();
2494 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2495 if (!object)
2496 return E_OUTOFMEMORY;
2498 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
2500 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2501 HeapFree(GetProcessHeap(), 0, object);
2502 return hr;
2505 TRACE("Created sampler state %p.\n", object);
2506 *sampler_state = &object->ID3D10SamplerState_iface;
2508 return S_OK;
2511 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
2512 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
2514 struct d3d_device *device = impl_from_ID3D10Device(iface);
2515 struct d3d10_query *object;
2516 HRESULT hr;
2518 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2520 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2521 return E_OUTOFMEMORY;
2523 if (FAILED(hr = d3d10_query_init(object, device, desc, FALSE)))
2525 WARN("Failed to initialize query, hr %#x.\n", hr);
2526 HeapFree(GetProcessHeap(), 0, object);
2527 return hr;
2530 TRACE("Created query %p.\n", object);
2531 *query = &object->ID3D10Query_iface;
2533 return S_OK;
2536 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
2537 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
2539 struct d3d_device *device = impl_from_ID3D10Device(iface);
2540 struct d3d10_query *object;
2541 HRESULT hr;
2543 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2545 if (!desc)
2546 return E_INVALIDARG;
2548 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
2550 WARN("Query type %#x is not a predicate.\n", desc->Query);
2551 return E_INVALIDARG;
2554 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2555 return E_OUTOFMEMORY;
2557 if (FAILED(hr = d3d10_query_init(object, device, desc, TRUE)))
2559 WARN("Failed to initialize predicate, hr %#x.\n", hr);
2560 HeapFree(GetProcessHeap(), 0, object);
2561 return hr;
2564 TRACE("Created predicate %p.\n", object);
2565 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
2567 return S_OK;
2570 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
2571 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
2573 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2575 return E_NOTIMPL;
2578 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
2579 DXGI_FORMAT format, UINT *format_support)
2581 FIXME("iface %p, format %s, format_support %p stub!\n",
2582 iface, debug_dxgi_format(format), format_support);
2584 return E_NOTIMPL;
2587 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
2588 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2590 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
2591 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2593 return E_NOTIMPL;
2596 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
2598 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
2601 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
2602 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
2603 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
2605 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
2606 "units %p, units_length %p, description %p, description_length %p stub!\n",
2607 iface, desc, type, active_counters, name, name_length,
2608 units, units_length, description, description_length);
2610 return E_NOTIMPL;
2613 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
2615 FIXME("iface %p stub!\n", iface);
2617 return 0;
2620 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
2621 HANDLE resource_handle, REFIID guid, void **resource)
2623 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
2624 iface, resource_handle, debugstr_guid(guid), resource);
2626 return E_NOTIMPL;
2629 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
2631 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
2634 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
2636 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
2639 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
2640 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
2642 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
2644 return E_NOTIMPL;
2647 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
2648 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
2650 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
2652 return E_NOTIMPL;
2655 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
2657 FIXME("iface %p stub!\n", iface);
2659 return D3D10_FEATURE_LEVEL_10_1;
2662 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
2664 /* IUnknown methods */
2665 d3d10_device_QueryInterface,
2666 d3d10_device_AddRef,
2667 d3d10_device_Release,
2668 /* ID3D10Device methods */
2669 d3d10_device_VSSetConstantBuffers,
2670 d3d10_device_PSSetShaderResources,
2671 d3d10_device_PSSetShader,
2672 d3d10_device_PSSetSamplers,
2673 d3d10_device_VSSetShader,
2674 d3d10_device_DrawIndexed,
2675 d3d10_device_Draw,
2676 d3d10_device_PSSetConstantBuffers,
2677 d3d10_device_IASetInputLayout,
2678 d3d10_device_IASetVertexBuffers,
2679 d3d10_device_IASetIndexBuffer,
2680 d3d10_device_DrawIndexedInstanced,
2681 d3d10_device_DrawInstanced,
2682 d3d10_device_GSSetConstantBuffers,
2683 d3d10_device_GSSetShader,
2684 d3d10_device_IASetPrimitiveTopology,
2685 d3d10_device_VSSetShaderResources,
2686 d3d10_device_VSSetSamplers,
2687 d3d10_device_SetPredication,
2688 d3d10_device_GSSetShaderResources,
2689 d3d10_device_GSSetSamplers,
2690 d3d10_device_OMSetRenderTargets,
2691 d3d10_device_OMSetBlendState,
2692 d3d10_device_OMSetDepthStencilState,
2693 d3d10_device_SOSetTargets,
2694 d3d10_device_DrawAuto,
2695 d3d10_device_RSSetState,
2696 d3d10_device_RSSetViewports,
2697 d3d10_device_RSSetScissorRects,
2698 d3d10_device_CopySubresourceRegion,
2699 d3d10_device_CopyResource,
2700 d3d10_device_UpdateSubresource,
2701 d3d10_device_ClearRenderTargetView,
2702 d3d10_device_ClearDepthStencilView,
2703 d3d10_device_GenerateMips,
2704 d3d10_device_ResolveSubresource,
2705 d3d10_device_VSGetConstantBuffers,
2706 d3d10_device_PSGetShaderResources,
2707 d3d10_device_PSGetShader,
2708 d3d10_device_PSGetSamplers,
2709 d3d10_device_VSGetShader,
2710 d3d10_device_PSGetConstantBuffers,
2711 d3d10_device_IAGetInputLayout,
2712 d3d10_device_IAGetVertexBuffers,
2713 d3d10_device_IAGetIndexBuffer,
2714 d3d10_device_GSGetConstantBuffers,
2715 d3d10_device_GSGetShader,
2716 d3d10_device_IAGetPrimitiveTopology,
2717 d3d10_device_VSGetShaderResources,
2718 d3d10_device_VSGetSamplers,
2719 d3d10_device_GetPredication,
2720 d3d10_device_GSGetShaderResources,
2721 d3d10_device_GSGetSamplers,
2722 d3d10_device_OMGetRenderTargets,
2723 d3d10_device_OMGetBlendState,
2724 d3d10_device_OMGetDepthStencilState,
2725 d3d10_device_SOGetTargets,
2726 d3d10_device_RSGetState,
2727 d3d10_device_RSGetViewports,
2728 d3d10_device_RSGetScissorRects,
2729 d3d10_device_GetDeviceRemovedReason,
2730 d3d10_device_SetExceptionMode,
2731 d3d10_device_GetExceptionMode,
2732 d3d10_device_GetPrivateData,
2733 d3d10_device_SetPrivateData,
2734 d3d10_device_SetPrivateDataInterface,
2735 d3d10_device_ClearState,
2736 d3d10_device_Flush,
2737 d3d10_device_CreateBuffer,
2738 d3d10_device_CreateTexture1D,
2739 d3d10_device_CreateTexture2D,
2740 d3d10_device_CreateTexture3D,
2741 d3d10_device_CreateShaderResourceView,
2742 d3d10_device_CreateRenderTargetView,
2743 d3d10_device_CreateDepthStencilView,
2744 d3d10_device_CreateInputLayout,
2745 d3d10_device_CreateVertexShader,
2746 d3d10_device_CreateGeometryShader,
2747 d3d10_device_CreateGeometryShaderWithStreamOutput,
2748 d3d10_device_CreatePixelShader,
2749 d3d10_device_CreateBlendState,
2750 d3d10_device_CreateDepthStencilState,
2751 d3d10_device_CreateRasterizerState,
2752 d3d10_device_CreateSamplerState,
2753 d3d10_device_CreateQuery,
2754 d3d10_device_CreatePredicate,
2755 d3d10_device_CreateCounter,
2756 d3d10_device_CheckFormatSupport,
2757 d3d10_device_CheckMultisampleQualityLevels,
2758 d3d10_device_CheckCounterInfo,
2759 d3d10_device_CheckCounter,
2760 d3d10_device_GetCreationFlags,
2761 d3d10_device_OpenSharedResource,
2762 d3d10_device_SetTextFilterSize,
2763 d3d10_device_GetTextFilterSize,
2764 d3d10_device_CreateShaderResourceView1,
2765 d3d10_device_CreateBlendState1,
2766 d3d10_device_GetFeatureLevel,
2769 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
2771 /* IUnknown methods */
2772 d3d10_device_inner_QueryInterface,
2773 d3d10_device_inner_AddRef,
2774 d3d10_device_inner_Release,
2777 /* ID3D10Multithread methods */
2779 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
2781 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
2784 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
2786 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2788 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2790 return IUnknown_QueryInterface(device->outer_unk, iid, out);
2793 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
2795 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2797 TRACE("iface %p.\n", iface);
2799 return IUnknown_AddRef(device->outer_unk);
2802 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2804 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2806 TRACE("iface %p.\n", iface);
2808 return IUnknown_Release(device->outer_unk);
2811 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2813 TRACE("iface %p.\n", iface);
2815 wined3d_mutex_lock();
2818 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2820 TRACE("iface %p.\n", iface);
2822 wined3d_mutex_unlock();
2825 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2827 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2829 return TRUE;
2832 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2834 FIXME("iface %p stub!\n", iface);
2836 return TRUE;
2839 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2841 d3d10_multithread_QueryInterface,
2842 d3d10_multithread_AddRef,
2843 d3d10_multithread_Release,
2844 d3d10_multithread_Enter,
2845 d3d10_multithread_Leave,
2846 d3d10_multithread_SetMultithreadProtected,
2847 d3d10_multithread_GetMultithreadProtected,
2850 /* IWineDXGIDeviceParent IUnknown methods */
2852 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2854 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
2857 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2858 REFIID riid, void **ppv)
2860 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2861 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2864 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2866 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2867 return IUnknown_AddRef(device->outer_unk);
2870 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2872 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2873 return IUnknown_Release(device->outer_unk);
2876 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2877 IWineDXGIDeviceParent *iface)
2879 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2880 return &device->device_parent;
2883 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2885 /* IUnknown methods */
2886 dxgi_device_parent_QueryInterface,
2887 dxgi_device_parent_AddRef,
2888 dxgi_device_parent_Release,
2889 /* IWineDXGIDeviceParent methods */
2890 dxgi_device_parent_get_wined3d_device_parent,
2893 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2895 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
2898 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2899 struct wined3d_device *wined3d_device)
2901 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2903 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2905 wined3d_device_incref(wined3d_device);
2906 device->wined3d_device = wined3d_device;
2909 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2911 TRACE("device_parent %p.\n", device_parent);
2914 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2916 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2919 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2920 void *container_parent, struct wined3d_surface *surface, void **parent,
2921 const struct wined3d_parent_ops **parent_ops)
2923 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2924 device_parent, container_parent, surface, parent, parent_ops);
2926 *parent = NULL;
2927 *parent_ops = &d3d10_null_wined3d_parent_ops;
2929 return S_OK;
2932 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2933 void *container_parent, struct wined3d_volume *volume, void **parent,
2934 const struct wined3d_parent_ops **parent_ops)
2936 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2937 device_parent, container_parent, volume, parent, parent_ops);
2939 *parent = NULL;
2940 *parent_ops = &d3d10_null_wined3d_parent_ops;
2942 return S_OK;
2945 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
2946 void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
2947 struct wined3d_texture **wined3d_texture)
2949 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2950 struct d3d_texture2d *texture;
2951 ID3D10Texture2D *texture_iface;
2952 D3D10_TEXTURE2D_DESC desc;
2953 HRESULT hr;
2955 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
2956 device_parent, container_parent, wined3d_desc, wined3d_texture);
2958 FIXME("Implement DXGI<->wined3d usage conversion\n");
2960 desc.Width = wined3d_desc->width;
2961 desc.Height = wined3d_desc->height;
2962 desc.MipLevels = 1;
2963 desc.ArraySize = 1;
2964 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2965 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2966 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2967 desc.Usage = D3D10_USAGE_DEFAULT;
2968 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2969 desc.CPUAccessFlags = 0;
2970 desc.MiscFlags = 0;
2972 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2973 &desc, NULL, &texture_iface)))
2975 ERR("CreateTexture2D failed, returning %#x\n", hr);
2976 return hr;
2979 texture = impl_from_ID3D10Texture2D(texture_iface);
2981 *wined3d_texture = texture->wined3d_texture;
2982 wined3d_texture_incref(*wined3d_texture);
2983 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2985 return S_OK;
2988 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2989 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2991 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2992 IWineDXGIDevice *wine_device;
2993 HRESULT hr;
2995 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2997 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2998 &IID_IWineDXGIDevice, (void **)&wine_device)))
3000 ERR("Device should implement IWineDXGIDevice.\n");
3001 return E_FAIL;
3004 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
3005 IWineDXGIDevice_Release(wine_device);
3006 if (FAILED(hr))
3008 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
3009 return hr;
3012 return S_OK;
3015 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
3017 device_parent_wined3d_device_created,
3018 device_parent_mode_changed,
3019 device_parent_activate,
3020 device_parent_surface_created,
3021 device_parent_volume_created,
3022 device_parent_create_swapchain_texture,
3023 device_parent_create_swapchain,
3026 static void *d3d10_rb_alloc(size_t size)
3028 return HeapAlloc(GetProcessHeap(), 0, size);
3031 static void *d3d10_rb_realloc(void *ptr, size_t size)
3033 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
3036 static void d3d10_rb_free(void *ptr)
3038 HeapFree(GetProcessHeap(), 0, ptr);
3041 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
3043 const D3D10_SAMPLER_DESC *ka = key;
3044 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
3046 return memcmp(ka, kb, sizeof(*ka));
3049 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
3051 d3d10_rb_alloc,
3052 d3d10_rb_realloc,
3053 d3d10_rb_free,
3054 d3d10_sampler_state_compare,
3057 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
3059 const D3D10_BLEND_DESC *ka = key;
3060 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
3062 return memcmp(ka, kb, sizeof(*ka));
3065 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
3067 d3d10_rb_alloc,
3068 d3d10_rb_realloc,
3069 d3d10_rb_free,
3070 d3d10_blend_state_compare,
3073 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
3075 const D3D10_DEPTH_STENCIL_DESC *ka = key;
3076 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
3077 const struct d3d10_depthstencil_state, entry)->desc;
3079 return memcmp(ka, kb, sizeof(*ka));
3082 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
3084 d3d10_rb_alloc,
3085 d3d10_rb_realloc,
3086 d3d10_rb_free,
3087 d3d10_depthstencil_state_compare,
3090 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
3092 const D3D10_RASTERIZER_DESC *ka = key;
3093 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
3095 return memcmp(ka, kb, sizeof(*ka));
3098 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
3100 d3d10_rb_alloc,
3101 d3d10_rb_realloc,
3102 d3d10_rb_free,
3103 d3d10_rasterizer_state_compare,
3106 HRESULT d3d10_device_init(struct d3d_device *device, void *outer_unknown)
3108 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
3109 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
3110 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
3111 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
3112 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
3113 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
3114 device->refcount = 1;
3115 /* COM aggregation always takes place */
3116 device->outer_unk = outer_unknown;
3118 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
3120 WARN("Failed to initialize blend state rbtree.\n");
3121 return E_FAIL;
3123 device->blend_factor[0] = 1.0f;
3124 device->blend_factor[1] = 1.0f;
3125 device->blend_factor[2] = 1.0f;
3126 device->blend_factor[3] = 1.0f;
3128 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
3130 WARN("Failed to initialize depthstencil state rbtree.\n");
3131 wine_rb_destroy(&device->blend_states, NULL, NULL);
3132 return E_FAIL;
3135 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
3137 WARN("Failed to initialize rasterizer state rbtree.\n");
3138 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3139 wine_rb_destroy(&device->blend_states, NULL, NULL);
3140 return E_FAIL;
3143 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
3145 WARN("Failed to initialize sampler state rbtree.\n");
3146 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3147 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3148 wine_rb_destroy(&device->blend_states, NULL, NULL);
3149 return E_FAIL;
3152 return S_OK;