wined3d: Introduce R10G10B10X2 vertex formats for D3D8/9.
[wine.git] / dlls / d3d11 / state.c
blob68ad1bdcdd7495eab76ec77cc6805392bf015f29
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 HRESULT STDMETHODCALLTYPE d3d11_blend_state_QueryInterface(ID3D11BlendState *iface,
30 REFIID riid, void **object)
32 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
34 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
36 if (IsEqualGUID(riid, &IID_ID3D11BlendState)
37 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
38 || IsEqualGUID(riid, &IID_IUnknown))
40 ID3D11BlendState_AddRef(iface);
41 *object = iface;
42 return S_OK;
45 if (IsEqualGUID(riid, &IID_ID3D10BlendState1)
46 || IsEqualGUID(riid, &IID_ID3D10BlendState)
47 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
49 ID3D10BlendState1_AddRef(&state->ID3D10BlendState1_iface);
50 *object = &state->ID3D10BlendState1_iface;
51 return S_OK;
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56 *object = NULL;
57 return E_NOINTERFACE;
60 static ULONG STDMETHODCALLTYPE d3d11_blend_state_AddRef(ID3D11BlendState *iface)
62 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
63 ULONG refcount = InterlockedIncrement(&state->refcount);
65 TRACE("%p increasing refcount to %u.\n", state, refcount);
67 return refcount;
70 static ULONG STDMETHODCALLTYPE d3d11_blend_state_Release(ID3D11BlendState *iface)
72 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
73 ULONG refcount = InterlockedDecrement(&state->refcount);
75 TRACE("%p decreasing refcount to %u.\n", state, refcount);
77 if (!refcount)
79 struct d3d_device *device = impl_from_ID3D11Device(state->device);
80 wined3d_mutex_lock();
81 wine_rb_remove(&device->blend_states, &state->desc);
82 ID3D11Device_Release(state->device);
83 wined3d_private_store_cleanup(&state->private_store);
84 wined3d_mutex_unlock();
85 HeapFree(GetProcessHeap(), 0, state);
88 return refcount;
91 static void STDMETHODCALLTYPE d3d11_blend_state_GetDevice(ID3D11BlendState *iface,
92 ID3D11Device **device)
94 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
96 TRACE("iface %p, device %p.\n", iface, device);
98 *device = state->device;
99 ID3D11Device_AddRef(*device);
102 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_GetPrivateData(ID3D11BlendState *iface,
103 REFGUID guid, UINT *data_size, void *data)
105 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
107 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
109 return d3d_get_private_data(&state->private_store, guid, data_size, data);
112 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateData(ID3D11BlendState *iface,
113 REFGUID guid, UINT data_size, const void *data)
115 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
117 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
119 return d3d_set_private_data(&state->private_store, guid, data_size, data);
122 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateDataInterface(ID3D11BlendState *iface,
123 REFGUID guid, const IUnknown *data)
125 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
127 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
129 return d3d_set_private_data_interface(&state->private_store, guid, data);
132 static void STDMETHODCALLTYPE d3d11_blend_state_GetDesc(ID3D11BlendState *iface, D3D11_BLEND_DESC *desc)
134 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
136 TRACE("iface %p, desc %p.\n", iface, desc);
138 *desc = state->desc;
141 static const struct ID3D11BlendStateVtbl d3d11_blend_state_vtbl =
143 /* IUnknown methods */
144 d3d11_blend_state_QueryInterface,
145 d3d11_blend_state_AddRef,
146 d3d11_blend_state_Release,
147 /* ID3D11DeviceChild methods */
148 d3d11_blend_state_GetDevice,
149 d3d11_blend_state_GetPrivateData,
150 d3d11_blend_state_SetPrivateData,
151 d3d11_blend_state_SetPrivateDataInterface,
152 /* ID3D11BlendState methods */
153 d3d11_blend_state_GetDesc,
156 /* ID3D10BlendState methods */
158 static inline struct d3d_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState1 *iface)
160 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D10BlendState1_iface);
163 /* IUnknown methods */
165 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState1 *iface,
166 REFIID riid, void **object)
168 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
170 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
172 return d3d11_blend_state_QueryInterface(&state->ID3D11BlendState_iface, riid, object);
175 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState1 *iface)
177 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
179 TRACE("iface %p.\n", iface);
181 return d3d11_blend_state_AddRef(&state->ID3D11BlendState_iface);
184 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState1 *iface)
186 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
188 TRACE("iface %p.\n", iface);
190 return d3d11_blend_state_Release(&state->ID3D11BlendState_iface);
193 /* ID3D10DeviceChild methods */
195 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState1 *iface, ID3D10Device **device)
197 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
199 TRACE("iface %p, device %p.\n", iface, device);
201 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
204 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState1 *iface,
205 REFGUID guid, UINT *data_size, void *data)
207 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
209 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
210 iface, debugstr_guid(guid), data_size, data);
212 return d3d_get_private_data(&state->private_store, guid, data_size, data);
215 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState1 *iface,
216 REFGUID guid, UINT data_size, const void *data)
218 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
220 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
221 iface, debugstr_guid(guid), data_size, data);
223 return d3d_set_private_data(&state->private_store, guid, data_size, data);
226 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState1 *iface,
227 REFGUID guid, const IUnknown *data)
229 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
231 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
233 return d3d_set_private_data_interface(&state->private_store, guid, data);
236 /* ID3D10BlendState methods */
238 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState1 *iface, D3D10_BLEND_DESC *desc)
240 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
241 const D3D11_BLEND_DESC *d3d11_desc = &state->desc;
242 unsigned int i;
244 TRACE("iface %p, desc %p.\n", iface, desc);
246 desc->AlphaToCoverageEnable = d3d11_desc->AlphaToCoverageEnable;
247 desc->SrcBlend = d3d11_desc->RenderTarget[0].SrcBlend;
248 desc->DestBlend = d3d11_desc->RenderTarget[0].DestBlend;
249 desc->BlendOp = d3d11_desc->RenderTarget[0].BlendOp;
250 desc->SrcBlendAlpha = d3d11_desc->RenderTarget[0].SrcBlendAlpha;
251 desc->DestBlendAlpha = d3d11_desc->RenderTarget[0].DestBlendAlpha;
252 desc->BlendOpAlpha = d3d11_desc->RenderTarget[0].BlendOpAlpha;
253 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
255 desc->BlendEnable[i] = d3d11_desc->RenderTarget[i].BlendEnable;
256 desc->RenderTargetWriteMask[i] = d3d11_desc->RenderTarget[i].RenderTargetWriteMask;
260 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc1(ID3D10BlendState1 *iface, D3D10_BLEND_DESC1 *desc)
262 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
264 TRACE("iface %p, desc %p.\n", iface, desc);
266 memcpy(desc, &state->desc, sizeof(*desc));
269 static const struct ID3D10BlendState1Vtbl d3d10_blend_state_vtbl =
271 /* IUnknown methods */
272 d3d10_blend_state_QueryInterface,
273 d3d10_blend_state_AddRef,
274 d3d10_blend_state_Release,
275 /* ID3D10DeviceChild methods */
276 d3d10_blend_state_GetDevice,
277 d3d10_blend_state_GetPrivateData,
278 d3d10_blend_state_SetPrivateData,
279 d3d10_blend_state_SetPrivateDataInterface,
280 /* ID3D10BlendState methods */
281 d3d10_blend_state_GetDesc,
282 /* ID3D10BlendState1 methods */
283 d3d10_blend_state_GetDesc1,
286 HRESULT d3d_blend_state_init(struct d3d_blend_state *state, struct d3d_device *device,
287 const D3D11_BLEND_DESC *desc)
289 state->ID3D11BlendState_iface.lpVtbl = &d3d11_blend_state_vtbl;
290 state->ID3D10BlendState1_iface.lpVtbl = &d3d10_blend_state_vtbl;
291 state->refcount = 1;
292 wined3d_mutex_lock();
293 wined3d_private_store_init(&state->private_store);
294 state->desc = *desc;
296 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
298 ERR("Failed to insert blend state entry.\n");
299 wined3d_private_store_cleanup(&state->private_store);
300 wined3d_mutex_unlock();
301 return E_FAIL;
303 wined3d_mutex_unlock();
305 state->device = &device->ID3D11Device_iface;
306 ID3D11Device_AddRef(state->device);
308 return S_OK;
311 struct d3d_blend_state *unsafe_impl_from_ID3D11BlendState(ID3D11BlendState *iface)
313 if (!iface)
314 return NULL;
315 assert(iface->lpVtbl == &d3d11_blend_state_vtbl);
317 return impl_from_ID3D11BlendState(iface);
320 struct d3d_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
322 if (!iface)
323 return NULL;
324 assert(iface->lpVtbl == (ID3D10BlendStateVtbl *)&d3d10_blend_state_vtbl);
326 return impl_from_ID3D10BlendState((ID3D10BlendState1 *)iface);
329 /* ID3D11DepthStencilState methods */
331 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_QueryInterface(ID3D11DepthStencilState *iface,
332 REFIID riid, void **object)
334 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
336 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
338 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilState)
339 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
340 || IsEqualGUID(riid, &IID_IUnknown))
342 ID3D11DepthStencilState_AddRef(iface);
343 *object = iface;
344 return S_OK;
347 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
348 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
350 ID3D10DepthStencilState_AddRef(&state->ID3D10DepthStencilState_iface);
351 *object = &state->ID3D10DepthStencilState_iface;
352 return S_OK;
355 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
357 *object = NULL;
358 return E_NOINTERFACE;
361 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_AddRef(ID3D11DepthStencilState *iface)
363 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
364 ULONG refcount = InterlockedIncrement(&state->refcount);
366 TRACE("%p increasing refcount to %u.\n", state, refcount);
368 return refcount;
371 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_Release(ID3D11DepthStencilState *iface)
373 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
374 ULONG refcount = InterlockedDecrement(&state->refcount);
376 TRACE("%p decreasing refcount to %u.\n", state, refcount);
378 if (!refcount)
380 struct d3d_device *device = impl_from_ID3D11Device(state->device);
381 wined3d_mutex_lock();
382 wine_rb_remove(&device->depthstencil_states, &state->desc);
383 ID3D11Device_Release(state->device);
384 wined3d_private_store_cleanup(&state->private_store);
385 wined3d_mutex_unlock();
386 HeapFree(GetProcessHeap(), 0, state);
389 return refcount;
392 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDevice(ID3D11DepthStencilState *iface,
393 ID3D11Device **device)
395 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
397 TRACE("iface %p, device %p.\n", iface, device);
399 *device = state->device;
400 ID3D11Device_AddRef(*device);
403 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_GetPrivateData(ID3D11DepthStencilState *iface,
404 REFGUID guid, UINT *data_size, void *data)
406 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
408 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
410 return d3d_get_private_data(&state->private_store, guid, data_size, data);
413 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateData(ID3D11DepthStencilState *iface,
414 REFGUID guid, UINT data_size, const void *data)
416 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
418 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
420 return d3d_set_private_data(&state->private_store, guid, data_size, data);
423 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateDataInterface(ID3D11DepthStencilState *iface,
424 REFGUID guid, const IUnknown *data)
426 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
428 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
430 return d3d_set_private_data_interface(&state->private_store, guid, data);
433 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDesc(ID3D11DepthStencilState *iface,
434 D3D11_DEPTH_STENCIL_DESC *desc)
436 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
438 TRACE("iface %p, desc %p.\n", iface, desc);
440 *desc = state->desc;
443 static const struct ID3D11DepthStencilStateVtbl d3d11_depthstencil_state_vtbl =
445 /* IUnknown methods */
446 d3d11_depthstencil_state_QueryInterface,
447 d3d11_depthstencil_state_AddRef,
448 d3d11_depthstencil_state_Release,
449 /* ID3D11DeviceChild methods */
450 d3d11_depthstencil_state_GetDevice,
451 d3d11_depthstencil_state_GetPrivateData,
452 d3d11_depthstencil_state_SetPrivateData,
453 d3d11_depthstencil_state_SetPrivateDataInterface,
454 /* ID3D11DepthStencilState methods */
455 d3d11_depthstencil_state_GetDesc,
458 /* ID3D10DepthStencilState methods */
460 static inline struct d3d_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
462 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D10DepthStencilState_iface);
465 /* IUnknown methods */
467 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
468 REFIID riid, void **object)
470 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
472 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
474 return d3d11_depthstencil_state_QueryInterface(&state->ID3D11DepthStencilState_iface, riid, object);
477 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
479 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
481 TRACE("iface %p.\n", iface);
483 return d3d11_depthstencil_state_AddRef(&state->ID3D11DepthStencilState_iface);
486 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
488 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
490 TRACE("iface %p.\n", iface);
492 return d3d11_depthstencil_state_Release(&state->ID3D11DepthStencilState_iface);
495 /* ID3D10DeviceChild methods */
497 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
499 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
501 TRACE("iface %p, device %p.\n", iface, device);
503 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
506 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
507 REFGUID guid, UINT *data_size, void *data)
509 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
511 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
512 iface, debugstr_guid(guid), data_size, data);
514 return d3d_get_private_data(&state->private_store, guid, data_size, data);
517 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
518 REFGUID guid, UINT data_size, const void *data)
520 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
522 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
523 iface, debugstr_guid(guid), data_size, data);
525 return d3d_set_private_data(&state->private_store, guid, data_size, data);
528 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
529 REFGUID guid, const IUnknown *data)
531 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
533 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
535 return d3d_set_private_data_interface(&state->private_store, guid, data);
538 /* ID3D10DepthStencilState methods */
540 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
541 D3D10_DEPTH_STENCIL_DESC *desc)
543 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
545 TRACE("iface %p, desc %p.\n", iface, desc);
547 memcpy(desc, &state->desc, sizeof(*desc));
550 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
552 /* IUnknown methods */
553 d3d10_depthstencil_state_QueryInterface,
554 d3d10_depthstencil_state_AddRef,
555 d3d10_depthstencil_state_Release,
556 /* ID3D10DeviceChild methods */
557 d3d10_depthstencil_state_GetDevice,
558 d3d10_depthstencil_state_GetPrivateData,
559 d3d10_depthstencil_state_SetPrivateData,
560 d3d10_depthstencil_state_SetPrivateDataInterface,
561 /* ID3D10DepthStencilState methods */
562 d3d10_depthstencil_state_GetDesc,
565 HRESULT d3d_depthstencil_state_init(struct d3d_depthstencil_state *state, struct d3d_device *device,
566 const D3D11_DEPTH_STENCIL_DESC *desc)
568 state->ID3D11DepthStencilState_iface.lpVtbl = &d3d11_depthstencil_state_vtbl;
569 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
570 state->refcount = 1;
571 wined3d_mutex_lock();
572 wined3d_private_store_init(&state->private_store);
573 state->desc = *desc;
575 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
577 ERR("Failed to insert depthstencil state entry.\n");
578 wined3d_private_store_cleanup(&state->private_store);
579 wined3d_mutex_unlock();
580 return E_FAIL;
582 wined3d_mutex_unlock();
584 state->device = &device->ID3D11Device_iface;
585 ID3D11Device_AddRef(state->device);
587 return S_OK;
590 struct d3d_depthstencil_state *unsafe_impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
592 if (!iface)
593 return NULL;
594 assert(iface->lpVtbl == &d3d11_depthstencil_state_vtbl);
596 return impl_from_ID3D11DepthStencilState(iface);
599 struct d3d_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
601 if (!iface)
602 return NULL;
603 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
605 return impl_from_ID3D10DepthStencilState(iface);
608 /* ID3D11RasterizerState methods */
610 static inline struct d3d_rasterizer_state *impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
612 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D11RasterizerState_iface);
615 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_QueryInterface(ID3D11RasterizerState *iface,
616 REFIID riid, void **object)
618 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
620 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
622 if (IsEqualGUID(riid, &IID_ID3D11RasterizerState)
623 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
624 || IsEqualGUID(riid, &IID_IUnknown))
626 ID3D11RasterizerState_AddRef(iface);
627 *object = iface;
628 return S_OK;
631 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
632 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
634 ID3D10RasterizerState_AddRef(&state->ID3D10RasterizerState_iface);
635 *object = &state->ID3D10RasterizerState_iface;
636 return S_OK;
639 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
641 *object = NULL;
642 return E_NOINTERFACE;
645 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_AddRef(ID3D11RasterizerState *iface)
647 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
648 ULONG refcount = InterlockedIncrement(&state->refcount);
650 TRACE("%p increasing refcount to %u.\n", state, refcount);
652 return refcount;
655 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_Release(ID3D11RasterizerState *iface)
657 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
658 ULONG refcount = InterlockedDecrement(&state->refcount);
660 TRACE("%p decreasing refcount to %u.\n", state, refcount);
662 if (!refcount)
664 struct d3d_device *device = impl_from_ID3D11Device(state->device);
665 wined3d_mutex_lock();
666 wine_rb_remove(&device->rasterizer_states, &state->desc);
667 ID3D11Device_Release(state->device);
668 wined3d_private_store_cleanup(&state->private_store);
669 wined3d_mutex_unlock();
670 HeapFree(GetProcessHeap(), 0, state);
673 return refcount;
676 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
677 ID3D11Device **device)
679 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
681 TRACE("iface %p, device %p.\n", iface, device);
683 *device = state->device;
684 ID3D11Device_AddRef(*device);
687 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
688 REFGUID guid, UINT *data_size, void *data)
690 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
692 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
694 return d3d_get_private_data(&state->private_store, guid, data_size, data);
697 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
698 REFGUID guid, UINT data_size, const void *data)
700 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
702 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
704 return d3d_set_private_data(&state->private_store, guid, data_size, data);
707 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
708 REFGUID guid, const IUnknown *data)
710 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
712 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
714 return d3d_set_private_data_interface(&state->private_store, guid, data);
717 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
718 D3D11_RASTERIZER_DESC *desc)
720 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
722 TRACE("iface %p, desc %p.\n", iface, desc);
724 *desc = state->desc;
727 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
729 /* IUnknown methods */
730 d3d11_rasterizer_state_QueryInterface,
731 d3d11_rasterizer_state_AddRef,
732 d3d11_rasterizer_state_Release,
733 /* ID3D11DeviceChild methods */
734 d3d11_rasterizer_state_GetDevice,
735 d3d11_rasterizer_state_GetPrivateData,
736 d3d11_rasterizer_state_SetPrivateData,
737 d3d11_rasterizer_state_SetPrivateDataInterface,
738 /* ID3D11RasterizerState methods */
739 d3d11_rasterizer_state_GetDesc,
742 /* ID3D10RasterizerState methods */
744 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
746 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
749 /* IUnknown methods */
751 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
752 REFIID riid, void **object)
754 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
756 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
758 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
761 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
763 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
765 TRACE("iface %p.\n", iface);
767 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
770 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
772 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
774 TRACE("iface %p.\n", state);
776 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
779 /* ID3D10DeviceChild methods */
781 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
783 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
785 TRACE("iface %p, device %p.\n", iface, device);
787 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
790 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
791 REFGUID guid, UINT *data_size, void *data)
793 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
795 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
796 iface, debugstr_guid(guid), data_size, data);
798 return d3d_get_private_data(&state->private_store, guid, data_size, data);
801 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
802 REFGUID guid, UINT data_size, const void *data)
804 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
806 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
807 iface, debugstr_guid(guid), data_size, data);
809 return d3d_set_private_data(&state->private_store, guid, data_size, data);
812 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
813 REFGUID guid, const IUnknown *data)
815 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
817 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
819 return d3d_set_private_data_interface(&state->private_store, guid, data);
822 /* ID3D10RasterizerState methods */
824 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
825 D3D10_RASTERIZER_DESC *desc)
827 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
829 TRACE("iface %p, desc %p.\n", iface, desc);
831 memcpy(desc, &state->desc, sizeof(*desc));
834 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
836 /* IUnknown methods */
837 d3d10_rasterizer_state_QueryInterface,
838 d3d10_rasterizer_state_AddRef,
839 d3d10_rasterizer_state_Release,
840 /* ID3D10DeviceChild methods */
841 d3d10_rasterizer_state_GetDevice,
842 d3d10_rasterizer_state_GetPrivateData,
843 d3d10_rasterizer_state_SetPrivateData,
844 d3d10_rasterizer_state_SetPrivateDataInterface,
845 /* ID3D10RasterizerState methods */
846 d3d10_rasterizer_state_GetDesc,
849 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
850 const D3D11_RASTERIZER_DESC *desc)
852 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
853 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
854 state->refcount = 1;
855 wined3d_mutex_lock();
856 wined3d_private_store_init(&state->private_store);
857 state->desc = *desc;
859 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
861 ERR("Failed to insert rasterizer state entry.\n");
862 wined3d_private_store_cleanup(&state->private_store);
863 wined3d_mutex_unlock();
864 return E_FAIL;
866 wined3d_mutex_unlock();
868 state->device = &device->ID3D11Device_iface;
869 ID3D11Device_AddRef(state->device);
871 return S_OK;
874 struct d3d_rasterizer_state *unsafe_impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
876 if (!iface)
877 return NULL;
878 assert(iface->lpVtbl == &d3d11_rasterizer_state_vtbl);
880 return impl_from_ID3D11RasterizerState(iface);
883 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
885 if (!iface)
886 return NULL;
887 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
889 return impl_from_ID3D10RasterizerState(iface);
892 /* ID3D11SampleState methods */
894 static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
896 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface);
899 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface,
900 REFIID riid, void **object)
902 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
904 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
906 if (IsEqualGUID(riid, &IID_ID3D11SamplerState)
907 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
908 || IsEqualGUID(riid, &IID_IUnknown))
910 ID3D11SamplerState_AddRef(iface);
911 *object = iface;
912 return S_OK;
915 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
916 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
918 ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface);
919 *object = &state->ID3D10SamplerState_iface;
920 return S_OK;
923 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
925 *object = NULL;
926 return E_NOINTERFACE;
929 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface)
931 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
932 ULONG refcount = InterlockedIncrement(&state->refcount);
934 TRACE("%p increasing refcount to %u.\n", state, refcount);
936 return refcount;
939 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface)
941 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
942 ULONG refcount = InterlockedDecrement(&state->refcount);
944 TRACE("%p decreasing refcount to %u.\n", state, refcount);
946 if (!refcount)
948 struct d3d_device *device = impl_from_ID3D11Device(state->device);
950 wined3d_mutex_lock();
951 wined3d_sampler_decref(state->wined3d_sampler);
952 wine_rb_remove(&device->sampler_states, &state->desc);
953 ID3D11Device_Release(state->device);
954 wined3d_private_store_cleanup(&state->private_store);
955 wined3d_mutex_unlock();
956 HeapFree(GetProcessHeap(), 0, state);
959 return refcount;
962 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface,
963 ID3D11Device **device)
965 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
967 TRACE("iface %p, device %p.\n", iface, device);
969 *device = state->device;
970 ID3D11Device_AddRef(*device);
973 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface,
974 REFGUID guid, UINT *data_size, void *data)
976 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
978 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
980 return d3d_get_private_data(&state->private_store, guid, data_size, data);
983 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface,
984 REFGUID guid, UINT data_size, const void *data)
986 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
988 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
990 return d3d_set_private_data(&state->private_store, guid, data_size, data);
993 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface,
994 REFGUID guid, const IUnknown *data)
996 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
998 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1000 return d3d_set_private_data_interface(&state->private_store, guid, data);
1003 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface,
1004 D3D11_SAMPLER_DESC *desc)
1006 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1008 TRACE("iface %p, desc %p.\n", iface, desc);
1010 *desc = state->desc;
1013 static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl =
1015 /* IUnknown methods */
1016 d3d11_sampler_state_QueryInterface,
1017 d3d11_sampler_state_AddRef,
1018 d3d11_sampler_state_Release,
1019 /* ID3D11DeviceChild methods */
1020 d3d11_sampler_state_GetDevice,
1021 d3d11_sampler_state_GetPrivateData,
1022 d3d11_sampler_state_SetPrivateData,
1023 d3d11_sampler_state_SetPrivateDataInterface,
1024 /* ID3D11SamplerState methods */
1025 d3d11_sampler_state_GetDesc,
1028 /* ID3D10SamplerState methods */
1030 static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1032 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface);
1035 /* IUnknown methods */
1037 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
1038 REFIID riid, void **object)
1040 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1042 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1044 return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object);
1047 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
1049 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1051 TRACE("iface %p.\n", iface);
1053 return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface);
1056 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
1058 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1060 TRACE("iface %p.\n", iface);
1062 return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface);
1065 /* ID3D10DeviceChild methods */
1067 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
1069 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1071 TRACE("iface %p, device %p.\n", iface, device);
1073 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
1076 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
1077 REFGUID guid, UINT *data_size, void *data)
1079 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1081 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1082 iface, debugstr_guid(guid), data_size, data);
1084 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1087 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
1088 REFGUID guid, UINT data_size, const void *data)
1090 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1092 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1093 iface, debugstr_guid(guid), data_size, data);
1095 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1098 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
1099 REFGUID guid, const IUnknown *data)
1101 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1103 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1105 return d3d_set_private_data_interface(&state->private_store, guid, data);
1108 /* ID3D10SamplerState methods */
1110 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
1111 D3D10_SAMPLER_DESC *desc)
1113 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1115 TRACE("iface %p, desc %p.\n", iface, desc);
1117 memcpy(desc, &state->desc, sizeof(*desc));
1120 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
1122 /* IUnknown methods */
1123 d3d10_sampler_state_QueryInterface,
1124 d3d10_sampler_state_AddRef,
1125 d3d10_sampler_state_Release,
1126 /* ID3D10DeviceChild methods */
1127 d3d10_sampler_state_GetDevice,
1128 d3d10_sampler_state_GetPrivateData,
1129 d3d10_sampler_state_SetPrivateData,
1130 d3d10_sampler_state_SetPrivateDataInterface,
1131 /* ID3D10SamplerState methods */
1132 d3d10_sampler_state_GetDesc,
1135 static enum wined3d_texture_address wined3d_texture_address_from_d3d11(enum D3D11_TEXTURE_ADDRESS_MODE t)
1137 return (enum wined3d_texture_address)t;
1140 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d11(enum D3D11_FILTER f)
1142 if (D3D11_DECODE_MIP_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1143 return WINED3D_TEXF_LINEAR;
1144 return WINED3D_TEXF_POINT;
1147 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d11(enum D3D11_FILTER f)
1149 if (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1150 return WINED3D_TEXF_LINEAR;
1151 return WINED3D_TEXF_POINT;
1154 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d11(enum D3D11_FILTER f)
1156 if (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1157 return WINED3D_TEXF_LINEAR;
1158 return WINED3D_TEXF_POINT;
1161 static BOOL wined3d_texture_compare_from_d3d11(enum D3D11_FILTER f)
1163 return D3D11_DECODE_IS_COMPARISON_FILTER(f);
1166 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f)
1168 return (enum wined3d_cmp_func)f;
1171 HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
1172 const D3D11_SAMPLER_DESC *desc)
1174 struct wined3d_sampler_desc wined3d_desc;
1175 HRESULT hr;
1177 state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl;
1178 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
1179 state->refcount = 1;
1180 wined3d_mutex_lock();
1181 wined3d_private_store_init(&state->private_store);
1182 state->desc = *desc;
1184 wined3d_desc.address_u = wined3d_texture_address_from_d3d11(desc->AddressU);
1185 wined3d_desc.address_v = wined3d_texture_address_from_d3d11(desc->AddressV);
1186 wined3d_desc.address_w = wined3d_texture_address_from_d3d11(desc->AddressW);
1187 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
1188 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d11(desc->Filter);
1189 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d11(desc->Filter);
1190 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d11(desc->Filter);
1191 wined3d_desc.lod_bias = desc->MipLODBias;
1192 wined3d_desc.min_lod = desc->MinLOD;
1193 wined3d_desc.max_lod = desc->MaxLOD;
1194 wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
1195 wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
1196 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
1197 wined3d_desc.srgb_decode = TRUE;
1199 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
1201 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
1202 wined3d_private_store_cleanup(&state->private_store);
1203 wined3d_mutex_unlock();
1204 return hr;
1207 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
1209 ERR("Failed to insert sampler state entry.\n");
1210 wined3d_sampler_decref(state->wined3d_sampler);
1211 wined3d_private_store_cleanup(&state->private_store);
1212 wined3d_mutex_unlock();
1213 return E_FAIL;
1215 wined3d_mutex_unlock();
1217 state->device = &device->ID3D11Device_iface;
1218 ID3D11Device_AddRef(state->device);
1220 return S_OK;
1223 struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
1225 if (!iface)
1226 return NULL;
1227 assert(iface->lpVtbl == &d3d11_sampler_state_vtbl);
1229 return impl_from_ID3D11SamplerState(iface);
1232 struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1234 if (!iface)
1235 return NULL;
1236 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
1238 return impl_from_ID3D10SamplerState(iface);