zink: fix location usage for explicit xfb outputs
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 24 Feb 2021 19:53:51 +0000 (14:53 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 9 Mar 2021 02:52:20 +0000 (02:52 +0000)
ensure that this accurately handles multi-slot emission

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9271>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index 14403ad..be682c7 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "nir.h"
 #include "pipe/p_state.h"
+#include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/hash_table.h"
 
@@ -1249,6 +1250,7 @@ get_output_type(struct ntv_context *ctx, unsigned register_index, unsigned num_c
 static void
 emit_so_info(struct ntv_context *ctx, const struct zink_so_info *so_info)
 {
+   unsigned output = 0;
    for (unsigned i = 0; i < so_info->so_info.num_outputs; i++) {
       struct pipe_stream_output so_output = so_info->so_info.output[i];
       unsigned slot = so_info->so_info_slots[i] << 2 | so_output.start_component;
@@ -1260,7 +1262,7 @@ emit_so_info(struct ntv_context *ctx, const struct zink_so_info *so_info)
                                             SpvStorageClassOutput);
       char name[10];
 
-      snprintf(name, 10, "xfb%d", i);
+      snprintf(name, 10, "xfb%d", output);
       spirv_builder_emit_name(&ctx->builder, var_id, name);
       spirv_builder_emit_offset(&ctx->builder, var_id, (so_output.dst_offset * 4));
       spirv_builder_emit_xfb_buffer(&ctx->builder, var_id, so_output.output_buffer);
@@ -1272,8 +1274,8 @@ emit_so_info(struct ntv_context *ctx, const struct zink_so_info *so_info)
        * so we need to ensure that the new xfb location slot doesn't conflict with any previously-emitted
        * outputs.
        */
-      uint32_t location = ctx->shader_slots_reserved + i;
-      assert(location < VARYING_SLOT_VAR0);
+      uint32_t location = ctx->shader_slots_reserved + output;
+      assert(location < VARYING_SLOT_VAR0 && ctx->shader_slot_map[location] == SLOT_UNSET);
       spirv_builder_emit_location(&ctx->builder, var_id, location);
 
       /* note: gl_ClipDistance[4] can the 0-indexed member of VARYING_SLOT_CLIP_DIST1 here,
@@ -1288,6 +1290,7 @@ emit_so_info(struct ntv_context *ctx, const struct zink_so_info *so_info)
 
       assert(ctx->num_entry_ifaces < ARRAY_SIZE(ctx->entry_ifaces));
       ctx->entry_ifaces[ctx->num_entry_ifaces++] = var_id;
+      output += align(so_output.num_components, 4) / 4;
    }
 }