nir: Add a type parameter to nir_lower_point_size()

On Mali, we need not only clamp but also convert to float16 on Valhall+.
We could have a separate pass for this but it fits in nicely with the
rest of nir_lower_point_size() so we might as well put it there.

Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38379>
This commit is contained in:
Faith Ekstrand 2025-11-11 13:22:24 -05:00 committed by Marge Bot
parent 5af8abbf8b
commit 6ee4ea5ea3
11 changed files with 48 additions and 22 deletions

View file

@ -1046,7 +1046,7 @@ hk_lower_hw_vs(nir_shader *nir, struct hk_shader *shader, bool kill_psiz)
*
* Must be synced with pointSizeRange.
*/
NIR_PASS(_, nir, nir_lower_point_size, 1.0f, 511.95f);
NIR_PASS(_, nir, nir_lower_point_size, 1.0f, 511.95f, nir_type_invalid);
if (kill_psiz) {
NIR_PASS(_, nir, nir_shader_intrinsics_pass, kill_psiz_write,

View file

@ -1035,7 +1035,7 @@ v3d_nir_lower_vs_early(struct v3d_compile *c)
/* This must go before nir_lower_io */
if (c->vs_key->per_vertex_point_size)
NIR_PASS(_, c->s, nir_lower_point_size, 1.0f, 0.0f);
NIR_PASS(_, c->s, nir_lower_point_size, 1.0f, 0.0f, nir_type_invalid);
NIR_PASS(_, c->s, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
type_size_vec4,
@ -1077,7 +1077,7 @@ v3d_nir_lower_gs_early(struct v3d_compile *c)
/* This must go before nir_lower_io */
if (c->gs_key->per_vertex_point_size)
NIR_PASS(_, c->s, nir_lower_point_size, 1.0f, 0.0f);
NIR_PASS(_, c->s, nir_lower_point_size, 1.0f, 0.0f, nir_type_invalid);
NIR_PASS(_, c->s, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
type_size_vec4,

View file

@ -6060,7 +6060,8 @@ typedef struct nir_tex_src_type_constraint {
bool nir_legalize_16bit_sampler_srcs(nir_shader *nir,
nir_tex_src_type_constraints constraints);
bool nir_lower_point_size(nir_shader *shader, float min, float max);
bool nir_lower_point_size(nir_shader *shader, float min, float max,
nir_alu_type type);
bool nir_lower_default_point_size(nir_shader *nir);

View file

@ -23,6 +23,12 @@
#include "nir_builder.h"
struct lower_point_size_options {
float min;
float max;
nir_alu_type type;
};
/** @file nir_lower_point_size.c
*
* The OpenGL spec requires that implementations clamp gl_PointSize to an
@ -35,7 +41,7 @@
static bool
lower_point_size_intrin(nir_builder *b, nir_intrinsic_instr *intr, void *data)
{
float *minmax = (float *)data;
const struct lower_point_size_options *opts = data;
gl_varying_slot location = VARYING_SLOT_MAX;
nir_src *psiz_src;
@ -62,11 +68,22 @@ lower_point_size_intrin(nir_builder *b, nir_intrinsic_instr *intr, void *data)
nir_def *psiz = psiz_src->ssa;
assert(psiz->num_components == 1);
if (minmax[0] > 0.0f)
psiz = nir_fmax(b, psiz, nir_imm_float(b, minmax[0]));
if (opts->min > 0.0f)
psiz = nir_fmax(b, psiz, nir_imm_float(b, opts->min));
if (minmax[1] > 0.0f)
psiz = nir_fmin(b, psiz, nir_imm_float(b, minmax[1]));
if (opts->max > 0.0f)
psiz = nir_fmin(b, psiz, nir_imm_float(b, opts->max));
if (opts->type != nir_type_invalid) {
/* Currently only supported for lowered I/O */
assert(intr->intrinsic != nir_intrinsic_store_deref);
nir_alu_type old_type = nir_intrinsic_src_type(intr);
if (old_type != opts->type) {
psiz = nir_type_convert(b, psiz, old_type, opts->type,
nir_rounding_mode_undef);
nir_intrinsic_set_src_type(intr, opts->type);
}
}
nir_src_rewrite(psiz_src, psiz);
@ -75,10 +92,13 @@ lower_point_size_intrin(nir_builder *b, nir_intrinsic_instr *intr, void *data)
/**
* Clamps gl_PointSize to the range [min, max]. If either min or max are not
* greater than 0 then no clamping is done for that side of the range.
* greater than 0 then no clamping is done for that side of the range. If
* type is not nir_type_invalid, the value is converted and the type on the
* store is updated accordingly.
*/
bool
nir_lower_point_size(nir_shader *s, float min, float max)
nir_lower_point_size(nir_shader *s, float min, float max,
nir_alu_type type)
{
assert(s->info.stage != MESA_SHADER_FRAGMENT &&
s->info.stage != MESA_SHADER_COMPUTE);
@ -86,10 +106,14 @@ nir_lower_point_size(nir_shader *s, float min, float max)
assert(min > 0.0f || max > 0.0f);
assert(min <= 0.0f || max <= 0.0f || min <= max);
float minmax[] = { min, max };
struct lower_point_size_options options = {
.min = min,
.max = max,
.type = type,
};
return nir_shader_intrinsics_pass(s, lower_point_size_intrin,
nir_metadata_control_flow,
minmax);
&options);
}
/*

View file

@ -1189,7 +1189,7 @@ crocus_compile_vs(struct crocus_context *ice,
}
if (key->clamp_pointsize)
nir_lower_point_size(nir, 1.0, 255.0);
nir_lower_point_size(nir, 1.0, 255.0, nir_type_invalid);
prog_data->use_alt_mode = nir->info.use_legacy_math_rules;
@ -1548,7 +1548,7 @@ crocus_compile_tes(struct crocus_context *ice,
}
if (key->clamp_pointsize)
nir_lower_point_size(nir, 1.0, 255.0);
nir_lower_point_size(nir, 1.0, 255.0, nir_type_invalid);
crocus_setup_uniforms(devinfo, mem_ctx, nir, prog_data, &system_values,
&num_system_values, &num_cbufs);
@ -1691,7 +1691,7 @@ crocus_compile_gs(struct crocus_context *ice,
}
if (key->clamp_pointsize)
nir_lower_point_size(nir, 1.0, 255.0);
nir_lower_point_size(nir, 1.0, 255.0, nir_type_invalid);
crocus_setup_uniforms(devinfo, mem_ctx, nir, prog_data, &system_values,
&num_system_values, &num_cbufs);

View file

@ -673,7 +673,7 @@ i915_create_vs_state(struct pipe_context *pipe,
if (templ->type == PIPE_SHADER_IR_NIR) {
nir_shader *s = templ->ir.nir;
NIR_PASS(_, s, nir_lower_point_size, 1.0, 255.0);
NIR_PASS(_, s, nir_lower_point_size, 1.0, 255.0, nir_type_invalid);
/* The gallivm draw path doesn't support non-native-integers NIR shaders,
* st/mesa does native-integers for the screen as a whole rather than

View file

@ -115,7 +115,7 @@ lima_program_optimize_vs_nir(struct nir_shader *s)
bool progress;
NIR_PASS(_, s, nir_lower_viewport_transform);
NIR_PASS(_, s, nir_lower_point_size, 1.0f, 100.0f);
NIR_PASS(_, s, nir_lower_point_size, 1.0f, 100.0f, nir_type_invalid);
NIR_PASS(_, s, nir_lower_io,
nir_var_shader_in | nir_var_shader_out, type_size, 0);
NIR_PASS(_, s, nir_lower_load_const_to_scalar);

View file

@ -2509,7 +2509,7 @@ vc4_shader_state_create(struct pipe_context *pctx,
}
if (s->info.stage == MESA_SHADER_VERTEX)
NIR_PASS(_, s, nir_lower_point_size, 1.0f, 0.0f);
NIR_PASS(_, s, nir_lower_point_size, 1.0f, 0.0f, nir_type_invalid);
NIR_PASS(_, s, nir_lower_io,
nir_var_shader_in | nir_var_shader_out | nir_var_uniform,

View file

@ -929,7 +929,8 @@ void pco_lower_nir(pco_ctx *ctx, nir_shader *nir, pco_data *data)
nir,
nir_lower_point_size,
PVR_POINT_SIZE_RANGE_MIN,
PVR_POINT_SIZE_RANGE_MAX);
PVR_POINT_SIZE_RANGE_MAX,
nir_type_invalid);
if (!nir->info.internal)
NIR_PASS(_, nir, pco_nir_point_size);

View file

@ -6115,7 +6115,7 @@ bifrost_postprocess_nir(nir_shader *nir, unsigned gpu_id)
NIR_PASS(_, nir, bifrost_nir_lower_load_output);
} else if (nir->info.stage == MESA_SHADER_VERTEX) {
NIR_PASS(_, nir, nir_lower_viewport_transform);
NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0);
NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0, nir_type_invalid);
NIR_PASS(_, nir, pan_nir_lower_noperspective_vs);
if (pan_arch(gpu_id) >= 9) {

View file

@ -396,7 +396,7 @@ midgard_postprocess_nir(nir_shader *nir, UNUSED unsigned gpu_id)
if (nir->info.stage == MESA_SHADER_VERTEX) {
NIR_PASS(_, nir, nir_lower_viewport_transform);
NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0);
NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0, nir_type_invalid);
/* nir_lower[_explicit]_io is lazy and emits mul+add chains even
* for offsets it could figure out are constant. Do some