From 1e0603eb58aaa3e28880bf82782619867ae441f5 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 13 Apr 2016 19:09:54 +0200 Subject: [PATCH] wined3d: Store the power-of-two dimensions in the texture. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/surface.c | 21 ++------------------- dlls/wined3d/texture.c | 18 +++++++++++------- dlls/wined3d/wined3d_private.h | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index cbaa14f8d59..de82dda6407 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -4501,25 +4501,6 @@ HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_tex unsigned int resource_size; HRESULT hr; - if (container->flags & WINED3D_TEXTURE_COND_NP2_EMULATED) - { - unsigned int pow2_width = 1, pow2_height = 1; - - /* Find the nearest pow2 match. */ - while (pow2_width < desc->width) - pow2_width <<= 1; - while (pow2_height < desc->height) - pow2_height <<= 1; - - surface->pow2Width = pow2_width; - surface->pow2Height = pow2_height; - } - else - { - surface->pow2Width = desc->width; - surface->pow2Height = desc->height; - } - /* Quick lockable sanity check. * TODO: remove this after surfaces, usage and lockability have been debugged properly * this function is too deep to need to care about things like this. @@ -4564,6 +4545,8 @@ HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_tex } surface->container = container; + surface->pow2Width = wined3d_texture_get_level_pow2_width(container, level); + surface->pow2Height = wined3d_texture_get_level_pow2_height(container, level); surface->texture_target = target; surface->texture_level = level; surface->texture_layer = layer; diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index e1d60cbf51a..2ca94c00582 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -899,18 +899,20 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT && !gl_info->supported[ARB_TEXTURE_RECTANGLE] && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]) { texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED; - surface->pow2Width = surface->pow2Height = 1; - while (surface->pow2Width < width) - surface->pow2Width <<= 1; - while (surface->pow2Height < height) - surface->pow2Height <<= 1; + texture->pow2_width = texture->pow2_height = 1; + while (texture->pow2_width < width) + texture->pow2_width <<= 1; + while (texture->pow2_height < height) + texture->pow2_height <<= 1; } else { texture->flags &= ~WINED3D_TEXTURE_COND_NP2_EMULATED; - surface->pow2Width = width; - surface->pow2Height = height; + texture->pow2_width = width; + texture->pow2_height = height; } + surface->pow2Width = texture->pow2_width; + surface->pow2Height = texture->pow2_height; sub_resource->locations = 0; @@ -1556,6 +1558,8 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3 texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED; } } + texture->pow2_width = pow2_width; + texture->pow2_height = pow2_height; if ((pow2_width > gl_info->limits.texture_size || pow2_height > gl_info->limits.texture_size) && (desc->usage & WINED3DUSAGE_TEXTURE)) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 967f39eac12..d74f143cd88 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2449,6 +2449,8 @@ struct wined3d_texture const struct wined3d_texture_ops *texture_ops; struct gl_texture texture_rgb, texture_srgb; struct wined3d_swapchain *swapchain; + unsigned int pow2_width; + unsigned int pow2_height; UINT layer_count; UINT level_count; unsigned int download_count; @@ -2521,6 +2523,18 @@ static inline unsigned int wined3d_texture_get_level_depth(const struct wined3d_ return max(1, texture->resource.depth >> level); } +static inline unsigned int wined3d_texture_get_level_pow2_width(const struct wined3d_texture *texture, + unsigned int level) +{ + return max(1, texture->pow2_width >> level); +} + +static inline unsigned int wined3d_texture_get_level_pow2_height(const struct wined3d_texture *texture, + unsigned int level) +{ + return max(1, texture->pow2_height >> level); +} + void wined3d_texture_apply_sampler_desc(struct wined3d_texture *texture, const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context *context) DECLSPEC_HIDDEN; void wined3d_texture_bind(struct wined3d_texture *texture, -- 2.11.4.GIT