intel/compiler: Allocate pull_param in assign_constant_locations
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 29 Sep 2017 18:30:25 +0000 (11:30 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 13 Oct 2017 05:39:31 +0000 (22:39 -0700)
Now that everything is nicely ralloc'd, we can allocate the pull_param
array in assign_constant_locations instead of higher up.  We can also
re-allocate the param array so that it's exactly the needed size.  This
should save us some memory because we're not allocating the total needed
param space for both push and pull.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/intel/compiler/brw_fs.cpp
src/intel/compiler/brw_vec4_visitor.cpp
src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp

index c08e28d166ab423c525a04b52b65db2557a85ac5..f9e7385afdf2b26a3f3a4d58339d89725191b287 100644 (file)
@@ -2084,14 +2084,17 @@ fs_visitor::assign_constant_locations()
    if (thread_local_id_index >= 0)
       push_constant_loc[thread_local_id_index] = num_push_constants++;
 
-   /* As the uniforms are going to be reordered, take the data from a temporary
-    * copy of the original param[].
+   /* As the uniforms are going to be reordered, stash the old array and
+    * create two new arrays for push/pull params.
     */
-   uint32_t *param = ralloc_array(NULL, uint32_t, stage_prog_data->nr_params);
-   memcpy(param, stage_prog_data->param,
-          sizeof(uint32_t) * stage_prog_data->nr_params);
+   uint32_t *param = stage_prog_data->param;
    stage_prog_data->nr_params = num_push_constants;
-   stage_prog_data->nr_pull_params = num_pull_constants;
+   stage_prog_data->param = ralloc_array(NULL, uint32_t, num_push_constants);
+   if (num_pull_constants > 0) {
+      stage_prog_data->nr_pull_params = num_pull_constants;
+      stage_prog_data->pull_param = ralloc_array(NULL, uint32_t,
+                                                 num_pull_constants);
+   }
 
    /* Now that we know how many regular uniforms we'll push, reduce the
     * UBO push ranges so we don't exceed the 3DSTATE_CONSTANT limits.
index ff5cd2d4334e11c23213432d6096d3cb5965562f..ae516196b15163b5d516b1ffe250b246d02e6080 100644 (file)
@@ -1782,6 +1782,11 @@ vec4_visitor::move_uniform_array_access_to_pull_constants()
       return;
    }
 
+   /* Allocate the pull_params array */
+   assert(stage_prog_data->nr_pull_params == 0);
+   stage_prog_data->pull_param = ralloc_array(mem_ctx, uint32_t,
+                                              this->uniforms * 4);
+
    int pull_constant_loc[this->uniforms];
    memset(pull_constant_loc, -1, sizeof(pull_constant_loc));
 
index a3e7b12acd3dd7760467cbf0bb6ee68f6039a3ae..62755fda206fab0555dc582d34e534964c436f6b 100644 (file)
@@ -195,7 +195,6 @@ brw_nir_setup_glsl_uniforms(void *mem_ctx, nir_shader *shader,
    unsigned nr_params = shader->num_uniforms / 4;
    stage_prog_data->nr_params = nr_params;
    stage_prog_data->param = rzalloc_array(mem_ctx, uint32_t, nr_params);
-   stage_prog_data->pull_param = rzalloc_array(mem_ctx, uint32_t, nr_params);
 
    nir_foreach_variable(var, &shader->uniforms) {
       /* UBO's, atomics and samplers don't take up space in the
@@ -223,7 +222,6 @@ brw_nir_setup_arb_uniforms(void *mem_ctx, nir_shader *shader,
    unsigned nr_params = plist->NumParameters * 4;
    stage_prog_data->nr_params = nr_params;
    stage_prog_data->param = rzalloc_array(mem_ctx, uint32_t, nr_params);
-   stage_prog_data->pull_param = rzalloc_array(mem_ctx, uint32_t, nr_params);
 
    /* For ARB programs, prog_to_nir generates a single "parameters" variable
     * for all uniform data.  nir_lower_wpos_ytransform may also create an