mesa: properly disallow param list reallocation
This can more easily detect shader variants adding too many state parameters and causing a reallocation. Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6946>
This commit is contained in:
parent
158351007e
commit
eda37fb269
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "main/glheader.h"
|
||||
#include "main/macros.h"
|
||||
#include "main/errors.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "prog_instruction.h"
|
||||
#include "prog_parameter.h"
|
||||
|
@ -192,6 +193,14 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
|
|||
const GLuint oldNum = paramList->NumParameters;
|
||||
const unsigned oldValNum = paramList->NumParameterValues;
|
||||
|
||||
if (paramList->DisallowRealloc &&
|
||||
(oldNum + reserve_params > paramList->Size ||
|
||||
oldValNum + reserve_values > paramList->SizeValues)) {
|
||||
_mesa_problem(NULL, "Parameter storage reallocation disallowed. This "
|
||||
"is a Mesa bug. Increase the reservation size in the code.");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (oldNum + reserve_params > paramList->Size) {
|
||||
/* Need to grow the parameter list array (alloc some extra) */
|
||||
paramList->Size += 4 * reserve_params;
|
||||
|
@ -218,6 +227,17 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disallow reallocating the parameter storage, so that uniform storage
|
||||
* can have pointers pointing to it.
|
||||
*/
|
||||
void
|
||||
_mesa_disallow_parameter_storage_realloc(struct gl_program_parameter_list *paramList)
|
||||
{
|
||||
paramList->DisallowRealloc = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new parameter to a parameter list.
|
||||
* Note that parameter values are usually 4-element GLfloat vectors.
|
||||
|
|
|
@ -142,6 +142,7 @@ struct gl_program_parameter_list
|
|||
gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */
|
||||
GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
|
||||
might invalidate ParameterValues[] */
|
||||
bool DisallowRealloc;
|
||||
};
|
||||
|
||||
|
||||
|
@ -159,6 +160,9 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
|
|||
unsigned reserve_params,
|
||||
unsigned reserve_values);
|
||||
|
||||
extern void
|
||||
_mesa_disallow_parameter_storage_realloc(struct gl_program_parameter_list *paramList);
|
||||
|
||||
extern GLint
|
||||
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
|
||||
gl_register_file type, const char *name,
|
||||
|
|
|
@ -468,6 +468,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
|
|||
* This should be enough for Bitmap and DrawPixels constants.
|
||||
*/
|
||||
_mesa_reserve_parameter_storage(prog->Parameters, 8, 8);
|
||||
_mesa_disallow_parameter_storage_realloc(prog->Parameters);
|
||||
|
||||
/* This has to be done last. Any operation the can cause
|
||||
* prog->ParameterValues to get reallocated (e.g., anything that adds a
|
||||
|
|
|
@ -7167,6 +7167,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
|
|||
* This should be enough for Bitmap and DrawPixels constants.
|
||||
*/
|
||||
_mesa_reserve_parameter_storage(prog->Parameters, 8, 8);
|
||||
_mesa_disallow_parameter_storage_realloc(prog->Parameters);
|
||||
|
||||
/* This has to be done last. Any operation the can cause
|
||||
* prog->ParameterValues to get reallocated (e.g., anything that adds a
|
||||
|
|
Loading…
Reference in New Issue