freedreno: Refactor ir3_cache shader compilation
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 23 Jun 2020 11:19:07 +0000 (13:19 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 26 Jun 2020 09:34:33 +0000 (09:34 +0000)
Use an array, which makes it more like turnip and makes implementing the
const limits easier.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5607>

src/gallium/drivers/freedreno/ir3/ir3_cache.c

index fdf81769f5a010353a86af334b479a4f58bec437..0a121c41358e1effd028eaa4d634b547415548d6 100644 (file)
@@ -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