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);
|
2014-07-06 18:06:42 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2004-10-14 02:32:04 +02:00
|
|
|
|
2019-01-31 13:17:23 +01:00
|
|
|
static void resource_check_usage(DWORD usage, unsigned int access)
|
2011-05-24 21:18:52 +02:00
|
|
|
{
|
2019-01-31 13:17:23 +01:00
|
|
|
static const DWORD handled = WINED3DUSAGE_DYNAMIC
|
2011-05-24 21:18:52 +02:00
|
|
|
| WINED3DUSAGE_STATICDECL
|
2013-09-06 00:11:11 +02:00
|
|
|
| WINED3DUSAGE_OVERLAY
|
2018-01-29 18:40:23 +01:00
|
|
|
| WINED3DUSAGE_SCRATCH
|
2017-04-13 00:10:59 +02:00
|
|
|
| WINED3DUSAGE_PRIVATE
|
2016-01-27 00:06:23 +01:00
|
|
|
| WINED3DUSAGE_LEGACY_CUBEMAP
|
2018-09-27 17:30:33 +02:00
|
|
|
| ~WINED3DUSAGE_MASK;
|
2011-05-24 21:18:52 +02:00
|
|
|
|
2019-01-31 13:17:23 +01:00
|
|
|
/* Write-only CPU access is supposed to result in write-combined mappings
|
2014-07-14 10:04:23 +02:00
|
|
|
* being returned. OpenGL doesn't give us explicit control over that, but
|
|
|
|
* the hints and access flags we set for typical access patterns on
|
|
|
|
* dynamic resources should in theory have the same effect on the OpenGL
|
|
|
|
* driver. */
|
|
|
|
|
2011-05-24 21:18:52 +02:00
|
|
|
if (usage & ~handled)
|
|
|
|
FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
|
2019-01-31 13:17:23 +01:00
|
|
|
if (usage & WINED3DUSAGE_DYNAMIC && access & WINED3D_RESOURCE_ACCESS_MAP_R)
|
|
|
|
WARN_(d3d_perf)("WINED3DUSAGE_DYNAMIC used with WINED3D_RESOURCE_ACCESS_MAP_R.\n");
|
2011-05-24 21:18:52 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
|
2015-06-06 17:53:53 +02:00
|
|
|
enum wined3d_resource_type type, const struct wined3d_format *format,
|
2018-10-30 10:48:47 +01:00
|
|
|
enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, unsigned int usage,
|
|
|
|
unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
|
2018-02-02 17:58:54 +01:00
|
|
|
unsigned int size, 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
|
|
|
{
|
2018-09-18 00:31:20 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
|
2016-01-27 00:06:23 +01:00
|
|
|
enum wined3d_gl_resource_type base_type = WINED3D_GL_RES_TYPE_COUNT;
|
|
|
|
enum wined3d_gl_resource_type gl_type = WINED3D_GL_RES_TYPE_COUNT;
|
2015-06-06 17:53:53 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2016-01-27 00:06:23 +01:00
|
|
|
BOOL tex_2d_ok = FALSE;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
enum wined3d_resource_type type;
|
|
|
|
DWORD cube_usage;
|
|
|
|
enum wined3d_gl_resource_type gl_type;
|
|
|
|
}
|
|
|
|
resource_types[] =
|
2015-06-06 17:53:53 +02:00
|
|
|
{
|
2016-01-27 00:06:24 +01:00
|
|
|
{WINED3D_RTYPE_BUFFER, 0, WINED3D_GL_RES_TYPE_BUFFER},
|
2018-04-02 22:58:23 +02:00
|
|
|
{WINED3D_RTYPE_TEXTURE_1D, 0, WINED3D_GL_RES_TYPE_TEX_1D},
|
2016-01-27 00:06:24 +01:00
|
|
|
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_2D},
|
|
|
|
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_TEX_RECT},
|
|
|
|
{WINED3D_RTYPE_TEXTURE_2D, 0, WINED3D_GL_RES_TYPE_RB},
|
|
|
|
{WINED3D_RTYPE_TEXTURE_2D, WINED3DUSAGE_LEGACY_CUBEMAP, WINED3D_GL_RES_TYPE_TEX_CUBE},
|
|
|
|
{WINED3D_RTYPE_TEXTURE_3D, 0, WINED3D_GL_RES_TYPE_TEX_3D},
|
2015-06-06 17:53:53 +02:00
|
|
|
};
|
2013-05-19 23:13:30 +02:00
|
|
|
|
2019-01-31 13:17:23 +01:00
|
|
|
resource_check_usage(usage, access);
|
2013-09-05 09:54:40 +02:00
|
|
|
|
2018-01-31 16:19:36 +01:00
|
|
|
if (usage & WINED3DUSAGE_SCRATCH && access & WINED3D_RESOURCE_ACCESS_GPU)
|
2018-01-29 18:40:23 +01:00
|
|
|
{
|
2018-01-31 16:19:36 +01:00
|
|
|
ERR("Trying to create a scratch resource with access flags %s.\n",
|
|
|
|
wined3d_debug_resource_access(access));
|
2018-01-29 18:40:23 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2018-11-18 19:39:18 +01:00
|
|
|
if (bind_flags & (WINED3D_BIND_RENDER_TARGET | WINED3D_BIND_DEPTH_STENCIL))
|
2018-11-18 19:39:17 +01:00
|
|
|
{
|
2018-11-18 19:39:18 +01:00
|
|
|
if ((access & (WINED3D_RESOURCE_ACCESS_CPU | WINED3D_RESOURCE_ACCESS_GPU)) != WINED3D_RESOURCE_ACCESS_GPU)
|
|
|
|
{
|
|
|
|
WARN("Bind flags %s are incompatible with resource access %s.\n",
|
|
|
|
wined3d_debug_bind_flags(bind_flags), wined3d_debug_resource_access(access));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dynamic usage is incompatible with GPU writes. */
|
|
|
|
if (usage & WINED3DUSAGE_DYNAMIC)
|
|
|
|
{
|
|
|
|
WARN("Bind flags %s are incompatible with resource usage %s.\n",
|
|
|
|
wined3d_debug_bind_flags(bind_flags), debug_d3dusage(usage));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2018-11-18 19:39:17 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 21:39:07 +01:00
|
|
|
if (!size)
|
|
|
|
ERR("Attempting to create a zero-sized resource.\n");
|
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
|
2015-06-06 17:53:53 +02:00
|
|
|
{
|
2016-01-27 00:06:23 +01:00
|
|
|
if (resource_types[i].type != type
|
|
|
|
|| resource_types[i].cube_usage != (usage & WINED3DUSAGE_LEGACY_CUBEMAP))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gl_type = resource_types[i].gl_type;
|
|
|
|
if (base_type == WINED3D_GL_RES_TYPE_COUNT)
|
|
|
|
base_type = gl_type;
|
2015-06-06 17:53:53 +02:00
|
|
|
|
2018-10-31 10:31:51 +01:00
|
|
|
if (type != WINED3D_RTYPE_BUFFER)
|
2015-06-06 17:53:53 +02:00
|
|
|
{
|
2018-10-31 10:31:51 +01:00
|
|
|
if ((bind_flags & WINED3D_BIND_RENDER_TARGET)
|
|
|
|
&& !(format->flags[gl_type] & WINED3DFMT_FLAG_RENDERTARGET))
|
|
|
|
{
|
|
|
|
WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((bind_flags & WINED3D_BIND_DEPTH_STENCIL)
|
2020-06-05 13:49:28 +02:00
|
|
|
&& !(format->flags[gl_type] & WINED3DFMT_FLAG_DEPTH_STENCIL))
|
2018-10-31 10:31:51 +01:00
|
|
|
{
|
|
|
|
WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((bind_flags & WINED3D_BIND_SHADER_RESOURCE)
|
|
|
|
&& !(format->flags[gl_type] & WINED3DFMT_FLAG_TEXTURE))
|
|
|
|
{
|
|
|
|
WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-27 00:06:23 +01:00
|
|
|
}
|
|
|
|
if (((width & (width - 1)) || (height & (height - 1)))
|
2018-09-18 00:31:20 +02:00
|
|
|
&& !d3d_info->texture_npot
|
2016-01-27 00:06:23 +01:00
|
|
|
&& !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]
|
|
|
|
&& gl_type == WINED3D_GL_RES_TYPE_TEX_2D)
|
|
|
|
{
|
|
|
|
TRACE("Skipping 2D texture type to try texture rectangle.\n");
|
|
|
|
tex_2d_ok = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-06 17:53:53 +02:00
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
if (base_type != WINED3D_GL_RES_TYPE_COUNT && i == ARRAY_SIZE(resource_types))
|
|
|
|
{
|
|
|
|
if (tex_2d_ok)
|
2015-06-06 17:53:53 +02:00
|
|
|
{
|
2016-01-27 00:06:23 +01:00
|
|
|
/* Non power of 2 texture and rectangle textures or renderbuffers do not work.
|
|
|
|
* Use 2D textures, the texture code will pad to a power of 2 size. */
|
|
|
|
gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
|
|
|
|
}
|
2018-01-29 18:40:23 +01:00
|
|
|
else if (usage & WINED3DUSAGE_SCRATCH)
|
2016-01-27 00:06:23 +01:00
|
|
|
{
|
|
|
|
/* Needed for proper format information. */
|
|
|
|
gl_type = base_type;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Did not find a suitable GL resource type for resource type %s.\n",
|
|
|
|
debug_d3dresourcetype(type));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2015-06-06 17:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base_type != WINED3D_GL_RES_TYPE_COUNT
|
|
|
|
&& (format->flags[base_type] & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BLOCKS_NO_VERIFY))
|
|
|
|
== WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
{
|
|
|
|
UINT width_mask = format->block_width - 1;
|
|
|
|
UINT height_mask = format->block_height - 1;
|
|
|
|
if (width & width_mask || height & height_mask)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-04-24 10:33:47 +02:00
|
|
|
resource->gl_type = gl_type;
|
2011-03-01 09:47:56 +01:00
|
|
|
resource->format = format;
|
2015-06-06 17:53:51 +02:00
|
|
|
if (gl_type < WINED3D_GL_RES_TYPE_COUNT)
|
|
|
|
resource->format_flags = format->flags[gl_type];
|
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;
|
2018-10-30 10:48:47 +01:00
|
|
|
resource->bind_flags = bind_flags;
|
2018-11-18 19:39:16 +01:00
|
|
|
if (resource->format_flags & WINED3DFMT_FLAG_MAPPABLE)
|
|
|
|
access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
2018-01-31 16:19:36 +01:00
|
|
|
resource->access = access;
|
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;
|
2014-08-26 10:35:48 +02:00
|
|
|
resource->map_binding = WINED3D_LOCATION_SYSMEM;
|
2018-04-10 12:29:55 +02:00
|
|
|
resource->heap_memory = NULL;
|
2009-01-13 10:31:57 +01:00
|
|
|
|
2017-04-13 00:10:59 +02:00
|
|
|
if (!(usage & WINED3DUSAGE_PRIVATE))
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
2017-04-13 00:10:59 +02:00
|
|
|
/* Check that we have enough video ram left */
|
2018-01-31 16:19:36 +01:00
|
|
|
if (!(access & WINED3D_RESOURCE_ACCESS_CPU) && device->wined3d->flags & WINED3D_VIDMEM_ACCOUNTING)
|
2009-01-13 10:31:57 +01:00
|
|
|
{
|
2017-04-13 00:10:59 +02:00
|
|
|
if (size > wined3d_device_get_available_texture_mem(device))
|
|
|
|
{
|
2018-04-10 12:29:55 +02:00
|
|
|
ERR("Out of adapter memory.\n");
|
2017-04-13 00:10:59 +02:00
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
adapter_adjust_memory(device->adapter, size);
|
2009-01-13 10:31:57 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 00:10:59 +02: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;
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:59:01 +02:00
|
|
|
static void wined3d_resource_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
struct wined3d_resource *resource = object;
|
|
|
|
|
|
|
|
wined3d_resource_free_sysmem(resource);
|
2018-03-22 10:52:44 +01:00
|
|
|
context_resource_released(resource->device, resource);
|
2016-07-08 10:59:05 +02:00
|
|
|
wined3d_resource_release(resource);
|
2016-07-08 10:59:01 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2007-05-11 00:09:35 +02:00
|
|
|
|
2011-01-06 09:39:00 +01:00
|
|
|
TRACE("Cleaning up resource %p.\n", resource);
|
|
|
|
|
2017-04-13 00:10:59 +02:00
|
|
|
if (!(resource->usage & WINED3DUSAGE_PRIVATE))
|
2011-01-06 09:39:00 +01:00
|
|
|
{
|
2018-01-31 16:19:37 +01:00
|
|
|
if (!(resource->access & WINED3D_RESOURCE_ACCESS_CPU) && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
|
2017-04-13 00:10:59 +02:00
|
|
|
{
|
|
|
|
TRACE("Decrementing device memory pool by %u.\n", resource->size);
|
|
|
|
adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
|
|
|
|
}
|
2005-03-29 21:01:00 +02:00
|
|
|
|
2017-04-13 00:10:59 +02:00
|
|
|
device_resource_released(resource->device, resource);
|
|
|
|
}
|
2016-07-08 10:59:05 +02:00
|
|
|
wined3d_resource_acquire(resource);
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(resource->device->cs, wined3d_resource_destroy_object, 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);
|
2010-08-15 23:21:42 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 14:39:14 +02:00
|
|
|
DWORD CDECL wined3d_resource_set_priority(struct wined3d_resource *resource, DWORD priority)
|
2008-12-02 18:41:33 +01:00
|
|
|
{
|
2014-07-08 15:58:43 +02:00
|
|
|
DWORD prev;
|
|
|
|
|
2018-01-31 16:19:38 +01:00
|
|
|
if (!wined3d_resource_access_is_managed(resource->access))
|
2014-07-08 15:58:43 +02:00
|
|
|
{
|
|
|
|
WARN("Called on non-managed resource %p, ignoring.\n", resource);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = resource->priority;
|
2011-03-01 09:47:56 +01:00
|
|
|
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
|
|
|
|
2014-07-16 14:39:14 +02:00
|
|
|
DWORD CDECL wined3d_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
|
|
|
|
2013-12-05 10:34:17 +01:00
|
|
|
void CDECL wined3d_resource_set_parent(struct wined3d_resource *resource, void *parent)
|
|
|
|
{
|
|
|
|
resource->parent = parent;
|
|
|
|
}
|
|
|
|
|
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;
|
2018-10-31 10:31:47 +01:00
|
|
|
desc->bind_flags = resource->bind_flags;
|
2018-02-02 17:58:54 +01:00
|
|
|
desc->access = resource->access;
|
2011-03-09 19:16:15 +01:00
|
|
|
desc->width = resource->width;
|
|
|
|
desc->height = resource->height;
|
|
|
|
desc->depth = resource->depth;
|
|
|
|
desc->size = resource->size;
|
|
|
|
}
|
2013-08-21 15:15:48 +02:00
|
|
|
|
2016-09-01 20:34:48 +02:00
|
|
|
static DWORD wined3d_resource_sanitise_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. */
|
2018-02-18 19:08:34 +01:00
|
|
|
if (flags & WINED3D_MAP_READ)
|
2016-09-01 20:34:48 +02:00
|
|
|
{
|
|
|
|
if (flags & WINED3D_MAP_DISCARD)
|
|
|
|
{
|
2018-02-18 19:08:34 +01:00
|
|
|
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
|
|
|
|
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
|
2016-09-01 20:34:48 +02:00
|
|
|
}
|
|
|
|
if (flags & WINED3D_MAP_NOOVERWRITE)
|
|
|
|
{
|
2018-02-18 19:08:34 +01:00
|
|
|
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
|
|
|
|
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
|
2016-09-01 20:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 16:06:55 +01:00
|
|
|
else if (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
2016-09-01 20:34:48 +02:00
|
|
|
{
|
2018-01-03 16:06:55 +01:00
|
|
|
if (!(resource->usage & WINED3DUSAGE_DYNAMIC))
|
|
|
|
{
|
|
|
|
WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
|
2018-02-18 19:08:34 +01:00
|
|
|
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
|
2018-01-03 16:06:55 +01:00
|
|
|
}
|
|
|
|
if ((flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
|
|
|
== (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
|
|
|
|
{
|
|
|
|
WARN("WINED3D_MAP_NOOVERWRITE used with WINED3D_MAP_DISCARD, ignoring WINED3D_MAP_DISCARD.\n");
|
|
|
|
flags &= ~WINED3D_MAP_DISCARD;
|
|
|
|
}
|
2016-09-01 20:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:12:25 +01:00
|
|
|
HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
|
|
|
|
{
|
2016-02-03 22:23:00 +01:00
|
|
|
TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
|
|
|
|
resource, sub_resource_idx, map_desc, debug_box(box), flags);
|
2015-11-02 17:12:25 +01:00
|
|
|
|
2018-02-18 19:08:34 +01:00
|
|
|
if (!(flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
|
|
|
|
{
|
|
|
|
WARN("No read/write flags specified.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-02-18 19:08:35 +01:00
|
|
|
if ((flags & WINED3D_MAP_READ) && !(resource->access & WINED3D_RESOURCE_ACCESS_MAP_R))
|
2018-02-14 07:39:55 +01:00
|
|
|
{
|
2018-02-18 19:08:35 +01:00
|
|
|
WARN("Resource does not have MAP_R access.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & WINED3D_MAP_WRITE) && !(resource->access & WINED3D_RESOURCE_ACCESS_MAP_W))
|
|
|
|
{
|
|
|
|
WARN("Resource does not have MAP_W access.\n");
|
2018-02-16 07:09:04 +01:00
|
|
|
return E_INVALIDARG;
|
2018-02-14 07:39:55 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 20:34:48 +02:00
|
|
|
flags = wined3d_resource_sanitise_map_flags(resource, flags);
|
2017-05-21 17:53:42 +02:00
|
|
|
wined3d_resource_wait_idle(resource);
|
2016-09-01 20:34:48 +02:00
|
|
|
|
2016-09-01 20:34:46 +02:00
|
|
|
return wined3d_cs_map(resource->device->cs, resource, sub_resource_idx, map_desc, box, flags);
|
2015-11-02 17:12:25 +01:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:12:26 +01:00
|
|
|
HRESULT CDECL wined3d_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
|
|
|
|
{
|
|
|
|
TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
|
|
|
|
|
2016-09-01 20:34:47 +02:00
|
|
|
return wined3d_cs_unmap(resource->device->cs, resource, sub_resource_idx);
|
2015-11-02 17:12:26 +01:00
|
|
|
}
|
|
|
|
|
2016-08-10 18:44:48 +02:00
|
|
|
void CDECL wined3d_resource_preload(struct wined3d_resource *resource)
|
|
|
|
{
|
2016-08-26 13:51:18 +02:00
|
|
|
wined3d_cs_emit_preload_resource(resource->device->cs, resource);
|
2016-08-10 18:44:48 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 23:01:35 +02:00
|
|
|
static 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;
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(mem = heap_alloc_zero(resource->size + align)))
|
2018-04-10 12:29:55 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate system memory.\n");
|
2013-09-16 10:57:24 +02:00
|
|
|
return FALSE;
|
2018-04-10 12:29:55 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-08-15 23:01:35 +02:00
|
|
|
BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
if (resource->heap_memory)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return wined3d_resource_allocate_sysmem(resource);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(*(--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
|
|
|
|
|
|
|
GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags)
|
|
|
|
{
|
|
|
|
GLbitfield ret = 0;
|
|
|
|
|
2018-02-18 19:08:34 +01:00
|
|
|
if (d3d_flags & WINED3D_MAP_WRITE)
|
2013-08-26 02:01:28 +02:00
|
|
|
ret |= GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
|
2018-02-18 19:08:34 +01:00
|
|
|
if (d3d_flags & WINED3D_MAP_READ)
|
2013-08-26 02:01:28 +02:00
|
|
|
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)
|
|
|
|
{
|
2018-02-18 19:08:34 +01:00
|
|
|
switch (d3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE))
|
|
|
|
{
|
|
|
|
case WINED3D_MAP_READ:
|
|
|
|
return GL_READ_ONLY_ARB;
|
|
|
|
|
|
|
|
case WINED3D_MAP_WRITE:
|
|
|
|
return GL_WRITE_ONLY_ARB;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return GL_READ_WRITE_ARB;
|
|
|
|
}
|
2013-09-19 11:02:55 +02:00
|
|
|
}
|
2014-08-19 09:22:29 +02:00
|
|
|
|
|
|
|
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
struct wined3d_swapchain *swapchain;
|
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
/* Only 2D texture resources can be onscreen. */
|
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
2014-08-19 09:22:29 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Not on a swapchain - must be offscreen */
|
2016-04-20 19:29:13 +02:00
|
|
|
if (!(swapchain = texture_from_resource(resource)->swapchain))
|
2014-08-19 09:22:29 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* The front buffer is always onscreen */
|
2014-08-20 13:20:02 +02:00
|
|
|
if (resource == &swapchain->front_buffer->resource)
|
2014-08-19 09:22:29 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If the swapchain is rendered to an FBO, the backbuffer is
|
|
|
|
* offscreen, otherwise onscreen */
|
|
|
|
return swapchain->render_to_fbo;
|
|
|
|
}
|
2014-08-20 13:19:59 +02:00
|
|
|
|
|
|
|
void wined3d_resource_update_draw_binding(struct wined3d_resource *resource)
|
|
|
|
{
|
2019-03-03 19:55:22 +01:00
|
|
|
const struct wined3d_d3d_info *d3d_info = &resource->device->adapter->d3d_info;
|
|
|
|
|
2014-08-20 13:19:59 +02:00
|
|
|
if (!wined3d_resource_is_offscreen(resource) || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
|
2018-02-09 13:03:23 +01:00
|
|
|
{
|
2014-08-20 13:19:59 +02:00
|
|
|
resource->draw_binding = WINED3D_LOCATION_DRAWABLE;
|
2018-02-09 13:03:23 +01:00
|
|
|
}
|
2014-08-20 13:19:59 +02:00
|
|
|
else if (resource->multisample_type)
|
2018-02-09 13:03:23 +01:00
|
|
|
{
|
2019-03-03 19:55:22 +01:00
|
|
|
resource->draw_binding = d3d_info->multisample_draw_location;
|
2018-02-09 13:03:23 +01:00
|
|
|
}
|
2015-06-09 09:28:06 +02:00
|
|
|
else if (resource->gl_type == WINED3D_GL_RES_TYPE_RB)
|
2018-02-09 13:03:23 +01:00
|
|
|
{
|
2015-06-09 09:28:06 +02:00
|
|
|
resource->draw_binding = WINED3D_LOCATION_RB_RESOLVED;
|
2018-02-09 13:03:23 +01:00
|
|
|
}
|
2014-08-20 13:19:59 +02:00
|
|
|
else
|
2018-02-09 13:03:23 +01:00
|
|
|
{
|
2014-08-20 13:19:59 +02:00
|
|
|
resource->draw_binding = WINED3D_LOCATION_TEXTURE_RGB;
|
2018-02-09 13:03:23 +01:00
|
|
|
}
|
2014-08-20 13:19:59 +02:00
|
|
|
}
|
2018-08-06 23:04:58 +02:00
|
|
|
|
2018-09-14 21:30:59 +02:00
|
|
|
const struct wined3d_format *wined3d_resource_get_decompress_format(const struct wined3d_resource *resource)
|
2018-08-06 23:04:58 +02:00
|
|
|
{
|
2018-08-23 14:34:03 +02:00
|
|
|
const struct wined3d_adapter *adapter = resource->device->adapter;
|
2018-08-06 23:04:58 +02:00
|
|
|
if (resource->format_flags & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE)
|
2018-08-23 14:34:03 +02:00
|
|
|
&& !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
|
2018-10-31 10:31:50 +01:00
|
|
|
return wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM_SRGB, resource->bind_flags);
|
|
|
|
return wined3d_get_format(adapter, WINED3DFMT_B8G8R8A8_UNORM, resource->bind_flags);
|
2018-08-06 23:04:58 +02:00
|
|
|
}
|
2019-03-03 19:55:23 +01:00
|
|
|
|
|
|
|
unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = resource->format;
|
|
|
|
|
|
|
|
/* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
|
|
|
|
* feature through type == MULTISAMPLE_XX and quality != 0. This could
|
|
|
|
* be mapped to GL_NV_framebuffer_multisample_coverage.
|
|
|
|
*
|
|
|
|
* AMD have a similar feature called Enhanced Quality Anti-Aliasing
|
|
|
|
* (EQAA), but it does not have an equivalent OpenGL extension. */
|
|
|
|
|
|
|
|
/* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
|
|
|
|
* levels as the count of advertised multisample types for the texture
|
|
|
|
* format. */
|
|
|
|
if (resource->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
|
|
|
|
{
|
|
|
|
unsigned int i, count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(format->multisample_types) * CHAR_BIT; ++i)
|
|
|
|
{
|
|
|
|
if (format->multisample_types & 1u << i)
|
|
|
|
{
|
|
|
|
if (resource->multisample_quality == count++)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resource->multisample_type;
|
|
|
|
}
|
2020-01-24 17:02:07 +01:00
|
|
|
|
|
|
|
VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags)
|
|
|
|
{
|
|
|
|
VkAccessFlags flags = 0;
|
|
|
|
|
|
|
|
if (bind_flags & WINED3D_BIND_VERTEX_BUFFER)
|
|
|
|
flags |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
|
|
|
|
flags |= VK_ACCESS_INDEX_READ_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
|
|
|
|
flags |= VK_ACCESS_UNIFORM_READ_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_SHADER_RESOURCE)
|
|
|
|
flags |= VK_ACCESS_SHADER_READ_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
|
|
|
|
flags |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
|
|
|
|
flags |= VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_RENDER_TARGET)
|
|
|
|
flags |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
|
|
|
|
flags |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
|
|
if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
|
|
|
|
FIXME("Ignoring some bind flags %#x.\n", bind_flags);
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|