Commit ee8a5b7d authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Track texture allocation per-texture.

parent 0c0a2adc
...@@ -599,11 +599,6 @@ static void surface_evict_sysmem(struct wined3d_surface *surface) ...@@ -599,11 +599,6 @@ static void surface_evict_sysmem(struct wined3d_surface *surface)
surface_invalidate_location(surface, WINED3D_LOCATION_SYSMEM); 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) static void surface_release_client_storage(struct wined3d_surface *surface)
{ {
struct wined3d_context *context = context_acquire(surface->resource.device, NULL); struct wined3d_context *context = context_acquire(surface->resource.device, NULL);
...@@ -621,11 +616,9 @@ static void surface_release_client_storage(struct wined3d_surface *surface) ...@@ -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_info->gl_ops.gl.p_glTexImage2D(surface->texture_target, surface->texture_level,
GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
} }
wined3d_texture_force_reload(surface->container);
context_release(context); 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) static BOOL surface_use_pbo(const struct wined3d_surface *surface)
...@@ -1211,7 +1204,7 @@ static void surface_unload(struct wined3d_resource *resource) ...@@ -1211,7 +1204,7 @@ static void surface_unload(struct wined3d_resource *resource)
surface_load_location(surface, surface->resource.map_binding); surface_load_location(surface, surface->resource.map_binding);
surface_invalidate_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); context = context_acquire(device, NULL);
gl_info = context->gl_info; gl_info = context->gl_info;
...@@ -1845,7 +1838,7 @@ void surface_load(struct wined3d_surface *surface, BOOL srgb) ...@@ -1845,7 +1838,7 @@ void surface_load(struct wined3d_surface *surface, BOOL srgb)
surface_invalidate_location(surface, ~surface->resource.map_binding); surface_invalidate_location(surface, ~surface->resource.map_binding);
/* Switching color keying on / off may change the internal format. */ /* Switching color keying on / off may change the internal format. */
if (ck_changed) if (ck_changed)
surface_force_reload(surface); wined3d_texture_force_reload(surface->container);
} }
else if (!(surface->locations & location)) else if (!(surface->locations & location))
{ {
......
...@@ -751,7 +751,26 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT ...@@ -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) 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->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) 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 ...@@ -817,11 +836,17 @@ static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource
wined3d_surface_destroy(surface); 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. */ /* Context activation is done by the caller. */
static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb) static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
{ {
UINT sub_count = texture->level_count * texture->layer_count; 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_format *format = texture->resource.format;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_color_key_conversion *conversion; const struct wined3d_color_key_conversion *conversion;
...@@ -864,9 +889,6 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi ...@@ -864,9 +889,6 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi
GLsizei width = surface->pow2Width; GLsizei width = surface->pow2Width;
const BYTE *mem = NULL; const BYTE *mem = NULL;
if (surface->flags & alloc_flag)
continue;
if (converted) if (converted)
surface->flags |= SFLAG_CONVERTED; surface->flags |= SFLAG_CONVERTED;
else else
...@@ -922,8 +944,6 @@ static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wi ...@@ -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); gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
checkGLcall("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 = ...@@ -932,6 +952,7 @@ static const struct wined3d_texture_ops texture2d_ops =
texture2d_sub_resource_load, texture2d_sub_resource_load,
texture2d_sub_resource_add_dirty_region, texture2d_sub_resource_add_dirty_region,
texture2d_sub_resource_cleanup, texture2d_sub_resource_cleanup,
texture2d_sub_resource_invalidate_location,
texture2d_prepare_texture, texture2d_prepare_texture,
}; };
...@@ -1261,9 +1282,15 @@ static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource ...@@ -1261,9 +1282,15 @@ static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource
wined3d_volume_destroy(volume); 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) 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; unsigned int sub_count = texture->level_count * texture->layer_count;
const struct wined3d_format *format = texture->resource.format; const struct wined3d_format *format = texture->resource.format;
const struct wined3d_gl_info *gl_info = context->gl_info; 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 ...@@ -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]); struct wined3d_volume *volume = volume_from_resource(texture->sub_resources[i]);
void *mem = NULL; void *mem = NULL;
if (volume->flags & alloc_flag)
continue;
if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert if (gl_info->supported[APPLE_CLIENT_STORAGE] && !format->convert
&& volume_prepare_system_memory(volume)) && volume_prepare_system_memory(volume))
{ {
...@@ -1300,8 +1324,6 @@ static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wi ...@@ -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); gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
checkGLcall("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 = ...@@ -1310,6 +1332,7 @@ static const struct wined3d_texture_ops texture3d_ops =
texture3d_sub_resource_load, texture3d_sub_resource_load,
texture3d_sub_resource_add_dirty_region, texture3d_sub_resource_add_dirty_region,
texture3d_sub_resource_cleanup, texture3d_sub_resource_cleanup,
texture3d_sub_resource_invalidate_location,
texture3d_prepare_texture, texture3d_prepare_texture,
}; };
......
...@@ -262,9 +262,9 @@ static void wined3d_volume_load_location(struct wined3d_volume *volume, ...@@ -262,9 +262,9 @@ static void wined3d_volume_load_location(struct wined3d_volume *volume,
case WINED3D_LOCATION_TEXTURE_RGB: case WINED3D_LOCATION_TEXTURE_RGB:
case WINED3D_LOCATION_TEXTURE_SRGB: case WINED3D_LOCATION_TEXTURE_SRGB:
if ((location == WINED3D_LOCATION_TEXTURE_RGB if ((location == WINED3D_LOCATION_TEXTURE_RGB
&& !(volume->flags & WINED3D_VFLAG_ALLOCATED)) && !(volume->container->flags & WINED3D_TEXTURE_RGB_ALLOCATED))
|| (location == WINED3D_LOCATION_TEXTURE_SRGB || (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"); ERR("Trying to load (s)RGB texture without prior allocation.\n");
if (volume->locations & WINED3D_LOCATION_DISCARDED) if (volume->locations & WINED3D_LOCATION_DISCARDED)
...@@ -451,8 +451,8 @@ static void volume_unload(struct wined3d_resource *resource) ...@@ -451,8 +451,8 @@ static void volume_unload(struct wined3d_resource *resource)
} }
/* The texture name is managed by the container. */ /* The texture name is managed by the container. */
volume->flags &= ~(WINED3D_VFLAG_ALLOCATED | WINED3D_VFLAG_SRGB_ALLOCATED wined3d_texture_force_reload(volume->container);
| WINED3D_VFLAG_CLIENT_STORAGE); volume->flags &= ~WINED3D_VFLAG_CLIENT_STORAGE;
resource_unload(resource); resource_unload(resource);
} }
......
...@@ -2116,6 +2116,7 @@ struct wined3d_texture_ops ...@@ -2116,6 +2116,7 @@ struct wined3d_texture_ops
void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource, void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource,
const struct wined3d_box *dirty_region); const struct wined3d_box *dirty_region);
void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource); 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, void (*texture_prepare_texture)(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb); struct wined3d_context *context, BOOL srgb);
}; };
...@@ -2123,8 +2124,10 @@ struct wined3d_texture_ops ...@@ -2123,8 +2124,10 @@ struct wined3d_texture_ops
#define WINED3D_TEXTURE_COND_NP2 0x00000001 #define WINED3D_TEXTURE_COND_NP2 0x00000001
#define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000002 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000002
#define WINED3D_TEXTURE_IS_SRGB 0x00000004 #define WINED3D_TEXTURE_IS_SRGB 0x00000004
#define WINED3D_TEXTURE_RGB_VALID 0x00000008 #define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000008
#define WINED3D_TEXTURE_SRGB_VALID 0x00000010 #define WINED3D_TEXTURE_RGB_VALID 0x00000010
#define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000020
#define WINED3D_TEXTURE_SRGB_VALID 0x00000040
struct wined3d_texture struct wined3d_texture
{ {
...@@ -2170,6 +2173,7 @@ void wined3d_texture_bind(struct wined3d_texture *texture, ...@@ -2170,6 +2173,7 @@ void wined3d_texture_bind(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture, void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; 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, void wined3d_texture_load(struct wined3d_texture *texture,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void wined3d_texture_prepare_texture(struct wined3d_texture *texture, void wined3d_texture_prepare_texture(struct wined3d_texture *texture,
...@@ -2191,9 +2195,7 @@ void wined3d_texture_set_swapchain(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; const char *wined3d_debug_location(DWORD location) DECLSPEC_HIDDEN;
#define WINED3D_VFLAG_ALLOCATED 0x00000001 #define WINED3D_VFLAG_CLIENT_STORAGE 0x00000001
#define WINED3D_VFLAG_SRGB_ALLOCATED 0x00000002
#define WINED3D_VFLAG_CLIENT_STORAGE 0x00000004
struct wined3d_volume struct wined3d_volume
{ {
...@@ -2354,8 +2356,6 @@ void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) D ...@@ -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_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_CLIENT 0x00000200 /* GL_APPLE_client_storage is used with this surface. */
#define SFLAG_DIBSECTION 0x00000400 /* Has a DIB section attached for GetDC. */ #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 struct wined3d_sampler
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment