Module: Mesa
Branch: main
Commit: f3d046af6ac3a124e4565b13075ef0b37e88e72d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f3d046af6ac3a124e4565b13075ef0b37e88e72d

Author: Mike Blumenkrantz <[email protected]>
Date:   Thu Jan 12 12:59:58 2023 -0500

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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20678>

---

 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;
 

Reply via email to