diff options
author | Nicolai Hähnle <[email protected]> | 2016-04-28 17:07:44 -0500 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2016-04-29 11:39:51 -0500 |
commit | a56edbdd8ff2619d54787b6d0705ab33dbe7d189 (patch) | |
tree | adae94a4e273c473315ea076f80abce846ef5b82 /src/gallium | |
parent | acb65a23a3488d820f851342b06d215cd4964b3d (diff) |
tgsi/text: add str_match_format helper function
Reviewed-by: Ilia Mirkin <[email protected]>
Reviewed-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_text.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index 3f5ef05109d..26e7c8f3165 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -119,6 +119,24 @@ static boolean str_match_nocase_whole( const char **pcur, const char *str ) return FALSE; } +/* Return the format corresponding to the name at *pcur. + * Returns -1 if there is no format name. + * + * On success, the pointer to the string is moved to the end of the read format + * name. + */ +static int str_match_format(const char **pcur) +{ + for (unsigned i = 0; i < PIPE_FORMAT_COUNT; i++) { + const struct util_format_description *desc = + util_format_description(i); + if (desc && str_match_nocase_whole(pcur, desc->name)) { + return i; + } + } + return -1; +} + /* Eat zero or more whitespaces. */ static void eat_opt_white( const char **pcur ) @@ -1302,16 +1320,11 @@ static boolean parse_declaration( struct translate_ctx *ctx ) decl.Image.Writable = 1; } else { - for (i = 0; i < PIPE_FORMAT_COUNT; i++) { - const struct util_format_description *desc = - util_format_description(i); - if (desc && str_match_nocase_whole(&cur2, desc->name)) { - decl.Image.Format = i; - break; - } - } - if (i == PIPE_FORMAT_COUNT) + int format = str_match_format(&cur2); + if (format < 0) break; + + decl.Image.Format = format; } cur = cur2; eat_opt_white(&cur2); |