nir/gather_info: fix partial masking of compact I/O with location_frac!=0

nir_lower_clip_cull_distance_arrays() can create compact variables with
location_frac!=0.

Fixes: cc7a187411 ("nir/gather_info: implement partial masking of struct and compact I/O")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4554
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10002>
This commit is contained in:
Rhys Perry
2021-04-02 10:17:25 +01:00
committed by Marge Bot
parent b927de8b7f
commit 5f62083c26

View File

@@ -194,8 +194,15 @@ mark_whole_variable(nir_shader *shader, nir_variable *var,
}
static unsigned
get_io_offset(nir_deref_instr *deref, bool compact, bool per_vertex)
get_io_offset(nir_deref_instr *deref, nir_variable *var, bool per_vertex)
{
if (var->data.compact) {
assert(deref->deref_type == nir_deref_type_array);
return nir_src_is_const(deref->arr.index) ?
(nir_src_as_uint(deref->arr.index) + var->data.location_frac) / 4u :
(unsigned)-1;
}
unsigned offset = 0;
for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {
@@ -206,9 +213,6 @@ get_io_offset(nir_deref_instr *deref, bool compact, bool per_vertex)
if (!nir_src_is_const(d->arr.index))
return -1;
if (compact)
offset += nir_src_as_uint(d->arr.index) / 4;
else
offset += glsl_count_attribute_slots(d->type, false) *
nir_src_as_uint(d->arr.index);
} else if (d->deref_type == nir_deref_type_struct) {
@@ -246,7 +250,7 @@ try_mask_partial_io(nir_shader *shader, nir_variable *var,
if (var->data.per_view)
return false;
unsigned offset = get_io_offset(deref, var->data.compact, per_vertex);
unsigned offset = get_io_offset(deref, var, per_vertex);
if (offset == -1)
return false;