mesa/gallium: automatically lower two-sided lighting
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 3 Oct 2019 20:51:19 +0000 (16:51 -0400)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Oct 2019 08:41:36 +0000 (10:41 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_screen.c
src/gallium/docs/source/screen.rst
src/gallium/include/pipe/p_defines.h
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 4c52874f3a5a33759ff7e62acd34b5ed0cf899e2..2a0c28aabc19af1f332ffedfdd024428f03daf77 100644 (file)
@@ -397,6 +397,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
    case PIPE_CAP_FLATSHADE:
    case PIPE_CAP_ALPHA_TEST:
    case PIPE_CAP_POINT_SIZE_FIXED:
+   case PIPE_CAP_TWO_SIDED_COLOR:
       return 1;
 
    default:
index f280ad1cfec54c8e6082c498f725ebf405a98206..ffe104e8dc60d2b6c011109b3a45d50aa01a856a 100644 (file)
@@ -562,6 +562,7 @@ The integer capabilities:
 * ``PIPE_CAP_ALPHA_TEST``: Driver supports alpha-testing.
 * ``PIPE_CAP_POINT_SIZE_FIXED``: Driver supports point-sizes that are fixed,
   as opposed to writing gl_PointSize for every point.
+* ``PIPE_CAP_TWO_SIDED_COLOR``: Driver supports two-sided coloring.
 
 .. _pipe_capf:
 
index e5a68ca7cf7244431f5cd8ac35a32b7bd3846d9f..ec446ad8de3b94866a77380d0d902ae240dd7722 100644 (file)
@@ -907,6 +907,7 @@ enum pipe_cap
    PIPE_CAP_FLATSHADE,
    PIPE_CAP_ALPHA_TEST,
    PIPE_CAP_POINT_SIZE_FIXED,
+   PIPE_CAP_TWO_SIDED_COLOR,
 };
 
 /**
index 1cbefce29b509c821b1bf3f04b50170c2ffe1e3d..bcbb3cd6b79b864130904051405328c09a64d307 100644 (file)
@@ -101,7 +101,8 @@ st_update_rasterizer(struct st_context *st)
                              GL_FIRST_VERTEX_CONVENTION_EXT;
 
    /* _NEW_LIGHT | _NEW_PROGRAM */
-   raster->light_twoside = _mesa_vertex_program_two_side_enabled(ctx);
+   if (!st->lower_two_sided_color)
+      raster->light_twoside = _mesa_vertex_program_two_side_enabled(ctx);
 
    /*_NEW_LIGHT | _NEW_BUFFERS */
    raster->clamp_vertex_color = !st->clamp_vert_color_in_shader &&
index 0f4b3b483878de066c364bd09e937c66a251fbc1..c784ea8c59debdff3a81666edb865b2742b32519 100644 (file)
@@ -38,6 +38,7 @@
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "main/framebuffer.h"
+#include "main/state.h"
 #include "main/texobj.h"
 #include "main/texstate.h"
 #include "program/program.h"
@@ -128,6 +129,10 @@ st_update_fp( struct st_context *st )
       if (st->lower_alpha_test && _mesa_is_alpha_test_enabled(st->ctx))
          key.lower_alpha_func = st->ctx->Color.AlphaFunc;
 
+      /* _NEW_LIGHT | _NEW_PROGRAM */
+      key.lower_two_sided_color = st->lower_two_sided_color &&
+         _mesa_vertex_program_two_side_enabled(st->ctx);
+
       /* _NEW_FRAG_CLAMP */
       key.clamp_color = st->clamp_frag_color_in_shader &&
                         st->ctx->Color._ClampFragmentColor;
index 6997e70035aa57a8f9cc18972858e46c1c1886e4..d0134bc3313d4a037b5b476e1c4955c6ec2bd894 100644 (file)
@@ -228,7 +228,7 @@ st_invalidate_state(struct gl_context *ctx)
       st->dirty |= ST_NEW_RASTERIZER;
 
    if ((new_state & _NEW_LIGHT) &&
-       st->lower_flatshade)
+       (st->lower_flatshade || st->lower_two_sided_color))
       st->dirty |= ST_NEW_FS_STATE;
 
    if (new_state & _NEW_PROJECTION &&
@@ -679,6 +679,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       !screen->get_param(screen, PIPE_CAP_ALPHA_TEST);
    st->lower_point_size =
       !screen->get_param(screen, PIPE_CAP_POINT_SIZE_FIXED);
+   st->lower_two_sided_color =
+      !screen->get_param(screen, PIPE_CAP_TWO_SIDED_COLOR);
 
    st->has_hw_atomics =
       screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
@@ -751,7 +753,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
          !st->lower_alpha_test &&
          !st->clamp_frag_color_in_shader &&
          !st->clamp_frag_depth_in_shader &&
-         !st->force_persample_in_shader;
+         !st->force_persample_in_shader &&
+         !st->lower_two_sided_color;
 
    st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
    st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] =
index 433e27160da06bc91479926f759c60ec6c840927..159aecad5cff4d9c4d0df4398ba4fa5e102131c1 100644 (file)
@@ -150,6 +150,7 @@ struct st_context
    boolean lower_flatshade;
    boolean lower_alpha_test;
    boolean lower_point_size;
+   boolean lower_two_sided_color;
 
    /**
     * If a shader can be created when we get its source.
index 857a5444fcc56364df8f29374a82d16645dc68b7..205fc9561fe1ce6348af83d9a94c53eed73b3475 100644 (file)
@@ -1181,6 +1181,9 @@ st_create_fp_variant(struct st_context *st,
                     false, alpha_ref_state);
       }
 
+      if (key->lower_two_sided_color)
+         NIR_PASS_V(tgsi.ir.nir, nir_lower_two_sided_color);
+
       if (key->persample_shading) {
           nir_shader *shader = tgsi.ir.nir;
           nir_foreach_variable(var, &shader->inputs)
index 85934ee1df5781a1cb357625d41960d425f83c9d..53638db687a7a297cad0dc943c5854d7770227a1 100644 (file)
@@ -126,6 +126,9 @@ struct st_fp_variant_key
    /** for ARB_depth_clamp */
    GLuint lower_depth_clamp:1;
 
+   /** for OpenGL 1.0 on modern hardware */
+   GLuint lower_two_sided_color:1;
+
    /** needed for ATI_fragment_shader */
    char texture_targets[MAX_NUM_FRAGMENT_REGISTERS_ATI];