From ee8a5b7dd1e554ef32229c766715f23ba17c9f6c Mon Sep 17 00:00:00 2001 From: Henri Verbeet <hverbeet@codeweavers.com> Date: Wed, 8 Oct 2014 08:47:20 +0200 Subject: [PATCH] wined3d: Track texture allocation per-texture. --- dlls/wined3d/surface.c | 13 +++------- dlls/wined3d/texture.c | 47 +++++++++++++++++++++++++--------- dlls/wined3d/volume.c | 8 +++--- dlls/wined3d/wined3d_private.h | 14 +++++----- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index d02d5f244a4..0967220998f 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -599,11 +599,6 @@ static void surface_evict_sysmem(struct wined3d_surface *surface) surface_invalidate_location(surface, WINED3D_LOCATION_SYSMEM); } -static void surface_force_reload(struct wined3d_surface *surface) -{ - surface->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED); -} - static void surface_release_client_storage(struct wined3d_surface *surface) { struct wined3d_context *context = context_acquire(surface->resource.device, NULL); @@ -621,11 +616,9 @@ static void surface_release_client_storage(struct wined3d_surface *surface) gl_info->gl_ops.gl.p_glTexImage2D(surface->texture_target, surface->texture_level, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } + wined3d_texture_force_reload(surface->container); context_release(context); - - surface_invalidate_location(surface, WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB); - surface_force_reload(surface); } static BOOL surface_use_pbo(const struct wined3d_surface *surface) @@ -1211,7 +1204,7 @@ static void surface_unload(struct wined3d_resource *resource) surface_load_location(surface, surface->resource.map_binding); surface_invalidate_location(surface, ~surface->resource.map_binding); } - surface->flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED); + wined3d_texture_force_reload(surface->container); context = context_acquire(device, NULL); gl_info = context->gl_info; @@ -1845,7 +1838,7 @@ void surface_load(struct wined3d_surface *surface, BOOL srgb) surface_invalidate_location(surface, ~surface->resource.map_binding); /* Switching color keying on / off may change the internal format. */ if (ck_changed) - surface_force_reload(surface); + wined3d_texture_force_reload(surface->container); } else if (!(surface->locations & location)) { diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 27a10c671c0..bc75305f4da 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -751,7 +751,26 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT void wined3d_texture_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) { + DWORD alloc_flag = srgb ? WINED3D_TEXTURE_SRGB_ALLOCATED : WINED3D_TEXTURE_RGB_ALLOCATED; + + if (texture->flags & alloc_flag) + return; + texture->texture_ops->texture_prepare_texture(texture, context, srgb); + texture->flags |= alloc_flag; +} + +void wined3d_texture_force_reload(struct wined3d_texture *texture) +{ + unsigned int sub_count = texture->level_count * texture->layer_count; + unsigned int i; + + texture->flags &= ~(WINED3D_TEXTURE_RGB_ALLOCATED | WINED3D_TEXTURE_SRGB_ALLOCATED); + for (i = 0; i < sub_count; ++i) + { + texture->texture_ops->texture_sub_resource_invalidate_location(texture->sub_resources[i], + WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB); + } } void CDECL wined3d_texture_generate_mipmaps(struct wined3d_texture *texture) @@ -817,11 +836,17 @@ static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource wined3d_surface_destroy(surface); } +static void texture2d_sub_resource_invalidate_location(struct wined3d_resource *sub_resource, DWORD location) +{ + struct wined3d_surface *surface = surface_from_resource(sub_resource); + + surface_invalidate_location(surface, location); +} + /* Context activation is done by the caller. */ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) { UINT sub_count = texture->level_count * texture->layer_count; - DWORD alloc_flag = srgb ? SFLAG_SRGBALLOCATED : SFLAG_ALLOCATED; const struct wined3d_format *format = texture->resource.format; const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_color_key_conversion *conversion; @@ -864,9 +889,6 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi GLsizei width = surface->pow2Width; const BYTE *mem = NULL; - if (surface->flags & alloc_flag) - continue; - if (converted) surface->flags |= SFLAG_CONVERTED; else @@ -922,8 +944,6 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); } - - surface->flags |= alloc_flag; } } @@ -932,6 +952,7 @@ static const struct wined3d_texture_ops texture2d_ops = texture2d_sub_resource_load, texture2d_sub_resource_add_dirty_region, texture2d_sub_resource_cleanup, + texture2d_sub_resource_invalidate_location, texture2d_prepare_texture, }; @@ -1261,9 +1282,15 @@ static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource wined3d_volume_destroy(volume); } +static void texture3d_sub_resource_invalidate_location(struct wined3d_resource *sub_resource, DWORD location) +{ + struct wined3d_volume *volume = volume_from_resource(sub_resource); + + wined3d_volume_invalidate_location(volume, location); +} + static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) { - DWORD alloc_flag = srgb ? WINED3D_VFLAG_SRGB_ALLOCATED : WINED3D_VFLAG_ALLOCATED; unsigned int sub_count = texture->level_count * texture->layer_count; const struct wined3d_format *format = texture->resource.format; const struct wined3d_gl_info *gl_info = context->gl_info; @@ -1276,9 +1303,6 @@ static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wi struct wined3d_volume *volume = volume_from_resource(texture->sub_resources[i]); void *mem = NULL; - if (volume->flags & alloc_flag) - continue; - if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert && volume_prepare_system_memory(volume)) { @@ -1300,8 +1324,6 @@ static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wi gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)"); } - - volume->flags |= alloc_flag; } } @@ -1310,6 +1332,7 @@ static const struct wined3d_texture_ops texture3d_ops = texture3d_sub_resource_load, texture3d_sub_resource_add_dirty_region, texture3d_sub_resource_cleanup, + texture3d_sub_resource_invalidate_location, texture3d_prepare_texture, }; diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index 92bc1e1da54..0cbc7d4ade9 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -262,9 +262,9 @@ static void wined3d_volume_load_location(struct wined3d_volume *volume, case WINED3D_LOCATION_TEXTURE_RGB: case WINED3D_LOCATION_TEXTURE_SRGB: if ((location == WINED3D_LOCATION_TEXTURE_RGB - && !(volume->flags & WINED3D_VFLAG_ALLOCATED)) + && !(volume->container->flags & WINED3D_TEXTURE_RGB_ALLOCATED)) || (location == WINED3D_LOCATION_TEXTURE_SRGB - && !(volume->flags & WINED3D_VFLAG_SRGB_ALLOCATED))) + && !(volume->container->flags & WINED3D_TEXTURE_SRGB_ALLOCATED))) ERR("Trying to load (s)RGB texture without prior allocation.\n"); if (volume->locations & WINED3D_LOCATION_DISCARDED) @@ -451,8 +451,8 @@ static void volume_unload(struct wined3d_resource *resource) } /* The texture name is managed by the container. */ - volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED - | WINED3D_VFLAG_CLIENT_STORAGE); + wined3d_texture_force_reload(volume->container); + volume->flags &= ~WINED3D_VFLAG_CLIENT_STORAGE; resource_unload(resource); } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 17a68dcd671..5ec5088ea77 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2116,6 +2116,7 @@ struct wined3d_texture_ops void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource, const struct wined3d_box *dirty_region); void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource); + void (*texture_sub_resource_invalidate_location)(struct wined3d_resource *sub_resource, DWORD location); void (*texture_prepare_texture)(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb); }; @@ -2123,8 +2124,10 @@ struct wined3d_texture_ops #define WINED3D_TEXTURE_COND_NP2 0x00000001 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000002 #define WINED3D_TEXTURE_IS_SRGB 0x00000004 -#define WINED3D_TEXTURE_RGB_VALID 0x00000008 -#define WINED3D_TEXTURE_SRGB_VALID 0x00000010 +#define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000008 +#define WINED3D_TEXTURE_RGB_VALID 0x00000010 +#define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000020 +#define WINED3D_TEXTURE_SRGB_VALID 0x00000040 struct wined3d_texture { @@ -2170,6 +2173,7 @@ void wined3d_texture_bind(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; +void wined3d_texture_force_reload(struct wined3d_texture *texture) DECLSPEC_HIDDEN; void wined3d_texture_load(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; void wined3d_texture_prepare_texture(struct wined3d_texture *texture, @@ -2191,9 +2195,7 @@ void wined3d_texture_set_swapchain(struct wined3d_texture *texture, const char *wined3d_debug_location(DWORD location) DECLSPEC_HIDDEN; -#define WINED3D_VFLAG_ALLOCATED 0x00000001 -#define WINED3D_VFLAG_SRGB_ALLOCATED 0x00000002 -#define WINED3D_VFLAG_CLIENT_STORAGE 0x00000004 +#define WINED3D_VFLAG_CLIENT_STORAGE 0x00000001 struct wined3d_volume { @@ -2354,8 +2356,6 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) D #define SFLAG_GLCKEY 0x00000100 /* The GL texture was created with a color key. */ #define SFLAG_CLIENT 0x00000200 /* GL_APPLE_client_storage is used with this surface. */ #define SFLAG_DIBSECTION 0x00000400 /* Has a DIB section attached for GetDC. */ -#define SFLAG_ALLOCATED 0x00000800 /* A GL texture is allocated for this surface. */ -#define SFLAG_SRGBALLOCATED 0x00001000 /* A sRGB GL texture is allocated for this surface. */ struct wined3d_sampler { -- GitLab