• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR 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
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \file prog_parameter.c
27  * Program parameter lists and functions.
28  * \author Brian Paul
29  */
30 
31 #ifndef PROG_PARAMETER_H
32 #define PROG_PARAMETER_H
33 
34 #include <stdbool.h>
35 #include <stdint.h>
36 #include "prog_statevars.h"
37 
38 #include <string.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**
45  * Names of the various vertex/fragment program register files, etc.
46  *
47  * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
48  * All values should fit in a 4-bit field.
49  *
50  * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
51  * considered to be "uniform" variables since they can only be set outside
52  * glBegin/End.  They're also all stored in the same Parameters array.
53  */
54 typedef enum
55 {
56    PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
57    PROGRAM_INPUT,       /**< machine->Inputs[] */
58    PROGRAM_OUTPUT,      /**< machine->Outputs[] */
59    PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
60    PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
61    PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
62    PROGRAM_ADDRESS,     /**< machine->AddressReg */
63    PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
64    PROGRAM_FILE_MAX
65 } gl_register_file;
66 
67 
68 /**
69  * Actual data for constant values of parameters.
70  */
71 typedef union gl_constant_value
72 {
73    GLfloat f;
74    GLint b;
75    GLint i;
76    GLuint u;
77 } gl_constant_value;
78 
79 
80 /**
81  * Program parameter.
82  * Used by shaders/programs for uniforms, constants, varying vars, etc.
83  */
84 struct gl_program_parameter
85 {
86    const char *Name;        /**< Null-terminated string */
87    gl_register_file Type:5;  /**< PROGRAM_CONSTANT or STATE_VAR */
88 
89    /**
90     * We need to keep track of whether the param is padded for use in the
91     * shader cache.
92     */
93    bool Padded:1;
94 
95    GLenum16 DataType;         /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
96 
97    /**
98     * Number of components (1..4), or more.
99     * If the number of components is greater than 4,
100     * this parameter is part of a larger uniform like a GLSL matrix or array.
101     */
102    GLushort Size;
103    /**
104     * A sequence of STATE_* tokens and integers to identify GL state.
105     */
106    gl_state_index16 StateIndexes[STATE_LENGTH];
107 
108    /**
109     * Offset within ParameterValues where this parameter is stored.
110     */
111    unsigned ValueOffset;
112 
113    /**
114     * Index of this parameter's uniform storage.
115     */
116    uint32_t UniformStorageIndex;
117 
118    /**
119     * Index of the first uniform storage that is associated with the same
120     * variable as this parameter.
121     */
122    uint32_t MainUniformStorageIndex;
123 };
124 
125 
126 /**
127  * List of gl_program_parameter instances.
128  */
129 struct gl_program_parameter_list
130 {
131    unsigned Size;           /**< allocated size of Parameters */
132    unsigned SizeValues;     /**< alllocate size of ParameterValues */
133    GLuint NumParameters;  /**< number of used parameters in array */
134    unsigned NumParameterValues;  /**< number of used parameter values array */
135    struct gl_program_parameter *Parameters; /**< Array [Size] */
136    gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */
137    GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
138                                might invalidate ParameterValues[] */
139    bool DisallowRealloc;
140 
141    /* Parameters are optionally sorted as follows. Uniforms and constants
142     * are first, then state vars. This should be true in all cases except
143     * ir_to_mesa, which adds constants at the end, and ARB_vp with ARL,
144     * which can't sort parameters.
145     */
146    int UniformBytes;
147    int FirstStateVarIndex;
148    int LastStateVarIndex;
149 };
150 
151 
152 extern struct gl_program_parameter_list *
153 _mesa_new_parameter_list(void);
154 
155 extern struct gl_program_parameter_list *
156 _mesa_new_parameter_list_sized(unsigned size);
157 
158 extern void
159 _mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
160 
161 extern void
162 _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
163                                 unsigned reserve_params,
164                                 unsigned reserve_values);
165 
166 extern void
167 _mesa_disallow_parameter_storage_realloc(struct gl_program_parameter_list *paramList);
168 
169 extern GLint
170 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
171                     gl_register_file type, const char *name,
172                     GLuint size, GLenum datatype,
173                     const gl_constant_value *values,
174                     const gl_state_index16 state[STATE_LENGTH],
175                     bool pad_and_align);
176 
177 extern GLint
178 _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
179                            const gl_constant_value *values, GLuint size,
180                            GLenum datatype, GLuint *swizzleOut);
181 
182 static inline GLint
_mesa_add_unnamed_constant(struct gl_program_parameter_list * paramList,const gl_constant_value * values,GLuint size,GLuint * swizzleOut)183 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
184                            const gl_constant_value *values, GLuint size,
185                            GLuint *swizzleOut)
186 {
187    return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
188                                            swizzleOut);
189 }
190 
191 extern GLint
192 _mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList,
193                                 const gl_state_index16 stateTokens[STATE_LENGTH],
194                                 const unsigned size, bool pad_and_align);
195 
196 extern GLint
197 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
198                           const gl_state_index16 stateTokens[STATE_LENGTH]);
199 
200 
201 static inline GLint
_mesa_lookup_parameter_index(const struct gl_program_parameter_list * paramList,const char * name)202 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
203                              const char *name)
204 {
205    if (!paramList)
206       return -1;
207 
208    /* name must be null-terminated */
209    for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) {
210       if (paramList->Parameters[i].Name &&
211          strcmp(paramList->Parameters[i].Name, name) == 0)
212          return i;
213    }
214 
215    return -1;
216 }
217 
218 static inline bool
_mesa_gl_datatype_is_64bit(GLenum datatype)219 _mesa_gl_datatype_is_64bit(GLenum datatype)
220 {
221    switch (datatype) {
222    case GL_DOUBLE:
223    case GL_DOUBLE_VEC2:
224    case GL_DOUBLE_VEC3:
225    case GL_DOUBLE_VEC4:
226    case GL_DOUBLE_MAT2:
227    case GL_DOUBLE_MAT2x3:
228    case GL_DOUBLE_MAT2x4:
229    case GL_DOUBLE_MAT3:
230    case GL_DOUBLE_MAT3x2:
231    case GL_DOUBLE_MAT3x4:
232    case GL_DOUBLE_MAT4:
233    case GL_DOUBLE_MAT4x2:
234    case GL_DOUBLE_MAT4x3:
235    case GL_INT64_ARB:
236    case GL_INT64_VEC2_ARB:
237    case GL_INT64_VEC3_ARB:
238    case GL_INT64_VEC4_ARB:
239    case GL_UNSIGNED_INT64_ARB:
240    case GL_UNSIGNED_INT64_VEC2_ARB:
241    case GL_UNSIGNED_INT64_VEC3_ARB:
242    case GL_UNSIGNED_INT64_VEC4_ARB:
243       return true;
244    default:
245       return false;
246    }
247 }
248 
249 void
250 _mesa_recompute_parameter_bounds(struct gl_program_parameter_list *list);
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* PROG_PARAMETER_H */
257