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 BOOL
is_gdi_compatible_texture(const D3D11_TEXTURE2D_DESC
*desc
)
448 if (!(desc
->Format
== DXGI_FORMAT_B8G8R8A8_UNORM
449 || desc
->Format
== DXGI_FORMAT_B8G8R8A8_TYPELESS
450 || desc
->Format
== DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
))
453 if (desc
->Usage
!= D3D11_USAGE_DEFAULT
)
459 static BOOL
validate_texture2d_desc(const D3D11_TEXTURE2D_DESC
*desc
)
461 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_TEXTURECUBE
462 && desc
->ArraySize
< 6)
464 WARN("Invalid array size %u for cube texture.\n", desc
->ArraySize
);
468 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GDI_COMPATIBLE
469 && !is_gdi_compatible_texture(desc
))
471 WARN("Incompatible description used to create GDI compatible texture.\n");
475 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GENERATE_MIPS
476 && (~desc
->BindFlags
& (D3D11_BIND_RENDER_TARGET
| D3D11_BIND_SHADER_RESOURCE
)))
478 WARN("D3D11_RESOURCE_MISC_GENERATE_MIPS used without D3D11_BIND_RENDER_TARGET and "
479 "D3D11_BIND_SHADER_RESOURCE.\n");
486 HRESULT
d3d_texture2d_create(struct d3d_device
*device
, const D3D11_TEXTURE2D_DESC
*desc
,
487 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture2d
**out
)
489 struct wined3d_resource_desc wined3d_desc
;
490 struct d3d_texture2d
*texture
;
495 if (!validate_texture2d_desc(desc
))
497 WARN("Failed to validate texture desc.\n");
501 if (!(texture
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*texture
))))
502 return E_OUTOFMEMORY
;
504 texture
->ID3D11Texture2D_iface
.lpVtbl
= &d3d11_texture2d_vtbl
;
505 texture
->ID3D10Texture2D_iface
.lpVtbl
= &d3d10_texture2d_vtbl
;
506 texture
->refcount
= 1;
507 wined3d_mutex_lock();
508 wined3d_private_store_init(&texture
->private_store
);
509 texture
->desc
= *desc
;
511 if (desc
->SampleDesc
.Count
> 1)
512 FIXME("Multisampled textures not implemented.\n");
514 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
515 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
516 wined3d_desc
.multisample_type
= desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
;
517 wined3d_desc
.multisample_quality
= desc
->SampleDesc
.Quality
;
518 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
519 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
520 wined3d_desc
.width
= desc
->Width
;
521 wined3d_desc
.height
= desc
->Height
;
522 wined3d_desc
.depth
= 1;
523 wined3d_desc
.size
= 0;
525 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(desc
->Width
, desc
->Height
)) + 1;
527 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GDI_COMPATIBLE
)
528 flags
|= WINED3D_TEXTURE_CREATE_GET_DC
;
529 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GENERATE_MIPS
)
530 flags
|= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS
;
532 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
533 desc
->ArraySize
, levels
, flags
, (struct wined3d_sub_resource_data
*)data
,
534 texture
, &d3d_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
536 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
537 wined3d_private_store_cleanup(&texture
->private_store
);
538 HeapFree(GetProcessHeap(), 0, texture
);
539 wined3d_mutex_unlock();
540 if (hr
== WINED3DERR_NOTAVAILABLE
|| hr
== WINED3DERR_INVALIDCALL
)
544 texture
->desc
.MipLevels
= levels
;
546 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
548 IWineDXGIDevice
*wine_device
;
550 if (FAILED(hr
= ID3D10Device1_QueryInterface(&device
->ID3D10Device1_iface
, &IID_IWineDXGIDevice
,
551 (void **)&wine_device
)))
553 ERR("Device should implement IWineDXGIDevice.\n");
554 wined3d_texture_decref(texture
->wined3d_texture
);
555 wined3d_mutex_unlock();
559 hr
= IWineDXGIDevice_create_surface(wine_device
, texture
->wined3d_texture
, 0, NULL
,
560 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
561 IWineDXGIDevice_Release(wine_device
);
564 ERR("Failed to create DXGI surface, returning %#.x\n", hr
);
565 texture
->dxgi_surface
= NULL
;
566 wined3d_texture_decref(texture
->wined3d_texture
);
567 wined3d_mutex_unlock();
571 wined3d_mutex_unlock();
573 ID3D11Device_AddRef(texture
->device
= &device
->ID3D11Device_iface
);
575 TRACE("Created texture %p.\n", texture
);
581 /* ID3D11Texture3D methods */
583 static inline struct d3d_texture3d
*impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
585 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D11Texture3D_iface
);
588 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_QueryInterface(ID3D11Texture3D
*iface
, REFIID riid
, void **object
)
590 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
592 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
594 if (IsEqualGUID(riid
, &IID_ID3D11Texture3D
)
595 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
596 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
597 || IsEqualGUID(riid
, &IID_IUnknown
))
599 IUnknown_AddRef(iface
);
603 else if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
604 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
605 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
607 IUnknown_AddRef(iface
);
608 *object
= &texture
->ID3D10Texture3D_iface
;
612 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
615 return E_NOINTERFACE
;
618 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_AddRef(ID3D11Texture3D
*iface
)
620 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
621 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
623 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
627 ID3D11Device_AddRef(texture
->device
);
628 wined3d_mutex_lock();
629 wined3d_texture_incref(texture
->wined3d_texture
);
630 wined3d_mutex_unlock();
636 static void STDMETHODCALLTYPE
d3d_texture3d_wined3d_object_released(void *parent
)
638 struct d3d_texture3d
*texture
= parent
;
640 wined3d_private_store_cleanup(&texture
->private_store
);
641 HeapFree(GetProcessHeap(), 0, parent
);
644 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_Release(ID3D11Texture3D
*iface
)
646 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
647 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
649 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
653 ID3D11Device
*device
= texture
->device
;
655 wined3d_mutex_lock();
656 wined3d_texture_decref(texture
->wined3d_texture
);
657 wined3d_mutex_unlock();
658 /* Release the device last, it may cause the wined3d device to be
660 ID3D11Device_Release(device
);
666 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDevice(ID3D11Texture3D
*iface
, ID3D11Device
**device
)
668 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
670 TRACE("iface %p, device %p.\n", iface
, device
);
672 *device
= texture
->device
;
673 ID3D11Device_AddRef(*device
);
676 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_GetPrivateData(ID3D11Texture3D
*iface
,
677 REFGUID guid
, UINT
*data_size
, void *data
)
679 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
681 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
683 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
686 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateData(ID3D11Texture3D
*iface
,
687 REFGUID guid
, UINT data_size
, const void *data
)
689 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
691 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
693 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
696 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateDataInterface(ID3D11Texture3D
*iface
,
697 REFGUID guid
, const IUnknown
*data
)
699 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
701 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
703 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
706 static void STDMETHODCALLTYPE
d3d11_texture3d_GetType(ID3D11Texture3D
*iface
,
707 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
709 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
711 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE3D
;
714 static void STDMETHODCALLTYPE
d3d11_texture3d_SetEvictionPriority(ID3D11Texture3D
*iface
, UINT eviction_priority
)
716 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
719 static UINT STDMETHODCALLTYPE
d3d11_texture3d_GetEvictionPriority(ID3D11Texture3D
*iface
)
721 FIXME("iface %p stub!\n", iface
);
726 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDesc(ID3D11Texture3D
*iface
, D3D11_TEXTURE3D_DESC
*desc
)
728 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
730 TRACE("iface %p, desc %p.\n", iface
, desc
);
732 *desc
= texture
->desc
;
735 static const struct ID3D11Texture3DVtbl d3d11_texture3d_vtbl
=
737 /* IUnknown methods */
738 d3d11_texture3d_QueryInterface
,
739 d3d11_texture3d_AddRef
,
740 d3d11_texture3d_Release
,
741 /* ID3D11DeviceChild methods */
742 d3d11_texture3d_GetDevice
,
743 d3d11_texture3d_GetPrivateData
,
744 d3d11_texture3d_SetPrivateData
,
745 d3d11_texture3d_SetPrivateDataInterface
,
746 /* ID3D11Resource methods */
747 d3d11_texture3d_GetType
,
748 d3d11_texture3d_SetEvictionPriority
,
749 d3d11_texture3d_GetEvictionPriority
,
750 /* ID3D11Texture3D methods */
751 d3d11_texture3d_GetDesc
,
754 /* ID3D10Texture3D methods */
756 static inline struct d3d_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
758 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D10Texture3D_iface
);
761 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
763 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
765 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
767 return d3d11_texture3d_QueryInterface(&texture
->ID3D11Texture3D_iface
, riid
, object
);
770 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
772 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
774 TRACE("iface %p.\n", iface
);
776 return d3d11_texture3d_AddRef(&texture
->ID3D11Texture3D_iface
);
779 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
781 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
783 TRACE("iface %p.\n", iface
);
785 return d3d11_texture3d_Release(&texture
->ID3D11Texture3D_iface
);
788 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
790 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
792 TRACE("iface %p, device %p.\n", iface
, device
);
794 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
797 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
798 REFGUID guid
, UINT
*data_size
, void *data
)
800 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
802 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
803 iface
, debugstr_guid(guid
), data_size
, data
);
805 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
808 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
809 REFGUID guid
, UINT data_size
, const void *data
)
811 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
813 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
814 iface
, debugstr_guid(guid
), data_size
, data
);
816 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
819 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
820 REFGUID guid
, const IUnknown
*data
)
822 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
824 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
826 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
829 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
830 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
832 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
834 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
837 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
839 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
842 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
844 FIXME("iface %p stub!\n", iface
);
849 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
850 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
852 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
853 struct wined3d_map_desc wined3d_map_desc
;
856 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
857 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
860 FIXME("Ignoring map_flags %#x.\n", map_flags
);
862 wined3d_mutex_lock();
863 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
864 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
866 mapped_texture
->pData
= wined3d_map_desc
.data
;
867 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
868 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
870 wined3d_mutex_unlock();
875 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
877 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
879 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
881 wined3d_mutex_lock();
882 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
883 wined3d_mutex_unlock();
886 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
888 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
889 D3D11_TEXTURE3D_DESC d3d11_desc
;
891 TRACE("iface %p, desc %p.\n", iface
, desc
);
893 d3d11_texture3d_GetDesc(&texture
->ID3D11Texture3D_iface
, &d3d11_desc
);
895 desc
->Width
= d3d11_desc
.Width
;
896 desc
->Height
= d3d11_desc
.Height
;
897 desc
->Depth
= d3d11_desc
.Depth
;
898 desc
->MipLevels
= d3d11_desc
.MipLevels
;
899 desc
->Format
= d3d11_desc
.Format
;
900 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
901 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
902 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
903 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
906 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
908 /* IUnknown methods */
909 d3d10_texture3d_QueryInterface
,
910 d3d10_texture3d_AddRef
,
911 d3d10_texture3d_Release
,
912 /* ID3D10DeviceChild methods */
913 d3d10_texture3d_GetDevice
,
914 d3d10_texture3d_GetPrivateData
,
915 d3d10_texture3d_SetPrivateData
,
916 d3d10_texture3d_SetPrivateDataInterface
,
917 /* ID3D10Resource methods */
918 d3d10_texture3d_GetType
,
919 d3d10_texture3d_SetEvictionPriority
,
920 d3d10_texture3d_GetEvictionPriority
,
921 /* ID3D10Texture3D methods */
923 d3d10_texture3d_Unmap
,
924 d3d10_texture3d_GetDesc
,
927 struct d3d_texture3d
*unsafe_impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
931 assert(iface
->lpVtbl
== &d3d11_texture3d_vtbl
);
932 return impl_from_ID3D11Texture3D(iface
);
935 static const struct wined3d_parent_ops d3d_texture3d_wined3d_parent_ops
=
937 d3d_texture3d_wined3d_object_released
,
940 static HRESULT
d3d_texture3d_init(struct d3d_texture3d
*texture
, struct d3d_device
*device
,
941 const D3D11_TEXTURE3D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
943 struct wined3d_resource_desc wined3d_desc
;
948 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GENERATE_MIPS
949 && (~desc
->BindFlags
& (D3D11_BIND_RENDER_TARGET
| D3D11_BIND_SHADER_RESOURCE
)))
951 WARN("D3D11_RESOURCE_MISC_GENERATE_MIPS used without D3D11_BIND_RENDER_TARGET "
952 "and D3D11_BIND_SHADER_RESOURCE.\n");
956 texture
->ID3D11Texture3D_iface
.lpVtbl
= &d3d11_texture3d_vtbl
;
957 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
958 texture
->refcount
= 1;
959 wined3d_mutex_lock();
960 wined3d_private_store_init(&texture
->private_store
);
961 texture
->desc
= *desc
;
963 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_3D
;
964 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
965 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
966 wined3d_desc
.multisample_quality
= 0;
967 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
968 wined3d_desc
.pool
= desc
->Usage
== D3D11_USAGE_STAGING
? WINED3D_POOL_MANAGED
: WINED3D_POOL_DEFAULT
;
969 wined3d_desc
.width
= desc
->Width
;
970 wined3d_desc
.height
= desc
->Height
;
971 wined3d_desc
.depth
= desc
->Depth
;
972 wined3d_desc
.size
= 0;
974 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(max(desc
->Width
, desc
->Height
), desc
->Depth
)) + 1;
976 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GENERATE_MIPS
)
977 flags
|= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS
;
979 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
980 1, levels
, flags
, (struct wined3d_sub_resource_data
*)data
, texture
,
981 &d3d_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
983 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
984 wined3d_private_store_cleanup(&texture
->private_store
);
985 wined3d_mutex_unlock();
986 if (hr
== WINED3DERR_INVALIDCALL
)
990 wined3d_mutex_unlock();
991 texture
->desc
.MipLevels
= levels
;
993 texture
->device
= &device
->ID3D11Device_iface
;
994 ID3D11Device_AddRef(texture
->device
);
999 HRESULT
d3d_texture3d_create(struct d3d_device
*device
, const D3D11_TEXTURE3D_DESC
*desc
,
1000 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture3d
**texture
)
1002 struct d3d_texture3d
*object
;
1005 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1006 return E_OUTOFMEMORY
;
1008 if (FAILED(hr
= d3d_texture3d_init(object
, device
, desc
, data
)))
1010 WARN("Failed to initialize texture, hr %#x.\n", hr
);
1011 HeapFree(GetProcessHeap(), 0, object
);
1015 TRACE("Created texture %p.\n", object
);