[Mesa-dev] [PATCH 04/15] ralloc: use rzalloc where it's necessary

Marek Olšák maraeo at gmail.com
Sat Oct 8 10:58:28 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

No change in behavior. ralloc_size is equivalent to rzalloc_size.
That will change though.

Calls not switched to rzalloc_size:
- ralloc_vasprintf
- glsl_type::name allocation (it's filled with snprintf)
- C++ classes where valgrind didn't show uninitialized values

I switched most of non-glsl stuff to rzalloc without checking whether
it's really needed.
---
 src/compiler/glsl/ast.h                     | 2 +-
 src/compiler/glsl/ast_to_hir.cpp            | 4 ++--
 src/compiler/glsl/glsl_parser_extras.h      | 2 +-
 src/compiler/glsl/link_uniform_blocks.cpp   | 2 +-
 src/compiler/glsl/list.h                    | 2 +-
 src/compiler/nir/nir.c                      | 8 +++++---
 src/compiler/spirv/vtn_variables.c          | 3 ++-
 src/gallium/drivers/freedreno/ir3/ir3.c     | 2 +-
 src/gallium/drivers/vc4/vc4_cl.c            | 2 +-
 src/gallium/drivers/vc4/vc4_program.c       | 2 +-
 src/gallium/drivers/vc4/vc4_simulator.c     | 5 +++--
 src/mesa/drivers/dri/i965/brw_state_batch.c | 5 +++--
 12 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
index 4c648d0..0713582 100644
--- a/src/compiler/glsl/ast.h
+++ b/src/compiler/glsl/ast.h
@@ -42,21 +42,21 @@ struct YYLTYPE;
  * syntactic checking is done.  Symantic checking is performed by a later
  * stage that converts the AST to a more generic intermediate representation.
  *
  *@{
  */
 /**
  * Base class of all abstract syntax tree nodes
  */
 class ast_node {
 public:
-   DECLARE_RALLOC_CXX_OPERATORS(ast_node);
+   DECLARE_RZALLOC_CXX_OPERATORS(ast_node);
 
    /**
     * Print an AST node in something approximating the original GLSL code
     */
    virtual void print(void) const;
 
    /**
     * Convert the AST node to the high-level intermediate representation
     */
    virtual ir_rvalue *hir(exec_list *instructions,
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 2ad97d9..7efd7a4 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -6619,22 +6619,22 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
     */
    foreach_list_typed (ast_declarator_list, decl_list, link, declarations) {
       decl_count += decl_list->declarations.length();
    }
 
    /* Allocate storage for the fields and process the field
     * declarations.  As the declarations are processed, try to also convert
     * the types to HIR.  This ensures that structure definitions embedded in
     * other structure definitions or in interface blocks are processed.
     */
-   glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field,
-                                                  decl_count);
+   glsl_struct_field *const fields = rzalloc_array(state, glsl_struct_field,
+                                                   decl_count);
 
    bool first_member = true;
    bool first_member_has_explicit_location = false;
 
    unsigned i = 0;
    foreach_list_typed (ast_declarator_list, decl_list, link, declarations) {
       const char *type_name;
       YYLTYPE loc = decl_list->get_location();
 
       decl_list->type->specifier->hir(instructions, state);
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index b9c9a1a..c0a5704 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -69,21 +69,21 @@ typedef struct YYLTYPE {
 # define YYLTYPE_IS_TRIVIAL 1
 
 extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
                              const char *fmt, ...);
 
 
 struct _mesa_glsl_parse_state {
    _mesa_glsl_parse_state(struct gl_context *_ctx, gl_shader_stage stage,
                           void *mem_ctx);
 
-   DECLARE_RALLOC_CXX_OPERATORS(_mesa_glsl_parse_state);
+   DECLARE_RZALLOC_CXX_OPERATORS(_mesa_glsl_parse_state);
 
    /**
     * Generate a string representing the GLSL version currently being compiled
     * (useful for error messages).
     */
    const char *get_version_string()
    {
       return glsl_compute_version_string(this, this->es_shader,
                                          this->language_version);
    }
diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index 5b0dff6..76b0079 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -308,21 +308,21 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
    if (num_blocks == 0) {
       assert(num_variables == 0);
       return;
    }
 
    assert(num_variables != 0);
 
    /* Allocate storage to hold all of the information related to uniform
     * blocks that can be queried through the API.
     */
-   struct gl_uniform_block *blocks = ralloc_array(mem_ctx, gl_uniform_block, num_blocks);
+   struct gl_uniform_block *blocks = rzalloc_array(mem_ctx, gl_uniform_block, num_blocks);
    gl_uniform_buffer_variable *variables =
       ralloc_array(blocks, gl_uniform_buffer_variable, num_variables);
 
    /* Add each variable from each uniform block to the API tracking
     * structures.
     */
    ubo_visitor parcel(blocks, variables, num_variables, prog);
 
    STATIC_ASSERT(unsigned(GLSL_INTERFACE_PACKING_STD140)
                  == unsigned(ubo_packing_std140));
diff --git a/src/compiler/glsl/list.h b/src/compiler/glsl/list.h
index b5b5b36..6afb9dc 100644
--- a/src/compiler/glsl/list.h
+++ b/src/compiler/glsl/list.h
@@ -49,21 +49,21 @@
 #endif
 #include <assert.h>
 
 #include "util/ralloc.h"
 
 struct exec_node {
    struct exec_node *next;
    struct exec_node *prev;
 
 #ifdef __cplusplus
-   DECLARE_RALLOC_CXX_OPERATORS(exec_node)
+   DECLARE_RZALLOC_CXX_OPERATORS(exec_node)
 
    exec_node() : next(NULL), prev(NULL)
    {
       /* empty */
    }
 
    const exec_node *get_next() const;
    exec_node *get_next();
 
    const exec_node *get_prev() const;
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 098e1b2..e56a1dc 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -439,23 +439,24 @@ alu_src_init(nir_alu_src *src)
    src->swizzle[0] = 0;
    src->swizzle[1] = 1;
    src->swizzle[2] = 2;
    src->swizzle[3] = 3;
 }
 
 nir_alu_instr *
 nir_alu_instr_create(nir_shader *shader, nir_op op)
 {
    unsigned num_srcs = nir_op_infos[op].num_inputs;
+   /* TODO: don't use rzalloc */
    nir_alu_instr *instr =
-      ralloc_size(shader,
-                  sizeof(nir_alu_instr) + num_srcs * sizeof(nir_alu_src));
+      rzalloc_size(shader,
+                   sizeof(nir_alu_instr) + num_srcs * sizeof(nir_alu_src));
 
    instr_init(&instr->instr, nir_instr_type_alu);
    instr->op = op;
    alu_dest_init(&instr->dest);
    for (unsigned i = 0; i < num_srcs; i++)
       alu_src_init(&instr->src[i]);
 
    return instr;
 }
 
@@ -477,22 +478,23 @@ nir_load_const_instr_create(nir_shader *shader, unsigned num_components,
 
    nir_ssa_def_init(&instr->instr, &instr->def, num_components, bit_size, NULL);
 
    return instr;
 }
 
 nir_intrinsic_instr *
 nir_intrinsic_instr_create(nir_shader *shader, nir_intrinsic_op op)
 {
    unsigned num_srcs = nir_intrinsic_infos[op].num_srcs;
+   /* TODO: don't use rzalloc */
    nir_intrinsic_instr *instr =
-      ralloc_size(shader,
+      rzalloc_size(shader,
                   sizeof(nir_intrinsic_instr) + num_srcs * sizeof(nir_src));
 
    instr_init(&instr->instr, nir_instr_type_intrinsic);
    instr->intrinsic = op;
 
    if (nir_intrinsic_infos[op].has_dest)
       dest_init(&instr->dest);
 
    for (unsigned i = 0; i < num_srcs; i++)
       src_init(&instr->src[i]);
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c
index 634058c..c4523d1 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -28,21 +28,22 @@
 #include "vtn_private.h"
 #include "spirv_info.h"
 
 static struct vtn_access_chain *
 vtn_access_chain_extend(struct vtn_builder *b, struct vtn_access_chain *old,
                         unsigned new_ids)
 {
    struct vtn_access_chain *chain;
 
    unsigned new_len = old->length + new_ids;
-   chain = ralloc_size(b, sizeof(*chain) + new_len * sizeof(chain->link[0]));
+   /* TODO: don't use rzalloc */
+   chain = rzalloc_size(b, sizeof(*chain) + new_len * sizeof(chain->link[0]));
 
    chain->var = old->var;
    chain->length = new_len;
 
    for (unsigned i = 0; i < old->length; i++)
       chain->link[i] = old->link[i];
 
    return chain;
 }
 
diff --git a/src/gallium/drivers/freedreno/ir3/ir3.c b/src/gallium/drivers/freedreno/ir3/ir3.c
index 78ec1cc..9f2116a 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3.c
@@ -33,21 +33,21 @@
 #include "util/ralloc.h"
 
 #include "freedreno_util.h"
 #include "instr-a3xx.h"
 
 /* simple allocator to carve allocations out of an up-front allocated heap,
  * so that we can free everything easily in one shot.
  */
 void * ir3_alloc(struct ir3 *shader, int sz)
 {
-	return ralloc_size(shader, sz);
+	return rzalloc_size(shader, sz); /* TODO: don't use rzalloc */
 }
 
 struct ir3 * ir3_create(struct ir3_compiler *compiler,
 		unsigned nin, unsigned nout)
 {
 	struct ir3 *shader = ralloc(compiler, struct ir3);
 
 	shader->compiler = compiler;
 	shader->ninputs = nin;
 	shader->inputs = ir3_alloc(shader, sizeof(shader->inputs[0]) * nin);
diff --git a/src/gallium/drivers/vc4/vc4_cl.c b/src/gallium/drivers/vc4/vc4_cl.c
index afb9987..91f51b0 100644
--- a/src/gallium/drivers/vc4/vc4_cl.c
+++ b/src/gallium/drivers/vc4/vc4_cl.c
@@ -21,21 +21,21 @@
  * IN THE SOFTWARE.
  */
 
 #include "util/u_math.h"
 #include "util/ralloc.h"
 #include "vc4_context.h"
 
 void
 vc4_init_cl(void *mem_ctx, struct vc4_cl *cl)
 {
-        cl->base = ralloc_size(mem_ctx, 1);
+        cl->base = rzalloc_size(mem_ctx, 1); /* TODO: don't use rzalloc */
         cl->next = cl->base;
         cl->size = 0;
 }
 
 void
 cl_ensure_space(struct vc4_cl *cl, uint32_t space)
 {
         uint32_t offset = cl_offset(cl);
 
         if (offset + space <= cl->size)
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 84add52..a785dc4 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -2465,21 +2465,21 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage,
                         fprintf(stderr, "SHADER-DB: %s prog %d/%d: %d UBO uniforms\n",
                                 qir_get_stage_name(c->stage),
                                 c->program_id, c->variant_id,
                                 shader->ubo_size / 4);
                 }
         }
 
         qir_compile_destroy(c);
 
         struct vc4_key *dup_key;
-        dup_key = ralloc_size(shader, key_size);
+        dup_key = rzalloc_size(shader, key_size); /* TODO: don't use rzalloc */
         memcpy(dup_key, key, key_size);
         _mesa_hash_table_insert(ht, dup_key, shader);
 
         return shader;
 }
 
 static void
 vc4_setup_shared_key(struct vc4_context *vc4, struct vc4_key *key,
                      struct vc4_texture_stateobj *texstate)
 {
diff --git a/src/gallium/drivers/vc4/vc4_simulator.c b/src/gallium/drivers/vc4/vc4_simulator.c
index b802391..8daff77 100644
--- a/src/gallium/drivers/vc4/vc4_simulator.c
+++ b/src/gallium/drivers/vc4/vc4_simulator.c
@@ -315,22 +315,23 @@ vc4_simulator_flush(struct vc4_context *vc4,
                 }
         }
 
         return 0;
 }
 
 void
 vc4_simulator_init(struct vc4_screen *screen)
 {
         screen->simulator_mem_size = 256 * 1024 * 1024;
-        screen->simulator_mem_base = ralloc_size(screen,
-                                                 screen->simulator_mem_size);
+        /* TODO: don't use rzalloc */
+        screen->simulator_mem_base = rzalloc_size(screen,
+                                                  screen->simulator_mem_size);
 
         /* We supply our own memory so that we can have more aperture
          * available (256MB instead of simpenrose's default 64MB).
          */
         simpenrose_init_hardware_supply_mem(screen->simulator_mem_base,
                                             screen->simulator_mem_size);
 
         /* Carve out low memory for tile allocation overflow.  The kernel
          * should be automatically handling overflow memory setup on real
          * hardware, but for simulation we just get one shot to set up enough
diff --git a/src/mesa/drivers/dri/i965/brw_state_batch.c b/src/mesa/drivers/dri/i965/brw_state_batch.c
index d79e0ea..9658b48 100644
--- a/src/mesa/drivers/dri/i965/brw_state_batch.c
+++ b/src/mesa/drivers/dri/i965/brw_state_batch.c
@@ -39,23 +39,24 @@ brw_track_state_batch(struct brw_context *brw,
 		      enum aub_state_struct_type type,
 		      uint32_t offset,
                       int size,
                       int index)
 {
    struct intel_batchbuffer *batch = &brw->batch;
 
    if (!brw->state_batch_list) {
       /* Our structs are always aligned to at least 32 bytes, so
        * our array doesn't need to be any larger
+       * TODO: don't use rzalloc
        */
-      brw->state_batch_list = ralloc_size(brw, sizeof(*brw->state_batch_list) *
-					  batch->bo->size / 32);
+      brw->state_batch_list = rzalloc_size(brw, sizeof(*brw->state_batch_list) *
+                                           batch->bo->size / 32);
    }
 
    brw->state_batch_list[brw->state_batch_count].offset = offset;
    brw->state_batch_list[brw->state_batch_count].size = size;
    brw->state_batch_list[brw->state_batch_count].type = type;
    brw->state_batch_list[brw->state_batch_count].index = index;
    brw->state_batch_count++;
 }
 
 /**
-- 
2.7.4



More information about the mesa-dev mailing list