From fae790ecfcd0f73c6512e52a2e430ed1ce7f5b12 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 15 Jul 2019 11:30:35 -0700 Subject: panfrost: Allocate UBOs on the stack, not the heap Saves a call to calloc (the maximum size is small and known at compile-time) and fixes a leak. Signed-off-by: Alyssa Rosenzweig --- src/gallium/drivers/panfrost/pan_context.c | 2 +- src/gallium/drivers/panfrost/pan_screen.c | 2 +- src/gallium/drivers/panfrost/pan_screen.h | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gallium/drivers/panfrost') diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index d8faaa39bc2..ed9b3dec529 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -1283,7 +1283,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) assert(ubo_count >= 1); size_t sz = sizeof(struct mali_uniform_buffer_meta) * ubo_count; - struct mali_uniform_buffer_meta *ubos = calloc(sz, 1); + struct mali_uniform_buffer_meta ubos[PAN_MAX_CONST_BUFFERS]; /* Upload uniforms as a UBO */ ubos[0].size = MALI_POSITIVE((2 + uniform_count)); diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index ff67c0b14bc..27ff0020915 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -258,7 +258,7 @@ panfrost_get_shader_param(struct pipe_screen *screen, return 16 * 1024 * sizeof(float); case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: - return 16; + return PAN_MAX_CONST_BUFFERS; case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: return 0; diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h index 3a0e544c1a6..a0c6e2df63d 100644 --- a/src/gallium/drivers/panfrost/pan_screen.h +++ b/src/gallium/drivers/panfrost/pan_screen.h @@ -42,6 +42,9 @@ struct panfrost_context; struct panfrost_resource; struct panfrost_screen; +/* Driver limits */ +#define PAN_MAX_CONST_BUFFERS 16 + /* Flags for allocated memory */ /* This memory region is executable */ -- cgit v1.2.3