diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 04441480692..bd8cf457606 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -1887,11 +1887,7 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface) TRACE("surface %p.\n", surface); - if (surface->container->row_pitch) - return surface->container->row_pitch; - - wined3d_format_calculate_pitch(surface->resource.format, surface->resource.device->surface_alignment, - surface->resource.width, surface->resource.height, &row_pitch, &slice_pitch); + wined3d_texture_get_pitch(surface->container, surface->texture_level, &row_pitch, &slice_pitch); TRACE("Returning %u.\n", row_pitch); @@ -1950,16 +1946,7 @@ HRESULT wined3d_surface_update_desc(struct wined3d_surface *surface, const struc surface->resource.format = texture_resource->format; surface->resource.multisample_type = texture_resource->multisample_type; surface->resource.multisample_quality = texture_resource->multisample_quality; - if (surface->container->row_pitch) - { - surface->resource.size = height * surface->container->row_pitch; - } - else - { - /* User memory surfaces don't have the regular surface alignment. */ - wined3d_format_calculate_pitch(texture_resource->format, 1, width, height, - &surface->container->row_pitch, &surface->resource.size); - } + surface->resource.size = surface->container->slice_pitch; /* The format might be changed to a format that needs conversion. * If the surface didn't use PBOs previously but could now, don't diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 0a084de6319..06abb38f4d6 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -499,6 +499,24 @@ void * CDECL wined3d_texture_get_parent(const struct wined3d_texture *texture) return texture->resource.parent; } +void wined3d_texture_get_pitch(const struct wined3d_texture *texture, + unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch) +{ + const struct wined3d_resource *resource = &texture->resource; + unsigned int width = max(1, texture->resource.width >> level); + unsigned int height = max(1, texture->resource.height >> level); + + if (texture->row_pitch) + { + *row_pitch = texture->row_pitch; + *slice_pitch = texture->slice_pitch; + return; + } + + wined3d_format_calculate_pitch(resource->format, resource->device->surface_alignment, + width, height, row_pitch, slice_pitch); +} + DWORD CDECL wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod) { DWORD old = texture->lod; @@ -645,7 +663,12 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT texture->resource.height = height; texture->user_memory = mem; - texture->row_pitch = pitch; + if ((texture->row_pitch = pitch)) + texture->slice_pitch = height * pitch; + else + /* User memory surfaces don't have the regular surface alignment. */ + wined3d_format_calculate_pitch(format, 1, width, height, + &texture->row_pitch, &texture->slice_pitch); return wined3d_surface_update_desc(surface, gl_info); } diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index 733b46868ff..99310578f2a 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -42,8 +42,7 @@ BOOL volume_prepare_system_memory(struct wined3d_volume *volume) void wined3d_volume_get_pitch(const struct wined3d_volume *volume, UINT *row_pitch, UINT *slice_pitch) { - wined3d_format_calculate_pitch(volume->resource.format, volume->resource.device->surface_alignment, - volume->resource.width, volume->resource.height, row_pitch, slice_pitch); + wined3d_texture_get_pitch(volume->container, volume->texture_level, row_pitch, slice_pitch); } /* This call just uploads data, the caller is responsible for binding the diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 443f763da4e..470db1f736c 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2366,6 +2366,7 @@ struct wined3d_texture void *user_memory; unsigned int row_pitch; + unsigned int slice_pitch; /* May only be accessed from the command stream worker thread. */ struct wined3d_texture_async @@ -2400,6 +2401,8 @@ void wined3d_texture_bind(struct wined3d_texture *texture, 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_get_pitch(const struct wined3d_texture *texture, + unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch) 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,