summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2019-01-24 13:12:10 +1000
committerErik Faye-Lund <[email protected]>2019-10-17 10:41:36 +0200
commitcce3ad166a5ad67ecfeb0777d8c60ddd3b95e3f3 (patch)
tree479197cd792ae200129c4c9309a9c0b7d0bc4ffc /src
parent731260de7ddb30638b194f1a52a62a5b94487398 (diff)
st/mesa: handling lower flatshading for NIR drivers.
This uses the NIR pass to lower flatshading when the driver requests it. Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/state_tracker/st_atom_rasterizer.c3
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c3
-rw-r--r--src/mesa/state_tracker/st_context.c7
-rw-r--r--src/mesa/state_tracker/st_context.h1
-rw-r--r--src/mesa/state_tracker/st_program.c3
-rw-r--r--src/mesa/state_tracker/st_program.h2
6 files changed, 18 insertions, 1 deletions
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index b1ac4b3f133..9bf9fb10846 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -96,7 +96,8 @@ st_update_rasterizer(struct st_context *st)
/* _NEW_LIGHT
*/
- raster->flatshade = ctx->Light.ShadeModel == GL_FLAT;
+ raster->flatshade = !st->lower_flatshade &&
+ ctx->Light.ShadeModel == GL_FLAT;
raster->flatshade_first = ctx->Light.ProvokingVertex ==
GL_FIRST_VERTEX_CONVENTION_EXT;
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 5004eefc083..da269537866 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -119,6 +119,9 @@ st_update_fp( struct st_context *st )
key.st = st->has_shareable_shaders ? NULL : st;
+ key.lower_flatshade = st->lower_flatshade &&
+ st->ctx->Light.ShadeModel == GL_FLAT;
+
/* _NEW_FRAG_CLAMP */
key.clamp_color = st->clamp_frag_color_in_shader &&
st->ctx->Color._ClampFragmentColor;
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 545d56996fb..0441ebb27c8 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -227,6 +227,10 @@ st_invalidate_state(struct gl_context *ctx)
_NEW_POINT))
st->dirty |= ST_NEW_RASTERIZER;
+ if ((new_state & _NEW_LIGHT) &&
+ st->lower_flatshade)
+ st->dirty |= ST_NEW_FS_STATE;
+
if (new_state & _NEW_PROJECTION &&
st_user_clip_planes_enabled(ctx))
st->dirty |= ST_NEW_CLIP_STATE;
@@ -664,6 +668,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
screen->get_param(screen, PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND);
st->has_signed_vertex_buffer_offset =
screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET);
+ st->lower_flatshade =
+ !screen->get_param(screen, PIPE_CAP_FLATSHADE);
st->has_hw_atomics =
screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
@@ -731,6 +737,7 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
st->shader_has_one_variant[MESA_SHADER_FRAGMENT] =
st->has_shareable_shaders &&
+ !st->lower_flatshade &&
!st->clamp_frag_color_in_shader &&
!st->clamp_frag_depth_in_shader &&
!st->force_persample_in_shader;
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 0a14ef9b98c..851202f61f0 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -147,6 +147,7 @@ struct st_context
boolean needs_rgb_dst_alpha_override;
boolean can_bind_const_buffer_as_vertex;
boolean has_signed_vertex_buffer_offset;
+ boolean lower_flatshade;
/**
* If a shader can be created when we get its source.
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 4d0906ace78..80487032063 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1161,6 +1161,9 @@ st_create_fp_variant(struct st_context *st,
if (key->clamp_color)
NIR_PASS_V(tgsi.ir.nir, nir_lower_clamp_color_outputs);
+ if (key->lower_flatshade)
+ NIR_PASS_V(tgsi.ir.nir, nir_lower_flatshade);
+
if (key->persample_shading) {
nir_shader *shader = tgsi.ir.nir;
nir_foreach_variable(var, &shader->inputs)
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index b74eb09280e..bd20c0259c0 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -130,6 +130,8 @@ struct st_fp_variant_key
char texture_targets[MAX_NUM_FRAGMENT_REGISTERS_ATI];
struct st_external_sampler_key external;
+
+ GLuint lower_flatshade:1;
};