wined3d: Introduce wined3d_device_context_map().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-04-12 22:46:30 -05:00 committed by Alexandre Julliard
parent 2fd3ec79cd
commit cfd25180ba
4 changed files with 71 additions and 57 deletions

View File

@ -5250,6 +5250,72 @@ void CDECL wined3d_device_context_clear_uav_uint(struct wined3d_device_context *
wined3d_device_context_emit_clear_uav_uint(context, view, clear_value);
}
static unsigned int sanitise_map_flags(const struct wined3d_resource *resource, unsigned int flags)
{
/* Not all flags make sense together, but Windows never returns an error.
* Catch the cases that could cause issues. */
if (flags & WINED3D_MAP_READ)
{
if (flags & WINED3D_MAP_DISCARD)
{
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
if (flags & WINED3D_MAP_NOOVERWRITE)
{
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
}
else if (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
{
if (!(resource->usage & WINED3DUSAGE_DYNAMIC))
{
WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
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;
}
}
return flags;
}
HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags)
{
TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
context, resource, sub_resource_idx, map_desc, debug_box(box), flags);
if (!(flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
{
WARN("No read/write flags specified.\n");
return E_INVALIDARG;
}
if ((flags & WINED3D_MAP_READ) && !(resource->access & WINED3D_RESOURCE_ACCESS_MAP_R))
{
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");
return E_INVALIDARG;
}
flags = sanitise_map_flags(resource, flags);
wined3d_resource_wait_idle(resource);
return context->ops->map(context, resource, sub_resource_idx, map_desc, box, flags);
}
struct wined3d_rendertarget_view * CDECL wined3d_device_get_rendertarget_view(const struct wined3d_device *device,
unsigned int view_idx)
{

View File

@ -314,69 +314,13 @@ void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, st
desc->size = resource->size;
}
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. */
if (flags & WINED3D_MAP_READ)
{
if (flags & WINED3D_MAP_DISCARD)
{
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
if (flags & WINED3D_MAP_NOOVERWRITE)
{
WARN("WINED3D_MAP_READ combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
}
else if (flags & (WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE))
{
if (!(resource->usage & WINED3DUSAGE_DYNAMIC))
{
WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
return flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE);
}
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;
}
}
return flags;
}
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)
{
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);
if (!(flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
{
WARN("No read/write flags specified.\n");
return E_INVALIDARG;
}
if ((flags & WINED3D_MAP_READ) && !(resource->access & WINED3D_RESOURCE_ACCESS_MAP_R))
{
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");
return E_INVALIDARG;
}
flags = wined3d_resource_sanitise_map_flags(resource, flags);
wined3d_resource_wait_idle(resource);
return resource->device->cs->c.ops->map(&resource->device->cs->c, resource, sub_resource_idx, map_desc, box, flags);
return wined3d_device_context_map(&resource->device->cs->c, resource, sub_resource_idx, map_desc, box, flags);
}
HRESULT CDECL wined3d_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)

View File

@ -171,6 +171,7 @@
@ cdecl wined3d_device_context_dispatch(ptr long long long)
@ cdecl wined3d_device_context_dispatch_indirect(ptr ptr long)
@ cdecl wined3d_device_context_generate_mipmaps(ptr ptr)
@ cdecl wined3d_device_context_map(ptr ptr long ptr ptr long)
@ cdecl wined3d_device_context_resolve_sub_resource(ptr ptr long ptr long long)
@ cdecl wined3d_device_context_set_blend_state(ptr ptr ptr long)
@ cdecl wined3d_device_context_set_constant_buffer(ptr long long ptr)

View File

@ -2566,6 +2566,9 @@ void __cdecl wined3d_device_context_draw_indirect(struct wined3d_device_context
struct wined3d_buffer *buffer, unsigned int offset, bool indexed);
void __cdecl wined3d_device_context_generate_mipmaps(struct wined3d_device_context *context,
struct wined3d_shader_resource_view *view);
HRESULT __cdecl wined3d_device_context_map(struct wined3d_device_context *context,
struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags);
void __cdecl wined3d_device_context_resolve_sub_resource(struct wined3d_device_context *context,
struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx,
struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, enum wined3d_format_id format_id);