From bc9277d81cd7201ea53feabbbfdf1006af3e0ded Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 6 Sep 2023 18:25:46 -0700 Subject: [PATCH] compiler/types: Move builtin type initialization to C While both clang and gcc can handle designated initializers in C++, MSVC only does with the C++20 support enabled. So move the initialization of builtins to a C file. Reviewed-by: Emma Anholt Part-of: --- src/compiler/builtin_type_defs.c | 13 +++++++++++++ src/compiler/glsl_types.cpp | 9 +-------- src/compiler/glsl_types.h | 14 +++++--------- src/compiler/meson.build | 1 + 4 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 src/compiler/builtin_type_defs.c diff --git a/src/compiler/builtin_type_defs.c b/src/compiler/builtin_type_defs.c new file mode 100644 index 00000000000..e0b437d8532 --- /dev/null +++ b/src/compiler/builtin_type_defs.c @@ -0,0 +1,13 @@ +/* + * Copyright © 2009 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "glsl_types.h" +#include "util/glheader.h" + +#define DECL_TYPE(NAME, ...) \ +const struct glsl_type glsl_type_builtin_##NAME = __VA_ARGS__; + +#include "compiler/builtin_type_macros.h" +#undef DECL_TYPE diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index 82e3ec33a6e..25c6cc0ac3b 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -2904,17 +2904,10 @@ glsl_type::coordinate_components() const return size; } -/** - * Declarations of type flyweights (glsl_type::_foo_type) and - * convenience pointers (glsl_type::foo_type). - * @{ - */ #define DECL_TYPE(NAME, ...) \ - const glsl_type glsl_type::_##NAME##_type = __VA_ARGS__; \ - const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type; + const glsl_type *const glsl_type::NAME##_type = &glsl_type_builtin_##NAME; #include "compiler/builtin_type_macros.h" #undef DECL_TYPE -/** @} */ union packed_type { uint32_t u32; diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index 5da8df12a87..6d60ba5d5c3 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -1213,15 +1213,6 @@ private: static bool record_key_compare(const void *a, const void *b); static unsigned record_key_hash(const void *key); - /** - * \name Built-in type flyweights - */ - /*@{*/ -#define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type; -#include "compiler/builtin_type_macros.h" -#undef DECL_TYPE - /*@}*/ - /** * \name Friend functions. * @@ -1240,6 +1231,11 @@ private: #endif /* __cplusplus */ }; +#define DECL_TYPE(NAME, ...) \ +extern const struct glsl_type glsl_type_builtin_##NAME; +#include "compiler/builtin_type_macros.h" +#undef DECL_TYPE + struct glsl_struct_field { const struct glsl_type *type; const char *name; diff --git a/src/compiler/meson.build b/src/compiler/meson.build index 38218e55444..20c807048b2 100644 --- a/src/compiler/meson.build +++ b/src/compiler/meson.build @@ -25,6 +25,7 @@ inc_spirv = include_directories('spirv') float64_glsl_file = files('glsl/float64.glsl') files_libcompiler = files( + 'builtin_type_defs.c', 'builtin_type_macros.h', 'glsl_types.cpp', 'glsl_types.h',