diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2013-06-18 04:22:33 -0700 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2013-06-26 11:25:12 -0700 |
commit | 4563dfe23a300f0fc1652a609f5ad9e9a755fb99 (patch) | |
tree | 0ca947ae4eedef1de1006eb336bef41b3675b23c /src/glsl/glsl_types.h | |
parent | 818da74af542f50aa9c32c7471de58185c7de541 (diff) | |
download | external_mesa3d-4563dfe23a300f0fc1652a609f5ad9e9a755fb99.zip external_mesa3d-4563dfe23a300f0fc1652a609f5ad9e9a755fb99.tar.gz external_mesa3d-4563dfe23a300f0fc1652a609f5ad9e9a755fb99.tar.bz2 |
glsl: Streamline the built-in type handling code.
Over the last few years, the compiler has grown to support 7 different
language versions and 6 extensions that add new built-in types. With
more and more features being added, some of our core code has devolved
into an unmaintainable spaghetti of sorts.
A few problems with the old code:
1. Built-in types are declared...where exactly?
The types in builtin_types.h were organized in arrays by the language
version or extension they were introduced in. It's factored out to
avoid duplicates---every type only exists in one array. But that
means that sampler1D is declared in 110, sampler2D is in core types,
sampler3D is a unique global not in a list...and so on.
2. Spaghetti call-chains with weird parameters:
generate_300ES_types calls generate_130_types which calls
generate_120_types and generate_EXT_texture_array_types, which calls
generate_110_types, which calls generate_100ES_types...and more
Except that ES doesn't want 1D types, so we have a skip_1d parameter.
add_deprecated also falls into this category.
3. Missing type accessors.
Common types have convenience pointers (like glsl_type::vec4_type),
but others may not be accessible at all without a symbol table (for
example, sampler types).
4. Global variable declarations in a header file?
#include "builtin_types.h" in two C++ files would break the build.
The new code addresses these problems. All built-in types are declared
together in a single table, independent of when they were introduced.
The macro that declares a new built-in type also creates a convenience
pointer, so every type is available and it won't get out of sync.
The code to populate a symbol table with the appropriate types for a
particular language version and set of extensions is now a single
table-driven function. The table lists the type name and GL/ES versions
when it was introduced (similar to how the lexer handles reserved
words). A single loop adds types based on the language version.
Explicit extension checks then add additional types. If they were
already added based on the language version, glsl_symbol_table simply
ignores the request to add them a second time, meaning we don't need
to worry about duplicates and can simply list types where they belong.
v2: Mark uvecs and shadow samplers as ES3 only, and 1DArrayShadow as
unsupported in ES entirely. Add a touch more doxygen.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'src/glsl/glsl_types.h')
-rw-r--r-- | src/glsl/glsl_types.h | 88 |
1 files changed, 15 insertions, 73 deletions
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index 665af8b..b7ddb1c 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -153,38 +153,17 @@ struct glsl_type { struct glsl_struct_field *structure; /**< List of struct fields. */ } fields; - /** * \name Pointers to various public type singletons */ /*@{*/ - static const glsl_type *const error_type; - static const glsl_type *const void_type; - static const glsl_type *const int_type; - static const glsl_type *const ivec2_type; - static const glsl_type *const ivec3_type; - static const glsl_type *const ivec4_type; - static const glsl_type *const uint_type; - static const glsl_type *const uvec2_type; - static const glsl_type *const uvec3_type; - static const glsl_type *const uvec4_type; - static const glsl_type *const float_type; - static const glsl_type *const vec2_type; - static const glsl_type *const vec3_type; - static const glsl_type *const vec4_type; - static const glsl_type *const bool_type; - static const glsl_type *const bvec2_type; - static const glsl_type *const bvec3_type; - static const glsl_type *const bvec4_type; - static const glsl_type *const mat2_type; - static const glsl_type *const mat2x3_type; - static const glsl_type *const mat2x4_type; - static const glsl_type *const mat3x2_type; - static const glsl_type *const mat3_type; - static const glsl_type *const mat3x4_type; - static const glsl_type *const mat4x2_type; - static const glsl_type *const mat4x3_type; - static const glsl_type *const mat4_type; +#undef DECL_TYPE +#define DECL_TYPE(NAME, REST...) \ + static const glsl_type *const NAME##_type; +#undef STRUCT_TYPE +#define STRUCT_TYPE(NAME) \ + static const glsl_type *const struct_##NAME##_type; +#include "builtin_type_macros.h" /*@}*/ /** @@ -551,53 +530,14 @@ private: static unsigned record_key_hash(const void *key); /** - * \name Pointers to various type singletons - */ - /*@{*/ - static const glsl_type _error_type; - static const glsl_type _void_type; - static const glsl_type _sampler3D_type; - static const glsl_type _samplerCubeShadow_type; - static const glsl_type builtin_core_types[]; - static const glsl_type builtin_structure_types[]; - static const glsl_type builtin_110_deprecated_structure_types[]; - static const glsl_type builtin_110_types[]; - static const glsl_type builtin_120_types[]; - static const glsl_type builtin_130_types[]; - static const glsl_type builtin_140_types[]; - static const glsl_type builtin_ARB_texture_rectangle_types[]; - static const glsl_type builtin_EXT_texture_array_types[]; - static const glsl_type builtin_EXT_texture_buffer_object_types[]; - static const glsl_type builtin_OES_EGL_image_external_types[]; - static const glsl_type builtin_ARB_texture_cube_map_array_types[]; - static const glsl_type builtin_ARB_texture_multisample_types[]; - /*@}*/ - - /** - * \name Methods to populate a symbol table with built-in types. - * - * \internal - * This is one of the truely annoying things about C++. Methods that are - * completely internal and private to a type still have to be advertised to - * the world in a public header file. + * \name Built-in type flyweights */ /*@{*/ - static void generate_100ES_types(glsl_symbol_table *); - static void generate_300ES_types(glsl_symbol_table *); - static void generate_110_types(glsl_symbol_table *, bool add_deprecated, - bool skip_1d); - static void generate_120_types(glsl_symbol_table *, bool add_deprecated, - bool skip_1d); - static void generate_130_types(glsl_symbol_table *, bool add_deprecated, - bool skip_1d); - static void generate_140_types(glsl_symbol_table *); - static void generate_150_types(glsl_symbol_table *); - static void generate_ARB_texture_rectangle_types(glsl_symbol_table *, bool); - static void generate_EXT_texture_array_types(glsl_symbol_table *, bool); - static void generate_OES_texture_3D_types(glsl_symbol_table *, bool); - static void generate_OES_EGL_image_external_types(glsl_symbol_table *, bool); - static void generate_ARB_texture_cube_map_array_types(glsl_symbol_table *, bool); - static void generate_ARB_texture_multisample_types(glsl_symbol_table *, bool); +#undef DECL_TYPE +#define DECL_TYPE(NAME, REST...) static const glsl_type _##NAME##_type; +#undef STRUCT_TYPE +#define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type; +#include "builtin_type_macros.h" /*@}*/ /** @@ -625,6 +565,8 @@ glsl_align(unsigned int a, unsigned int align) return (a + align - 1) / align * align; } +#undef DECL_TYPE +#undef STRUCT_TYPE #endif /* __cplusplus */ #endif /* GLSL_TYPES_H */ |