Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* -*- c++ -*- */
  2. /*
  3.  * Copyright © 2009 Intel Corporation
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the "Software"),
  7.  * to deal in the Software without restriction, including without limitation
  8.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9.  * and/or sell copies of the Software, and to permit persons to whom the
  10.  * Software is furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice (including the next
  13.  * paragraph) shall be included in all copies or substantial portions of the
  14.  * Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  */
  24.  
  25. #pragma once
  26. #ifndef GLSL_TYPES_H
  27. #define GLSL_TYPES_H
  28.  
  29. #include <string.h>
  30. #include <assert.h>
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. struct _mesa_glsl_parse_state;
  37. struct glsl_symbol_table;
  38.  
  39. extern void
  40. _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
  41.  
  42. extern void
  43. _mesa_glsl_release_types(void);
  44.  
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48.  
  49. enum glsl_base_type {
  50.    GLSL_TYPE_UINT = 0,
  51.    GLSL_TYPE_INT,
  52.    GLSL_TYPE_FLOAT,
  53.    GLSL_TYPE_DOUBLE,
  54.    GLSL_TYPE_BOOL,
  55.    GLSL_TYPE_SAMPLER,
  56.    GLSL_TYPE_IMAGE,
  57.    GLSL_TYPE_ATOMIC_UINT,
  58.    GLSL_TYPE_STRUCT,
  59.    GLSL_TYPE_INTERFACE,
  60.    GLSL_TYPE_ARRAY,
  61.    GLSL_TYPE_VOID,
  62.    GLSL_TYPE_ERROR
  63. };
  64.  
  65. enum glsl_sampler_dim {
  66.    GLSL_SAMPLER_DIM_1D = 0,
  67.    GLSL_SAMPLER_DIM_2D,
  68.    GLSL_SAMPLER_DIM_3D,
  69.    GLSL_SAMPLER_DIM_CUBE,
  70.    GLSL_SAMPLER_DIM_RECT,
  71.    GLSL_SAMPLER_DIM_BUF,
  72.    GLSL_SAMPLER_DIM_EXTERNAL,
  73.    GLSL_SAMPLER_DIM_MS
  74. };
  75.  
  76. enum glsl_interface_packing {
  77.    GLSL_INTERFACE_PACKING_STD140,
  78.    GLSL_INTERFACE_PACKING_SHARED,
  79.    GLSL_INTERFACE_PACKING_PACKED
  80. };
  81.  
  82. enum glsl_matrix_layout {
  83.    /**
  84.     * The layout of the matrix is inherited from the object containing the
  85.     * matrix (the top level structure or the uniform block).
  86.     */
  87.    GLSL_MATRIX_LAYOUT_INHERITED,
  88.  
  89.    /**
  90.     * Explicit column-major layout
  91.     *
  92.     * If a uniform block doesn't have an explicit layout set, it will default
  93.     * to this layout.
  94.     */
  95.    GLSL_MATRIX_LAYOUT_COLUMN_MAJOR,
  96.  
  97.    /**
  98.     * Row-major layout
  99.     */
  100.    GLSL_MATRIX_LAYOUT_ROW_MAJOR
  101. };
  102.  
  103. #ifdef __cplusplus
  104. #include "GL/gl.h"
  105. #include "util/ralloc.h"
  106. #include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */
  107.  
  108. struct glsl_type {
  109.    GLenum gl_type;
  110.    glsl_base_type base_type;
  111.  
  112.    unsigned sampler_dimensionality:3; /**< \see glsl_sampler_dim */
  113.    unsigned sampler_shadow:1;
  114.    unsigned sampler_array:1;
  115.    unsigned sampler_type:2;    /**< Type of data returned using this
  116.                                 * sampler or image.  Only \c
  117.                                 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
  118.                                 * and \c GLSL_TYPE_UINT are valid.
  119.                                 */
  120.    unsigned interface_packing:2;
  121.  
  122.    /* Callers of this ralloc-based new need not call delete. It's
  123.     * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
  124.    static void* operator new(size_t size)
  125.    {
  126.       mtx_lock(&glsl_type::mutex);
  127.  
  128.       /* mem_ctx should have been created by the static members */
  129.       assert(glsl_type::mem_ctx != NULL);
  130.  
  131.       void *type;
  132.  
  133.       type = ralloc_size(glsl_type::mem_ctx, size);
  134.       assert(type != NULL);
  135.  
  136.       mtx_unlock(&glsl_type::mutex);
  137.  
  138.       return type;
  139.    }
  140.  
  141.    /* If the user *does* call delete, that's OK, we will just
  142.     * ralloc_free in that case. */
  143.    static void operator delete(void *type)
  144.    {
  145.       mtx_lock(&glsl_type::mutex);
  146.       ralloc_free(type);
  147.       mtx_unlock(&glsl_type::mutex);
  148.    }
  149.  
  150.    /**
  151.     * \name Vector and matrix element counts
  152.     *
  153.     * For scalars, each of these values will be 1.  For non-numeric types
  154.     * these will be 0.
  155.     */
  156.    /*@{*/
  157.    uint8_t vector_elements;    /**< 1, 2, 3, or 4 vector elements. */
  158.    uint8_t matrix_columns;     /**< 1, 2, 3, or 4 matrix columns. */
  159.    /*@}*/
  160.  
  161.    /**
  162.     * For \c GLSL_TYPE_ARRAY, this is the length of the array.  For
  163.     * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
  164.     * elements in the structure and the number of values pointed to by
  165.     * \c fields.structure (below).
  166.     */
  167.    unsigned length;
  168.  
  169.    /**
  170.     * Name of the data type
  171.     *
  172.     * Will never be \c NULL.
  173.     */
  174.    const char *name;
  175.  
  176.    /**
  177.     * Subtype of composite data types.
  178.     */
  179.    union {
  180.       const struct glsl_type *array;            /**< Type of array elements. */
  181.       const struct glsl_type *parameters;       /**< Parameters to function. */
  182.       struct glsl_struct_field *structure;      /**< List of struct fields. */
  183.    } fields;
  184.  
  185.    /**
  186.     * \name Pointers to various public type singletons
  187.     */
  188.    /*@{*/
  189. #undef  DECL_TYPE
  190. #define DECL_TYPE(NAME, ...) \
  191.    static const glsl_type *const NAME##_type;
  192. #undef  STRUCT_TYPE
  193. #define STRUCT_TYPE(NAME) \
  194.    static const glsl_type *const struct_##NAME##_type;
  195. #include "builtin_type_macros.h"
  196.    /*@}*/
  197.  
  198.    /**
  199.     * Convenience accessors for vector types (shorter than get_instance()).
  200.     * @{
  201.     */
  202.    static const glsl_type *vec(unsigned components);
  203.    static const glsl_type *dvec(unsigned components);
  204.    static const glsl_type *ivec(unsigned components);
  205.    static const glsl_type *uvec(unsigned components);
  206.    static const glsl_type *bvec(unsigned components);
  207.    /**@}*/
  208.  
  209.    /**
  210.     * For numeric and boolean derived types returns the basic scalar type
  211.     *
  212.     * If the type is a numeric or boolean scalar, vector, or matrix type,
  213.     * this function gets the scalar type of the individual components.  For
  214.     * all other types, including arrays of numeric or boolean types, the
  215.     * error type is returned.
  216.     */
  217.    const glsl_type *get_base_type() const;
  218.  
  219.    /**
  220.     * Get the basic scalar type which this type aggregates.
  221.     *
  222.     * If the type is a numeric or boolean scalar, vector, or matrix, or an
  223.     * array of any of those, this function gets the scalar type of the
  224.     * individual components.  For structs and arrays of structs, this function
  225.     * returns the struct type.  For samplers and arrays of samplers, this
  226.     * function returns the sampler type.
  227.     */
  228.    const glsl_type *get_scalar_type() const;
  229.  
  230.    /**
  231.     * Query the type of elements in an array
  232.     *
  233.     * \return
  234.     * Pointer to the type of elements in the array for array types, or \c NULL
  235.     * for non-array types.
  236.     */
  237.    const glsl_type *element_type() const
  238.    {
  239.       return is_array() ? fields.array : NULL;
  240.    }
  241.  
  242.    /**
  243.     * Get the instance of a built-in scalar, vector, or matrix type
  244.     */
  245.    static const glsl_type *get_instance(unsigned base_type, unsigned rows,
  246.                                         unsigned columns);
  247.  
  248.    /**
  249.     * Get the instance of a sampler type
  250.     */
  251.    static const glsl_type *get_sampler_instance(enum glsl_sampler_dim dim,
  252.                                                 bool shadow,
  253.                                                 bool array,
  254.                                                 glsl_base_type type);
  255.  
  256.  
  257.    /**
  258.     * Get the instance of an array type
  259.     */
  260.    static const glsl_type *get_array_instance(const glsl_type *base,
  261.                                               unsigned elements);
  262.  
  263.    /**
  264.     * Get the instance of a record type
  265.     */
  266.    static const glsl_type *get_record_instance(const glsl_struct_field *fields,
  267.                                                unsigned num_fields,
  268.                                                const char *name);
  269.  
  270.    /**
  271.     * Get the instance of an interface block type
  272.     */
  273.    static const glsl_type *get_interface_instance(const glsl_struct_field *fields,
  274.                                                   unsigned num_fields,
  275.                                                   enum glsl_interface_packing packing,
  276.                                                   const char *block_name);
  277.  
  278.    /**
  279.     * Get the type resulting from a multiplication of \p type_a * \p type_b
  280.     */
  281.    static const glsl_type *get_mul_type(const glsl_type *type_a,
  282.                                         const glsl_type *type_b);
  283.  
  284.    /**
  285.     * Query the total number of scalars that make up a scalar, vector or matrix
  286.     */
  287.    unsigned components() const
  288.    {
  289.       return vector_elements * matrix_columns;
  290.    }
  291.  
  292.    /**
  293.     * Calculate the number of components slots required to hold this type
  294.     *
  295.     * This is used to determine how many uniform or varying locations a type
  296.     * might occupy.
  297.     */
  298.    unsigned component_slots() const;
  299.  
  300.    /**
  301.     * Calculate the number of unique values from glGetUniformLocation for the
  302.     * elements of the type.
  303.     *
  304.     * This is used to allocate slots in the UniformRemapTable, the amount of
  305.     * locations may not match with actual used storage space by the driver.
  306.     */
  307.    unsigned uniform_locations() const;
  308.  
  309.    /**
  310.     * Calculate the number of attribute slots required to hold this type
  311.     *
  312.     * This implements the language rules of GLSL 1.50 for counting the number
  313.     * of slots used by a vertex attribute.  It also determines the number of
  314.     * varying slots the type will use up in the absence of varying packing
  315.     * (and thus, it can be used to measure the number of varying slots used by
  316.     * the varyings that are generated by lower_packed_varyings).
  317.     */
  318.    unsigned count_attribute_slots() const;
  319.  
  320.  
  321.    /**
  322.     * Alignment in bytes of the start of this type in a std140 uniform
  323.     * block.
  324.     */
  325.    unsigned std140_base_alignment(bool row_major) const;
  326.  
  327.    /** Size in bytes of this type in a std140 uniform block.
  328.     *
  329.     * Note that this is not GL_UNIFORM_SIZE (which is the number of
  330.     * elements in the array)
  331.     */
  332.    unsigned std140_size(bool row_major) const;
  333.  
  334.    /**
  335.     * \brief Can this type be implicitly converted to another?
  336.     *
  337.     * \return True if the types are identical or if this type can be converted
  338.     *         to \c desired according to Section 4.1.10 of the GLSL spec.
  339.     *
  340.     * \verbatim
  341.     * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
  342.     * Implicit Conversions:
  343.     *
  344.     *     In some situations, an expression and its type will be implicitly
  345.     *     converted to a different type. The following table shows all allowed
  346.     *     implicit conversions:
  347.     *
  348.     *     Type of expression | Can be implicitly converted to
  349.     *     --------------------------------------------------
  350.     *     int                  float
  351.     *     uint
  352.     *
  353.     *     ivec2                vec2
  354.     *     uvec2
  355.     *
  356.     *     ivec3                vec3
  357.     *     uvec3
  358.     *
  359.     *     ivec4                vec4
  360.     *     uvec4
  361.     *
  362.     *     There are no implicit array or structure conversions. For example,
  363.     *     an array of int cannot be implicitly converted to an array of float.
  364.     *     There are no implicit conversions between signed and unsigned
  365.     *     integers.
  366.     * \endverbatim
  367.     */
  368.    bool can_implicitly_convert_to(const glsl_type *desired,
  369.                                   _mesa_glsl_parse_state *state) const;
  370.  
  371.    /**
  372.     * Query whether or not a type is a scalar (non-vector and non-matrix).
  373.     */
  374.    bool is_scalar() const
  375.    {
  376.       return (vector_elements == 1)
  377.          && (base_type >= GLSL_TYPE_UINT)
  378.          && (base_type <= GLSL_TYPE_BOOL);
  379.    }
  380.  
  381.    /**
  382.     * Query whether or not a type is a vector
  383.     */
  384.    bool is_vector() const
  385.    {
  386.       return (vector_elements > 1)
  387.          && (matrix_columns == 1)
  388.          && (base_type >= GLSL_TYPE_UINT)
  389.          && (base_type <= GLSL_TYPE_BOOL);
  390.    }
  391.  
  392.    /**
  393.     * Query whether or not a type is a matrix
  394.     */
  395.    bool is_matrix() const
  396.    {
  397.       /* GLSL only has float matrices. */
  398.       return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT || base_type == GLSL_TYPE_DOUBLE);
  399.    }
  400.  
  401.    /**
  402.     * Query whether or not a type is a non-array numeric type
  403.     */
  404.    bool is_numeric() const
  405.    {
  406.       return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
  407.    }
  408.  
  409.    /**
  410.     * Query whether or not a type is an integral type
  411.     */
  412.    bool is_integer() const
  413.    {
  414.       return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
  415.    }
  416.  
  417.    /**
  418.     * Query whether or not type is an integral type, or for struct and array
  419.     * types, contains an integral type.
  420.     */
  421.    bool contains_integer() const;
  422.  
  423.    /**
  424.     * Query whether or not type is a double type, or for struct and array
  425.     * types, contains a double type.
  426.     */
  427.    bool contains_double() const;
  428.  
  429.    /**
  430.     * Query whether or not a type is a float type
  431.     */
  432.    bool is_float() const
  433.    {
  434.       return base_type == GLSL_TYPE_FLOAT;
  435.    }
  436.  
  437.    /**
  438.     * Query whether or not a type is a double type
  439.     */
  440.    bool is_double() const
  441.    {
  442.       return base_type == GLSL_TYPE_DOUBLE;
  443.    }
  444.  
  445.    /**
  446.     * Query whether or not a type is a non-array boolean type
  447.     */
  448.    bool is_boolean() const
  449.    {
  450.       return base_type == GLSL_TYPE_BOOL;
  451.    }
  452.  
  453.    /**
  454.     * Query whether or not a type is a sampler
  455.     */
  456.    bool is_sampler() const
  457.    {
  458.       return base_type == GLSL_TYPE_SAMPLER;
  459.    }
  460.  
  461.    /**
  462.     * Query whether or not type is a sampler, or for struct and array
  463.     * types, contains a sampler.
  464.     */
  465.    bool contains_sampler() const;
  466.  
  467.    /**
  468.     * Get the Mesa texture target index for a sampler type.
  469.     */
  470.    gl_texture_index sampler_index() const;
  471.  
  472.    /**
  473.     * Query whether or not type is an image, or for struct and array
  474.     * types, contains an image.
  475.     */
  476.    bool contains_image() const;
  477.  
  478.    /**
  479.     * Query whether or not a type is an image
  480.     */
  481.    bool is_image() const
  482.    {
  483.       return base_type == GLSL_TYPE_IMAGE;
  484.    }
  485.  
  486.    /**
  487.     * Query whether or not a type is an array
  488.     */
  489.    bool is_array() const
  490.    {
  491.       return base_type == GLSL_TYPE_ARRAY;
  492.    }
  493.  
  494.    /**
  495.     * Query whether or not a type is a record
  496.     */
  497.    bool is_record() const
  498.    {
  499.       return base_type == GLSL_TYPE_STRUCT;
  500.    }
  501.  
  502.    /**
  503.     * Query whether or not a type is an interface
  504.     */
  505.    bool is_interface() const
  506.    {
  507.       return base_type == GLSL_TYPE_INTERFACE;
  508.    }
  509.  
  510.    /**
  511.     * Query whether or not a type is the void type singleton.
  512.     */
  513.    bool is_void() const
  514.    {
  515.       return base_type == GLSL_TYPE_VOID;
  516.    }
  517.  
  518.    /**
  519.     * Query whether or not a type is the error type singleton.
  520.     */
  521.    bool is_error() const
  522.    {
  523.       return base_type == GLSL_TYPE_ERROR;
  524.    }
  525.  
  526.    /**
  527.     * Query if a type is unnamed/anonymous (named by the parser)
  528.     */
  529.    bool is_anonymous() const
  530.    {
  531.       return !strncmp(name, "#anon", 5);
  532.    }
  533.  
  534.    /**
  535.     * Get the type stripped of any arrays
  536.     *
  537.     * \return
  538.     * Pointer to the type of elements of the first non-array type for array
  539.     * types, or pointer to itself for non-array types.
  540.     */
  541.    const glsl_type *without_array() const
  542.    {
  543.       const glsl_type *t = this;
  544.  
  545.       while (t->is_array())
  546.          t = t->fields.array;
  547.  
  548.       return t;
  549.    }
  550.  
  551.    /**
  552.     * Return the amount of atomic counter storage required for a type.
  553.     */
  554.    unsigned atomic_size() const
  555.    {
  556.       if (base_type == GLSL_TYPE_ATOMIC_UINT)
  557.          return ATOMIC_COUNTER_SIZE;
  558.       else if (is_array())
  559.          return length * element_type()->atomic_size();
  560.       else
  561.          return 0;
  562.    }
  563.  
  564.    /**
  565.     * Return whether a type contains any atomic counters.
  566.     */
  567.    bool contains_atomic() const
  568.    {
  569.       return atomic_size() > 0;
  570.    }
  571.  
  572.    /**
  573.     * Return whether a type contains any opaque types.
  574.     */
  575.    bool contains_opaque() const;
  576.  
  577.    /**
  578.     * Query the full type of a matrix row
  579.     *
  580.     * \return
  581.     * If the type is not a matrix, \c glsl_type::error_type is returned.
  582.     * Otherwise a type matching the rows of the matrix is returned.
  583.     */
  584.    const glsl_type *row_type() const
  585.    {
  586.       return is_matrix()
  587.          ? get_instance(base_type, matrix_columns, 1)
  588.          : error_type;
  589.    }
  590.  
  591.    /**
  592.     * Query the full type of a matrix column
  593.     *
  594.     * \return
  595.     * If the type is not a matrix, \c glsl_type::error_type is returned.
  596.     * Otherwise a type matching the columns of the matrix is returned.
  597.     */
  598.    const glsl_type *column_type() const
  599.    {
  600.       return is_matrix()
  601.          ? get_instance(base_type, vector_elements, 1)
  602.          : error_type;
  603.    }
  604.  
  605.    /**
  606.     * Get the type of a structure field
  607.     *
  608.     * \return
  609.     * Pointer to the type of the named field.  If the type is not a structure
  610.     * or the named field does not exist, \c glsl_type::error_type is returned.
  611.     */
  612.    const glsl_type *field_type(const char *name) const;
  613.  
  614.    /**
  615.     * Get the location of a filed within a record type
  616.     */
  617.    int field_index(const char *name) const;
  618.  
  619.    /**
  620.     * Query the number of elements in an array type
  621.     *
  622.     * \return
  623.     * The number of elements in the array for array types or -1 for non-array
  624.     * types.  If the number of elements in the array has not yet been declared,
  625.     * zero is returned.
  626.     */
  627.    int array_size() const
  628.    {
  629.       return is_array() ? length : -1;
  630.    }
  631.  
  632.    /**
  633.     * Query whether the array size for all dimensions has been declared.
  634.     */
  635.    bool is_unsized_array() const
  636.    {
  637.       return is_array() && length == 0;
  638.    }
  639.  
  640.    /**
  641.     * Return the number of coordinate components needed for this
  642.     * sampler or image type.
  643.     *
  644.     * This is based purely on the sampler's dimensionality.  For example, this
  645.     * returns 1 for sampler1D, and 3 for sampler2DArray.
  646.     *
  647.     * Note that this is often different than actual coordinate type used in
  648.     * a texturing built-in function, since those pack additional values (such
  649.     * as the shadow comparitor or projector) into the coordinate type.
  650.     */
  651.    int coordinate_components() const;
  652.  
  653.    /**
  654.     * Compare a record type against another record type.
  655.     *
  656.     * This is useful for matching record types declared across shader stages.
  657.     */
  658.    bool record_compare(const glsl_type *b) const;
  659.  
  660. private:
  661.  
  662.    static mtx_t mutex;
  663.  
  664.    /**
  665.     * ralloc context for all glsl_type allocations
  666.     *
  667.     * Set on the first call to \c glsl_type::new.
  668.     */
  669.    static void *mem_ctx;
  670.  
  671.    void init_ralloc_type_ctx(void);
  672.  
  673.    /** Constructor for vector and matrix types */
  674.    glsl_type(GLenum gl_type,
  675.              glsl_base_type base_type, unsigned vector_elements,
  676.              unsigned matrix_columns, const char *name);
  677.  
  678.    /** Constructor for sampler or image types */
  679.    glsl_type(GLenum gl_type, glsl_base_type base_type,
  680.              enum glsl_sampler_dim dim, bool shadow, bool array,
  681.              unsigned type, const char *name);
  682.  
  683.    /** Constructor for record types */
  684.    glsl_type(const glsl_struct_field *fields, unsigned num_fields,
  685.              const char *name);
  686.  
  687.    /** Constructor for interface types */
  688.    glsl_type(const glsl_struct_field *fields, unsigned num_fields,
  689.              enum glsl_interface_packing packing, const char *name);
  690.  
  691.    /** Constructor for array types */
  692.    glsl_type(const glsl_type *array, unsigned length);
  693.  
  694.    /** Hash table containing the known array types. */
  695.    static struct hash_table *array_types;
  696.  
  697.    /** Hash table containing the known record types. */
  698.    static struct hash_table *record_types;
  699.  
  700.    /** Hash table containing the known interface types. */
  701.    static struct hash_table *interface_types;
  702.  
  703.    static int record_key_compare(const void *a, const void *b);
  704.    static unsigned record_key_hash(const void *key);
  705.  
  706.    /**
  707.     * \name Built-in type flyweights
  708.     */
  709.    /*@{*/
  710. #undef  DECL_TYPE
  711. #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
  712. #undef  STRUCT_TYPE
  713. #define STRUCT_TYPE(NAME)        static const glsl_type _struct_##NAME##_type;
  714. #include "builtin_type_macros.h"
  715.    /*@}*/
  716.  
  717.    /**
  718.     * \name Friend functions.
  719.     *
  720.     * These functions are friends because they must have C linkage and the
  721.     * need to call various private methods or access various private static
  722.     * data.
  723.     */
  724.    /*@{*/
  725.    friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
  726.    friend void _mesa_glsl_release_types(void);
  727.    /*@}*/
  728. };
  729.  
  730. struct glsl_struct_field {
  731.    const struct glsl_type *type;
  732.    const char *name;
  733.  
  734.    /**
  735.     * For interface blocks, gl_varying_slot corresponding to the input/output
  736.     * if this is a built-in input/output (i.e. a member of the built-in
  737.     * gl_PerVertex interface block); -1 otherwise.
  738.     *
  739.     * Ignored for structs.
  740.     */
  741.    int location;
  742.  
  743.    /**
  744.     * For interface blocks, the interpolation mode (as in
  745.     * ir_variable::interpolation).  0 otherwise.
  746.     */
  747.    unsigned interpolation:2;
  748.  
  749.    /**
  750.     * For interface blocks, 1 if this variable uses centroid interpolation (as
  751.     * in ir_variable::centroid).  0 otherwise.
  752.     */
  753.    unsigned centroid:1;
  754.  
  755.    /**
  756.     * For interface blocks, 1 if this variable uses sample interpolation (as
  757.     * in ir_variable::sample). 0 otherwise.
  758.     */
  759.    unsigned sample:1;
  760.  
  761.    /**
  762.     * Layout of the matrix.  Uses glsl_matrix_layout values.
  763.     */
  764.    unsigned matrix_layout:2;
  765.  
  766.    /**
  767.     * For interface blocks, it has a value if this variable uses multiple vertex
  768.     * streams (as in ir_variable::stream). -1 otherwise.
  769.     */
  770.    int stream;
  771. };
  772.  
  773. static inline unsigned int
  774. glsl_align(unsigned int a, unsigned int align)
  775. {
  776.    return (a + align - 1) / align * align;
  777. }
  778.  
  779. #undef DECL_TYPE
  780. #undef STRUCT_TYPE
  781. #endif /* __cplusplus */
  782.  
  783. #endif /* GLSL_TYPES_H */
  784.