d3d11: Rename d3d10_texture3d to d3d_texture3d.
[wine.git] / dlls / d3d11 / device.c
blob7aef1f7947b64e1e1d87ca3b5b958e4a13c4fc17
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 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 static void STDMETHODCALLTYPE d3d10_null_wined3d_object_destroyed(void *parent) {}
29 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
31 d3d10_null_wined3d_object_destroyed,
34 /* ID3D11Device methods */
36 static inline struct d3d_device *impl_from_ID3D11Device(ID3D11Device *iface)
38 return CONTAINING_RECORD(iface, struct d3d_device, ID3D11Device_iface);
41 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
43 struct d3d_device *device = impl_from_ID3D11Device(iface);
44 return IUnknown_QueryInterface(device->outer_unk, riid, out);
47 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
49 struct d3d_device *device = impl_from_ID3D11Device(iface);
50 return IUnknown_AddRef(device->outer_unk);
53 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
55 struct d3d_device *device = impl_from_ID3D11Device(iface);
56 return IUnknown_Release(device->outer_unk);
59 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
60 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
62 FIXME("iface %p, desc %p, data %p, buffer %p stub!\n", iface, desc, data, buffer);
64 return E_NOTIMPL;
67 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
68 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
70 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
72 return E_NOTIMPL;
75 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
76 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
78 struct d3d_device *device = impl_from_ID3D11Device(iface);
79 struct d3d_texture2d *object;
80 HRESULT hr;
82 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
84 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
85 return hr;
87 *texture = &object->ID3D11Texture2D_iface;
89 return S_OK;
92 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
93 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
95 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
97 return E_NOTIMPL;
100 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
101 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
103 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
105 return E_NOTIMPL;
108 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
109 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
111 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
113 return E_NOTIMPL;
116 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
117 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
119 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
121 return E_NOTIMPL;
124 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
125 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
127 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
129 return E_NOTIMPL;
132 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
133 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
134 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
136 FIXME("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
137 "input_layout %p stub!\n", iface, element_descs, element_count, shader_byte_code,
138 shader_byte_code_length, input_layout);
140 return E_NOTIMPL;
143 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
144 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
146 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
147 iface, byte_code, byte_code_length, class_linkage, shader);
149 return E_NOTIMPL;
152 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
153 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
155 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
156 iface, byte_code, byte_code_length, class_linkage, shader);
158 return E_NOTIMPL;
161 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
162 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
163 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
164 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
166 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
167 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
168 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
169 rasterized_stream, class_linkage, shader);
171 return E_NOTIMPL;
174 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
175 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
177 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
178 iface, byte_code, byte_code_length, class_linkage, shader);
180 return E_NOTIMPL;
183 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
184 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
186 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
187 iface, byte_code, byte_code_length, class_linkage, shader);
189 return E_NOTIMPL;
192 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
193 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
195 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
196 iface, byte_code, byte_code_length, class_linkage, shader);
198 return E_NOTIMPL;
201 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
202 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
204 FIXME("iface %p, byte_code %p, byte_code_lenghth %lu, class_linkage %p, shader %p stub!\n",
205 iface, byte_code, byte_code_length, class_linkage, shader);
207 return E_NOTIMPL;
210 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
211 ID3D11ClassLinkage **class_linkage)
213 FIXME("iface %p, class_linkage %p stub!\n", iface, class_linkage);
215 return E_NOTIMPL;
218 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
219 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
221 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
223 return E_NOTIMPL;
226 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
227 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
229 FIXME("iface %p, desc %p, depth_stencil_state %p stub!\n", iface, desc, depth_stencil_state);
231 return E_NOTIMPL;
234 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
235 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
237 FIXME("iface %p, desc %p, rasterizer_state %p stub!\n", iface, desc, rasterizer_state);
239 return E_NOTIMPL;
242 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
243 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
245 FIXME("iface %p, desc %p, sampler_state %p stub!\n", iface, desc, sampler_state);
247 return E_NOTIMPL;
250 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
251 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
253 FIXME("iface %p, desc %p, query %p stub!\n", iface, desc, query);
255 return E_NOTIMPL;
258 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
259 ID3D11Predicate **predicate)
261 FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
263 return E_NOTIMPL;
266 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
267 ID3D11Counter **counter)
269 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
271 return E_NOTIMPL;
274 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
275 ID3D11DeviceContext **context)
277 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
279 return E_NOTIMPL;
282 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
283 void **out)
285 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
287 return E_NOTIMPL;
290 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
291 UINT *format_support)
293 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
295 return E_NOTIMPL;
298 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
299 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
301 FIXME("iface %p, format %u, sample_count %u, quality_level_count %p stub!\n",
302 iface, format, sample_count, quality_level_count);
304 return E_NOTIMPL;
307 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
309 FIXME("iface %p, info %p stub!\n", iface, info);
312 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
313 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
314 char *units, UINT *units_length, char *description, UINT *description_length)
316 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
317 "units %p, units_length %p, description %p, description_length %p stub!\n",
318 iface, desc, type, active_counter_count, name, name_length,
319 units, units_length, description, description_length);
321 return E_NOTIMPL;
324 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
325 void *feature_support_data, UINT feature_support_data_size)
327 FIXME("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u stub!\n",
328 iface, feature, feature_support_data, feature_support_data_size);
330 return E_NOTIMPL;
333 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
334 UINT *data_size, void *data)
336 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
338 return E_NOTIMPL;
341 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
342 UINT data_size, const void *data)
344 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
346 return E_NOTIMPL;
349 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
350 const IUnknown *data_iface)
352 FIXME("iface %p, guid %s, data_iface %p stub!\n", iface, debugstr_guid(guid), data_iface);
354 return E_NOTIMPL;
357 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
359 FIXME("iface %p stub!\n", iface);
361 return D3D_FEATURE_LEVEL_10_0;
364 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
366 FIXME("iface %p stub!\n", iface);
368 return 0;
371 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
373 FIXME("iface %p stub!\n", iface);
375 return S_OK;
378 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
379 ID3D11DeviceContext **immediate_context)
381 FIXME("iface %p, immediate_context %p stub!\n", iface, immediate_context);
384 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
386 FIXME("iface %p, flags %#x stub!\n", iface, flags);
388 return E_NOTIMPL;
391 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
393 FIXME("iface %p stub!\n", iface);
395 return 0;
398 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
400 /* IUnknown methods */
401 d3d11_device_QueryInterface,
402 d3d11_device_AddRef,
403 d3d11_device_Release,
404 /* ID3D11Device methods */
405 d3d11_device_CreateBuffer,
406 d3d11_device_CreateTexture1D,
407 d3d11_device_CreateTexture2D,
408 d3d11_device_CreateTexture3D,
409 d3d11_device_CreateShaderResourceView,
410 d3d11_device_CreateUnorderedAccessView,
411 d3d11_device_CreateRenderTargetView,
412 d3d11_device_CreateDepthStencilView,
413 d3d11_device_CreateInputLayout,
414 d3d11_device_CreateVertexShader,
415 d3d11_device_CreateGeometryShader,
416 d3d11_device_CreateGeometryShaderWithStreamOutput,
417 d3d11_device_CreatePixelShader,
418 d3d11_device_CreateHullShader,
419 d3d11_device_CreateDomainShader,
420 d3d11_device_CreateComputeShader,
421 d3d11_device_CreateClassLinkage,
422 d3d11_device_CreateBlendState,
423 d3d11_device_CreateDepthStencilState,
424 d3d11_device_CreateRasterizerState,
425 d3d11_device_CreateSamplerState,
426 d3d11_device_CreateQuery,
427 d3d11_device_CreatePredicate,
428 d3d11_device_CreateCounter,
429 d3d11_device_CreateDeferredContext,
430 d3d11_device_OpenSharedResource,
431 d3d11_device_CheckFormatSupport,
432 d3d11_device_CheckMultisampleQualityLevels,
433 d3d11_device_CheckCounterInfo,
434 d3d11_device_CheckCounter,
435 d3d11_device_CheckFeatureSupport,
436 d3d11_device_GetPrivateData,
437 d3d11_device_SetPrivateData,
438 d3d11_device_SetPrivateDataInterface,
439 d3d11_device_GetFeatureLevel,
440 d3d11_device_GetCreationFlags,
441 d3d11_device_GetDeviceRemovedReason,
442 d3d11_device_GetImmediateContext,
443 d3d11_device_SetExceptionMode,
444 d3d11_device_GetExceptionMode,
447 /* Inner IUnknown methods */
449 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
451 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
454 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
456 struct d3d_device *device = impl_from_IUnknown(iface);
458 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
460 if (IsEqualGUID(riid, &IID_ID3D11Device)
461 || IsEqualGUID(riid, &IID_IUnknown))
463 *out = &device->ID3D11Device_iface;
465 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
466 || IsEqualGUID(riid, &IID_ID3D10Device))
468 *out = &device->ID3D10Device1_iface;
470 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
472 *out = &device->ID3D10Multithread_iface;
474 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
476 *out = &device->IWineDXGIDeviceParent_iface;
478 else
480 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
481 *out = NULL;
482 return E_NOINTERFACE;
485 IUnknown_AddRef((IUnknown *)*out);
486 return S_OK;
489 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
491 struct d3d_device *This = impl_from_IUnknown(iface);
492 ULONG refcount = InterlockedIncrement(&This->refcount);
494 TRACE("%p increasing refcount to %u\n", This, refcount);
496 return refcount;
499 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
501 struct d3d_device *device = impl_from_IUnknown(iface);
502 ULONG refcount = InterlockedDecrement(&device->refcount);
504 TRACE("%p decreasing refcount to %u.\n", device, refcount);
506 if (!refcount)
508 if (device->wined3d_device)
510 wined3d_mutex_lock();
511 wined3d_device_decref(device->wined3d_device);
512 wined3d_mutex_unlock();
514 wine_rb_destroy(&device->sampler_states, NULL, NULL);
515 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
516 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
517 wine_rb_destroy(&device->blend_states, NULL, NULL);
520 return refcount;
523 /* IUnknown methods */
525 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
526 void **ppv)
528 struct d3d_device *This = impl_from_ID3D10Device(iface);
529 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
532 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
534 struct d3d_device *This = impl_from_ID3D10Device(iface);
535 return IUnknown_AddRef(This->outer_unk);
538 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
540 struct d3d_device *This = impl_from_ID3D10Device(iface);
541 return IUnknown_Release(This->outer_unk);
544 /* ID3D10Device methods */
546 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
547 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
549 struct d3d_device *device = impl_from_ID3D10Device(iface);
550 unsigned int i;
552 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
553 iface, start_slot, buffer_count, buffers);
555 wined3d_mutex_lock();
556 for (i = 0; i < buffer_count; ++i)
558 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
560 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
561 buffer ? buffer->wined3d_buffer : NULL);
563 wined3d_mutex_unlock();
566 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
567 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
569 struct d3d_device *device = impl_from_ID3D10Device(iface);
570 unsigned int i;
572 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
573 iface, start_slot, view_count, views);
575 wined3d_mutex_lock();
576 for (i = 0; i < view_count; ++i)
578 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
580 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
581 view ? view->wined3d_view : NULL);
583 wined3d_mutex_unlock();
586 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
587 ID3D10PixelShader *shader)
589 struct d3d_device *This = impl_from_ID3D10Device(iface);
590 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
592 TRACE("iface %p, shader %p\n", iface, shader);
594 wined3d_mutex_lock();
595 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
596 wined3d_mutex_unlock();
599 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
600 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
602 struct d3d_device *device = impl_from_ID3D10Device(iface);
603 unsigned int i;
605 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
606 iface, start_slot, sampler_count, samplers);
608 wined3d_mutex_lock();
609 for (i = 0; i < sampler_count; ++i)
611 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
613 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
614 sampler ? sampler->wined3d_sampler : NULL);
616 wined3d_mutex_unlock();
619 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
620 ID3D10VertexShader *shader)
622 struct d3d_device *This = impl_from_ID3D10Device(iface);
623 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
625 TRACE("iface %p, shader %p\n", iface, shader);
627 wined3d_mutex_lock();
628 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
629 wined3d_mutex_unlock();
632 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
633 UINT start_index_location, INT base_vertex_location)
635 struct d3d_device *This = impl_from_ID3D10Device(iface);
637 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
638 iface, index_count, start_index_location, base_vertex_location);
640 wined3d_mutex_lock();
641 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
642 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
643 wined3d_mutex_unlock();
646 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
647 UINT start_vertex_location)
649 struct d3d_device *This = impl_from_ID3D10Device(iface);
651 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
652 iface, vertex_count, start_vertex_location);
654 wined3d_mutex_lock();
655 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
656 wined3d_mutex_unlock();
659 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
660 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
662 struct d3d_device *device = impl_from_ID3D10Device(iface);
663 unsigned int i;
665 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
666 iface, start_slot, buffer_count, buffers);
668 wined3d_mutex_lock();
669 for (i = 0; i < buffer_count; ++i)
671 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
673 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
674 buffer ? buffer->wined3d_buffer : NULL);
676 wined3d_mutex_unlock();
679 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
680 ID3D10InputLayout *input_layout)
682 struct d3d_device *This = impl_from_ID3D10Device(iface);
683 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
685 TRACE("iface %p, input_layout %p\n", iface, input_layout);
687 wined3d_mutex_lock();
688 wined3d_device_set_vertex_declaration(This->wined3d_device,
689 layout ? layout->wined3d_decl : NULL);
690 wined3d_mutex_unlock();
693 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
694 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
696 struct d3d_device *This = impl_from_ID3D10Device(iface);
697 unsigned int i;
699 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
700 iface, start_slot, buffer_count, buffers, strides, offsets);
702 wined3d_mutex_lock();
703 for (i = 0; i < buffer_count; ++i)
705 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
707 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
708 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
710 wined3d_mutex_unlock();
713 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
714 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
716 struct d3d_device *This = impl_from_ID3D10Device(iface);
717 struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
719 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
720 iface, buffer, debug_dxgi_format(format), offset);
722 wined3d_mutex_lock();
723 wined3d_device_set_index_buffer(This->wined3d_device,
724 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
725 wined3dformat_from_dxgi_format(format));
726 wined3d_mutex_unlock();
727 if (offset) FIXME("offset %u not supported.\n", offset);
730 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
731 UINT instance_index_count, UINT instance_count, UINT start_index_location,
732 INT base_vertex_location, UINT start_instance_location)
734 struct d3d_device *device = impl_from_ID3D10Device(iface);
736 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
737 "base_vertex_location %d, start_instance_location %u.\n",
738 iface, instance_index_count, instance_count, start_index_location,
739 base_vertex_location, start_instance_location);
741 wined3d_mutex_lock();
742 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
743 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
744 instance_index_count, start_instance_location, instance_count);
745 wined3d_mutex_unlock();
748 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
749 UINT instance_vertex_count, UINT instance_count,
750 UINT start_vertex_location, UINT start_instance_location)
752 struct d3d_device *device = impl_from_ID3D10Device(iface);
754 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
755 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
756 start_vertex_location, start_instance_location);
758 wined3d_mutex_lock();
759 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
760 instance_vertex_count, start_instance_location, instance_count);
761 wined3d_mutex_unlock();
764 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
765 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
767 struct d3d_device *device = impl_from_ID3D10Device(iface);
768 unsigned int i;
770 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
771 iface, start_slot, buffer_count, buffers);
773 wined3d_mutex_lock();
774 for (i = 0; i < buffer_count; ++i)
776 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
778 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
779 buffer ? buffer->wined3d_buffer : NULL);
781 wined3d_mutex_unlock();
784 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
786 struct d3d_device *device = impl_from_ID3D10Device(iface);
787 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
789 TRACE("iface %p, shader %p.\n", iface, shader);
791 wined3d_mutex_lock();
792 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
793 wined3d_mutex_unlock();
796 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
797 D3D10_PRIMITIVE_TOPOLOGY topology)
799 struct d3d_device *This = impl_from_ID3D10Device(iface);
801 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
803 wined3d_mutex_lock();
804 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
805 wined3d_mutex_unlock();
808 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
809 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
811 struct d3d_device *device = impl_from_ID3D10Device(iface);
812 unsigned int i;
814 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
815 iface, start_slot, view_count, views);
817 wined3d_mutex_lock();
818 for (i = 0; i < view_count; ++i)
820 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
822 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
823 view ? view->wined3d_view : NULL);
825 wined3d_mutex_unlock();
828 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
829 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
831 struct d3d_device *device = impl_from_ID3D10Device(iface);
832 unsigned int i;
834 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
835 iface, start_slot, sampler_count, samplers);
837 wined3d_mutex_lock();
838 for (i = 0; i < sampler_count; ++i)
840 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
842 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
843 sampler ? sampler->wined3d_sampler : NULL);
845 wined3d_mutex_unlock();
848 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
850 struct d3d_device *device = impl_from_ID3D10Device(iface);
851 struct d3d10_query *query;
853 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
855 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
856 wined3d_mutex_lock();
857 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
858 wined3d_mutex_unlock();
861 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
862 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
864 struct d3d_device *device = impl_from_ID3D10Device(iface);
865 unsigned int i;
867 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
868 iface, start_slot, view_count, views);
870 wined3d_mutex_lock();
871 for (i = 0; i < view_count; ++i)
873 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
875 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
876 view ? view->wined3d_view : NULL);
878 wined3d_mutex_unlock();
881 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
882 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
884 struct d3d_device *device = impl_from_ID3D10Device(iface);
885 unsigned int i;
887 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
888 iface, start_slot, sampler_count, samplers);
890 wined3d_mutex_lock();
891 for (i = 0; i < sampler_count; ++i)
893 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
895 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
896 sampler ? sampler->wined3d_sampler : NULL);
898 wined3d_mutex_unlock();
901 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
902 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
903 ID3D10DepthStencilView *depth_stencil_view)
905 struct d3d_device *device = impl_from_ID3D10Device(iface);
906 struct d3d10_depthstencil_view *dsv;
907 unsigned int i;
909 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
910 iface, render_target_view_count, render_target_views, depth_stencil_view);
912 wined3d_mutex_lock();
913 for (i = 0; i < render_target_view_count; ++i)
915 struct d3d10_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
917 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
918 rtv ? rtv->wined3d_view : NULL, FALSE);
920 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
922 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
925 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
926 wined3d_device_set_depth_stencil_view(device->wined3d_device,
927 dsv ? dsv->wined3d_view : NULL);
928 wined3d_mutex_unlock();
931 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
932 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
934 struct d3d_device *device = impl_from_ID3D10Device(iface);
935 const D3D10_BLEND_DESC *desc;
937 TRACE("iface %p, blend_state %p, blend_factor {%.8e %.8e %.8e %.8e}, sample_mask 0x%08x.\n",
938 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
940 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
941 FIXME("Ignoring blend factor {%.8e %.8e %.8e %.8e}.\n",
942 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
943 wined3d_mutex_lock();
944 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
945 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
946 if (!(device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state)))
948 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
949 wined3d_device_set_render_state(device->wined3d_device,
950 WINED3D_RS_COLORWRITEENABLE, D3D10_COLOR_WRITE_ENABLE_ALL);
951 wined3d_device_set_render_state(device->wined3d_device,
952 WINED3D_RS_COLORWRITEENABLE1, D3D10_COLOR_WRITE_ENABLE_ALL);
953 wined3d_device_set_render_state(device->wined3d_device,
954 WINED3D_RS_COLORWRITEENABLE2, D3D10_COLOR_WRITE_ENABLE_ALL);
955 wined3d_device_set_render_state(device->wined3d_device,
956 WINED3D_RS_COLORWRITEENABLE3, D3D10_COLOR_WRITE_ENABLE_ALL);
957 wined3d_mutex_unlock();
958 return;
961 desc = &device->blend_state->desc;
962 /* glSampleCoverage() */
963 if (desc->AlphaToCoverageEnable)
964 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
965 /* glEnableIndexedEXT(GL_BLEND, ...) */
966 FIXME("Per-rendertarget blend enable not implemented.\n");
967 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, desc->BlendEnable[0]);
968 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->SrcBlend);
969 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->DestBlend);
970 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->BlendOp);
971 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
972 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, desc->SrcBlendAlpha);
973 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, desc->DestBlendAlpha);
974 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, desc->BlendOpAlpha);
975 FIXME("Color mask > 3 not implemented.\n");
976 wined3d_device_set_render_state(device->wined3d_device,
977 WINED3D_RS_COLORWRITEENABLE, desc->RenderTargetWriteMask[0]);
978 wined3d_device_set_render_state(device->wined3d_device,
979 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTargetWriteMask[1]);
980 wined3d_device_set_render_state(device->wined3d_device,
981 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTargetWriteMask[2]);
982 wined3d_device_set_render_state(device->wined3d_device,
983 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTargetWriteMask[3]);
984 wined3d_mutex_unlock();
987 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
988 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
990 struct d3d_device *device = impl_from_ID3D10Device(iface);
992 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
993 iface, depth_stencil_state, stencil_ref);
995 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
996 device->stencil_ref = stencil_ref;
999 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
1000 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
1002 struct d3d_device *device = impl_from_ID3D10Device(iface);
1003 unsigned int count, i;
1005 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
1007 count = min(target_count, 4);
1008 wined3d_mutex_lock();
1009 for (i = 0; i < count; ++i)
1011 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
1013 wined3d_device_set_stream_output(device->wined3d_device, i,
1014 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
1017 for (i = count; i < 4; ++i)
1019 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1021 wined3d_mutex_unlock();
1024 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
1026 FIXME("iface %p stub!\n", iface);
1029 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
1031 struct d3d_device *device = impl_from_ID3D10Device(iface);
1032 const D3D10_RASTERIZER_DESC *desc;
1034 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1036 wined3d_mutex_lock();
1037 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
1039 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
1040 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
1041 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
1042 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1043 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
1044 wined3d_mutex_unlock();
1045 return;
1048 desc = &device->rasterizer_state->desc;
1049 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
1050 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
1051 /* glFrontFace() */
1052 if (desc->FrontCounterClockwise)
1053 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
1054 /* OpenGL style depth bias. */
1055 if (desc->DepthBias || desc->SlopeScaledDepthBias)
1056 FIXME("Ignoring depth bias.\n");
1057 /* GL_DEPTH_CLAMP */
1058 if (!desc->DepthClipEnable)
1059 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
1060 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
1061 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1062 wined3d_device_set_render_state(device->wined3d_device,
1063 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
1064 wined3d_mutex_unlock();
1067 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
1068 UINT viewport_count, const D3D10_VIEWPORT *viewports)
1070 struct d3d_device *device = impl_from_ID3D10Device(iface);
1071 struct wined3d_viewport wined3d_vp;
1073 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1075 if (viewport_count > 1)
1076 FIXME("Multiple viewports not implemented.\n");
1078 if (!viewport_count)
1079 return;
1081 wined3d_vp.x = viewports[0].TopLeftX;
1082 wined3d_vp.y = viewports[0].TopLeftY;
1083 wined3d_vp.width = viewports[0].Width;
1084 wined3d_vp.height = viewports[0].Height;
1085 wined3d_vp.min_z = viewports[0].MinDepth;
1086 wined3d_vp.max_z = viewports[0].MaxDepth;
1088 wined3d_mutex_lock();
1089 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
1090 wined3d_mutex_unlock();
1093 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
1094 UINT rect_count, const D3D10_RECT *rects)
1096 struct d3d_device *device = impl_from_ID3D10Device(iface);
1098 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1100 if (rect_count > 1)
1101 FIXME("Multiple scissor rects not implemented.\n");
1103 if (!rect_count)
1104 return;
1106 wined3d_mutex_lock();
1107 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
1108 wined3d_mutex_unlock();
1111 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
1112 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1113 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
1115 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1116 struct d3d_device *device = impl_from_ID3D10Device(iface);
1117 struct wined3d_box wined3d_src_box;
1119 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1120 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1121 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1122 src_resource, src_subresource_idx, src_box);
1124 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
1125 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
1126 wined3d_src_box.left = src_box->left;
1127 wined3d_src_box.top = src_box->top;
1128 wined3d_src_box.front = src_box->front;
1129 wined3d_src_box.right = src_box->right;
1130 wined3d_src_box.bottom = src_box->bottom;
1131 wined3d_src_box.back = src_box->back;
1132 wined3d_mutex_lock();
1133 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
1134 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, &wined3d_src_box);
1135 wined3d_mutex_unlock();
1138 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
1139 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
1141 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1142 struct d3d_device *device = impl_from_ID3D10Device(iface);
1144 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1146 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
1147 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
1148 wined3d_mutex_lock();
1149 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1150 wined3d_mutex_unlock();
1153 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
1154 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
1155 const void *data, UINT row_pitch, UINT depth_pitch)
1157 struct d3d_device *device = impl_from_ID3D10Device(iface);
1158 struct wined3d_resource *wined3d_resource;
1159 struct wined3d_box wined3d_box;
1161 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1162 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1164 if (box)
1166 wined3d_box.left = box->left;
1167 wined3d_box.top = box->top;
1168 wined3d_box.front = box->front;
1169 wined3d_box.right = box->right;
1170 wined3d_box.bottom = box->bottom;
1171 wined3d_box.back = box->back;
1174 wined3d_resource = wined3d_resource_from_resource(resource);
1175 wined3d_mutex_lock();
1176 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1177 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1178 wined3d_mutex_unlock();
1181 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
1182 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
1184 struct d3d_device *device = impl_from_ID3D10Device(iface);
1185 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
1186 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1187 HRESULT hr;
1189 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
1190 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
1192 wined3d_mutex_lock();
1193 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
1194 ERR("Failed to clear view, hr %#x.\n", hr);
1195 wined3d_mutex_unlock();
1198 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
1199 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1201 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
1202 iface, depth_stencil_view, flags, depth, stencil);
1205 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
1206 ID3D10ShaderResourceView *shader_resource_view)
1208 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
1211 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
1212 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
1213 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
1215 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
1216 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
1217 iface, dst_resource, dst_subresource_idx,
1218 src_resource, src_subresource_idx, debug_dxgi_format(format));
1221 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
1222 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1224 struct d3d_device *device = impl_from_ID3D10Device(iface);
1225 unsigned int i;
1227 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1228 iface, start_slot, buffer_count, buffers);
1230 wined3d_mutex_lock();
1231 for (i = 0; i < buffer_count; ++i)
1233 struct wined3d_buffer *wined3d_buffer;
1234 struct d3d10_buffer *buffer_impl;
1236 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1238 buffers[i] = NULL;
1239 continue;
1242 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1243 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1244 ID3D10Buffer_AddRef(buffers[i]);
1246 wined3d_mutex_unlock();
1249 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
1250 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1252 struct d3d_device *device = impl_from_ID3D10Device(iface);
1253 unsigned int i;
1255 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1256 iface, start_slot, view_count, views);
1258 wined3d_mutex_lock();
1259 for (i = 0; i < view_count; ++i)
1261 struct wined3d_shader_resource_view *wined3d_view;
1262 struct d3d10_shader_resource_view *view_impl;
1264 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1266 views[i] = NULL;
1267 continue;
1270 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1271 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1272 ID3D10ShaderResourceView_AddRef(views[i]);
1274 wined3d_mutex_unlock();
1277 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
1279 struct d3d_device *device = impl_from_ID3D10Device(iface);
1280 struct d3d10_pixel_shader *shader_impl;
1281 struct wined3d_shader *wined3d_shader;
1283 TRACE("iface %p, shader %p.\n", iface, shader);
1285 wined3d_mutex_lock();
1286 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1288 wined3d_mutex_unlock();
1289 *shader = NULL;
1290 return;
1293 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1294 wined3d_mutex_unlock();
1295 *shader = &shader_impl->ID3D10PixelShader_iface;
1296 ID3D10PixelShader_AddRef(*shader);
1299 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
1300 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1302 struct d3d_device *device = impl_from_ID3D10Device(iface);
1303 unsigned int i;
1305 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1306 iface, start_slot, sampler_count, samplers);
1308 wined3d_mutex_lock();
1309 for (i = 0; i < sampler_count; ++i)
1311 struct d3d10_sampler_state *sampler_impl;
1312 struct wined3d_sampler *wined3d_sampler;
1314 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1316 samplers[i] = NULL;
1317 continue;
1320 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1321 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1322 ID3D10SamplerState_AddRef(samplers[i]);
1324 wined3d_mutex_unlock();
1327 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
1329 struct d3d_device *device = impl_from_ID3D10Device(iface);
1330 struct d3d10_vertex_shader *shader_impl;
1331 struct wined3d_shader *wined3d_shader;
1333 TRACE("iface %p, shader %p.\n", iface, shader);
1335 wined3d_mutex_lock();
1336 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1338 wined3d_mutex_unlock();
1339 *shader = NULL;
1340 return;
1343 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1344 wined3d_mutex_unlock();
1345 *shader = &shader_impl->ID3D10VertexShader_iface;
1346 ID3D10VertexShader_AddRef(*shader);
1349 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
1350 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1352 struct d3d_device *device = impl_from_ID3D10Device(iface);
1353 unsigned int i;
1355 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1356 iface, start_slot, buffer_count, buffers);
1358 wined3d_mutex_lock();
1359 for (i = 0; i < buffer_count; ++i)
1361 struct wined3d_buffer *wined3d_buffer;
1362 struct d3d10_buffer *buffer_impl;
1364 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1366 buffers[i] = NULL;
1367 continue;
1370 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1371 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1372 ID3D10Buffer_AddRef(buffers[i]);
1374 wined3d_mutex_unlock();
1377 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
1379 struct d3d_device *device = impl_from_ID3D10Device(iface);
1380 struct wined3d_vertex_declaration *wined3d_declaration;
1381 struct d3d10_input_layout *input_layout_impl;
1383 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1385 wined3d_mutex_lock();
1386 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1388 wined3d_mutex_unlock();
1389 *input_layout = NULL;
1390 return;
1393 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1394 wined3d_mutex_unlock();
1395 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
1396 ID3D10InputLayout_AddRef(*input_layout);
1399 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
1400 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
1402 struct d3d_device *device = impl_from_ID3D10Device(iface);
1403 unsigned int i;
1405 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1406 iface, start_slot, buffer_count, buffers, strides, offsets);
1408 wined3d_mutex_lock();
1409 for (i = 0; i < buffer_count; ++i)
1411 struct wined3d_buffer *wined3d_buffer;
1412 struct d3d10_buffer *buffer_impl;
1414 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1415 &wined3d_buffer, &offsets[i], &strides[i])))
1416 ERR("Failed to get vertex buffer.\n");
1418 if (!wined3d_buffer)
1420 buffers[i] = NULL;
1421 continue;
1424 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1425 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1426 ID3D10Buffer_AddRef(buffers[i]);
1428 wined3d_mutex_unlock();
1431 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
1432 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1434 struct d3d_device *device = impl_from_ID3D10Device(iface);
1435 enum wined3d_format_id wined3d_format;
1436 struct wined3d_buffer *wined3d_buffer;
1437 struct d3d10_buffer *buffer_impl;
1439 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1441 wined3d_mutex_lock();
1442 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
1443 *format = dxgi_format_from_wined3dformat(wined3d_format);
1444 *offset = 0; /* FIXME */
1445 if (!wined3d_buffer)
1447 wined3d_mutex_unlock();
1448 *buffer = NULL;
1449 return;
1452 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1453 wined3d_mutex_unlock();
1454 *buffer = &buffer_impl->ID3D10Buffer_iface;
1455 ID3D10Buffer_AddRef(*buffer);
1458 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
1459 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1461 struct d3d_device *device = impl_from_ID3D10Device(iface);
1462 unsigned int i;
1464 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1465 iface, start_slot, buffer_count, buffers);
1467 wined3d_mutex_lock();
1468 for (i = 0; i < buffer_count; ++i)
1470 struct wined3d_buffer *wined3d_buffer;
1471 struct d3d10_buffer *buffer_impl;
1473 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1475 buffers[i] = NULL;
1476 continue;
1479 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1480 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1481 ID3D10Buffer_AddRef(buffers[i]);
1483 wined3d_mutex_unlock();
1486 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
1488 struct d3d_device *device = impl_from_ID3D10Device(iface);
1489 struct d3d10_geometry_shader *shader_impl;
1490 struct wined3d_shader *wined3d_shader;
1492 TRACE("iface %p, shader %p.\n", iface, shader);
1494 wined3d_mutex_lock();
1495 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1497 wined3d_mutex_unlock();
1498 *shader = NULL;
1499 return;
1502 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1503 wined3d_mutex_unlock();
1504 *shader = &shader_impl->ID3D10GeometryShader_iface;
1505 ID3D10GeometryShader_AddRef(*shader);
1508 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
1509 D3D10_PRIMITIVE_TOPOLOGY *topology)
1511 struct d3d_device *This = impl_from_ID3D10Device(iface);
1513 TRACE("iface %p, topology %p\n", iface, topology);
1515 wined3d_mutex_lock();
1516 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
1517 wined3d_mutex_unlock();
1520 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
1521 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1523 struct d3d_device *device = impl_from_ID3D10Device(iface);
1524 unsigned int i;
1526 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1527 iface, start_slot, view_count, views);
1529 wined3d_mutex_lock();
1530 for (i = 0; i < view_count; ++i)
1532 struct wined3d_shader_resource_view *wined3d_view;
1533 struct d3d10_shader_resource_view *view_impl;
1535 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1537 views[i] = NULL;
1538 continue;
1541 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1542 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1543 ID3D10ShaderResourceView_AddRef(views[i]);
1545 wined3d_mutex_unlock();
1548 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
1549 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1551 struct d3d_device *device = impl_from_ID3D10Device(iface);
1552 unsigned int i;
1554 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1555 iface, start_slot, sampler_count, samplers);
1557 wined3d_mutex_lock();
1558 for (i = 0; i < sampler_count; ++i)
1560 struct d3d10_sampler_state *sampler_impl;
1561 struct wined3d_sampler *wined3d_sampler;
1563 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1565 samplers[i] = NULL;
1566 continue;
1569 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1570 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1571 ID3D10SamplerState_AddRef(samplers[i]);
1573 wined3d_mutex_unlock();
1576 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
1577 ID3D10Predicate **predicate, BOOL *value)
1579 struct d3d_device *device = impl_from_ID3D10Device(iface);
1580 struct wined3d_query *wined3d_predicate;
1581 struct d3d10_query *predicate_impl;
1583 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1585 wined3d_mutex_lock();
1586 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1588 wined3d_mutex_unlock();
1589 *predicate = NULL;
1590 return;
1593 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1594 wined3d_mutex_unlock();
1595 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
1596 ID3D10Predicate_AddRef(*predicate);
1599 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
1600 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1602 struct d3d_device *device = impl_from_ID3D10Device(iface);
1603 unsigned int i;
1605 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1606 iface, start_slot, view_count, views);
1608 wined3d_mutex_lock();
1609 for (i = 0; i < view_count; ++i)
1611 struct wined3d_shader_resource_view *wined3d_view;
1612 struct d3d10_shader_resource_view *view_impl;
1614 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1616 views[i] = NULL;
1617 continue;
1620 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1621 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1622 ID3D10ShaderResourceView_AddRef(views[i]);
1624 wined3d_mutex_unlock();
1627 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1628 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1630 struct d3d_device *device = impl_from_ID3D10Device(iface);
1631 unsigned int i;
1633 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1634 iface, start_slot, sampler_count, samplers);
1636 wined3d_mutex_lock();
1637 for (i = 0; i < sampler_count; ++i)
1639 struct d3d10_sampler_state *sampler_impl;
1640 struct wined3d_sampler *wined3d_sampler;
1642 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1644 samplers[i] = NULL;
1645 continue;
1648 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1649 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1650 ID3D10SamplerState_AddRef(samplers[i]);
1652 wined3d_mutex_unlock();
1655 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1656 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1658 struct d3d_device *device = impl_from_ID3D10Device(iface);
1659 struct wined3d_rendertarget_view *wined3d_view;
1661 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1662 iface, view_count, render_target_views, depth_stencil_view);
1664 wined3d_mutex_lock();
1665 if (render_target_views)
1667 struct d3d10_rendertarget_view *view_impl;
1668 unsigned int i;
1670 for (i = 0; i < view_count; ++i)
1672 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1673 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1675 render_target_views[i] = NULL;
1676 continue;
1679 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1680 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1684 if (depth_stencil_view)
1686 struct d3d10_depthstencil_view *view_impl;
1688 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1689 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1691 *depth_stencil_view = NULL;
1693 else
1695 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1696 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1699 wined3d_mutex_unlock();
1702 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1703 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1705 struct d3d_device *device = impl_from_ID3D10Device(iface);
1707 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1708 iface, blend_state, blend_factor, sample_mask);
1710 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1711 ID3D10BlendState_AddRef(*blend_state);
1712 wined3d_mutex_lock();
1713 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1714 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1715 wined3d_mutex_unlock();
1718 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1719 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1721 struct d3d_device *device = impl_from_ID3D10Device(iface);
1723 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1724 iface, depth_stencil_state, stencil_ref);
1726 if ((*depth_stencil_state = device->depth_stencil_state
1727 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1728 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1729 *stencil_ref = device->stencil_ref;
1732 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1733 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1735 struct d3d_device *device = impl_from_ID3D10Device(iface);
1736 unsigned int i;
1738 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1739 iface, buffer_count, buffers, offsets);
1741 wined3d_mutex_lock();
1742 for (i = 0; i < buffer_count; ++i)
1744 struct wined3d_buffer *wined3d_buffer;
1745 struct d3d10_buffer *buffer_impl;
1747 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1749 buffers[i] = NULL;
1750 continue;
1753 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1754 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1755 ID3D10Buffer_AddRef(buffers[i]);
1757 wined3d_mutex_unlock();
1760 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1762 struct d3d_device *device = impl_from_ID3D10Device(iface);
1764 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1766 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1767 ID3D10RasterizerState_AddRef(*rasterizer_state);
1770 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1771 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1773 struct d3d_device *device = impl_from_ID3D10Device(iface);
1774 struct wined3d_viewport wined3d_vp;
1776 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1778 if (!viewports)
1780 *viewport_count = 1;
1781 return;
1784 if (!*viewport_count)
1785 return;
1787 wined3d_mutex_lock();
1788 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1789 wined3d_mutex_unlock();
1791 viewports[0].TopLeftX = wined3d_vp.x;
1792 viewports[0].TopLeftY = wined3d_vp.y;
1793 viewports[0].Width = wined3d_vp.width;
1794 viewports[0].Height = wined3d_vp.height;
1795 viewports[0].MinDepth = wined3d_vp.min_z;
1796 viewports[0].MaxDepth = wined3d_vp.max_z;
1798 if (*viewport_count > 1)
1799 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1802 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1804 struct d3d_device *device = impl_from_ID3D10Device(iface);
1806 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1808 if (!rects)
1810 *rect_count = 1;
1811 return;
1814 if (!*rect_count)
1815 return;
1817 wined3d_mutex_lock();
1818 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1819 wined3d_mutex_unlock();
1820 if (*rect_count > 1)
1821 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1824 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1826 TRACE("iface %p.\n", iface);
1828 /* In the current implementation the device is never removed, so we can
1829 * just return S_OK here. */
1831 return S_OK;
1834 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1836 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1838 return E_NOTIMPL;
1841 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1843 FIXME("iface %p stub!\n", iface);
1845 return 0;
1848 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1849 REFGUID guid, UINT *data_size, void *data)
1851 IDXGIDevice *dxgi_device;
1852 HRESULT hr;
1854 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1855 iface, debugstr_guid(guid), data_size, data);
1857 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1858 return hr;
1859 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
1860 IDXGIDevice_Release(dxgi_device);
1862 return hr;
1865 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1866 REFGUID guid, UINT data_size, const void *data)
1868 IDXGIDevice *dxgi_device;
1869 HRESULT hr;
1871 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1872 iface, debugstr_guid(guid), data_size, data);
1874 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1875 return hr;
1876 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
1877 IDXGIDevice_Release(dxgi_device);
1879 return hr;
1882 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1883 REFGUID guid, const IUnknown *data)
1885 IDXGIDevice *dxgi_device;
1886 HRESULT hr;
1888 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1890 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1891 return hr;
1892 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
1893 IDXGIDevice_Release(dxgi_device);
1895 return hr;
1898 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1900 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1901 struct d3d_device *device = impl_from_ID3D10Device(iface);
1902 unsigned int i;
1904 TRACE("iface %p.\n", iface);
1906 wined3d_mutex_lock();
1907 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
1908 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1910 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
1912 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1914 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
1916 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1918 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
1920 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
1921 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1923 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
1925 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1927 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
1929 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1931 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
1933 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
1934 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1936 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
1938 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1940 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
1942 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1944 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
1946 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1948 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
1950 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
1951 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
1952 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
1953 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1955 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
1957 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
1958 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
1959 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
1960 ID3D10Device1_RSSetViewports(iface, 0, NULL);
1961 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
1962 ID3D10Device1_RSSetState(iface, NULL);
1963 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1965 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1967 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
1968 wined3d_mutex_unlock();
1971 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1973 FIXME("iface %p stub!\n", iface);
1976 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1977 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1979 struct d3d_device *This = impl_from_ID3D10Device(iface);
1980 struct d3d10_buffer *object;
1981 HRESULT hr;
1983 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
1985 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1986 if (!object)
1987 return E_OUTOFMEMORY;
1989 hr = d3d10_buffer_init(object, This, desc, data);
1990 if (FAILED(hr))
1992 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1993 HeapFree(GetProcessHeap(), 0, object);
1994 return hr;
1997 *buffer = &object->ID3D10Buffer_iface;
1999 TRACE("Created ID3D10Buffer %p\n", object);
2001 return S_OK;
2004 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
2005 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
2007 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2009 return E_NOTIMPL;
2012 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
2013 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2014 ID3D10Texture2D **texture)
2016 struct d3d_device *device = impl_from_ID3D10Device(iface);
2017 D3D11_TEXTURE2D_DESC d3d11_desc;
2018 struct d3d_texture2d *object;
2019 HRESULT hr;
2021 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2023 d3d11_desc.Width = desc->Width;
2024 d3d11_desc.Height = desc->Height;
2025 d3d11_desc.MipLevels = desc->MipLevels;
2026 d3d11_desc.ArraySize = desc->ArraySize;
2027 d3d11_desc.Format = desc->Format;
2028 d3d11_desc.SampleDesc = desc->SampleDesc;
2029 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2030 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2031 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2032 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2034 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2035 return hr;
2037 *texture = &object->ID3D10Texture2D_iface;
2039 return S_OK;
2042 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
2043 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2044 ID3D10Texture3D **texture)
2046 struct d3d_device *device = impl_from_ID3D10Device(iface);
2047 struct d3d_texture3d *object;
2048 HRESULT hr;
2050 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2052 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2053 if (!object)
2054 return E_OUTOFMEMORY;
2056 if (FAILED(hr = d3d_texture3d_init(object, device, desc, data)))
2058 WARN("Failed to initialize texture, hr %#x.\n", hr);
2059 HeapFree(GetProcessHeap(), 0, object);
2060 return hr;
2063 TRACE("Created 3D texture %p.\n", object);
2064 *texture = &object->ID3D10Texture3D_iface;
2066 return S_OK;
2069 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
2070 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
2072 struct d3d_device *device = impl_from_ID3D10Device(iface);
2073 struct d3d10_shader_resource_view *object;
2074 HRESULT hr;
2076 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2078 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2079 return E_OUTOFMEMORY;
2081 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
2083 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
2084 HeapFree(GetProcessHeap(), 0, object);
2085 return hr;
2088 TRACE("Created shader resource view %p.\n", object);
2089 *view = &object->ID3D10ShaderResourceView_iface;
2091 return S_OK;
2094 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
2095 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
2097 struct d3d_device *device = impl_from_ID3D10Device(iface);
2098 struct d3d10_rendertarget_view *object;
2099 HRESULT hr;
2101 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2103 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2104 return E_OUTOFMEMORY;
2106 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
2108 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
2109 HeapFree(GetProcessHeap(), 0, object);
2110 return hr;
2113 TRACE("Created rendertarget view %p.\n", object);
2114 *view = &object->ID3D10RenderTargetView_iface;
2116 return S_OK;
2119 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
2120 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
2122 struct d3d_device *device = impl_from_ID3D10Device(iface);
2123 struct d3d10_depthstencil_view *object;
2124 HRESULT hr;
2126 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2128 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2129 return E_OUTOFMEMORY;
2131 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
2133 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
2134 HeapFree(GetProcessHeap(), 0, object);
2135 return hr;
2138 TRACE("Created depthstencil view %p.\n", object);
2139 *view = &object->ID3D10DepthStencilView_iface;
2141 return S_OK;
2144 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
2145 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
2146 const void *shader_byte_code, SIZE_T shader_byte_code_length,
2147 ID3D10InputLayout **input_layout)
2149 struct d3d_device *This = impl_from_ID3D10Device(iface);
2150 struct d3d10_input_layout *object;
2151 HRESULT hr;
2153 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
2154 "shader_byte_code_length %lu, input_layout %p\n",
2155 iface, element_descs, element_count, shader_byte_code,
2156 shader_byte_code_length, input_layout);
2158 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2159 if (!object)
2160 return E_OUTOFMEMORY;
2162 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
2163 shader_byte_code, shader_byte_code_length);
2164 if (FAILED(hr))
2166 WARN("Failed to initialize input layout, hr %#x.\n", hr);
2167 HeapFree(GetProcessHeap(), 0, object);
2168 return hr;
2171 TRACE("Created input layout %p.\n", object);
2172 *input_layout = &object->ID3D10InputLayout_iface;
2174 return S_OK;
2177 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
2178 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
2180 struct d3d_device *This = impl_from_ID3D10Device(iface);
2181 struct d3d10_vertex_shader *object;
2182 HRESULT hr;
2184 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
2185 iface, byte_code, byte_code_length, shader);
2187 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2188 if (!object)
2189 return E_OUTOFMEMORY;
2191 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
2192 if (FAILED(hr))
2194 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2195 HeapFree(GetProcessHeap(), 0, object);
2196 return hr;
2199 TRACE("Created vertex shader %p.\n", object);
2200 *shader = &object->ID3D10VertexShader_iface;
2202 return S_OK;
2205 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
2206 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
2208 struct d3d_device *This = impl_from_ID3D10Device(iface);
2209 struct d3d10_geometry_shader *object;
2210 HRESULT hr;
2212 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
2213 iface, byte_code, byte_code_length, shader);
2215 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2216 if (!object)
2217 return E_OUTOFMEMORY;
2219 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
2220 if (FAILED(hr))
2222 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
2223 HeapFree(GetProcessHeap(), 0, object);
2224 return hr;
2227 TRACE("Created geometry shader %p.\n", object);
2228 *shader = &object->ID3D10GeometryShader_iface;
2230 return S_OK;
2233 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
2234 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
2235 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
2237 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
2238 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
2239 iface, byte_code, byte_code_length, output_stream_decls,
2240 output_stream_decl_count, output_stream_stride, shader);
2242 return E_NOTIMPL;
2245 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
2246 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
2248 struct d3d_device *This = impl_from_ID3D10Device(iface);
2249 struct d3d10_pixel_shader *object;
2250 HRESULT hr;
2252 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
2253 iface, byte_code, byte_code_length, shader);
2255 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2256 if (!object)
2257 return E_OUTOFMEMORY;
2259 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
2260 if (FAILED(hr))
2262 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2263 HeapFree(GetProcessHeap(), 0, object);
2264 return hr;
2267 TRACE("Created pixel shader %p.\n", object);
2268 *shader = &object->ID3D10PixelShader_iface;
2270 return S_OK;
2273 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
2274 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
2276 struct d3d_device *device = impl_from_ID3D10Device(iface);
2277 struct d3d10_blend_state *object;
2278 struct wine_rb_entry *entry;
2279 HRESULT hr;
2281 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2283 if (!desc)
2284 return E_INVALIDARG;
2286 wined3d_mutex_lock();
2287 if ((entry = wine_rb_get(&device->blend_states, desc)))
2289 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
2291 TRACE("Returning existing blend state %p.\n", object);
2292 *blend_state = &object->ID3D10BlendState_iface;
2293 ID3D10BlendState_AddRef(*blend_state);
2294 wined3d_mutex_unlock();
2296 return S_OK;
2298 wined3d_mutex_unlock();
2300 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2301 if (!object)
2302 return E_OUTOFMEMORY;
2304 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
2306 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2307 HeapFree(GetProcessHeap(), 0, object);
2308 return hr;
2311 TRACE("Created blend state %p.\n", object);
2312 *blend_state = &object->ID3D10BlendState_iface;
2314 return S_OK;
2317 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
2318 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
2320 struct d3d_device *device = impl_from_ID3D10Device(iface);
2321 struct d3d10_depthstencil_state *object;
2322 D3D10_DEPTH_STENCIL_DESC tmp_desc;
2323 struct wine_rb_entry *entry;
2324 HRESULT hr;
2326 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2328 if (!desc)
2329 return E_INVALIDARG;
2331 /* D3D10_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
2332 * it as a key in the rbtree. */
2333 memset(&tmp_desc, 0, sizeof(tmp_desc));
2334 tmp_desc.DepthEnable = desc->DepthEnable;
2335 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
2336 tmp_desc.DepthFunc = desc->DepthFunc;
2337 tmp_desc.StencilEnable = desc->StencilEnable;
2338 tmp_desc.StencilReadMask = desc->StencilReadMask;
2339 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
2340 tmp_desc.FrontFace = desc->FrontFace;
2341 tmp_desc.BackFace = desc->BackFace;
2343 wined3d_mutex_lock();
2344 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
2346 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
2348 TRACE("Returning existing depthstencil state %p.\n", object);
2349 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
2350 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
2351 wined3d_mutex_unlock();
2353 return S_OK;
2355 wined3d_mutex_unlock();
2357 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2358 if (!object)
2359 return E_OUTOFMEMORY;
2361 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, &tmp_desc)))
2363 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
2364 HeapFree(GetProcessHeap(), 0, object);
2365 return hr;
2368 TRACE("Created depthstencil state %p.\n", object);
2369 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
2371 return S_OK;
2374 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
2375 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
2377 struct d3d_device *device = impl_from_ID3D10Device(iface);
2378 struct d3d10_rasterizer_state *object;
2379 struct wine_rb_entry *entry;
2380 HRESULT hr;
2382 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2384 if (!desc)
2385 return E_INVALIDARG;
2387 wined3d_mutex_lock();
2388 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
2390 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
2392 TRACE("Returning existing rasterizer state %p.\n", object);
2393 *rasterizer_state = &object->ID3D10RasterizerState_iface;
2394 ID3D10RasterizerState_AddRef(*rasterizer_state);
2395 wined3d_mutex_unlock();
2397 return S_OK;
2399 wined3d_mutex_unlock();
2401 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2402 if (!object)
2403 return E_OUTOFMEMORY;
2405 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
2407 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
2408 HeapFree(GetProcessHeap(), 0, object);
2409 return hr;
2412 TRACE("Created rasterizer state %p.\n", object);
2413 *rasterizer_state = &object->ID3D10RasterizerState_iface;
2415 return S_OK;
2418 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
2419 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
2421 struct d3d_device *device = impl_from_ID3D10Device(iface);
2422 struct d3d10_sampler_state *object;
2423 struct wine_rb_entry *entry;
2424 HRESULT hr;
2426 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2428 if (!desc)
2429 return E_INVALIDARG;
2431 wined3d_mutex_lock();
2432 if ((entry = wine_rb_get(&device->sampler_states, desc)))
2434 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
2436 TRACE("Returning existing sampler state %p.\n", object);
2437 *sampler_state = &object->ID3D10SamplerState_iface;
2438 ID3D10SamplerState_AddRef(*sampler_state);
2439 wined3d_mutex_unlock();
2441 return S_OK;
2443 wined3d_mutex_unlock();
2445 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2446 if (!object)
2447 return E_OUTOFMEMORY;
2449 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
2451 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2452 HeapFree(GetProcessHeap(), 0, object);
2453 return hr;
2456 TRACE("Created sampler state %p.\n", object);
2457 *sampler_state = &object->ID3D10SamplerState_iface;
2459 return S_OK;
2462 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
2463 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
2465 struct d3d_device *device = impl_from_ID3D10Device(iface);
2466 struct d3d10_query *object;
2467 HRESULT hr;
2469 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2471 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2472 return E_OUTOFMEMORY;
2474 if (FAILED(hr = d3d10_query_init(object, device, desc, FALSE)))
2476 WARN("Failed to initialize query, hr %#x.\n", hr);
2477 HeapFree(GetProcessHeap(), 0, object);
2478 return hr;
2481 TRACE("Created query %p.\n", object);
2482 *query = &object->ID3D10Query_iface;
2484 return S_OK;
2487 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
2488 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
2490 struct d3d_device *device = impl_from_ID3D10Device(iface);
2491 struct d3d10_query *object;
2492 HRESULT hr;
2494 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2496 if (!desc)
2497 return E_INVALIDARG;
2499 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
2501 WARN("Query type %#x is not a predicate.\n", desc->Query);
2502 return E_INVALIDARG;
2505 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2506 return E_OUTOFMEMORY;
2508 if (FAILED(hr = d3d10_query_init(object, device, desc, TRUE)))
2510 WARN("Failed to initialize predicate, hr %#x.\n", hr);
2511 HeapFree(GetProcessHeap(), 0, object);
2512 return hr;
2515 TRACE("Created predicate %p.\n", object);
2516 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
2518 return S_OK;
2521 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
2522 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
2524 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2526 return E_NOTIMPL;
2529 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
2530 DXGI_FORMAT format, UINT *format_support)
2532 FIXME("iface %p, format %s, format_support %p stub!\n",
2533 iface, debug_dxgi_format(format), format_support);
2535 return E_NOTIMPL;
2538 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
2539 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2541 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
2542 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2544 return E_NOTIMPL;
2547 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
2549 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
2552 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
2553 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
2554 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
2556 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
2557 "units %p, units_length %p, description %p, description_length %p stub!\n",
2558 iface, desc, type, active_counters, name, name_length,
2559 units, units_length, description, description_length);
2561 return E_NOTIMPL;
2564 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
2566 FIXME("iface %p stub!\n", iface);
2568 return 0;
2571 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
2572 HANDLE resource_handle, REFIID guid, void **resource)
2574 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
2575 iface, resource_handle, debugstr_guid(guid), resource);
2577 return E_NOTIMPL;
2580 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
2582 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
2585 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
2587 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
2590 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
2591 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
2593 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
2595 return E_NOTIMPL;
2598 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
2599 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
2601 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
2603 return E_NOTIMPL;
2606 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
2608 FIXME("iface %p stub!\n", iface);
2610 return D3D10_FEATURE_LEVEL_10_1;
2613 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
2615 /* IUnknown methods */
2616 d3d10_device_QueryInterface,
2617 d3d10_device_AddRef,
2618 d3d10_device_Release,
2619 /* ID3D10Device methods */
2620 d3d10_device_VSSetConstantBuffers,
2621 d3d10_device_PSSetShaderResources,
2622 d3d10_device_PSSetShader,
2623 d3d10_device_PSSetSamplers,
2624 d3d10_device_VSSetShader,
2625 d3d10_device_DrawIndexed,
2626 d3d10_device_Draw,
2627 d3d10_device_PSSetConstantBuffers,
2628 d3d10_device_IASetInputLayout,
2629 d3d10_device_IASetVertexBuffers,
2630 d3d10_device_IASetIndexBuffer,
2631 d3d10_device_DrawIndexedInstanced,
2632 d3d10_device_DrawInstanced,
2633 d3d10_device_GSSetConstantBuffers,
2634 d3d10_device_GSSetShader,
2635 d3d10_device_IASetPrimitiveTopology,
2636 d3d10_device_VSSetShaderResources,
2637 d3d10_device_VSSetSamplers,
2638 d3d10_device_SetPredication,
2639 d3d10_device_GSSetShaderResources,
2640 d3d10_device_GSSetSamplers,
2641 d3d10_device_OMSetRenderTargets,
2642 d3d10_device_OMSetBlendState,
2643 d3d10_device_OMSetDepthStencilState,
2644 d3d10_device_SOSetTargets,
2645 d3d10_device_DrawAuto,
2646 d3d10_device_RSSetState,
2647 d3d10_device_RSSetViewports,
2648 d3d10_device_RSSetScissorRects,
2649 d3d10_device_CopySubresourceRegion,
2650 d3d10_device_CopyResource,
2651 d3d10_device_UpdateSubresource,
2652 d3d10_device_ClearRenderTargetView,
2653 d3d10_device_ClearDepthStencilView,
2654 d3d10_device_GenerateMips,
2655 d3d10_device_ResolveSubresource,
2656 d3d10_device_VSGetConstantBuffers,
2657 d3d10_device_PSGetShaderResources,
2658 d3d10_device_PSGetShader,
2659 d3d10_device_PSGetSamplers,
2660 d3d10_device_VSGetShader,
2661 d3d10_device_PSGetConstantBuffers,
2662 d3d10_device_IAGetInputLayout,
2663 d3d10_device_IAGetVertexBuffers,
2664 d3d10_device_IAGetIndexBuffer,
2665 d3d10_device_GSGetConstantBuffers,
2666 d3d10_device_GSGetShader,
2667 d3d10_device_IAGetPrimitiveTopology,
2668 d3d10_device_VSGetShaderResources,
2669 d3d10_device_VSGetSamplers,
2670 d3d10_device_GetPredication,
2671 d3d10_device_GSGetShaderResources,
2672 d3d10_device_GSGetSamplers,
2673 d3d10_device_OMGetRenderTargets,
2674 d3d10_device_OMGetBlendState,
2675 d3d10_device_OMGetDepthStencilState,
2676 d3d10_device_SOGetTargets,
2677 d3d10_device_RSGetState,
2678 d3d10_device_RSGetViewports,
2679 d3d10_device_RSGetScissorRects,
2680 d3d10_device_GetDeviceRemovedReason,
2681 d3d10_device_SetExceptionMode,
2682 d3d10_device_GetExceptionMode,
2683 d3d10_device_GetPrivateData,
2684 d3d10_device_SetPrivateData,
2685 d3d10_device_SetPrivateDataInterface,
2686 d3d10_device_ClearState,
2687 d3d10_device_Flush,
2688 d3d10_device_CreateBuffer,
2689 d3d10_device_CreateTexture1D,
2690 d3d10_device_CreateTexture2D,
2691 d3d10_device_CreateTexture3D,
2692 d3d10_device_CreateShaderResourceView,
2693 d3d10_device_CreateRenderTargetView,
2694 d3d10_device_CreateDepthStencilView,
2695 d3d10_device_CreateInputLayout,
2696 d3d10_device_CreateVertexShader,
2697 d3d10_device_CreateGeometryShader,
2698 d3d10_device_CreateGeometryShaderWithStreamOutput,
2699 d3d10_device_CreatePixelShader,
2700 d3d10_device_CreateBlendState,
2701 d3d10_device_CreateDepthStencilState,
2702 d3d10_device_CreateRasterizerState,
2703 d3d10_device_CreateSamplerState,
2704 d3d10_device_CreateQuery,
2705 d3d10_device_CreatePredicate,
2706 d3d10_device_CreateCounter,
2707 d3d10_device_CheckFormatSupport,
2708 d3d10_device_CheckMultisampleQualityLevels,
2709 d3d10_device_CheckCounterInfo,
2710 d3d10_device_CheckCounter,
2711 d3d10_device_GetCreationFlags,
2712 d3d10_device_OpenSharedResource,
2713 d3d10_device_SetTextFilterSize,
2714 d3d10_device_GetTextFilterSize,
2715 d3d10_device_CreateShaderResourceView1,
2716 d3d10_device_CreateBlendState1,
2717 d3d10_device_GetFeatureLevel,
2720 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
2722 /* IUnknown methods */
2723 d3d10_device_inner_QueryInterface,
2724 d3d10_device_inner_AddRef,
2725 d3d10_device_inner_Release,
2728 /* ID3D10Multithread methods */
2730 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
2732 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
2735 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
2737 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2739 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2741 return IUnknown_QueryInterface(device->outer_unk, iid, out);
2744 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
2746 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2748 TRACE("iface %p.\n", iface);
2750 return IUnknown_AddRef(device->outer_unk);
2753 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2755 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2757 TRACE("iface %p.\n", iface);
2759 return IUnknown_Release(device->outer_unk);
2762 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2764 TRACE("iface %p.\n", iface);
2766 wined3d_mutex_lock();
2769 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2771 TRACE("iface %p.\n", iface);
2773 wined3d_mutex_unlock();
2776 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2778 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2780 return TRUE;
2783 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2785 FIXME("iface %p stub!\n", iface);
2787 return TRUE;
2790 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2792 d3d10_multithread_QueryInterface,
2793 d3d10_multithread_AddRef,
2794 d3d10_multithread_Release,
2795 d3d10_multithread_Enter,
2796 d3d10_multithread_Leave,
2797 d3d10_multithread_SetMultithreadProtected,
2798 d3d10_multithread_GetMultithreadProtected,
2801 /* IWineDXGIDeviceParent IUnknown methods */
2803 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2805 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
2808 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2809 REFIID riid, void **ppv)
2811 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2812 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2815 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2817 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2818 return IUnknown_AddRef(device->outer_unk);
2821 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2823 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2824 return IUnknown_Release(device->outer_unk);
2827 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2828 IWineDXGIDeviceParent *iface)
2830 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2831 return &device->device_parent;
2834 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2836 /* IUnknown methods */
2837 dxgi_device_parent_QueryInterface,
2838 dxgi_device_parent_AddRef,
2839 dxgi_device_parent_Release,
2840 /* IWineDXGIDeviceParent methods */
2841 dxgi_device_parent_get_wined3d_device_parent,
2844 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2846 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
2849 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2850 struct wined3d_device *wined3d_device)
2852 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2854 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2856 wined3d_device_incref(wined3d_device);
2857 device->wined3d_device = wined3d_device;
2860 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2862 TRACE("device_parent %p.\n", device_parent);
2865 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2867 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2870 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2871 void *container_parent, struct wined3d_surface *surface, void **parent,
2872 const struct wined3d_parent_ops **parent_ops)
2874 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2875 device_parent, container_parent, surface, parent, parent_ops);
2877 *parent = container_parent;
2878 *parent_ops = &d3d10_null_wined3d_parent_ops;
2880 return S_OK;
2883 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2884 void *container_parent, struct wined3d_volume *volume, void **parent,
2885 const struct wined3d_parent_ops **parent_ops)
2887 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2888 device_parent, container_parent, volume, parent, parent_ops);
2890 *parent = container_parent;
2891 *parent_ops = &d3d10_null_wined3d_parent_ops;
2893 return S_OK;
2896 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2897 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2899 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2900 struct wined3d_resource *sub_resource;
2901 struct d3d_texture2d *texture;
2902 ID3D10Texture2D *texture_iface;
2903 D3D10_TEXTURE2D_DESC desc;
2904 HRESULT hr;
2906 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2907 device_parent, container_parent, wined3d_desc, surface);
2909 FIXME("Implement DXGI<->wined3d usage conversion\n");
2911 desc.Width = wined3d_desc->width;
2912 desc.Height = wined3d_desc->height;
2913 desc.MipLevels = 1;
2914 desc.ArraySize = 1;
2915 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2916 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2917 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2918 desc.Usage = D3D10_USAGE_DEFAULT;
2919 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2920 desc.CPUAccessFlags = 0;
2921 desc.MiscFlags = 0;
2923 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2924 &desc, NULL, &texture_iface)))
2926 ERR("CreateTexture2D failed, returning %#x\n", hr);
2927 return hr;
2930 texture = impl_from_ID3D10Texture2D(texture_iface);
2932 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2933 *surface = wined3d_surface_from_resource(sub_resource);
2934 wined3d_surface_incref(*surface);
2935 ID3D10Texture2D_Release(texture_iface);
2937 return S_OK;
2940 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2941 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2943 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2944 IWineDXGIDevice *wine_device;
2945 HRESULT hr;
2947 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2949 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2950 &IID_IWineDXGIDevice, (void **)&wine_device)))
2952 ERR("Device should implement IWineDXGIDevice.\n");
2953 return E_FAIL;
2956 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2957 IWineDXGIDevice_Release(wine_device);
2958 if (FAILED(hr))
2960 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2961 return hr;
2964 return S_OK;
2967 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2969 device_parent_wined3d_device_created,
2970 device_parent_mode_changed,
2971 device_parent_activate,
2972 device_parent_surface_created,
2973 device_parent_volume_created,
2974 device_parent_create_swapchain_surface,
2975 device_parent_create_swapchain,
2978 static void *d3d10_rb_alloc(size_t size)
2980 return HeapAlloc(GetProcessHeap(), 0, size);
2983 static void *d3d10_rb_realloc(void *ptr, size_t size)
2985 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2988 static void d3d10_rb_free(void *ptr)
2990 HeapFree(GetProcessHeap(), 0, ptr);
2993 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2995 const D3D10_SAMPLER_DESC *ka = key;
2996 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2998 return memcmp(ka, kb, sizeof(*ka));
3001 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
3003 d3d10_rb_alloc,
3004 d3d10_rb_realloc,
3005 d3d10_rb_free,
3006 d3d10_sampler_state_compare,
3009 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
3011 const D3D10_BLEND_DESC *ka = key;
3012 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
3014 return memcmp(ka, kb, sizeof(*ka));
3017 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
3019 d3d10_rb_alloc,
3020 d3d10_rb_realloc,
3021 d3d10_rb_free,
3022 d3d10_blend_state_compare,
3025 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
3027 const D3D10_DEPTH_STENCIL_DESC *ka = key;
3028 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
3029 const struct d3d10_depthstencil_state, entry)->desc;
3031 return memcmp(ka, kb, sizeof(*ka));
3034 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
3036 d3d10_rb_alloc,
3037 d3d10_rb_realloc,
3038 d3d10_rb_free,
3039 d3d10_depthstencil_state_compare,
3042 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
3044 const D3D10_RASTERIZER_DESC *ka = key;
3045 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
3047 return memcmp(ka, kb, sizeof(*ka));
3050 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
3052 d3d10_rb_alloc,
3053 d3d10_rb_realloc,
3054 d3d10_rb_free,
3055 d3d10_rasterizer_state_compare,
3058 HRESULT d3d10_device_init(struct d3d_device *device, void *outer_unknown)
3060 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
3061 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
3062 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
3063 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
3064 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
3065 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
3066 device->refcount = 1;
3067 /* COM aggregation always takes place */
3068 device->outer_unk = outer_unknown;
3070 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
3072 WARN("Failed to initialize blend state rbtree.\n");
3073 return E_FAIL;
3075 device->blend_factor[0] = 1.0f;
3076 device->blend_factor[1] = 1.0f;
3077 device->blend_factor[2] = 1.0f;
3078 device->blend_factor[3] = 1.0f;
3080 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
3082 WARN("Failed to initialize depthstencil state rbtree.\n");
3083 wine_rb_destroy(&device->blend_states, NULL, NULL);
3084 return E_FAIL;
3087 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
3089 WARN("Failed to initialize rasterizer state rbtree.\n");
3090 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3091 wine_rb_destroy(&device->blend_states, NULL, NULL);
3092 return E_FAIL;
3095 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
3097 WARN("Failed to initialize sampler state rbtree.\n");
3098 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3099 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3100 wine_rb_destroy(&device->blend_states, NULL, NULL);
3101 return E_FAIL;
3104 return S_OK;