wined3d: Unify the 2D and 3D paths in wined3d_device_update_texture().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2017-04-10 23:47:32 +02:00 committed by Alexandre Julliard
parent 3b5a8707e6
commit c1ebab1a4b
3 changed files with 44 additions and 72 deletions

View File

@ -3542,6 +3542,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture) struct wined3d_texture *src_texture, struct wined3d_texture *dst_texture)
{ {
unsigned int src_size, dst_size, src_skip_levels = 0; unsigned int src_size, dst_size, src_skip_levels = 0;
unsigned int src_level_count, dst_level_count;
unsigned int layer_count, level_count, i, j; unsigned int layer_count, level_count, i, j;
unsigned int row_pitch, slice_pitch; unsigned int row_pitch, slice_pitch;
enum wined3d_resource_type type; enum wined3d_resource_type type;
@ -3591,8 +3592,9 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
level_count = min(wined3d_texture_get_level_count(src_texture), src_level_count = src_texture->level_count;
wined3d_texture_get_level_count(dst_texture)); dst_level_count = dst_texture->level_count;
level_count = min(src_level_count, dst_level_count);
src_size = max(src_texture->resource.width, src_texture->resource.height); src_size = max(src_texture->resource.width, src_texture->resource.height);
dst_size = max(dst_texture->resource.width, dst_texture->resource.height); dst_size = max(dst_texture->resource.width, dst_texture->resource.height);
@ -3615,88 +3617,60 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device,
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
/* Make sure that the destination texture is loaded. */
context = context_acquire(device, NULL, 0); context = context_acquire(device, NULL, 0);
/* Make sure that the destination texture is loaded. */
wined3d_texture_load(dst_texture, context, FALSE); wined3d_texture_load(dst_texture, context, FALSE);
context_release(context);
/* Only a prepare, since we're uploading entire sub-resources. */
wined3d_texture_prepare_texture(dst_texture, context, FALSE);
wined3d_texture_bind_and_dirtify(dst_texture, context, FALSE);
/* Update every surface level of the texture. */ /* Update every surface level of the texture. */
switch (type) for (i = 0; i < level_count; ++i)
{ {
case WINED3D_RTYPE_TEXTURE_2D: for (j = 0; j < layer_count; ++j)
{ {
unsigned int src_levels = src_texture->level_count; unsigned int src_sub_resource_idx = j * src_level_count + i + src_skip_levels;
unsigned int dst_levels = dst_texture->level_count; unsigned int dst_sub_resource_idx = j * dst_level_count + i;
struct wined3d_surface *src_surface;
struct wined3d_surface *dst_surface;
for (i = 0; i < layer_count; ++i) /* Use wined3d_texture_blt() instead of uploading directly if we need conversion. */
if (dst_texture->resource.format->convert
|| wined3d_format_get_color_key_conversion(dst_texture, FALSE))
{ {
for (j = 0; j < level_count; ++j) SetRect(&r, 0, 0, wined3d_texture_get_level_width(dst_texture, i),
wined3d_texture_get_level_height(dst_texture, i));
if (FAILED(hr = wined3d_texture_blt(dst_texture, dst_sub_resource_idx, &r,
src_texture, src_sub_resource_idx, &r, 0, NULL, WINED3D_TEXF_POINT)))
{ {
unsigned int src_sub_resource_idx = i * src_levels + j + src_skip_levels; WARN("Failed to update surface, hr %#x.\n", hr);
unsigned int dst_sub_resource_idx = i * dst_levels + j;
/* Use wined3d_texture_blt() instead of uploading directly if we need conversion. */
if (dst_texture->resource.format->convert
|| wined3d_format_get_color_key_conversion(dst_texture, FALSE))
{
SetRect(&r, 0, 0, wined3d_texture_get_level_width(dst_texture, j),
wined3d_texture_get_level_height(dst_texture, j));
if (FAILED(hr = wined3d_texture_blt(dst_texture, dst_sub_resource_idx, &r,
src_texture, src_sub_resource_idx, &r, 0, NULL, WINED3D_TEXF_POINT)))
{
WARN("Failed to update surface, hr %#x.\n", hr);
return hr;
}
continue;
}
src_surface = src_texture->sub_resources[src_sub_resource_idx].u.surface;
dst_surface = dst_texture->sub_resources[dst_sub_resource_idx].u.surface;
if (FAILED(hr = surface_upload_from_surface(dst_surface, NULL, src_surface, NULL)))
{
WARN("Failed to update surface, hr %#x.\n", hr);
return hr;
}
}
}
return WINED3D_OK;
}
case WINED3D_RTYPE_TEXTURE_3D:
context = context_acquire(device, NULL, 0);
/* Only a prepare, since we're uploading entire volumes. */
wined3d_texture_prepare_texture(dst_texture, context, FALSE);
wined3d_texture_bind_and_dirtify(dst_texture, context, FALSE);
for (j = 0; j < level_count; ++j)
{
if (!wined3d_texture_load_location(src_texture, src_skip_levels + j,
context, src_texture->resource.map_binding))
{
WARN("Failed to load source sub-resource %u into %s.\n", src_skip_levels + j,
wined3d_debug_location(src_texture->resource.map_binding));
context_release(context); context_release(context);
return WINED3DERR_INVALIDCALL; return hr;
} }
continue;
wined3d_texture_get_memory(src_texture, src_skip_levels + j, &data, src_texture->resource.map_binding);
wined3d_texture_get_pitch(src_texture, src_skip_levels + j, &row_pitch, &slice_pitch);
wined3d_texture_upload_data(dst_texture, j, context, NULL,
wined3d_const_bo_address(&data), row_pitch, slice_pitch);
wined3d_texture_invalidate_location(dst_texture, j, ~WINED3D_LOCATION_TEXTURE_RGB);
} }
context_release(context); if (!wined3d_texture_load_location(src_texture, src_sub_resource_idx,
return WINED3D_OK; context, src_texture->resource.map_binding))
{
WARN("Failed to load source sub-resource %u into %s.\n", src_sub_resource_idx,
wined3d_debug_location(src_texture->resource.map_binding));
context_release(context);
return WINED3DERR_INVALIDCALL;
}
default: wined3d_texture_get_memory(src_texture, src_sub_resource_idx, &data, src_texture->resource.map_binding);
FIXME("Unsupported texture type %#x.\n", type); wined3d_texture_get_pitch(src_texture, src_skip_levels + i, &row_pitch, &slice_pitch);
return WINED3DERR_INVALIDCALL;
wined3d_texture_upload_data(dst_texture, dst_sub_resource_idx, context, NULL,
wined3d_const_bo_address(&data), row_pitch, slice_pitch);
wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
}
} }
context_release(context);
return WINED3D_OK;
} }
HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes) HRESULT CDECL wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes)

View File

@ -866,7 +866,7 @@ static BOOL wined3d_surface_check_rect_dimensions(struct wined3d_surface *surfac
return SUCCEEDED(wined3d_texture_check_box_dimensions(surface->container, surface->texture_level, &box)); return SUCCEEDED(wined3d_texture_check_box_dimensions(surface->container, surface->texture_level, &box));
} }
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point, static HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
struct wined3d_surface *src_surface, const RECT *src_rect) struct wined3d_surface *src_surface, const RECT *src_rect)
{ {
unsigned int src_sub_resource_idx = surface_get_sub_resource_idx(src_surface); unsigned int src_sub_resource_idx = surface_get_sub_resource_idx(src_surface);

View File

@ -3085,8 +3085,6 @@ BOOL surface_load_location(struct wined3d_surface *surface,
void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
const struct wined3d_rendertarget_info *rt) DECLSPEC_HIDDEN; const struct wined3d_rendertarget_info *rt) DECLSPEC_HIDDEN;
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN; void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN;
void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info, void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct wined3d_gl_info *gl_info,
const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point, const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point,
BOOL srgb, const struct wined3d_const_bo_address *data) DECLSPEC_HIDDEN; BOOL srgb, const struct wined3d_const_bo_address *data) DECLSPEC_HIDDEN;