mesa: don't overallocate ParameterValues 4 times (v2)
The additional memory was never used. v2: rework Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9360>
This commit is contained in:
parent
e91dec36bc
commit
bcc61a01d4
|
@ -199,10 +199,11 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
|
||||||
{
|
{
|
||||||
const GLuint oldNum = paramList->NumParameters;
|
const GLuint oldNum = paramList->NumParameters;
|
||||||
const unsigned oldValNum = paramList->NumParameterValues;
|
const unsigned oldValNum = paramList->NumParameterValues;
|
||||||
|
const unsigned needSizeValues = oldValNum + reserve_values * 4;
|
||||||
|
|
||||||
if (paramList->DisallowRealloc &&
|
if (paramList->DisallowRealloc &&
|
||||||
(oldNum + reserve_params > paramList->Size ||
|
(oldNum + reserve_params > paramList->Size ||
|
||||||
oldValNum + reserve_values > paramList->SizeValues)) {
|
needSizeValues > paramList->SizeValues)) {
|
||||||
_mesa_problem(NULL, "Parameter storage reallocation disallowed. This "
|
_mesa_problem(NULL, "Parameter storage reallocation disallowed. This "
|
||||||
"is a Mesa bug. Increase the reservation size in the code.");
|
"is a Mesa bug. Increase the reservation size in the code.");
|
||||||
abort();
|
abort();
|
||||||
|
@ -218,17 +219,17 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
|
||||||
paramList->Size * sizeof(struct gl_program_parameter));
|
paramList->Size * sizeof(struct gl_program_parameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldValNum + reserve_values > paramList->SizeValues) {
|
if (needSizeValues > paramList->SizeValues) {
|
||||||
paramList->SizeValues += 4 * reserve_values;
|
paramList->SizeValues = needSizeValues + 16; /* alloc some extra */
|
||||||
|
|
||||||
paramList->ParameterValues = (gl_constant_value *)
|
paramList->ParameterValues = (gl_constant_value *)
|
||||||
align_realloc(paramList->ParameterValues, /* old buf */
|
align_realloc(paramList->ParameterValues, /* old buf */
|
||||||
oldValNum * 4 * sizeof(gl_constant_value),/* old sz */
|
oldValNum * sizeof(gl_constant_value),/* old sz */
|
||||||
/* Overallocate the size by 12 because matrix rows can
|
/* Overallocate the size by 12 because matrix rows can
|
||||||
* be allocated partially but fetch_state always writes
|
* be allocated partially but fetch_state always writes
|
||||||
* 4 components (16 bytes).
|
* 4 components (16 bytes).
|
||||||
*/
|
*/
|
||||||
paramList->SizeValues * 4 * sizeof(gl_constant_value) +
|
paramList->SizeValues * sizeof(gl_constant_value) +
|
||||||
12, 16);
|
12, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,6 +349,9 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
|
||||||
unreachable("invalid parameter type");
|
unreachable("invalid parameter type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(paramList->NumParameters <= paramList->Size);
|
||||||
|
assert(paramList->NumParameterValues <= paramList->SizeValues);
|
||||||
|
|
||||||
return (GLint) oldNum;
|
return (GLint) oldNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue