mesa/gallium: automatically lower alpha-testing
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 3 Oct 2019 20:35:23 +0000 (16:35 -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_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 3593e055590476130161a877bbdf4328a3faca71..ec43f9b7971414f47a6aab445b9c9622450f2186 100644 (file)
@@ -395,6 +395,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
       return 1;
 
    case PIPE_CAP_FLATSHADE:
+   case PIPE_CAP_ALPHA_TEST:
       return 1;
 
    default:
index 8bb83aff77cb4be3512a5f7400b9f461576f45e9..a18f481f2127f31fc2008af64d79f5a33a3a5486 100644 (file)
@@ -559,6 +559,7 @@ The integer capabilities:
 * ``PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION``: True if driver supports demote keyword in GLSL programs.
 * ``PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE``: True if driver wants the TG4 component encoded in sampler swizzle rather than as a separate source.
 * ``PIPE_CAP_FLATSHADE``: Driver supports pipe_rasterizer_state::flatshade.
+* ``PIPE_CAP_ALPHA_TEST``: Driver supports alpha-testing.
 
 .. _pipe_capf:
 
index a9c5a4661945d2778c67c916550b655802c556d7..8a0a86a8c42929e67f63e0447c602eed14beea1a 100644 (file)
@@ -905,6 +905,7 @@ enum pipe_cap
    PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION,
    PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE,
    PIPE_CAP_FLATSHADE,
+   PIPE_CAP_ALPHA_TEST,
 };
 
 /**
index da269537866c57d04be9943505d2f53dfc3c927a..f79c401e3e7a4f5d797e1d735d6ce1a30b8cc12a 100644 (file)
@@ -122,6 +122,11 @@ st_update_fp( struct st_context *st )
       key.lower_flatshade = st->lower_flatshade &&
                             st->ctx->Light.ShadeModel == GL_FLAT;
 
+      /* _NEW_COLOR */
+      key.lower_alpha_func = COMPARE_FUNC_NEVER;
+      if (st->lower_alpha_test && _mesa_is_alpha_test_enabled(st->ctx))
+         key.lower_alpha_func = st->ctx->Color.AlphaFunc;
+
       /* _NEW_FRAG_CLAMP */
       key.clamp_color = st->clamp_frag_color_in_shader &&
                         st->ctx->Color._ClampFragmentColor;
index 0441ebb27c8fe9c06b748ab8241faa8fc26a90da..8d4705bcc68a1677d896b162f85d7a09db637347 100644 (file)
@@ -500,7 +500,12 @@ st_init_driver_flags(struct st_context *st)
    f->NewFramebufferSRGB = ST_NEW_FB_STATE;
    f->NewScissorRect = ST_NEW_SCISSOR;
    f->NewScissorTest = ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
-   f->NewAlphaTest = ST_NEW_DSA;
+
+   if (st->lower_alpha_test)
+      f->NewAlphaTest = ST_NEW_FS_STATE;
+   else
+      f->NewAlphaTest = ST_NEW_DSA;
+
    f->NewBlend = ST_NEW_BLEND;
    f->NewBlendColor = ST_NEW_BLEND_COLOR;
    f->NewColorMask = ST_NEW_BLEND;
@@ -670,6 +675,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET);
    st->lower_flatshade =
       !screen->get_param(screen, PIPE_CAP_FLATSHADE);
+   st->lower_alpha_test =
+      !screen->get_param(screen, PIPE_CAP_ALPHA_TEST);
 
    st->has_hw_atomics =
       screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
@@ -738,6 +745,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->lower_alpha_test &&
          !st->clamp_frag_color_in_shader &&
          !st->clamp_frag_depth_in_shader &&
          !st->force_persample_in_shader;
index 851202f61f0c2d0f30f2d0b3b1d851b27d0da059..99f43828f445b7962498299f549e365bd017ca58 100644 (file)
@@ -148,6 +148,7 @@ struct st_context
    boolean can_bind_const_buffer_as_vertex;
    boolean has_signed_vertex_buffer_offset;
    boolean lower_flatshade;
+   boolean lower_alpha_test;
 
    /**
     * If a shader can be created when we get its source.
index 80487032063d59a847b3dbde3bdb4b66ac4218d6..f1d3f7b3ce70e1d2acdb932d1baaa2bf5aafedfc 100644 (file)
@@ -1150,6 +1150,8 @@ st_create_fp_variant(struct st_context *st,
       { STATE_INTERNAL, STATE_PT_SCALE };
    static const gl_state_index16 bias_state[STATE_LENGTH] =
       { STATE_INTERNAL, STATE_PT_BIAS };
+   static const gl_state_index16 alpha_ref_state[STATE_LENGTH] =
+      { STATE_INTERNAL, STATE_ALPHA_REF };
 
    if (!variant)
       return NULL;
@@ -1164,6 +1166,12 @@ st_create_fp_variant(struct st_context *st,
       if (key->lower_flatshade)
          NIR_PASS_V(tgsi.ir.nir, nir_lower_flatshade);
 
+      if (key->lower_alpha_func != COMPARE_FUNC_NEVER) {
+         _mesa_add_state_reference(params, alpha_ref_state);
+         NIR_PASS_V(tgsi.ir.nir, nir_lower_alpha_test, key->lower_alpha_func,
+                    false, alpha_ref_state);
+      }
+
       if (key->persample_shading) {
           nir_shader *shader = tgsi.ir.nir;
           nir_foreach_variable(var, &shader->inputs)
index bd20c0259c05a238f6f9f27eccb755b9972f5946..b84d219e3c8e2e44a04c06f63467fce409cf5b44 100644 (file)
@@ -132,6 +132,7 @@ struct st_fp_variant_key
    struct st_external_sampler_key external;
 
    GLuint lower_flatshade:1;
+   enum compare_func lower_alpha_func:3;
 };