st/glsl: support clamping color outputs in compat for gs/tes
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 25 Jun 2019 10:53:15 +0000 (20:53 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 26 Jun 2019 00:36:48 +0000 (00:36 +0000)
This support requires the driver to be a NIR driver as we use the
NIR lowering pass to do the clamping.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h

index a4475e28df72022a0449cce49107c508c330f8e2..700239a00a27190cead1729a3e11188ed959db22 100644 (file)
@@ -220,7 +220,25 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
    if (st->shader_has_one_variant[prog->info.stage] && stp->variants)
       return stp->variants->driver_shader;
 
-   return st_get_basic_variant(st, pipe_shader, stp)->driver_shader;
+   struct st_basic_variant_key key;
+
+   /* use memset, not an initializer to be sure all memory is zeroed */
+   memset(&key, 0, sizeof(key));
+
+   key.st = st->has_shareable_shaders ? NULL : st;
+
+   if (pipe_shader == PIPE_SHADER_GEOMETRY ||
+       pipe_shader == PIPE_SHADER_TESS_EVAL) {
+      key.clamp_color = st->clamp_vert_color_in_shader &&
+                        st->ctx->Light._ClampVertexColor &&
+                        (stp->Base.info.outputs_written &
+                         (VARYING_SLOT_COL0 |
+                          VARYING_SLOT_COL1 |
+                          VARYING_SLOT_BFC0 |
+                          VARYING_SLOT_BFC1));
+   }
+
+   return st_get_basic_variant(st, pipe_shader, stp, &key)->driver_shader;
 }
 
 
index 875be9d0029ff0a289f424594e32734d55e0f829..e60962388cb04491665d44ca3cadf9faaeee9c50 100644 (file)
@@ -238,8 +238,12 @@ st_invalidate_state(struct gl_context *ctx)
       st->dirty |= ST_NEW_VERTEX_ARRAYS;
 
    /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
-   if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT))
+   if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT)) {
       st->dirty |= ST_NEW_VS_STATE;
+      if (st->ctx->API == API_OPENGL_COMPAT && ctx->Version >= 32) {
+         st->dirty |= ST_NEW_GS_STATE | ST_NEW_TES_STATE;
+      }
+   }
 
    /* Which shaders are dirty will be determined manually. */
    if (new_state & _NEW_PROGRAM) {
@@ -701,8 +705,12 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
          !st->force_persample_in_shader;
 
    st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
-   st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders;
-   st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders;
+   st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] =
+         st->has_shareable_shaders &&
+         !st->clamp_vert_color_in_shader;
+   st->shader_has_one_variant[MESA_SHADER_GEOMETRY] =
+         st->has_shareable_shaders &&
+         !st->clamp_vert_color_in_shader;
    st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders;
 
    st->bitmap.cache.empty = true;
index 9f6e492d6fb64498a6814b5ea84dc50c17c3121e..3c99721a8a70da41418df834f8a3985a24dacab1 100644 (file)
@@ -1632,14 +1632,12 @@ st_translate_geometry_program(struct st_context *st,
 struct st_basic_variant *
 st_get_basic_variant(struct st_context *st,
                      unsigned pipe_shader,
-                     struct st_common_program *prog)
+                     struct st_common_program *prog,
+                     const struct st_basic_variant_key *key)
 {
    struct pipe_context *pipe = st->pipe;
    struct st_basic_variant *v;
-   struct st_basic_variant_key key;
    struct pipe_shader_state tgsi = {0};
-   memset(&key, 0, sizeof(key));
-   key.st = st->has_shareable_shaders ? NULL : st;
 
    /* Search for existing variant */
    for (v = prog->variants; v; v = v->next) {
@@ -1656,6 +1654,10 @@ st_get_basic_variant(struct st_context *st,
         if (prog->tgsi.type == PIPE_SHADER_IR_NIR) {
            tgsi.type = PIPE_SHADER_IR_NIR;
            tgsi.ir.nir = nir_shader_clone(NULL, prog->tgsi.ir.nir);
+
+            if (key->clamp_color)
+               NIR_PASS_V(tgsi.ir.nir, nir_lower_clamp_color_outputs);
+
             tgsi.stream_output = prog->tgsi.stream_output;
         } else
            tgsi = prog->tgsi;
@@ -1676,7 +1678,7 @@ st_get_basic_variant(struct st_context *st,
             return NULL;
          }
 
-         v->key = key;
+         v->key = *key;
 
          /* insert into list */
          v->next = prog->variants;
@@ -2058,19 +2060,34 @@ st_precompile_shader_variant(struct st_context *st,
 
    case GL_TESS_CONTROL_PROGRAM_NV: {
       struct st_common_program *p = st_common_program(prog);
-      st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, p);
+      struct st_basic_variant_key key;
+
+      memset(&key, 0, sizeof(key));
+
+      key.st = st->has_shareable_shaders ? NULL : st;
+      st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, p, &key);
       break;
    }
 
    case GL_TESS_EVALUATION_PROGRAM_NV: {
       struct st_common_program *p = st_common_program(prog);
-      st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, p);
+      struct st_basic_variant_key key;
+
+      memset(&key, 0, sizeof(key));
+
+      key.st = st->has_shareable_shaders ? NULL : st;
+      st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, p, &key);
       break;
    }
 
    case GL_GEOMETRY_PROGRAM_NV: {
       struct st_common_program *p = st_common_program(prog);
-      st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, p);
+      struct st_basic_variant_key key;
+
+      memset(&key, 0, sizeof(key));
+
+      key.st = st->has_shareable_shaders ? NULL : st;
+      st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, p, &key);
       break;
    }
 
index f67ea5eb2087cccde456eb314d40b75e02fc0f02..59a60368039720eab82e45176bed604045e01597 100644 (file)
@@ -241,6 +241,9 @@ struct st_vertex_program
 struct st_basic_variant_key
 {
    struct st_context *st;          /**< variants are per-context */
+
+   /** For compat profile */
+   bool clamp_color;
 };
 
 
@@ -401,7 +404,8 @@ st_get_cp_variant(struct st_context *st,
 extern struct st_basic_variant *
 st_get_basic_variant(struct st_context *st,
                      unsigned pipe_shader,
-                     struct st_common_program *p);
+                     struct st_common_program *p,
+                     const struct st_basic_variant_key *key);
 
 extern void
 st_release_vp_variants( struct st_context *st,