nir: fix slot calculations for compact variables with location_frac

a variable with a component offset may span multiple slots, and this cannot
be inferred from its type alone (e.g., compacted clip+cull distances)

cc: mesa-stable

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24163>
(cherry picked from commit 59396eefe6)
This commit is contained in:
Mike Blumenkrantz 2023-07-14 12:18:05 -04:00 committed by Dylan Baker
parent 6fd9633b57
commit 4ce8ed7bbe
6 changed files with 8 additions and 8 deletions

View file

@ -22594,7 +22594,7 @@
"description": "nir: fix slot calculations for compact variables with location_frac",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -211,7 +211,7 @@ mark_whole_variable(nir_shader *shader, nir_variable *var,
}
const unsigned slots =
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4)
: glsl_count_attribute_slots(type, false);
set_io_mask(shader, var, 0, slots, deref, is_output_read);
@ -288,7 +288,7 @@ try_mask_partial_io(nir_shader *shader, nir_variable *var,
return false;
const unsigned slots =
var->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4)
var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4)
: glsl_count_attribute_slots(type, false);
if (offset >= slots) {

View file

@ -927,7 +927,7 @@ tu_gather_xfb_info(nir_shader *nir, struct ir3_stream_output_info *info)
nir_foreach_shader_out_variable(var, nir) {
unsigned slots =
var->data.compact ? DIV_ROUND_UP(glsl_get_length(var->type), 4)
var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(var->type), 4)
: glsl_count_attribute_slots(var->type, false);
for (unsigned i = 0; i < slots; i++)
output_map[var->data.location + i] = var->data.driver_location + i;

View file

@ -477,7 +477,7 @@ void nir_tgsi_scan_shader(const struct nir_shader *nir,
type = glsl_get_array_element(type);
}
unsigned attrib_count = variable->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4) :
unsigned attrib_count = variable->data.compact ? DIV_ROUND_UP(variable->data.location_frac + glsl_get_length(type), 4) :
glsl_count_attribute_slots(type, nir->info.stage == MESA_SHADER_VERTEX);
i = variable->data.driver_location;
@ -577,7 +577,7 @@ void nir_tgsi_scan_shader(const struct nir_shader *nir,
type = glsl_get_array_element(type);
}
unsigned attrib_count = variable->data.compact ? DIV_ROUND_UP(glsl_get_length(type), 4) :
unsigned attrib_count = variable->data.compact ? DIV_ROUND_UP(variable->data.location_frac + glsl_get_length(type), 4) :
glsl_count_attribute_slots(type, false);
for (unsigned k = 0; k < attrib_count; k++, i++) {

View file

@ -527,7 +527,7 @@ lvp_shader_xfb_init(struct lvp_shader *shader)
memset(output_mapping, 0, sizeof(output_mapping));
nir_foreach_shader_out_variable(var, shader->pipeline_nir->nir) {
unsigned slots = var->data.compact ? DIV_ROUND_UP(glsl_get_length(var->type), 4)
unsigned slots = var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(var->type), 4)
: glsl_count_attribute_slots(var->type, false);
for (unsigned i = 0; i < slots; i++)
output_mapping[var->data.location + i] = var->data.driver_location + i;

View file

@ -70,7 +70,7 @@ fs_visitor::nir_setup_outputs()
nir_foreach_shader_out_variable(var, nir) {
const int loc = var->data.driver_location;
const unsigned var_vec4s =
var->data.compact ? DIV_ROUND_UP(glsl_get_length(var->type), 4)
var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(var->type), 4)
: type_size_vec4(var->type, true);
vec4s[loc] = MAX2(vec4s[loc], var_vec4s);
}