From cfcc348e15675582f5c8a2470941899e73984ee9 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 5 Sep 2017 22:41:41 +0300 Subject: [PATCH] gallium/{r600,radeonsi}: Fix segfault with color format To: mesa-dev@lists.freedesktop.org Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102552 --- src/gallium/auxiliary/util/u_format.h | 3 +++ src/gallium/drivers/r600/r600_state_common.c | 4 ++++ src/gallium/drivers/radeonsi/si_state.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 88bfd72d05..54284bfad6 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -1206,6 +1206,9 @@ util_format_get_first_non_void_channel(enum pipe_format format) const struct util_format_description *desc = util_format_description(format); int i; + if (!desc) + return -1; + for (i = 0; i < 4; i++) if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) break; diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index 4c97efa73b..e9818e4bd5 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -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) && \ diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 5bbfbdd1ac..27001338ee 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -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) && \ @@ -1442,6 +1444,9 @@ static uint32_t si_translate_texformat(struct pipe_screen *screen, bool uniform = true; int i; + if (!desc) + goto out_unknown; + /* Colorspace (return non-RGB formats directly). */ switch (desc->colorspace) { /* Depth stencil formats */ @@ -1925,6 +1930,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 @@ -3114,6 +3121,9 @@ si_make_buffer_descriptor(struct si_screen *screen, struct r600_resource *buf, unsigned num_format, data_format; desc = util_format_description(format); + if (!desc) + return; + first_non_void = util_format_get_first_non_void_channel(format); stride = desc->block.bits / 8; num_format = si_translate_buffer_numformat(&screen->b.b, desc, first_non_void); -- 2.14.1