Mesa (main): mesa/st: rework psiz lowering

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 4 02:23:15 UTC 2021


Module: Mesa
Branch: main
Commit: 8be35803a549f7075b6acfeeac2d0ce386ec8cf6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8be35803a549f7075b6acfeeac2d0ce386ec8cf6

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Jun 23 12:40:47 2021 -0400

mesa/st: rework psiz lowering

the context flag is immutable, and it's set by drivers that always
require the shader to export a psiz value for rasterization

"always" is all cases except GL_VERTEX_PROGRAM_POINT_SIZE being
enabled, in which case it should be assumed that the shader already
writes it, and no changes should be made

thus the shader key value can be changed to reflect that, when set,
it requires the shader to export a psiz value if it doesn't already

Acked-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13588>

---

 src/mesa/state_tracker/st_atom_shader.c | 20 ++++++++++-----
 src/mesa/state_tracker/st_program.c     | 45 ++++++++++++++++++---------------
 src/mesa/state_tracker/st_program.h     |  2 +-
 3 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index e5c3c48edd0..809cfa2c15a 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -250,9 +250,13 @@ st_update_vp( struct st_context *st )
       if (!st->ctx->GeometryProgram._Current &&
           !st->ctx->TessEvalProgram._Current) {
          /* _NEW_POINT */
-         key.lower_point_size = st->lower_point_size &&
-                                !st_point_size_per_vertex(st->ctx);
-
+         if (st->lower_point_size) {
+            if (st->ctx->API != API_OPENGLES2)
+               key.export_point_size = !st->ctx->VertexProgram.PointSizeEnabled;
+            else
+               /* PointSizeEnabled is always set in ES2 contexts */
+               key.export_point_size = true;
+         }
          /* _NEW_TRANSFORM */
          if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx))
             key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
@@ -320,9 +324,13 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
           pipe_shader == PIPE_SHADER_GEOMETRY)
          key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
 
-      key.lower_point_size = st->lower_point_size &&
-                             !st_point_size_per_vertex(st->ctx);
-
+      if (st->lower_point_size) {
+         if (st->ctx->API != API_OPENGLES2)
+            key.export_point_size = !st->ctx->VertexProgram.PointSizeEnabled;
+         else
+            /* PointSizeEnabled is always set in ES2 contexts */
+            key.export_point_size = true;
+      }
    }
 
    update_gl_clamp(st, prog, key.gl_clamp);
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index ece98763bb8..ad8055e3c55 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -792,26 +792,31 @@ st_create_common_variant(struct st_context *st,
          finalize = true;
       }
 
-      if (key->lower_point_size) {
-         _mesa_add_state_reference(params, point_size_state);
-         NIR_PASS_V(state.ir.nir, nir_lower_point_size_mov,
-                    point_size_state);
-
-         switch (stp->Base.info.stage) {
-         case MESA_SHADER_VERTEX:
-            stp->affected_states |= ST_NEW_VS_CONSTANTS;
-            break;
-         case MESA_SHADER_TESS_EVAL:
-            stp->affected_states |= ST_NEW_TES_CONSTANTS;
-            break;
-         case MESA_SHADER_GEOMETRY:
-            stp->affected_states |= ST_NEW_GS_CONSTANTS;
-            break;
-         default:
-            unreachable("bad shader stage");
-         }
+      if (key->export_point_size) {
+         /* if flag is set, shader must export psiz */
+         nir_shader *nir = state.ir.nir;
+         /* avoid clobbering existing psiz output */
+         if (!(nir->info.outputs_written & BITFIELD64_BIT(VARYING_SLOT_PSIZ))) {
+            _mesa_add_state_reference(params, point_size_state);
+            NIR_PASS_V(state.ir.nir, nir_lower_point_size_mov,
+                       point_size_state);
+
+            switch (stp->Base.info.stage) {
+            case MESA_SHADER_VERTEX:
+               stp->affected_states |= ST_NEW_VS_CONSTANTS;
+               break;
+            case MESA_SHADER_TESS_EVAL:
+               stp->affected_states |= ST_NEW_TES_CONSTANTS;
+               break;
+            case MESA_SHADER_GEOMETRY:
+               stp->affected_states |= ST_NEW_GS_CONSTANTS;
+               break;
+            default:
+               unreachable("bad shader stage");
+            }
 
-         finalize = true;
+            finalize = true;
+         }
       }
 
       if (key->lower_ucp) {
@@ -976,7 +981,7 @@ st_get_common_variant(struct st_context *st,
                           key->clamp_color ? "clamp_color," : "",
                           key->lower_depth_clamp ? "depth_clamp," : "",
                           key->clip_negative_one_to_one ? "clip_negative_one," : "",
-                          key->lower_point_size ? "point_size," : "",
+                          key->export_point_size ? "point_size," : "",
                           key->lower_ucp ? "ucp," : "",
                           key->is_draw_shader ? "draw," : "",
                           key->gl_clamp[0] || key->gl_clamp[1] || key->gl_clamp[2] ? "GL_CLAMP," : "");
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index af8c32fc3cf..163359ade96 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -226,7 +226,7 @@ struct st_common_variant_key
    bool clip_negative_one_to_one;
 
    /** lower glPointSize to gl_PointSize */
-   boolean lower_point_size;
+   boolean export_point_size;
 
    /* for user-defined clip-planes */
    uint8_t lower_ucp;



More information about the mesa-commit mailing list