2004-10-14 02:32:04 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2004 Jason Edmeades
|
|
|
|
* Copyright 2003-2004 Raphael Junqueira
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2010-11-18 20:50:40 +01:00
|
|
|
* Copyright 2009-2010 Henri Verbeet for CodeWeavers
|
2013-08-21 15:15:48 +02:00
|
|
|
* Copyright 2006-2008, 2013 Stefan Dösinger for CodeWeavers
|
2004-10-14 02:32:04 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-10-14 02:32:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2004-10-14 02:32:04 +02:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2010-11-30 18:39:36 +01:00
|
|
|
struct private_data
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
|
|
|
|
GUID tag;
|
|
|
|
DWORD flags; /* DDSPD_* */
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
IUnknown *object;
|
|
|
|
} ptr;
|
|
|
|
|
|
|
|
DWORD size;
|
|
|
|
};
|
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
static DWORD resource_access_from_pool(enum wined3d_pool pool)
|
2011-05-05 20:56:07 +02:00
|
|
|
{
|
|
|
|
switch (pool)
|
|
|
|
{
|
2012-01-17 21:13:37 +01:00
|
|
|
case WINED3D_POOL_DEFAULT:
|
2011-05-05 20:56:07 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_GPU;
|
|
|
|
|
2012-01-17 21:13:37 +01:00
|
|
|
case WINED3D_POOL_MANAGED:
|
2011-05-05 20:56:07 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
|
2013-08-22 14:57:58 +02:00
|
|
|
case WINED3D_POOL_SCRATCH:
|
2012-01-17 21:13:37 +01:00
|
|
|
case WINED3D_POOL_SYSTEM_MEM:
|
2011-05-05 20:56:07 +02:00
|
|
|
return WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled pool %#x.\n", pool);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-24 21:18:52 +02:00
|
|
|
static void resource_check_usage(DWORD usage)
|
|
|
|
{
|
|
|
|
static const DWORD handled = WINED3DUSAGE_RENDERTARGET
|
|
|
|
| WINED3DUSAGE_DEPTHSTENCIL
|
|
|
|
| WINED3DUSAGE_DYNAMIC
|
|
|
|
| WINED3DUSAGE_AUTOGENMIPMAP
|
|
|
|
| WINED3DUSAGE_STATICDECL
|
2013-09-06 00:11:11 +02:00
|
|
|
| WINED3DUSAGE_OVERLAY
|
|
|
|
| WINED3DUSAGE_TEXTURE;
|
2011-05-24 21:18:52 +02:00
|
|
|
|
|
|
|
if (usage & ~handled)
|
|
|
|
FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
|
2012-01-17 21:13:36 +01:00
|
|
|
enum wined3d_resource_type type, const struct wined3d_format *format,
|
2012-01-08 21:15:00 +01:00
|
|
|
enum wined3d_multisample_type multisample_type, UINT multisample_quality,
|
2012-01-17 21:13:37 +01:00
|
|
|
DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size,
|
2011-03-08 19:41:07 +01:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops,
|
2011-02-28 08:05:39 +01:00
|
|
|
const struct wined3d_resource_ops *resource_ops)
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
2013-05-19 23:13:30 +02:00
|
|
|
const struct wined3d *d3d = device->wined3d;
|
|
|
|
|
2013-09-05 09:54:40 +02:00
|
|
|
resource_check_usage(usage);
|
|
|
|
if (pool != WINED3D_POOL_SCRATCH)
|
|
|
|
{
|
|
|
|
if ((usage & WINED3DUSAGE_RENDERTARGET) && !(format->flags & WINED3DFMT_FLAG_RENDERTARGET))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2013-09-05 09:54:41 +02:00
|
|
|
if ((usage & WINED3DUSAGE_DEPTHSTENCIL) && !(format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2013-09-06 00:11:11 +02:00
|
|
|
if ((usage & WINED3DUSAGE_TEXTURE) && !(format->flags & WINED3DFMT_FLAG_TEXTURE))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2013-09-05 09:54:40 +02:00
|
|
|
}
|
|
|
|
|
2011-03-08 19:41:07 +01:00
|
|
|
resource->ref = 1;
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->device = device;
|
2012-01-17 21:13:36 +01:00
|
|
|
resource->type = type;
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->format = format;
|
2011-03-08 19:41:07 +01:00
|
|
|
resource->multisample_type = multisample_type;
|
|
|
|
resource->multisample_quality = multisample_quality;
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->usage = usage;
|
2011-03-08 19:41:07 +01:00
|
|
|
resource->pool = pool;
|
2011-05-05 20:56:07 +02:00
|
|
|
resource->access_flags = resource_access_from_pool(pool);
|
|
|
|
if (usage & WINED3DUSAGE_DYNAMIC)
|
|
|
|
resource->access_flags |= WINED3D_RESOURCE_ACCESS_CPU;
|
2011-03-08 19:41:07 +01:00
|
|
|
resource->width = width;
|
|
|
|
resource->height = height;
|
|
|
|
resource->depth = depth;
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->size = size;
|
|
|
|
resource->priority = 0;
|
|
|
|
resource->parent = parent;
|
|
|
|
resource->parent_ops = parent_ops;
|
|
|
|
resource->resource_ops = resource_ops;
|
|
|
|
list_init(&resource->privateData);
|
2009-01-13 10:31:57 +01:00
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
2013-09-16 10:57:24 +02:00
|
|
|
if (!wined3d_resource_allocate_sysmem(resource))
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
2013-09-16 10:57:24 +02:00
|
|
|
ERR("Failed to allocate system memory.\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2009-01-13 10:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-21 15:15:48 +02:00
|
|
|
resource->heap_memory = NULL;
|
2009-01-13 10:31:57 +01:00
|
|
|
}
|
2013-08-21 15:15:48 +02:00
|
|
|
resource->allocatedMemory = resource->heap_memory;
|
2009-01-13 10:31:57 +01:00
|
|
|
|
|
|
|
/* Check that we have enough video ram left */
|
2013-05-19 23:13:30 +02:00
|
|
|
if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
if (size > wined3d_device_get_available_texture_mem(device))
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
|
|
|
ERR("Out of adapter memory\n");
|
2013-09-16 10:57:25 +02:00
|
|
|
wined3d_resource_free_sysmem(resource);
|
2009-01-13 10:31:57 +01:00
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
2011-08-28 23:27:45 +02:00
|
|
|
adapter_adjust_memory(device->adapter, size);
|
2009-01-13 10:31:57 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 23:36:45 +01:00
|
|
|
device_resource_add(device, resource);
|
2009-05-29 09:13:21 +02:00
|
|
|
|
2009-01-13 10:31:57 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
void resource_cleanup(struct wined3d_resource *resource)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2013-05-19 23:13:30 +02:00
|
|
|
const struct wined3d *d3d = resource->device->wined3d;
|
2010-11-30 18:39:36 +01:00
|
|
|
struct private_data *data;
|
2007-05-11 00:09:35 +02:00
|
|
|
struct list *e1, *e2;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-01-06 09:39:00 +01:00
|
|
|
TRACE("Cleaning up resource %p.\n", resource);
|
|
|
|
|
2013-05-19 23:13:30 +02:00
|
|
|
if (resource->pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
|
2011-01-06 09:39:00 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
TRACE("Decrementing device memory pool by %u.\n", resource->size);
|
2011-08-28 23:27:45 +02:00
|
|
|
adapter_adjust_memory(resource->device->adapter, 0 - resource->size);
|
2005-07-13 13:34:55 +02:00
|
|
|
}
|
2005-03-29 21:01:00 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
LIST_FOR_EACH_SAFE(e1, e2, &resource->privateData)
|
2010-11-30 18:39:36 +01:00
|
|
|
{
|
|
|
|
data = LIST_ENTRY(e1, struct private_data, entry);
|
2011-06-16 22:38:26 +02:00
|
|
|
hr = wined3d_resource_free_private_data(resource, &data->tag);
|
2011-01-06 09:39:00 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
|
2007-05-11 00:09:35 +02:00
|
|
|
}
|
|
|
|
|
2013-09-16 10:57:25 +02:00
|
|
|
wined3d_resource_free_sysmem(resource);
|
2013-08-21 15:15:48 +02:00
|
|
|
resource->allocatedMemory = NULL;
|
2005-07-26 12:34:15 +02:00
|
|
|
|
2013-05-25 09:40:54 +02:00
|
|
|
device_resource_released(resource->device, resource);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
void resource_unload(struct wined3d_resource *resource)
|
2010-08-15 23:21:42 +02:00
|
|
|
{
|
2012-05-21 20:48:35 +02:00
|
|
|
if (resource->map_count)
|
|
|
|
ERR("Resource %p is being unloaded while mapped.\n", resource);
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
context_resource_unloaded(resource->device,
|
2012-01-17 21:13:36 +01:00
|
|
|
resource, resource->type);
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
static struct private_data *resource_find_private_data(const struct wined3d_resource *resource, REFGUID tag)
|
2005-07-15 11:54:57 +02:00
|
|
|
{
|
2010-11-30 18:39:36 +01:00
|
|
|
struct private_data *data;
|
2007-05-07 20:46:24 +02:00
|
|
|
struct list *entry;
|
|
|
|
|
|
|
|
TRACE("Searching for private data %s\n", debugstr_guid(tag));
|
2011-03-01 09:47:56 +01:00
|
|
|
LIST_FOR_EACH(entry, &resource->privateData)
|
2005-07-15 11:54:57 +02:00
|
|
|
{
|
2010-11-30 18:39:36 +01:00
|
|
|
data = LIST_ENTRY(entry, struct private_data, entry);
|
2007-05-07 20:46:24 +02:00
|
|
|
if (IsEqualGUID(&data->tag, tag)) {
|
|
|
|
TRACE("Found %p\n", data);
|
|
|
|
return data;
|
|
|
|
}
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2007-05-07 20:46:24 +02:00
|
|
|
TRACE("Not found\n");
|
|
|
|
return NULL;
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
|
|
|
|
2011-06-16 22:38:26 +02:00
|
|
|
HRESULT CDECL wined3d_resource_set_private_data(struct wined3d_resource *resource, REFGUID guid,
|
2011-01-07 10:16:38 +01:00
|
|
|
const void *data, DWORD data_size, DWORD flags)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2011-01-07 10:16:38 +01:00
|
|
|
struct private_data *d;
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-01-07 10:16:38 +01:00
|
|
|
TRACE("resource %p, riid %s, data %p, data_size %u, flags %#x.\n",
|
|
|
|
resource, debugstr_guid(guid), data, data_size, flags);
|
2010-11-18 20:50:40 +01:00
|
|
|
|
2011-06-16 22:38:26 +02:00
|
|
|
wined3d_resource_free_private_data(resource, guid);
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-01-07 10:16:38 +01:00
|
|
|
d = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*d));
|
|
|
|
if (!d) return E_OUTOFMEMORY;
|
2007-05-11 00:09:35 +02:00
|
|
|
|
2011-01-07 10:16:38 +01:00
|
|
|
d->tag = *guid;
|
|
|
|
d->flags = flags;
|
2008-12-01 15:32:15 +01:00
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags & WINED3DSPD_IUNKNOWN)
|
|
|
|
{
|
2011-01-07 10:16:38 +01:00
|
|
|
if (data_size != sizeof(IUnknown *))
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2011-01-07 10:16:38 +01:00
|
|
|
WARN("IUnknown data with size %u, returning WINED3DERR_INVALIDCALL.\n", data_size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, d);
|
2007-05-11 00:09:35 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2011-01-07 10:16:38 +01:00
|
|
|
d->ptr.object = (IUnknown *)data;
|
|
|
|
d->size = sizeof(IUnknown *);
|
|
|
|
IUnknown_AddRef(d->ptr.object);
|
2007-05-11 00:09:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-07 10:16:38 +01:00
|
|
|
d->ptr.data = HeapAlloc(GetProcessHeap(), 0, data_size);
|
|
|
|
if (!d->ptr.data)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-01-07 10:16:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d);
|
2007-05-11 00:09:35 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2011-01-07 10:16:38 +01:00
|
|
|
d->size = data_size;
|
|
|
|
memcpy(d->ptr.data, data, data_size);
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2011-03-01 09:47:56 +01:00
|
|
|
list_add_tail(&resource->privateData, &d->entry);
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-06-16 22:38:26 +02:00
|
|
|
HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid,
|
|
|
|
void *data, DWORD *data_size)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2011-01-06 09:39:02 +01:00
|
|
|
const struct private_data *d;
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-01-06 09:39:02 +01:00
|
|
|
TRACE("resource %p, guid %s, data %p, data_size %p.\n",
|
|
|
|
resource, debugstr_guid(guid), data, data_size);
|
|
|
|
|
|
|
|
d = resource_find_private_data(resource, guid);
|
|
|
|
if (!d) return WINED3DERR_NOTFOUND;
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-01-06 09:39:02 +01:00
|
|
|
if (*data_size < d->size)
|
|
|
|
{
|
|
|
|
*data_size = d->size;
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3DERR_MOREDATA;
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
|
|
|
|
2011-01-06 09:39:02 +01:00
|
|
|
if (d->flags & WINED3DSPD_IUNKNOWN)
|
|
|
|
{
|
|
|
|
*(IUnknown **)data = d->ptr.object;
|
2011-03-01 09:47:56 +01:00
|
|
|
if (resource->device->wined3d->dxVersion != 7)
|
2009-12-07 20:20:02 +01:00
|
|
|
{
|
2011-01-06 09:39:02 +01:00
|
|
|
/* D3D8 and D3D9 addref the private data, DDraw does not. This
|
|
|
|
* can't be handled in ddraw because it doesn't know if the
|
|
|
|
* pointer returned is an IUnknown * or just a blob. */
|
|
|
|
IUnknown_AddRef(d->ptr.object);
|
2007-05-11 00:09:35 +02:00
|
|
|
}
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2011-01-06 09:39:02 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(data, d->ptr.data, d->size);
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
2011-06-16 22:38:26 +02:00
|
|
|
HRESULT CDECL wined3d_resource_free_private_data(struct wined3d_resource *resource, REFGUID guid)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2010-11-30 18:39:36 +01:00
|
|
|
struct private_data *data;
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2011-01-06 09:39:01 +01:00
|
|
|
TRACE("resource %p, guid %s.\n", resource, debugstr_guid(guid));
|
|
|
|
|
|
|
|
data = resource_find_private_data(resource, guid);
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!data) return WINED3DERR_NOTFOUND;
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2007-05-07 20:46:24 +02:00
|
|
|
if (data->flags & WINED3DSPD_IUNKNOWN)
|
2005-07-15 11:54:57 +02:00
|
|
|
{
|
2010-09-14 13:38:39 +02:00
|
|
|
if (data->ptr.object)
|
2007-05-07 20:46:24 +02:00
|
|
|
IUnknown_Release(data->ptr.object);
|
2010-09-14 13:38:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-07 20:46:24 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, data->ptr.data);
|
2005-07-15 11:54:57 +02:00
|
|
|
}
|
2007-05-07 20:46:24 +02:00
|
|
|
list_remove(&data->entry);
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2007-05-07 20:46:24 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
2005-07-15 11:54:57 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
DWORD prev = resource->priority;
|
|
|
|
resource->priority = priority;
|
2011-01-07 10:16:40 +01:00
|
|
|
TRACE("resource %p, new priority %u, returning old priority %u.\n", resource, priority, prev);
|
|
|
|
return prev;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
2008-09-29 19:52:18 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
DWORD resource_get_priority(const struct wined3d_resource *resource)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2011-03-01 09:47:56 +01:00
|
|
|
TRACE("resource %p, returning %u.\n", resource, resource->priority);
|
|
|
|
return resource->priority;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
void * CDECL wined3d_resource_get_parent(const struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
return resource->parent;
|
2004-10-14 02:32:04 +02:00
|
|
|
}
|
2011-03-09 19:16:15 +01:00
|
|
|
|
2011-03-09 19:16:17 +01:00
|
|
|
void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, struct wined3d_resource_desc *desc)
|
2011-03-09 19:16:15 +01:00
|
|
|
{
|
2012-01-17 21:13:36 +01:00
|
|
|
desc->resource_type = resource->type;
|
2011-03-09 19:16:15 +01:00
|
|
|
desc->format = resource->format->id;
|
|
|
|
desc->multisample_type = resource->multisample_type;
|
|
|
|
desc->multisample_quality = resource->multisample_quality;
|
|
|
|
desc->usage = resource->usage;
|
|
|
|
desc->pool = resource->pool;
|
|
|
|
desc->width = resource->width;
|
|
|
|
desc->height = resource->height;
|
|
|
|
desc->depth = resource->depth;
|
|
|
|
desc->size = resource->size;
|
|
|
|
}
|
2013-08-21 15:15:48 +02:00
|
|
|
|
2013-09-16 10:57:24 +02:00
|
|
|
BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource)
|
2013-08-21 15:15:48 +02:00
|
|
|
{
|
|
|
|
void **p;
|
|
|
|
SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
|
|
|
|
void *mem;
|
|
|
|
|
2013-09-16 10:57:24 +02:00
|
|
|
if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, resource->size + align)))
|
|
|
|
return FALSE;
|
2013-08-21 15:15:48 +02:00
|
|
|
|
|
|
|
p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
|
|
|
|
*p = mem;
|
|
|
|
|
2013-09-16 10:57:24 +02:00
|
|
|
resource->heap_memory = ++p;
|
|
|
|
|
|
|
|
return TRUE;
|
2013-08-21 15:15:48 +02:00
|
|
|
}
|
|
|
|
|
2013-09-16 10:57:25 +02:00
|
|
|
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
|
2013-08-21 15:15:48 +02:00
|
|
|
{
|
2013-09-16 10:57:25 +02:00
|
|
|
void **p = resource->heap_memory;
|
2013-08-21 15:15:48 +02:00
|
|
|
|
2013-09-16 10:57:25 +02:00
|
|
|
if (!p)
|
2013-08-21 15:15:48 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, *(--p));
|
2013-09-16 10:57:25 +02:00
|
|
|
resource->heap_memory = NULL;
|
2013-08-21 15:15:48 +02:00
|
|
|
}
|
2013-08-26 02:01:28 +02:00
|
|
|
|
|
|
|
DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource, DWORD flags)
|
|
|
|
{
|
|
|
|
/* Not all flags make sense together, but Windows never returns an error.
|
|
|
|
* Catch the cases that could cause issues. */
|
|
|
|
if (flags & WINED3D_MAP_READONLY)
|
|
|
|
{
|
|
|
|
if (flags & WINED3D_MAP_DISCARD)
|
|
|
|
{
|
|
|
|
WARN("WINED3D_MAP_READONLY combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (flags & WINED3D_MAP_NOOVERWRITE)
|
|
|
|
{
|
|
|
|
WARN("WINED3D_MAP_READONLY combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
|
|
|
== (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
|
|
|
{
|
|
|
|
WARN("WINED3D_MAP_DISCARD and WINED3D_MAP_NOOVERWRITE used together, ignoring.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE)
|
|
|
|
&& !(resource->usage & WINED3DUSAGE_DYNAMIC))
|
|
|
|
{
|
|
|
|
WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags)
|
|
|
|
{
|
|
|
|
GLbitfield ret = 0;
|
|
|
|
|
|
|
|
if (!(d3d_flags & WINED3D_MAP_READONLY))
|
|
|
|
ret |= GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
|
|
|
|
if (!(d3d_flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE)))
|
|
|
|
ret |= GL_MAP_READ_BIT;
|
|
|
|
|
|
|
|
if (d3d_flags & WINED3D_MAP_DISCARD)
|
|
|
|
ret |= GL_MAP_INVALIDATE_BUFFER_BIT;
|
|
|
|
if (d3d_flags & WINED3D_MAP_NOOVERWRITE)
|
|
|
|
ret |= GL_MAP_UNSYNCHRONIZED_BIT;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2013-09-19 11:02:55 +02:00
|
|
|
|
|
|
|
GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags)
|
|
|
|
{
|
|
|
|
if (d3d_flags & WINED3D_MAP_READONLY)
|
|
|
|
return GL_READ_ONLY_ARB;
|
|
|
|
if (d3d_flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
|
|
|
return GL_WRITE_ONLY_ARB;
|
|
|
|
return GL_READ_WRITE_ARB;
|
|
|
|
}
|