ddraw/tests: Validate the "surface" pointer is unmodified after CreateSurface() witho...
[wine.git] / dlls / d3d11 / state.c
blob77c8e558bb82de4a4632f149406c6a9e689ebe01
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->entry);
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->entry);
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->entry);
667 wined3d_rasterizer_state_decref(state->wined3d_state);
668 wined3d_private_store_cleanup(&state->private_store);
669 wined3d_mutex_unlock();
670 ID3D11Device_Release(state->device);
671 HeapFree(GetProcessHeap(), 0, state);
674 return refcount;
677 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
678 ID3D11Device **device)
680 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
682 TRACE("iface %p, device %p.\n", iface, device);
684 *device = state->device;
685 ID3D11Device_AddRef(*device);
688 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
689 REFGUID guid, UINT *data_size, void *data)
691 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
693 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
695 return d3d_get_private_data(&state->private_store, guid, data_size, data);
698 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
699 REFGUID guid, UINT data_size, const void *data)
701 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
703 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
705 return d3d_set_private_data(&state->private_store, guid, data_size, data);
708 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
709 REFGUID guid, const IUnknown *data)
711 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
713 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
715 return d3d_set_private_data_interface(&state->private_store, guid, data);
718 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
719 D3D11_RASTERIZER_DESC *desc)
721 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
723 TRACE("iface %p, desc %p.\n", iface, desc);
725 *desc = state->desc;
728 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
730 /* IUnknown methods */
731 d3d11_rasterizer_state_QueryInterface,
732 d3d11_rasterizer_state_AddRef,
733 d3d11_rasterizer_state_Release,
734 /* ID3D11DeviceChild methods */
735 d3d11_rasterizer_state_GetDevice,
736 d3d11_rasterizer_state_GetPrivateData,
737 d3d11_rasterizer_state_SetPrivateData,
738 d3d11_rasterizer_state_SetPrivateDataInterface,
739 /* ID3D11RasterizerState methods */
740 d3d11_rasterizer_state_GetDesc,
743 /* ID3D10RasterizerState methods */
745 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
747 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
750 /* IUnknown methods */
752 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
753 REFIID riid, void **object)
755 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
757 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
759 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
762 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
764 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
766 TRACE("iface %p.\n", iface);
768 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
771 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
773 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
775 TRACE("iface %p.\n", state);
777 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
780 /* ID3D10DeviceChild methods */
782 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
784 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
786 TRACE("iface %p, device %p.\n", iface, device);
788 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
791 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
792 REFGUID guid, UINT *data_size, void *data)
794 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
796 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
797 iface, debugstr_guid(guid), data_size, data);
799 return d3d_get_private_data(&state->private_store, guid, data_size, data);
802 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
803 REFGUID guid, UINT data_size, const void *data)
805 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
807 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
808 iface, debugstr_guid(guid), data_size, data);
810 return d3d_set_private_data(&state->private_store, guid, data_size, data);
813 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
814 REFGUID guid, const IUnknown *data)
816 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
818 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
820 return d3d_set_private_data_interface(&state->private_store, guid, data);
823 /* ID3D10RasterizerState methods */
825 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
826 D3D10_RASTERIZER_DESC *desc)
828 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
830 TRACE("iface %p, desc %p.\n", iface, desc);
832 memcpy(desc, &state->desc, sizeof(*desc));
835 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
837 /* IUnknown methods */
838 d3d10_rasterizer_state_QueryInterface,
839 d3d10_rasterizer_state_AddRef,
840 d3d10_rasterizer_state_Release,
841 /* ID3D10DeviceChild methods */
842 d3d10_rasterizer_state_GetDevice,
843 d3d10_rasterizer_state_GetPrivateData,
844 d3d10_rasterizer_state_SetPrivateData,
845 d3d10_rasterizer_state_SetPrivateDataInterface,
846 /* ID3D10RasterizerState methods */
847 d3d10_rasterizer_state_GetDesc,
850 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
851 const D3D11_RASTERIZER_DESC *desc)
853 struct wined3d_rasterizer_state_desc wined3d_desc;
854 HRESULT hr;
856 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
857 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
858 state->refcount = 1;
859 wined3d_mutex_lock();
860 wined3d_private_store_init(&state->private_store);
861 state->desc = *desc;
863 wined3d_desc.front_ccw = desc->FrontCounterClockwise;
864 if (FAILED(hr = wined3d_rasterizer_state_create(device->wined3d_device,
865 &wined3d_desc, &state->wined3d_state)))
867 WARN("Failed to create wined3d rasterizer state, hr %#x.\n", hr);
868 wined3d_private_store_cleanup(&state->private_store);
869 wined3d_mutex_unlock();
870 return hr;
873 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
875 ERR("Failed to insert rasterizer state entry.\n");
876 wined3d_private_store_cleanup(&state->private_store);
877 wined3d_rasterizer_state_decref(state->wined3d_state);
878 wined3d_mutex_unlock();
879 return E_FAIL;
881 wined3d_mutex_unlock();
883 ID3D11Device_AddRef(state->device = &device->ID3D11Device_iface);
885 return S_OK;
888 struct d3d_rasterizer_state *unsafe_impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
890 if (!iface)
891 return NULL;
892 assert(iface->lpVtbl == &d3d11_rasterizer_state_vtbl);
894 return impl_from_ID3D11RasterizerState(iface);
897 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
899 if (!iface)
900 return NULL;
901 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
903 return impl_from_ID3D10RasterizerState(iface);
906 /* ID3D11SampleState methods */
908 static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
910 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface);
913 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface,
914 REFIID riid, void **object)
916 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
918 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
920 if (IsEqualGUID(riid, &IID_ID3D11SamplerState)
921 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
922 || IsEqualGUID(riid, &IID_IUnknown))
924 ID3D11SamplerState_AddRef(iface);
925 *object = iface;
926 return S_OK;
929 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
930 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
932 ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface);
933 *object = &state->ID3D10SamplerState_iface;
934 return S_OK;
937 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
939 *object = NULL;
940 return E_NOINTERFACE;
943 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface)
945 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
946 ULONG refcount = InterlockedIncrement(&state->refcount);
948 TRACE("%p increasing refcount to %u.\n", state, refcount);
950 return refcount;
953 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface)
955 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
956 ULONG refcount = InterlockedDecrement(&state->refcount);
958 TRACE("%p decreasing refcount to %u.\n", state, refcount);
960 if (!refcount)
962 struct d3d_device *device = impl_from_ID3D11Device(state->device);
964 wined3d_mutex_lock();
965 wined3d_sampler_decref(state->wined3d_sampler);
966 wine_rb_remove(&device->sampler_states, &state->entry);
967 ID3D11Device_Release(state->device);
968 wined3d_private_store_cleanup(&state->private_store);
969 wined3d_mutex_unlock();
970 HeapFree(GetProcessHeap(), 0, state);
973 return refcount;
976 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface,
977 ID3D11Device **device)
979 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
981 TRACE("iface %p, device %p.\n", iface, device);
983 *device = state->device;
984 ID3D11Device_AddRef(*device);
987 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface,
988 REFGUID guid, UINT *data_size, void *data)
990 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
992 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
994 return d3d_get_private_data(&state->private_store, guid, data_size, data);
997 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface,
998 REFGUID guid, UINT data_size, const void *data)
1000 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1002 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1004 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1007 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface,
1008 REFGUID guid, const IUnknown *data)
1010 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1012 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1014 return d3d_set_private_data_interface(&state->private_store, guid, data);
1017 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface,
1018 D3D11_SAMPLER_DESC *desc)
1020 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1022 TRACE("iface %p, desc %p.\n", iface, desc);
1024 *desc = state->desc;
1027 static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl =
1029 /* IUnknown methods */
1030 d3d11_sampler_state_QueryInterface,
1031 d3d11_sampler_state_AddRef,
1032 d3d11_sampler_state_Release,
1033 /* ID3D11DeviceChild methods */
1034 d3d11_sampler_state_GetDevice,
1035 d3d11_sampler_state_GetPrivateData,
1036 d3d11_sampler_state_SetPrivateData,
1037 d3d11_sampler_state_SetPrivateDataInterface,
1038 /* ID3D11SamplerState methods */
1039 d3d11_sampler_state_GetDesc,
1042 /* ID3D10SamplerState methods */
1044 static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1046 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface);
1049 /* IUnknown methods */
1051 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
1052 REFIID riid, void **object)
1054 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1056 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1058 return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object);
1061 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
1063 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1065 TRACE("iface %p.\n", iface);
1067 return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface);
1070 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
1072 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1074 TRACE("iface %p.\n", iface);
1076 return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface);
1079 /* ID3D10DeviceChild methods */
1081 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
1083 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1085 TRACE("iface %p, device %p.\n", iface, device);
1087 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
1090 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
1091 REFGUID guid, UINT *data_size, void *data)
1093 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1095 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1096 iface, debugstr_guid(guid), data_size, data);
1098 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1101 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
1102 REFGUID guid, UINT data_size, const void *data)
1104 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1106 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1107 iface, debugstr_guid(guid), data_size, data);
1109 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1112 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
1113 REFGUID guid, const IUnknown *data)
1115 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1117 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1119 return d3d_set_private_data_interface(&state->private_store, guid, data);
1122 /* ID3D10SamplerState methods */
1124 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
1125 D3D10_SAMPLER_DESC *desc)
1127 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1129 TRACE("iface %p, desc %p.\n", iface, desc);
1131 memcpy(desc, &state->desc, sizeof(*desc));
1134 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
1136 /* IUnknown methods */
1137 d3d10_sampler_state_QueryInterface,
1138 d3d10_sampler_state_AddRef,
1139 d3d10_sampler_state_Release,
1140 /* ID3D10DeviceChild methods */
1141 d3d10_sampler_state_GetDevice,
1142 d3d10_sampler_state_GetPrivateData,
1143 d3d10_sampler_state_SetPrivateData,
1144 d3d10_sampler_state_SetPrivateDataInterface,
1145 /* ID3D10SamplerState methods */
1146 d3d10_sampler_state_GetDesc,
1149 static enum wined3d_texture_address wined3d_texture_address_from_d3d11(enum D3D11_TEXTURE_ADDRESS_MODE t)
1151 return (enum wined3d_texture_address)t;
1154 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d11(enum D3D11_FILTER f)
1156 if (D3D11_DECODE_MIP_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1157 return WINED3D_TEXF_LINEAR;
1158 return WINED3D_TEXF_POINT;
1161 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d11(enum D3D11_FILTER f)
1163 if (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1164 return WINED3D_TEXF_LINEAR;
1165 return WINED3D_TEXF_POINT;
1168 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d11(enum D3D11_FILTER f)
1170 if (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1171 return WINED3D_TEXF_LINEAR;
1172 return WINED3D_TEXF_POINT;
1175 static BOOL wined3d_texture_compare_from_d3d11(enum D3D11_FILTER f)
1177 return D3D11_DECODE_IS_COMPARISON_FILTER(f);
1180 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f)
1182 return (enum wined3d_cmp_func)f;
1185 HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
1186 const D3D11_SAMPLER_DESC *desc)
1188 struct wined3d_sampler_desc wined3d_desc;
1189 HRESULT hr;
1191 state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl;
1192 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
1193 state->refcount = 1;
1194 wined3d_mutex_lock();
1195 wined3d_private_store_init(&state->private_store);
1196 state->desc = *desc;
1198 wined3d_desc.address_u = wined3d_texture_address_from_d3d11(desc->AddressU);
1199 wined3d_desc.address_v = wined3d_texture_address_from_d3d11(desc->AddressV);
1200 wined3d_desc.address_w = wined3d_texture_address_from_d3d11(desc->AddressW);
1201 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
1202 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d11(desc->Filter);
1203 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d11(desc->Filter);
1204 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d11(desc->Filter);
1205 wined3d_desc.lod_bias = desc->MipLODBias;
1206 wined3d_desc.min_lod = desc->MinLOD;
1207 wined3d_desc.max_lod = desc->MaxLOD;
1208 wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
1209 wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
1210 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
1211 wined3d_desc.srgb_decode = TRUE;
1213 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
1215 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
1216 wined3d_private_store_cleanup(&state->private_store);
1217 wined3d_mutex_unlock();
1218 return hr;
1221 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
1223 ERR("Failed to insert sampler state entry.\n");
1224 wined3d_sampler_decref(state->wined3d_sampler);
1225 wined3d_private_store_cleanup(&state->private_store);
1226 wined3d_mutex_unlock();
1227 return E_FAIL;
1229 wined3d_mutex_unlock();
1231 state->device = &device->ID3D11Device_iface;
1232 ID3D11Device_AddRef(state->device);
1234 return S_OK;
1237 struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
1239 if (!iface)
1240 return NULL;
1241 assert(iface->lpVtbl == &d3d11_sampler_state_vtbl);
1243 return impl_from_ID3D11SamplerState(iface);
1246 struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1248 if (!iface)
1249 return NULL;
1250 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
1252 return impl_from_ID3D10SamplerState(iface);