d3d11: Implement d3d11_device_CreateDepthStencilState().
[wine/multimedia.git] / dlls / d3d11 / device.c
blob79e3ea8fd8f669f2bd194b6991f6b7649a094cd8
1 /*
2 * Copyright 2008-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #define NONAMELESSUNION
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
28 static void STDMETHODCALLTYPE d3d10_null_wined3d_object_destroyed(void *parent) {}
30 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
32 d3d10_null_wined3d_object_destroyed,
35 /* ID3D11Device methods */
37 static HRESULT STDMETHODCALLTYPE d3d11_device_QueryInterface(ID3D11Device *iface, REFIID riid, void **out)
39 struct d3d_device *device = impl_from_ID3D11Device(iface);
40 return IUnknown_QueryInterface(device->outer_unk, riid, out);
43 static ULONG STDMETHODCALLTYPE d3d11_device_AddRef(ID3D11Device *iface)
45 struct d3d_device *device = impl_from_ID3D11Device(iface);
46 return IUnknown_AddRef(device->outer_unk);
49 static ULONG STDMETHODCALLTYPE d3d11_device_Release(ID3D11Device *iface)
51 struct d3d_device *device = impl_from_ID3D11Device(iface);
52 return IUnknown_Release(device->outer_unk);
55 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBuffer(ID3D11Device *iface, const D3D11_BUFFER_DESC *desc,
56 const D3D11_SUBRESOURCE_DATA *data, ID3D11Buffer **buffer)
58 struct d3d_device *device = impl_from_ID3D11Device(iface);
59 struct d3d_buffer *object;
60 HRESULT hr;
62 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
64 if (FAILED(hr = d3d_buffer_create(device, desc, data, &object)))
65 return hr;
67 *buffer = &object->ID3D11Buffer_iface;
69 return S_OK;
72 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture1D(ID3D11Device *iface,
73 const D3D11_TEXTURE1D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture1D **texture)
75 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
77 return E_NOTIMPL;
80 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture2D(ID3D11Device *iface,
81 const D3D11_TEXTURE2D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture2D **texture)
83 struct d3d_device *device = impl_from_ID3D11Device(iface);
84 struct d3d_texture2d *object;
85 HRESULT hr;
87 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
89 if (FAILED(hr = d3d_texture2d_create(device, desc, data, &object)))
90 return hr;
92 *texture = &object->ID3D11Texture2D_iface;
94 return S_OK;
97 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateTexture3D(ID3D11Device *iface,
98 const D3D11_TEXTURE3D_DESC *desc, const D3D11_SUBRESOURCE_DATA *data, ID3D11Texture3D **texture)
100 struct d3d_device *device = impl_from_ID3D11Device(iface);
101 struct d3d_texture3d *object;
102 HRESULT hr;
104 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
106 if (FAILED(hr = d3d_texture3d_create(device, desc, data, &object)))
107 return hr;
109 *texture = &object->ID3D11Texture3D_iface;
111 return S_OK;
114 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateShaderResourceView(ID3D11Device *iface,
115 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11ShaderResourceView **view)
117 struct d3d_device *device = impl_from_ID3D11Device(iface);
118 struct d3d_shader_resource_view *object;
119 HRESULT hr;
121 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
123 if (FAILED(hr = d3d_shader_resource_view_create(device, resource, desc, &object)))
124 return hr;
126 *view = &object->ID3D11ShaderResourceView_iface;
128 return S_OK;
131 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateUnorderedAccessView(ID3D11Device *iface,
132 ID3D11Resource *resource, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc, ID3D11UnorderedAccessView **view)
134 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
136 return E_NOTIMPL;
139 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRenderTargetView(ID3D11Device *iface,
140 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11RenderTargetView **view)
142 struct d3d_device *device = impl_from_ID3D11Device(iface);
143 struct d3d_rendertarget_view *object;
144 HRESULT hr;
146 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
148 if (FAILED(hr = d3d_rendertarget_view_create(device, resource, desc, &object)))
149 return hr;
151 *view = &object->ID3D11RenderTargetView_iface;
153 return S_OK;
156 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilView(ID3D11Device *iface,
157 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11DepthStencilView **view)
159 struct d3d_device *device = impl_from_ID3D11Device(iface);
160 struct d3d_depthstencil_view *object;
161 HRESULT hr;
163 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
165 if (FAILED(hr = d3d_depthstencil_view_create(device, resource, desc, &object)))
166 return hr;
168 *view = &object->ID3D11DepthStencilView_iface;
170 return S_OK;
173 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateInputLayout(ID3D11Device *iface,
174 const D3D11_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
175 SIZE_T shader_byte_code_length, ID3D11InputLayout **input_layout)
177 struct d3d_device *device = impl_from_ID3D11Device(iface);
178 struct d3d_input_layout *object;
179 HRESULT hr;
181 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, shader_byte_code_length %lu, "
182 "input_layout %p.\n", iface, element_descs, element_count, shader_byte_code,
183 shader_byte_code_length, input_layout);
185 if (FAILED(hr = d3d_input_layout_create(device, element_descs, element_count,
186 shader_byte_code, shader_byte_code_length, &object)))
187 return hr;
189 *input_layout = &object->ID3D11InputLayout_iface;
191 return S_OK;
194 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateVertexShader(ID3D11Device *iface, const void *byte_code,
195 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11VertexShader **shader)
197 struct d3d_device *device = impl_from_ID3D11Device(iface);
198 struct d3d_vertex_shader *object;
199 HRESULT hr;
201 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
202 iface, byte_code, byte_code_length, class_linkage, shader);
204 if (class_linkage)
205 FIXME("Class linkage is not implemented yet.\n");
207 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
208 return hr;
210 *shader = &object->ID3D11VertexShader_iface;
212 return S_OK;
215 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShader(ID3D11Device *iface, const void *byte_code,
216 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
218 struct d3d_device *device = impl_from_ID3D11Device(iface);
219 struct d3d_geometry_shader *object;
220 HRESULT hr;
222 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
223 iface, byte_code, byte_code_length, class_linkage, shader);
225 if (class_linkage)
226 FIXME("Class linkage is not implemented yet.\n");
228 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
229 return hr;
231 *shader = &object->ID3D11GeometryShader_iface;
233 return S_OK;
236 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateGeometryShaderWithStreamOutput(ID3D11Device *iface,
237 const void *byte_code, SIZE_T byte_code_length, const D3D11_SO_DECLARATION_ENTRY *so_entries,
238 UINT entry_count, const UINT *buffer_strides, UINT strides_count, UINT rasterized_stream,
239 ID3D11ClassLinkage *class_linkage, ID3D11GeometryShader **shader)
241 FIXME("iface %p, byte_code %p, byte_code_length %lu, so_entries %p, entry_count %u, "
242 "buffer_strides %p, strides_count %u, rasterized_stream %u, class_linkage %p, shader %p stub!\n",
243 iface, byte_code, byte_code_length, so_entries, entry_count, buffer_strides, strides_count,
244 rasterized_stream, class_linkage, shader);
246 return E_NOTIMPL;
249 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePixelShader(ID3D11Device *iface, const void *byte_code,
250 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11PixelShader **shader)
252 struct d3d_device *device = impl_from_ID3D11Device(iface);
253 struct d3d_pixel_shader *object;
254 HRESULT hr;
256 TRACE("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p.\n",
257 iface, byte_code, byte_code_length, class_linkage, shader);
259 if (class_linkage)
260 FIXME("Class linkage is not implemented yet.\n");
262 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
263 return hr;
265 *shader = &object->ID3D11PixelShader_iface;
267 return S_OK;
270 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateHullShader(ID3D11Device *iface, const void *byte_code,
271 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11HullShader **shader)
273 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
274 iface, byte_code, byte_code_length, class_linkage, shader);
276 return E_NOTIMPL;
279 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDomainShader(ID3D11Device *iface, const void *byte_code,
280 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11DomainShader **shader)
282 FIXME("iface %p, byte_code %p, byte_code_length %lu, class_linkage %p, shader %p stub!\n",
283 iface, byte_code, byte_code_length, class_linkage, shader);
285 return E_NOTIMPL;
288 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateComputeShader(ID3D11Device *iface, const void *byte_code,
289 SIZE_T byte_code_length, ID3D11ClassLinkage *class_linkage, ID3D11ComputeShader **shader)
291 FIXME("iface %p, byte_code %p, byte_code_lenghth %lu, class_linkage %p, shader %p stub!\n",
292 iface, byte_code, byte_code_length, class_linkage, shader);
294 return E_NOTIMPL;
297 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateClassLinkage(ID3D11Device *iface,
298 ID3D11ClassLinkage **class_linkage)
300 FIXME("iface %p, class_linkage %p stub!\n", iface, class_linkage);
302 return E_NOTIMPL;
305 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateBlendState(ID3D11Device *iface,
306 const D3D11_BLEND_DESC *desc, ID3D11BlendState **blend_state)
308 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
310 return E_NOTIMPL;
313 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDepthStencilState(ID3D11Device *iface,
314 const D3D11_DEPTH_STENCIL_DESC *desc, ID3D11DepthStencilState **depth_stencil_state)
316 struct d3d_device *device = impl_from_ID3D11Device(iface);
317 struct d3d_depthstencil_state *object;
318 D3D11_DEPTH_STENCIL_DESC tmp_desc;
319 struct wine_rb_entry *entry;
320 HRESULT hr;
322 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
324 if (!desc)
325 return E_INVALIDARG;
327 /* D3D11_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
328 * it as a key in the rbtree. */
329 memset(&tmp_desc, 0, sizeof(tmp_desc));
330 tmp_desc.DepthEnable = desc->DepthEnable;
331 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
332 tmp_desc.DepthFunc = desc->DepthFunc;
333 tmp_desc.StencilEnable = desc->StencilEnable;
334 tmp_desc.StencilReadMask = desc->StencilReadMask;
335 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
336 tmp_desc.FrontFace = desc->FrontFace;
337 tmp_desc.BackFace = desc->BackFace;
339 wined3d_mutex_lock();
340 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
342 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_depthstencil_state, entry);
344 TRACE("Returning existing depthstencil state %p.\n", object);
345 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
346 ID3D11DepthStencilState_AddRef(*depth_stencil_state);
347 wined3d_mutex_unlock();
349 return S_OK;
351 wined3d_mutex_unlock();
353 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
354 return E_OUTOFMEMORY;
356 if (FAILED(hr = d3d_depthstencil_state_init(object, device, &tmp_desc)))
358 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
359 HeapFree(GetProcessHeap(), 0, object);
360 return hr;
363 TRACE("Created depthstencil state %p.\n", object);
364 *depth_stencil_state = &object->ID3D11DepthStencilState_iface;
366 return S_OK;
369 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateRasterizerState(ID3D11Device *iface,
370 const D3D11_RASTERIZER_DESC *desc, ID3D11RasterizerState **rasterizer_state)
372 struct d3d_device *device = impl_from_ID3D11Device(iface);
373 struct d3d_rasterizer_state *object;
374 struct wine_rb_entry *entry;
375 HRESULT hr;
377 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
379 if (!desc)
380 return E_INVALIDARG;
382 wined3d_mutex_lock();
383 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
385 object = WINE_RB_ENTRY_VALUE(entry, struct d3d_rasterizer_state, entry);
387 TRACE("Returning existing rasterizer state %p.\n", object);
388 *rasterizer_state = &object->ID3D11RasterizerState_iface;
389 ID3D11RasterizerState_AddRef(*rasterizer_state);
390 wined3d_mutex_unlock();
392 return S_OK;
394 wined3d_mutex_unlock();
396 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
397 return E_OUTOFMEMORY;
399 if (FAILED(hr = d3d_rasterizer_state_init(object, device, desc)))
401 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
402 HeapFree(GetProcessHeap(), 0, object);
403 return hr;
406 TRACE("Created rasterizer state %p.\n", object);
407 *rasterizer_state = &object->ID3D11RasterizerState_iface;
409 return S_OK;
412 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateSamplerState(ID3D11Device *iface,
413 const D3D11_SAMPLER_DESC *desc, ID3D11SamplerState **sampler_state)
415 FIXME("iface %p, desc %p, sampler_state %p stub!\n", iface, desc, sampler_state);
417 return E_NOTIMPL;
420 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateQuery(ID3D11Device *iface,
421 const D3D11_QUERY_DESC *desc, ID3D11Query **query)
423 FIXME("iface %p, desc %p, query %p stub!\n", iface, desc, query);
425 return E_NOTIMPL;
428 static HRESULT STDMETHODCALLTYPE d3d11_device_CreatePredicate(ID3D11Device *iface, const D3D11_QUERY_DESC *desc,
429 ID3D11Predicate **predicate)
431 FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
433 return E_NOTIMPL;
436 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
437 ID3D11Counter **counter)
439 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
441 return E_NOTIMPL;
444 static HRESULT STDMETHODCALLTYPE d3d11_device_CreateDeferredContext(ID3D11Device *iface, UINT flags,
445 ID3D11DeviceContext **context)
447 FIXME("iface %p, flags %#x, context %p stub!\n", iface, flags, context);
449 return E_NOTIMPL;
452 static HRESULT STDMETHODCALLTYPE d3d11_device_OpenSharedResource(ID3D11Device *iface, HANDLE resource, REFIID riid,
453 void **out)
455 FIXME("iface %p, resource %p, riid %s, out %p stub!\n", iface, resource, debugstr_guid(riid), out);
457 return E_NOTIMPL;
460 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device *iface, DXGI_FORMAT format,
461 UINT *format_support)
463 FIXME("iface %p, format %u, format_support %p stub!\n", iface, format, format_support);
465 return E_NOTIMPL;
468 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckMultisampleQualityLevels(ID3D11Device *iface,
469 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
471 FIXME("iface %p, format %u, sample_count %u, quality_level_count %p stub!\n",
472 iface, format, sample_count, quality_level_count);
474 return E_NOTIMPL;
477 static void STDMETHODCALLTYPE d3d11_device_CheckCounterInfo(ID3D11Device *iface, D3D11_COUNTER_INFO *info)
479 FIXME("iface %p, info %p stub!\n", iface, info);
482 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckCounter(ID3D11Device *iface, const D3D11_COUNTER_DESC *desc,
483 D3D11_COUNTER_TYPE *type, UINT *active_counter_count, char *name, UINT *name_length,
484 char *units, UINT *units_length, char *description, UINT *description_length)
486 FIXME("iface %p, desc %p, type %p, active_counter_count %p, name %p, name_length %p, "
487 "units %p, units_length %p, description %p, description_length %p stub!\n",
488 iface, desc, type, active_counter_count, name, name_length,
489 units, units_length, description, description_length);
491 return E_NOTIMPL;
494 static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFeatureSupport(ID3D11Device *iface, D3D11_FEATURE feature,
495 void *feature_support_data, UINT feature_support_data_size)
497 FIXME("iface %p, feature %u, feature_support_data %p, feature_support_data_size %u stub!\n",
498 iface, feature, feature_support_data, feature_support_data_size);
500 return E_NOTIMPL;
503 static HRESULT STDMETHODCALLTYPE d3d11_device_GetPrivateData(ID3D11Device *iface, REFGUID guid,
504 UINT *data_size, void *data)
506 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
508 return E_NOTIMPL;
511 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateData(ID3D11Device *iface, REFGUID guid,
512 UINT data_size, const void *data)
514 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
516 return E_NOTIMPL;
519 static HRESULT STDMETHODCALLTYPE d3d11_device_SetPrivateDataInterface(ID3D11Device *iface, REFGUID guid,
520 const IUnknown *data_iface)
522 FIXME("iface %p, guid %s, data_iface %p stub!\n", iface, debugstr_guid(guid), data_iface);
524 return E_NOTIMPL;
527 static D3D_FEATURE_LEVEL STDMETHODCALLTYPE d3d11_device_GetFeatureLevel(ID3D11Device *iface)
529 FIXME("iface %p stub!\n", iface);
531 return D3D_FEATURE_LEVEL_10_0;
534 static UINT STDMETHODCALLTYPE d3d11_device_GetCreationFlags(ID3D11Device *iface)
536 FIXME("iface %p stub!\n", iface);
538 return 0;
541 static HRESULT STDMETHODCALLTYPE d3d11_device_GetDeviceRemovedReason(ID3D11Device *iface)
543 FIXME("iface %p stub!\n", iface);
545 return S_OK;
548 static void STDMETHODCALLTYPE d3d11_device_GetImmediateContext(ID3D11Device *iface,
549 ID3D11DeviceContext **immediate_context)
551 FIXME("iface %p, immediate_context %p stub!\n", iface, immediate_context);
553 *immediate_context = NULL;
556 static HRESULT STDMETHODCALLTYPE d3d11_device_SetExceptionMode(ID3D11Device *iface, UINT flags)
558 FIXME("iface %p, flags %#x stub!\n", iface, flags);
560 return E_NOTIMPL;
563 static UINT STDMETHODCALLTYPE d3d11_device_GetExceptionMode(ID3D11Device *iface)
565 FIXME("iface %p stub!\n", iface);
567 return 0;
570 static const struct ID3D11DeviceVtbl d3d11_device_vtbl =
572 /* IUnknown methods */
573 d3d11_device_QueryInterface,
574 d3d11_device_AddRef,
575 d3d11_device_Release,
576 /* ID3D11Device methods */
577 d3d11_device_CreateBuffer,
578 d3d11_device_CreateTexture1D,
579 d3d11_device_CreateTexture2D,
580 d3d11_device_CreateTexture3D,
581 d3d11_device_CreateShaderResourceView,
582 d3d11_device_CreateUnorderedAccessView,
583 d3d11_device_CreateRenderTargetView,
584 d3d11_device_CreateDepthStencilView,
585 d3d11_device_CreateInputLayout,
586 d3d11_device_CreateVertexShader,
587 d3d11_device_CreateGeometryShader,
588 d3d11_device_CreateGeometryShaderWithStreamOutput,
589 d3d11_device_CreatePixelShader,
590 d3d11_device_CreateHullShader,
591 d3d11_device_CreateDomainShader,
592 d3d11_device_CreateComputeShader,
593 d3d11_device_CreateClassLinkage,
594 d3d11_device_CreateBlendState,
595 d3d11_device_CreateDepthStencilState,
596 d3d11_device_CreateRasterizerState,
597 d3d11_device_CreateSamplerState,
598 d3d11_device_CreateQuery,
599 d3d11_device_CreatePredicate,
600 d3d11_device_CreateCounter,
601 d3d11_device_CreateDeferredContext,
602 d3d11_device_OpenSharedResource,
603 d3d11_device_CheckFormatSupport,
604 d3d11_device_CheckMultisampleQualityLevels,
605 d3d11_device_CheckCounterInfo,
606 d3d11_device_CheckCounter,
607 d3d11_device_CheckFeatureSupport,
608 d3d11_device_GetPrivateData,
609 d3d11_device_SetPrivateData,
610 d3d11_device_SetPrivateDataInterface,
611 d3d11_device_GetFeatureLevel,
612 d3d11_device_GetCreationFlags,
613 d3d11_device_GetDeviceRemovedReason,
614 d3d11_device_GetImmediateContext,
615 d3d11_device_SetExceptionMode,
616 d3d11_device_GetExceptionMode,
619 /* Inner IUnknown methods */
621 static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
623 return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
626 static HRESULT STDMETHODCALLTYPE d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
628 struct d3d_device *device = impl_from_IUnknown(iface);
630 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
632 if (IsEqualGUID(riid, &IID_ID3D11Device)
633 || IsEqualGUID(riid, &IID_IUnknown))
635 *out = &device->ID3D11Device_iface;
637 else if (IsEqualGUID(riid, &IID_ID3D10Device1)
638 || IsEqualGUID(riid, &IID_ID3D10Device))
640 *out = &device->ID3D10Device1_iface;
642 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
644 *out = &device->ID3D10Multithread_iface;
646 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
648 *out = &device->IWineDXGIDeviceParent_iface;
650 else
652 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
653 *out = NULL;
654 return E_NOINTERFACE;
657 IUnknown_AddRef((IUnknown *)*out);
658 return S_OK;
661 static ULONG STDMETHODCALLTYPE d3d_device_inner_AddRef(IUnknown *iface)
663 struct d3d_device *device = impl_from_IUnknown(iface);
664 ULONG refcount = InterlockedIncrement(&device->refcount);
666 TRACE("%p increasing refcount to %u.\n", device, refcount);
668 return refcount;
671 static ULONG STDMETHODCALLTYPE d3d_device_inner_Release(IUnknown *iface)
673 struct d3d_device *device = impl_from_IUnknown(iface);
674 ULONG refcount = InterlockedDecrement(&device->refcount);
676 TRACE("%p decreasing refcount to %u.\n", device, refcount);
678 if (!refcount)
680 if (device->wined3d_device)
682 wined3d_mutex_lock();
683 wined3d_device_decref(device->wined3d_device);
684 wined3d_mutex_unlock();
686 wine_rb_destroy(&device->sampler_states, NULL, NULL);
687 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
688 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
689 wine_rb_destroy(&device->blend_states, NULL, NULL);
692 return refcount;
695 /* IUnknown methods */
697 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
698 void **ppv)
700 struct d3d_device *This = impl_from_ID3D10Device(iface);
701 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
704 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
706 struct d3d_device *This = impl_from_ID3D10Device(iface);
707 return IUnknown_AddRef(This->outer_unk);
710 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
712 struct d3d_device *This = impl_from_ID3D10Device(iface);
713 return IUnknown_Release(This->outer_unk);
716 /* ID3D10Device methods */
718 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
719 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
721 struct d3d_device *device = impl_from_ID3D10Device(iface);
722 unsigned int i;
724 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
725 iface, start_slot, buffer_count, buffers);
727 wined3d_mutex_lock();
728 for (i = 0; i < buffer_count; ++i)
730 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
732 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
733 buffer ? buffer->wined3d_buffer : NULL);
735 wined3d_mutex_unlock();
738 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
739 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
741 struct d3d_device *device = impl_from_ID3D10Device(iface);
742 unsigned int i;
744 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
745 iface, start_slot, view_count, views);
747 wined3d_mutex_lock();
748 for (i = 0; i < view_count; ++i)
750 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
752 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
753 view ? view->wined3d_view : NULL);
755 wined3d_mutex_unlock();
758 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
759 ID3D10PixelShader *shader)
761 struct d3d_device *This = impl_from_ID3D10Device(iface);
762 struct d3d_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
764 TRACE("iface %p, shader %p\n", iface, shader);
766 wined3d_mutex_lock();
767 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
768 wined3d_mutex_unlock();
771 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
772 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
774 struct d3d_device *device = impl_from_ID3D10Device(iface);
775 unsigned int i;
777 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
778 iface, start_slot, sampler_count, samplers);
780 wined3d_mutex_lock();
781 for (i = 0; i < sampler_count; ++i)
783 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
785 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
786 sampler ? sampler->wined3d_sampler : NULL);
788 wined3d_mutex_unlock();
791 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
792 ID3D10VertexShader *shader)
794 struct d3d_device *This = impl_from_ID3D10Device(iface);
795 struct d3d_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
797 TRACE("iface %p, shader %p\n", iface, shader);
799 wined3d_mutex_lock();
800 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
801 wined3d_mutex_unlock();
804 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
805 UINT start_index_location, INT base_vertex_location)
807 struct d3d_device *This = impl_from_ID3D10Device(iface);
809 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
810 iface, index_count, start_index_location, base_vertex_location);
812 wined3d_mutex_lock();
813 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
814 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
815 wined3d_mutex_unlock();
818 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
819 UINT start_vertex_location)
821 struct d3d_device *This = impl_from_ID3D10Device(iface);
823 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
824 iface, vertex_count, start_vertex_location);
826 wined3d_mutex_lock();
827 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
828 wined3d_mutex_unlock();
831 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
832 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
834 struct d3d_device *device = impl_from_ID3D10Device(iface);
835 unsigned int i;
837 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
838 iface, start_slot, buffer_count, buffers);
840 wined3d_mutex_lock();
841 for (i = 0; i < buffer_count; ++i)
843 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
845 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
846 buffer ? buffer->wined3d_buffer : NULL);
848 wined3d_mutex_unlock();
851 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
852 ID3D10InputLayout *input_layout)
854 struct d3d_device *This = impl_from_ID3D10Device(iface);
855 struct d3d_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
857 TRACE("iface %p, input_layout %p\n", iface, input_layout);
859 wined3d_mutex_lock();
860 wined3d_device_set_vertex_declaration(This->wined3d_device,
861 layout ? layout->wined3d_decl : NULL);
862 wined3d_mutex_unlock();
865 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
866 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
868 struct d3d_device *This = impl_from_ID3D10Device(iface);
869 unsigned int i;
871 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
872 iface, start_slot, buffer_count, buffers, strides, offsets);
874 wined3d_mutex_lock();
875 for (i = 0; i < buffer_count; ++i)
877 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
879 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
880 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
882 wined3d_mutex_unlock();
885 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
886 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
888 struct d3d_device *This = impl_from_ID3D10Device(iface);
889 struct d3d_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
891 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
892 iface, buffer, debug_dxgi_format(format), offset);
894 wined3d_mutex_lock();
895 wined3d_device_set_index_buffer(This->wined3d_device,
896 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
897 wined3dformat_from_dxgi_format(format));
898 wined3d_mutex_unlock();
899 if (offset) FIXME("offset %u not supported.\n", offset);
902 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
903 UINT instance_index_count, UINT instance_count, UINT start_index_location,
904 INT base_vertex_location, UINT start_instance_location)
906 struct d3d_device *device = impl_from_ID3D10Device(iface);
908 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u, "
909 "base_vertex_location %d, start_instance_location %u.\n",
910 iface, instance_index_count, instance_count, start_index_location,
911 base_vertex_location, start_instance_location);
913 wined3d_mutex_lock();
914 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
915 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
916 instance_index_count, start_instance_location, instance_count);
917 wined3d_mutex_unlock();
920 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
921 UINT instance_vertex_count, UINT instance_count,
922 UINT start_vertex_location, UINT start_instance_location)
924 struct d3d_device *device = impl_from_ID3D10Device(iface);
926 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
927 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
928 start_vertex_location, start_instance_location);
930 wined3d_mutex_lock();
931 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
932 instance_vertex_count, start_instance_location, instance_count);
933 wined3d_mutex_unlock();
936 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
937 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
939 struct d3d_device *device = impl_from_ID3D10Device(iface);
940 unsigned int i;
942 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
943 iface, start_slot, buffer_count, buffers);
945 wined3d_mutex_lock();
946 for (i = 0; i < buffer_count; ++i)
948 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
950 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
951 buffer ? buffer->wined3d_buffer : NULL);
953 wined3d_mutex_unlock();
956 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
958 struct d3d_device *device = impl_from_ID3D10Device(iface);
959 struct d3d_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
961 TRACE("iface %p, shader %p.\n", iface, shader);
963 wined3d_mutex_lock();
964 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
965 wined3d_mutex_unlock();
968 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
969 D3D10_PRIMITIVE_TOPOLOGY topology)
971 struct d3d_device *This = impl_from_ID3D10Device(iface);
973 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
975 wined3d_mutex_lock();
976 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
977 wined3d_mutex_unlock();
980 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
981 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
983 struct d3d_device *device = impl_from_ID3D10Device(iface);
984 unsigned int i;
986 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
987 iface, start_slot, view_count, views);
989 wined3d_mutex_lock();
990 for (i = 0; i < view_count; ++i)
992 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
994 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
995 view ? view->wined3d_view : NULL);
997 wined3d_mutex_unlock();
1000 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
1001 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
1003 struct d3d_device *device = impl_from_ID3D10Device(iface);
1004 unsigned int i;
1006 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1007 iface, start_slot, sampler_count, samplers);
1009 wined3d_mutex_lock();
1010 for (i = 0; i < sampler_count; ++i)
1012 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
1014 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
1015 sampler ? sampler->wined3d_sampler : NULL);
1017 wined3d_mutex_unlock();
1020 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
1022 struct d3d_device *device = impl_from_ID3D10Device(iface);
1023 struct d3d10_query *query;
1025 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
1027 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
1028 wined3d_mutex_lock();
1029 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
1030 wined3d_mutex_unlock();
1033 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
1034 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
1036 struct d3d_device *device = impl_from_ID3D10Device(iface);
1037 unsigned int i;
1039 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1040 iface, start_slot, view_count, views);
1042 wined3d_mutex_lock();
1043 for (i = 0; i < view_count; ++i)
1045 struct d3d_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
1047 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
1048 view ? view->wined3d_view : NULL);
1050 wined3d_mutex_unlock();
1053 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
1054 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
1056 struct d3d_device *device = impl_from_ID3D10Device(iface);
1057 unsigned int i;
1059 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1060 iface, start_slot, sampler_count, samplers);
1062 wined3d_mutex_lock();
1063 for (i = 0; i < sampler_count; ++i)
1065 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
1067 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
1068 sampler ? sampler->wined3d_sampler : NULL);
1070 wined3d_mutex_unlock();
1073 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
1074 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
1075 ID3D10DepthStencilView *depth_stencil_view)
1077 struct d3d_device *device = impl_from_ID3D10Device(iface);
1078 struct d3d_depthstencil_view *dsv;
1079 unsigned int i;
1081 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1082 iface, render_target_view_count, render_target_views, depth_stencil_view);
1084 wined3d_mutex_lock();
1085 for (i = 0; i < render_target_view_count; ++i)
1087 struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
1089 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
1090 rtv ? rtv->wined3d_view : NULL, FALSE);
1092 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1094 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
1097 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
1098 wined3d_device_set_depth_stencil_view(device->wined3d_device,
1099 dsv ? dsv->wined3d_view : NULL);
1100 wined3d_mutex_unlock();
1103 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
1104 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
1106 struct d3d_device *device = impl_from_ID3D10Device(iface);
1107 const D3D10_BLEND_DESC *desc;
1109 TRACE("iface %p, blend_state %p, blend_factor {%.8e %.8e %.8e %.8e}, sample_mask 0x%08x.\n",
1110 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
1112 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
1113 FIXME("Ignoring blend factor {%.8e %.8e %.8e %.8e}.\n",
1114 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
1115 wined3d_mutex_lock();
1116 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
1117 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
1118 if (!(device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state)))
1120 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
1121 wined3d_device_set_render_state(device->wined3d_device,
1122 WINED3D_RS_COLORWRITEENABLE, D3D10_COLOR_WRITE_ENABLE_ALL);
1123 wined3d_device_set_render_state(device->wined3d_device,
1124 WINED3D_RS_COLORWRITEENABLE1, D3D10_COLOR_WRITE_ENABLE_ALL);
1125 wined3d_device_set_render_state(device->wined3d_device,
1126 WINED3D_RS_COLORWRITEENABLE2, D3D10_COLOR_WRITE_ENABLE_ALL);
1127 wined3d_device_set_render_state(device->wined3d_device,
1128 WINED3D_RS_COLORWRITEENABLE3, D3D10_COLOR_WRITE_ENABLE_ALL);
1129 wined3d_mutex_unlock();
1130 return;
1133 desc = &device->blend_state->desc;
1134 /* glSampleCoverage() */
1135 if (desc->AlphaToCoverageEnable)
1136 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
1137 /* glEnableIndexedEXT(GL_BLEND, ...) */
1138 FIXME("Per-rendertarget blend enable not implemented.\n");
1139 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, desc->BlendEnable[0]);
1140 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->SrcBlend);
1141 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->DestBlend);
1142 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->BlendOp);
1143 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
1144 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, desc->SrcBlendAlpha);
1145 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, desc->DestBlendAlpha);
1146 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, desc->BlendOpAlpha);
1147 FIXME("Color mask > 3 not implemented.\n");
1148 wined3d_device_set_render_state(device->wined3d_device,
1149 WINED3D_RS_COLORWRITEENABLE, desc->RenderTargetWriteMask[0]);
1150 wined3d_device_set_render_state(device->wined3d_device,
1151 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTargetWriteMask[1]);
1152 wined3d_device_set_render_state(device->wined3d_device,
1153 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTargetWriteMask[2]);
1154 wined3d_device_set_render_state(device->wined3d_device,
1155 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTargetWriteMask[3]);
1156 wined3d_mutex_unlock();
1159 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
1160 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
1162 struct d3d_device *device = impl_from_ID3D10Device(iface);
1164 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
1165 iface, depth_stencil_state, stencil_ref);
1167 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
1168 device->stencil_ref = stencil_ref;
1171 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
1172 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
1174 struct d3d_device *device = impl_from_ID3D10Device(iface);
1175 unsigned int count, i;
1177 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
1179 count = min(target_count, 4);
1180 wined3d_mutex_lock();
1181 for (i = 0; i < count; ++i)
1183 struct d3d_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
1185 wined3d_device_set_stream_output(device->wined3d_device, i,
1186 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
1189 for (i = count; i < 4; ++i)
1191 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1193 wined3d_mutex_unlock();
1196 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
1198 FIXME("iface %p stub!\n", iface);
1201 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
1203 struct d3d_device *device = impl_from_ID3D10Device(iface);
1204 const D3D11_RASTERIZER_DESC *desc;
1206 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1208 wined3d_mutex_lock();
1209 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
1211 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
1212 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
1213 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
1214 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
1215 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
1216 wined3d_mutex_unlock();
1217 return;
1220 desc = &device->rasterizer_state->desc;
1221 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
1222 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
1223 /* glFrontFace() */
1224 if (desc->FrontCounterClockwise)
1225 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
1226 /* OpenGL style depth bias. */
1227 if (desc->DepthBias || desc->SlopeScaledDepthBias)
1228 FIXME("Ignoring depth bias.\n");
1229 /* GL_DEPTH_CLAMP */
1230 if (!desc->DepthClipEnable)
1231 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
1232 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
1233 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
1234 wined3d_device_set_render_state(device->wined3d_device,
1235 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
1236 wined3d_mutex_unlock();
1239 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
1240 UINT viewport_count, const D3D10_VIEWPORT *viewports)
1242 struct d3d_device *device = impl_from_ID3D10Device(iface);
1243 struct wined3d_viewport wined3d_vp;
1245 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
1247 if (viewport_count > 1)
1248 FIXME("Multiple viewports not implemented.\n");
1250 if (!viewport_count)
1251 return;
1253 wined3d_vp.x = viewports[0].TopLeftX;
1254 wined3d_vp.y = viewports[0].TopLeftY;
1255 wined3d_vp.width = viewports[0].Width;
1256 wined3d_vp.height = viewports[0].Height;
1257 wined3d_vp.min_z = viewports[0].MinDepth;
1258 wined3d_vp.max_z = viewports[0].MaxDepth;
1260 wined3d_mutex_lock();
1261 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
1262 wined3d_mutex_unlock();
1265 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
1266 UINT rect_count, const D3D10_RECT *rects)
1268 struct d3d_device *device = impl_from_ID3D10Device(iface);
1270 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
1272 if (rect_count > 1)
1273 FIXME("Multiple scissor rects not implemented.\n");
1275 if (!rect_count)
1276 return;
1278 wined3d_mutex_lock();
1279 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
1280 wined3d_mutex_unlock();
1283 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
1284 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
1285 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
1287 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1288 struct d3d_device *device = impl_from_ID3D10Device(iface);
1289 struct wined3d_box wined3d_src_box;
1291 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
1292 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
1293 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
1294 src_resource, src_subresource_idx, src_box);
1296 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
1297 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
1298 wined3d_src_box.left = src_box->left;
1299 wined3d_src_box.top = src_box->top;
1300 wined3d_src_box.front = src_box->front;
1301 wined3d_src_box.right = src_box->right;
1302 wined3d_src_box.bottom = src_box->bottom;
1303 wined3d_src_box.back = src_box->back;
1304 wined3d_mutex_lock();
1305 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
1306 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, &wined3d_src_box);
1307 wined3d_mutex_unlock();
1310 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
1311 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
1313 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
1314 struct d3d_device *device = impl_from_ID3D10Device(iface);
1316 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
1318 wined3d_dst_resource = wined3d_resource_from_d3d10_resource(dst_resource);
1319 wined3d_src_resource = wined3d_resource_from_d3d10_resource(src_resource);
1320 wined3d_mutex_lock();
1321 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
1322 wined3d_mutex_unlock();
1325 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
1326 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
1327 const void *data, UINT row_pitch, UINT depth_pitch)
1329 struct d3d_device *device = impl_from_ID3D10Device(iface);
1330 struct wined3d_resource *wined3d_resource;
1331 struct wined3d_box wined3d_box;
1333 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
1334 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
1336 if (box)
1338 wined3d_box.left = box->left;
1339 wined3d_box.top = box->top;
1340 wined3d_box.front = box->front;
1341 wined3d_box.right = box->right;
1342 wined3d_box.bottom = box->bottom;
1343 wined3d_box.back = box->back;
1346 wined3d_resource = wined3d_resource_from_d3d10_resource(resource);
1347 wined3d_mutex_lock();
1348 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
1349 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
1350 wined3d_mutex_unlock();
1353 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
1354 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
1356 struct d3d_device *device = impl_from_ID3D10Device(iface);
1357 struct d3d_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
1358 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
1359 HRESULT hr;
1361 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
1362 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
1364 wined3d_mutex_lock();
1365 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
1366 ERR("Failed to clear view, hr %#x.\n", hr);
1367 wined3d_mutex_unlock();
1370 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
1371 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
1373 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
1374 iface, depth_stencil_view, flags, depth, stencil);
1377 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
1378 ID3D10ShaderResourceView *shader_resource_view)
1380 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
1383 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
1384 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
1385 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
1387 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, "
1388 "src_resource %p, src_subresource_idx %u, format %s stub!\n",
1389 iface, dst_resource, dst_subresource_idx,
1390 src_resource, src_subresource_idx, debug_dxgi_format(format));
1393 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
1394 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1396 struct d3d_device *device = impl_from_ID3D10Device(iface);
1397 unsigned int i;
1399 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1400 iface, start_slot, buffer_count, buffers);
1402 wined3d_mutex_lock();
1403 for (i = 0; i < buffer_count; ++i)
1405 struct wined3d_buffer *wined3d_buffer;
1406 struct d3d_buffer *buffer_impl;
1408 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
1410 buffers[i] = NULL;
1411 continue;
1414 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1415 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1416 ID3D10Buffer_AddRef(buffers[i]);
1418 wined3d_mutex_unlock();
1421 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
1422 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1424 struct d3d_device *device = impl_from_ID3D10Device(iface);
1425 unsigned int i;
1427 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1428 iface, start_slot, view_count, views);
1430 wined3d_mutex_lock();
1431 for (i = 0; i < view_count; ++i)
1433 struct wined3d_shader_resource_view *wined3d_view;
1434 struct d3d_shader_resource_view *view_impl;
1436 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
1438 views[i] = NULL;
1439 continue;
1442 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1443 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1444 ID3D10ShaderResourceView_AddRef(views[i]);
1446 wined3d_mutex_unlock();
1449 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
1451 struct d3d_device *device = impl_from_ID3D10Device(iface);
1452 struct d3d_pixel_shader *shader_impl;
1453 struct wined3d_shader *wined3d_shader;
1455 TRACE("iface %p, shader %p.\n", iface, shader);
1457 wined3d_mutex_lock();
1458 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
1460 wined3d_mutex_unlock();
1461 *shader = NULL;
1462 return;
1465 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1466 wined3d_mutex_unlock();
1467 *shader = &shader_impl->ID3D10PixelShader_iface;
1468 ID3D10PixelShader_AddRef(*shader);
1471 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
1472 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1474 struct d3d_device *device = impl_from_ID3D10Device(iface);
1475 unsigned int i;
1477 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1478 iface, start_slot, sampler_count, samplers);
1480 wined3d_mutex_lock();
1481 for (i = 0; i < sampler_count; ++i)
1483 struct d3d10_sampler_state *sampler_impl;
1484 struct wined3d_sampler *wined3d_sampler;
1486 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
1488 samplers[i] = NULL;
1489 continue;
1492 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1493 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1494 ID3D10SamplerState_AddRef(samplers[i]);
1496 wined3d_mutex_unlock();
1499 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
1501 struct d3d_device *device = impl_from_ID3D10Device(iface);
1502 struct d3d_vertex_shader *shader_impl;
1503 struct wined3d_shader *wined3d_shader;
1505 TRACE("iface %p, shader %p.\n", iface, shader);
1507 wined3d_mutex_lock();
1508 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
1510 wined3d_mutex_unlock();
1511 *shader = NULL;
1512 return;
1515 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1516 wined3d_mutex_unlock();
1517 *shader = &shader_impl->ID3D10VertexShader_iface;
1518 ID3D10VertexShader_AddRef(*shader);
1521 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
1522 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1524 struct d3d_device *device = impl_from_ID3D10Device(iface);
1525 unsigned int i;
1527 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1528 iface, start_slot, buffer_count, buffers);
1530 wined3d_mutex_lock();
1531 for (i = 0; i < buffer_count; ++i)
1533 struct wined3d_buffer *wined3d_buffer;
1534 struct d3d_buffer *buffer_impl;
1536 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
1538 buffers[i] = NULL;
1539 continue;
1542 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1543 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1544 ID3D10Buffer_AddRef(buffers[i]);
1546 wined3d_mutex_unlock();
1549 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
1551 struct d3d_device *device = impl_from_ID3D10Device(iface);
1552 struct wined3d_vertex_declaration *wined3d_declaration;
1553 struct d3d_input_layout *input_layout_impl;
1555 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
1557 wined3d_mutex_lock();
1558 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
1560 wined3d_mutex_unlock();
1561 *input_layout = NULL;
1562 return;
1565 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
1566 wined3d_mutex_unlock();
1567 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
1568 ID3D10InputLayout_AddRef(*input_layout);
1571 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
1572 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
1574 struct d3d_device *device = impl_from_ID3D10Device(iface);
1575 unsigned int i;
1577 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
1578 iface, start_slot, buffer_count, buffers, strides, offsets);
1580 wined3d_mutex_lock();
1581 for (i = 0; i < buffer_count; ++i)
1583 struct wined3d_buffer *wined3d_buffer;
1584 struct d3d_buffer *buffer_impl;
1586 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
1587 &wined3d_buffer, &offsets[i], &strides[i])))
1588 ERR("Failed to get vertex buffer.\n");
1590 if (!wined3d_buffer)
1592 buffers[i] = NULL;
1593 continue;
1596 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1597 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1598 ID3D10Buffer_AddRef(buffers[i]);
1600 wined3d_mutex_unlock();
1603 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
1604 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1606 struct d3d_device *device = impl_from_ID3D10Device(iface);
1607 enum wined3d_format_id wined3d_format;
1608 struct wined3d_buffer *wined3d_buffer;
1609 struct d3d_buffer *buffer_impl;
1611 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1613 wined3d_mutex_lock();
1614 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
1615 *format = dxgi_format_from_wined3dformat(wined3d_format);
1616 *offset = 0; /* FIXME */
1617 if (!wined3d_buffer)
1619 wined3d_mutex_unlock();
1620 *buffer = NULL;
1621 return;
1624 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1625 wined3d_mutex_unlock();
1626 *buffer = &buffer_impl->ID3D10Buffer_iface;
1627 ID3D10Buffer_AddRef(*buffer);
1630 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
1631 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1633 struct d3d_device *device = impl_from_ID3D10Device(iface);
1634 unsigned int i;
1636 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1637 iface, start_slot, buffer_count, buffers);
1639 wined3d_mutex_lock();
1640 for (i = 0; i < buffer_count; ++i)
1642 struct wined3d_buffer *wined3d_buffer;
1643 struct d3d_buffer *buffer_impl;
1645 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1647 buffers[i] = NULL;
1648 continue;
1651 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1652 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1653 ID3D10Buffer_AddRef(buffers[i]);
1655 wined3d_mutex_unlock();
1658 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
1660 struct d3d_device *device = impl_from_ID3D10Device(iface);
1661 struct d3d_geometry_shader *shader_impl;
1662 struct wined3d_shader *wined3d_shader;
1664 TRACE("iface %p, shader %p.\n", iface, shader);
1666 wined3d_mutex_lock();
1667 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1669 wined3d_mutex_unlock();
1670 *shader = NULL;
1671 return;
1674 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1675 wined3d_mutex_unlock();
1676 *shader = &shader_impl->ID3D10GeometryShader_iface;
1677 ID3D10GeometryShader_AddRef(*shader);
1680 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
1681 D3D10_PRIMITIVE_TOPOLOGY *topology)
1683 struct d3d_device *This = impl_from_ID3D10Device(iface);
1685 TRACE("iface %p, topology %p\n", iface, topology);
1687 wined3d_mutex_lock();
1688 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
1689 wined3d_mutex_unlock();
1692 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
1693 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1695 struct d3d_device *device = impl_from_ID3D10Device(iface);
1696 unsigned int i;
1698 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1699 iface, start_slot, view_count, views);
1701 wined3d_mutex_lock();
1702 for (i = 0; i < view_count; ++i)
1704 struct wined3d_shader_resource_view *wined3d_view;
1705 struct d3d_shader_resource_view *view_impl;
1707 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1709 views[i] = NULL;
1710 continue;
1713 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1714 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1715 ID3D10ShaderResourceView_AddRef(views[i]);
1717 wined3d_mutex_unlock();
1720 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
1721 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1723 struct d3d_device *device = impl_from_ID3D10Device(iface);
1724 unsigned int i;
1726 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1727 iface, start_slot, sampler_count, samplers);
1729 wined3d_mutex_lock();
1730 for (i = 0; i < sampler_count; ++i)
1732 struct d3d10_sampler_state *sampler_impl;
1733 struct wined3d_sampler *wined3d_sampler;
1735 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1737 samplers[i] = NULL;
1738 continue;
1741 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1742 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1743 ID3D10SamplerState_AddRef(samplers[i]);
1745 wined3d_mutex_unlock();
1748 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
1749 ID3D10Predicate **predicate, BOOL *value)
1751 struct d3d_device *device = impl_from_ID3D10Device(iface);
1752 struct wined3d_query *wined3d_predicate;
1753 struct d3d10_query *predicate_impl;
1755 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1757 wined3d_mutex_lock();
1758 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1760 wined3d_mutex_unlock();
1761 *predicate = NULL;
1762 return;
1765 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1766 wined3d_mutex_unlock();
1767 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
1768 ID3D10Predicate_AddRef(*predicate);
1771 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
1772 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1774 struct d3d_device *device = impl_from_ID3D10Device(iface);
1775 unsigned int i;
1777 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1778 iface, start_slot, view_count, views);
1780 wined3d_mutex_lock();
1781 for (i = 0; i < view_count; ++i)
1783 struct wined3d_shader_resource_view *wined3d_view;
1784 struct d3d_shader_resource_view *view_impl;
1786 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1788 views[i] = NULL;
1789 continue;
1792 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1793 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1794 ID3D10ShaderResourceView_AddRef(views[i]);
1796 wined3d_mutex_unlock();
1799 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1800 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1802 struct d3d_device *device = impl_from_ID3D10Device(iface);
1803 unsigned int i;
1805 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1806 iface, start_slot, sampler_count, samplers);
1808 wined3d_mutex_lock();
1809 for (i = 0; i < sampler_count; ++i)
1811 struct d3d10_sampler_state *sampler_impl;
1812 struct wined3d_sampler *wined3d_sampler;
1814 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1816 samplers[i] = NULL;
1817 continue;
1820 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1821 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1822 ID3D10SamplerState_AddRef(samplers[i]);
1824 wined3d_mutex_unlock();
1827 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1828 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1830 struct d3d_device *device = impl_from_ID3D10Device(iface);
1831 struct wined3d_rendertarget_view *wined3d_view;
1833 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1834 iface, view_count, render_target_views, depth_stencil_view);
1836 wined3d_mutex_lock();
1837 if (render_target_views)
1839 struct d3d_rendertarget_view *view_impl;
1840 unsigned int i;
1842 for (i = 0; i < view_count; ++i)
1844 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1845 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1847 render_target_views[i] = NULL;
1848 continue;
1851 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1852 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1856 if (depth_stencil_view)
1858 struct d3d_depthstencil_view *view_impl;
1860 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1861 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1863 *depth_stencil_view = NULL;
1865 else
1867 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1868 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1871 wined3d_mutex_unlock();
1874 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1875 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1877 struct d3d_device *device = impl_from_ID3D10Device(iface);
1879 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1880 iface, blend_state, blend_factor, sample_mask);
1882 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1883 ID3D10BlendState_AddRef(*blend_state);
1884 wined3d_mutex_lock();
1885 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1886 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1887 wined3d_mutex_unlock();
1890 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1891 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1893 struct d3d_device *device = impl_from_ID3D10Device(iface);
1895 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1896 iface, depth_stencil_state, stencil_ref);
1898 if ((*depth_stencil_state = device->depth_stencil_state
1899 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1900 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1901 *stencil_ref = device->stencil_ref;
1904 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1905 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1907 struct d3d_device *device = impl_from_ID3D10Device(iface);
1908 unsigned int i;
1910 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1911 iface, buffer_count, buffers, offsets);
1913 wined3d_mutex_lock();
1914 for (i = 0; i < buffer_count; ++i)
1916 struct wined3d_buffer *wined3d_buffer;
1917 struct d3d_buffer *buffer_impl;
1919 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1921 buffers[i] = NULL;
1922 continue;
1925 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1926 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1927 ID3D10Buffer_AddRef(buffers[i]);
1929 wined3d_mutex_unlock();
1932 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1934 struct d3d_device *device = impl_from_ID3D10Device(iface);
1936 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1938 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1939 ID3D10RasterizerState_AddRef(*rasterizer_state);
1942 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1943 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1945 struct d3d_device *device = impl_from_ID3D10Device(iface);
1946 struct wined3d_viewport wined3d_vp;
1948 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1950 if (!viewports)
1952 *viewport_count = 1;
1953 return;
1956 if (!*viewport_count)
1957 return;
1959 wined3d_mutex_lock();
1960 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1961 wined3d_mutex_unlock();
1963 viewports[0].TopLeftX = wined3d_vp.x;
1964 viewports[0].TopLeftY = wined3d_vp.y;
1965 viewports[0].Width = wined3d_vp.width;
1966 viewports[0].Height = wined3d_vp.height;
1967 viewports[0].MinDepth = wined3d_vp.min_z;
1968 viewports[0].MaxDepth = wined3d_vp.max_z;
1970 if (*viewport_count > 1)
1971 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1974 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1976 struct d3d_device *device = impl_from_ID3D10Device(iface);
1978 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1980 if (!rects)
1982 *rect_count = 1;
1983 return;
1986 if (!*rect_count)
1987 return;
1989 wined3d_mutex_lock();
1990 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1991 wined3d_mutex_unlock();
1992 if (*rect_count > 1)
1993 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1996 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1998 TRACE("iface %p.\n", iface);
2000 /* In the current implementation the device is never removed, so we can
2001 * just return S_OK here. */
2003 return S_OK;
2006 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
2008 FIXME("iface %p, flags %#x stub!\n", iface, flags);
2010 return E_NOTIMPL;
2013 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
2015 FIXME("iface %p stub!\n", iface);
2017 return 0;
2020 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
2021 REFGUID guid, UINT *data_size, void *data)
2023 IDXGIDevice *dxgi_device;
2024 HRESULT hr;
2026 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
2027 iface, debugstr_guid(guid), data_size, data);
2029 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2030 return hr;
2031 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
2032 IDXGIDevice_Release(dxgi_device);
2034 return hr;
2037 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
2038 REFGUID guid, UINT data_size, const void *data)
2040 IDXGIDevice *dxgi_device;
2041 HRESULT hr;
2043 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
2044 iface, debugstr_guid(guid), data_size, data);
2046 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2047 return hr;
2048 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
2049 IDXGIDevice_Release(dxgi_device);
2051 return hr;
2054 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
2055 REFGUID guid, const IUnknown *data)
2057 IDXGIDevice *dxgi_device;
2058 HRESULT hr;
2060 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
2062 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
2063 return hr;
2064 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
2065 IDXGIDevice_Release(dxgi_device);
2067 return hr;
2070 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
2072 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
2073 struct d3d_device *device = impl_from_ID3D10Device(iface);
2074 unsigned int i;
2076 TRACE("iface %p.\n", iface);
2078 wined3d_mutex_lock();
2079 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2080 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2082 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
2084 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2086 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
2088 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2090 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
2092 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
2093 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2095 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
2097 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2099 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
2101 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2103 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
2105 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2106 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
2108 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
2110 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
2112 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
2114 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
2116 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
2118 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
2120 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
2122 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
2123 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
2124 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
2125 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
2127 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
2129 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
2130 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
2131 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
2132 ID3D10Device1_RSSetViewports(iface, 0, NULL);
2133 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
2134 ID3D10Device1_RSSetState(iface, NULL);
2135 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
2137 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
2139 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
2140 wined3d_mutex_unlock();
2143 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
2145 FIXME("iface %p stub!\n", iface);
2148 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
2149 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
2151 struct d3d_device *device = impl_from_ID3D10Device(iface);
2152 D3D11_BUFFER_DESC d3d11_desc;
2153 struct d3d_buffer *object;
2154 HRESULT hr;
2156 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
2158 d3d11_desc.ByteWidth = desc->ByteWidth;
2159 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2160 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2161 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2162 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2163 d3d11_desc.StructureByteStride = 0;
2165 if (FAILED(hr = d3d_buffer_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2166 return hr;
2168 *buffer = &object->ID3D10Buffer_iface;
2170 return S_OK;
2173 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
2174 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
2176 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
2178 return E_NOTIMPL;
2181 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
2182 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2183 ID3D10Texture2D **texture)
2185 struct d3d_device *device = impl_from_ID3D10Device(iface);
2186 D3D11_TEXTURE2D_DESC d3d11_desc;
2187 struct d3d_texture2d *object;
2188 HRESULT hr;
2190 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2192 d3d11_desc.Width = desc->Width;
2193 d3d11_desc.Height = desc->Height;
2194 d3d11_desc.MipLevels = desc->MipLevels;
2195 d3d11_desc.ArraySize = desc->ArraySize;
2196 d3d11_desc.Format = desc->Format;
2197 d3d11_desc.SampleDesc = desc->SampleDesc;
2198 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2199 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2200 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2201 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2203 if (FAILED(hr = d3d_texture2d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2204 return hr;
2206 *texture = &object->ID3D10Texture2D_iface;
2208 return S_OK;
2211 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
2212 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
2213 ID3D10Texture3D **texture)
2215 struct d3d_device *device = impl_from_ID3D10Device(iface);
2216 D3D11_TEXTURE3D_DESC d3d11_desc;
2217 struct d3d_texture3d *object;
2218 HRESULT hr;
2220 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
2222 d3d11_desc.Width = desc->Width;
2223 d3d11_desc.Height = desc->Height;
2224 d3d11_desc.Depth = desc->Depth;
2225 d3d11_desc.MipLevels = desc->MipLevels;
2226 d3d11_desc.Format = desc->Format;
2227 d3d11_desc.Usage = d3d11_usage_from_d3d10_usage(desc->Usage);
2228 d3d11_desc.BindFlags = d3d11_bind_flags_from_d3d10_bind_flags(desc->BindFlags);
2229 d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags);
2230 d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
2232 if (FAILED(hr = d3d_texture3d_create(device, &d3d11_desc, (const D3D11_SUBRESOURCE_DATA *)data, &object)))
2233 return hr;
2235 *texture = &object->ID3D10Texture3D_iface;
2237 return S_OK;
2240 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
2241 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
2243 struct d3d_device *device = impl_from_ID3D10Device(iface);
2244 struct d3d_shader_resource_view *object;
2245 ID3D11Resource *d3d11_resource;
2246 HRESULT hr;
2248 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2250 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
2252 ERR("Resource does not implement ID3D11Resource.\n");
2253 return E_FAIL;
2256 hr = d3d_shader_resource_view_create(device, d3d11_resource, (const D3D11_SHADER_RESOURCE_VIEW_DESC *)desc,
2257 &object);
2258 ID3D11Resource_Release(d3d11_resource);
2259 if (FAILED(hr))
2260 return hr;
2262 *view = &object->ID3D10ShaderResourceView_iface;
2264 return S_OK;
2267 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
2268 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
2270 struct d3d_device *device = impl_from_ID3D10Device(iface);
2271 struct d3d_rendertarget_view *object;
2272 ID3D11Resource *d3d11_resource;
2273 HRESULT hr;
2275 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2277 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
2279 ERR("Resource does not implement ID3D11Resource.\n");
2280 return E_FAIL;
2283 hr = d3d_rendertarget_view_create(device, d3d11_resource, (const D3D11_RENDER_TARGET_VIEW_DESC *)desc, &object);
2284 ID3D11Resource_Release(d3d11_resource);
2285 if (FAILED(hr))
2286 return hr;
2288 *view = &object->ID3D10RenderTargetView_iface;
2290 return S_OK;
2293 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
2294 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
2296 struct d3d_device *device = impl_from_ID3D10Device(iface);
2297 D3D11_DEPTH_STENCIL_VIEW_DESC d3d11_desc;
2298 struct d3d_depthstencil_view *object;
2299 ID3D11Resource *d3d11_resource;
2300 HRESULT hr;
2302 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
2304 if (desc)
2306 d3d11_desc.Format = desc->Format;
2307 d3d11_desc.ViewDimension = desc->ViewDimension;
2308 d3d11_desc.Flags = 0;
2309 memcpy(&d3d11_desc.u, &desc->u, sizeof(d3d11_desc.u));
2312 if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
2314 ERR("Resource does not implement ID3D11Resource.\n");
2315 return E_FAIL;
2318 hr = d3d_depthstencil_view_create(device, d3d11_resource, desc ? &d3d11_desc : NULL, &object);
2319 ID3D11Resource_Release(d3d11_resource);
2320 if (FAILED(hr))
2321 return hr;
2323 *view = &object->ID3D10DepthStencilView_iface;
2325 return S_OK;
2328 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
2329 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
2330 const void *shader_byte_code, SIZE_T shader_byte_code_length,
2331 ID3D10InputLayout **input_layout)
2333 struct d3d_device *device = impl_from_ID3D10Device(iface);
2334 struct d3d_input_layout *object;
2335 HRESULT hr;
2337 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p, "
2338 "shader_byte_code_length %lu, input_layout %p\n",
2339 iface, element_descs, element_count, shader_byte_code,
2340 shader_byte_code_length, input_layout);
2342 if (FAILED(hr = d3d_input_layout_create(device, (const D3D11_INPUT_ELEMENT_DESC *)element_descs, element_count,
2343 shader_byte_code, shader_byte_code_length, &object)))
2344 return hr;
2346 *input_layout = &object->ID3D10InputLayout_iface;
2348 return S_OK;
2351 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
2352 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
2354 struct d3d_device *device = impl_from_ID3D10Device(iface);
2355 struct d3d_vertex_shader *object;
2356 HRESULT hr;
2358 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
2359 iface, byte_code, byte_code_length, shader);
2361 if (FAILED(hr = d3d_vertex_shader_create(device, byte_code, byte_code_length, &object)))
2362 return hr;
2364 *shader = &object->ID3D10VertexShader_iface;
2366 return S_OK;
2369 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
2370 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
2372 struct d3d_device *device = impl_from_ID3D10Device(iface);
2373 struct d3d_geometry_shader *object;
2374 HRESULT hr;
2376 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
2377 iface, byte_code, byte_code_length, shader);
2379 if (FAILED(hr = d3d_geometry_shader_create(device, byte_code, byte_code_length, &object)))
2380 return hr;
2382 *shader = &object->ID3D10GeometryShader_iface;
2384 return S_OK;
2387 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
2388 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
2389 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
2391 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p, "
2392 "output_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
2393 iface, byte_code, byte_code_length, output_stream_decls,
2394 output_stream_decl_count, output_stream_stride, shader);
2396 return E_NOTIMPL;
2399 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
2400 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
2402 struct d3d_device *device = impl_from_ID3D10Device(iface);
2403 struct d3d_pixel_shader *object;
2404 HRESULT hr;
2406 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
2407 iface, byte_code, byte_code_length, shader);
2409 if (FAILED(hr = d3d_pixel_shader_create(device, byte_code, byte_code_length, &object)))
2410 return hr;
2412 *shader = &object->ID3D10PixelShader_iface;
2414 return S_OK;
2417 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
2418 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
2420 struct d3d_device *device = impl_from_ID3D10Device(iface);
2421 struct d3d10_blend_state *object;
2422 struct wine_rb_entry *entry;
2423 HRESULT hr;
2425 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
2427 if (!desc)
2428 return E_INVALIDARG;
2430 wined3d_mutex_lock();
2431 if ((entry = wine_rb_get(&device->blend_states, desc)))
2433 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
2435 TRACE("Returning existing blend state %p.\n", object);
2436 *blend_state = &object->ID3D10BlendState_iface;
2437 ID3D10BlendState_AddRef(*blend_state);
2438 wined3d_mutex_unlock();
2440 return S_OK;
2442 wined3d_mutex_unlock();
2444 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2445 if (!object)
2446 return E_OUTOFMEMORY;
2448 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
2450 WARN("Failed to initialize blend state, hr %#x.\n", hr);
2451 HeapFree(GetProcessHeap(), 0, object);
2452 return hr;
2455 TRACE("Created blend state %p.\n", object);
2456 *blend_state = &object->ID3D10BlendState_iface;
2458 return S_OK;
2461 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
2462 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
2464 struct d3d_device *device = impl_from_ID3D10Device(iface);
2465 ID3D11DepthStencilState *d3d11_depth_stencil_state;
2466 HRESULT hr;
2468 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
2470 if (FAILED(hr = d3d11_device_CreateDepthStencilState(&device->ID3D11Device_iface,
2471 (const D3D11_DEPTH_STENCIL_DESC *)desc, &d3d11_depth_stencil_state)))
2472 return hr;
2474 hr = ID3D11DepthStencilState_QueryInterface(d3d11_depth_stencil_state, &IID_ID3D10DepthStencilState,
2475 (void **)depth_stencil_state);
2476 ID3D11DepthStencilState_Release(d3d11_depth_stencil_state);
2477 return hr;
2480 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
2481 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
2483 struct d3d_device *device = impl_from_ID3D10Device(iface);
2484 ID3D11RasterizerState *d3d11_rasterizer_state;
2485 HRESULT hr;
2487 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
2489 if (FAILED(hr = d3d11_device_CreateRasterizerState(&device->ID3D11Device_iface,
2490 (const D3D11_RASTERIZER_DESC *)desc, &d3d11_rasterizer_state)))
2491 return hr;
2493 hr = ID3D11RasterizerState_QueryInterface(d3d11_rasterizer_state,
2494 &IID_ID3D10RasterizerState, (void **)rasterizer_state);
2495 ID3D11RasterizerState_Release(d3d11_rasterizer_state);
2496 return hr;
2499 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
2500 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
2502 struct d3d_device *device = impl_from_ID3D10Device(iface);
2503 struct d3d10_sampler_state *object;
2504 struct wine_rb_entry *entry;
2505 HRESULT hr;
2507 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2509 if (!desc)
2510 return E_INVALIDARG;
2512 wined3d_mutex_lock();
2513 if ((entry = wine_rb_get(&device->sampler_states, desc)))
2515 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
2517 TRACE("Returning existing sampler state %p.\n", object);
2518 *sampler_state = &object->ID3D10SamplerState_iface;
2519 ID3D10SamplerState_AddRef(*sampler_state);
2520 wined3d_mutex_unlock();
2522 return S_OK;
2524 wined3d_mutex_unlock();
2526 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2527 if (!object)
2528 return E_OUTOFMEMORY;
2530 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
2532 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2533 HeapFree(GetProcessHeap(), 0, object);
2534 return hr;
2537 TRACE("Created sampler state %p.\n", object);
2538 *sampler_state = &object->ID3D10SamplerState_iface;
2540 return S_OK;
2543 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
2544 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
2546 struct d3d_device *device = impl_from_ID3D10Device(iface);
2547 struct d3d10_query *object;
2548 HRESULT hr;
2550 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2552 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2553 return E_OUTOFMEMORY;
2555 if (FAILED(hr = d3d10_query_init(object, device, desc, FALSE)))
2557 WARN("Failed to initialize query, hr %#x.\n", hr);
2558 HeapFree(GetProcessHeap(), 0, object);
2559 return hr;
2562 TRACE("Created query %p.\n", object);
2563 *query = &object->ID3D10Query_iface;
2565 return S_OK;
2568 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
2569 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
2571 struct d3d_device *device = impl_from_ID3D10Device(iface);
2572 struct d3d10_query *object;
2573 HRESULT hr;
2575 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2577 if (!desc)
2578 return E_INVALIDARG;
2580 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
2582 WARN("Query type %#x is not a predicate.\n", desc->Query);
2583 return E_INVALIDARG;
2586 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2587 return E_OUTOFMEMORY;
2589 if (FAILED(hr = d3d10_query_init(object, device, desc, TRUE)))
2591 WARN("Failed to initialize predicate, hr %#x.\n", hr);
2592 HeapFree(GetProcessHeap(), 0, object);
2593 return hr;
2596 TRACE("Created predicate %p.\n", object);
2597 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
2599 return S_OK;
2602 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
2603 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
2605 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2607 return E_NOTIMPL;
2610 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
2611 DXGI_FORMAT format, UINT *format_support)
2613 FIXME("iface %p, format %s, format_support %p stub!\n",
2614 iface, debug_dxgi_format(format), format_support);
2616 return E_NOTIMPL;
2619 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
2620 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2622 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
2623 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2625 return E_NOTIMPL;
2628 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
2630 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
2633 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
2634 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
2635 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
2637 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p, "
2638 "units %p, units_length %p, description %p, description_length %p stub!\n",
2639 iface, desc, type, active_counters, name, name_length,
2640 units, units_length, description, description_length);
2642 return E_NOTIMPL;
2645 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
2647 FIXME("iface %p stub!\n", iface);
2649 return 0;
2652 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
2653 HANDLE resource_handle, REFIID guid, void **resource)
2655 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
2656 iface, resource_handle, debugstr_guid(guid), resource);
2658 return E_NOTIMPL;
2661 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
2663 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
2666 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
2668 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
2671 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
2672 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
2674 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
2676 return E_NOTIMPL;
2679 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
2680 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
2682 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
2684 return E_NOTIMPL;
2687 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
2689 FIXME("iface %p stub!\n", iface);
2691 return D3D10_FEATURE_LEVEL_10_1;
2694 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
2696 /* IUnknown methods */
2697 d3d10_device_QueryInterface,
2698 d3d10_device_AddRef,
2699 d3d10_device_Release,
2700 /* ID3D10Device methods */
2701 d3d10_device_VSSetConstantBuffers,
2702 d3d10_device_PSSetShaderResources,
2703 d3d10_device_PSSetShader,
2704 d3d10_device_PSSetSamplers,
2705 d3d10_device_VSSetShader,
2706 d3d10_device_DrawIndexed,
2707 d3d10_device_Draw,
2708 d3d10_device_PSSetConstantBuffers,
2709 d3d10_device_IASetInputLayout,
2710 d3d10_device_IASetVertexBuffers,
2711 d3d10_device_IASetIndexBuffer,
2712 d3d10_device_DrawIndexedInstanced,
2713 d3d10_device_DrawInstanced,
2714 d3d10_device_GSSetConstantBuffers,
2715 d3d10_device_GSSetShader,
2716 d3d10_device_IASetPrimitiveTopology,
2717 d3d10_device_VSSetShaderResources,
2718 d3d10_device_VSSetSamplers,
2719 d3d10_device_SetPredication,
2720 d3d10_device_GSSetShaderResources,
2721 d3d10_device_GSSetSamplers,
2722 d3d10_device_OMSetRenderTargets,
2723 d3d10_device_OMSetBlendState,
2724 d3d10_device_OMSetDepthStencilState,
2725 d3d10_device_SOSetTargets,
2726 d3d10_device_DrawAuto,
2727 d3d10_device_RSSetState,
2728 d3d10_device_RSSetViewports,
2729 d3d10_device_RSSetScissorRects,
2730 d3d10_device_CopySubresourceRegion,
2731 d3d10_device_CopyResource,
2732 d3d10_device_UpdateSubresource,
2733 d3d10_device_ClearRenderTargetView,
2734 d3d10_device_ClearDepthStencilView,
2735 d3d10_device_GenerateMips,
2736 d3d10_device_ResolveSubresource,
2737 d3d10_device_VSGetConstantBuffers,
2738 d3d10_device_PSGetShaderResources,
2739 d3d10_device_PSGetShader,
2740 d3d10_device_PSGetSamplers,
2741 d3d10_device_VSGetShader,
2742 d3d10_device_PSGetConstantBuffers,
2743 d3d10_device_IAGetInputLayout,
2744 d3d10_device_IAGetVertexBuffers,
2745 d3d10_device_IAGetIndexBuffer,
2746 d3d10_device_GSGetConstantBuffers,
2747 d3d10_device_GSGetShader,
2748 d3d10_device_IAGetPrimitiveTopology,
2749 d3d10_device_VSGetShaderResources,
2750 d3d10_device_VSGetSamplers,
2751 d3d10_device_GetPredication,
2752 d3d10_device_GSGetShaderResources,
2753 d3d10_device_GSGetSamplers,
2754 d3d10_device_OMGetRenderTargets,
2755 d3d10_device_OMGetBlendState,
2756 d3d10_device_OMGetDepthStencilState,
2757 d3d10_device_SOGetTargets,
2758 d3d10_device_RSGetState,
2759 d3d10_device_RSGetViewports,
2760 d3d10_device_RSGetScissorRects,
2761 d3d10_device_GetDeviceRemovedReason,
2762 d3d10_device_SetExceptionMode,
2763 d3d10_device_GetExceptionMode,
2764 d3d10_device_GetPrivateData,
2765 d3d10_device_SetPrivateData,
2766 d3d10_device_SetPrivateDataInterface,
2767 d3d10_device_ClearState,
2768 d3d10_device_Flush,
2769 d3d10_device_CreateBuffer,
2770 d3d10_device_CreateTexture1D,
2771 d3d10_device_CreateTexture2D,
2772 d3d10_device_CreateTexture3D,
2773 d3d10_device_CreateShaderResourceView,
2774 d3d10_device_CreateRenderTargetView,
2775 d3d10_device_CreateDepthStencilView,
2776 d3d10_device_CreateInputLayout,
2777 d3d10_device_CreateVertexShader,
2778 d3d10_device_CreateGeometryShader,
2779 d3d10_device_CreateGeometryShaderWithStreamOutput,
2780 d3d10_device_CreatePixelShader,
2781 d3d10_device_CreateBlendState,
2782 d3d10_device_CreateDepthStencilState,
2783 d3d10_device_CreateRasterizerState,
2784 d3d10_device_CreateSamplerState,
2785 d3d10_device_CreateQuery,
2786 d3d10_device_CreatePredicate,
2787 d3d10_device_CreateCounter,
2788 d3d10_device_CheckFormatSupport,
2789 d3d10_device_CheckMultisampleQualityLevels,
2790 d3d10_device_CheckCounterInfo,
2791 d3d10_device_CheckCounter,
2792 d3d10_device_GetCreationFlags,
2793 d3d10_device_OpenSharedResource,
2794 d3d10_device_SetTextFilterSize,
2795 d3d10_device_GetTextFilterSize,
2796 d3d10_device_CreateShaderResourceView1,
2797 d3d10_device_CreateBlendState1,
2798 d3d10_device_GetFeatureLevel,
2801 static const struct IUnknownVtbl d3d_device_inner_unknown_vtbl =
2803 /* IUnknown methods */
2804 d3d_device_inner_QueryInterface,
2805 d3d_device_inner_AddRef,
2806 d3d_device_inner_Release,
2809 /* ID3D10Multithread methods */
2811 static inline struct d3d_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
2813 return CONTAINING_RECORD(iface, struct d3d_device, ID3D10Multithread_iface);
2816 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
2818 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2820 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2822 return IUnknown_QueryInterface(device->outer_unk, iid, out);
2825 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
2827 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2829 TRACE("iface %p.\n", iface);
2831 return IUnknown_AddRef(device->outer_unk);
2834 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2836 struct d3d_device *device = impl_from_ID3D10Multithread(iface);
2838 TRACE("iface %p.\n", iface);
2840 return IUnknown_Release(device->outer_unk);
2843 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2845 TRACE("iface %p.\n", iface);
2847 wined3d_mutex_lock();
2850 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2852 TRACE("iface %p.\n", iface);
2854 wined3d_mutex_unlock();
2857 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2859 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2861 return TRUE;
2864 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2866 FIXME("iface %p stub!\n", iface);
2868 return TRUE;
2871 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2873 d3d10_multithread_QueryInterface,
2874 d3d10_multithread_AddRef,
2875 d3d10_multithread_Release,
2876 d3d10_multithread_Enter,
2877 d3d10_multithread_Leave,
2878 d3d10_multithread_SetMultithreadProtected,
2879 d3d10_multithread_GetMultithreadProtected,
2882 /* IWineDXGIDeviceParent IUnknown methods */
2884 static inline struct d3d_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2886 return CONTAINING_RECORD(iface, struct d3d_device, IWineDXGIDeviceParent_iface);
2889 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2890 REFIID riid, void **ppv)
2892 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2893 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2896 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2898 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2899 return IUnknown_AddRef(device->outer_unk);
2902 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2904 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2905 return IUnknown_Release(device->outer_unk);
2908 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2909 IWineDXGIDeviceParent *iface)
2911 struct d3d_device *device = device_from_dxgi_device_parent(iface);
2912 return &device->device_parent;
2915 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2917 /* IUnknown methods */
2918 dxgi_device_parent_QueryInterface,
2919 dxgi_device_parent_AddRef,
2920 dxgi_device_parent_Release,
2921 /* IWineDXGIDeviceParent methods */
2922 dxgi_device_parent_get_wined3d_device_parent,
2925 static inline struct d3d_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2927 return CONTAINING_RECORD(device_parent, struct d3d_device, device_parent);
2930 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2931 struct wined3d_device *wined3d_device)
2933 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2935 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2937 wined3d_device_incref(wined3d_device);
2938 device->wined3d_device = wined3d_device;
2941 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2943 TRACE("device_parent %p.\n", device_parent);
2946 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2948 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2951 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2952 void *container_parent, struct wined3d_surface *surface, void **parent,
2953 const struct wined3d_parent_ops **parent_ops)
2955 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2956 device_parent, container_parent, surface, parent, parent_ops);
2958 *parent = NULL;
2959 *parent_ops = &d3d10_null_wined3d_parent_ops;
2961 return S_OK;
2964 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2965 void *container_parent, struct wined3d_volume *volume, void **parent,
2966 const struct wined3d_parent_ops **parent_ops)
2968 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2969 device_parent, container_parent, volume, parent, parent_ops);
2971 *parent = NULL;
2972 *parent_ops = &d3d10_null_wined3d_parent_ops;
2974 return S_OK;
2977 static HRESULT CDECL device_parent_create_swapchain_texture(struct wined3d_device_parent *device_parent,
2978 void *container_parent, const struct wined3d_resource_desc *wined3d_desc,
2979 struct wined3d_texture **wined3d_texture)
2981 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
2982 struct d3d_texture2d *texture;
2983 ID3D10Texture2D *texture_iface;
2984 D3D10_TEXTURE2D_DESC desc;
2985 HRESULT hr;
2987 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, wined3d_texture %p partial stub!\n",
2988 device_parent, container_parent, wined3d_desc, wined3d_texture);
2990 FIXME("Implement DXGI<->wined3d usage conversion\n");
2992 desc.Width = wined3d_desc->width;
2993 desc.Height = wined3d_desc->height;
2994 desc.MipLevels = 1;
2995 desc.ArraySize = 1;
2996 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2997 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2998 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2999 desc.Usage = D3D10_USAGE_DEFAULT;
3000 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
3001 desc.CPUAccessFlags = 0;
3002 desc.MiscFlags = 0;
3004 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
3005 &desc, NULL, &texture_iface)))
3007 ERR("CreateTexture2D failed, returning %#x\n", hr);
3008 return hr;
3011 texture = impl_from_ID3D10Texture2D(texture_iface);
3013 *wined3d_texture = texture->wined3d_texture;
3014 wined3d_texture_incref(*wined3d_texture);
3015 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
3017 return S_OK;
3020 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
3021 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
3023 struct d3d_device *device = device_from_wined3d_device_parent(device_parent);
3024 IWineDXGIDevice *wine_device;
3025 HRESULT hr;
3027 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
3029 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
3030 &IID_IWineDXGIDevice, (void **)&wine_device)))
3032 ERR("Device should implement IWineDXGIDevice.\n");
3033 return E_FAIL;
3036 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
3037 IWineDXGIDevice_Release(wine_device);
3038 if (FAILED(hr))
3040 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
3041 return hr;
3044 return S_OK;
3047 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
3049 device_parent_wined3d_device_created,
3050 device_parent_mode_changed,
3051 device_parent_activate,
3052 device_parent_surface_created,
3053 device_parent_volume_created,
3054 device_parent_create_swapchain_texture,
3055 device_parent_create_swapchain,
3058 static void *d3d_rb_alloc(size_t size)
3060 return HeapAlloc(GetProcessHeap(), 0, size);
3063 static void *d3d_rb_realloc(void *ptr, size_t size)
3065 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
3068 static void d3d_rb_free(void *ptr)
3070 HeapFree(GetProcessHeap(), 0, ptr);
3073 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
3075 const D3D10_SAMPLER_DESC *ka = key;
3076 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
3078 return memcmp(ka, kb, sizeof(*ka));
3081 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
3083 d3d_rb_alloc,
3084 d3d_rb_realloc,
3085 d3d_rb_free,
3086 d3d10_sampler_state_compare,
3089 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
3091 const D3D10_BLEND_DESC *ka = key;
3092 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
3094 return memcmp(ka, kb, sizeof(*ka));
3097 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
3099 d3d_rb_alloc,
3100 d3d_rb_realloc,
3101 d3d_rb_free,
3102 d3d10_blend_state_compare,
3105 static int d3d_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
3107 const D3D11_DEPTH_STENCIL_DESC *ka = key;
3108 const D3D11_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
3109 const struct d3d_depthstencil_state, entry)->desc;
3111 return memcmp(ka, kb, sizeof(*ka));
3114 static const struct wine_rb_functions d3d_depthstencil_state_rb_ops =
3116 d3d_rb_alloc,
3117 d3d_rb_realloc,
3118 d3d_rb_free,
3119 d3d_depthstencil_state_compare,
3122 static int d3d_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
3124 const D3D11_RASTERIZER_DESC *ka = key;
3125 const D3D11_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d_rasterizer_state, entry)->desc;
3127 return memcmp(ka, kb, sizeof(*ka));
3130 static const struct wine_rb_functions d3d_rasterizer_state_rb_ops =
3132 d3d_rb_alloc,
3133 d3d_rb_realloc,
3134 d3d_rb_free,
3135 d3d_rasterizer_state_compare,
3138 HRESULT d3d_device_init(struct d3d_device *device, void *outer_unknown)
3140 device->IUnknown_inner.lpVtbl = &d3d_device_inner_unknown_vtbl;
3141 device->ID3D11Device_iface.lpVtbl = &d3d11_device_vtbl;
3142 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
3143 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
3144 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
3145 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
3146 device->refcount = 1;
3147 /* COM aggregation always takes place */
3148 device->outer_unk = outer_unknown;
3150 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
3152 WARN("Failed to initialize blend state rbtree.\n");
3153 return E_FAIL;
3155 device->blend_factor[0] = 1.0f;
3156 device->blend_factor[1] = 1.0f;
3157 device->blend_factor[2] = 1.0f;
3158 device->blend_factor[3] = 1.0f;
3160 if (wine_rb_init(&device->depthstencil_states, &d3d_depthstencil_state_rb_ops) == -1)
3162 WARN("Failed to initialize depthstencil state rbtree.\n");
3163 wine_rb_destroy(&device->blend_states, NULL, NULL);
3164 return E_FAIL;
3167 if (wine_rb_init(&device->rasterizer_states, &d3d_rasterizer_state_rb_ops) == -1)
3169 WARN("Failed to initialize rasterizer state rbtree.\n");
3170 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3171 wine_rb_destroy(&device->blend_states, NULL, NULL);
3172 return E_FAIL;
3175 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
3177 WARN("Failed to initialize sampler state rbtree.\n");
3178 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
3179 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
3180 wine_rb_destroy(&device->blend_states, NULL, NULL);
3181 return E_FAIL;
3184 return S_OK;