2009-01-23 10:22:34 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-08-21 00:07:53 +02:00
|
|
|
#include "d3d11_private.h"
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2015-08-21 00:07:53 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
/* ID3D11Buffer methods */
|
|
|
|
|
|
|
|
static inline struct d3d_buffer *impl_from_ID3D11Buffer(ID3D11Buffer *iface)
|
2012-04-15 18:57:11 +02:00
|
|
|
{
|
2015-09-03 00:06:53 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_buffer, ID3D11Buffer_iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_buffer_QueryInterface(ID3D11Buffer *iface, REFIID riid, void **out)
|
2009-01-23 10:22:34 +01:00
|
|
|
{
|
2015-09-03 00:06:53 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
|
|
|
|
2012-04-15 18:57:11 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_ID3D11Buffer)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3D11Resource)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3D11DeviceChild)
|
2009-01-23 10:22:34 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2015-09-03 00:06:53 +02:00
|
|
|
ID3D11Buffer_AddRef(iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
*out = iface;
|
2009-01-23 10:22:34 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_ID3D10Buffer)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3D10Resource)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3D10DeviceChild))
|
|
|
|
{
|
|
|
|
ID3D10Buffer_AddRef(&buffer->ID3D10Buffer_iface);
|
|
|
|
*out = &buffer->ID3D10Buffer_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2012-04-15 18:57:11 +02:00
|
|
|
*out = NULL;
|
2009-01-23 10:22:34 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d3d11_buffer_AddRef(ID3D11Buffer *iface)
|
2009-01-23 10:22:34 +01:00
|
|
|
{
|
2015-09-03 00:06:53 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&buffer->refcount);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2012-04-15 18:57:11 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", buffer, refcount);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2011-03-03 21:49:09 +01:00
|
|
|
if (refcount == 1)
|
2014-02-13 10:14:21 +01:00
|
|
|
{
|
2018-05-16 11:55:27 +02:00
|
|
|
ID3D11Device2_AddRef(buffer->device);
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-04-15 18:57:11 +02:00
|
|
|
wined3d_buffer_incref(buffer->wined3d_buffer);
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-02-13 10:14:21 +01:00
|
|
|
}
|
2009-09-17 23:03:32 +02:00
|
|
|
|
2009-01-23 10:22:34 +01:00
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d3d11_buffer_Release(ID3D11Buffer *iface)
|
2009-01-23 10:22:34 +01:00
|
|
|
{
|
2015-09-03 00:06:53 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&buffer->refcount);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2012-04-15 18:57:11 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
|
|
|
if (!refcount)
|
2014-02-13 10:14:21 +01:00
|
|
|
{
|
2018-05-16 11:55:27 +02:00
|
|
|
ID3D11Device2 *device = buffer->device;
|
2014-02-13 10:14:21 +01:00
|
|
|
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-04-15 18:57:11 +02:00
|
|
|
wined3d_buffer_decref(buffer->wined3d_buffer);
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-02-13 10:14:21 +01:00
|
|
|
/* Release the device last, it may cause the wined3d device to be
|
|
|
|
* destroyed. */
|
2018-05-16 11:55:27 +02:00
|
|
|
ID3D11Device2_Release(device);
|
2014-02-13 10:14:21 +01:00
|
|
|
}
|
2009-01-23 10:22:34 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
static void STDMETHODCALLTYPE d3d11_buffer_GetDevice(ID3D11Buffer *iface, ID3D11Device **device)
|
|
|
|
{
|
2015-09-03 00:06:55 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, device %p.\n", iface, device);
|
|
|
|
|
2018-04-30 13:30:08 +02:00
|
|
|
*device = (ID3D11Device *)buffer->device;
|
2015-09-06 16:45:49 +02:00
|
|
|
ID3D11Device_AddRef(*device);
|
2015-09-03 00:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_buffer_GetPrivateData(ID3D11Buffer *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
2015-09-03 00:06:54 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
2015-09-03 00:06:53 +02:00
|
|
|
|
2015-09-03 00:06:54 +02:00
|
|
|
return d3d_get_private_data(&buffer->private_store, guid, data_size, data);
|
2015-09-03 00:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_buffer_SetPrivateData(ID3D11Buffer *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
2015-09-03 00:06:54 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
2015-09-03 00:06:53 +02:00
|
|
|
|
2015-09-03 00:06:54 +02:00
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return d3d_set_private_data(&buffer->private_store, guid, data_size, data);
|
2015-09-03 00:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d11_buffer_SetPrivateDataInterface(ID3D11Buffer *iface,
|
|
|
|
REFGUID guid, const IUnknown *data)
|
|
|
|
{
|
2015-09-03 00:06:54 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
|
2015-09-03 00:06:53 +02:00
|
|
|
|
2015-09-03 00:06:54 +02:00
|
|
|
return d3d_set_private_data_interface(&buffer->private_store, guid, data);
|
2015-09-03 00:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d11_buffer_GetType(ID3D11Buffer *iface,
|
|
|
|
D3D11_RESOURCE_DIMENSION *resource_dimension)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, resource_dimension %p.\n", iface, resource_dimension);
|
|
|
|
|
|
|
|
*resource_dimension = D3D11_RESOURCE_DIMENSION_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d11_buffer_SetEvictionPriority(ID3D11Buffer *iface, UINT eviction_priority)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, eviction_priority %#x stub!\n", iface, eviction_priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STDMETHODCALLTYPE d3d11_buffer_GetEvictionPriority(ID3D11Buffer *iface)
|
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d11_buffer_GetDesc(ID3D11Buffer *iface, D3D11_BUFFER_DESC *desc)
|
|
|
|
{
|
2015-09-06 16:45:46 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D11Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
*desc = buffer->desc;
|
2015-09-03 00:06:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ID3D11BufferVtbl d3d11_buffer_vtbl =
|
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
d3d11_buffer_QueryInterface,
|
|
|
|
d3d11_buffer_AddRef,
|
|
|
|
d3d11_buffer_Release,
|
|
|
|
/* ID3D11DeviceChild methods */
|
|
|
|
d3d11_buffer_GetDevice,
|
|
|
|
d3d11_buffer_GetPrivateData,
|
|
|
|
d3d11_buffer_SetPrivateData,
|
|
|
|
d3d11_buffer_SetPrivateDataInterface,
|
|
|
|
/* ID3D11Resource methods */
|
|
|
|
d3d11_buffer_GetType,
|
|
|
|
d3d11_buffer_SetEvictionPriority,
|
|
|
|
d3d11_buffer_GetEvictionPriority,
|
|
|
|
/* ID3D11Buffer methods */
|
|
|
|
d3d11_buffer_GetDesc,
|
|
|
|
};
|
|
|
|
|
2015-09-08 01:12:45 +02:00
|
|
|
struct d3d_buffer *unsafe_impl_from_ID3D11Buffer(ID3D11Buffer *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d11_buffer_vtbl);
|
|
|
|
return CONTAINING_RECORD(iface, struct d3d_buffer, ID3D11Buffer_iface);
|
|
|
|
}
|
|
|
|
|
2015-09-03 00:06:53 +02:00
|
|
|
/* ID3D10Buffer methods */
|
|
|
|
|
|
|
|
static inline struct d3d_buffer *impl_from_ID3D10Buffer(ID3D10Buffer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct d3d_buffer, ID3D10Buffer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IUnknown methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **out)
|
|
|
|
{
|
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
|
|
|
|
|
|
|
return d3d11_buffer_QueryInterface(&buffer->ID3D11Buffer_iface, riid, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface)
|
|
|
|
{
|
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
return d3d11_buffer_AddRef(&buffer->ID3D11Buffer_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
|
|
|
|
{
|
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
return d3d11_buffer_Release(&buffer->ID3D11Buffer_iface);
|
|
|
|
}
|
|
|
|
|
2009-01-23 10:22:34 +01:00
|
|
|
/* ID3D10DeviceChild methods */
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2014-02-13 10:14:21 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, device %p.\n", iface, device);
|
|
|
|
|
2018-05-16 11:55:27 +02:00
|
|
|
ID3D11Device2_QueryInterface(buffer->device, &IID_ID3D10Device, (void **)device);
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2015-02-25 09:34:07 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n",
|
2009-01-23 10:22:34 +01:00
|
|
|
iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
2015-09-03 00:06:50 +02:00
|
|
|
return d3d_get_private_data(&buffer->private_store, guid, data_size, data);
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2015-02-23 17:59:48 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n",
|
2009-01-23 10:22:34 +01:00
|
|
|
iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
2015-09-03 00:06:50 +02:00
|
|
|
return d3d_set_private_data(&buffer->private_store, guid, data_size, data);
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
|
|
|
|
REFGUID guid, const IUnknown *data)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2015-02-25 09:34:06 +01:00
|
|
|
TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
|
|
|
|
|
2015-09-03 00:06:50 +02:00
|
|
|
return d3d_set_private_data_interface(&buffer->private_store, guid, data);
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ID3D10Resource methods */
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
|
|
|
|
{
|
2009-01-26 09:38:14 +01:00
|
|
|
TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
|
|
|
|
|
|
|
|
*resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
|
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ID3D10Buffer methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2016-08-31 11:27:50 +02:00
|
|
|
struct wined3d_map_desc wined3d_map_desc;
|
2015-08-12 17:37:08 +02:00
|
|
|
HRESULT hr;
|
2009-01-23 10:22:34 +01:00
|
|
|
|
2010-10-15 14:35:14 +02:00
|
|
|
TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
|
|
|
|
|
|
|
|
if (map_flags)
|
|
|
|
FIXME("Ignoring map_flags %#x.\n", map_flags);
|
|
|
|
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_lock();
|
2016-08-31 11:27:50 +02:00
|
|
|
hr = wined3d_resource_map(wined3d_buffer_get_resource(buffer->wined3d_buffer), 0,
|
|
|
|
&wined3d_map_desc, NULL, wined3d_map_flags_from_d3d11_map_type(map_type));
|
|
|
|
*data = wined3d_map_desc.data;
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return hr;
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
|
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
|
2010-10-15 14:35:13 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_lock();
|
2016-08-31 11:27:51 +02:00
|
|
|
wined3d_resource_unmap(wined3d_buffer_get_resource(buffer->wined3d_buffer), 0);
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
|
|
|
|
{
|
2015-09-06 16:45:47 +02:00
|
|
|
struct d3d_buffer *buffer = impl_from_ID3D10Buffer(iface);
|
|
|
|
const D3D11_BUFFER_DESC *d3d11_desc = &buffer->desc;
|
|
|
|
|
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
|
|
|
desc->ByteWidth = d3d11_desc->ByteWidth;
|
|
|
|
desc->Usage = d3d10_usage_from_d3d11_usage(d3d11_desc->Usage);
|
|
|
|
desc->BindFlags = d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc->BindFlags);
|
|
|
|
desc->CPUAccessFlags = d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc->CPUAccessFlags);
|
|
|
|
desc->MiscFlags = d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc->MiscFlags);
|
2009-01-23 10:22:34 +01:00
|
|
|
}
|
|
|
|
|
2009-09-17 23:03:27 +02:00
|
|
|
static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
|
2009-01-23 10:22:34 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
d3d10_buffer_QueryInterface,
|
|
|
|
d3d10_buffer_AddRef,
|
|
|
|
d3d10_buffer_Release,
|
|
|
|
/* ID3D10DeviceChild methods */
|
|
|
|
d3d10_buffer_GetDevice,
|
|
|
|
d3d10_buffer_GetPrivateData,
|
|
|
|
d3d10_buffer_SetPrivateData,
|
|
|
|
d3d10_buffer_SetPrivateDataInterface,
|
|
|
|
/* ID3D10Resource methods */
|
|
|
|
d3d10_buffer_GetType,
|
|
|
|
d3d10_buffer_SetEvictionPriority,
|
|
|
|
d3d10_buffer_GetEvictionPriority,
|
|
|
|
/* ID3D10Buffer methods */
|
|
|
|
d3d10_buffer_Map,
|
|
|
|
d3d10_buffer_Unmap,
|
|
|
|
d3d10_buffer_GetDesc,
|
|
|
|
};
|
2009-09-17 23:03:27 +02:00
|
|
|
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface)
|
2012-04-15 18:57:11 +02:00
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d10_buffer_vtbl);
|
2015-09-03 00:06:52 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_buffer, ID3D10Buffer_iface);
|
2012-04-15 18:57:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-20 15:49:40 +02:00
|
|
|
static void STDMETHODCALLTYPE d3d_buffer_wined3d_object_released(void *parent)
|
2009-09-17 23:03:32 +02:00
|
|
|
{
|
2015-09-03 00:06:52 +02:00
|
|
|
struct d3d_buffer *buffer = parent;
|
2015-02-23 17:59:48 +01:00
|
|
|
|
|
|
|
wined3d_private_store_cleanup(&buffer->private_store);
|
2018-02-04 14:50:57 +01:00
|
|
|
heap_free(parent);
|
2009-09-17 23:03:32 +02:00
|
|
|
}
|
|
|
|
|
2016-07-20 15:49:40 +02:00
|
|
|
static const struct wined3d_parent_ops d3d_buffer_wined3d_parent_ops =
|
2009-09-17 23:03:32 +02:00
|
|
|
{
|
2016-07-20 15:49:40 +02:00
|
|
|
d3d_buffer_wined3d_object_released,
|
2009-09-17 23:03:32 +02:00
|
|
|
};
|
|
|
|
|
2018-02-01 09:50:31 +01:00
|
|
|
static BOOL validate_buffer_desc(D3D11_BUFFER_DESC *desc, D3D_FEATURE_LEVEL feature_level)
|
2009-09-17 23:03:27 +02:00
|
|
|
{
|
2018-02-01 09:50:31 +01:00
|
|
|
if (!validate_d3d11_resource_access_flags(D3D11_RESOURCE_DIMENSION_BUFFER,
|
|
|
|
desc->Usage, desc->BindFlags, desc->CPUAccessFlags, feature_level))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-10 12:26:56 +01:00
|
|
|
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
2017-02-10 12:26:56 +01:00
|
|
|
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
|
|
|
WARN("Raw and structure buffers are mutually exclusive.\n");
|
2017-02-10 12:26:56 +01:00
|
|
|
return FALSE;
|
2016-07-20 15:49:40 +02:00
|
|
|
}
|
2017-02-10 12:26:56 +01:00
|
|
|
if (!(desc->BindFlags & (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS)))
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
2017-02-10 12:26:56 +01:00
|
|
|
WARN("Invalid bind flags %#x for raw buffer.\n", desc->BindFlags);
|
|
|
|
return FALSE;
|
2016-07-20 15:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:26:56 +01:00
|
|
|
if (desc->MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
2017-02-10 12:26:56 +01:00
|
|
|
if (!desc->StructureByteStride || desc->StructureByteStride % 4)
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
2017-02-10 12:26:56 +01:00
|
|
|
WARN("Invalid structure byte stride %u.\n", desc->StructureByteStride);
|
|
|
|
return FALSE;
|
2016-07-20 15:49:40 +02:00
|
|
|
}
|
2017-02-10 12:26:56 +01:00
|
|
|
if (desc->ByteWidth % desc->StructureByteStride)
|
2016-07-20 15:49:40 +02:00
|
|
|
{
|
|
|
|
WARN("Byte width %u is not divisible by structure byte stride %u.\n",
|
2017-02-10 12:26:56 +01:00
|
|
|
desc->ByteWidth, desc->StructureByteStride);
|
|
|
|
return FALSE;
|
2016-07-20 15:49:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-10 12:26:56 +01:00
|
|
|
desc->StructureByteStride = 0;
|
2016-07-20 15:49:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 18:07:28 +01:00
|
|
|
if (desc->MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS)
|
|
|
|
{
|
|
|
|
WARN("Buffer with the D3D11_RESOURCE_MISC_GENERATE_MIPS flag.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:26:56 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT d3d_buffer_init(struct d3d_buffer *buffer, struct d3d_device *device,
|
|
|
|
const D3D11_BUFFER_DESC *desc, const D3D11_SUBRESOURCE_DATA *data)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer_desc wined3d_desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
buffer->ID3D11Buffer_iface.lpVtbl = &d3d11_buffer_vtbl;
|
|
|
|
buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
|
|
|
|
buffer->refcount = 1;
|
|
|
|
buffer->desc = *desc;
|
|
|
|
|
2018-02-01 09:50:31 +01:00
|
|
|
if (!validate_buffer_desc(&buffer->desc, device->feature_level))
|
2017-02-10 12:26:56 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2016-07-20 15:49:40 +02:00
|
|
|
wined3d_desc.byte_width = buffer->desc.ByteWidth;
|
2018-11-06 11:12:59 +01:00
|
|
|
wined3d_desc.usage = wined3d_usage_from_d3d11(buffer->desc.Usage);
|
2018-10-31 10:31:47 +01:00
|
|
|
wined3d_desc.bind_flags = wined3d_bind_flags_from_d3d11(buffer->desc.BindFlags);
|
2018-02-16 07:09:04 +01:00
|
|
|
wined3d_desc.access = wined3d_access_from_d3d11(buffer->desc.Usage, buffer->desc.CPUAccessFlags);
|
2016-07-20 15:49:40 +02:00
|
|
|
wined3d_desc.misc_flags = buffer->desc.MiscFlags;
|
2017-02-23 15:00:56 +01:00
|
|
|
wined3d_desc.structure_byte_stride = buffer->desc.StructureByteStride;
|
2015-09-06 16:45:46 +02:00
|
|
|
|
2017-02-10 12:26:56 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_private_store_init(&buffer->private_store);
|
|
|
|
|
2015-07-31 09:46:29 +02:00
|
|
|
if (FAILED(hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
|
|
|
|
(const struct wined3d_sub_resource_data *)data, buffer,
|
2016-07-20 15:49:40 +02:00
|
|
|
&d3d_buffer_wined3d_parent_ops, &buffer->wined3d_buffer)))
|
2009-09-17 23:03:27 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
|
2015-02-23 17:59:48 +01:00
|
|
|
wined3d_private_store_cleanup(&buffer->private_store);
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
2009-09-17 23:03:27 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2015-08-12 17:37:08 +02:00
|
|
|
wined3d_mutex_unlock();
|
2009-09-17 23:03:27 +02:00
|
|
|
|
2018-05-16 11:55:27 +02:00
|
|
|
ID3D11Device2_AddRef(buffer->device = &device->ID3D11Device2_iface);
|
2014-02-13 10:14:21 +01:00
|
|
|
|
2009-09-17 23:03:27 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2015-09-06 16:45:48 +02:00
|
|
|
|
|
|
|
HRESULT d3d_buffer_create(struct d3d_device *device, const D3D11_BUFFER_DESC *desc,
|
|
|
|
const D3D11_SUBRESOURCE_DATA *data, struct d3d_buffer **buffer)
|
|
|
|
{
|
|
|
|
struct d3d_buffer *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-02-04 14:50:57 +01:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2015-09-06 16:45:48 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (FAILED(hr = d3d_buffer_init(object, device, desc, data)))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize buffer, hr %#x.\n", hr);
|
2018-02-04 14:50:57 +01:00
|
|
|
heap_free(object);
|
2015-09-06 16:45:48 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created buffer %p.\n", object);
|
|
|
|
*buffer = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|