Home | History | Annotate | Download | only in glsl
      1 /*
      2  * Copyright  2011 Intel Corporation
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice (including the next
     12  * paragraph) shall be included in all copies or substantial portions of the
     13  * Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21  * DEALINGS IN THE SOFTWARE.
     22  */
     23 
     24 #pragma once
     25 #ifndef IR_UNIFORM_H
     26 #define IR_UNIFORM_H
     27 
     28 
     29 /* stdbool.h is necessary because this file is included in both C and C++ code.
     30  */
     31 #include <stdbool.h>
     32 
     33 #include "program/prog_parameter.h"  /* For union gl_constant_value. */
     34 
     35 /**
     36  * Used by GL_ARB_explicit_uniform_location extension code in the linker
     37  * and glUniform* functions to identify inactive explicit uniform locations.
     38  */
     39 #define INACTIVE_UNIFORM_EXPLICIT_LOCATION ((gl_uniform_storage *) -1)
     40 
     41 #ifdef __cplusplus
     42 extern "C" {
     43 #endif
     44 
     45 enum PACKED gl_uniform_driver_format {
     46    uniform_native = 0,          /**< Store data in the native format. */
     47    uniform_int_float,           /**< Store integer data as floats. */
     48 };
     49 
     50 struct gl_uniform_driver_storage {
     51    /**
     52     * Number of bytes from one array element to the next.
     53     */
     54    uint8_t element_stride;
     55 
     56    /**
     57     * Number of bytes from one vector in a matrix to the next.
     58     */
     59    uint8_t vector_stride;
     60 
     61    /**
     62     * Base format of the stored data.
     63     */
     64    enum gl_uniform_driver_format format;
     65 
     66    /**
     67     * Pointer to the base of the data.
     68     */
     69    void *data;
     70 };
     71 
     72 struct gl_opaque_uniform_index {
     73    /**
     74     * Base opaque uniform index
     75     *
     76     * If \c gl_uniform_storage::base_type is an opaque type, this
     77     * represents its uniform index.  If \c
     78     * gl_uniform_storage::array_elements is not zero, the array will
     79     * use opaque uniform indices \c index through \c index + \c
     80     * gl_uniform_storage::array_elements - 1, inclusive.
     81     *
     82     * Note that the index may be different in each shader stage.
     83     */
     84    uint8_t index;
     85 
     86    /**
     87     * Whether this opaque uniform is used in this shader stage.
     88     */
     89    bool active;
     90 };
     91 
     92 struct gl_uniform_storage {
     93    char *name;
     94    /** Type of this uniform data stored.
     95     *
     96     * In the case of an array, it's the type of a single array element.
     97     */
     98    const struct glsl_type *type;
     99 
    100    /**
    101     * The number of elements in this uniform.
    102     *
    103     * For non-arrays, this is always 0.  For arrays, the value is the size of
    104     * the array.
    105     */
    106    unsigned array_elements;
    107 
    108    struct gl_opaque_uniform_index opaque[MESA_SHADER_STAGES];
    109 
    110    /**
    111     * Storage used by the driver for the uniform
    112     */
    113    unsigned num_driver_storage;
    114    struct gl_uniform_driver_storage *driver_storage;
    115 
    116    /**
    117     * Storage used by Mesa for the uniform
    118     *
    119     * This form of the uniform is used by Mesa's implementation of \c
    120     * glGetUniform.  It can also be used by drivers to obtain the value of the
    121     * uniform if the \c ::driver_storage interface is not used.
    122     */
    123    union gl_constant_value *storage;
    124 
    125    /** Fields for GL_ARB_uniform_buffer_object
    126     * @{
    127     */
    128 
    129    /**
    130     * GL_UNIFORM_BLOCK_INDEX: index of the uniform block containing
    131     * the uniform, or -1 for the default uniform block.  Note that the
    132     * index is into the linked program's UniformBlocks[] array, not
    133     * the linked shader's.
    134     */
    135    int block_index;
    136 
    137    /** GL_UNIFORM_OFFSET: byte offset within the uniform block, or -1. */
    138    int offset;
    139 
    140    /**
    141     * GL_UNIFORM_MATRIX_STRIDE: byte stride between columns or rows of
    142     * a matrix.  Set to 0 for non-matrices in UBOs, or -1 for uniforms
    143     * in the default uniform block.
    144     */
    145    int matrix_stride;
    146 
    147    /**
    148     * GL_UNIFORM_ARRAY_STRIDE: byte stride between elements of the
    149     * array.  Set to zero for non-arrays in UBOs, or -1 for uniforms
    150     * in the default uniform block.
    151     */
    152    int array_stride;
    153 
    154    /** GL_UNIFORM_ROW_MAJOR: true iff it's a row-major matrix in a UBO */
    155    bool row_major;
    156 
    157    /** @} */
    158 
    159    /**
    160     * This is a compiler-generated uniform that should not be advertised
    161     * via the API.
    162     */
    163    bool hidden;
    164 
    165    /**
    166     * This is a built-in uniform that should not be modified through any gl API.
    167     */
    168    bool builtin;
    169 
    170    /**
    171     * This is a shader storage buffer variable, not an uniform.
    172     */
    173    bool is_shader_storage;
    174 
    175    /**
    176     * Index within gl_shader_program::AtomicBuffers[] of the atomic
    177     * counter buffer this uniform is stored in, or -1 if this is not
    178     * an atomic counter.
    179     */
    180    int atomic_buffer_index;
    181 
    182    /**
    183     * The 'base location' for this uniform in the uniform remap table. For
    184     * arrays this is the first element in the array.
    185     * for subroutines this is in shader subroutine uniform remap table.
    186     */
    187    unsigned remap_location;
    188 
    189    /**
    190     * The number of compatible subroutines with this subroutine uniform.
    191     */
    192    unsigned num_compatible_subroutines;
    193 
    194    /**
    195     * A single integer identifying the number of active array elements of
    196     * the top-level shader storage block member (GL_TOP_LEVEL_ARRAY_SIZE).
    197     */
    198    unsigned top_level_array_size;
    199 
    200    /**
    201     * A single integer identifying the stride between array elements of the
    202     * top-level shader storage block member. (GL_TOP_LEVEL_ARRAY_STRIDE).
    203     */
    204    unsigned top_level_array_stride;
    205 };
    206 
    207 #ifdef __cplusplus
    208 }
    209 #endif
    210 
    211 #endif /* IR_UNIFORM_H */
    212