mesa/st: support lowering user-clip-planes automatically

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Erik Faye-Lund 2019-07-25 14:06:33 +02:00
parent 439f499591
commit 3298aedd6e
8 changed files with 45 additions and 2 deletions

View 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:

View 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:

View 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,
};
/**

View 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);
}

View 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 &&

View 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.

View 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);

View 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;
};