freedreno/ir3: refactor out helpers for comparing shader keys
authorRob Clark <robdclark@gmail.com>
Tue, 18 Apr 2017 14:24:38 +0000 (10:24 -0400)
committerRob Clark <robdclark@gmail.com>
Tue, 18 Apr 2017 20:32:00 +0000 (16:32 -0400)
Each of the ir3 users has *basically* the same logic for comparing the
previous and current shader key, to see which, if any, shader state
needs to be marked dirty due to shader variant change.

The difference between gen's was just that some lowering flags never get
set on certain generations.  But it doesn't really hurt to include the
extra checks (because both keys would have false).

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/a3xx/fd3_draw.c
src/gallium/drivers/freedreno/a4xx/fd4_draw.c
src/gallium/drivers/freedreno/a5xx/fd5_draw.c
src/gallium/drivers/freedreno/ir3/ir3_shader.h

index b3cd4619559fbe78ababda73478c3a68c315abf4..afa2c3c7ef74525be9ac08dfb9b2f4fbe496613e 100644 (file)
@@ -100,32 +100,13 @@ fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
        struct ir3_shader_key *last_key = &fd3_ctx->last_key;
 
        if (!ir3_shader_key_equal(last_key, key)) {
-               if (last_key->has_per_samp || key->has_per_samp) {
-                       if ((last_key->vsaturate_s != key->vsaturate_s) ||
-                                       (last_key->vsaturate_t != key->vsaturate_t) ||
-                                       (last_key->vsaturate_r != key->vsaturate_r))
-                               ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-                       if ((last_key->fsaturate_s != key->fsaturate_s) ||
-                                       (last_key->fsaturate_t != key->fsaturate_t) ||
-                                       (last_key->fsaturate_r != key->fsaturate_r))
-                               ctx->dirty |= FD_SHADER_DIRTY_FP;
+               if (ir3_shader_key_changes_fs(last_key, key)) {
+                       ctx->dirty |= FD_SHADER_DIRTY_FP;
                }
 
-               if (last_key->vclamp_color != key->vclamp_color)
+               if (ir3_shader_key_changes_vs(last_key, key)) {
                        ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-               if (last_key->fclamp_color != key->fclamp_color)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->color_two_side != key->color_two_side)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->half_precision != key->half_precision)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->ucp_enables != key->ucp_enables)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP | FD_SHADER_DIRTY_VP;
+               }
 
                fd3_ctx->last_key = *key;
        }
index 641c58a15bdb0e419c9fa982d94be04685bfbf55..c0ada87f83ee30a0a249df4577182cf5b5b47ce5 100644 (file)
@@ -84,37 +84,13 @@ fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
        struct ir3_shader_key *last_key = &fd4_ctx->last_key;
 
        if (!ir3_shader_key_equal(last_key, key)) {
-               if (last_key->has_per_samp || key->has_per_samp) {
-                       if ((last_key->vsaturate_s != key->vsaturate_s) ||
-                                       (last_key->vsaturate_t != key->vsaturate_t) ||
-                                       (last_key->vsaturate_r != key->vsaturate_r) ||
-                                       (last_key->vastc_srgb != key->vastc_srgb))
-                               ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-                       if ((last_key->fsaturate_s != key->fsaturate_s) ||
-                                       (last_key->fsaturate_t != key->fsaturate_t) ||
-                                       (last_key->fsaturate_r != key->fsaturate_r) ||
-                                       (last_key->fastc_srgb != key->fastc_srgb))
-                               ctx->dirty |= FD_SHADER_DIRTY_FP;
+               if (ir3_shader_key_changes_fs(last_key, key)) {
+                       ctx->dirty |= FD_SHADER_DIRTY_FP;
                }
 
-               if (last_key->vclamp_color != key->vclamp_color)
+               if (ir3_shader_key_changes_vs(last_key, key)) {
                        ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-               if (last_key->fclamp_color != key->fclamp_color)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->color_two_side != key->color_two_side)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->half_precision != key->half_precision)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->rasterflat != key->rasterflat)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->ucp_enables != key->ucp_enables)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP | FD_SHADER_DIRTY_VP;
+               }
 
                fd4_ctx->last_key = *key;
        }
index d9fce2f7ee898b2d9767f8220f4944135d523255..b7417ec92a9d44c764f5e0419b0e3f14cd3af54e 100644 (file)
@@ -77,37 +77,13 @@ fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
        struct ir3_shader_key *last_key = &fd5_ctx->last_key;
 
        if (!ir3_shader_key_equal(last_key, key)) {
-               if (last_key->has_per_samp || key->has_per_samp) {
-                       if ((last_key->vsaturate_s != key->vsaturate_s) ||
-                                       (last_key->vsaturate_t != key->vsaturate_t) ||
-                                       (last_key->vsaturate_r != key->vsaturate_r) ||
-                                       (last_key->vastc_srgb != key->vastc_srgb))
-                               ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-                       if ((last_key->fsaturate_s != key->fsaturate_s) ||
-                                       (last_key->fsaturate_t != key->fsaturate_t) ||
-                                       (last_key->fsaturate_r != key->fsaturate_r) ||
-                                       (last_key->fastc_srgb != key->fastc_srgb))
-                               ctx->dirty |= FD_SHADER_DIRTY_FP;
+               if (ir3_shader_key_changes_fs(last_key, key)) {
+                       ctx->dirty |= FD_SHADER_DIRTY_FP;
                }
 
-               if (last_key->vclamp_color != key->vclamp_color)
+               if (ir3_shader_key_changes_vs(last_key, key)) {
                        ctx->dirty |= FD_SHADER_DIRTY_VP;
-
-               if (last_key->fclamp_color != key->fclamp_color)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->color_two_side != key->color_two_side)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->half_precision != key->half_precision)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->rasterflat != key->rasterflat)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP;
-
-               if (last_key->ucp_enables != key->ucp_enables)
-                       ctx->dirty |= FD_SHADER_DIRTY_FP | FD_SHADER_DIRTY_VP;
+               }
 
                fd5_ctx->last_key = *key;
        }
index 052a563b9455a821920a95a3d69abf01ffea8b50..59584ec5b7b9eb8a0180af08230564d6dfee9c78 100644 (file)
@@ -105,6 +105,57 @@ ir3_shader_key_equal(struct ir3_shader_key *a, struct ir3_shader_key *b)
        return a->global == b->global;
 }
 
+/* will the two keys produce different lowering for a fragment shader? */
+static inline bool
+ir3_shader_key_changes_fs(struct ir3_shader_key *key, struct ir3_shader_key *last_key)
+{
+       if (last_key->has_per_samp || key->has_per_samp) {
+               if ((last_key->fsaturate_s != key->fsaturate_s) ||
+                               (last_key->fsaturate_t != key->fsaturate_t) ||
+                               (last_key->fsaturate_r != key->fsaturate_r) ||
+                               (last_key->fastc_srgb != key->fastc_srgb))
+                       return true;
+       }
+
+       if (last_key->fclamp_color != key->fclamp_color)
+               return true;
+
+       if (last_key->color_two_side != key->color_two_side)
+               return true;
+
+       if (last_key->half_precision != key->half_precision)
+               return true;
+
+       if (last_key->rasterflat != key->rasterflat)
+               return true;
+
+       if (last_key->ucp_enables != key->ucp_enables)
+               return true;
+
+       return false;
+}
+
+/* will the two keys produce different lowering for a vertex shader? */
+static inline bool
+ir3_shader_key_changes_vs(struct ir3_shader_key *key, struct ir3_shader_key *last_key)
+{
+       if (last_key->has_per_samp || key->has_per_samp) {
+               if ((last_key->vsaturate_s != key->vsaturate_s) ||
+                               (last_key->vsaturate_t != key->vsaturate_t) ||
+                               (last_key->vsaturate_r != key->vsaturate_r) ||
+                               (last_key->vastc_srgb != key->vastc_srgb))
+                       return true;
+       }
+
+       if (last_key->vclamp_color != key->vclamp_color)
+               return true;
+
+       if (last_key->ucp_enables != key->ucp_enables)
+               return true;
+
+       return false;
+}
+
 struct ir3_shader_variant {
        struct fd_bo *bo;