From 9cf6163ea1ac4f77d21dd06b1843c8314f4a0c99 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 12 Jun 2019 18:54:29 +0200 Subject: [PATCH] zink: emit dedicated block for variables Acked-by: Jordan Justen --- .../drivers/zink/nir_to_spirv/nir_to_spirv.c | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index c465a866d24..1cfc821cc3b 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -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); -- 2.30.2