From: Ian Romanick <ian.d.roman...@intel.com> v2/Kayden: Use enum glsl_base_type instead of unsigned for the glsl_type::get_sampler_instance base type parameter.
Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> Signed-off-by: Kenneth Graunke <kenn...@whitecape.org> --- src/glsl/glsl_types.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ src/glsl/glsl_types.h | 14 ++++++ 2 files changed, 138 insertions(+) diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp index 3d78660..798d658 100644 --- a/src/glsl/glsl_types.cpp +++ b/src/glsl/glsl_types.cpp @@ -555,6 +555,130 @@ glsl_type::get_record_instance(const glsl_struct_field *fields, return t; } +/** + * Convert sampler type attributes into an index in the sampler_types array + */ +#define SAMPLER_TYPE_INDEX(dim, sample_type, array, shadow) \ + ((unsigned(dim) * 12) + (sample_type * 4) + (unsigned(array) * 2) \ + + unsigned(shadow)) + +/** + * \note + * Arrays like this are \b the argument for C99-style designated initializers. + * Too bad C++ and VisualStudio are too cool for that sort of useful + * functionality. + */ +const glsl_type *const glsl_type::sampler_types[] = { + /* GLSL_SAMPLER_DIM_1D */ + &builtin_130_types[10], /* uint */ + NULL, /* uint, shadow */ + &builtin_130_types[5], /* uint, array */ + NULL, /* uint, array, shadow */ + &builtin_130_types[9], /* int */ + NULL, /* int, shadow */ + &builtin_130_types[4], /* int, array */ + NULL, /* int, array, shadow */ + &builtin_110_types[0], /* float */ + &builtin_110_types[1], /* float, shadow */ + &builtin_EXT_texture_array_types[0], /* float, array */ + &builtin_EXT_texture_array_types[2], /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_2D */ + &builtin_130_types[12], /* uint */ + NULL, /* uint, shadow */ + &builtin_130_types[7], /* uint, array */ + NULL, /* uint, array, shadow */ + &builtin_130_types[11], /* int */ + NULL, /* int, shadow */ + &builtin_130_types[6], /* int, array */ + NULL, /* int, array, shadow */ + &builtin_core_types[15], /* float */ + &builtin_110_types[2], /* float, shadow */ + &builtin_EXT_texture_array_types[1], /* float, array */ + &builtin_EXT_texture_array_types[3], /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_3D */ + &builtin_130_types[14], /* uint */ + NULL, /* uint, shadow */ + NULL, /* uint, array */ + NULL, /* uint, array, shadow */ + &builtin_130_types[13], /* int */ + NULL, /* int, shadow */ + NULL, /* int, array */ + NULL, /* int, array, shadow */ + &builtin_110_types[3], /* float */ + NULL, /* float, shadow */ + NULL, /* float, array */ + NULL, /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_CUBE */ + &builtin_130_types[16], /* uint */ + NULL, /* uint, shadow */ + NULL, /* uint, array */ + NULL, /* uint, array, shadow */ + &builtin_130_types[15], /* int */ + NULL, /* int, shadow */ + NULL, /* int, array */ + NULL, /* int, array, shadow */ + &builtin_core_types[16], /* float */ + &builtin_130_types[8], /* float, shadow */ + NULL, /* float, array */ + NULL, /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_RECT */ + NULL, /* uint */ + NULL, /* uint, shadow */ + NULL, /* uint, array */ + NULL, /* uint, array, shadow */ + NULL, /* int */ + NULL, /* int, shadow */ + NULL, /* int, array */ + NULL, /* int, array, shadow */ + &builtin_ARB_texture_rectangle_types[0], /* float */ + &builtin_ARB_texture_rectangle_types[1], /* float, shadow */ + NULL, /* float, array */ + NULL, /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_BUF */ + &builtin_EXT_texture_buffer_object_types[2], /* uint */ + NULL, /* uint, shadow */ + NULL, /* uint, array */ + NULL, /* uint, array, shadow */ + &builtin_EXT_texture_buffer_object_types[1], /* int */ + NULL, /* int, shadow */ + NULL, /* int, array */ + NULL, /* int, array, shadow */ + &builtin_EXT_texture_buffer_object_types[0], /* float */ + NULL, /* float, shadow */ + NULL, /* float, array */ + NULL, /* float, array, shadow */ + + /* GLSL_SAMPLER_DIM_EXTERNAL */ + NULL, /* uint */ + NULL, /* uint, shadow */ + NULL, /* uint, array */ + NULL, /* uint, array, shadow */ + NULL, /* int */ + NULL, /* int, shadow */ + NULL, /* int, array */ + NULL, /* int, array, shadow */ + &builtin_OES_EGL_image_external_types[0], /* float */ + NULL, /* float, shadow */ + NULL, /* float, array */ + NULL, /* float, array, shadow */ +}; + +const glsl_type * +glsl_type::get_sampler_instance(glsl_sampler_dim dim, + bool shadow, bool array, + enum glsl_base_type base_type) +{ + const glsl_type *const t = + sampler_types[SAMPLER_TYPE_INDEX(dim, base_type, array, shadow)]; + + return t; +} + const glsl_type * glsl_type::field_type(const char *name) const diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index 915d1a2..681eda7 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -232,6 +232,13 @@ struct glsl_type { const char *name); /** + * Get the instance of a sampler type + */ + static const glsl_type *get_sampler_instance(glsl_sampler_dim dim, + bool shadow, bool array, + enum glsl_base_type base_type); + + /** * Query the total number of scalars that make up a scalar, vector or matrix */ unsigned components() const @@ -524,6 +531,13 @@ private: /*@}*/ /** + * Table of sampler types used internally by get_sampler_instance + * + * \sa glsl_type::get_sampler_instance + */ + static const glsl_type *const sampler_types[]; + + /** * \name Methods to populate a symbol table with built-in types. * * \internal -- 1.7.11.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev