diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c index 7bbc2f29e51..b6347681fc1 100644 --- a/src/gallium/drivers/r600/evergreen_state.c +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -1069,11 +1069,7 @@ static void evergreen_set_color_surface_buffer(struct r600_context *rctx, endian = r600_colorformat_endian_swap(format, FALSE); desc = util_format_description(pformat); - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } + i = util_format_get_first_non_void_channel(pformat); ntype = V_028C70_NUMBER_UNORM; if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) ntype = V_028C70_NUMBER_SRGB; @@ -1179,11 +1175,7 @@ static void evergreen_set_color_surface_common(struct r600_context *rctx, } nbanks = eg_num_banks(rscreen->b.info.r600_num_banks); desc = util_format_description(pformat); - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } + i = util_format_get_first_non_void_channel(pformat); color->attrib = S_028C74_TILE_SPLIT(tile_split)| S_028C74_NUM_BANKS(nbanks) | S_028C74_BANK_WIDTH(bankw) | diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 9d29d7759d9..bcc2435799f 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -2657,12 +2657,7 @@ void r600_vertex_data_type(enum pipe_format pformat, goto out_unknown; } - /* Find the first non-VOID channel. */ - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } + i = util_format_get_first_non_void_channel(pformat); *endian = r600_endian_swap(desc->channel[i].size); diff --git a/src/gallium/drivers/r600/r600_formats.h b/src/gallium/drivers/r600/r600_formats.h index 714bc465e43..aee87183cb7 100644 --- a/src/gallium/drivers/r600/r600_formats.h +++ b/src/gallium/drivers/r600/r600_formats.h @@ -90,12 +90,8 @@ static inline bool r600_is_buffer_format_supported(enum pipe_format format, bool if (format == PIPE_FORMAT_R11G11B10_FLOAT) return true; - /* Find the first non-VOID channel. */ - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) - break; - } - if (i == 4) + i = util_format_get_first_non_void_channel(format); + if (i == -1) return false; /* No fixed, no double. */ diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c index 0b200782fab..67af78a8feb 100644 --- a/src/gallium/drivers/r600/r600_state.c +++ b/src/gallium/drivers/r600/r600_state.c @@ -854,11 +854,7 @@ static void r600_init_color_surface(struct r600_context *rctx, desc = util_format_description(surf->base.format); - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } + i = util_format_get_first_non_void_channel(surf->base.format); ntype = V_0280A0_NUMBER_UNORM; if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index a124a81e318..31a9b728e5e 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -3036,14 +3036,8 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, goto out_unknown; } - /* Find the first non-VOID channel. */ - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } - - if (i == 4) + i = util_format_get_first_non_void_channel(format); + if (i == -1) goto out_unknown; /* uniform formats */