Matteo Bruni : wined3d: Refuse to create texture views changing format from non-typeless.

Alexandre Julliard julliard at winehq.org
Fri Dec 1 14:08:19 CST 2017


Module: wine
Branch: master
Commit: 21c7b94c810c4722e060a105dbb66958b058f7c0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=21c7b94c810c4722e060a105dbb66958b058f7c0

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Mon Nov 27 20:17:32 2017 +0100

wined3d: Refuse to create texture views changing format from non-typeless.

Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 5eda92a..f739685 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 62f087b..b35b66b 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 3a9ac2e..bd4a210 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;
 




More information about the wine-cvs mailing list