mesa/st: support lowering user-clip-planes automatically
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 25 Jul 2019 12:06:33 +0000 (14:06 +0200)
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 2a0c28aabc19af1f332ffedfdd024428f03daf77..05dcecd1c27c77b56de8d5f1a524a279e122276b 100644 (file)
@@ -398,6 +398,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
    case PIPE_CAP_ALPHA_TEST:
    case PIPE_CAP_POINT_SIZE_FIXED:
    case PIPE_CAP_TWO_SIDED_COLOR:
+   case PIPE_CAP_CLIP_PLANES:
       return 1;
 
    default:
index ffe104e8dc60d2b6c011109b3a45d50aa01a856a..a081bbc9f80909de718b20b45e6ad798767fb7be 100644 (file)
@@ -563,6 +563,7 @@ The integer capabilities:
 * ``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_CAP_CLIP_PLANES``: Driver supports user-defined clip-planes.
 
 .. _pipe_capf:
 
index ec446ad8de3b94866a77380d0d902ae240dd7722..2ddb31acbdc4283d8642a79d461afc1c8d4b7847 100644 (file)
@@ -908,6 +908,7 @@ enum pipe_cap
    PIPE_CAP_ALPHA_TEST,
    PIPE_CAP_POINT_SIZE_FIXED,
    PIPE_CAP_TWO_SIDED_COLOR,
+   PIPE_CAP_CLIP_PLANES,
 };
 
 /**
index c784ea8c59debdff3a81666edb865b2742b32519..b82b28f4d40c6bb31eaa8563e32dca255d0c5306 100644 (file)
@@ -226,6 +226,10 @@ st_update_vp( struct st_context *st )
       key.lower_point_size = st->lower_point_size &&
                              !st_point_size_per_vertex(st->ctx);
 
+      /* _NEW_TRANSFORM */
+      if (st->lower_ucp && st_user_clip_planes_enabled(st->ctx))
+         key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
+
       st->vp_variant = st_get_vp_variant(st, stvp, &key);
    }
 
index d0134bc3313d4a037b5b476e1c4955c6ec2bd894..8279562fa81ba3fefa86baa490cd25d0334d98f5 100644 (file)
@@ -529,7 +529,6 @@ st_init_driver_flags(struct st_context *st)
 
    f->NewClipControl = ST_NEW_VIEWPORT | ST_NEW_RASTERIZER;
    f->NewClipPlane = ST_NEW_CLIP_STATE;
-   f->NewClipPlaneEnable = ST_NEW_RASTERIZER;
 
    if (st->clamp_frag_depth_in_shader) {
       f->NewClipControl |= ST_NEW_VS_STATE | ST_NEW_GS_STATE |
@@ -541,6 +540,11 @@ st_init_driver_flags(struct st_context *st)
       f->NewDepthClamp = ST_NEW_RASTERIZER;
    }
 
+   if (st->lower_ucp)
+      f->NewClipPlaneEnable = ST_NEW_VS_STATE;
+   else
+      f->NewClipPlaneEnable = ST_NEW_RASTERIZER;
+
    f->NewLineState = ST_NEW_RASTERIZER;
    f->NewPolygonState = ST_NEW_RASTERIZER;
    f->NewPolygonStipple = ST_NEW_POLY_STIPPLE;
@@ -681,6 +685,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
       !screen->get_param(screen, PIPE_CAP_POINT_SIZE_FIXED);
    st->lower_two_sided_color =
       !screen->get_param(screen, PIPE_CAP_TWO_SIDED_COLOR);
+   st->lower_ucp =
+      !screen->get_param(screen, PIPE_CAP_CLIP_PLANES);
 
    st->has_hw_atomics =
       screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
@@ -745,7 +751,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
          st->has_shareable_shaders &&
          !st->clamp_frag_depth_in_shader &&
          !st->clamp_vert_color_in_shader &&
-         !st->lower_point_size;
+         !st->lower_point_size &&
+         !st->lower_ucp;
 
    st->shader_has_one_variant[MESA_SHADER_FRAGMENT] =
          st->has_shareable_shaders &&
index 159aecad5cff4d9c4d0df4398ba4fa5e102131c1..e29e1ed713f9d5082f8fb514d1e07239b062fc74 100644 (file)
@@ -151,6 +151,7 @@ struct st_context
    boolean lower_alpha_test;
    boolean lower_point_size;
    boolean lower_two_sided_color;
+   boolean lower_ucp;
 
    /**
     * If a shader can be created when we get its source.
index 205fc9561fe1ce6348af83d9a94c53eed73b3475..fb43cdd23524d08940b9870a8029b3ee1a58a5eb 100644 (file)
@@ -680,6 +680,31 @@ st_create_vp_variant(struct st_context *st,
                     point_size_state);
       }
 
+      if (key->lower_ucp) {
+         struct pipe_screen *screen = pipe->screen;
+         bool can_compact = screen->get_param(screen,
+                                              PIPE_CAP_NIR_COMPACT_ARRAYS);
+
+         bool use_eye = st->ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] != NULL;
+         gl_state_index16 clipplane_state[MAX_CLIP_PLANES][STATE_LENGTH];
+         for (int i = 0; i < MAX_CLIP_PLANES; ++i) {
+            if (use_eye) {
+               clipplane_state[i][0] = STATE_CLIPPLANE;
+               clipplane_state[i][1] = i;
+            } else {
+               clipplane_state[i][0] = STATE_INTERNAL;
+               clipplane_state[i][1] = STATE_CLIP_INTERNAL;
+               clipplane_state[i][2] = i;
+            }
+            _mesa_add_state_reference(params, clipplane_state[i]);
+         }
+
+         NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_clip_vs, key->lower_ucp,
+                    true, can_compact, clipplane_state);
+         NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_io_to_temporaries,
+                    nir_shader_get_entrypoint(vpv->tgsi.ir.nir), true, false);
+      }
+
       st_finalize_nir(st, &stvp->Base, stvp->shader_program,
                       vpv->tgsi.ir.nir);
 
index 53638db687a7a297cad0dc943c5854d7770227a1..b26ae8109370deca2601a0c8dab628b3ed2c246c 100644 (file)
@@ -199,6 +199,9 @@ struct st_vp_variant_key
 
    /** lower glPointSize to gl_PointSize */
    boolean lower_point_size;
+
+   /* for user-defined clip-planes */
+   uint8_t lower_ucp;
 };