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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13588>
This commit is contained in:
Mike Blumenkrantz 2021-06-23 12:40:47 -04:00 committed by Marge Bot
parent 97c3b658b3
commit 8be35803a5
3 changed files with 39 additions and 26 deletions

View file

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

View file

@ -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);
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");
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," : "");

View file

@ -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;