wined3d: Keep track of the download count in the texture.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2016-03-09 16:21:53 +01:00 committed by Alexandre Julliard
parent 9da6dd2ac9
commit bc24fbf6d6
3 changed files with 17 additions and 34 deletions

View File

@ -507,11 +507,10 @@ static void surface_prepare_system_memory(struct wined3d_surface *surface)
static void surface_evict_sysmem(struct wined3d_surface *surface) static void surface_evict_sysmem(struct wined3d_surface *surface)
{ {
/* In some conditions the surface memory must not be freed: struct wined3d_texture *texture = surface->container;
* WINED3D_TEXTURE_CONVERTED: Converting the data back would take too long
* WINED3D_TEXTURE_DYNAMIC_MAP: Avoid freeing the data for performance */ if (surface->resource.map_count || texture->download_count > MAXLOCKCOUNT
if (surface->resource.map_count || surface->container->flags & (WINED3D_TEXTURE_CONVERTED || texture->flags & (WINED3D_TEXTURE_CONVERTED | WINED3D_TEXTURE_PIN_SYSMEM))
| WINED3D_TEXTURE_PIN_SYSMEM | WINED3D_TEXTURE_DYNAMIC_MAP))
return; return;
wined3d_resource_free_sysmem(&surface->resource); wined3d_resource_free_sysmem(&surface->resource);
@ -1259,11 +1258,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
* standard texture with a non-power2 width instead of a texture boxed up to be a power2 texture. * standard texture with a non-power2 width instead of a texture boxed up to be a power2 texture.
* *
* internally the texture is still stored in a boxed format so any references to textureName will * internally the texture is still stored in a boxed format so any references to textureName will
* get a boxed texture with width pow2width and not a texture of width resource.width. * get a boxed texture with width pow2width and not a texture of width resource.width. */
*
* Performance should not be an issue, because applications normally do not lock the surfaces when
* rendering. If an app does, the WINED3D_TEXTURE_DYNAMIC_MAP flag will kick in and the memory copy
* won't be released, and doesn't have to be re-read. */
src_data = mem; src_data = mem;
dst_data = data.addr; dst_data = data.addr;
TRACE("Repacking the surface data from pitch %u to pitch %u.\n", src_row_pitch, dst_row_pitch); TRACE("Repacking the surface data from pitch %u to pitch %u.\n", src_row_pitch, dst_row_pitch);
@ -2169,21 +2164,6 @@ HRESULT wined3d_surface_map(struct wined3d_surface *surface, struct wined3d_map_
if (!(surface->resource.access_flags & WINED3D_RESOURCE_ACCESS_CPU)) if (!(surface->resource.access_flags & WINED3D_RESOURCE_ACCESS_CPU))
WARN("Trying to lock unlockable surface.\n"); WARN("Trying to lock unlockable surface.\n");
/* Performance optimization: Count how often a surface is mapped, if it is
* mapped regularly do not throw away the system memory copy. This avoids
* the need to download the surface from OpenGL all the time. The surface
* is still downloaded if the OpenGL texture is changed. Note that this
* only really makes sense for managed textures.*/
if (!(texture->flags & WINED3D_TEXTURE_DYNAMIC_MAP)
&& surface->resource.map_binding == WINED3D_LOCATION_SYSMEM)
{
if (++surface->lockCount > MAXLOCKCOUNT)
{
TRACE("Surface is mapped regularly, not freeing the system memory copy any more.\n");
texture->flags |= WINED3D_TEXTURE_DYNAMIC_MAP;
}
}
flags = wined3d_resource_sanitize_map_flags(&texture->resource, flags); flags = wined3d_resource_sanitize_map_flags(&texture->resource, flags);
if (device->d3d_initialized) if (device->d3d_initialized)
@ -3475,9 +3455,12 @@ static void surface_load_sysmem(struct wined3d_surface *surface,
/* Download the surface to system memory. */ /* Download the surface to system memory. */
if (surface->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB)) if (surface->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
{ {
wined3d_texture_bind_and_dirtify(surface->container, context, struct wined3d_texture *texture = surface->container;
wined3d_texture_bind_and_dirtify(texture, context,
!(surface->locations & WINED3D_LOCATION_TEXTURE_RGB)); !(surface->locations & WINED3D_LOCATION_TEXTURE_RGB));
surface_download_data(surface, gl_info, dst_location); surface_download_data(surface, gl_info, dst_location);
++texture->download_count;
return; return;
} }

View File

@ -234,11 +234,13 @@ static void wined3d_volume_srgb_transfer(struct wined3d_volume *volume,
static BOOL wined3d_volume_can_evict(const struct wined3d_volume *volume) static BOOL wined3d_volume_can_evict(const struct wined3d_volume *volume)
{ {
if (volume->resource.pool != WINED3D_POOL_MANAGED) struct wined3d_texture *texture = volume->container;
if (texture->resource.pool != WINED3D_POOL_MANAGED)
return FALSE; return FALSE;
if (volume->download_count >= 10) if (texture->download_count >= 10)
return FALSE; return FALSE;
if (volume->resource.format->convert) if (texture->resource.format->convert)
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -324,8 +326,8 @@ static BOOL wined3d_volume_load_location(struct wined3d_volume *volume,
else else
wined3d_texture_bind_and_dirtify(texture, context, TRUE); wined3d_texture_bind_and_dirtify(texture, context, TRUE);
volume->download_count++;
wined3d_volume_download_data(volume, context, &data); wined3d_volume_download_data(volume, context, &data);
++texture->download_count;
} }
else else
{ {

View File

@ -2352,8 +2352,7 @@ struct wined3d_texture_ops
#define WINED3D_TEXTURE_SRGB_VALID 0x00000080 #define WINED3D_TEXTURE_SRGB_VALID 0x00000080
#define WINED3D_TEXTURE_CONVERTED 0x00000100 #define WINED3D_TEXTURE_CONVERTED 0x00000100
#define WINED3D_TEXTURE_PIN_SYSMEM 0x00000200 #define WINED3D_TEXTURE_PIN_SYSMEM 0x00000200
#define WINED3D_TEXTURE_DYNAMIC_MAP 0x00000400 #define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
#define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000800
#define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001 #define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001
@ -2365,6 +2364,7 @@ struct wined3d_texture
struct wined3d_swapchain *swapchain; struct wined3d_swapchain *swapchain;
UINT layer_count; UINT layer_count;
UINT level_count; UINT level_count;
unsigned int download_count;
float pow2_matrix[16]; float pow2_matrix[16];
UINT lod; UINT lod;
enum wined3d_texture_filter_type filter_type; enum wined3d_texture_filter_type filter_type;
@ -2457,7 +2457,6 @@ struct wined3d_volume
DWORD locations; DWORD locations;
GLint texture_level; GLint texture_level;
DWORD download_count;
}; };
static inline struct wined3d_volume *volume_from_resource(struct wined3d_resource *resource) static inline struct wined3d_volume *volume_from_resource(struct wined3d_resource *resource)
@ -2537,7 +2536,6 @@ struct wined3d_surface
GLenum texture_target; GLenum texture_target;
unsigned int texture_level; unsigned int texture_level;
unsigned int texture_layer; unsigned int texture_layer;
int lockCount;
/* For GetDC */ /* For GetDC */
struct wined3d_surface_dib dib; struct wined3d_surface_dib dib;