gallium/{r600, radeonsi}: Fix segfault with color format (v2)
authorDenis Pauk <pauk.denis@gmail.com>
Tue, 12 Sep 2017 20:38:45 +0000 (23:38 +0300)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 13 Sep 2017 22:59:24 +0000 (00:59 +0200)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102552

v2: Patch cleanup proposed by Nicolai Hähnle.
    * deleted changes in si_translate_texformat.

Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_format.c
src/gallium/drivers/r600/r600_state_common.c
src/gallium/drivers/radeonsi/si_state.c

index 3d281905ce7aab59e5e7fd282f6f93a45c07aa55..a6d42a428dcc9e0c52c84e1dbbe9eab77676a75b 100644 (file)
@@ -238,6 +238,10 @@ util_format_is_subsampled_422(enum pipe_format format)
 boolean
 util_format_is_supported(enum pipe_format format, unsigned bind)
 {
+   if (format >= PIPE_FORMAT_COUNT) {
+      return FALSE;
+   }
+
    if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) {
       return FALSE;
    }
index c1bce8304b210b7616c3dc36ce821ecedf167d87..1515c28091cbc64c139c4010301613ac3671150c 100644 (file)
@@ -2284,6 +2284,8 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
                format = PIPE_FORMAT_A4R4_UNORM;
 
        desc = util_format_description(format);
+       if (!desc)
+               goto out_unknown;
 
        /* Depth and stencil swizzling is handled separately. */
        if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) {
@@ -2650,6 +2652,8 @@ uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format forma
        const struct util_format_description *desc = util_format_description(format);
        int channel = util_format_get_first_non_void_channel(format);
        bool is_float;
+       if (!desc)
+               return ~0U;
 
 #define HAS_SIZE(x,y,z,w) \
        (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
index da3c7debd5780519675aa70cc2279eb89c7be5e2..1602406000ea59ef1dd47a87be5645cc9d1d450e 100644 (file)
@@ -1292,6 +1292,8 @@ static void si_emit_db_render_state(struct si_context *sctx, struct r600_atom *s
 static uint32_t si_translate_colorformat(enum pipe_format format)
 {
        const struct util_format_description *desc = util_format_description(format);
+       if (!desc)
+               return V_028C70_COLOR_INVALID;
 
 #define HAS_SIZE(x,y,z,w) \
        (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
@@ -1796,7 +1798,11 @@ static unsigned si_tex_dim(struct si_screen *sscreen, struct r600_texture *rtex,
 
 static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format)
 {
-       return si_translate_texformat(screen, format, util_format_description(format),
+       const struct util_format_description *desc = util_format_description(format);
+       if (!desc)
+               return false;
+
+       return si_translate_texformat(screen, format, desc,
                                      util_format_get_first_non_void_channel(format)) != ~0U;
 }
 
@@ -1925,6 +1931,8 @@ static unsigned si_is_vertex_format_supported(struct pipe_screen *screen,
                          PIPE_BIND_VERTEX_BUFFER)) == 0);
 
        desc = util_format_description(format);
+       if (!desc)
+               return 0;
 
        /* There are no native 8_8_8 or 16_16_16 data formats, and we currently
         * select 8_8_8_8 and 16_16_16_16 instead. This works reasonably well