2010-03-10 21:58:12 +00:00
|
|
|
/* -*- c++ -*- */
|
2010-02-22 21:19:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2009 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef GLSL_TYPES_H
|
|
|
|
#define GLSL_TYPES_H
|
|
|
|
|
2011-02-10 18:26:42 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2011-11-14 22:02:09 +00:00
|
|
|
#include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */
|
2010-03-09 23:17:37 +00:00
|
|
|
|
2011-10-12 00:11:40 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-11-09 10:20:51 +00:00
|
|
|
struct _mesa_glsl_parse_state;
|
|
|
|
struct glsl_symbol_table;
|
|
|
|
|
2011-10-12 00:11:40 +01:00
|
|
|
extern void
|
2010-06-28 19:01:57 +01:00
|
|
|
_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
|
|
|
|
|
2011-10-12 00:11:40 +01:00
|
|
|
extern void
|
2010-06-28 21:17:18 +01:00
|
|
|
_mesa_glsl_release_types(void);
|
|
|
|
|
2011-10-12 00:11:40 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-11 07:20:47 +00:00
|
|
|
enum glsl_base_type {
|
|
|
|
GLSL_TYPE_UINT = 0,
|
|
|
|
GLSL_TYPE_INT,
|
|
|
|
GLSL_TYPE_FLOAT,
|
|
|
|
GLSL_TYPE_BOOL,
|
|
|
|
GLSL_TYPE_SAMPLER,
|
2013-10-20 20:35:47 +01:00
|
|
|
GLSL_TYPE_ATOMIC_UINT,
|
2010-11-11 07:20:47 +00:00
|
|
|
GLSL_TYPE_STRUCT,
|
2012-12-11 20:11:16 +00:00
|
|
|
GLSL_TYPE_INTERFACE,
|
2010-11-11 07:20:47 +00:00
|
|
|
GLSL_TYPE_ARRAY,
|
|
|
|
GLSL_TYPE_VOID,
|
|
|
|
GLSL_TYPE_ERROR
|
|
|
|
};
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-03-09 23:17:37 +00:00
|
|
|
enum glsl_sampler_dim {
|
|
|
|
GLSL_SAMPLER_DIM_1D = 0,
|
|
|
|
GLSL_SAMPLER_DIM_2D,
|
|
|
|
GLSL_SAMPLER_DIM_3D,
|
|
|
|
GLSL_SAMPLER_DIM_CUBE,
|
|
|
|
GLSL_SAMPLER_DIM_RECT,
|
2011-10-23 11:51:06 +01:00
|
|
|
GLSL_SAMPLER_DIM_BUF,
|
2012-12-21 08:33:37 +00:00
|
|
|
GLSL_SAMPLER_DIM_EXTERNAL,
|
|
|
|
GLSL_SAMPLER_DIM_MS
|
2010-03-09 23:17:37 +00:00
|
|
|
};
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2012-12-11 20:11:16 +00:00
|
|
|
enum glsl_interface_packing {
|
|
|
|
GLSL_INTERFACE_PACKING_STD140,
|
|
|
|
GLSL_INTERFACE_PACKING_SHARED,
|
|
|
|
GLSL_INTERFACE_PACKING_PACKED
|
|
|
|
};
|
|
|
|
|
2011-10-12 00:11:40 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "GL/gl.h"
|
|
|
|
#include "ralloc.h"
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
struct glsl_type {
|
2010-06-25 22:27:07 +01:00
|
|
|
GLenum gl_type;
|
2010-11-11 07:20:47 +00:00
|
|
|
glsl_base_type base_type;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2011-03-03 22:07:42 +00:00
|
|
|
unsigned sampler_dimensionality:3; /**< \see glsl_sampler_dim */
|
2010-02-22 21:19:34 +00:00
|
|
|
unsigned sampler_shadow:1;
|
|
|
|
unsigned sampler_array:1;
|
|
|
|
unsigned sampler_type:2; /**< Type of data returned using this sampler.
|
|
|
|
* only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
|
|
|
|
* and \c GLSL_TYPE_UINT are valid.
|
|
|
|
*/
|
2012-12-11 20:11:16 +00:00
|
|
|
unsigned interface_packing:2;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2011-01-21 22:32:31 +00:00
|
|
|
/* Callers of this ralloc-based new need not call delete. It's
|
|
|
|
* easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
|
2010-06-28 20:19:52 +01:00
|
|
|
static void* operator new(size_t size)
|
2010-06-24 03:04:45 +01:00
|
|
|
{
|
2010-08-04 04:05:53 +01:00
|
|
|
if (glsl_type::mem_ctx == NULL) {
|
2011-01-21 22:32:31 +00:00
|
|
|
glsl_type::mem_ctx = ralloc_context(NULL);
|
2010-08-04 04:05:53 +01:00
|
|
|
assert(glsl_type::mem_ctx != NULL);
|
2010-06-28 20:19:52 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:04:45 +01:00
|
|
|
void *type;
|
|
|
|
|
2011-01-21 22:32:31 +00:00
|
|
|
type = ralloc_size(glsl_type::mem_ctx, size);
|
2010-06-24 03:04:45 +01:00
|
|
|
assert(type != NULL);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the user *does* call delete, that's OK, we will just
|
2011-01-21 22:32:31 +00:00
|
|
|
* ralloc_free in that case. */
|
2010-06-24 03:04:45 +01:00
|
|
|
static void operator delete(void *type)
|
|
|
|
{
|
2011-01-21 22:32:31 +00:00
|
|
|
ralloc_free(type);
|
2010-06-24 03:04:45 +01:00
|
|
|
}
|
|
|
|
|
2010-03-26 18:43:36 +00:00
|
|
|
/**
|
|
|
|
* \name Vector and matrix element counts
|
|
|
|
*
|
|
|
|
* For scalars, each of these values will be 1. For non-numeric types
|
|
|
|
* these will be 0.
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */
|
|
|
|
unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */
|
|
|
|
/*@}*/
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the data type
|
|
|
|
*
|
2013-04-10 04:36:30 +01:00
|
|
|
* Will never be \c NULL.
|
2010-02-22 21:19:34 +00:00
|
|
|
*/
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For \c GLSL_TYPE_ARRAY, this is the length of the array. For
|
2012-12-11 20:11:16 +00:00
|
|
|
* \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
|
|
|
|
* elements in the structure and the number of values pointed to by
|
|
|
|
* \c fields.structure (below).
|
2010-02-22 21:19:34 +00:00
|
|
|
*/
|
|
|
|
unsigned length;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtype of composite data types.
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
const struct glsl_type *array; /**< Type of array elements. */
|
|
|
|
const struct glsl_type *parameters; /**< Parameters to function. */
|
2010-07-21 00:47:25 +01:00
|
|
|
struct glsl_struct_field *structure; /**< List of struct fields. */
|
2010-02-22 21:19:34 +00:00
|
|
|
} fields;
|
2010-03-09 23:17:37 +00:00
|
|
|
|
2010-03-26 21:33:41 +00:00
|
|
|
/**
|
|
|
|
* \name Pointers to various public type singletons
|
|
|
|
*/
|
|
|
|
/*@{*/
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
#undef DECL_TYPE
|
2013-06-27 07:41:36 +01:00
|
|
|
#define DECL_TYPE(NAME, ...) \
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
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"
|
2010-03-26 21:33:41 +00:00
|
|
|
/*@}*/
|
|
|
|
|
2013-06-18 12:22:30 +01:00
|
|
|
/**
|
|
|
|
* Convenience accessors for vector types (shorter than get_instance()).
|
|
|
|
* @{
|
|
|
|
*/
|
2013-07-26 21:37:29 +01:00
|
|
|
static const glsl_type *vec(unsigned components);
|
|
|
|
static const glsl_type *ivec(unsigned components);
|
|
|
|
static const glsl_type *uvec(unsigned components);
|
|
|
|
static const glsl_type *bvec(unsigned components);
|
2013-06-18 12:22:30 +01:00
|
|
|
/**@}*/
|
2010-03-26 21:33:41 +00:00
|
|
|
|
2010-03-24 00:31:39 +00:00
|
|
|
/**
|
|
|
|
* For numeric and boolean derrived types returns the basic scalar type
|
|
|
|
*
|
|
|
|
* If the type is a numeric or boolean scalar, vector, or matrix type,
|
|
|
|
* this function gets the scalar type of the individual components. For
|
|
|
|
* all other types, including arrays of numeric or boolean types, the
|
|
|
|
* error type is returned.
|
|
|
|
*/
|
|
|
|
const glsl_type *get_base_type() const;
|
|
|
|
|
2010-04-02 01:17:34 +01:00
|
|
|
/**
|
2011-10-26 00:24:03 +01:00
|
|
|
* Get the basic scalar type which this type aggregates.
|
|
|
|
*
|
|
|
|
* If the type is a numeric or boolean scalar, vector, or matrix, or an
|
|
|
|
* array of any of those, this function gets the scalar type of the
|
|
|
|
* individual components. For structs and arrays of structs, this function
|
|
|
|
* returns the struct type. For samplers and arrays of samplers, this
|
|
|
|
* function returns the sampler type.
|
|
|
|
*/
|
|
|
|
const glsl_type *get_scalar_type() const;
|
|
|
|
|
|
|
|
/**
|
2010-04-02 01:17:34 +01:00
|
|
|
* Query the type of elements in an array
|
|
|
|
*
|
|
|
|
* \return
|
|
|
|
* Pointer to the type of elements in the array for array types, or \c NULL
|
|
|
|
* for non-array types.
|
|
|
|
*/
|
|
|
|
const glsl_type *element_type() const
|
|
|
|
{
|
|
|
|
return is_array() ? fields.array : NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-25 00:11:30 +00:00
|
|
|
/**
|
|
|
|
* Get the instance of a built-in scalar, vector, or matrix type
|
|
|
|
*/
|
|
|
|
static const glsl_type *get_instance(unsigned base_type, unsigned rows,
|
|
|
|
unsigned columns);
|
|
|
|
|
2010-03-31 00:58:19 +01:00
|
|
|
/**
|
|
|
|
* Get the instance of an array type
|
|
|
|
*/
|
2010-07-20 23:33:40 +01:00
|
|
|
static const glsl_type *get_array_instance(const glsl_type *base,
|
2010-03-31 00:58:19 +01:00
|
|
|
unsigned elements);
|
|
|
|
|
2010-06-28 19:54:57 +01:00
|
|
|
/**
|
|
|
|
* Get the instance of a record type
|
|
|
|
*/
|
|
|
|
static const glsl_type *get_record_instance(const glsl_struct_field *fields,
|
|
|
|
unsigned num_fields,
|
|
|
|
const char *name);
|
2010-04-01 00:30:56 +01:00
|
|
|
|
2012-12-11 20:11:16 +00:00
|
|
|
/**
|
|
|
|
* Get the instance of an interface block type
|
|
|
|
*/
|
|
|
|
static const glsl_type *get_interface_instance(const glsl_struct_field *fields,
|
|
|
|
unsigned num_fields,
|
|
|
|
enum glsl_interface_packing packing,
|
2013-10-08 22:09:48 +01:00
|
|
|
const char *block_name);
|
2012-12-11 20:11:16 +00:00
|
|
|
|
2010-03-26 18:13:43 +00:00
|
|
|
/**
|
|
|
|
* Query the total number of scalars that make up a scalar, vector or matrix
|
|
|
|
*/
|
|
|
|
unsigned components() const
|
|
|
|
{
|
2010-03-26 18:43:36 +00:00
|
|
|
return vector_elements * matrix_columns;
|
2010-03-26 18:13:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 00:05:00 +01:00
|
|
|
/**
|
|
|
|
* Calculate the number of components slots required to hold this type
|
|
|
|
*
|
|
|
|
* This is used to determine how many uniform or varying locations a type
|
|
|
|
* might occupy.
|
|
|
|
*/
|
|
|
|
unsigned component_slots() const;
|
|
|
|
|
2013-07-31 16:15:08 +01:00
|
|
|
/**
|
|
|
|
* Calculate the number of attribute slots required to hold this type
|
|
|
|
*
|
|
|
|
* This implements the language rules of GLSL 1.50 for counting the number
|
|
|
|
* of slots used by a vertex attribute. It also determines the number of
|
|
|
|
* varying slots the type will use up in the absence of varying packing
|
|
|
|
* (and thus, it can be used to measure the number of varying slots used by
|
|
|
|
* the varyings that are generated by lower_packed_varyings).
|
|
|
|
*/
|
|
|
|
unsigned count_attribute_slots() const;
|
|
|
|
|
|
|
|
|
2012-05-01 23:10:14 +01:00
|
|
|
/**
|
|
|
|
* Alignment in bytes of the start of this type in a std140 uniform
|
|
|
|
* block.
|
|
|
|
*/
|
|
|
|
unsigned std140_base_alignment(bool row_major) const;
|
|
|
|
|
|
|
|
/** Size in bytes of this type in a std140 uniform block.
|
|
|
|
*
|
|
|
|
* Note that this is not GL_UNIFORM_SIZE (which is the number of
|
|
|
|
* elements in the array)
|
|
|
|
*/
|
|
|
|
unsigned std140_size(bool row_major) const;
|
|
|
|
|
2011-07-27 20:21:27 +01:00
|
|
|
/**
|
|
|
|
* \brief Can this type be implicitly converted to another?
|
|
|
|
*
|
|
|
|
* \return True if the types are identical or if this type can be converted
|
|
|
|
* to \c desired according to Section 4.1.10 of the GLSL spec.
|
|
|
|
*
|
|
|
|
* \verbatim
|
|
|
|
* From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
|
|
|
|
* Implicit Conversions:
|
|
|
|
*
|
|
|
|
* In some situations, an expression and its type will be implicitly
|
|
|
|
* converted to a different type. The following table shows all allowed
|
|
|
|
* implicit conversions:
|
|
|
|
*
|
|
|
|
* Type of expression | Can be implicitly converted to
|
|
|
|
* --------------------------------------------------
|
|
|
|
* int float
|
|
|
|
* uint
|
|
|
|
*
|
|
|
|
* ivec2 vec2
|
|
|
|
* uvec2
|
|
|
|
*
|
|
|
|
* ivec3 vec3
|
|
|
|
* uvec3
|
|
|
|
*
|
|
|
|
* ivec4 vec4
|
|
|
|
* uvec4
|
|
|
|
*
|
|
|
|
* There are no implicit array or structure conversions. For example,
|
|
|
|
* an array of int cannot be implicitly converted to an array of float.
|
|
|
|
* There are no implicit conversions between signed and unsigned
|
|
|
|
* integers.
|
|
|
|
* \endverbatim
|
|
|
|
*/
|
|
|
|
bool can_implicitly_convert_to(const glsl_type *desired) const;
|
2010-06-22 00:05:00 +01:00
|
|
|
|
2010-03-09 23:51:22 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a scalar (non-vector and non-matrix).
|
|
|
|
*/
|
|
|
|
bool is_scalar() const
|
|
|
|
{
|
2010-03-26 18:43:36 +00:00
|
|
|
return (vector_elements == 1)
|
2010-03-09 23:51:22 +00:00
|
|
|
&& (base_type >= GLSL_TYPE_UINT)
|
|
|
|
&& (base_type <= GLSL_TYPE_BOOL);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-03-09 23:55:16 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a vector
|
|
|
|
*/
|
|
|
|
bool is_vector() const
|
|
|
|
{
|
2010-03-26 18:43:36 +00:00
|
|
|
return (vector_elements > 1)
|
|
|
|
&& (matrix_columns == 1)
|
2010-03-09 23:55:16 +00:00
|
|
|
&& (base_type >= GLSL_TYPE_UINT)
|
|
|
|
&& (base_type <= GLSL_TYPE_BOOL);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-03-09 23:58:52 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a matrix
|
|
|
|
*/
|
|
|
|
bool is_matrix() const
|
|
|
|
{
|
|
|
|
/* GLSL only has float matrices. */
|
2010-03-26 18:43:36 +00:00
|
|
|
return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT);
|
2010-03-09 23:58:52 +00:00
|
|
|
}
|
2010-03-23 19:28:28 +00:00
|
|
|
|
2010-03-24 00:31:03 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a non-array numeric type
|
|
|
|
*/
|
|
|
|
bool is_numeric() const
|
|
|
|
{
|
|
|
|
return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_FLOAT);
|
|
|
|
}
|
|
|
|
|
2010-03-26 21:38:37 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is an integral type
|
|
|
|
*/
|
|
|
|
bool is_integer() const
|
|
|
|
{
|
|
|
|
return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
|
|
|
|
}
|
|
|
|
|
2013-02-07 00:09:39 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not type is an integral type, or for struct and array
|
|
|
|
* types, contains an integral type.
|
|
|
|
*/
|
|
|
|
bool contains_integer() const;
|
|
|
|
|
2010-03-30 00:17:15 +01:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a float type
|
|
|
|
*/
|
|
|
|
bool is_float() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_FLOAT;
|
|
|
|
}
|
|
|
|
|
2010-03-24 00:31:03 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a non-array boolean type
|
|
|
|
*/
|
|
|
|
bool is_boolean() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_BOOL;
|
|
|
|
}
|
|
|
|
|
2010-03-23 22:03:46 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a sampler
|
|
|
|
*/
|
|
|
|
bool is_sampler() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_SAMPLER;
|
|
|
|
}
|
|
|
|
|
2011-07-12 00:44:13 +01:00
|
|
|
/**
|
|
|
|
* Query whether or not type is a sampler, or for struct and array
|
|
|
|
* types, contains a sampler.
|
|
|
|
*/
|
|
|
|
bool contains_sampler() const;
|
|
|
|
|
2011-11-14 22:02:09 +00:00
|
|
|
/**
|
|
|
|
* Get the Mesa texture target index for a sampler type.
|
|
|
|
*/
|
|
|
|
gl_texture_index sampler_index() const;
|
|
|
|
|
2010-03-30 00:17:15 +01:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is an array
|
|
|
|
*/
|
|
|
|
bool is_array() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_ARRAY;
|
|
|
|
}
|
|
|
|
|
2010-06-10 01:17:47 +01:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is a record
|
|
|
|
*/
|
|
|
|
bool is_record() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_STRUCT;
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:11:16 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is an interface
|
|
|
|
*/
|
|
|
|
bool is_interface() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2010-03-23 19:28:28 +00:00
|
|
|
/**
|
|
|
|
* Query whether or not a type is the void type singleton.
|
|
|
|
*/
|
|
|
|
bool is_void() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query whether or not a type is the error type singleton.
|
|
|
|
*/
|
|
|
|
bool is_error() const
|
|
|
|
{
|
|
|
|
return base_type == GLSL_TYPE_ERROR;
|
|
|
|
}
|
2010-03-25 00:05:09 +00:00
|
|
|
|
2013-10-20 20:35:47 +01:00
|
|
|
/**
|
|
|
|
* Return the amount of atomic counter storage required for a type.
|
|
|
|
*/
|
|
|
|
unsigned atomic_size() const
|
|
|
|
{
|
|
|
|
if (base_type == GLSL_TYPE_ATOMIC_UINT)
|
|
|
|
return ATOMIC_COUNTER_SIZE;
|
|
|
|
else if (is_array())
|
|
|
|
return length * element_type()->atomic_size();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether a type contains any atomic counters.
|
|
|
|
*/
|
|
|
|
bool contains_atomic() const
|
|
|
|
{
|
2013-10-29 20:09:46 +00:00
|
|
|
return atomic_size() > 0;
|
2013-10-20 20:35:47 +01:00
|
|
|
}
|
|
|
|
|
2013-09-20 22:58:03 +01:00
|
|
|
/**
|
|
|
|
* Return whether a type contains any opaque types.
|
|
|
|
*/
|
|
|
|
bool contains_opaque() const;
|
|
|
|
|
2010-03-25 18:42:45 +00:00
|
|
|
/**
|
|
|
|
* Query the full type of a matrix row
|
|
|
|
*
|
|
|
|
* \return
|
2010-03-26 21:33:41 +00:00
|
|
|
* If the type is not a matrix, \c glsl_type::error_type is returned.
|
|
|
|
* Otherwise a type matching the rows of the matrix is returned.
|
2010-03-25 18:42:45 +00:00
|
|
|
*/
|
|
|
|
const glsl_type *row_type() const
|
|
|
|
{
|
|
|
|
return is_matrix()
|
2010-03-25 20:19:13 +00:00
|
|
|
? get_instance(base_type, matrix_columns, 1)
|
2010-03-26 21:33:41 +00:00
|
|
|
: error_type;
|
2010-03-25 18:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query the full type of a matrix column
|
|
|
|
*
|
|
|
|
* \return
|
2010-03-26 21:33:41 +00:00
|
|
|
* If the type is not a matrix, \c glsl_type::error_type is returned.
|
|
|
|
* Otherwise a type matching the columns of the matrix is returned.
|
2010-03-25 18:42:45 +00:00
|
|
|
*/
|
|
|
|
const glsl_type *column_type() const
|
|
|
|
{
|
|
|
|
return is_matrix()
|
|
|
|
? get_instance(base_type, vector_elements, 1)
|
2010-03-26 21:33:41 +00:00
|
|
|
: error_type;
|
2010-03-25 18:42:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 23:40:01 +01:00
|
|
|
/**
|
|
|
|
* Get the type of a structure field
|
|
|
|
*
|
|
|
|
* \return
|
|
|
|
* Pointer to the type of the named field. If the type is not a structure
|
|
|
|
* or the named field does not exist, \c glsl_type::error_type is returned.
|
|
|
|
*/
|
|
|
|
const glsl_type *field_type(const char *name) const;
|
|
|
|
|
2010-06-10 01:27:31 +01:00
|
|
|
/**
|
|
|
|
* Get the location of a filed within a record type
|
|
|
|
*/
|
|
|
|
int field_index(const char *name) const;
|
|
|
|
|
2010-04-02 01:17:34 +01:00
|
|
|
/**
|
|
|
|
* Query the number of elements in an array type
|
|
|
|
*
|
|
|
|
* \return
|
|
|
|
* The number of elements in the array for array types or -1 for non-array
|
|
|
|
* types. If the number of elements in the array has not yet been declared,
|
|
|
|
* zero is returned.
|
|
|
|
*/
|
|
|
|
int array_size() const
|
|
|
|
{
|
|
|
|
return is_array() ? length : -1;
|
|
|
|
}
|
|
|
|
|
2013-10-23 11:31:27 +01:00
|
|
|
/**
|
|
|
|
* Query whether the array size for all dimensions has been declared.
|
|
|
|
*/
|
|
|
|
bool is_unsized_array() const
|
|
|
|
{
|
|
|
|
return is_array() && length == 0;
|
|
|
|
}
|
|
|
|
|
2013-09-11 19:14:14 +01:00
|
|
|
/**
|
|
|
|
* Return the number of coordinate components needed for this sampler type.
|
|
|
|
*
|
|
|
|
* This is based purely on the sampler's dimensionality. For example, this
|
|
|
|
* returns 1 for sampler1D, and 3 for sampler2DArray.
|
|
|
|
*
|
|
|
|
* Note that this is often different than actual coordinate type used in
|
|
|
|
* a texturing built-in function, since those pack additional values (such
|
|
|
|
* as the shadow comparitor or projector) into the coordinate type.
|
|
|
|
*/
|
|
|
|
int sampler_coordinate_components() const;
|
|
|
|
|
2010-08-02 19:35:14 +01:00
|
|
|
private:
|
2010-06-28 20:19:52 +01:00
|
|
|
/**
|
2011-01-21 22:32:31 +00:00
|
|
|
* ralloc context for all glsl_type allocations
|
2010-06-28 20:19:52 +01:00
|
|
|
*
|
|
|
|
* Set on the first call to \c glsl_type::new.
|
|
|
|
*/
|
2010-08-04 04:05:53 +01:00
|
|
|
static void *mem_ctx;
|
2010-06-28 20:19:52 +01:00
|
|
|
|
2011-01-21 22:32:31 +00:00
|
|
|
void init_ralloc_type_ctx(void);
|
2010-08-02 19:35:14 +01:00
|
|
|
|
2010-06-28 19:09:40 +01:00
|
|
|
/** Constructor for vector and matrix types */
|
|
|
|
glsl_type(GLenum gl_type,
|
2010-11-11 07:20:47 +00:00
|
|
|
glsl_base_type base_type, unsigned vector_elements,
|
2010-06-28 19:09:40 +01:00
|
|
|
unsigned matrix_columns, const char *name);
|
|
|
|
|
|
|
|
/** Constructor for sampler types */
|
|
|
|
glsl_type(GLenum gl_type,
|
|
|
|
enum glsl_sampler_dim dim, bool shadow, bool array,
|
|
|
|
unsigned type, const char *name);
|
|
|
|
|
2010-06-28 19:57:38 +01:00
|
|
|
/** Constructor for record types */
|
|
|
|
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
|
|
|
|
const char *name);
|
|
|
|
|
2012-12-11 20:11:16 +00:00
|
|
|
/** Constructor for interface types */
|
|
|
|
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
|
|
|
|
enum glsl_interface_packing packing, const char *name);
|
|
|
|
|
2010-06-28 19:09:40 +01:00
|
|
|
/** Constructor for array types */
|
2010-07-20 23:33:40 +01:00
|
|
|
glsl_type(const glsl_type *array, unsigned length);
|
2010-03-31 22:37:42 +01:00
|
|
|
|
2010-03-31 00:58:19 +01:00
|
|
|
/** Hash table containing the known array types. */
|
|
|
|
static struct hash_table *array_types;
|
|
|
|
|
2010-06-28 19:54:57 +01:00
|
|
|
/** Hash table containing the known record types. */
|
|
|
|
static struct hash_table *record_types;
|
|
|
|
|
2012-12-11 20:11:16 +00:00
|
|
|
/** Hash table containing the known interface types. */
|
|
|
|
static struct hash_table *interface_types;
|
|
|
|
|
2010-06-28 19:54:57 +01:00
|
|
|
static int record_key_compare(const void *a, const void *b);
|
|
|
|
static unsigned record_key_hash(const void *key);
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
/**
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
* \name Built-in type flyweights
|
2010-06-28 19:01:57 +01:00
|
|
|
*/
|
|
|
|
/*@{*/
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
#undef DECL_TYPE
|
2013-06-27 07:41:36 +01:00
|
|
|
#define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
#undef STRUCT_TYPE
|
|
|
|
#define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
|
|
|
|
#include "builtin_type_macros.h"
|
2010-06-28 21:17:18 +01:00
|
|
|
/*@}*/
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
/**
|
2010-06-28 21:17:18 +01:00
|
|
|
* \name Friend functions.
|
|
|
|
*
|
|
|
|
* These functions are friends because they must have C linkage and the
|
|
|
|
* need to call various private methods or access various private static
|
|
|
|
* data.
|
2010-06-28 19:01:57 +01:00
|
|
|
*/
|
2010-06-28 21:17:18 +01:00
|
|
|
/*@{*/
|
2010-06-28 19:01:57 +01:00
|
|
|
friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
|
2010-06-28 21:17:18 +01:00
|
|
|
friend void _mesa_glsl_release_types(void);
|
2010-06-28 19:01:57 +01:00
|
|
|
/*@}*/
|
2010-03-09 23:58:52 +00:00
|
|
|
};
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
struct glsl_struct_field {
|
|
|
|
const struct glsl_type *type;
|
|
|
|
const char *name;
|
2012-12-11 20:09:32 +00:00
|
|
|
bool row_major;
|
2013-09-10 00:39:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For interface blocks, gl_varying_slot corresponding to the input/output
|
|
|
|
* if this is a built-in input/output (i.e. a member of the built-in
|
|
|
|
* gl_PerVertex interface block); -1 otherwise.
|
|
|
|
*
|
|
|
|
* Ignored for structs.
|
|
|
|
*/
|
|
|
|
int location;
|
2013-10-22 23:11:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For interface blocks, the interpolation mode (as in
|
|
|
|
* ir_variable::interpolation). 0 otherwise.
|
|
|
|
*/
|
|
|
|
unsigned interpolation:2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For interface blocks, 1 if this variable uses centroid interpolation (as
|
|
|
|
* in ir_variable::centroid). 0 otherwise.
|
|
|
|
*/
|
|
|
|
unsigned centroid:1;
|
2013-11-29 08:26:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For interface blocks, 1 if this variable uses sample interpolation (as
|
|
|
|
* in ir_variable::sample). 0 otherwise.
|
|
|
|
*/
|
|
|
|
unsigned sample:1;
|
2010-02-22 21:19:34 +00:00
|
|
|
};
|
|
|
|
|
2013-01-22 05:06:10 +00:00
|
|
|
static inline unsigned int
|
|
|
|
glsl_align(unsigned int a, unsigned int align)
|
|
|
|
{
|
|
|
|
return (a + align - 1) / align * align;
|
|
|
|
}
|
|
|
|
|
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>
2013-06-18 12:22:33 +01:00
|
|
|
#undef DECL_TYPE
|
|
|
|
#undef STRUCT_TYPE
|
2011-10-12 00:11:40 +01:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
#endif /* GLSL_TYPES_H */
|