glsl: Don't create struct type builtins

Unlike for simpler types, struct types have a runtime cache, that's used to
ensure same type can be compared to same pointer.  The existing code was bypassing
it, potentially breaking that invariant.  One potential issue would be when
decoding/encoding types, the resulting type would be pointer-different than what
was stored.

This hasn't caused a visible issue, but the (incomplete) special handling for struct
builtins is in the way of other changes.

Change the code to use get_struct_instance(), and also only ever load those if the
parser need the types, since some of them are deprecated types that we might never
want to load.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25006>
This commit is contained in:
Caio Oliveira 2023-09-11 14:34:21 -07:00 committed by Marge Bot
parent 78af1d0d9a
commit 3bdd2ba194
2 changed files with 27 additions and 48 deletions

View file

@ -39,10 +39,6 @@
#include "util/macros.h"
#include "main/consts_exts.h"
/**
* Declarations of struct builtins types.
* @{
*/
static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
glsl_struct_field(glsl_type::float_type, GLSL_PRECISION_HIGH, "near"),
glsl_struct_field(glsl_type::float_type, GLSL_PRECISION_HIGH, "far"),
@ -104,24 +100,6 @@ static const struct glsl_struct_field gl_FogParameters_fields[] = {
glsl_struct_field(glsl_type::float_type, "scale"),
};
#define STRUCT_TYPE(NAME) \
const glsl_type _struct_##NAME##_type = \
glsl_type(NAME##_fields, ARRAY_SIZE(NAME##_fields), #NAME); \
const glsl_type *const struct_##NAME##_type = \
&_struct_##NAME##_type;
STRUCT_TYPE(gl_DepthRangeParameters)
STRUCT_TYPE(gl_PointParameters)
STRUCT_TYPE(gl_MaterialParameters)
STRUCT_TYPE(gl_LightSourceParameters)
STRUCT_TYPE(gl_LightModelParameters)
STRUCT_TYPE(gl_LightModelProducts)
STRUCT_TYPE(gl_LightProducts)
STRUCT_TYPE(gl_FogParameters)
#undef STRUCT_TYPE
/** @} */
/**
* Code to populate a symbol table with the built-in types available in a
* particular shading language version. The table below contains tags every
@ -132,9 +110,6 @@ STRUCT_TYPE(gl_FogParameters)
#define T(TYPE, MIN_GL, MIN_ES) \
{ glsl_type::TYPE##_type, MIN_GL, MIN_ES },
#define S(TYPE, MIN_GL, MIN_ES) \
{ TYPE##_type, MIN_GL, MIN_ES },
static const struct builtin_type_versions {
const glsl_type *const type;
int min_gl;
@ -225,8 +200,6 @@ static const struct builtin_type_versions {
T(samplerCubeArrayShadow, 400, 320)
T(sampler2DRectShadow, 140, 999)
S(struct_gl_DepthRangeParameters, 110, 100)
T(image1D, 420, 999)
T(image2D, 420, 310)
T(image3D, 420, 310)
@ -265,17 +238,6 @@ static const struct builtin_type_versions {
};
#undef T
#undef S
static const glsl_type *const deprecated_types[] = {
struct_gl_PointParameters_type,
struct_gl_MaterialParameters_type,
struct_gl_LightSourceParameters_type,
struct_gl_LightModelParameters_type,
struct_gl_LightModelProducts_type,
struct_gl_LightProducts_type,
struct_gl_FogParameters_type,
};
static inline void
add_type(glsl_symbol_table *symbols, const glsl_type *const type)
@ -298,13 +260,30 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
}
}
/* Add deprecated structure types. While these were deprecated in 1.30,
* they're still present. We've removed them in 1.40+ (OpenGL 3.1+).
/* Note: use glsl_type::get_struct_instance() to get the properly cached
* copy of the struct types.
*/
if (state->compat_shader || state->ARB_compatibility_enable) {
for (unsigned i = 0; i < ARRAY_SIZE(deprecated_types); i++) {
add_type(symbols, deprecated_types[i]);
{
#define GET_STRUCT_TYPE(NAME) glsl_type::get_struct_instance(NAME##_fields, ARRAY_SIZE(NAME##_fields), #NAME)
if (state->is_version(110, 100)) {
add_type(symbols, GET_STRUCT_TYPE(gl_DepthRangeParameters));
}
/* Add deprecated structure types. While these were deprecated in 1.30,
* they're still present. We've removed them in 1.40+ (OpenGL 3.1+).
*/
if (state->compat_shader || state->ARB_compatibility_enable) {
add_type(symbols, GET_STRUCT_TYPE(gl_PointParameters));
add_type(symbols, GET_STRUCT_TYPE(gl_MaterialParameters));
add_type(symbols, GET_STRUCT_TYPE(gl_LightSourceParameters));
add_type(symbols, GET_STRUCT_TYPE(gl_LightModelParameters));
add_type(symbols, GET_STRUCT_TYPE(gl_LightModelProducts));
add_type(symbols, GET_STRUCT_TYPE(gl_LightProducts));
add_type(symbols, GET_STRUCT_TYPE(gl_FogParameters));
};
#undef GET_STRUCT_TYPE
}
/* Add types for enabled extensions. They may have already been added

View file

@ -1224,11 +1224,6 @@ public:
~glsl_type();
/** Constructor for record types */
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
const char *name, bool packed = false,
unsigned explicit_alignment = 0);
private:
static simple_mtx_t hash_mutex;
@ -1250,6 +1245,11 @@ private:
enum glsl_sampler_dim dim, bool shadow, bool array,
glsl_base_type type, const char *name);
/** Constructor for record types */
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
const char *name, bool packed = false,
unsigned explicit_alignment = 0);
/** Constructor for interface types */
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
enum glsl_interface_packing packing,