From f3d046af6ac3a124e4565b13075ef0b37e88e72d Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 12 Jan 2023 12:59:58 -0500 Subject: [PATCH] zink: simplify get_slot_components() for xfb emission multiplying by the array size is always wrong for this case, and not doing so allows for some simplification and better inlining, though the output results are identical the one corner case is clip/cull distance, which need special handling since they're arrays with vec semantics Part-of: --- src/gallium/drivers/zink/zink_compiler.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 39be4f5ba42..30a8247fb05 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -1365,10 +1365,15 @@ get_slot_components(nir_variable *var, unsigned slot, unsigned so_slot) /* arrays here are already fully unrolled from their structs, so slot handling is implicit */ unsigned num_components = glsl_get_components(glsl_without_array(type)); - const struct glsl_type *arraytype = orig_type; - while (glsl_type_is_array(arraytype) && !glsl_type_is_struct_or_ifc(glsl_without_array(arraytype))) { - num_components *= glsl_array_size(arraytype); - arraytype = glsl_get_array_element(arraytype); + /* special handling: clip/cull distance are arrays with vector semantics */ + if (var->data.location == VARYING_SLOT_CLIP_DIST0 || var->data.location == VARYING_SLOT_CULL_DIST0) { + num_components = glsl_array_size(type); + if (slot_idx) + /* this is the second vec4 */ + num_components %= 4; + else + /* this is the first vec4 */ + num_components = MIN2(num_components, 4); } assert(num_components); /* gallium handles xfb in terms of 32bit units */ @@ -1495,8 +1500,6 @@ update_so_info(struct zink_shader *zs, const struct pipe_stream_output_info *so_ /* if all the components the variable exports to this slot aren't captured, skip consolidation */ unsigned num_components = get_slot_components(var, slot, var->data.location); - if (glsl_type_is_array(var->type) && !glsl_type_is_struct_or_ifc(glsl_without_array(var->type))) - num_components /= glsl_array_size(var->type); if (num_components != packed_components[slot]) goto out;