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 #ifndef IR_UNIFORM_H 25 #define IR_UNIFORM_H 26 27 28 /* stdbool.h is necessary because this file is included in both C and C++ code. 29 */ 30 #include <stdbool.h> 31 #include "util/macros.h" 32 #include "program/prog_parameter.h" /* For union gl_constant_value. */ 33 34 /** 35 * Used by GL_ARB_explicit_uniform_location extension code in the linker 36 * and glUniform* functions to identify inactive explicit uniform locations. 37 */ 38 #define INACTIVE_UNIFORM_EXPLICIT_LOCATION ((gl_uniform_storage *) -1) 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 enum PACKED gl_uniform_driver_format { 45 uniform_native = 0, /**< Store data in the native format. */ 46 uniform_int_float, /**< Store integer data as floats. */ 47 }; 48 49 struct gl_uniform_driver_storage { 50 /** 51 * Number of bytes from one array element to the next. 52 */ 53 uint8_t element_stride; 54 55 /** 56 * Number of bytes from one vector in a matrix to the next. 57 */ 58 uint8_t vector_stride; 59 60 /** 61 * Base format of the stored data. 62 */ 63 enum gl_uniform_driver_format format; 64 65 /** 66 * Pointer to the base of the data. 67 */ 68 void *data; 69 }; 70 71 struct gl_opaque_uniform_index { 72 /** 73 * Base opaque uniform index 74 * 75 * If \c gl_uniform_storage::base_type is an opaque type, this 76 * represents its uniform index. If \c 77 * gl_uniform_storage::array_elements is not zero, the array will 78 * use opaque uniform indices \c index through \c index + \c 79 * gl_uniform_storage::array_elements - 1, inclusive. 80 * 81 * Note that the index may be different in each shader stage. 82 */ 83 uint8_t index; 84 85 /** 86 * Whether this opaque uniform is used in this shader stage. 87 */ 88 bool active; 89 }; 90 91 struct gl_resource_name 92 { 93 char *string; 94 int length; /* strlen(string) or 0 */ 95 int last_square_bracket; /* (strrchr(name, '[') - name) or -1 */ 96 bool suffix_is_zero_square_bracketed; /* suffix is [0] */ 97 }; 98 99 struct gl_uniform_storage { 100 struct gl_resource_name name; 101 102 /** Type of this uniform data stored. 103 * 104 * In the case of an array, it's the type of a single array element. 105 */ 106 const struct glsl_type *type; 107 108 /** 109 * The number of elements in this uniform. 110 * 111 * For non-arrays, this is always 0. For arrays, the value is the size of 112 * the array. 113 */ 114 unsigned array_elements; 115 116 struct gl_opaque_uniform_index opaque[MESA_SHADER_STAGES]; 117 118 /** 119 * Mask of shader stages (1 << MESA_SHADER_xxx) where this uniform is used. 120 */ 121 unsigned active_shader_mask; 122 123 /** 124 * Storage used by the driver for the uniform 125 */ 126 unsigned num_driver_storage; 127 struct gl_uniform_driver_storage *driver_storage; 128 129 /** 130 * Storage used by Mesa for the uniform 131 * 132 * This form of the uniform is used by Mesa's implementation of \c 133 * glGetUniform. It can also be used by drivers to obtain the value of the 134 * uniform if the \c ::driver_storage interface is not used. 135 */ 136 union gl_constant_value *storage; 137 138 /** Fields for GL_ARB_uniform_buffer_object 139 * @{ 140 */ 141 142 /** 143 * GL_UNIFORM_BLOCK_INDEX: index of the uniform block containing 144 * the uniform, or -1 for the default uniform block. Note that the 145 * index is into the linked program's UniformBlocks[] array, not 146 * the linked shader's. 147 */ 148 int block_index; 149 150 /** GL_UNIFORM_OFFSET: byte offset within the uniform block, or -1. */ 151 int offset; 152 153 /** 154 * GL_UNIFORM_MATRIX_STRIDE: byte stride between columns or rows of 155 * a matrix. Set to 0 for non-matrices in UBOs, or -1 for uniforms 156 * in the default uniform block. 157 */ 158 int matrix_stride; 159 160 /** 161 * GL_UNIFORM_ARRAY_STRIDE: byte stride between elements of the 162 * array. Set to zero for non-arrays in UBOs, or -1 for uniforms 163 * in the default uniform block. 164 */ 165 int array_stride; 166 167 /** GL_UNIFORM_ROW_MAJOR: true iff it's a row-major matrix in a UBO */ 168 bool row_major; 169 170 /** @} */ 171 172 /** 173 * This is a compiler-generated uniform that should not be advertised 174 * via the API. 175 */ 176 bool hidden; 177 178 /** 179 * This is a built-in uniform that should not be modified through any gl API. 180 */ 181 bool builtin; 182 183 /** 184 * This is a shader storage buffer variable, not an uniform. 185 */ 186 bool is_shader_storage; 187 188 /** 189 * Index within gl_shader_program::AtomicBuffers[] of the atomic 190 * counter buffer this uniform is stored in, or -1 if this is not 191 * an atomic counter. 192 */ 193 int atomic_buffer_index; 194 195 /** 196 * The 'base location' for this uniform in the uniform remap table. For 197 * arrays this is the first element in the array. 198 * for subroutines this is in shader subroutine uniform remap table. 199 */ 200 unsigned remap_location; 201 202 /** 203 * The number of compatible subroutines with this subroutine uniform. 204 */ 205 unsigned num_compatible_subroutines; 206 207 /** 208 * A single integer identifying the number of active array elements of 209 * the top-level shader storage block member (GL_TOP_LEVEL_ARRAY_SIZE). 210 */ 211 unsigned top_level_array_size; 212 213 /** 214 * A single integer identifying the stride between array elements of the 215 * top-level shader storage block member. (GL_TOP_LEVEL_ARRAY_STRIDE). 216 */ 217 unsigned top_level_array_stride; 218 219 /** 220 * Whether this uniform variable has the bindless_sampler or bindless_image 221 * layout qualifier as specified by ARB_bindless_texture. 222 */ 223 bool is_bindless; 224 }; 225 226 void 227 resource_name_updated(struct gl_resource_name *name); 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif /* IR_UNIFORM_H */ 234