wined3d: Merge common code between texture3d_load_location() and surface_load_location().
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
87f98ee88b
commit
25188eb71f
|
@ -2492,28 +2492,6 @@ static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RE
|
||||||
return WINED3DERR_INVALIDCALL;
|
return WINED3DERR_INVALIDCALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD resource_access_from_location(DWORD location)
|
|
||||||
{
|
|
||||||
switch (location)
|
|
||||||
{
|
|
||||||
case WINED3D_LOCATION_SYSMEM:
|
|
||||||
case WINED3D_LOCATION_USER_MEMORY:
|
|
||||||
case WINED3D_LOCATION_BUFFER:
|
|
||||||
return WINED3D_RESOURCE_ACCESS_CPU;
|
|
||||||
|
|
||||||
case WINED3D_LOCATION_DRAWABLE:
|
|
||||||
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
||||||
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
||||||
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
|
||||||
case WINED3D_LOCATION_RB_RESOLVED:
|
|
||||||
return WINED3D_RESOURCE_ACCESS_GPU;
|
|
||||||
|
|
||||||
default:
|
|
||||||
FIXME("Unhandled location %#x.\n", location);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void surface_copy_simple_location(struct wined3d_surface *surface, DWORD location)
|
static void surface_copy_simple_location(struct wined3d_surface *surface, DWORD location)
|
||||||
{
|
{
|
||||||
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
||||||
|
@ -2814,46 +2792,15 @@ HRESULT surface_load_location(struct wined3d_surface *surface, struct wined3d_co
|
||||||
{
|
{
|
||||||
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
|
||||||
struct wined3d_texture *texture = surface->container;
|
struct wined3d_texture *texture = surface->container;
|
||||||
struct wined3d_texture_sub_resource *sub_resource;
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
TRACE("surface %p, location %s.\n", surface, wined3d_debug_location(location));
|
TRACE("surface %p, location %s.\n", surface, wined3d_debug_location(location));
|
||||||
|
|
||||||
sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
||||||
if (sub_resource->locations & location)
|
|
||||||
{
|
|
||||||
TRACE("Location (%#x) is already up to date.\n", location);
|
|
||||||
return WINED3D_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WARN_ON(d3d))
|
|
||||||
{
|
|
||||||
DWORD required_access = resource_access_from_location(location);
|
|
||||||
if ((texture->resource.access_flags & required_access) != required_access)
|
|
||||||
WARN("Operation requires %#x access, but surface only has %#x.\n",
|
|
||||||
required_access, texture->resource.access_flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
|
||||||
{
|
|
||||||
TRACE("Surface previously discarded, nothing to do.\n");
|
|
||||||
wined3d_texture_prepare_location(texture, sub_resource_idx, context, location);
|
|
||||||
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
||||||
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sub_resource->locations)
|
|
||||||
{
|
|
||||||
ERR("Surface %p does not have any up to date location.\n", surface);
|
|
||||||
wined3d_texture_validate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
|
||||||
return surface_load_location(surface, context, location);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
if (texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
||||||
{
|
{
|
||||||
|
DWORD current = texture->sub_resources[sub_resource_idx].locations;
|
||||||
FIXME("Unimplemented copy from %s to %s for depth/stencil buffers.\n",
|
FIXME("Unimplemented copy from %s to %s for depth/stencil buffers.\n",
|
||||||
wined3d_debug_location(sub_resource->locations), wined3d_debug_location(location));
|
wined3d_debug_location(current), wined3d_debug_location(location));
|
||||||
return WINED3DERR_INVALIDCALL;
|
return WINED3DERR_INVALIDCALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2887,9 +2834,6 @@ HRESULT surface_load_location(struct wined3d_surface *surface, struct wined3d_co
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
||||||
|
|
||||||
return WINED3D_OK;
|
return WINED3D_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,11 +88,15 @@ static DWORD wined3d_resource_access_from_location(DWORD location)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WINED3D_LOCATION_SYSMEM:
|
case WINED3D_LOCATION_SYSMEM:
|
||||||
|
case WINED3D_LOCATION_USER_MEMORY:
|
||||||
return WINED3D_RESOURCE_ACCESS_CPU;
|
return WINED3D_RESOURCE_ACCESS_CPU;
|
||||||
|
|
||||||
case WINED3D_LOCATION_BUFFER:
|
case WINED3D_LOCATION_BUFFER:
|
||||||
|
case WINED3D_LOCATION_DRAWABLE:
|
||||||
case WINED3D_LOCATION_TEXTURE_RGB:
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
||||||
case WINED3D_LOCATION_TEXTURE_SRGB:
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
||||||
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
||||||
|
case WINED3D_LOCATION_RB_RESOLVED:
|
||||||
return WINED3D_RESOURCE_ACCESS_GPU;
|
return WINED3D_RESOURCE_ACCESS_GPU;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -179,7 +183,50 @@ void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
|
||||||
BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
|
BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
|
||||||
unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
|
unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
|
||||||
{
|
{
|
||||||
return texture->texture_ops->texture_load_location(texture, sub_resource_idx, context, location);
|
DWORD current = texture->sub_resources[sub_resource_idx].locations;
|
||||||
|
BOOL ret;
|
||||||
|
|
||||||
|
TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
|
||||||
|
texture, sub_resource_idx, context, wined3d_debug_location(location));
|
||||||
|
|
||||||
|
TRACE("Current resource location %s.\n", wined3d_debug_location(current));
|
||||||
|
|
||||||
|
if (current & location)
|
||||||
|
{
|
||||||
|
TRACE("Location %s is already up to date.\n", wined3d_debug_location(location));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WARN_ON(d3d))
|
||||||
|
{
|
||||||
|
DWORD required_access = wined3d_resource_access_from_location(location);
|
||||||
|
if ((texture->resource.access_flags & required_access) != required_access)
|
||||||
|
WARN("Operation requires %#x access, but texture only has %#x.\n",
|
||||||
|
required_access, texture->resource.access_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current & WINED3D_LOCATION_DISCARDED)
|
||||||
|
{
|
||||||
|
TRACE("Sub-resource previously discarded, nothing to do.\n");
|
||||||
|
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
|
||||||
|
return FALSE;
|
||||||
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
||||||
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!current)
|
||||||
|
{
|
||||||
|
ERR("Sub-resource %u of texture %p does not have any up to date location.\n",
|
||||||
|
sub_resource_idx, texture);
|
||||||
|
wined3d_texture_validate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
||||||
|
return wined3d_texture_load_location(texture, sub_resource_idx, context, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret = texture->texture_ops->texture_load_location(texture, sub_resource_idx, context, location)))
|
||||||
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Context activation is done by the caller. */
|
/* Context activation is done by the caller. */
|
||||||
|
@ -2253,38 +2300,11 @@ static BOOL texture3d_load_location(struct wined3d_texture *texture, unsigned in
|
||||||
struct wined3d_context *context, DWORD location)
|
struct wined3d_context *context, DWORD location)
|
||||||
{
|
{
|
||||||
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
|
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
|
||||||
DWORD required_access = wined3d_resource_access_from_location(location);
|
|
||||||
unsigned int row_pitch, slice_pitch;
|
unsigned int row_pitch, slice_pitch;
|
||||||
|
|
||||||
TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
|
|
||||||
texture, sub_resource_idx, context, wined3d_debug_location(location));
|
|
||||||
|
|
||||||
TRACE("Current resource location %s.\n", wined3d_debug_location(sub_resource->locations));
|
|
||||||
|
|
||||||
if ((sub_resource->locations & location) == location)
|
|
||||||
{
|
|
||||||
TRACE("Location(s) already up to date.\n");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((texture->resource.access_flags & required_access) != required_access)
|
|
||||||
{
|
|
||||||
ERR("Operation requires %#x access, but volume only has %#x.\n",
|
|
||||||
required_access, texture->resource.access_flags);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
|
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
|
||||||
{
|
|
||||||
TRACE("Volume previously discarded, nothing to do.\n");
|
|
||||||
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
||||||
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (location)
|
switch (location)
|
||||||
{
|
{
|
||||||
case WINED3D_LOCATION_TEXTURE_RGB:
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
||||||
|
@ -2369,9 +2389,6 @@ static BOOL texture3d_load_location(struct wined3d_texture *texture, unsigned in
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue