mesa/st: Tie depth clamp lowering in to the VP code
authorGert Wollny <gert.wollny@collabora.com>
Thu, 25 Jul 2019 08:33:36 +0000 (10:33 +0200)
committerGert Wollny <gw.fossdev@gmail.com>
Thu, 1 Aug 2019 05:58:53 +0000 (05:58 +0000)
v1: implemented by Erik Faye-Lund <erik.faye-lund@collabora.com>
v2: Add handling of the ARB_clip_control depth mode
v3: Move depth_range_state to file scope and remove training zeros (Erik)
v4: - don't use the one_shader_variant property, as this is not correct (Marek)
    - also use tests on available shader stages to enable depth_clamp lowering
V5: Don't use key.st, use st directly (Marek)

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h

index 700239a..97abe72 100644 (file)
@@ -193,6 +193,16 @@ st_update_vp( struct st_context *st )
                           VARYING_SLOT_BFC0 |
                           VARYING_SLOT_BFC1));
 
+      key.lower_depth_clamp =
+            !st->gp && !st->tep &&
+            st->clamp_frag_depth_in_shader &&
+            (st->ctx->Transform.DepthClampNear ||
+             st->ctx->Transform.DepthClampFar);
+
+      if (key.lower_depth_clamp)
+         key.clip_negative_one_to_one =
+               st->ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE;
+
       st->vp_variant = st_get_vp_variant(st, stvp, &key);
    }
 
index 93387df..50c4a1f 100644 (file)
@@ -131,6 +131,7 @@ struct st_context
    struct draw_stage *rastpos_stage;  /**< For glRasterPos */
    GLboolean clamp_frag_color_in_shader;
    GLboolean clamp_vert_color_in_shader;
+   boolean clamp_frag_depth_in_shader;
    boolean has_stencil_export; /**< can do shader stencil export? */
    boolean has_time_elapsed;
    boolean has_etc1;
index 8106561..23e9f15 100644 (file)
@@ -55,6 +55,7 @@
 #include "st_cb_bitmap.h"
 #include "st_cb_drawpixels.h"
 #include "st_context.h"
+#include "st_tgsi_lower_depth_clamp.h"
 #include "st_tgsi_lower_yuv.h"
 #include "st_program.h"
 #include "st_mesa_to_tgsi.h"
@@ -633,6 +634,9 @@ st_translate_vertex_program(struct st_context *st,
    return stvp->tgsi.tokens != NULL;
 }
 
+static const gl_state_index16 depth_range_state[STATE_LENGTH] =
+   { STATE_DEPTH_RANGE };
+
 static struct st_vp_variant *
 st_create_vp_variant(struct st_context *st,
                      struct st_vertex_program *stvp,
@@ -640,6 +644,7 @@ st_create_vp_variant(struct st_context *st,
 {
    struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
    struct pipe_context *pipe = st->pipe;
+   struct gl_program_parameter_list *params = stvp->Base.Parameters;
 
    vpv->key = *key;
    vpv->tgsi.stream_output = stvp->tgsi.stream_output;
@@ -691,6 +696,18 @@ st_create_vp_variant(struct st_context *st,
          fprintf(stderr, "mesa: cannot emulate deprecated features\n");
    }
 
+   if (key->lower_depth_clamp) {
+      unsigned depth_range_const =
+            _mesa_add_state_reference(params, depth_range_state);
+
+      const struct tgsi_token *tokens;
+      tokens = st_tgsi_lower_depth_clamp(vpv->tgsi.tokens, depth_range_const,
+                                         key->clip_negative_one_to_one);
+      if (tokens != vpv->tgsi.tokens)
+         tgsi_free_tokens(vpv->tgsi.tokens);
+      vpv->tgsi.tokens = tokens;
+   }
+
    if (ST_DEBUG & DEBUG_TGSI) {
       tgsi_dump(vpv->tgsi.tokens, 0);
       debug_printf("\n");
index 3da3f62..ef55fe3 100644 (file)
@@ -183,6 +183,10 @@ struct st_vp_variant_key
 
    /** for ARB_color_buffer_float */
    bool clamp_color;
+
+   /** both for ARB_depth_clamp */
+   bool lower_depth_clamp;
+   bool clip_negative_one_to_one;
 };