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
->SampleDesc
.Count
> 1)
461 FIXME("Multisampled textures not implemented.\n");
463 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
464 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
465 wined3d_desc
.multisample_type
= desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
;
466 wined3d_desc
.multisample_quality
= desc
->SampleDesc
.Quality
;
467 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
468 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
469 wined3d_desc
.width
= desc
->Width
;
470 wined3d_desc
.height
= desc
->Height
;
471 wined3d_desc
.depth
= 1;
472 wined3d_desc
.size
= 0;
474 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(desc
->Width
, desc
->Height
)) + 1;
476 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
477 desc
->ArraySize
, levels
, 0, (struct wined3d_sub_resource_data
*)data
,
478 texture
, &d3d_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
480 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
481 wined3d_private_store_cleanup(&texture
->private_store
);
482 wined3d_mutex_unlock();
483 if (hr
== WINED3DERR_NOTAVAILABLE
|| hr
== WINED3DERR_INVALIDCALL
)
487 texture
->desc
.MipLevels
= levels
;
489 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
491 IWineDXGIDevice
*wine_device
;
493 if (FAILED(hr
= ID3D10Device1_QueryInterface(&device
->ID3D10Device1_iface
, &IID_IWineDXGIDevice
,
494 (void **)&wine_device
)))
496 ERR("Device should implement IWineDXGIDevice.\n");
497 wined3d_texture_decref(texture
->wined3d_texture
);
498 wined3d_mutex_unlock();
502 hr
= IWineDXGIDevice_create_surface(wine_device
, wined3d_texture_get_resource(texture
->wined3d_texture
),
503 0, NULL
, (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
504 IWineDXGIDevice_Release(wine_device
);
507 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
508 texture
->dxgi_surface
= NULL
;
509 wined3d_texture_decref(texture
->wined3d_texture
);
510 wined3d_mutex_unlock();
514 wined3d_mutex_unlock();
516 texture
->device
= &device
->ID3D11Device_iface
;
517 ID3D11Device_AddRef(texture
->device
);
522 HRESULT
d3d_texture2d_create(struct d3d_device
*device
, const D3D11_TEXTURE2D_DESC
*desc
,
523 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture2d
**texture
)
525 struct d3d_texture2d
*object
;
528 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
529 return E_OUTOFMEMORY
;
531 if (FAILED(hr
= d3d_texture2d_init(object
, device
, desc
, data
)))
533 WARN("Failed to initialize texture, hr %#x.\n", hr
);
534 HeapFree(GetProcessHeap(), 0, object
);
538 TRACE("Created texture %p.\n", object
);
544 /* ID3D11Texture3D methods */
546 static inline struct d3d_texture3d
*impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
548 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D11Texture3D_iface
);
551 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_QueryInterface(ID3D11Texture3D
*iface
, REFIID riid
, void **object
)
553 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
555 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
557 if (IsEqualGUID(riid
, &IID_ID3D11Texture3D
)
558 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
559 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
560 || IsEqualGUID(riid
, &IID_IUnknown
))
562 IUnknown_AddRef(iface
);
566 else if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
567 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
568 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
570 IUnknown_AddRef(iface
);
571 *object
= &texture
->ID3D10Texture3D_iface
;
575 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
578 return E_NOINTERFACE
;
581 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_AddRef(ID3D11Texture3D
*iface
)
583 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
584 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
586 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
590 ID3D11Device_AddRef(texture
->device
);
591 wined3d_mutex_lock();
592 wined3d_texture_incref(texture
->wined3d_texture
);
593 wined3d_mutex_unlock();
599 static void STDMETHODCALLTYPE
d3d_texture3d_wined3d_object_released(void *parent
)
601 struct d3d_texture3d
*texture
= parent
;
603 wined3d_private_store_cleanup(&texture
->private_store
);
604 HeapFree(GetProcessHeap(), 0, parent
);
607 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_Release(ID3D11Texture3D
*iface
)
609 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
610 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
612 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
616 ID3D11Device
*device
= texture
->device
;
618 wined3d_mutex_lock();
619 wined3d_texture_decref(texture
->wined3d_texture
);
620 wined3d_mutex_unlock();
621 /* Release the device last, it may cause the wined3d device to be
623 ID3D11Device_Release(device
);
629 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDevice(ID3D11Texture3D
*iface
, ID3D11Device
**device
)
631 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
633 TRACE("iface %p, device %p.\n", iface
, device
);
635 *device
= texture
->device
;
636 ID3D11Device_AddRef(*device
);
639 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_GetPrivateData(ID3D11Texture3D
*iface
,
640 REFGUID guid
, UINT
*data_size
, void *data
)
642 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
644 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
646 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
649 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateData(ID3D11Texture3D
*iface
,
650 REFGUID guid
, UINT data_size
, const void *data
)
652 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
654 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
656 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
659 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateDataInterface(ID3D11Texture3D
*iface
,
660 REFGUID guid
, const IUnknown
*data
)
662 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
664 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
666 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
669 static void STDMETHODCALLTYPE
d3d11_texture3d_GetType(ID3D11Texture3D
*iface
,
670 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
672 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
674 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE3D
;
677 static void STDMETHODCALLTYPE
d3d11_texture3d_SetEvictionPriority(ID3D11Texture3D
*iface
, UINT eviction_priority
)
679 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
682 static UINT STDMETHODCALLTYPE
d3d11_texture3d_GetEvictionPriority(ID3D11Texture3D
*iface
)
684 FIXME("iface %p stub!\n", iface
);
689 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDesc(ID3D11Texture3D
*iface
, D3D11_TEXTURE3D_DESC
*desc
)
691 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
693 TRACE("iface %p, desc %p.\n", iface
, desc
);
695 *desc
= texture
->desc
;
698 static const struct ID3D11Texture3DVtbl d3d11_texture3d_vtbl
=
700 /* IUnknown methods */
701 d3d11_texture3d_QueryInterface
,
702 d3d11_texture3d_AddRef
,
703 d3d11_texture3d_Release
,
704 /* ID3D11DeviceChild methods */
705 d3d11_texture3d_GetDevice
,
706 d3d11_texture3d_GetPrivateData
,
707 d3d11_texture3d_SetPrivateData
,
708 d3d11_texture3d_SetPrivateDataInterface
,
709 /* ID3D11Resource methods */
710 d3d11_texture3d_GetType
,
711 d3d11_texture3d_SetEvictionPriority
,
712 d3d11_texture3d_GetEvictionPriority
,
713 /* ID3D11Texture3D methods */
714 d3d11_texture3d_GetDesc
,
717 /* ID3D10Texture3D methods */
719 static inline struct d3d_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
721 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D10Texture3D_iface
);
724 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
726 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
728 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
730 return d3d11_texture3d_QueryInterface(&texture
->ID3D11Texture3D_iface
, riid
, object
);
733 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
735 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
737 TRACE("iface %p.\n", iface
);
739 return d3d11_texture3d_AddRef(&texture
->ID3D11Texture3D_iface
);
742 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
744 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
746 TRACE("iface %p.\n", iface
);
748 return d3d11_texture3d_Release(&texture
->ID3D11Texture3D_iface
);
751 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
753 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
755 TRACE("iface %p, device %p.\n", iface
, device
);
757 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
760 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
761 REFGUID guid
, UINT
*data_size
, void *data
)
763 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
765 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
766 iface
, debugstr_guid(guid
), data_size
, data
);
768 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
771 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
772 REFGUID guid
, UINT data_size
, const void *data
)
774 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
776 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
777 iface
, debugstr_guid(guid
), data_size
, data
);
779 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
782 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
783 REFGUID guid
, const IUnknown
*data
)
785 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
787 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
789 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
792 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
793 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
795 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
797 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
800 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
802 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
805 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
807 FIXME("iface %p stub!\n", iface
);
812 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
813 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
815 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
816 struct wined3d_map_desc wined3d_map_desc
;
819 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
820 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
823 FIXME("Ignoring map_flags %#x.\n", map_flags
);
825 wined3d_mutex_lock();
826 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
827 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
829 mapped_texture
->pData
= wined3d_map_desc
.data
;
830 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
831 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
833 wined3d_mutex_unlock();
838 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
840 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
842 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
844 wined3d_mutex_lock();
845 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
846 wined3d_mutex_unlock();
849 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
851 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
852 D3D11_TEXTURE3D_DESC d3d11_desc
;
854 TRACE("iface %p, desc %p.\n", iface
, desc
);
856 d3d11_texture3d_GetDesc(&texture
->ID3D11Texture3D_iface
, &d3d11_desc
);
858 desc
->Width
= d3d11_desc
.Width
;
859 desc
->Height
= d3d11_desc
.Height
;
860 desc
->Depth
= d3d11_desc
.Depth
;
861 desc
->MipLevels
= d3d11_desc
.MipLevels
;
862 desc
->Format
= d3d11_desc
.Format
;
863 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
864 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
865 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
866 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
869 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
871 /* IUnknown methods */
872 d3d10_texture3d_QueryInterface
,
873 d3d10_texture3d_AddRef
,
874 d3d10_texture3d_Release
,
875 /* ID3D10DeviceChild methods */
876 d3d10_texture3d_GetDevice
,
877 d3d10_texture3d_GetPrivateData
,
878 d3d10_texture3d_SetPrivateData
,
879 d3d10_texture3d_SetPrivateDataInterface
,
880 /* ID3D10Resource methods */
881 d3d10_texture3d_GetType
,
882 d3d10_texture3d_SetEvictionPriority
,
883 d3d10_texture3d_GetEvictionPriority
,
884 /* ID3D10Texture3D methods */
886 d3d10_texture3d_Unmap
,
887 d3d10_texture3d_GetDesc
,
890 struct d3d_texture3d
*unsafe_impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
894 assert(iface
->lpVtbl
== &d3d11_texture3d_vtbl
);
895 return impl_from_ID3D11Texture3D(iface
);
898 static const struct wined3d_parent_ops d3d_texture3d_wined3d_parent_ops
=
900 d3d_texture3d_wined3d_object_released
,
903 static HRESULT
d3d_texture3d_init(struct d3d_texture3d
*texture
, struct d3d_device
*device
,
904 const D3D11_TEXTURE3D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
906 struct wined3d_resource_desc wined3d_desc
;
910 texture
->ID3D11Texture3D_iface
.lpVtbl
= &d3d11_texture3d_vtbl
;
911 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
912 texture
->refcount
= 1;
913 wined3d_mutex_lock();
914 wined3d_private_store_init(&texture
->private_store
);
915 texture
->desc
= *desc
;
917 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_3D
;
918 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
919 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
920 wined3d_desc
.multisample_quality
= 0;
921 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
922 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
923 wined3d_desc
.width
= desc
->Width
;
924 wined3d_desc
.height
= desc
->Height
;
925 wined3d_desc
.depth
= desc
->Depth
;
926 wined3d_desc
.size
= 0;
928 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(max(desc
->Width
, desc
->Height
), desc
->Depth
)) + 1;
930 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
931 1, levels
, 0, (struct wined3d_sub_resource_data
*)data
, texture
,
932 &d3d_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
934 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
935 wined3d_private_store_cleanup(&texture
->private_store
);
936 wined3d_mutex_unlock();
937 if (hr
== WINED3DERR_INVALIDCALL
)
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
);