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