[PATCH v2] wined3d: Refuse to create texture views changing format from non-typeless.

Matteo Bruni mbruni at codeweavers.com
Mon Nov 27 13:17:32 CST 2017


Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
v2: Allow views with the sRGB variant.

 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 5eda92acf1..f73968546f 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 62f087b23a..b35b66bfeb 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 3a9ac2e181..bd4a2102f2 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.13.6




More information about the wine-devel mailing list