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 <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25006>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user