zink: emit dedicated block for variables
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 12 Jun 2019 16:54:29 +0000 (18:54 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 28 Oct 2019 08:51:44 +0000 (08:51 +0000)
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index c465a866d249e05f756709862f0211b91c4e75e2..1cfc821cc3b7f6731b28dcadbb31f64ace21565c 100644 (file)
@@ -396,17 +396,7 @@ static SpvId
 get_var_from_reg(struct ntv_context *ctx, nir_register *reg)
 {
    struct hash_entry *he = _mesa_hash_table_search(ctx->vars, reg);
-   if (!he) {
-      SpvId type = get_uvec_type(ctx, reg->bit_size, reg->num_components);
-      SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
-                                                      SpvStorageClassFunction,
-                                                      type);
-
-      SpvId var = spirv_builder_emit_var(&ctx->builder, pointer_type,
-                                         SpvStorageClassFunction);
-
-      he = _mesa_hash_table_insert(ctx->vars, reg, (void *)(intptr_t)var);
-   }
+   assert(he);
    return (SpvId)(intptr_t)he->data;
 }
 
@@ -1452,6 +1442,20 @@ nir_to_spirv(struct nir_shader *s)
    ctx.block_ids = block_ids;
    ctx.num_blocks = entry->num_blocks;
 
+   /* emit a block only for the variable declarations */
+   start_block(&ctx, spirv_builder_new_id(&ctx.builder));
+   foreach_list_typed(nir_register, reg, node, &entry->registers) {
+      SpvId type = get_uvec_type(&ctx, reg->bit_size, reg->num_components);
+      SpvId pointer_type = spirv_builder_type_pointer(&ctx.builder,
+                                                      SpvStorageClassFunction,
+                                                      type);
+      SpvId var = spirv_builder_emit_var(&ctx.builder, pointer_type,
+                                         SpvStorageClassFunction);
+
+      if (!_mesa_hash_table_insert(ctx.vars, reg, (void *)(intptr_t)var))
+         goto fail;
+   }
+
    emit_cf_list(&ctx, &entry->body);
 
    free(ctx.defs);