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
21 #include "wine/port.h"
23 #define NONAMELESSUNION
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
28 static HRESULT
set_dsdesc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
30 D3D11_RESOURCE_DIMENSION dimension
;
32 ID3D11Resource_GetType(resource
, &dimension
);
38 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
40 D3D11_TEXTURE1D_DESC texture_desc
;
41 ID3D11Texture1D
*texture
;
43 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
45 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
49 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
50 ID3D11Texture1D_Release(texture
);
52 desc
->Format
= texture_desc
.Format
;
53 if (texture_desc
.ArraySize
== 1)
55 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1D
;
56 desc
->u
.Texture1D
.MipSlice
= 0;
60 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
;
61 desc
->u
.Texture1DArray
.MipSlice
= 0;
62 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
63 desc
->u
.Texture1DArray
.ArraySize
= 1;
69 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
71 D3D11_TEXTURE2D_DESC texture_desc
;
72 ID3D11Texture2D
*texture
;
74 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
76 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
80 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
81 ID3D11Texture2D_Release(texture
);
83 desc
->Format
= texture_desc
.Format
;
84 if (texture_desc
.ArraySize
== 1)
86 if (texture_desc
.SampleDesc
.Count
== 1)
88 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2D
;
89 desc
->u
.Texture2D
.MipSlice
= 0;
93 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMS
;
98 if (texture_desc
.SampleDesc
.Count
== 1)
100 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
;
101 desc
->u
.Texture2DArray
.MipSlice
= 0;
102 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
103 desc
->u
.Texture2DArray
.ArraySize
= 1;
107 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
;
108 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
109 desc
->u
.Texture2DMSArray
.ArraySize
= 1;
117 FIXME("Unhandled resource dimension %#x.\n", dimension
);
118 case D3D11_RESOURCE_DIMENSION_BUFFER
:
119 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
124 static HRESULT
set_rtdesc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
126 D3D11_RESOURCE_DIMENSION dimension
;
129 ID3D11Resource_GetType(resource
, &dimension
);
133 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
135 ID3D11Texture1D
*texture
;
136 D3D11_TEXTURE1D_DESC texture_desc
;
138 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
);
141 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D?\n");
145 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
146 ID3D11Texture1D_Release(texture
);
148 desc
->Format
= texture_desc
.Format
;
149 if (texture_desc
.ArraySize
== 1)
151 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1D
;
152 desc
->u
.Texture1D
.MipSlice
= 0;
156 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
;
157 desc
->u
.Texture1DArray
.MipSlice
= 0;
158 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
159 desc
->u
.Texture1DArray
.ArraySize
= 1;
165 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
167 ID3D11Texture2D
*texture
;
168 D3D11_TEXTURE2D_DESC texture_desc
;
170 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
);
173 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D?\n");
177 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
178 ID3D11Texture2D_Release(texture
);
180 desc
->Format
= texture_desc
.Format
;
181 if (texture_desc
.ArraySize
== 1)
183 if (texture_desc
.SampleDesc
.Count
== 1)
185 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2D
;
186 desc
->u
.Texture2D
.MipSlice
= 0;
190 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMS
;
195 if (texture_desc
.SampleDesc
.Count
== 1)
197 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
;
198 desc
->u
.Texture2DArray
.MipSlice
= 0;
199 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
200 desc
->u
.Texture2DArray
.ArraySize
= 1;
204 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
;
205 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
206 desc
->u
.Texture2DMSArray
.ArraySize
= 1;
213 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
215 ID3D11Texture3D
*texture
;
216 D3D11_TEXTURE3D_DESC texture_desc
;
218 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
);
221 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D?\n");
225 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
226 ID3D11Texture3D_Release(texture
);
228 desc
->Format
= texture_desc
.Format
;
229 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE3D
;
230 desc
->u
.Texture3D
.MipSlice
= 0;
231 desc
->u
.Texture3D
.FirstWSlice
= 0;
232 desc
->u
.Texture3D
.WSize
= 1;
238 FIXME("Unhandled resource dimension %#x.\n", dimension
);
243 static HRESULT
set_srdesc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
245 D3D11_RESOURCE_DIMENSION dimension
;
247 ID3D11Resource_GetType(resource
, &dimension
);
251 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
253 D3D11_TEXTURE1D_DESC texture_desc
;
254 ID3D11Texture1D
*texture
;
256 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
258 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
262 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
263 ID3D11Texture1D_Release(texture
);
265 desc
->Format
= texture_desc
.Format
;
266 if (texture_desc
.ArraySize
== 1)
268 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1D
;
269 desc
->u
.Texture1D
.MostDetailedMip
= 0;
270 desc
->u
.Texture1D
.MipLevels
= texture_desc
.MipLevels
;
274 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
;
275 desc
->u
.Texture1DArray
.MostDetailedMip
= 0;
276 desc
->u
.Texture1DArray
.MipLevels
= texture_desc
.MipLevels
;
277 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
278 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
284 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
286 D3D11_TEXTURE2D_DESC texture_desc
;
287 ID3D11Texture2D
*texture
;
289 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
291 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
295 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
296 ID3D11Texture2D_Release(texture
);
298 desc
->Format
= texture_desc
.Format
;
299 if (texture_desc
.ArraySize
== 1)
301 if (texture_desc
.SampleDesc
.Count
== 1)
303 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2D
;
304 desc
->u
.Texture2D
.MostDetailedMip
= 0;
305 desc
->u
.Texture2D
.MipLevels
= texture_desc
.MipLevels
;
309 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMS
;
314 if (texture_desc
.SampleDesc
.Count
== 1)
316 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
;
317 desc
->u
.Texture2DArray
.MostDetailedMip
= 0;
318 desc
->u
.Texture2DArray
.MipLevels
= texture_desc
.MipLevels
;
319 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
320 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
324 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
;
325 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
326 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
333 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
335 D3D11_TEXTURE3D_DESC texture_desc
;
336 ID3D11Texture3D
*texture
;
338 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
340 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
344 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
345 ID3D11Texture3D_Release(texture
);
347 desc
->Format
= texture_desc
.Format
;
348 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE3D
;
349 desc
->u
.Texture3D
.MostDetailedMip
= 0;
350 desc
->u
.Texture3D
.MipLevels
= texture_desc
.MipLevels
;
356 FIXME("Unhandled resource dimension %#x.\n", dimension
);
357 case D3D11_RESOURCE_DIMENSION_BUFFER
:
362 /* ID3D11DepthStencilView methods */
364 static inline struct d3d_depthstencil_view
*impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
366 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D11DepthStencilView_iface
);
369 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_QueryInterface(ID3D11DepthStencilView
*iface
,
370 REFIID riid
, void **object
)
372 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
374 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
376 if (IsEqualGUID(riid
, &IID_ID3D11DepthStencilView
)
377 || IsEqualGUID(riid
, &IID_ID3D11View
)
378 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
379 || IsEqualGUID(riid
, &IID_IUnknown
))
381 ID3D11DepthStencilView_AddRef(iface
);
386 if (IsEqualGUID(riid
, &IID_ID3D10DepthStencilView
)
387 || IsEqualGUID(riid
, &IID_ID3D10View
)
388 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
390 ID3D10DepthStencilView_AddRef(&view
->ID3D10DepthStencilView_iface
);
391 *object
= &view
->ID3D10DepthStencilView_iface
;
395 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
398 return E_NOINTERFACE
;
401 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_AddRef(ID3D11DepthStencilView
*iface
)
403 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
404 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
406 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
411 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_Release(ID3D11DepthStencilView
*iface
)
413 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
414 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
416 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
420 wined3d_mutex_lock();
421 wined3d_rendertarget_view_decref(view
->wined3d_view
);
422 ID3D11Resource_Release(view
->resource
);
423 ID3D11Device_Release(view
->device
);
424 wined3d_private_store_cleanup(&view
->private_store
);
425 wined3d_mutex_unlock();
426 HeapFree(GetProcessHeap(), 0, view
);
432 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDevice(ID3D11DepthStencilView
*iface
,
433 ID3D11Device
**device
)
435 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
437 TRACE("iface %p, device %p.\n", iface
, device
);
439 *device
= view
->device
;
440 ID3D11Device_AddRef(*device
);
443 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_GetPrivateData(ID3D11DepthStencilView
*iface
,
444 REFGUID guid
, UINT
*data_size
, void *data
)
446 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
448 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
450 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
453 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateData(ID3D11DepthStencilView
*iface
,
454 REFGUID guid
, UINT data_size
, const void *data
)
456 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
458 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
460 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
463 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateDataInterface(ID3D11DepthStencilView
*iface
,
464 REFGUID guid
, const IUnknown
*data
)
466 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
468 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
470 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
473 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView
*iface
,
474 ID3D11Resource
**resource
)
476 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
478 TRACE("iface %p, resource %p.\n", iface
, resource
);
480 *resource
= view
->resource
;
481 ID3D11Resource_AddRef(*resource
);
484 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView
*iface
,
485 D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
487 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
489 TRACE("iface %p, desc %p.\n", iface
, desc
);
494 static const struct ID3D11DepthStencilViewVtbl d3d11_depthstencil_view_vtbl
=
496 /* IUnknown methods */
497 d3d11_depthstencil_view_QueryInterface
,
498 d3d11_depthstencil_view_AddRef
,
499 d3d11_depthstencil_view_Release
,
500 /* ID3D11DeviceChild methods */
501 d3d11_depthstencil_view_GetDevice
,
502 d3d11_depthstencil_view_GetPrivateData
,
503 d3d11_depthstencil_view_SetPrivateData
,
504 d3d11_depthstencil_view_SetPrivateDataInterface
,
505 /* ID3D11View methods */
506 d3d11_depthstencil_view_GetResource
,
507 /* ID3D11DepthStencilView methods */
508 d3d11_depthstencil_view_GetDesc
,
511 /* ID3D10DepthStencilView methods */
513 static inline struct d3d_depthstencil_view
*impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
515 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D10DepthStencilView_iface
);
518 /* IUnknown methods */
520 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView
*iface
,
521 REFIID riid
, void **object
)
523 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
525 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
527 return d3d11_depthstencil_view_QueryInterface(&view
->ID3D11DepthStencilView_iface
, riid
, object
);
530 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView
*iface
)
532 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
534 TRACE("iface %p.\n", iface
);
536 return d3d11_depthstencil_view_AddRef(&view
->ID3D11DepthStencilView_iface
);
539 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_Release(ID3D10DepthStencilView
*iface
)
541 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
543 TRACE("iface %p.\n", iface
);
545 return d3d11_depthstencil_view_Release(&view
->ID3D11DepthStencilView_iface
);
548 /* ID3D10DeviceChild methods */
550 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView
*iface
, ID3D10Device
**device
)
552 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
554 TRACE("iface %p, device %p.\n", iface
, device
);
556 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
559 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView
*iface
,
560 REFGUID guid
, UINT
*data_size
, void *data
)
562 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
564 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
565 iface
, debugstr_guid(guid
), data_size
, data
);
567 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
570 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView
*iface
,
571 REFGUID guid
, UINT data_size
, const void *data
)
573 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
575 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
576 iface
, debugstr_guid(guid
), data_size
, data
);
578 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
581 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView
*iface
,
582 REFGUID guid
, const IUnknown
*data
)
584 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
586 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
588 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
591 /* ID3D10View methods */
593 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView
*iface
,
594 ID3D10Resource
**resource
)
596 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
598 TRACE("iface %p, resource %p.\n", iface
, resource
);
600 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
603 /* ID3D10DepthStencilView methods */
605 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView
*iface
,
606 D3D10_DEPTH_STENCIL_VIEW_DESC
*desc
)
608 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
609 const D3D11_DEPTH_STENCIL_VIEW_DESC
*d3d11_desc
= &view
->desc
;
611 TRACE("iface %p, desc %p.\n", iface
, desc
);
613 desc
->Format
= d3d11_desc
->Format
;
614 desc
->ViewDimension
= (D3D10_DSV_DIMENSION
)d3d11_desc
->ViewDimension
;
615 memcpy(&desc
->u
, &d3d11_desc
->u
, sizeof(desc
->u
));
618 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl
=
620 /* IUnknown methods */
621 d3d10_depthstencil_view_QueryInterface
,
622 d3d10_depthstencil_view_AddRef
,
623 d3d10_depthstencil_view_Release
,
624 /* ID3D10DeviceChild methods */
625 d3d10_depthstencil_view_GetDevice
,
626 d3d10_depthstencil_view_GetPrivateData
,
627 d3d10_depthstencil_view_SetPrivateData
,
628 d3d10_depthstencil_view_SetPrivateDataInterface
,
629 /* ID3D10View methods */
630 d3d10_depthstencil_view_GetResource
,
631 /* ID3D10DepthStencilView methods */
632 d3d10_depthstencil_view_GetDesc
,
635 static void wined3d_depth_stencil_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc
*wined3d_desc
,
636 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
638 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
641 FIXME("Unhandled depth stencil view flags %#x.\n", desc
->Flags
);
643 switch (desc
->ViewDimension
)
645 case D3D11_DSV_DIMENSION_TEXTURE1D
:
646 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
647 wined3d_desc
->u
.texture
.layer_idx
= 0;
648 wined3d_desc
->u
.texture
.layer_count
= 1;
651 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
652 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
653 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
654 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
657 case D3D11_DSV_DIMENSION_TEXTURE2D
:
658 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
659 wined3d_desc
->u
.texture
.layer_idx
= 0;
660 wined3d_desc
->u
.texture
.layer_count
= 1;
663 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
664 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
665 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
666 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
669 case D3D11_DSV_DIMENSION_TEXTURE2DMS
:
670 wined3d_desc
->u
.texture
.level_idx
= 0;
671 wined3d_desc
->u
.texture
.layer_idx
= 0;
672 wined3d_desc
->u
.texture
.layer_count
= 1;
675 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
676 wined3d_desc
->u
.texture
.level_idx
= 0;
677 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
678 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
682 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
683 wined3d_desc
->u
.texture
.level_idx
= 0;
684 wined3d_desc
->u
.texture
.layer_idx
= 0;
685 wined3d_desc
->u
.texture
.layer_count
= 1;
690 static HRESULT
d3d_depthstencil_view_init(struct d3d_depthstencil_view
*view
, struct d3d_device
*device
,
691 ID3D11Resource
*resource
, const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
693 struct wined3d_rendertarget_view_desc wined3d_desc
;
694 struct wined3d_resource
*wined3d_resource
;
697 view
->ID3D11DepthStencilView_iface
.lpVtbl
= &d3d11_depthstencil_view_vtbl
;
698 view
->ID3D10DepthStencilView_iface
.lpVtbl
= &d3d10_depthstencil_view_vtbl
;
703 if (FAILED(hr
= set_dsdesc_from_resource(&view
->desc
, resource
)))
711 wined3d_mutex_lock();
712 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
714 wined3d_mutex_unlock();
715 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
719 wined3d_depth_stencil_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
720 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
721 view
, &d3d10_null_wined3d_parent_ops
, &view
->wined3d_view
)))
723 wined3d_mutex_unlock();
724 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
728 wined3d_private_store_init(&view
->private_store
);
729 wined3d_mutex_unlock();
730 view
->resource
= resource
;
731 ID3D11Resource_AddRef(resource
);
732 view
->device
= &device
->ID3D11Device_iface
;
733 ID3D11Device_AddRef(view
->device
);
738 HRESULT
d3d_depthstencil_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
739 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, struct d3d_depthstencil_view
**view
)
741 struct d3d_depthstencil_view
*object
;
744 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
745 return E_OUTOFMEMORY
;
747 if (FAILED(hr
= d3d_depthstencil_view_init(object
, device
, resource
, desc
)))
749 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr
);
750 HeapFree(GetProcessHeap(), 0, object
);
754 TRACE("Created depthstencil view %p.\n", object
);
760 struct d3d_depthstencil_view
*unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
764 assert(iface
->lpVtbl
== &d3d10_depthstencil_view_vtbl
);
766 return impl_from_ID3D10DepthStencilView(iface
);
769 /* ID3D11RenderTargetView methods */
771 static inline struct d3d_rendertarget_view
*impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView
*iface
)
773 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D11RenderTargetView_iface
);
776 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_QueryInterface(ID3D11RenderTargetView
*iface
,
777 REFIID riid
, void **object
)
779 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
781 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
783 if (IsEqualGUID(riid
, &IID_ID3D11RenderTargetView
)
784 || IsEqualGUID(riid
, &IID_ID3D11View
)
785 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
786 || IsEqualGUID(riid
, &IID_IUnknown
))
788 ID3D11RenderTargetView_AddRef(iface
);
793 if (IsEqualGUID(riid
, &IID_ID3D10RenderTargetView
)
794 || IsEqualGUID(riid
, &IID_ID3D10View
)
795 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
797 ID3D10RenderTargetView_AddRef(&view
->ID3D10RenderTargetView_iface
);
798 *object
= &view
->ID3D10RenderTargetView_iface
;
802 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
805 return E_NOINTERFACE
;
808 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_AddRef(ID3D11RenderTargetView
*iface
)
810 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
811 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
813 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
818 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_Release(ID3D11RenderTargetView
*iface
)
820 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
821 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
823 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
827 wined3d_mutex_lock();
828 wined3d_rendertarget_view_decref(view
->wined3d_view
);
829 ID3D11Resource_Release(view
->resource
);
830 ID3D11Device_Release(view
->device
);
831 wined3d_private_store_cleanup(&view
->private_store
);
832 wined3d_mutex_unlock();
833 HeapFree(GetProcessHeap(), 0, view
);
839 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDevice(ID3D11RenderTargetView
*iface
,
840 ID3D11Device
**device
)
842 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
844 TRACE("iface %p, device %p.\n", iface
, device
);
846 *device
= view
->device
;
847 ID3D11Device_AddRef(*device
);
850 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_GetPrivateData(ID3D11RenderTargetView
*iface
,
851 REFGUID guid
, UINT
*data_size
, void *data
)
853 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
855 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
857 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
860 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateData(ID3D11RenderTargetView
*iface
,
861 REFGUID guid
, UINT data_size
, const void *data
)
863 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
865 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
867 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
870 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateDataInterface(ID3D11RenderTargetView
*iface
,
871 REFGUID guid
, const IUnknown
*data
)
873 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
875 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
877 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
880 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetResource(ID3D11RenderTargetView
*iface
,
881 ID3D11Resource
**resource
)
883 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
885 TRACE("iface %p, resource %p.\n", iface
, resource
);
887 *resource
= view
->resource
;
888 ID3D11Resource_AddRef(*resource
);
891 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDesc(ID3D11RenderTargetView
*iface
,
892 D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
894 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
896 TRACE("iface %p, desc %p.\n", iface
, desc
);
901 static const struct ID3D11RenderTargetViewVtbl d3d11_rendertarget_view_vtbl
=
903 /* IUnknown methods */
904 d3d11_rendertarget_view_QueryInterface
,
905 d3d11_rendertarget_view_AddRef
,
906 d3d11_rendertarget_view_Release
,
907 /* ID3D11DeviceChild methods */
908 d3d11_rendertarget_view_GetDevice
,
909 d3d11_rendertarget_view_GetPrivateData
,
910 d3d11_rendertarget_view_SetPrivateData
,
911 d3d11_rendertarget_view_SetPrivateDataInterface
,
912 /* ID3D11View methods */
913 d3d11_rendertarget_view_GetResource
,
914 /* ID3D11RenderTargetView methods */
915 d3d11_rendertarget_view_GetDesc
,
918 /* ID3D10RenderTargetView methods */
920 static inline struct d3d_rendertarget_view
*impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
922 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D10RenderTargetView_iface
);
925 /* IUnknown methods */
927 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView
*iface
,
928 REFIID riid
, void **object
)
930 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
932 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
934 return d3d11_rendertarget_view_QueryInterface(&view
->ID3D11RenderTargetView_iface
, riid
, object
);
937 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView
*iface
)
939 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
941 TRACE("iface %p.\n", iface
);
943 return d3d11_rendertarget_view_AddRef(&view
->ID3D11RenderTargetView_iface
);
946 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_Release(ID3D10RenderTargetView
*iface
)
948 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
950 TRACE("iface %p.\n", iface
);
952 return d3d11_rendertarget_view_Release(&view
->ID3D11RenderTargetView_iface
);
955 /* ID3D10DeviceChild methods */
957 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView
*iface
, ID3D10Device
**device
)
959 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
961 TRACE("iface %p, device %p.\n", iface
, device
);
963 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
966 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView
*iface
,
967 REFGUID guid
, UINT
*data_size
, void *data
)
969 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
971 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
972 iface
, debugstr_guid(guid
), data_size
, data
);
974 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
977 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView
*iface
,
978 REFGUID guid
, UINT data_size
, const void *data
)
980 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
982 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
983 iface
, debugstr_guid(guid
), data_size
, data
);
985 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
988 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView
*iface
,
989 REFGUID guid
, const IUnknown
*data
)
991 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
993 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
995 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
998 /* ID3D10View methods */
1000 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView
*iface
,
1001 ID3D10Resource
**resource
)
1003 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1005 TRACE("iface %p, resource %p\n", iface
, resource
);
1007 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1010 /* ID3D10RenderTargetView methods */
1012 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView
*iface
,
1013 D3D10_RENDER_TARGET_VIEW_DESC
*desc
)
1015 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1017 TRACE("iface %p, desc %p\n", iface
, desc
);
1019 memcpy(desc
, &view
->desc
, sizeof(*desc
));
1022 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl
=
1024 /* IUnknown methods */
1025 d3d10_rendertarget_view_QueryInterface
,
1026 d3d10_rendertarget_view_AddRef
,
1027 d3d10_rendertarget_view_Release
,
1028 /* ID3D10DeviceChild methods */
1029 d3d10_rendertarget_view_GetDevice
,
1030 d3d10_rendertarget_view_GetPrivateData
,
1031 d3d10_rendertarget_view_SetPrivateData
,
1032 d3d10_rendertarget_view_SetPrivateDataInterface
,
1033 /* ID3D10View methods */
1034 d3d10_rendertarget_view_GetResource
,
1035 /* ID3D10RenderTargetView methods */
1036 d3d10_rendertarget_view_GetDesc
,
1039 static void wined3d_rendertarget_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc
*wined3d_desc
,
1040 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1042 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1044 switch (desc
->ViewDimension
)
1046 case D3D11_RTV_DIMENSION_BUFFER
:
1047 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.u1
.FirstElement
;
1048 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.u2
.NumElements
;
1051 case D3D11_RTV_DIMENSION_TEXTURE1D
:
1052 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
1053 wined3d_desc
->u
.texture
.layer_idx
= 0;
1054 wined3d_desc
->u
.texture
.layer_count
= 1;
1057 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
1058 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
1059 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
1060 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
1063 case D3D11_RTV_DIMENSION_TEXTURE2D
:
1064 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
1065 wined3d_desc
->u
.texture
.layer_idx
= 0;
1066 wined3d_desc
->u
.texture
.layer_count
= 1;
1069 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
1070 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
1071 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
1072 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
1075 case D3D11_RTV_DIMENSION_TEXTURE2DMS
:
1076 wined3d_desc
->u
.texture
.level_idx
= 0;
1077 wined3d_desc
->u
.texture
.layer_idx
= 0;
1078 wined3d_desc
->u
.texture
.layer_count
= 1;
1081 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
1082 wined3d_desc
->u
.texture
.level_idx
= 0;
1083 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
1084 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
1087 case D3D11_RTV_DIMENSION_TEXTURE3D
:
1088 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MipSlice
;
1089 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture3D
.FirstWSlice
;
1090 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture3D
.WSize
;
1094 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
1095 wined3d_desc
->u
.texture
.level_idx
= 0;
1096 wined3d_desc
->u
.texture
.layer_idx
= 0;
1097 wined3d_desc
->u
.texture
.layer_count
= 1;
1102 static HRESULT
d3d_rendertarget_view_init(struct d3d_rendertarget_view
*view
, struct d3d_device
*device
,
1103 ID3D11Resource
*resource
, const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1105 struct wined3d_rendertarget_view_desc wined3d_desc
;
1106 struct wined3d_resource
*wined3d_resource
;
1109 view
->ID3D11RenderTargetView_iface
.lpVtbl
= &d3d11_rendertarget_view_vtbl
;
1110 view
->ID3D10RenderTargetView_iface
.lpVtbl
= &d3d10_rendertarget_view_vtbl
;
1115 HRESULT hr
= set_rtdesc_from_resource(&view
->desc
, resource
);
1116 if (FAILED(hr
)) return hr
;
1123 wined3d_mutex_lock();
1124 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1126 wined3d_mutex_unlock();
1127 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
1131 wined3d_rendertarget_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
1132 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
1133 view
, &d3d10_null_wined3d_parent_ops
, &view
->wined3d_view
)))
1135 wined3d_mutex_unlock();
1136 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
1140 wined3d_private_store_init(&view
->private_store
);
1141 wined3d_mutex_unlock();
1142 view
->resource
= resource
;
1143 ID3D11Resource_AddRef(resource
);
1144 view
->device
= &device
->ID3D11Device_iface
;
1145 ID3D11Device_AddRef(view
->device
);
1150 HRESULT
d3d_rendertarget_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1151 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
, struct d3d_rendertarget_view
**view
)
1153 struct d3d_rendertarget_view
*object
;
1156 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1157 return E_OUTOFMEMORY
;
1159 if (FAILED(hr
= d3d_rendertarget_view_init(object
, device
, resource
, desc
)))
1161 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr
);
1162 HeapFree(GetProcessHeap(), 0, object
);
1166 TRACE("Created rendertarget view %p.\n", object
);
1172 struct d3d_rendertarget_view
*unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
1176 assert(iface
->lpVtbl
== &d3d10_rendertarget_view_vtbl
);
1178 return impl_from_ID3D10RenderTargetView(iface
);
1181 /* ID3D11ShaderResourceView methods */
1183 struct d3d_shader_resource_view
*impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView
*iface
)
1185 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D11ShaderResourceView_iface
);
1188 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_QueryInterface(ID3D11ShaderResourceView
*iface
,
1189 REFIID riid
, void **object
)
1191 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1193 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1195 if (IsEqualGUID(riid
, &IID_ID3D11ShaderResourceView
)
1196 || IsEqualGUID(riid
, &IID_ID3D11View
)
1197 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
1198 || IsEqualGUID(riid
, &IID_IUnknown
))
1200 ID3D11ShaderResourceView_AddRef(iface
);
1205 if (IsEqualGUID(riid
, &IID_ID3D10ShaderResourceView
)
1206 || IsEqualGUID(riid
, &IID_ID3D10View
)
1207 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
1209 ID3D10ShaderResourceView_AddRef(&view
->ID3D10ShaderResourceView_iface
);
1210 *object
= &view
->ID3D10ShaderResourceView_iface
;
1214 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1217 return E_NOINTERFACE
;
1220 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_AddRef(ID3D11ShaderResourceView
*iface
)
1222 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1223 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
1225 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
1230 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_Release(ID3D11ShaderResourceView
*iface
)
1232 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1233 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
1235 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
1239 wined3d_mutex_lock();
1240 wined3d_shader_resource_view_decref(view
->wined3d_view
);
1241 ID3D11Resource_Release(view
->resource
);
1242 ID3D11Device_Release(view
->device
);
1243 wined3d_private_store_cleanup(&view
->private_store
);
1244 wined3d_mutex_unlock();
1245 HeapFree(GetProcessHeap(), 0, view
);
1251 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDevice(ID3D11ShaderResourceView
*iface
,
1252 ID3D11Device
**device
)
1254 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1256 TRACE("iface %p, device %p.\n", iface
, device
);
1258 *device
= view
->device
;
1259 ID3D11Device_AddRef(*device
);
1262 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_GetPrivateData(ID3D11ShaderResourceView
*iface
,
1263 REFGUID guid
, UINT
*data_size
, void *data
)
1265 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1267 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1269 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1272 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateData(ID3D11ShaderResourceView
*iface
,
1273 REFGUID guid
, UINT data_size
, const void *data
)
1275 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1277 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1279 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1282 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateDataInterface(ID3D11ShaderResourceView
*iface
,
1283 REFGUID guid
, const IUnknown
*data
)
1285 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1287 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1289 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1292 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetResource(ID3D11ShaderResourceView
*iface
,
1293 ID3D11Resource
**resource
)
1295 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1297 TRACE("iface %p, resource %p.\n", iface
, resource
);
1299 *resource
= view
->resource
;
1300 ID3D11Resource_AddRef(*resource
);
1303 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDesc(ID3D11ShaderResourceView
*iface
,
1304 D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
1306 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1308 TRACE("iface %p, desc %p.\n", iface
, desc
);
1313 static const struct ID3D11ShaderResourceViewVtbl d3d11_shader_resource_view_vtbl
=
1315 /* IUnknown methods */
1316 d3d11_shader_resource_view_QueryInterface
,
1317 d3d11_shader_resource_view_AddRef
,
1318 d3d11_shader_resource_view_Release
,
1319 /* ID3D11DeviceChild methods */
1320 d3d11_shader_resource_view_GetDevice
,
1321 d3d11_shader_resource_view_GetPrivateData
,
1322 d3d11_shader_resource_view_SetPrivateData
,
1323 d3d11_shader_resource_view_SetPrivateDataInterface
,
1324 /* ID3D11View methods */
1325 d3d11_shader_resource_view_GetResource
,
1326 /* ID3D11ShaderResourceView methods */
1327 d3d11_shader_resource_view_GetDesc
,
1330 /* ID3D10ShaderResourceView methods */
1332 static inline struct d3d_shader_resource_view
*impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView
*iface
)
1334 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView_iface
);
1337 /* IUnknown methods */
1339 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView
*iface
,
1340 REFIID riid
, void **object
)
1342 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1344 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1346 return d3d11_shader_resource_view_QueryInterface(&view
->ID3D11ShaderResourceView_iface
, riid
, object
);
1349 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView
*iface
)
1351 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1353 TRACE("iface %p.\n", iface
);
1355 return d3d11_shader_resource_view_AddRef(&view
->ID3D11ShaderResourceView_iface
);
1358 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_Release(ID3D10ShaderResourceView
*iface
)
1360 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1362 TRACE("iface %p.\n", iface
);
1364 return d3d11_shader_resource_view_Release(&view
->ID3D11ShaderResourceView_iface
);
1367 /* ID3D10DeviceChild methods */
1369 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView
*iface
,
1370 ID3D10Device
**device
)
1372 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1374 TRACE("iface %p, device %p.\n", iface
, device
);
1376 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1379 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView
*iface
,
1380 REFGUID guid
, UINT
*data_size
, void *data
)
1382 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1384 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1385 iface
, debugstr_guid(guid
), data_size
, data
);
1387 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1390 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView
*iface
,
1391 REFGUID guid
, UINT data_size
, const void *data
)
1393 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1395 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1396 iface
, debugstr_guid(guid
), data_size
, data
);
1398 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1401 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView
*iface
,
1402 REFGUID guid
, const IUnknown
*data
)
1404 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1406 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1408 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1411 /* ID3D10View methods */
1413 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView
*iface
,
1414 ID3D10Resource
**resource
)
1416 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1418 TRACE("iface %p, resource %p.\n", iface
, resource
);
1420 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1423 /* ID3D10ShaderResourceView methods */
1425 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView
*iface
,
1426 D3D10_SHADER_RESOURCE_VIEW_DESC
*desc
)
1428 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1430 TRACE("iface %p, desc %p.\n", iface
, desc
);
1432 memcpy(desc
, &view
->desc
, sizeof(*desc
));
1435 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl
=
1437 /* IUnknown methods */
1438 d3d10_shader_resource_view_QueryInterface
,
1439 d3d10_shader_resource_view_AddRef
,
1440 d3d10_shader_resource_view_Release
,
1441 /* ID3D10DeviceChild methods */
1442 d3d10_shader_resource_view_GetDevice
,
1443 d3d10_shader_resource_view_GetPrivateData
,
1444 d3d10_shader_resource_view_SetPrivateData
,
1445 d3d10_shader_resource_view_SetPrivateDataInterface
,
1446 /* ID3D10View methods */
1447 d3d10_shader_resource_view_GetResource
,
1448 /* ID3D10ShaderResourceView methods */
1449 d3d10_shader_resource_view_GetDesc
,
1452 static HRESULT
d3d_shader_resource_view_init(struct d3d_shader_resource_view
*view
, struct d3d_device
*device
,
1453 ID3D11Resource
*resource
, const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
1455 struct wined3d_resource
*wined3d_resource
;
1458 view
->ID3D11ShaderResourceView_iface
.lpVtbl
= &d3d11_shader_resource_view_vtbl
;
1459 view
->ID3D10ShaderResourceView_iface
.lpVtbl
= &d3d10_shader_resource_view_vtbl
;
1464 if (FAILED(hr
= set_srdesc_from_resource(&view
->desc
, resource
)))
1472 wined3d_mutex_lock();
1473 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1475 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource
);
1479 if (FAILED(hr
= wined3d_shader_resource_view_create(wined3d_resource
,
1480 view
, &d3d10_null_wined3d_parent_ops
, &view
->wined3d_view
)))
1482 WARN("Failed to create wined3d shader resource view, hr %#x.\n", hr
);
1486 wined3d_private_store_init(&view
->private_store
);
1487 wined3d_mutex_unlock();
1488 view
->resource
= resource
;
1489 ID3D11Resource_AddRef(resource
);
1490 view
->device
= &device
->ID3D11Device_iface
;
1491 ID3D11Device_AddRef(view
->device
);
1496 HRESULT
d3d_shader_resource_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1497 const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, struct d3d_shader_resource_view
**view
)
1499 struct d3d_shader_resource_view
*object
;
1502 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1503 return E_OUTOFMEMORY
;
1505 if (FAILED(hr
= d3d_shader_resource_view_init(object
, device
, resource
, desc
)))
1507 WARN("Failed to initialize shader resource view, hr %#x.\n", hr
);
1508 HeapFree(GetProcessHeap(), 0, object
);
1512 TRACE("Created shader resource view %p.\n", object
);
1518 struct d3d_shader_resource_view
*unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView
*iface
)
1522 assert(iface
->lpVtbl
== &d3d10_shader_resource_view_vtbl
);
1523 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView_iface
);