From: Connor Abbott Date: Tue, 23 Jun 2020 11:19:07 +0000 (+0200) Subject: freedreno: Refactor ir3_cache shader compilation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d9dd989d2a5d08e465f3c7fcb427aa24ec6247d2;p=mesa.git freedreno: Refactor ir3_cache shader compilation Use an array, which makes it more like turnip and makes implementing the const limits easier. Part-of: --- diff --git a/src/gallium/drivers/freedreno/ir3/ir3_cache.c b/src/gallium/drivers/freedreno/ir3/ir3_cache.c index fdf81769f5a..0a121c41358 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_cache.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_cache.c @@ -93,17 +93,29 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key, return entry->data; } - struct ir3_shader_variant *vs = ir3_shader_variant(key->vs, key->key, false, debug); - if (!vs) - return NULL; - - struct ir3_shader_variant *hs = NULL, *ds = NULL; - if (key->hs) { + if (key->hs) debug_assert(key->ds); - hs = ir3_shader_variant(key->hs, key->key, false, debug); - ds = ir3_shader_variant(key->ds, key->key, false, debug); - if (!hs || ! ds) - return NULL; + + struct ir3_shader *shaders[MESA_SHADER_STAGES] = { + [MESA_SHADER_VERTEX] = key->vs, + [MESA_SHADER_TESS_CTRL] = key->hs, + [MESA_SHADER_TESS_EVAL] = key->ds, + [MESA_SHADER_GEOMETRY] = key->gs, + [MESA_SHADER_FRAGMENT] = key->fs, + }; + + struct ir3_shader_variant *variants[MESA_SHADER_STAGES]; + + for (gl_shader_stage stage = MESA_SHADER_VERTEX; + stage < MESA_SHADER_STAGES; stage++) { + if (shaders[stage]) { + variants[stage] = + ir3_shader_variant(shaders[stage], key->key, false, debug); + if (!variants[stage]) + return NULL; + } else { + variants[stage] = NULL; + } } /* For tessellation, the binning shader is derived from the DS. */ @@ -115,19 +127,14 @@ ir3_cache_lookup(struct ir3_cache *cache, const struct ir3_cache_key *key, if (!bs) return NULL; - struct ir3_shader_variant *gs = NULL; - if (key->gs) { - gs = ir3_shader_variant(key->gs, key->key, false, debug); - if (!gs) - return NULL; - } - - struct ir3_shader_variant *fs = ir3_shader_variant(key->fs, key->key, false, debug); - if (!fs) - return NULL; - struct ir3_program_state *state = - cache->funcs->create_state(cache->data, bs, vs, hs, ds, gs, fs, &key->key); + cache->funcs->create_state(cache->data, bs, + variants[MESA_SHADER_VERTEX], + variants[MESA_SHADER_TESS_CTRL], + variants[MESA_SHADER_TESS_EVAL], + variants[MESA_SHADER_GEOMETRY], + variants[MESA_SHADER_FRAGMENT], + &key->key); state->key = *key; /* NOTE: uses copy of key in state obj, because pointer passed by caller