diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index e5c3c48edd0..809cfa2c15a 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -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); diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index ece98763bb8..ad8055e3c55 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -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," : ""); diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index af8c32fc3cf..163359ade96 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -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;