101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2011 Intel Corporation
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
901e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2101e04c3fSmrg * DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg#ifndef IR_UNIFORM_H
2501e04c3fSmrg#define IR_UNIFORM_H
2601e04c3fSmrg
2701e04c3fSmrg
2801e04c3fSmrg/* stdbool.h is necessary because this file is included in both C and C++ code.
2901e04c3fSmrg */
3001e04c3fSmrg#include <stdbool.h>
3101e04c3fSmrg#include "util/macros.h"
3201e04c3fSmrg#include "program/prog_parameter.h"  /* For union gl_constant_value. */
3301e04c3fSmrg
3401e04c3fSmrg/**
3501e04c3fSmrg * Used by GL_ARB_explicit_uniform_location extension code in the linker
3601e04c3fSmrg * and glUniform* functions to identify inactive explicit uniform locations.
3701e04c3fSmrg */
3801e04c3fSmrg#define INACTIVE_UNIFORM_EXPLICIT_LOCATION ((gl_uniform_storage *) -1)
3901e04c3fSmrg
4001e04c3fSmrg#ifdef __cplusplus
4101e04c3fSmrgextern "C" {
4201e04c3fSmrg#endif
4301e04c3fSmrg
4401e04c3fSmrgenum PACKED gl_uniform_driver_format {
4501e04c3fSmrg   uniform_native = 0,          /**< Store data in the native format. */
4601e04c3fSmrg   uniform_int_float,           /**< Store integer data as floats. */
4701e04c3fSmrg};
4801e04c3fSmrg
4901e04c3fSmrgstruct gl_uniform_driver_storage {
5001e04c3fSmrg   /**
5101e04c3fSmrg    * Number of bytes from one array element to the next.
5201e04c3fSmrg    */
5301e04c3fSmrg   uint8_t element_stride;
5401e04c3fSmrg
5501e04c3fSmrg   /**
5601e04c3fSmrg    * Number of bytes from one vector in a matrix to the next.
5701e04c3fSmrg    */
5801e04c3fSmrg   uint8_t vector_stride;
5901e04c3fSmrg
6001e04c3fSmrg   /**
6101e04c3fSmrg    * Base format of the stored data.
6201e04c3fSmrg    */
6301e04c3fSmrg   enum gl_uniform_driver_format format;
6401e04c3fSmrg
6501e04c3fSmrg   /**
6601e04c3fSmrg    * Pointer to the base of the data.
6701e04c3fSmrg    */
6801e04c3fSmrg   void *data;
6901e04c3fSmrg};
7001e04c3fSmrg
7101e04c3fSmrgstruct gl_opaque_uniform_index {
7201e04c3fSmrg   /**
7301e04c3fSmrg    * Base opaque uniform index
7401e04c3fSmrg    *
7501e04c3fSmrg    * If \c gl_uniform_storage::base_type is an opaque type, this
7601e04c3fSmrg    * represents its uniform index.  If \c
7701e04c3fSmrg    * gl_uniform_storage::array_elements is not zero, the array will
7801e04c3fSmrg    * use opaque uniform indices \c index through \c index + \c
7901e04c3fSmrg    * gl_uniform_storage::array_elements - 1, inclusive.
8001e04c3fSmrg    *
8101e04c3fSmrg    * Note that the index may be different in each shader stage.
8201e04c3fSmrg    */
8301e04c3fSmrg   uint8_t index;
8401e04c3fSmrg
8501e04c3fSmrg   /**
8601e04c3fSmrg    * Whether this opaque uniform is used in this shader stage.
8701e04c3fSmrg    */
8801e04c3fSmrg   bool active;
8901e04c3fSmrg};
9001e04c3fSmrg
9101e04c3fSmrgstruct gl_uniform_storage {
9201e04c3fSmrg   char *name;
9301e04c3fSmrg   /** Type of this uniform data stored.
9401e04c3fSmrg    *
9501e04c3fSmrg    * In the case of an array, it's the type of a single array element.
9601e04c3fSmrg    */
9701e04c3fSmrg   const struct glsl_type *type;
9801e04c3fSmrg
9901e04c3fSmrg   /**
10001e04c3fSmrg    * The number of elements in this uniform.
10101e04c3fSmrg    *
10201e04c3fSmrg    * For non-arrays, this is always 0.  For arrays, the value is the size of
10301e04c3fSmrg    * the array.
10401e04c3fSmrg    */
10501e04c3fSmrg   unsigned array_elements;
10601e04c3fSmrg
10701e04c3fSmrg   struct gl_opaque_uniform_index opaque[MESA_SHADER_STAGES];
10801e04c3fSmrg
10901e04c3fSmrg   /**
11001e04c3fSmrg    * Mask of shader stages (1 << MESA_SHADER_xxx) where this uniform is used.
11101e04c3fSmrg    */
11201e04c3fSmrg   unsigned active_shader_mask;
11301e04c3fSmrg
11401e04c3fSmrg   /**
11501e04c3fSmrg    * Storage used by the driver for the uniform
11601e04c3fSmrg    */
11701e04c3fSmrg   unsigned num_driver_storage;
11801e04c3fSmrg   struct gl_uniform_driver_storage *driver_storage;
11901e04c3fSmrg
12001e04c3fSmrg   /**
12101e04c3fSmrg    * Storage used by Mesa for the uniform
12201e04c3fSmrg    *
12301e04c3fSmrg    * This form of the uniform is used by Mesa's implementation of \c
12401e04c3fSmrg    * glGetUniform.  It can also be used by drivers to obtain the value of the
12501e04c3fSmrg    * uniform if the \c ::driver_storage interface is not used.
12601e04c3fSmrg    */
12701e04c3fSmrg   union gl_constant_value *storage;
12801e04c3fSmrg
12901e04c3fSmrg   /** Fields for GL_ARB_uniform_buffer_object
13001e04c3fSmrg    * @{
13101e04c3fSmrg    */
13201e04c3fSmrg
13301e04c3fSmrg   /**
13401e04c3fSmrg    * GL_UNIFORM_BLOCK_INDEX: index of the uniform block containing
13501e04c3fSmrg    * the uniform, or -1 for the default uniform block.  Note that the
13601e04c3fSmrg    * index is into the linked program's UniformBlocks[] array, not
13701e04c3fSmrg    * the linked shader's.
13801e04c3fSmrg    */
13901e04c3fSmrg   int block_index;
14001e04c3fSmrg
14101e04c3fSmrg   /** GL_UNIFORM_OFFSET: byte offset within the uniform block, or -1. */
14201e04c3fSmrg   int offset;
14301e04c3fSmrg
14401e04c3fSmrg   /**
14501e04c3fSmrg    * GL_UNIFORM_MATRIX_STRIDE: byte stride between columns or rows of
14601e04c3fSmrg    * a matrix.  Set to 0 for non-matrices in UBOs, or -1 for uniforms
14701e04c3fSmrg    * in the default uniform block.
14801e04c3fSmrg    */
14901e04c3fSmrg   int matrix_stride;
15001e04c3fSmrg
15101e04c3fSmrg   /**
15201e04c3fSmrg    * GL_UNIFORM_ARRAY_STRIDE: byte stride between elements of the
15301e04c3fSmrg    * array.  Set to zero for non-arrays in UBOs, or -1 for uniforms
15401e04c3fSmrg    * in the default uniform block.
15501e04c3fSmrg    */
15601e04c3fSmrg   int array_stride;
15701e04c3fSmrg
15801e04c3fSmrg   /** GL_UNIFORM_ROW_MAJOR: true iff it's a row-major matrix in a UBO */
15901e04c3fSmrg   bool row_major;
16001e04c3fSmrg
16101e04c3fSmrg   /** @} */
16201e04c3fSmrg
16301e04c3fSmrg   /**
16401e04c3fSmrg    * This is a compiler-generated uniform that should not be advertised
16501e04c3fSmrg    * via the API.
16601e04c3fSmrg    */
16701e04c3fSmrg   bool hidden;
16801e04c3fSmrg
16901e04c3fSmrg   /**
17001e04c3fSmrg    * This is a built-in uniform that should not be modified through any gl API.
17101e04c3fSmrg    */
17201e04c3fSmrg   bool builtin;
17301e04c3fSmrg
17401e04c3fSmrg   /**
17501e04c3fSmrg    * This is a shader storage buffer variable, not an uniform.
17601e04c3fSmrg    */
17701e04c3fSmrg   bool is_shader_storage;
17801e04c3fSmrg
17901e04c3fSmrg   /**
18001e04c3fSmrg    * Index within gl_shader_program::AtomicBuffers[] of the atomic
18101e04c3fSmrg    * counter buffer this uniform is stored in, or -1 if this is not
18201e04c3fSmrg    * an atomic counter.
18301e04c3fSmrg    */
18401e04c3fSmrg   int atomic_buffer_index;
18501e04c3fSmrg
18601e04c3fSmrg   /**
18701e04c3fSmrg    * The 'base location' for this uniform in the uniform remap table. For
18801e04c3fSmrg    * arrays this is the first element in the array.
18901e04c3fSmrg    * for subroutines this is in shader subroutine uniform remap table.
19001e04c3fSmrg    */
19101e04c3fSmrg   unsigned remap_location;
19201e04c3fSmrg
19301e04c3fSmrg   /**
19401e04c3fSmrg    * The number of compatible subroutines with this subroutine uniform.
19501e04c3fSmrg    */
19601e04c3fSmrg   unsigned num_compatible_subroutines;
19701e04c3fSmrg
19801e04c3fSmrg   /**
19901e04c3fSmrg    * A single integer identifying the number of active array elements of
20001e04c3fSmrg    * the top-level shader storage block member (GL_TOP_LEVEL_ARRAY_SIZE).
20101e04c3fSmrg    */
20201e04c3fSmrg   unsigned top_level_array_size;
20301e04c3fSmrg
20401e04c3fSmrg   /**
20501e04c3fSmrg    * A single integer identifying the stride between array elements of the
20601e04c3fSmrg    * top-level shader storage block member. (GL_TOP_LEVEL_ARRAY_STRIDE).
20701e04c3fSmrg    */
20801e04c3fSmrg   unsigned top_level_array_stride;
20901e04c3fSmrg
21001e04c3fSmrg   /**
21101e04c3fSmrg    * Whether this uniform variable has the bindless_sampler or bindless_image
21201e04c3fSmrg    * layout qualifier as specified by ARB_bindless_texture.
21301e04c3fSmrg    */
21401e04c3fSmrg   bool is_bindless;
21501e04c3fSmrg};
21601e04c3fSmrg
21701e04c3fSmrg#ifdef __cplusplus
21801e04c3fSmrg}
21901e04c3fSmrg#endif
22001e04c3fSmrg
22101e04c3fSmrg#endif /* IR_UNIFORM_H */
222