summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2019-07-25 14:06:33 +0200
committerErik Faye-Lund <[email protected]>2019-10-17 10:41:36 +0200
commit3298aedd6e9f12cefd5aa7414eeebf69ce7538d1 (patch)
tree3f66f56ef46a76e625aed9820c81e51543c3a6e5
parent439f4995916c3be4260217d5b10f450c9b3b3aa7 (diff)
mesa/st: support lowering user-clip-planes automatically
Reviewed-by: Marek Olšák <[email protected]>
-rw-r--r--src/gallium/auxiliary/util/u_screen.c1
-rw-r--r--src/gallium/docs/source/screen.rst1
-rw-r--r--src/gallium/include/pipe/p_defines.h1
-rw-r--r--src/mesa/state_tracker/st_atom_shader.c4
-rw-r--r--src/mesa/state_tracker/st_context.c11
-rw-r--r--src/mesa/state_tracker/st_context.h1
-rw-r--r--src/mesa/state_tracker/st_program.c25
-rw-r--r--src/mesa/state_tracker/st_program.h3
8 files changed, 45 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c
index 2a0c28aabc1..05dcecd1c27 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -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:
diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
index ffe104e8dc6..a081bbc9f80 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -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:
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index ec446ad8de3..2ddb31acbdc 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -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,
};
/**
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index c784ea8c59d..b82b28f4d40 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -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);
}
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index d0134bc3313..8279562fa81 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -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 &&
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 159aecad5cf..e29e1ed713f 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -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.
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 205fc9561fe..fb43cdd2352 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 53638db687a..b26ae810937 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -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;
};