mesa/gallium: automatically lower point-size
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 3 Oct 2019 20:49:15 +0000 (16:49 -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 ec43f9b7971414f47a6aab445b9c9622450f2186..4c52874f3a5a33759ff7e62acd34b5ed0cf899e2 100644 (file)
@@ -396,6 +396,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:
       return 1;
 
    default:
index a18f481f2127f31fc2008af64d79f5a33a3a5486..f280ad1cfec54c8e6082c498f725ebf405a98206 100644 (file)
@@ -560,6 +560,8 @@ The integer capabilities:
 * ``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_CAP_POINT_SIZE_FIXED``: Driver supports point-sizes that are fixed,
+  as opposed to writing gl_PointSize for every point.
 
 .. _pipe_capf:
 
index 8a0a86a8c42929e67f63e0447c602eed14beea1a..e5a68ca7cf7244431f5cd8ac35a32b7bd3846d9f 100644 (file)
@@ -906,6 +906,7 @@ enum pipe_cap
    PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE,
    PIPE_CAP_FLATSHADE,
    PIPE_CAP_ALPHA_TEST,
+   PIPE_CAP_POINT_SIZE_FIXED,
 };
 
 /**
index f79c401e3e7a4f5d797e1d735d6ce1a30b8cc12a..0f4b3b483878de066c364bd09e937c66a251fbc1 100644 (file)
@@ -52,6 +52,7 @@
 #include "st_atom.h"
 #include "st_program.h"
 #include "st_texture.h"
+#include "st_util.h"
 
 
 static unsigned
@@ -216,6 +217,10 @@ st_update_vp( struct st_context *st )
          key.clip_negative_one_to_one =
                st->ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE;
 
+      /* _NEW_POINT */
+      key.lower_point_size = st->lower_point_size &&
+                             !st_point_size_per_vertex(st->ctx);
+
       st->vp_variant = st_get_vp_variant(st, stvp, &key);
    }
 
index 8d4705bcc68a1677d896b162f85d7a09db637347..6997e70035aa57a8f9cc18972858e46c1c1886e4 100644 (file)
@@ -677,6 +677,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       !screen->get_param(screen, PIPE_CAP_FLATSHADE);
    st->lower_alpha_test =
       !screen->get_param(screen, PIPE_CAP_ALPHA_TEST);
+   st->lower_point_size =
+      !screen->get_param(screen, PIPE_CAP_POINT_SIZE_FIXED);
 
    st->has_hw_atomics =
       screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
@@ -740,7 +742,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
    st->shader_has_one_variant[MESA_SHADER_VERTEX] =
          st->has_shareable_shaders &&
          !st->clamp_frag_depth_in_shader &&
-         !st->clamp_vert_color_in_shader;
+         !st->clamp_vert_color_in_shader &&
+         !st->lower_point_size;
 
    st->shader_has_one_variant[MESA_SHADER_FRAGMENT] =
          st->has_shareable_shaders &&
index 99f43828f445b7962498299f549e365bd017ca58..433e27160da06bc91479926f759c60ec6c840927 100644 (file)
@@ -149,6 +149,7 @@ struct st_context
    boolean has_signed_vertex_buffer_offset;
    boolean lower_flatshade;
    boolean lower_alpha_test;
+   boolean lower_point_size;
 
    /**
     * If a shader can be created when we get its source.
index f1d3f7b3ce70e1d2acdb932d1baaa2bf5aafedfc..857a5444fcc56364df8f29374a82d16645dc68b7 100644 (file)
@@ -647,6 +647,9 @@ st_create_vp_variant(struct st_context *st,
 {
    struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
    struct pipe_context *pipe = st->pipe;
+
+   static const gl_state_index16 point_size_state[STATE_LENGTH] =
+      { STATE_INTERNAL, STATE_POINT_SIZE_CLAMPED, 0 };
    struct gl_program_parameter_list *params = stvp->Base.Parameters;
 
    vpv->key = *key;
@@ -671,6 +674,12 @@ st_create_vp_variant(struct st_context *st,
          vpv->num_inputs++;
       }
 
+      if (key->lower_point_size) {
+         _mesa_add_state_reference(params, point_size_state);
+         NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_point_size_mov,
+                    point_size_state);
+      }
+
       st_finalize_nir(st, &stvp->Base, stvp->shader_program,
                       vpv->tgsi.ir.nir);
 
index b84d219e3c8e2e44a04c06f63467fce409cf5b44..85934ee1df5781a1cb357625d41960d425f83c9d 100644 (file)
@@ -193,6 +193,9 @@ struct st_vp_variant_key
    /** both for ARB_depth_clamp */
    bool lower_depth_clamp;
    bool clip_negative_one_to_one;
+
+   /** lower glPointSize to gl_PointSize */
+   boolean lower_point_size;
 };