2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
28 /* ID3D11Texture2D methods */
30 static inline struct d3d_texture2d
*impl_from_ID3D11Texture2D(ID3D11Texture2D
*iface
)
32 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D11Texture2D_iface
);
35 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_QueryInterface(ID3D11Texture2D
*iface
, REFIID riid
, void **object
)
37 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
39 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
41 if (IsEqualGUID(riid
, &IID_ID3D11Texture2D
)
42 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
43 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
44 || IsEqualGUID(riid
, &IID_IUnknown
))
46 *object
= &texture
->ID3D11Texture2D_iface
;
47 IUnknown_AddRef((IUnknown
*)*object
);
50 else if (IsEqualGUID(riid
, &IID_ID3D10Texture2D
)
51 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
52 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
54 *object
= &texture
->ID3D10Texture2D_iface
;
55 IUnknown_AddRef((IUnknown
*)*object
);
59 if (texture
->dxgi_surface
)
61 TRACE("Forwarding to dxgi surface.\n");
62 return IUnknown_QueryInterface(texture
->dxgi_surface
, riid
, object
);
65 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
71 static ULONG STDMETHODCALLTYPE
d3d11_texture2d_AddRef(ID3D11Texture2D
*iface
)
73 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
74 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
76 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
80 ID3D11Device_AddRef(texture
->device
);
82 wined3d_texture_incref(texture
->wined3d_texture
);
83 wined3d_mutex_unlock();
89 static ULONG STDMETHODCALLTYPE
d3d11_texture2d_Release(ID3D11Texture2D
*iface
)
91 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
92 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
94 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
98 ID3D11Device
*device
= texture
->device
;
100 wined3d_mutex_lock();
101 wined3d_texture_decref(texture
->wined3d_texture
);
102 wined3d_mutex_unlock();
103 /* Release the device last, it may cause the wined3d device to be
105 ID3D11Device_Release(device
);
111 static void STDMETHODCALLTYPE
d3d11_texture2d_GetDevice(ID3D11Texture2D
*iface
, ID3D11Device
**device
)
113 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
115 TRACE("iface %p, device %p.\n", iface
, device
);
117 *device
= texture
->device
;
118 ID3D11Device_AddRef(*device
);
121 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_GetPrivateData(ID3D11Texture2D
*iface
,
122 REFGUID guid
, UINT
*data_size
, void *data
)
124 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
125 IDXGISurface
*dxgi_surface
;
128 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
130 if (texture
->dxgi_surface
131 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
133 hr
= IDXGISurface_GetPrivateData(dxgi_surface
, guid
, data_size
, data
);
134 IDXGISurface_Release(dxgi_surface
);
138 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
141 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_SetPrivateData(ID3D11Texture2D
*iface
,
142 REFGUID guid
, UINT data_size
, const void *data
)
144 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
145 IDXGISurface
*dxgi_surface
;
148 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
150 if (texture
->dxgi_surface
151 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
153 hr
= IDXGISurface_SetPrivateData(dxgi_surface
, guid
, data_size
, data
);
154 IDXGISurface_Release(dxgi_surface
);
158 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
161 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_SetPrivateDataInterface(ID3D11Texture2D
*iface
,
162 REFGUID guid
, const IUnknown
*data
)
164 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
165 IDXGISurface
*dxgi_surface
;
168 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
170 if (texture
->dxgi_surface
171 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
173 hr
= IDXGISurface_SetPrivateDataInterface(dxgi_surface
, guid
, data
);
174 IDXGISurface_Release(dxgi_surface
);
178 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
181 static void STDMETHODCALLTYPE
d3d11_texture2d_GetType(ID3D11Texture2D
*iface
,
182 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
184 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
186 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE2D
;
189 static void STDMETHODCALLTYPE
d3d11_texture2d_SetEvictionPriority(ID3D11Texture2D
*iface
, UINT eviction_priority
)
191 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
194 static UINT STDMETHODCALLTYPE
d3d11_texture2d_GetEvictionPriority(ID3D11Texture2D
*iface
)
196 FIXME("iface %p stub!\n", iface
);
201 static void STDMETHODCALLTYPE
d3d11_texture2d_GetDesc(ID3D11Texture2D
*iface
, D3D11_TEXTURE2D_DESC
*desc
)
203 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
204 struct wined3d_resource_desc wined3d_desc
;
206 TRACE("iface %p, desc %p.\n", iface
, desc
);
208 *desc
= texture
->desc
;
210 wined3d_mutex_lock();
211 wined3d_resource_get_desc(wined3d_texture_get_resource(texture
->wined3d_texture
), &wined3d_desc
);
212 wined3d_mutex_unlock();
214 /* FIXME: Resizing swapchain buffers can cause these to change. We'd like
215 * to get everything from wined3d, but e.g. bind flags don't exist as such
217 desc
->Width
= wined3d_desc
.width
;
218 desc
->Height
= wined3d_desc
.height
;
219 desc
->Format
= dxgi_format_from_wined3dformat(wined3d_desc
.format
);
220 desc
->SampleDesc
.Count
= wined3d_desc
.multisample_type
== WINED3D_MULTISAMPLE_NONE
221 ? 1 : wined3d_desc
.multisample_type
;
222 desc
->SampleDesc
.Quality
= wined3d_desc
.multisample_quality
;
225 static const struct ID3D11Texture2DVtbl d3d11_texture2d_vtbl
=
227 /* IUnknown methods */
228 d3d11_texture2d_QueryInterface
,
229 d3d11_texture2d_AddRef
,
230 d3d11_texture2d_Release
,
231 /* ID3D11DeviceChild methods */
232 d3d11_texture2d_GetDevice
,
233 d3d11_texture2d_GetPrivateData
,
234 d3d11_texture2d_SetPrivateData
,
235 d3d11_texture2d_SetPrivateDataInterface
,
236 /* ID3D11Resource methods */
237 d3d11_texture2d_GetType
,
238 d3d11_texture2d_SetEvictionPriority
,
239 d3d11_texture2d_GetEvictionPriority
,
240 /* ID3D11Texture2D methods */
241 d3d11_texture2d_GetDesc
,
244 struct d3d_texture2d
*unsafe_impl_from_ID3D11Texture2D(ID3D11Texture2D
*iface
)
248 assert(iface
->lpVtbl
== &d3d11_texture2d_vtbl
);
249 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D11Texture2D_iface
);
252 /* IUnknown methods */
254 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_QueryInterface(ID3D10Texture2D
*iface
, REFIID riid
, void **object
)
256 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
258 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
260 return d3d11_texture2d_QueryInterface(&texture
->ID3D11Texture2D_iface
, riid
, object
);
263 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_AddRef(ID3D10Texture2D
*iface
)
265 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
267 TRACE("iface %p.\n", iface
);
269 return d3d11_texture2d_AddRef(&texture
->ID3D11Texture2D_iface
);
272 static void STDMETHODCALLTYPE
d3d_texture2d_wined3d_object_released(void *parent
)
274 struct d3d_texture2d
*texture
= parent
;
276 if (texture
->dxgi_surface
) IUnknown_Release(texture
->dxgi_surface
);
277 wined3d_private_store_cleanup(&texture
->private_store
);
278 HeapFree(GetProcessHeap(), 0, texture
);
281 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_Release(ID3D10Texture2D
*iface
)
283 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
285 TRACE("iface %p.\n", iface
);
287 return d3d11_texture2d_Release(&texture
->ID3D11Texture2D_iface
);
290 /* ID3D10DeviceChild methods */
292 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDevice(ID3D10Texture2D
*iface
, ID3D10Device
**device
)
294 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
296 TRACE("iface %p, device %p.\n", iface
, device
);
298 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
301 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_GetPrivateData(ID3D10Texture2D
*iface
,
302 REFGUID guid
, UINT
*data_size
, void *data
)
304 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
306 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
308 return d3d11_texture2d_GetPrivateData(&texture
->ID3D11Texture2D_iface
, guid
, data_size
, data
);
311 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateData(ID3D10Texture2D
*iface
,
312 REFGUID guid
, UINT data_size
, const void *data
)
314 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
316 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
318 return d3d11_texture2d_SetPrivateData(&texture
->ID3D11Texture2D_iface
, guid
, data_size
, data
);
321 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateDataInterface(ID3D10Texture2D
*iface
,
322 REFGUID guid
, const IUnknown
*data
)
324 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
326 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
328 return d3d11_texture2d_SetPrivateDataInterface(&texture
->ID3D11Texture2D_iface
, guid
, data
);
331 /* ID3D10Resource methods */
333 static void STDMETHODCALLTYPE
d3d10_texture2d_GetType(ID3D10Texture2D
*iface
,
334 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
336 TRACE("iface %p, resource_dimension %p\n", iface
, resource_dimension
);
338 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE2D
;
341 static void STDMETHODCALLTYPE
d3d10_texture2d_SetEvictionPriority(ID3D10Texture2D
*iface
, UINT eviction_priority
)
343 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
346 static UINT STDMETHODCALLTYPE
d3d10_texture2d_GetEvictionPriority(ID3D10Texture2D
*iface
)
348 FIXME("iface %p stub!\n", iface
);
353 /* ID3D10Texture2D methods */
355 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_Map(ID3D10Texture2D
*iface
, UINT sub_resource_idx
,
356 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE2D
*mapped_texture
)
358 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
359 struct wined3d_map_desc wined3d_map_desc
;
362 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
363 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
366 FIXME("Ignoring map_flags %#x.\n", map_flags
);
368 wined3d_mutex_lock();
369 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
370 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
372 mapped_texture
->pData
= wined3d_map_desc
.data
;
373 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
375 wined3d_mutex_unlock();
380 static void STDMETHODCALLTYPE
d3d10_texture2d_Unmap(ID3D10Texture2D
*iface
, UINT sub_resource_idx
)
382 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
384 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
386 wined3d_mutex_lock();
387 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
388 wined3d_mutex_unlock();
391 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDesc(ID3D10Texture2D
*iface
, D3D10_TEXTURE2D_DESC
*desc
)
393 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
394 D3D11_TEXTURE2D_DESC d3d11_desc
;
396 TRACE("iface %p, desc %p\n", iface
, desc
);
398 d3d11_texture2d_GetDesc(&texture
->ID3D11Texture2D_iface
, &d3d11_desc
);
400 desc
->Width
= d3d11_desc
.Width
;
401 desc
->Height
= d3d11_desc
.Height
;
402 desc
->MipLevels
= d3d11_desc
.MipLevels
;
403 desc
->ArraySize
= d3d11_desc
.ArraySize
;
404 desc
->Format
= d3d11_desc
.Format
;
405 desc
->SampleDesc
= d3d11_desc
.SampleDesc
;
406 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
407 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
408 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
409 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
412 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl
=
414 /* IUnknown methods */
415 d3d10_texture2d_QueryInterface
,
416 d3d10_texture2d_AddRef
,
417 d3d10_texture2d_Release
,
418 /* ID3D10DeviceChild methods */
419 d3d10_texture2d_GetDevice
,
420 d3d10_texture2d_GetPrivateData
,
421 d3d10_texture2d_SetPrivateData
,
422 d3d10_texture2d_SetPrivateDataInterface
,
423 /* ID3D10Resource methods */
424 d3d10_texture2d_GetType
,
425 d3d10_texture2d_SetEvictionPriority
,
426 d3d10_texture2d_GetEvictionPriority
,
427 /* ID3D10Texture2D methods */
429 d3d10_texture2d_Unmap
,
430 d3d10_texture2d_GetDesc
,
433 struct d3d_texture2d
*unsafe_impl_from_ID3D10Texture2D(ID3D10Texture2D
*iface
)
437 assert(iface
->lpVtbl
== &d3d10_texture2d_vtbl
);
438 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D10Texture2D_iface
);
441 static const struct wined3d_parent_ops d3d_texture2d_wined3d_parent_ops
=
443 d3d_texture2d_wined3d_object_released
,
446 static HRESULT
d3d_texture2d_init(struct d3d_texture2d
*texture
, struct d3d_device
*device
,
447 const D3D11_TEXTURE2D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
449 struct wined3d_resource_desc wined3d_desc
;
453 texture
->ID3D11Texture2D_iface
.lpVtbl
= &d3d11_texture2d_vtbl
;
454 texture
->ID3D10Texture2D_iface
.lpVtbl
= &d3d10_texture2d_vtbl
;
455 texture
->refcount
= 1;
456 wined3d_mutex_lock();
457 wined3d_private_store_init(&texture
->private_store
);
458 texture
->desc
= *desc
;
460 if (desc
->ArraySize
!= 1)
461 FIXME("Array textures not implemented.\n");
462 if (desc
->SampleDesc
.Count
> 1)
463 FIXME("Multisampled textures not implemented.\n");
465 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
466 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
467 wined3d_desc
.multisample_type
= desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
;
468 wined3d_desc
.multisample_quality
= desc
->SampleDesc
.Quality
;
469 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
470 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
471 wined3d_desc
.width
= desc
->Width
;
472 wined3d_desc
.height
= desc
->Height
;
473 wined3d_desc
.depth
= 1;
474 wined3d_desc
.size
= 0;
476 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(desc
->Width
, desc
->Height
)) + 1;
478 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
479 levels
, 0, (struct wined3d_sub_resource_data
*)data
, texture
,
480 &d3d_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
482 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
483 wined3d_private_store_cleanup(&texture
->private_store
);
484 wined3d_mutex_unlock();
485 if (hr
== WINED3DERR_NOTAVAILABLE
)
489 texture
->desc
.MipLevels
= levels
;
491 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
493 IWineDXGIDevice
*wine_device
;
495 if (FAILED(hr
= ID3D10Device1_QueryInterface(&device
->ID3D10Device1_iface
, &IID_IWineDXGIDevice
,
496 (void **)&wine_device
)))
498 ERR("Device should implement IWineDXGIDevice.\n");
499 wined3d_texture_decref(texture
->wined3d_texture
);
500 wined3d_mutex_unlock();
504 hr
= IWineDXGIDevice_create_surface(wine_device
, wined3d_texture_get_resource(texture
->wined3d_texture
),
505 0, NULL
, (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
506 IWineDXGIDevice_Release(wine_device
);
509 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
510 texture
->dxgi_surface
= NULL
;
511 wined3d_texture_decref(texture
->wined3d_texture
);
512 wined3d_mutex_unlock();
516 wined3d_mutex_unlock();
518 texture
->device
= &device
->ID3D11Device_iface
;
519 ID3D11Device_AddRef(texture
->device
);
524 HRESULT
d3d_texture2d_create(struct d3d_device
*device
, const D3D11_TEXTURE2D_DESC
*desc
,
525 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture2d
**texture
)
527 struct d3d_texture2d
*object
;
530 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
531 return E_OUTOFMEMORY
;
533 if (FAILED(hr
= d3d_texture2d_init(object
, device
, desc
, data
)))
535 WARN("Failed to initialize texture, hr %#x.\n", hr
);
536 HeapFree(GetProcessHeap(), 0, object
);
540 TRACE("Created texture %p.\n", object
);
546 /* ID3D11Texture3D methods */
548 static inline struct d3d_texture3d
*impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
550 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D11Texture3D_iface
);
553 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_QueryInterface(ID3D11Texture3D
*iface
, REFIID riid
, void **object
)
555 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
557 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
559 if (IsEqualGUID(riid
, &IID_ID3D11Texture3D
)
560 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
561 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
562 || IsEqualGUID(riid
, &IID_IUnknown
))
564 IUnknown_AddRef(iface
);
568 else if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
569 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
570 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
572 IUnknown_AddRef(iface
);
573 *object
= &texture
->ID3D10Texture3D_iface
;
577 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
580 return E_NOINTERFACE
;
583 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_AddRef(ID3D11Texture3D
*iface
)
585 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
586 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
588 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
592 ID3D11Device_AddRef(texture
->device
);
593 wined3d_mutex_lock();
594 wined3d_texture_incref(texture
->wined3d_texture
);
595 wined3d_mutex_unlock();
601 static void STDMETHODCALLTYPE
d3d_texture3d_wined3d_object_released(void *parent
)
603 struct d3d_texture3d
*texture
= parent
;
605 wined3d_private_store_cleanup(&texture
->private_store
);
606 HeapFree(GetProcessHeap(), 0, parent
);
609 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_Release(ID3D11Texture3D
*iface
)
611 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
612 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
614 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
618 ID3D11Device
*device
= texture
->device
;
620 wined3d_mutex_lock();
621 wined3d_texture_decref(texture
->wined3d_texture
);
622 wined3d_mutex_unlock();
623 /* Release the device last, it may cause the wined3d device to be
625 ID3D11Device_Release(device
);
631 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDevice(ID3D11Texture3D
*iface
, ID3D11Device
**device
)
633 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
635 TRACE("iface %p, device %p.\n", iface
, device
);
637 *device
= texture
->device
;
638 ID3D11Device_AddRef(*device
);
641 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_GetPrivateData(ID3D11Texture3D
*iface
,
642 REFGUID guid
, UINT
*data_size
, void *data
)
644 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
646 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
648 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
651 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateData(ID3D11Texture3D
*iface
,
652 REFGUID guid
, UINT data_size
, const void *data
)
654 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
656 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
658 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
661 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateDataInterface(ID3D11Texture3D
*iface
,
662 REFGUID guid
, const IUnknown
*data
)
664 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
666 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
668 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
671 static void STDMETHODCALLTYPE
d3d11_texture3d_GetType(ID3D11Texture3D
*iface
,
672 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
674 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
676 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE3D
;
679 static void STDMETHODCALLTYPE
d3d11_texture3d_SetEvictionPriority(ID3D11Texture3D
*iface
, UINT eviction_priority
)
681 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
684 static UINT STDMETHODCALLTYPE
d3d11_texture3d_GetEvictionPriority(ID3D11Texture3D
*iface
)
686 FIXME("iface %p stub!\n", iface
);
691 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDesc(ID3D11Texture3D
*iface
, D3D11_TEXTURE3D_DESC
*desc
)
693 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
695 TRACE("iface %p, desc %p.\n", iface
, desc
);
697 *desc
= texture
->desc
;
700 static const struct ID3D11Texture3DVtbl d3d11_texture3d_vtbl
=
702 /* IUnknown methods */
703 d3d11_texture3d_QueryInterface
,
704 d3d11_texture3d_AddRef
,
705 d3d11_texture3d_Release
,
706 /* ID3D11DeviceChild methods */
707 d3d11_texture3d_GetDevice
,
708 d3d11_texture3d_GetPrivateData
,
709 d3d11_texture3d_SetPrivateData
,
710 d3d11_texture3d_SetPrivateDataInterface
,
711 /* ID3D11Resource methods */
712 d3d11_texture3d_GetType
,
713 d3d11_texture3d_SetEvictionPriority
,
714 d3d11_texture3d_GetEvictionPriority
,
715 /* ID3D11Texture3D methods */
716 d3d11_texture3d_GetDesc
,
719 /* ID3D10Texture3D methods */
721 static inline struct d3d_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
723 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D10Texture3D_iface
);
726 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
728 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
730 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
732 return d3d11_texture3d_QueryInterface(&texture
->ID3D11Texture3D_iface
, riid
, object
);
735 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
737 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
739 TRACE("iface %p.\n", iface
);
741 return d3d11_texture3d_AddRef(&texture
->ID3D11Texture3D_iface
);
744 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
746 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
748 TRACE("iface %p.\n", iface
);
750 return d3d11_texture3d_Release(&texture
->ID3D11Texture3D_iface
);
753 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
755 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
757 TRACE("iface %p, device %p.\n", iface
, device
);
759 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
762 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
763 REFGUID guid
, UINT
*data_size
, void *data
)
765 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
767 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
768 iface
, debugstr_guid(guid
), data_size
, data
);
770 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
773 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
774 REFGUID guid
, UINT data_size
, const void *data
)
776 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
778 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
779 iface
, debugstr_guid(guid
), data_size
, data
);
781 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
784 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
785 REFGUID guid
, const IUnknown
*data
)
787 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
789 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
791 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
794 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
795 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
797 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
799 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
802 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
804 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
807 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
809 FIXME("iface %p stub!\n", iface
);
814 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
815 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
817 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
818 struct wined3d_map_desc wined3d_map_desc
;
821 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
822 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
825 FIXME("Ignoring map_flags %#x.\n", map_flags
);
827 wined3d_mutex_lock();
828 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
829 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
831 mapped_texture
->pData
= wined3d_map_desc
.data
;
832 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
833 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
835 wined3d_mutex_unlock();
840 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
842 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
844 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
846 wined3d_mutex_lock();
847 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
848 wined3d_mutex_unlock();
851 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
853 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
854 D3D11_TEXTURE3D_DESC d3d11_desc
;
856 TRACE("iface %p, desc %p.\n", iface
, desc
);
858 d3d11_texture3d_GetDesc(&texture
->ID3D11Texture3D_iface
, &d3d11_desc
);
860 desc
->Width
= d3d11_desc
.Width
;
861 desc
->Height
= d3d11_desc
.Height
;
862 desc
->Depth
= d3d11_desc
.Depth
;
863 desc
->MipLevels
= d3d11_desc
.MipLevels
;
864 desc
->Format
= d3d11_desc
.Format
;
865 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
866 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
867 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
868 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
871 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
873 /* IUnknown methods */
874 d3d10_texture3d_QueryInterface
,
875 d3d10_texture3d_AddRef
,
876 d3d10_texture3d_Release
,
877 /* ID3D10DeviceChild methods */
878 d3d10_texture3d_GetDevice
,
879 d3d10_texture3d_GetPrivateData
,
880 d3d10_texture3d_SetPrivateData
,
881 d3d10_texture3d_SetPrivateDataInterface
,
882 /* ID3D10Resource methods */
883 d3d10_texture3d_GetType
,
884 d3d10_texture3d_SetEvictionPriority
,
885 d3d10_texture3d_GetEvictionPriority
,
886 /* ID3D10Texture3D methods */
888 d3d10_texture3d_Unmap
,
889 d3d10_texture3d_GetDesc
,
892 struct d3d_texture3d
*unsafe_impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
896 assert(iface
->lpVtbl
== &d3d11_texture3d_vtbl
);
897 return impl_from_ID3D11Texture3D(iface
);
900 static const struct wined3d_parent_ops d3d_texture3d_wined3d_parent_ops
=
902 d3d_texture3d_wined3d_object_released
,
905 static HRESULT
d3d_texture3d_init(struct d3d_texture3d
*texture
, struct d3d_device
*device
,
906 const D3D11_TEXTURE3D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
908 struct wined3d_resource_desc wined3d_desc
;
912 texture
->ID3D11Texture3D_iface
.lpVtbl
= &d3d11_texture3d_vtbl
;
913 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
914 texture
->refcount
= 1;
915 wined3d_mutex_lock();
916 wined3d_private_store_init(&texture
->private_store
);
917 texture
->desc
= *desc
;
919 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_3D
;
920 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
921 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
922 wined3d_desc
.multisample_quality
= 0;
923 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
924 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
925 wined3d_desc
.width
= desc
->Width
;
926 wined3d_desc
.height
= desc
->Height
;
927 wined3d_desc
.depth
= desc
->Depth
;
928 wined3d_desc
.size
= 0;
930 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(max(desc
->Width
, desc
->Height
), desc
->Depth
)) + 1;
932 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
933 levels
, 0, (struct wined3d_sub_resource_data
*)data
, texture
,
934 &d3d_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
936 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
937 wined3d_private_store_cleanup(&texture
->private_store
);
938 wined3d_mutex_unlock();
941 wined3d_mutex_unlock();
942 texture
->desc
.MipLevels
= levels
;
944 texture
->device
= &device
->ID3D11Device_iface
;
945 ID3D11Device_AddRef(texture
->device
);
950 HRESULT
d3d_texture3d_create(struct d3d_device
*device
, const D3D11_TEXTURE3D_DESC
*desc
,
951 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture3d
**texture
)
953 struct d3d_texture3d
*object
;
956 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
957 return E_OUTOFMEMORY
;
959 if (FAILED(hr
= d3d_texture3d_init(object
, device
, desc
, data
)))
961 WARN("Failed to initialize texture, hr %#x.\n", hr
);
962 HeapFree(GetProcessHeap(), 0, object
);
966 TRACE("Created texture %p.\n", object
);