summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGert Wollny <[email protected]>2019-07-25 10:35:46 +0200
committerGert Wollny <[email protected]>2019-08-01 05:58:53 +0000
commit57361d89fa1085b953ef7618817f752c3cc824ef (patch)
tree8bfcb3225516ef3db88666c11cad810631758923 /src
parentd81ba38b02cb1ef8f87b5551e6d668fa245e138e (diff)
mesa/st: Tie depth_clamp code into other shaders (GS and TES)
v2: Use file scope defined depth_range_state in common v3: - 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 v4: 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]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c11
-rw-r--r--src/mesa/state_tracker/st_program.c21
-rw-r--r--src/mesa/state_tracker/st_program.h5
3 files changed, 36 insertions, 1 deletions
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index a10cc21021c..f9c61c055cc 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -251,6 +251,17 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
VARYING_SLOT_COL1 |
VARYING_SLOT_BFC0 |
VARYING_SLOT_BFC1));
+
+ key.lower_depth_clamp =
+ (pipe_shader == PIPE_SHADER_GEOMETRY || !st->gp) &&
+ 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;
+
}
return st_get_basic_variant(st, pipe_shader, stp, &key)->driver_shader;
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index fa7552b2592..df6c8e81f55 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1697,8 +1697,27 @@ st_get_basic_variant(struct st_context *st,
NIR_PASS_V(tgsi.ir.nir, nir_lower_clamp_color_outputs);
tgsi.stream_output = prog->tgsi.stream_output;
- } else
+ } else {
+ if (key->lower_depth_clamp) {
+ struct gl_program_parameter_list *params = prog->Base.Parameters;
+
+ unsigned depth_range_const =
+ _mesa_add_state_reference(params, depth_range_state);
+
+ const struct tgsi_token *tokens;
+ tokens =
+ st_tgsi_lower_depth_clamp(prog->tgsi.tokens,
+ depth_range_const,
+ key->clip_negative_one_to_one);
+
+ if (tokens != prog->tgsi.tokens)
+ tgsi_free_tokens(prog->tgsi.tokens);
+
+ prog->tgsi.tokens = tokens;
+ prog->num_tgsi_tokens = tgsi_num_tokens(tokens);
+ }
tgsi = prog->tgsi;
+ }
/* fill in new variant */
switch (pipe_shader) {
case PIPE_SHADER_TESS_CTRL:
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index eefa340e5cb..77b335993a5 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -269,6 +269,11 @@ struct st_basic_variant_key
/** For compat profile */
bool clamp_color;
+
+ /** both for ARB_depth_clamp */
+ bool lower_depth_clamp;
+ bool clip_negative_one_to_one;
+
};