st/mesa: Enable clip planes lowering for geometry shaders
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>
Mon, 29 Jun 2020 07:21:54 +0000 (03:21 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 17 Aug 2020 10:10:07 +0000 (10:10 +0000)
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6218>

src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_program.c

index b349c2a1f17eb637f300e254be86a9e44fcb14da..d92a542922e69e174df8ecc5cf778b37acaa8764 100644 (file)
@@ -228,7 +228,8 @@ st_update_vp( struct st_context *st )
                              !st_point_size_per_vertex(st->ctx);
 
       /* _NEW_TRANSFORM */
-      if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx))
+      if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx) &&
+          !st->ctx->GeometryProgram._Current)
          key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
 
       st->vp_variant = st_get_vp_variant(st, stvp, &key);
@@ -285,6 +286,9 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
          key.clip_negative_one_to_one =
                st->ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE;
 
+      if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx) &&
+          pipe_shader == PIPE_SHADER_GEOMETRY)
+         key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
    }
 
    return st_get_common_variant(st, stp, &key)->driver_shader;
index 490e959d6da382f2aa53e448dffc052385dd3202..6c8ba9dd73254cae75d24573b58e2e141a293e31 100644 (file)
@@ -553,7 +553,7 @@ st_init_driver_flags(struct st_context *st)
    }
 
    if (st->lower_ucp)
-      f->NewClipPlaneEnable = ST_NEW_VS_STATE;
+      f->NewClipPlaneEnable = ST_NEW_VS_STATE | ST_NEW_GS_STATE;
    else
       f->NewClipPlaneEnable = ST_NEW_RASTERIZER;
 
@@ -722,10 +722,7 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
    assert(!ctx->Extensions.OES_geometry_shader || !st->lower_point_size);
    assert(!ctx->Extensions.ARB_tessellation_shader || !st->lower_point_size);
 
-   /* FIXME: add support for geometry and tessellation shaders for
-    * lower_ucp
-    */
-   assert(!ctx->Extensions.OES_geometry_shader || !st->lower_ucp);
+   /* FIXME: add support for tessellation shaders for lower_ucp */
    assert(!ctx->Extensions.ARB_tessellation_shader || !st->lower_ucp);
 
    if (st_have_perfmon(st)) {
@@ -808,7 +805,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
    st->shader_has_one_variant[MESA_SHADER_GEOMETRY] =
          st->has_shareable_shaders &&
          !st->clamp_frag_depth_in_shader &&
-         !st->clamp_vert_color_in_shader;
+         !st->clamp_vert_color_in_shader &&
+         !st->lower_ucp;
    st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders;
 
    st->bitmap.cache.empty = true;
index aad4d4d99225d2b7af8f0cd6fbabfe78ccd577c7..7e7373dc85e91b5950153df40ab4ebcf08d6bc90 100644 (file)
@@ -695,8 +695,14 @@ lower_ucp(struct st_context *st,
          _mesa_add_state_reference(params, clipplane_state[i]);
       }
 
-      NIR_PASS_V(nir, nir_lower_clip_vs, ucp_enables,
-                 true, can_compact, clipplane_state);
+      if (nir->info.stage == MESA_SHADER_VERTEX) {
+         NIR_PASS_V(nir, nir_lower_clip_vs, ucp_enables,
+                    true, can_compact, clipplane_state);
+      } else if (nir->info.stage == MESA_SHADER_GEOMETRY) {
+         NIR_PASS_V(nir, nir_lower_clip_gs, ucp_enables,
+                    can_compact, clipplane_state);
+      }
+
       NIR_PASS_V(nir, nir_lower_io_to_temporaries,
                  nir_shader_get_entrypoint(nir), true, false);
       NIR_PASS_V(nir, nir_lower_global_vars_to_local);
@@ -1782,6 +1788,7 @@ st_get_common_variant(struct st_context *st,
    struct pipe_context *pipe = st->pipe;
    struct st_variant *v;
    struct pipe_shader_state state = {0};
+   struct gl_program_parameter_list *params = prog->Base.Parameters;
 
    /* Search for existing variant */
    for (v = prog->variants; v; v = v->next) {
@@ -1804,6 +1811,11 @@ st_get_common_variant(struct st_context *st,
                finalize = true;
             }
 
+            if (key->lower_ucp) {
+               lower_ucp(st, state.ir.nir, key->lower_ucp, params);
+               finalize = true;
+            }
+
             state.stream_output = prog->state.stream_output;
 
             if (finalize || !st->allow_st_finalize_nir_twice) {