Mesa (master): intel/fs: Don' t allocate a param array for zero push constants

Jason Ekstrand jekstrand at kemper.freedesktop.org
Thu Nov 2 16:55:26 UTC 2017


Module: Mesa
Branch: master
Commit: 172e8e42c4eb898a80e3b967d495b4b8619905c7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=172e8e42c4eb898a80e3b967d495b4b8619905c7

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Wed Nov  1 08:02:34 2017 -0700

intel/fs: Don't allocate a param array for zero push constants

Thanks to the ralloc invariant of "any pointer returned from ralloc can
be used as a context", calling ralloc_size with a size of zero will
cause it to allocate at least a header.  If we don't have any push
constants, then NULL is perfectly acceptable (and even preferred).

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>

---

 src/intel/compiler/brw_fs.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
index e2176827a6..afad6805d2 100644
--- a/src/intel/compiler/brw_fs.cpp
+++ b/src/intel/compiler/brw_fs.cpp
@@ -2092,7 +2092,14 @@ fs_visitor::assign_constant_locations()
     */
    uint32_t *param = stage_prog_data->param;
    stage_prog_data->nr_params = num_push_constants;
-   stage_prog_data->param = ralloc_array(mem_ctx, uint32_t, num_push_constants);
+   if (num_push_constants) {
+      stage_prog_data->param = ralloc_array(mem_ctx, uint32_t,
+                                            num_push_constants);
+   } else {
+      stage_prog_data->param = NULL;
+   }
+   assert(stage_prog_data->nr_pull_params == 0);
+   assert(stage_prog_data->pull_param == NULL);
    if (num_pull_constants > 0) {
       stage_prog_data->nr_pull_params = num_pull_constants;
       stage_prog_data->pull_param = ralloc_array(mem_ctx, uint32_t,




More information about the mesa-commit mailing list