hidclass.sys: Implement IRP_MN_QUERY_ID for HID devices.
[wine.git] / dlls / d3d11 / state.c
blob665d142c4cf52e2d09bd84be9eb75016d9399e55
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 /* ID3D11BlendState methods */
29 static inline struct d3d_blend_state *impl_from_ID3D11BlendState(ID3D11BlendState *iface)
31 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D11BlendState_iface);
34 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_QueryInterface(ID3D11BlendState *iface,
35 REFIID riid, void **object)
37 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
39 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
41 if (IsEqualGUID(riid, &IID_ID3D11BlendState)
42 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
43 || IsEqualGUID(riid, &IID_IUnknown))
45 ID3D11BlendState_AddRef(iface);
46 *object = iface;
47 return S_OK;
50 if (IsEqualGUID(riid, &IID_ID3D10BlendState1)
51 || IsEqualGUID(riid, &IID_ID3D10BlendState)
52 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
54 ID3D10BlendState1_AddRef(&state->ID3D10BlendState1_iface);
55 *object = &state->ID3D10BlendState1_iface;
56 return S_OK;
59 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
61 *object = NULL;
62 return E_NOINTERFACE;
65 static ULONG STDMETHODCALLTYPE d3d11_blend_state_AddRef(ID3D11BlendState *iface)
67 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
68 ULONG refcount = InterlockedIncrement(&state->refcount);
70 TRACE("%p increasing refcount to %u.\n", state, refcount);
72 return refcount;
75 static ULONG STDMETHODCALLTYPE d3d11_blend_state_Release(ID3D11BlendState *iface)
77 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
78 ULONG refcount = InterlockedDecrement(&state->refcount);
80 TRACE("%p decreasing refcount to %u.\n", state, refcount);
82 if (!refcount)
84 struct d3d_device *device = impl_from_ID3D11Device(state->device);
85 wined3d_mutex_lock();
86 wine_rb_remove(&device->blend_states, &state->desc);
87 ID3D11Device_Release(state->device);
88 wined3d_private_store_cleanup(&state->private_store);
89 wined3d_mutex_unlock();
90 HeapFree(GetProcessHeap(), 0, state);
93 return refcount;
96 static void STDMETHODCALLTYPE d3d11_blend_state_GetDevice(ID3D11BlendState *iface,
97 ID3D11Device **device)
99 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
101 TRACE("iface %p, device %p.\n", iface, device);
103 *device = state->device;
104 ID3D11Device_AddRef(*device);
107 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_GetPrivateData(ID3D11BlendState *iface,
108 REFGUID guid, UINT *data_size, void *data)
110 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
112 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
114 return d3d_get_private_data(&state->private_store, guid, data_size, data);
117 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateData(ID3D11BlendState *iface,
118 REFGUID guid, UINT data_size, const void *data)
120 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
122 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
124 return d3d_set_private_data(&state->private_store, guid, data_size, data);
127 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateDataInterface(ID3D11BlendState *iface,
128 REFGUID guid, const IUnknown *data)
130 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
132 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
134 return d3d_set_private_data_interface(&state->private_store, guid, data);
137 static void STDMETHODCALLTYPE d3d11_blend_state_GetDesc(ID3D11BlendState *iface, D3D11_BLEND_DESC *desc)
139 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
141 TRACE("iface %p, desc %p.\n", iface, desc);
143 *desc = state->desc;
146 static const struct ID3D11BlendStateVtbl d3d11_blend_state_vtbl =
148 /* IUnknown methods */
149 d3d11_blend_state_QueryInterface,
150 d3d11_blend_state_AddRef,
151 d3d11_blend_state_Release,
152 /* ID3D11DeviceChild methods */
153 d3d11_blend_state_GetDevice,
154 d3d11_blend_state_GetPrivateData,
155 d3d11_blend_state_SetPrivateData,
156 d3d11_blend_state_SetPrivateDataInterface,
157 /* ID3D11BlendState methods */
158 d3d11_blend_state_GetDesc,
161 /* ID3D10BlendState methods */
163 static inline struct d3d_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState1 *iface)
165 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D10BlendState1_iface);
168 /* IUnknown methods */
170 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState1 *iface,
171 REFIID riid, void **object)
173 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
175 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
177 return d3d11_blend_state_QueryInterface(&state->ID3D11BlendState_iface, riid, object);
180 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState1 *iface)
182 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
184 TRACE("iface %p.\n", iface);
186 return d3d11_blend_state_AddRef(&state->ID3D11BlendState_iface);
189 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState1 *iface)
191 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
193 TRACE("iface %p.\n", iface);
195 return d3d11_blend_state_Release(&state->ID3D11BlendState_iface);
198 /* ID3D10DeviceChild methods */
200 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState1 *iface, ID3D10Device **device)
202 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
204 TRACE("iface %p, device %p.\n", iface, device);
206 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
209 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState1 *iface,
210 REFGUID guid, UINT *data_size, void *data)
212 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
214 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
215 iface, debugstr_guid(guid), data_size, data);
217 return d3d_get_private_data(&state->private_store, guid, data_size, data);
220 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState1 *iface,
221 REFGUID guid, UINT data_size, const void *data)
223 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
225 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
226 iface, debugstr_guid(guid), data_size, data);
228 return d3d_set_private_data(&state->private_store, guid, data_size, data);
231 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState1 *iface,
232 REFGUID guid, const IUnknown *data)
234 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
236 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
238 return d3d_set_private_data_interface(&state->private_store, guid, data);
241 /* ID3D10BlendState methods */
243 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState1 *iface, D3D10_BLEND_DESC *desc)
245 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
246 const D3D11_BLEND_DESC *d3d11_desc = &state->desc;
247 unsigned int i;
249 TRACE("iface %p, desc %p.\n", iface, desc);
251 desc->AlphaToCoverageEnable = d3d11_desc->AlphaToCoverageEnable;
252 desc->SrcBlend = d3d11_desc->RenderTarget[0].SrcBlend;
253 desc->DestBlend = d3d11_desc->RenderTarget[0].DestBlend;
254 desc->BlendOp = d3d11_desc->RenderTarget[0].BlendOp;
255 desc->SrcBlendAlpha = d3d11_desc->RenderTarget[0].SrcBlendAlpha;
256 desc->DestBlendAlpha = d3d11_desc->RenderTarget[0].DestBlendAlpha;
257 desc->BlendOpAlpha = d3d11_desc->RenderTarget[0].BlendOpAlpha;
258 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
260 desc->BlendEnable[i] = d3d11_desc->RenderTarget[i].BlendEnable;
261 desc->RenderTargetWriteMask[i] = d3d11_desc->RenderTarget[i].RenderTargetWriteMask;
265 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc1(ID3D10BlendState1 *iface, D3D10_BLEND_DESC1 *desc)
267 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
269 TRACE("iface %p, desc %p.\n", iface, desc);
271 memcpy(desc, &state->desc, sizeof(*desc));
274 static const struct ID3D10BlendState1Vtbl d3d10_blend_state_vtbl =
276 /* IUnknown methods */
277 d3d10_blend_state_QueryInterface,
278 d3d10_blend_state_AddRef,
279 d3d10_blend_state_Release,
280 /* ID3D10DeviceChild methods */
281 d3d10_blend_state_GetDevice,
282 d3d10_blend_state_GetPrivateData,
283 d3d10_blend_state_SetPrivateData,
284 d3d10_blend_state_SetPrivateDataInterface,
285 /* ID3D10BlendState methods */
286 d3d10_blend_state_GetDesc,
287 /* ID3D10BlendState1 methods */
288 d3d10_blend_state_GetDesc1,
291 HRESULT d3d_blend_state_init(struct d3d_blend_state *state, struct d3d_device *device,
292 const D3D11_BLEND_DESC *desc)
294 state->ID3D11BlendState_iface.lpVtbl = &d3d11_blend_state_vtbl;
295 state->ID3D10BlendState1_iface.lpVtbl = &d3d10_blend_state_vtbl;
296 state->refcount = 1;
297 wined3d_mutex_lock();
298 wined3d_private_store_init(&state->private_store);
299 state->desc = *desc;
301 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
303 ERR("Failed to insert blend state entry.\n");
304 wined3d_private_store_cleanup(&state->private_store);
305 wined3d_mutex_unlock();
306 return E_FAIL;
308 wined3d_mutex_unlock();
310 state->device = &device->ID3D11Device_iface;
311 ID3D11Device_AddRef(state->device);
313 return S_OK;
316 struct d3d_blend_state *unsafe_impl_from_ID3D11BlendState(ID3D11BlendState *iface)
318 if (!iface)
319 return NULL;
320 assert(iface->lpVtbl == &d3d11_blend_state_vtbl);
322 return impl_from_ID3D11BlendState(iface);
325 struct d3d_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
327 if (!iface)
328 return NULL;
329 assert(iface->lpVtbl == (ID3D10BlendStateVtbl *)&d3d10_blend_state_vtbl);
331 return impl_from_ID3D10BlendState((ID3D10BlendState1 *)iface);
334 /* ID3D11DepthStencilState methods */
336 static inline struct d3d_depthstencil_state *impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
338 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D11DepthStencilState_iface);
341 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_QueryInterface(ID3D11DepthStencilState *iface,
342 REFIID riid, void **object)
344 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
346 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
348 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilState)
349 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
350 || IsEqualGUID(riid, &IID_IUnknown))
352 ID3D11DepthStencilState_AddRef(iface);
353 *object = iface;
354 return S_OK;
357 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
358 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
360 ID3D10DepthStencilState_AddRef(&state->ID3D10DepthStencilState_iface);
361 *object = &state->ID3D10DepthStencilState_iface;
362 return S_OK;
365 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
367 *object = NULL;
368 return E_NOINTERFACE;
371 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_AddRef(ID3D11DepthStencilState *iface)
373 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
374 ULONG refcount = InterlockedIncrement(&state->refcount);
376 TRACE("%p increasing refcount to %u.\n", state, refcount);
378 return refcount;
381 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_Release(ID3D11DepthStencilState *iface)
383 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
384 ULONG refcount = InterlockedDecrement(&state->refcount);
386 TRACE("%p decreasing refcount to %u.\n", state, refcount);
388 if (!refcount)
390 struct d3d_device *device = impl_from_ID3D11Device(state->device);
391 wined3d_mutex_lock();
392 wine_rb_remove(&device->depthstencil_states, &state->desc);
393 ID3D11Device_Release(state->device);
394 wined3d_private_store_cleanup(&state->private_store);
395 wined3d_mutex_unlock();
396 HeapFree(GetProcessHeap(), 0, state);
399 return refcount;
402 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDevice(ID3D11DepthStencilState *iface,
403 ID3D11Device **device)
405 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
407 TRACE("iface %p, device %p.\n", iface, device);
409 *device = state->device;
410 ID3D11Device_AddRef(*device);
413 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_GetPrivateData(ID3D11DepthStencilState *iface,
414 REFGUID guid, UINT *data_size, void *data)
416 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
418 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
420 return d3d_get_private_data(&state->private_store, guid, data_size, data);
423 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateData(ID3D11DepthStencilState *iface,
424 REFGUID guid, UINT data_size, const void *data)
426 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
428 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
430 return d3d_set_private_data(&state->private_store, guid, data_size, data);
433 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateDataInterface(ID3D11DepthStencilState *iface,
434 REFGUID guid, const IUnknown *data)
436 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
438 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
440 return d3d_set_private_data_interface(&state->private_store, guid, data);
443 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDesc(ID3D11DepthStencilState *iface,
444 D3D11_DEPTH_STENCIL_DESC *desc)
446 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
448 TRACE("iface %p, desc %p.\n", iface, desc);
450 *desc = state->desc;
453 static const struct ID3D11DepthStencilStateVtbl d3d11_depthstencil_state_vtbl =
455 /* IUnknown methods */
456 d3d11_depthstencil_state_QueryInterface,
457 d3d11_depthstencil_state_AddRef,
458 d3d11_depthstencil_state_Release,
459 /* ID3D11DeviceChild methods */
460 d3d11_depthstencil_state_GetDevice,
461 d3d11_depthstencil_state_GetPrivateData,
462 d3d11_depthstencil_state_SetPrivateData,
463 d3d11_depthstencil_state_SetPrivateDataInterface,
464 /* ID3D11DepthStencilState methods */
465 d3d11_depthstencil_state_GetDesc,
468 /* ID3D10DepthStencilState methods */
470 static inline struct d3d_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
472 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D10DepthStencilState_iface);
475 /* IUnknown methods */
477 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
478 REFIID riid, void **object)
480 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
482 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
484 return d3d11_depthstencil_state_QueryInterface(&state->ID3D11DepthStencilState_iface, riid, object);
487 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
489 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
491 TRACE("iface %p.\n", iface);
493 return d3d11_depthstencil_state_AddRef(&state->ID3D11DepthStencilState_iface);
496 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
498 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
500 TRACE("iface %p.\n", iface);
502 return d3d11_depthstencil_state_Release(&state->ID3D11DepthStencilState_iface);
505 /* ID3D10DeviceChild methods */
507 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
509 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
511 TRACE("iface %p, device %p.\n", iface, device);
513 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
516 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
517 REFGUID guid, UINT *data_size, void *data)
519 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
521 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
522 iface, debugstr_guid(guid), data_size, data);
524 return d3d_get_private_data(&state->private_store, guid, data_size, data);
527 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
528 REFGUID guid, UINT data_size, const void *data)
530 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
532 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
533 iface, debugstr_guid(guid), data_size, data);
535 return d3d_set_private_data(&state->private_store, guid, data_size, data);
538 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
539 REFGUID guid, const IUnknown *data)
541 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
543 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
545 return d3d_set_private_data_interface(&state->private_store, guid, data);
548 /* ID3D10DepthStencilState methods */
550 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
551 D3D10_DEPTH_STENCIL_DESC *desc)
553 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
555 TRACE("iface %p, desc %p.\n", iface, desc);
557 memcpy(desc, &state->desc, sizeof(*desc));
560 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
562 /* IUnknown methods */
563 d3d10_depthstencil_state_QueryInterface,
564 d3d10_depthstencil_state_AddRef,
565 d3d10_depthstencil_state_Release,
566 /* ID3D10DeviceChild methods */
567 d3d10_depthstencil_state_GetDevice,
568 d3d10_depthstencil_state_GetPrivateData,
569 d3d10_depthstencil_state_SetPrivateData,
570 d3d10_depthstencil_state_SetPrivateDataInterface,
571 /* ID3D10DepthStencilState methods */
572 d3d10_depthstencil_state_GetDesc,
575 HRESULT d3d_depthstencil_state_init(struct d3d_depthstencil_state *state, struct d3d_device *device,
576 const D3D11_DEPTH_STENCIL_DESC *desc)
578 state->ID3D11DepthStencilState_iface.lpVtbl = &d3d11_depthstencil_state_vtbl;
579 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
580 state->refcount = 1;
581 wined3d_mutex_lock();
582 wined3d_private_store_init(&state->private_store);
583 state->desc = *desc;
585 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
587 ERR("Failed to insert depthstencil state entry.\n");
588 wined3d_private_store_cleanup(&state->private_store);
589 wined3d_mutex_unlock();
590 return E_FAIL;
592 wined3d_mutex_unlock();
594 state->device = &device->ID3D11Device_iface;
595 ID3D11Device_AddRef(state->device);
597 return S_OK;
600 struct d3d_depthstencil_state *unsafe_impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
602 if (!iface)
603 return NULL;
604 assert(iface->lpVtbl == &d3d11_depthstencil_state_vtbl);
606 return impl_from_ID3D11DepthStencilState(iface);
609 struct d3d_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
611 if (!iface)
612 return NULL;
613 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
615 return impl_from_ID3D10DepthStencilState(iface);
618 /* ID3D11RasterizerState methods */
620 static inline struct d3d_rasterizer_state *impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
622 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D11RasterizerState_iface);
625 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_QueryInterface(ID3D11RasterizerState *iface,
626 REFIID riid, void **object)
628 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
630 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
632 if (IsEqualGUID(riid, &IID_ID3D11RasterizerState)
633 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
634 || IsEqualGUID(riid, &IID_IUnknown))
636 ID3D11RasterizerState_AddRef(iface);
637 *object = iface;
638 return S_OK;
641 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
642 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
644 ID3D10RasterizerState_AddRef(&state->ID3D10RasterizerState_iface);
645 *object = &state->ID3D10RasterizerState_iface;
646 return S_OK;
649 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
651 *object = NULL;
652 return E_NOINTERFACE;
655 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_AddRef(ID3D11RasterizerState *iface)
657 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
658 ULONG refcount = InterlockedIncrement(&state->refcount);
660 TRACE("%p increasing refcount to %u.\n", state, refcount);
662 return refcount;
665 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_Release(ID3D11RasterizerState *iface)
667 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
668 ULONG refcount = InterlockedDecrement(&state->refcount);
670 TRACE("%p decreasing refcount to %u.\n", state, refcount);
672 if (!refcount)
674 struct d3d_device *device = impl_from_ID3D11Device(state->device);
675 wined3d_mutex_lock();
676 wine_rb_remove(&device->rasterizer_states, &state->desc);
677 ID3D11Device_Release(state->device);
678 wined3d_private_store_cleanup(&state->private_store);
679 wined3d_mutex_unlock();
680 HeapFree(GetProcessHeap(), 0, state);
683 return refcount;
686 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
687 ID3D11Device **device)
689 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
691 TRACE("iface %p, device %p.\n", iface, device);
693 *device = state->device;
694 ID3D11Device_AddRef(*device);
697 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
698 REFGUID guid, UINT *data_size, void *data)
700 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
702 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
704 return d3d_get_private_data(&state->private_store, guid, data_size, data);
707 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
708 REFGUID guid, UINT data_size, const void *data)
710 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
712 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
714 return d3d_set_private_data(&state->private_store, guid, data_size, data);
717 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
718 REFGUID guid, const IUnknown *data)
720 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
722 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
724 return d3d_set_private_data_interface(&state->private_store, guid, data);
727 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
728 D3D11_RASTERIZER_DESC *desc)
730 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
732 TRACE("iface %p, desc %p.\n", iface, desc);
734 *desc = state->desc;
737 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
739 /* IUnknown methods */
740 d3d11_rasterizer_state_QueryInterface,
741 d3d11_rasterizer_state_AddRef,
742 d3d11_rasterizer_state_Release,
743 /* ID3D11DeviceChild methods */
744 d3d11_rasterizer_state_GetDevice,
745 d3d11_rasterizer_state_GetPrivateData,
746 d3d11_rasterizer_state_SetPrivateData,
747 d3d11_rasterizer_state_SetPrivateDataInterface,
748 /* ID3D11RasterizerState methods */
749 d3d11_rasterizer_state_GetDesc,
752 /* ID3D10RasterizerState methods */
754 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
756 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
759 /* IUnknown methods */
761 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
762 REFIID riid, void **object)
764 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
766 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
768 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
771 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
773 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
775 TRACE("iface %p.\n", iface);
777 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
780 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
782 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
784 TRACE("iface %p.\n", state);
786 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
789 /* ID3D10DeviceChild methods */
791 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
793 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
795 TRACE("iface %p, device %p.\n", iface, device);
797 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
800 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
801 REFGUID guid, UINT *data_size, void *data)
803 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
805 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
806 iface, debugstr_guid(guid), data_size, data);
808 return d3d_get_private_data(&state->private_store, guid, data_size, data);
811 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
812 REFGUID guid, UINT data_size, const void *data)
814 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
816 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
817 iface, debugstr_guid(guid), data_size, data);
819 return d3d_set_private_data(&state->private_store, guid, data_size, data);
822 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
823 REFGUID guid, const IUnknown *data)
825 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
827 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
829 return d3d_set_private_data_interface(&state->private_store, guid, data);
832 /* ID3D10RasterizerState methods */
834 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
835 D3D10_RASTERIZER_DESC *desc)
837 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
839 TRACE("iface %p, desc %p.\n", iface, desc);
841 memcpy(desc, &state->desc, sizeof(*desc));
844 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
846 /* IUnknown methods */
847 d3d10_rasterizer_state_QueryInterface,
848 d3d10_rasterizer_state_AddRef,
849 d3d10_rasterizer_state_Release,
850 /* ID3D10DeviceChild methods */
851 d3d10_rasterizer_state_GetDevice,
852 d3d10_rasterizer_state_GetPrivateData,
853 d3d10_rasterizer_state_SetPrivateData,
854 d3d10_rasterizer_state_SetPrivateDataInterface,
855 /* ID3D10RasterizerState methods */
856 d3d10_rasterizer_state_GetDesc,
859 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
860 const D3D11_RASTERIZER_DESC *desc)
862 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
863 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
864 state->refcount = 1;
865 wined3d_mutex_lock();
866 wined3d_private_store_init(&state->private_store);
867 state->desc = *desc;
869 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
871 ERR("Failed to insert rasterizer state entry.\n");
872 wined3d_private_store_cleanup(&state->private_store);
873 wined3d_mutex_unlock();
874 return E_FAIL;
876 wined3d_mutex_unlock();
878 state->device = &device->ID3D11Device_iface;
879 ID3D11Device_AddRef(state->device);
881 return S_OK;
884 struct d3d_rasterizer_state *unsafe_impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
886 if (!iface)
887 return NULL;
888 assert(iface->lpVtbl == &d3d11_rasterizer_state_vtbl);
890 return impl_from_ID3D11RasterizerState(iface);
893 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
895 if (!iface)
896 return NULL;
897 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
899 return impl_from_ID3D10RasterizerState(iface);
902 /* ID3D11SampleState methods */
904 static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
906 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface);
909 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface,
910 REFIID riid, void **object)
912 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
914 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
916 if (IsEqualGUID(riid, &IID_ID3D11SamplerState)
917 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
918 || IsEqualGUID(riid, &IID_IUnknown))
920 ID3D11SamplerState_AddRef(iface);
921 *object = iface;
922 return S_OK;
925 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
926 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
928 ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface);
929 *object = &state->ID3D10SamplerState_iface;
930 return S_OK;
933 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
935 *object = NULL;
936 return E_NOINTERFACE;
939 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface)
941 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
942 ULONG refcount = InterlockedIncrement(&state->refcount);
944 TRACE("%p increasing refcount to %u.\n", state, refcount);
946 return refcount;
949 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface)
951 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
952 ULONG refcount = InterlockedDecrement(&state->refcount);
954 TRACE("%p decreasing refcount to %u.\n", state, refcount);
956 if (!refcount)
958 struct d3d_device *device = impl_from_ID3D11Device(state->device);
960 wined3d_mutex_lock();
961 wined3d_sampler_decref(state->wined3d_sampler);
962 wine_rb_remove(&device->sampler_states, &state->desc);
963 ID3D11Device_Release(state->device);
964 wined3d_private_store_cleanup(&state->private_store);
965 wined3d_mutex_unlock();
966 HeapFree(GetProcessHeap(), 0, state);
969 return refcount;
972 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface,
973 ID3D11Device **device)
975 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
977 TRACE("iface %p, device %p.\n", iface, device);
979 *device = state->device;
980 ID3D11Device_AddRef(*device);
983 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface,
984 REFGUID guid, UINT *data_size, void *data)
986 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
988 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
990 return d3d_get_private_data(&state->private_store, guid, data_size, data);
993 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface,
994 REFGUID guid, UINT data_size, const void *data)
996 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
998 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1000 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1003 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface,
1004 REFGUID guid, const IUnknown *data)
1006 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1008 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1010 return d3d_set_private_data_interface(&state->private_store, guid, data);
1013 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface,
1014 D3D11_SAMPLER_DESC *desc)
1016 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1018 TRACE("iface %p, desc %p.\n", iface, desc);
1020 *desc = state->desc;
1023 static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl =
1025 /* IUnknown methods */
1026 d3d11_sampler_state_QueryInterface,
1027 d3d11_sampler_state_AddRef,
1028 d3d11_sampler_state_Release,
1029 /* ID3D11DeviceChild methods */
1030 d3d11_sampler_state_GetDevice,
1031 d3d11_sampler_state_GetPrivateData,
1032 d3d11_sampler_state_SetPrivateData,
1033 d3d11_sampler_state_SetPrivateDataInterface,
1034 /* ID3D11SamplerState methods */
1035 d3d11_sampler_state_GetDesc,
1038 /* ID3D10SamplerState methods */
1040 static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1042 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface);
1045 /* IUnknown methods */
1047 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
1048 REFIID riid, void **object)
1050 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1052 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1054 return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object);
1057 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
1059 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1061 TRACE("iface %p.\n", iface);
1063 return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface);
1066 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
1068 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1070 TRACE("iface %p.\n", iface);
1072 return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface);
1075 /* ID3D10DeviceChild methods */
1077 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
1079 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1081 TRACE("iface %p, device %p.\n", iface, device);
1083 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
1086 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
1087 REFGUID guid, UINT *data_size, void *data)
1089 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1091 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1092 iface, debugstr_guid(guid), data_size, data);
1094 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1097 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
1098 REFGUID guid, UINT data_size, const void *data)
1100 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1102 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1103 iface, debugstr_guid(guid), data_size, data);
1105 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1108 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
1109 REFGUID guid, const IUnknown *data)
1111 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1113 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1115 return d3d_set_private_data_interface(&state->private_store, guid, data);
1118 /* ID3D10SamplerState methods */
1120 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
1121 D3D10_SAMPLER_DESC *desc)
1123 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1125 TRACE("iface %p, desc %p.\n", iface, desc);
1127 memcpy(desc, &state->desc, sizeof(*desc));
1130 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
1132 /* IUnknown methods */
1133 d3d10_sampler_state_QueryInterface,
1134 d3d10_sampler_state_AddRef,
1135 d3d10_sampler_state_Release,
1136 /* ID3D10DeviceChild methods */
1137 d3d10_sampler_state_GetDevice,
1138 d3d10_sampler_state_GetPrivateData,
1139 d3d10_sampler_state_SetPrivateData,
1140 d3d10_sampler_state_SetPrivateDataInterface,
1141 /* ID3D10SamplerState methods */
1142 d3d10_sampler_state_GetDesc,
1145 static enum wined3d_texture_address wined3d_texture_address_from_d3d11(enum D3D11_TEXTURE_ADDRESS_MODE t)
1147 return (enum wined3d_texture_address)t;
1150 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d11(enum D3D11_FILTER f)
1152 if (D3D11_DECODE_MIP_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1153 return WINED3D_TEXF_LINEAR;
1154 return WINED3D_TEXF_POINT;
1157 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d11(enum D3D11_FILTER f)
1159 if (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1160 return WINED3D_TEXF_LINEAR;
1161 return WINED3D_TEXF_POINT;
1164 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d11(enum D3D11_FILTER f)
1166 if (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1167 return WINED3D_TEXF_LINEAR;
1168 return WINED3D_TEXF_POINT;
1171 static BOOL wined3d_texture_compare_from_d3d11(enum D3D11_FILTER f)
1173 return D3D11_DECODE_IS_COMPARISON_FILTER(f);
1176 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f)
1178 return (enum wined3d_cmp_func)f;
1181 HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
1182 const D3D11_SAMPLER_DESC *desc)
1184 struct wined3d_sampler_desc wined3d_desc;
1185 HRESULT hr;
1187 state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl;
1188 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
1189 state->refcount = 1;
1190 wined3d_mutex_lock();
1191 wined3d_private_store_init(&state->private_store);
1192 state->desc = *desc;
1194 wined3d_desc.address_u = wined3d_texture_address_from_d3d11(desc->AddressU);
1195 wined3d_desc.address_v = wined3d_texture_address_from_d3d11(desc->AddressV);
1196 wined3d_desc.address_w = wined3d_texture_address_from_d3d11(desc->AddressW);
1197 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
1198 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d11(desc->Filter);
1199 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d11(desc->Filter);
1200 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d11(desc->Filter);
1201 wined3d_desc.lod_bias = desc->MipLODBias;
1202 wined3d_desc.min_lod = desc->MinLOD;
1203 wined3d_desc.max_lod = desc->MaxLOD;
1204 wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
1205 wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
1206 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
1207 wined3d_desc.srgb_decode = TRUE;
1209 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
1211 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
1212 wined3d_private_store_cleanup(&state->private_store);
1213 wined3d_mutex_unlock();
1214 return hr;
1217 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
1219 ERR("Failed to insert sampler state entry.\n");
1220 wined3d_sampler_decref(state->wined3d_sampler);
1221 wined3d_private_store_cleanup(&state->private_store);
1222 wined3d_mutex_unlock();
1223 return E_FAIL;
1225 wined3d_mutex_unlock();
1227 state->device = &device->ID3D11Device_iface;
1228 ID3D11Device_AddRef(state->device);
1230 return S_OK;
1233 struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
1235 if (!iface)
1236 return NULL;
1237 assert(iface->lpVtbl == &d3d11_sampler_state_vtbl);
1239 return impl_from_ID3D11SamplerState(iface);
1242 struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1244 if (!iface)
1245 return NULL;
1246 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
1248 return impl_from_ID3D10SamplerState(iface);