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>
This commit is contained in:
Kenneth Graunke
2013-06-18 04:22:33 -07:00
parent 818da74af5
commit 4563dfe23a
6 changed files with 424 additions and 694 deletions
+1
View File
@@ -21,6 +21,7 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/ast_function.cpp \
$(GLSL_SRCDIR)/ast_to_hir.cpp \
$(GLSL_SRCDIR)/ast_type.cpp \
$(GLSL_SRCDIR)/builtin_types.cpp \
$(GLSL_SRCDIR)/builtin_variables.cpp \
$(GLSL_SRCDIR)/glsl_parser_extras.cpp \
$(GLSL_SRCDIR)/glsl_types.cpp \
+120
View File
@@ -0,0 +1,120 @@
/*
* Copyright © 2013 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.
*/
/**
* \file builtin_type_macros.h
*
* This contains definitions for all GLSL built-in types, regardless of what
* language version or extension might provide them.
*/
#include "glsl_types.h"
DECL_TYPE(error, GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0)
DECL_TYPE(void, GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0)
DECL_TYPE(bool, GL_BOOL, GLSL_TYPE_BOOL, 1, 1)
DECL_TYPE(bvec2, GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1)
DECL_TYPE(bvec3, GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1)
DECL_TYPE(bvec4, GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1)
DECL_TYPE(int, GL_INT, GLSL_TYPE_INT, 1, 1)
DECL_TYPE(ivec2, GL_INT_VEC2, GLSL_TYPE_INT, 2, 1)
DECL_TYPE(ivec3, GL_INT_VEC3, GLSL_TYPE_INT, 3, 1)
DECL_TYPE(ivec4, GL_INT_VEC4, GLSL_TYPE_INT, 4, 1)
DECL_TYPE(uint, GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1)
DECL_TYPE(uvec2, GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1)
DECL_TYPE(uvec3, GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1)
DECL_TYPE(uvec4, GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1)
DECL_TYPE(float, GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1)
DECL_TYPE(vec2, GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1)
DECL_TYPE(vec3, GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1)
DECL_TYPE(vec4, GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1)
DECL_TYPE(mat2, GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2)
DECL_TYPE(mat3, GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3)
DECL_TYPE(mat4, GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4)
DECL_TYPE(mat2x3, GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2)
DECL_TYPE(mat2x4, GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2)
DECL_TYPE(mat3x2, GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3)
DECL_TYPE(mat3x4, GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3)
DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4)
DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4)
DECL_TYPE(sampler1D, GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2D, GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler3D, GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerCube, GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler1DArray, GL_SAMPLER_1D_ARRAY, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DArray, GL_SAMPLER_2D_ARRAY, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerCubeArray, GL_SAMPLER_CUBE_MAP_ARRAY, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DRect, GL_SAMPLER_2D_RECT, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerBuffer, GL_SAMPLER_BUFFER, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DMS, GL_SAMPLER_2D_MULTISAMPLE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DMSArray, GL_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(isampler1D, GL_INT_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isampler2D, GL_INT_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isampler3D, GL_INT_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isamplerCube, GL_INT_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isampler1DArray, GL_INT_SAMPLER_1D_ARRAY, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(isampler2DArray, GL_INT_SAMPLER_2D_ARRAY, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(isamplerCubeArray, GL_INT_SAMPLER_CUBE_MAP_ARRAY, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(isampler2DRect, GL_INT_SAMPLER_2D_RECT, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isamplerBuffer, GL_INT_SAMPLER_BUFFER, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isampler2DMS, GL_INT_SAMPLER_2D_MULTISAMPLE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(isampler2DMSArray, GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(usampler1D, GL_UNSIGNED_INT_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usampler2D, GL_UNSIGNED_INT_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usampler3D, GL_UNSIGNED_INT_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usamplerCube, GL_INT_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usampler1DArray, GL_UNSIGNED_INT_SAMPLER_1D_ARRAY, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(usampler2DArray, GL_UNSIGNED_INT_SAMPLER_2D_ARRAY, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(usamplerCubeArray, GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(usampler2DRect, GL_UNSIGNED_INT_SAMPLER_2D_RECT, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usamplerBuffer, GL_UNSIGNED_INT_SAMPLER_BUFFER, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usampler2DMS, GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(usampler2DMSArray, GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(sampler1DShadow, GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DShadow, GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerCubeShadow, GL_SAMPLER_CUBE_SHADOW, GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler1DArrayShadow, GL_SAMPLER_1D_ARRAY_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DArrayShadow, GL_SAMPLER_2D_ARRAY_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerCubeArrayShadow, GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW, GLSL_SAMPLER_DIM_CUBE, 1, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2DRectShadow, GL_SAMPLER_2D_RECT_SHADOW, GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(samplerExternalOES, GL_SAMPLER_EXTERNAL_OES, GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT)
STRUCT_TYPE(gl_DepthRangeParameters)
STRUCT_TYPE(gl_PointParameters)
STRUCT_TYPE(gl_MaterialParameters)
STRUCT_TYPE(gl_LightSourceParameters)
STRUCT_TYPE(gl_LightModelParameters)
STRUCT_TYPE(gl_LightModelProducts)
STRUCT_TYPE(gl_LightProducts)
STRUCT_TYPE(gl_FogParameters)
+288
View File
@@ -0,0 +1,288 @@
/*
* Copyright © 2013 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.
*/
/**
* \file builtin_types.cpp
*
* The glsl_type class has static members to represent all the built-in types
* (such as the glsl_type::_float_type flyweight) as well as convenience pointer
* accessors (such as glsl_type::float_type). Those global variables are
* declared and initialized in this file.
*
* This also contains _mesa_glsl_initialize_types(), a function which populates
* a symbol table with the available built-in types for a particular language
* version and set of enabled extensions.
*/
#include "glsl_types.h"
#include "glsl_parser_extras.h"
/**
* Declarations of type flyweights (glsl_type::_foo_type) and
* convenience pointers (glsl_type::foo_type).
* @{
*/
#define DECL_TYPE(NAME, REST...) \
const glsl_type glsl_type::_##NAME##_type = glsl_type(REST, #NAME); \
const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
#define STRUCT_TYPE(NAME) \
const glsl_type glsl_type::_struct_##NAME##_type = \
glsl_type(NAME##_fields, Elements(NAME##_fields), #NAME); \
const glsl_type *const glsl_type::struct_##NAME##_type = \
&glsl_type::_struct_##NAME##_type;
static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
{ glsl_type::float_type, "near", false },
{ glsl_type::float_type, "far", false },
{ glsl_type::float_type, "diff", false },
};
static const struct glsl_struct_field gl_PointParameters_fields[] = {
{ glsl_type::float_type, "size", false },
{ glsl_type::float_type, "sizeMin", false },
{ glsl_type::float_type, "sizeMax", false },
{ glsl_type::float_type, "fadeThresholdSize", false },
{ glsl_type::float_type, "distanceConstantAttenuation", false },
{ glsl_type::float_type, "distanceLinearAttenuation", false },
{ glsl_type::float_type, "distanceQuadraticAttenuation", false },
};
static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
{ glsl_type::vec4_type, "emission", false },
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
{ glsl_type::float_type, "shininess", false },
};
static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
{ glsl_type::vec4_type, "position", false },
{ glsl_type::vec4_type, "halfVector", false },
{ glsl_type::vec3_type, "spotDirection", false },
{ glsl_type::float_type, "spotExponent", false },
{ glsl_type::float_type, "spotCutoff", false },
{ glsl_type::float_type, "spotCosCutoff", false },
{ glsl_type::float_type, "constantAttenuation", false },
{ glsl_type::float_type, "linearAttenuation", false },
{ glsl_type::float_type, "quadraticAttenuation", false },
};
static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
};
static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
{ glsl_type::vec4_type, "sceneColor", false },
};
static const struct glsl_struct_field gl_LightProducts_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
};
static const struct glsl_struct_field gl_FogParameters_fields[] = {
{ glsl_type::vec4_type, "color", false },
{ glsl_type::float_type, "density", false },
{ glsl_type::float_type, "start", false },
{ glsl_type::float_type, "end", false },
{ glsl_type::float_type, "scale", false },
};
#include "builtin_type_macros.h"
/** @} */
/**
* Code to populate a symbol table with the built-in types available in a
* particular shading language version. The table below contains tags every
* type with the GLSL/GLSL ES versions where it was introduced.
*
* @{
*/
#define T(TYPE, MIN_GL, MIN_ES) \
{ glsl_type::TYPE##_type, MIN_GL, MIN_ES },
const static struct builtin_type_versions {
const glsl_type *const type;
int min_gl;
int min_es;
} builtin_type_versions[] = {
T(void, 110, 100)
T(bool, 110, 100)
T(bvec2, 110, 100)
T(bvec3, 110, 100)
T(bvec4, 110, 100)
T(int, 110, 100)
T(ivec2, 110, 100)
T(ivec3, 110, 100)
T(ivec4, 110, 100)
T(uint, 130, 300)
T(uvec2, 130, 300)
T(uvec3, 130, 300)
T(uvec4, 130, 300)
T(float, 110, 100)
T(vec2, 110, 100)
T(vec3, 110, 100)
T(vec4, 110, 100)
T(mat2, 110, 100)
T(mat3, 110, 100)
T(mat4, 110, 100)
T(mat2x3, 120, 300)
T(mat2x4, 120, 300)
T(mat3x2, 120, 300)
T(mat3x4, 120, 300)
T(mat4x2, 120, 300)
T(mat4x3, 120, 300)
T(sampler1D, 110, 999)
T(sampler2D, 110, 100)
T(sampler3D, 110, 300)
T(samplerCube, 110, 100)
T(sampler1DArray, 130, 999)
T(sampler2DArray, 130, 300)
T(samplerCubeArray, 400, 999)
T(sampler2DRect, 140, 999)
T(samplerBuffer, 140, 999)
T(sampler2DMS, 150, 999)
T(sampler2DMSArray, 150, 999)
T(isampler1D, 130, 999)
T(isampler2D, 130, 300)
T(isampler3D, 130, 300)
T(isamplerCube, 130, 300)
T(isampler1DArray, 130, 999)
T(isampler2DArray, 130, 300)
T(isamplerCubeArray, 400, 999)
T(isampler2DRect, 140, 999)
T(isamplerBuffer, 140, 999)
T(isampler2DMS, 150, 999)
T(isampler2DMSArray, 150, 999)
T(usampler1D, 130, 999)
T(usampler2D, 130, 300)
T(usampler3D, 130, 300)
T(usamplerCube, 130, 300)
T(usampler1DArray, 130, 999)
T(usampler2DArray, 130, 300)
T(usamplerCubeArray, 400, 999)
T(usampler2DRect, 140, 999)
T(usamplerBuffer, 140, 999)
T(usampler2DMS, 150, 999)
T(usampler2DMSArray, 150, 999)
T(sampler1DShadow, 110, 999)
T(sampler2DShadow, 110, 300)
T(samplerCubeShadow, 130, 300)
T(sampler1DArrayShadow, 130, 999)
T(sampler2DArrayShadow, 130, 300)
T(samplerCubeArrayShadow, 400, 999)
T(sampler2DRectShadow, 140, 999)
T(struct_gl_DepthRangeParameters, 110, 100)
};
const glsl_type *const deprecated_types[] = {
glsl_type::struct_gl_PointParameters_type,
glsl_type::struct_gl_MaterialParameters_type,
glsl_type::struct_gl_LightSourceParameters_type,
glsl_type::struct_gl_LightModelParameters_type,
glsl_type::struct_gl_LightModelProducts_type,
glsl_type::struct_gl_LightProducts_type,
glsl_type::struct_gl_FogParameters_type,
};
static inline void
add_type(glsl_symbol_table *symbols, const glsl_type *const type)
{
symbols->add_type(type->name, type);
}
/**
* Populate the symbol table with available built-in types.
*/
void
_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
{
struct glsl_symbol_table *symbols = state->symbols;
for (unsigned i = 0; i < Elements(builtin_type_versions); i++) {
const struct builtin_type_versions *const t = &builtin_type_versions[i];
if (state->is_version(t->min_gl, t->min_es)) {
add_type(symbols, t->type);
}
}
/* Add deprecated structure types. While these were deprecated in 1.30,
* they're still present. We've removed them in 1.40+ (OpenGL 3.1+).
*/
if (!state->es_shader && state->language_version < 140) {
for (unsigned i = 0; i < Elements(deprecated_types); i++) {
add_type(symbols, deprecated_types[i]);
}
}
/* Add types for enabled extensions. They may have already been added
* by the version-based loop, but attempting to add them a second time
* is harmless.
*/
if (state->ARB_texture_cube_map_array_enable) {
add_type(symbols, glsl_type::samplerCubeArray_type);
add_type(symbols, glsl_type::samplerCubeArrayShadow_type);
add_type(symbols, glsl_type::isamplerCubeArray_type);
add_type(symbols, glsl_type::usamplerCubeArray_type);
}
if (state->ARB_texture_multisample_enable) {
add_type(symbols, glsl_type::sampler2DMS_type);
add_type(symbols, glsl_type::isampler2DMS_type);
add_type(symbols, glsl_type::usampler2DMS_type);
add_type(symbols, glsl_type::sampler2DMSArray_type);
add_type(symbols, glsl_type::isampler2DMSArray_type);
add_type(symbols, glsl_type::usampler2DMSArray_type);
}
if (state->ARB_texture_rectangle_enable) {
add_type(symbols, glsl_type::sampler2DRect_type);
add_type(symbols, glsl_type::sampler2DRectShadow_type);
}
if (state->EXT_texture_array_enable) {
add_type(symbols, glsl_type::sampler1DArray_type);
add_type(symbols, glsl_type::sampler2DArray_type);
add_type(symbols, glsl_type::sampler1DArrayShadow_type);
add_type(symbols, glsl_type::sampler2DArrayShadow_type);
}
if (state->OES_EGL_image_external_enable) {
add_type(symbols, glsl_type::samplerExternalOES_type);
}
if (state->OES_texture_3D_enable) {
add_type(symbols, glsl_type::sampler3D_type);
}
}
/** @} */
-368
View File
@@ -1,368 +0,0 @@
/*
* 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.
*/
const glsl_type glsl_type::_error_type =
glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
const glsl_type glsl_type::_void_type =
glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
const glsl_type glsl_type::_sampler3D_type =
glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
"sampler3D");
const glsl_type glsl_type::_samplerCubeShadow_type =
glsl_type(GL_SAMPLER_CUBE_SHADOW,
GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT,
"samplerCubeShadow");
const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
const glsl_type *const glsl_type::void_type = & glsl_type::_void_type;
/** \name Core built-in types
*
* These types exist in all versions of GLSL.
*/
/*@{*/
const glsl_type glsl_type::builtin_core_types[] = {
glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"),
glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"),
glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"),
glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"),
glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"),
glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"),
glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"),
glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"),
glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"),
glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"),
glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"),
glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"),
glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"),
glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"),
glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"),
glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
"sampler2D"),
glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
"samplerCube"),
};
const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
const glsl_type *const glsl_type::bvec2_type = & builtin_core_types[1];
const glsl_type *const glsl_type::bvec3_type = & builtin_core_types[2];
const glsl_type *const glsl_type::bvec4_type = & builtin_core_types[3];
const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
const glsl_type *const glsl_type::ivec2_type = & builtin_core_types[5];
const glsl_type *const glsl_type::ivec3_type = & builtin_core_types[6];
const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
/*@}*/
/** \name GLSL structures that have not been deprecated.
*/
/*@{*/
static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
{ glsl_type::float_type, "near", false },
{ glsl_type::float_type, "far", false },
{ glsl_type::float_type, "diff", false },
};
const glsl_type glsl_type::builtin_structure_types[] = {
glsl_type(gl_DepthRangeParameters_fields,
Elements(gl_DepthRangeParameters_fields),
"gl_DepthRangeParameters"),
};
/*@}*/
/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
*/
/*@{*/
static const struct glsl_struct_field gl_PointParameters_fields[] = {
{ glsl_type::float_type, "size", false },
{ glsl_type::float_type, "sizeMin", false },
{ glsl_type::float_type, "sizeMax", false },
{ glsl_type::float_type, "fadeThresholdSize", false },
{ glsl_type::float_type, "distanceConstantAttenuation", false },
{ glsl_type::float_type, "distanceLinearAttenuation", false },
{ glsl_type::float_type, "distanceQuadraticAttenuation", false },
};
static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
{ glsl_type::vec4_type, "emission", false },
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
{ glsl_type::float_type, "shininess", false },
};
static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
{ glsl_type::vec4_type, "position", false },
{ glsl_type::vec4_type, "halfVector", false },
{ glsl_type::vec3_type, "spotDirection", false },
{ glsl_type::float_type, "spotExponent", false },
{ glsl_type::float_type, "spotCutoff", false },
{ glsl_type::float_type, "spotCosCutoff", false },
{ glsl_type::float_type, "constantAttenuation", false },
{ glsl_type::float_type, "linearAttenuation", false },
{ glsl_type::float_type, "quadraticAttenuation", false },
};
static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
};
static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
{ glsl_type::vec4_type, "sceneColor", false },
};
static const struct glsl_struct_field gl_LightProducts_fields[] = {
{ glsl_type::vec4_type, "ambient", false },
{ glsl_type::vec4_type, "diffuse", false },
{ glsl_type::vec4_type, "specular", false },
};
static const struct glsl_struct_field gl_FogParameters_fields[] = {
{ glsl_type::vec4_type, "color", false },
{ glsl_type::float_type, "density", false },
{ glsl_type::float_type, "start", false },
{ glsl_type::float_type, "end", false },
{ glsl_type::float_type, "scale", false },
};
const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
glsl_type(gl_PointParameters_fields,
Elements(gl_PointParameters_fields),
"gl_PointParameters"),
glsl_type(gl_MaterialParameters_fields,
Elements(gl_MaterialParameters_fields),
"gl_MaterialParameters"),
glsl_type(gl_LightSourceParameters_fields,
Elements(gl_LightSourceParameters_fields),
"gl_LightSourceParameters"),
glsl_type(gl_LightModelParameters_fields,
Elements(gl_LightModelParameters_fields),
"gl_LightModelParameters"),
glsl_type(gl_LightModelProducts_fields,
Elements(gl_LightModelProducts_fields),
"gl_LightModelProducts"),
glsl_type(gl_LightProducts_fields,
Elements(gl_LightProducts_fields),
"gl_LightProducts"),
glsl_type(gl_FogParameters_fields,
Elements(gl_FogParameters_fields),
"gl_FogParameters"),
};
/*@}*/
/** \name Types in GLSL 1.10 (but not GLSL ES 1.00)
*/
/*@{*/
const glsl_type glsl_type::builtin_110_types[] = {
glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
"sampler1D"),
glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
"sampler1DShadow"),
glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
"sampler2DShadow"),
};
/*@}*/
/** \name Types added in GLSL 1.20
*/
/*@{*/
const glsl_type glsl_type::builtin_120_types[] = {
glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
};
const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
/*@}*/
/** \name Types added in GLSL 1.30
*/
/*@{*/
const glsl_type glsl_type::builtin_130_types[] = {
glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"),
glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
/* 1D and 2D texture arrays - several of these are included only in
* builtin_EXT_texture_array_types.
*/
glsl_type(GL_INT_SAMPLER_1D_ARRAY,
GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
glsl_type(GL_INT_SAMPLER_2D_ARRAY,
GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
/* cube shadow samplers */
glsl_type(GL_SAMPLER_CUBE_SHADOW,
GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
/* signed and unsigned integer samplers */
glsl_type(GL_INT_SAMPLER_1D,
GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
glsl_type(GL_INT_SAMPLER_2D,
GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
glsl_type(GL_INT_SAMPLER_3D,
GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
glsl_type(GL_INT_SAMPLER_CUBE,
GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
glsl_type(GL_INT_SAMPLER_CUBE,
GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
};
const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1];
const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
/*@}*/
/** \name Types added in GLSL 1.40
*/
/*@{*/
const glsl_type glsl_type::builtin_140_types[] = {
glsl_type(GL_INT_SAMPLER_2D_RECT,
GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_INT, "isampler2DRect"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_RECT,
GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_UINT, "usampler2DRect"),
};
/*@}*/
/** \name Sampler types added by GL_ARB_texture_rectangle
*/
/*@{*/
const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
glsl_type(GL_SAMPLER_2D_RECT,
GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
};
/*@}*/
/** \name Sampler types added by GL_EXT_texture_array
*/
/*@{*/
const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
glsl_type(GL_SAMPLER_1D_ARRAY,
GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
glsl_type(GL_SAMPLER_2D_ARRAY,
GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
};
/*@}*/
/** \name Sampler types added by GL_EXT_texture_buffer_object
*/
/*@{*/
const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
glsl_type(GL_SAMPLER_BUFFER,
GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
glsl_type(GL_INT_SAMPLER_BUFFER,
GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
};
/*@}*/
/** \name Sampler types added by GL_OES_EGL_image_external
*/
/*@{*/
const glsl_type glsl_type::builtin_OES_EGL_image_external_types[] = {
glsl_type(GL_SAMPLER_EXTERNAL_OES,
GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT, "samplerExternalOES"),
};
/*@}*/
/** \name Sampler types added by GL_ARB_texture_cube_map_array
*/
/*@{*/
const glsl_type glsl_type::builtin_ARB_texture_cube_map_array_types[] = {
glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY,
GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_FLOAT, "samplerCubeArray"),
glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW,
GLSL_SAMPLER_DIM_CUBE, 1, 1, GLSL_TYPE_FLOAT, "samplerCubeArrayShadow"),
glsl_type(GL_INT_SAMPLER_CUBE_MAP_ARRAY,
GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_INT, "isamplerCubeArray"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY,
GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT, "usamplerCubeArray"),
};
/*@}*/
/** \name Sampler types added by GL_ARB_texture_multisample
*/
/*@{*/
const glsl_type glsl_type::builtin_ARB_texture_multisample_types[] = {
glsl_type(GL_SAMPLER_2D_MULTISAMPLE,
GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_FLOAT, "sampler2DMS"),
glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE,
GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_INT, "isampler2DMS"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE,
GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_UINT, "usampler2DMS"),
glsl_type(GL_SAMPLER_2D_MULTISAMPLE_ARRAY,
GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_FLOAT, "sampler2DMSArray"),
glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_INT, "isampler2DMSArray"),
glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_UINT, "usampler2DMSArray"),
};
/*@}*/
-253
View File
@@ -27,7 +27,6 @@
#include "glsl_symbol_table.h"
#include "glsl_parser_extras.h"
#include "glsl_types.h"
#include "builtin_types.h"
extern "C" {
#include "program/hash_table.h"
}
@@ -129,22 +128,6 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
}
}
static void
add_types_to_symbol_table(glsl_symbol_table *symtab,
const struct glsl_type *types,
unsigned num_types, bool warn,
bool skip_1d)
{
(void) warn;
for (unsigned i = 0; i < num_types; i++) {
if (skip_1d && types[i].base_type == GLSL_TYPE_SAMPLER
&& types[i].sampler_dimensionality == GLSL_SAMPLER_DIM_1D)
continue;
symtab->add_type(types[i].name, & types[i]);
}
}
bool
glsl_type::contains_sampler() const
@@ -210,242 +193,6 @@ glsl_type::sampler_index() const
}
}
void
glsl_type::generate_100ES_types(glsl_symbol_table *symtab)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_core_types,
Elements(builtin_core_types),
false, skip_1d);
add_types_to_symbol_table(symtab, builtin_structure_types,
Elements(builtin_structure_types),
false, skip_1d);
add_types_to_symbol_table(symtab, void_type, 1, false, skip_1d);
}
void
glsl_type::generate_300ES_types(glsl_symbol_table *symtab)
{
/* GLSL 3.00 ES types are the same as GLSL 1.30 types, except that 1D
* samplers are skipped, and samplerCubeShadow is added.
*/
bool add_deprecated = false;
bool skip_1d = true;
generate_130_types(symtab, add_deprecated, skip_1d);
add_types_to_symbol_table(symtab, &_samplerCubeShadow_type, 1, false,
skip_1d);
}
void
glsl_type::generate_110_types(glsl_symbol_table *symtab, bool add_deprecated,
bool skip_1d)
{
generate_100ES_types(symtab);
add_types_to_symbol_table(symtab, builtin_110_types,
Elements(builtin_110_types),
false, skip_1d);
add_types_to_symbol_table(symtab, &_sampler3D_type, 1, false, skip_1d);
if (add_deprecated) {
add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
Elements(builtin_110_deprecated_structure_types),
false, skip_1d);
}
}
void
glsl_type::generate_120_types(glsl_symbol_table *symtab, bool add_deprecated,
bool skip_1d)
{
generate_110_types(symtab, add_deprecated, skip_1d);
add_types_to_symbol_table(symtab, builtin_120_types,
Elements(builtin_120_types), false, skip_1d);
}
void
glsl_type::generate_130_types(glsl_symbol_table *symtab, bool add_deprecated,
bool skip_1d)
{
generate_120_types(symtab, add_deprecated, skip_1d);
add_types_to_symbol_table(symtab, builtin_130_types,
Elements(builtin_130_types), false, skip_1d);
generate_EXT_texture_array_types(symtab, false);
}
void
glsl_type::generate_140_types(glsl_symbol_table *symtab)
{
bool skip_1d = false;
generate_130_types(symtab, false, skip_1d);
add_types_to_symbol_table(symtab, builtin_140_types,
Elements(builtin_140_types), false, skip_1d);
add_types_to_symbol_table(symtab, builtin_EXT_texture_buffer_object_types,
Elements(builtin_EXT_texture_buffer_object_types),
false, skip_1d);
}
void
glsl_type::generate_150_types(glsl_symbol_table *symtab)
{
generate_140_types(symtab);
generate_ARB_texture_multisample_types(symtab, false);
}
void
glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab,
bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types,
Elements(builtin_ARB_texture_rectangle_types),
warn, skip_1d);
}
void
glsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab,
bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types,
Elements(builtin_EXT_texture_array_types),
warn, skip_1d);
}
void
glsl_type::generate_OES_texture_3D_types(glsl_symbol_table *symtab, bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, &_sampler3D_type, 1, warn, skip_1d);
}
void
glsl_type::generate_OES_EGL_image_external_types(glsl_symbol_table *symtab,
bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_OES_EGL_image_external_types,
Elements(builtin_OES_EGL_image_external_types),
warn, skip_1d);
}
void
glsl_type::generate_ARB_texture_cube_map_array_types(glsl_symbol_table *symtab,
bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_ARB_texture_cube_map_array_types,
Elements(builtin_ARB_texture_cube_map_array_types),
warn, skip_1d);
}
void
glsl_type::generate_ARB_texture_multisample_types(glsl_symbol_table *symtab,
bool warn)
{
bool skip_1d = false;
add_types_to_symbol_table(symtab, builtin_ARB_texture_multisample_types,
Elements(builtin_ARB_texture_multisample_types),
warn, skip_1d);
}
void
_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
{
if (state->es_shader) {
switch (state->language_version) {
case 100:
assert(state->es_shader);
glsl_type::generate_100ES_types(state->symbols);
break;
case 300:
glsl_type::generate_300ES_types(state->symbols);
break;
default:
assert(!"Unexpected language version");
break;
}
} else {
bool skip_1d = false;
switch (state->language_version) {
case 110:
glsl_type::generate_110_types(state->symbols, true, skip_1d);
break;
case 120:
glsl_type::generate_120_types(state->symbols, true, skip_1d);
break;
case 130:
glsl_type::generate_130_types(state->symbols, true, skip_1d);
break;
case 140:
glsl_type::generate_140_types(state->symbols);
break;
case 150:
glsl_type::generate_150_types(state->symbols);
break;
default:
assert(!"Unexpected language version");
break;
}
}
if (state->ARB_texture_rectangle_enable ||
state->is_version(140, 0)) {
glsl_type::generate_ARB_texture_rectangle_types(state->symbols,
state->ARB_texture_rectangle_warn);
}
if (state->OES_texture_3D_enable
&& state->is_version(0, 100)) {
glsl_type::generate_OES_texture_3D_types(state->symbols,
state->OES_texture_3D_warn);
}
if (state->EXT_texture_array_enable
&& !state->is_version(130, 0)) {
// These are already included in 130; don't create twice.
glsl_type::generate_EXT_texture_array_types(state->symbols,
state->EXT_texture_array_warn);
}
/* We cannot check for language_version == 100 here because we need the
* types to support fixed-function program generation. But this is fine
* since the extension is never enabled for OpenGL contexts.
*/
if (state->OES_EGL_image_external_enable) {
glsl_type::generate_OES_EGL_image_external_types(state->symbols,
state->OES_EGL_image_external_warn);
}
if (state->ARB_texture_cube_map_array_enable) {
glsl_type::generate_ARB_texture_cube_map_array_types(state->symbols,
state->ARB_texture_cube_map_array_warn);
}
if (state->ARB_texture_multisample_enable) {
glsl_type::generate_ARB_texture_multisample_types(state->symbols,
state->ARB_texture_multisample_warn);
}
}
const glsl_type *glsl_type::get_base_type() const
{
+15 -73
View File
@@ -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
* \name Built-in type flyweights
*/
/*@{*/
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.
*/
/*@{*/
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 */