From: Ian Romanick Date: Wed, 8 Jul 2009 18:39:13 +0000 (-0700) Subject: Add new _mesa_new_parameter_list_sized to pre-allocate a parameter list X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=480567d5c451511a72744b0c849960c2b712e093;p=mesa.git Add new _mesa_new_parameter_list_sized to pre-allocate a parameter list --- diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index bcd8c5d9dc0..6b9e73b2cbd 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -44,6 +44,34 @@ _mesa_new_parameter_list(void) } +struct gl_program_parameter_list * +_mesa_new_parameter_list_sized(unsigned size) +{ + struct gl_program_parameter_list *p = _mesa_new_parameter_list(); + + if ((p != NULL) && (size != 0)) { + p->Size = size; + + /* alloc arrays */ + p->Parameters = (struct gl_program_parameter *) + _mesa_calloc(size * sizeof(struct gl_program_parameter)); + + p->ParameterValues = (GLfloat (*)[4]) + _mesa_align_malloc(size * 4 *sizeof(GLfloat), 16); + + + if ((p->Parameters == NULL) || (p->ParameterValues == NULL)) { + _mesa_free(p->Parameters); + _mesa_align_free(p->ParameterValues); + _mesa_free(p); + p = NULL; + } + } + + return p; +} + + /** * Free a parameter list and all its parameters */ diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h index 01f5a0e179f..d1fcf47e61b 100644 --- a/src/mesa/shader/prog_parameter.h +++ b/src/mesa/shader/prog_parameter.h @@ -84,6 +84,9 @@ struct gl_program_parameter_list extern struct gl_program_parameter_list * _mesa_new_parameter_list(void); +extern struct gl_program_parameter_list * +_mesa_new_parameter_list_sized(unsigned size); + extern void _mesa_free_parameter_list(struct gl_program_parameter_list *paramList);