diff options
author | Gert Wollny <[email protected]> | 2019-07-25 10:33:36 +0200 |
---|---|---|
committer | Gert Wollny <[email protected]> | 2019-08-01 05:58:53 +0000 |
commit | fefb152067bd81b0e7ecc1af3794494dcc389421 (patch) | |
tree | a6ba72196dd4822d5bbb4d9d524e091e65305f61 | |
parent | b048d8bf8f056759d1845a799d4ba2ac84bce30f (diff) |
mesa/st: Tie depth clamp lowering in to the VP code
v1: implemented by Erik Faye-Lund <[email protected]>
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 <[email protected]>
Reviewed-by: Reviewed-by: Marek Olšák <[email protected]>
-rw-r--r-- | src/mesa/state_tracker/st_atom_shader.c | 10 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_context.h | 1 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.c | 17 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.h | 4 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 700239a00a2..97abe72d3ef 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -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); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 93387df7cca..50c4a1f28b2 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -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; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 81065612adb..23e9f15cd60 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -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"); diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index 3da3f625e3c..ef55fe33320 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -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; }; |