From: Caio Oliveira Date: Fri, 1 Sep 2023 05:28:29 +0000 (-0700) Subject: compiler/types: Use designated initializer syntax to specify builtins X-Git-Tag: upstream/23.3.3~2079 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6bf0654f4a1eb02303fdd14514a1f8026e67560a;p=platform%2Fupstream%2Fmesa.git compiler/types: Use designated initializer syntax to specify builtins For now we use a temporary glsl_type_params struct, we will be able to use the glsl_type directly once we make it a POD ("plain old data") struct by getting rid of its constructors and destructors. Note that since the name is statically allocated, there's no need to strdup() it, deallocate it and also no need to have a mem_ctx. Reviewed-by: Emma Anholt Part-of: --- diff --git a/src/compiler/builtin_type_macros.h b/src/compiler/builtin_type_macros.h index d2e8215..114f095 100644 --- a/src/compiler/builtin_type_macros.h +++ b/src/compiler/builtin_type_macros.h @@ -29,10 +29,10 @@ */ #define DECL_SIMPLE_TYPE(NAME, GLTYPE, BASE_TYPE, ELEMENTS, COLS) \ - DECL_TYPE(NAME, GLTYPE, BASE_TYPE, ELEMENTS, COLS) + DECL_TYPE(NAME, { .gl_type = GLTYPE, .base_type = BASE_TYPE, .vector_elements = ELEMENTS, .matrix_columns = COLS, .name = #NAME }) #define DECL_SAMPLER_TYPE(NAME, GLTYPE, BASE_TYPE, DIM, SHADOW, ARRAY, SAMPLED_TYPE) \ - DECL_TYPE(NAME, GLTYPE, BASE_TYPE, DIM, SHADOW, ARRAY, SAMPLED_TYPE) + DECL_TYPE(NAME, { .gl_type = GLTYPE, .base_type = BASE_TYPE, .sampled_type = SAMPLED_TYPE, .sampler_dimensionality = DIM, .sampler_shadow = SHADOW, .sampler_array = ARRAY, .vector_elements = 1, .matrix_columns = 1, .name = #NAME }) DECL_SIMPLE_TYPE(error, GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0) DECL_SIMPLE_TYPE(void, GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0) diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index f623906..ebd9c84 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -22,6 +22,7 @@ */ #include +#include #include "glsl_types.h" #include "util/compiler.h" #include "util/glheader.h" @@ -46,6 +47,20 @@ hash_table *glsl_type::subroutine_types = NULL; */ static uint32_t glsl_type_users = 0; +glsl_type::glsl_type(const glsl_type_params ¶ms) +{ + gl_type = params.gl_type; + base_type = params.base_type; + sampled_type = params.sampled_type; + sampler_dimensionality = params.sampler_dimensionality; + sampler_shadow = params.sampler_shadow; + sampler_array = params.sampler_array; + vector_elements = params.vector_elements; + matrix_columns = params.matrix_columns; + length = params.length; + name = params.name; +} + glsl_type::glsl_type(uint32_t gl_type, glsl_base_type base_type, unsigned vector_elements, unsigned matrix_columns, const char *name, @@ -2923,7 +2938,7 @@ glsl_type::coordinate_components() const * @{ */ #define DECL_TYPE(NAME, ...) \ - const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \ + const glsl_type glsl_type::_##NAME##_type = glsl_type((glsl_type_params)__VA_ARGS__); \ const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type; #include "compiler/builtin_type_macros.h" #undef DECL_TYPE diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index 233297c..8e7a89b 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -287,6 +287,20 @@ enum { /* C++ struct types for glsl */ #ifdef __cplusplus +/* TODO: Remove this once glsl_type is a plain struct. */ +struct glsl_type_params { + uint32_t gl_type; + glsl_base_type base_type:8; + glsl_base_type sampled_type:8; + unsigned sampler_dimensionality:4; + unsigned sampler_shadow:1; + unsigned sampler_array:1; + uint8_t vector_elements; + uint8_t matrix_columns; + unsigned length; + const char *name; +}; + struct glsl_type { uint32_t gl_type; glsl_base_type base_type:8; @@ -1233,6 +1247,9 @@ private: */ void *mem_ctx; + /** Constructor for builtins. */ + explicit glsl_type(const glsl_type_params ¶ms); + /** Constructor for vector and matrix types */ glsl_type(uint32_t gl_type, glsl_base_type base_type, unsigned vector_elements,