zink: use ralloc for spirv_builder as well
[mesa.git] / src / gallium / drivers / zink / nir_to_spirv / nir_to_spirv.c
index 44eade4e25a8ab9f389055886c58c0c590a7d5f0..3d1e56d5f0e94765c31b33c27abe96335286b2d6 100644 (file)
@@ -917,7 +917,7 @@ emit_so_info(struct ntv_context *ctx, unsigned max_output_location,
       if (so_output.start_component)
          spirv_builder_emit_component(&ctx->builder, var_id, so_output.start_component);
 
-      uint32_t *key = ralloc_size(NULL, sizeof(uint32_t));
+      uint32_t *key = ralloc_size(ctx->mem_ctx, sizeof(uint32_t));
       *key = (uint32_t)so_output.register_index << 2 | so_output.start_component;
       _mesa_hash_table_insert(ctx->so_outputs, key, (void *)(intptr_t)var_id);
 
@@ -2171,6 +2171,7 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
 
    struct ntv_context ctx = {};
    ctx.mem_ctx = ralloc_context(NULL);
+   ctx.builder.mem_ctx = ctx.mem_ctx;
 
    switch (s->info.stage) {
    case MESA_SHADER_VERTEX:
@@ -2274,18 +2275,21 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
    nir_function_impl *entry = nir_shader_get_entrypoint(s);
    nir_metadata_require(entry, nir_metadata_block_index);
 
-   ctx.defs = (SpvId *)malloc(sizeof(SpvId) * entry->ssa_alloc);
+   ctx.defs = ralloc_array_size(ctx.mem_ctx,
+                                sizeof(SpvId), entry->ssa_alloc);
    if (!ctx.defs)
       goto fail;
    ctx.num_defs = entry->ssa_alloc;
 
    nir_index_local_regs(entry);
-   ctx.regs = malloc(sizeof(SpvId) * entry->reg_alloc);
+   ctx.regs = ralloc_array_size(ctx.mem_ctx,
+                                sizeof(SpvId), entry->reg_alloc);
    if (!ctx.regs)
       goto fail;
    ctx.num_regs = entry->reg_alloc;
 
-   SpvId *block_ids = (SpvId *)malloc(sizeof(SpvId) * entry->num_blocks);
+   SpvId *block_ids = ralloc_array_size(ctx.mem_ctx,
+                                        sizeof(SpvId), entry->num_blocks);
    if (!block_ids)
       goto fail;
 
@@ -2310,8 +2314,6 @@ nir_to_spirv(struct nir_shader *s, const struct pipe_stream_output_info *so_info
 
    emit_cf_list(&ctx, &entry->body);
 
-   free(ctx.defs);
-
    if (so_info)
       emit_so_outputs(&ctx, so_info, local_so_info);