st/mesa: handling lower flatshading for NIR drivers.
authorDave Airlie <airlied@redhat.com>
Thu, 24 Jan 2019 03:12:10 +0000 (13:12 +1000)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Oct 2019 08:41:36 +0000 (10:41 +0200)
This uses the NIR pass to lower flatshading when the driver
requests it.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_atom_rasterizer.c
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h

index b1ac4b3f1330ba2df0989d8b7b545e4fd84b6c5d..9bf9fb108465096c041496b456af3108f89b7cf1 100644 (file)
@@ -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;
index 5004eefc083ac472700f0a8f461b6712fda6454e..da269537866c57d04be9943505d2f53dfc3c927a 100644 (file)
@@ -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;
index 545d56996fb126ea70a307ef7da5d5fea819e3c8..0441ebb27c8fe9c06b748ab8241faa8fc26a90da 100644 (file)
@@ -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;
index 0a14ef9b98c81ba9010c6c38dba356bdb6e86e71..851202f61f0c2d0f30f2d0b3b1d851b27d0da059 100644 (file)
@@ -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.
index 4d0906ace781fe580153b22b8beacddd77bb8276..80487032063d59a847b3dbde3bdb4b66ac4218d6 100644 (file)
@@ -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)
index b74eb09280e80ad350539a343696d000c084f635..bd20c0259c05a238f6f9f27eccb755b9972f5946 100644 (file)
@@ -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;
 };