From 21c7b94c810c4722e060a105dbb66958b058f7c0 Mon Sep 17 00:00:00 2001 From: Matteo Bruni Date: Mon, 27 Nov 2017 20:17:32 +0100 Subject: [PATCH] wined3d: Refuse to create texture views changing format from non-typeless. Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/wined3d/utils.c | 14 ++++++++++++++ dlls/wined3d/view.c | 8 ++++++++ dlls/wined3d/wined3d_private.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 5eda92acf1f..f73968546fb 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -3815,6 +3815,20 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali return slice_pitch * depth; } +BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1, enum wined3d_format_id format2) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(format_srgb_info); ++i) + { + if (format1 == format_srgb_info[i].srgb_format_id) + return format2 == format_srgb_info[i].base_format_id; + if (format1 == format_srgb_info[i].base_format_id) + return format2 == format_srgb_info[i].srgb_format_id; + } + return FALSE; +} + /***************************************************************************** * Trace formatting of useful values */ diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c index 62f087b23a4..b35b66bfebb 100644 --- a/dlls/wined3d/view.c +++ b/dlls/wined3d/view.c @@ -128,6 +128,14 @@ static const struct wined3d_format *validate_resource_view(const struct wined3d_ struct wined3d_texture *texture = texture_from_resource(resource); unsigned int depth_or_layer_count; + if (resource->format->id != format->id && !wined3d_format_is_typeless(resource->format) + && !wined3d_formats_are_srgb_variants(resource->format->id, format->id)) + { + WARN("Trying to create incompatible view for non typeless format %s.\n", + debug_d3dformat(format->id)); + return NULL; + } + if (mip_slice && resource->type == WINED3D_RTYPE_TEXTURE_3D) depth_or_layer_count = wined3d_texture_get_level_depth(texture, desc->u.texture.level_idx); else diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 3a9ac2e1815..bd4a2102f25 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4251,6 +4251,8 @@ BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id, enum wined3d_format_id view_format_id) DECLSPEC_HIDDEN; const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion( const struct wined3d_texture *texture, BOOL need_alpha_ck) DECLSPEC_HIDDEN; +BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1, + enum wined3d_format_id format2) DECLSPEC_HIDDEN; BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN; -- 2.11.4.GIT