pan/compiler: Don't crash nopersp if pos is undefined

VS does not need to write the position, it can also leave it as
undefined.  We agree that there isn't much sense in noperspective
varyings with undefined perspective, but we still do not want to crash.
This does lead to some real crashes if we mistake some int varying to
noperspective (see next commit).

Signed-off-by: Lorenzo Rossi <lorenzo.rossi@collabora.com>
Reviewed-by: Christoph Pillmayer <christoph.pillmayer@arm.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40844>
This commit is contained in:
Lorenzo Rossi 2026-04-04 22:08:15 +02:00 committed by Marge Bot
parent 5607417f57
commit 6e67f2a996

View file

@ -256,8 +256,11 @@ pan_nir_lower_noperspective_vs(nir_shader *shader)
return false;
nir_intrinsic_instr *pos_store = find_pos_store(impl);
assert(pos_store);
assert(nir_intrinsic_write_mask(pos_store) & BITFIELD_BIT(3));
/* gl_Position may be written, it can also be left undefined */
bool has_pos_w =
pos_store && !!(nir_intrinsic_write_mask(pos_store) & BITFIELD_BIT(3));
if (!has_pos_w)
return false;
nir_builder b = nir_builder_at(nir_after_instr(&pos_store->instr));