nir: fix nir_link_varying_precision

link_varyings ignores precisions and can assign the same location to
variables with different precisions.  nir_link_varying_precision should
check location_frac as well.

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20113>
(cherry picked from commit 7244d88516)
This commit is contained in:
Chia-I Wu 2022-12-01 11:17:04 -08:00 committed by Eric Engestrom
parent 7b5ba2d363
commit 3ef6b27bde
2 changed files with 15 additions and 3 deletions

View file

@ -3550,7 +3550,7 @@
"description": "nir: fix nir_link_varying_precision",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -1322,6 +1322,18 @@ nir_link_precision(unsigned producer, unsigned consumer, bool fs)
return fs ? MAX2(producer, consumer) : consumer;
}
static nir_variable *
find_consumer_variable(const nir_shader *consumer,
const nir_variable *producer_var)
{
nir_foreach_variable_with_modes(var, consumer, nir_var_shader_in) {
if (var->data.location == producer_var->data.location &&
var->data.location_frac == producer_var->data.location_frac)
return var;
}
return NULL;
}
void
nir_link_varying_precision(nir_shader *producer, nir_shader *consumer)
{
@ -1332,8 +1344,8 @@ nir_link_varying_precision(nir_shader *producer, nir_shader *consumer)
if (producer_var->data.location < 0)
continue;
nir_variable *consumer_var = nir_find_variable_with_location(consumer,
nir_var_shader_in, producer_var->data.location);
nir_variable *consumer_var = find_consumer_variable(consumer,
producer_var);
/* Skip if the variable will be eliminated */
if (!consumer_var)