zink: use ralloc in nir-to-spirv
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 17 Jul 2020 16:52:13 +0000 (18:52 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Jul 2020 17:33:34 +0000 (17:33 +0000)
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5954>

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

index 6c4c91b09277a37cb34124836c74b77e52057d73..44eade4e25a8ab9f389055886c58c0c590a7d5f0 100644 (file)
@@ -90,6 +90,8 @@ static unsigned slot_pack_map[] = {
 #define NTV_MIN_RESERVED_SLOTS 11
 
 struct ntv_context {
+   void *mem_ctx;
+
    struct spirv_builder builder;
 
    SpvId GLSL_std_450;
@@ -2168,6 +2170,7 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
    struct spirv_shader *ret = NULL;
 
    struct ntv_context ctx = {};
+   ctx.mem_ctx = ralloc_context(NULL);
 
    switch (s->info.stage) {
    case MESA_SHADER_VERTEX:
@@ -2233,10 +2236,10 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
    SpvId entry_point = spirv_builder_new_id(&ctx.builder);
    spirv_builder_emit_name(&ctx.builder, entry_point, "main");
 
-   ctx.vars = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
+   ctx.vars = _mesa_hash_table_create(ctx.mem_ctx, _mesa_hash_pointer,
                                       _mesa_key_pointer_equal);
 
-   ctx.so_outputs = _mesa_hash_table_create(NULL, _mesa_hash_u32,
+   ctx.so_outputs = _mesa_hash_table_create(ctx.mem_ctx, _mesa_hash_u32,
                                             _mesa_key_u32_equal);
 
    nir_foreach_variable(var, &s->inputs)
@@ -2332,19 +2335,16 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
    ret->num_words = spirv_builder_get_words(&ctx.builder, ret->words, num_words);
    assert(ret->num_words == num_words);
 
+   ralloc_free(ctx.mem_ctx);
+
    return ret;
 
 fail:
+   ralloc_free(ctx.mem_ctx);
 
    if (ret)
       spirv_shader_delete(ret);
 
-   if (ctx.vars)
-      _mesa_hash_table_destroy(ctx.vars, NULL);
-
-   if (ctx.so_outputs)
-      _mesa_hash_table_destroy(ctx.so_outputs, NULL);
-
    return NULL;
 }