2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
27 /* ID3D11Buffer methods */
29 static inline struct d3d_buffer
*impl_from_ID3D11Buffer(ID3D11Buffer
*iface
)
31 return CONTAINING_RECORD(iface
, struct d3d_buffer
, ID3D11Buffer_iface
);
34 static HRESULT STDMETHODCALLTYPE
d3d11_buffer_QueryInterface(ID3D11Buffer
*iface
, REFIID riid
, void **out
)
36 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
38 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
40 if (IsEqualGUID(riid
, &IID_ID3D11Buffer
)
41 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
42 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
43 || IsEqualGUID(riid
, &IID_IUnknown
))
45 ID3D11Buffer_AddRef(iface
);
50 if (IsEqualGUID(riid
, &IID_ID3D10Buffer
)
51 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
52 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
54 ID3D10Buffer_AddRef(&buffer
->ID3D10Buffer_iface
);
55 *out
= &buffer
->ID3D10Buffer_iface
;
59 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
65 static ULONG STDMETHODCALLTYPE
d3d11_buffer_AddRef(ID3D11Buffer
*iface
)
67 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
68 ULONG refcount
= InterlockedIncrement(&buffer
->refcount
);
70 TRACE("%p increasing refcount to %u.\n", buffer
, refcount
);
74 ID3D11Device_AddRef(buffer
->device
);
76 wined3d_buffer_incref(buffer
->wined3d_buffer
);
77 wined3d_mutex_unlock();
83 static ULONG STDMETHODCALLTYPE
d3d11_buffer_Release(ID3D11Buffer
*iface
)
85 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
86 ULONG refcount
= InterlockedDecrement(&buffer
->refcount
);
88 TRACE("%p decreasing refcount to %u.\n", buffer
, refcount
);
92 ID3D11Device
*device
= buffer
->device
;
95 wined3d_buffer_decref(buffer
->wined3d_buffer
);
96 wined3d_mutex_unlock();
97 /* Release the device last, it may cause the wined3d device to be
99 ID3D11Device_Release(device
);
105 static void STDMETHODCALLTYPE
d3d11_buffer_GetDevice(ID3D11Buffer
*iface
, ID3D11Device
**device
)
107 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
109 TRACE("iface %p, device %p.\n", iface
, device
);
111 *device
= buffer
->device
;
114 static HRESULT STDMETHODCALLTYPE
d3d11_buffer_GetPrivateData(ID3D11Buffer
*iface
,
115 REFGUID guid
, UINT
*data_size
, void *data
)
117 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
119 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
121 return d3d_get_private_data(&buffer
->private_store
, guid
, data_size
, data
);
124 static HRESULT STDMETHODCALLTYPE
d3d11_buffer_SetPrivateData(ID3D11Buffer
*iface
,
125 REFGUID guid
, UINT data_size
, const void *data
)
127 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
129 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
131 return d3d_set_private_data(&buffer
->private_store
, guid
, data_size
, data
);
134 static HRESULT STDMETHODCALLTYPE
d3d11_buffer_SetPrivateDataInterface(ID3D11Buffer
*iface
,
135 REFGUID guid
, const IUnknown
*data
)
137 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
139 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
141 return d3d_set_private_data_interface(&buffer
->private_store
, guid
, data
);
144 static void STDMETHODCALLTYPE
d3d11_buffer_GetType(ID3D11Buffer
*iface
,
145 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
147 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
149 *resource_dimension
= D3D11_RESOURCE_DIMENSION_BUFFER
;
152 static void STDMETHODCALLTYPE
d3d11_buffer_SetEvictionPriority(ID3D11Buffer
*iface
, UINT eviction_priority
)
154 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
157 static UINT STDMETHODCALLTYPE
d3d11_buffer_GetEvictionPriority(ID3D11Buffer
*iface
)
159 FIXME("iface %p stub!\n", iface
);
164 static void STDMETHODCALLTYPE
d3d11_buffer_GetDesc(ID3D11Buffer
*iface
, D3D11_BUFFER_DESC
*desc
)
166 struct d3d_buffer
*buffer
= impl_from_ID3D11Buffer(iface
);
168 TRACE("iface %p, desc %p.\n", iface
, desc
);
170 *desc
= buffer
->desc
;
173 static const struct ID3D11BufferVtbl d3d11_buffer_vtbl
=
175 /* IUnknown methods */
176 d3d11_buffer_QueryInterface
,
178 d3d11_buffer_Release
,
179 /* ID3D11DeviceChild methods */
180 d3d11_buffer_GetDevice
,
181 d3d11_buffer_GetPrivateData
,
182 d3d11_buffer_SetPrivateData
,
183 d3d11_buffer_SetPrivateDataInterface
,
184 /* ID3D11Resource methods */
185 d3d11_buffer_GetType
,
186 d3d11_buffer_SetEvictionPriority
,
187 d3d11_buffer_GetEvictionPriority
,
188 /* ID3D11Buffer methods */
189 d3d11_buffer_GetDesc
,
192 /* ID3D10Buffer methods */
194 static inline struct d3d_buffer
*impl_from_ID3D10Buffer(ID3D10Buffer
*iface
)
196 return CONTAINING_RECORD(iface
, struct d3d_buffer
, ID3D10Buffer_iface
);
199 /* IUnknown methods */
201 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_QueryInterface(ID3D10Buffer
*iface
, REFIID riid
, void **out
)
203 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
205 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
207 return d3d11_buffer_QueryInterface(&buffer
->ID3D11Buffer_iface
, riid
, out
);
210 static ULONG STDMETHODCALLTYPE
d3d10_buffer_AddRef(ID3D10Buffer
*iface
)
212 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
214 TRACE("iface %p.\n", iface
);
216 return d3d11_buffer_AddRef(&buffer
->ID3D11Buffer_iface
);
219 static ULONG STDMETHODCALLTYPE
d3d10_buffer_Release(ID3D10Buffer
*iface
)
221 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
223 TRACE("iface %p.\n", iface
);
225 return d3d11_buffer_Release(&buffer
->ID3D11Buffer_iface
);
228 /* ID3D10DeviceChild methods */
230 static void STDMETHODCALLTYPE
d3d10_buffer_GetDevice(ID3D10Buffer
*iface
, ID3D10Device
**device
)
232 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
234 TRACE("iface %p, device %p.\n", iface
, device
);
236 ID3D11Device_QueryInterface(buffer
->device
, &IID_ID3D10Device
, (void **)device
);
239 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_GetPrivateData(ID3D10Buffer
*iface
,
240 REFGUID guid
, UINT
*data_size
, void *data
)
242 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
244 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
245 iface
, debugstr_guid(guid
), data_size
, data
);
247 return d3d_get_private_data(&buffer
->private_store
, guid
, data_size
, data
);
250 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_SetPrivateData(ID3D10Buffer
*iface
,
251 REFGUID guid
, UINT data_size
, const void *data
)
253 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
255 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
256 iface
, debugstr_guid(guid
), data_size
, data
);
258 return d3d_set_private_data(&buffer
->private_store
, guid
, data_size
, data
);
261 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer
*iface
,
262 REFGUID guid
, const IUnknown
*data
)
264 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
266 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
268 return d3d_set_private_data_interface(&buffer
->private_store
, guid
, data
);
271 /* ID3D10Resource methods */
273 static void STDMETHODCALLTYPE
d3d10_buffer_GetType(ID3D10Buffer
*iface
, D3D10_RESOURCE_DIMENSION
*resource_dimension
)
275 TRACE("iface %p, resource_dimension %p\n", iface
, resource_dimension
);
277 *resource_dimension
= D3D10_RESOURCE_DIMENSION_BUFFER
;
280 static void STDMETHODCALLTYPE
d3d10_buffer_SetEvictionPriority(ID3D10Buffer
*iface
, UINT eviction_priority
)
282 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
285 static UINT STDMETHODCALLTYPE
d3d10_buffer_GetEvictionPriority(ID3D10Buffer
*iface
)
287 FIXME("iface %p stub!\n", iface
);
292 /* ID3D10Buffer methods */
294 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_Map(ID3D10Buffer
*iface
, D3D10_MAP map_type
, UINT map_flags
, void **data
)
296 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
299 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface
, map_type
, map_flags
, data
);
302 FIXME("Ignoring map_flags %#x.\n", map_flags
);
304 wined3d_mutex_lock();
305 hr
= wined3d_buffer_map(buffer
->wined3d_buffer
, 0, 0, (BYTE
**)data
,
306 wined3d_map_flags_from_d3d10_map_type(map_type
));
307 wined3d_mutex_unlock();
312 static void STDMETHODCALLTYPE
d3d10_buffer_Unmap(ID3D10Buffer
*iface
)
314 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
316 TRACE("iface %p.\n", iface
);
318 wined3d_mutex_lock();
319 wined3d_buffer_unmap(buffer
->wined3d_buffer
);
320 wined3d_mutex_unlock();
323 static void STDMETHODCALLTYPE
d3d10_buffer_GetDesc(ID3D10Buffer
*iface
, D3D10_BUFFER_DESC
*desc
)
325 struct d3d_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
326 const D3D11_BUFFER_DESC
*d3d11_desc
= &buffer
->desc
;
328 TRACE("iface %p, desc %p.\n", iface
, desc
);
330 desc
->ByteWidth
= d3d11_desc
->ByteWidth
;
331 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
->Usage
);
332 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
->BindFlags
);
333 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
->CPUAccessFlags
);
334 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
->MiscFlags
);
337 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl
=
339 /* IUnknown methods */
340 d3d10_buffer_QueryInterface
,
342 d3d10_buffer_Release
,
343 /* ID3D10DeviceChild methods */
344 d3d10_buffer_GetDevice
,
345 d3d10_buffer_GetPrivateData
,
346 d3d10_buffer_SetPrivateData
,
347 d3d10_buffer_SetPrivateDataInterface
,
348 /* ID3D10Resource methods */
349 d3d10_buffer_GetType
,
350 d3d10_buffer_SetEvictionPriority
,
351 d3d10_buffer_GetEvictionPriority
,
352 /* ID3D10Buffer methods */
355 d3d10_buffer_GetDesc
,
358 struct d3d_buffer
*unsafe_impl_from_ID3D10Buffer(ID3D10Buffer
*iface
)
362 assert(iface
->lpVtbl
== &d3d10_buffer_vtbl
);
363 return CONTAINING_RECORD(iface
, struct d3d_buffer
, ID3D10Buffer_iface
);
366 static void STDMETHODCALLTYPE
d3d10_buffer_wined3d_object_released(void *parent
)
368 struct d3d_buffer
*buffer
= parent
;
370 wined3d_private_store_cleanup(&buffer
->private_store
);
371 HeapFree(GetProcessHeap(), 0, parent
);
374 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops
=
376 d3d10_buffer_wined3d_object_released
,
379 static HRESULT
d3d_buffer_init(struct d3d_buffer
*buffer
, struct d3d_device
*device
,
380 const D3D11_BUFFER_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
382 struct wined3d_buffer_desc wined3d_desc
;
385 buffer
->ID3D11Buffer_iface
.lpVtbl
= &d3d11_buffer_vtbl
;
386 buffer
->ID3D10Buffer_iface
.lpVtbl
= &d3d10_buffer_vtbl
;
387 buffer
->refcount
= 1;
388 wined3d_mutex_lock();
389 wined3d_private_store_init(&buffer
->private_store
);
390 buffer
->desc
= *desc
;
392 wined3d_desc
.byte_width
= desc
->ByteWidth
;
393 wined3d_desc
.usage
= wined3d_usage_from_d3d11(0, desc
->Usage
);
394 wined3d_desc
.bind_flags
= desc
->BindFlags
;
395 wined3d_desc
.cpu_access_flags
= desc
->CPUAccessFlags
;
396 wined3d_desc
.misc_flags
= desc
->MiscFlags
;
398 if (desc
->StructureByteStride
)
399 FIXME("Ignoring structure byte stride %u.\n", desc
->StructureByteStride
);
401 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &wined3d_desc
,
402 (const struct wined3d_sub_resource_data
*)data
, buffer
,
403 &d3d10_buffer_wined3d_parent_ops
, &buffer
->wined3d_buffer
)))
405 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
406 wined3d_private_store_cleanup(&buffer
->private_store
);
407 wined3d_mutex_unlock();
410 wined3d_mutex_unlock();
412 buffer
->device
= &device
->ID3D11Device_iface
;
413 ID3D11Device_AddRef(buffer
->device
);
418 HRESULT
d3d_buffer_create(struct d3d_device
*device
, const D3D11_BUFFER_DESC
*desc
,
419 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_buffer
**buffer
)
421 struct d3d_buffer
*object
;
424 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
425 return E_OUTOFMEMORY
;
427 if (FAILED(hr
= d3d_buffer_init(object
, device
, desc
, data
)))
429 WARN("Failed to initialize buffer, hr %#x.\n", hr
);
430 HeapFree(GetProcessHeap(), 0, object
);
434 TRACE("Created buffer %p.\n", object
);