glsl/nir: Fill in the Parameters in NIR linker
[mesa.git] / src / mesa / program / prog_parameter.h
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 "prog_statevars.h"
35
36 #include <string.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /**
43 * Names of the various vertex/fragment program register files, etc.
44 *
45 * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
46 * All values should fit in a 4-bit field.
47 *
48 * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
49 * considered to be "uniform" variables since they can only be set outside
50 * glBegin/End. They're also all stored in the same Parameters array.
51 */
52 typedef enum
53 {
54 PROGRAM_TEMPORARY, /**< machine->Temporary[] */
55 PROGRAM_ARRAY, /**< Arrays & Matrixes */
56 PROGRAM_INPUT, /**< machine->Inputs[] */
57 PROGRAM_OUTPUT, /**< machine->Outputs[] */
58 PROGRAM_STATE_VAR, /**< gl_program->Parameters[] */
59 PROGRAM_CONSTANT, /**< gl_program->Parameters[] */
60 PROGRAM_UNIFORM, /**< gl_program->Parameters[] */
61 PROGRAM_WRITE_ONLY, /**< A dummy, write-only register */
62 PROGRAM_ADDRESS, /**< machine->AddressReg */
63 PROGRAM_SAMPLER, /**< for shader samplers, compile-time only */
64 PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
65 PROGRAM_UNDEFINED, /**< Invalid/TBD value */
66 PROGRAM_IMMEDIATE, /**< Immediate value, used by TGSI */
67 PROGRAM_BUFFER, /**< for shader buffers, compile-time only */
68 PROGRAM_MEMORY, /**< for shared, global and local memory */
69 PROGRAM_IMAGE, /**< for shader images, compile-time only */
70 PROGRAM_HW_ATOMIC, /**< for hw atomic counters, compile-time only */
71 PROGRAM_FILE_MAX
72 } gl_register_file;
73
74
75 /**
76 * Actual data for constant values of parameters.
77 */
78 typedef union gl_constant_value
79 {
80 GLfloat f;
81 GLint b;
82 GLint i;
83 GLuint u;
84 } gl_constant_value;
85
86
87 /**
88 * Program parameter.
89 * Used by shaders/programs for uniforms, constants, varying vars, etc.
90 */
91 struct gl_program_parameter
92 {
93 const char *Name; /**< Null-terminated string */
94 gl_register_file Type:5; /**< PROGRAM_CONSTANT or STATE_VAR */
95
96 /**
97 * We need to keep track of whether the param is padded for use in the
98 * shader cache.
99 */
100 bool Padded:1;
101
102 GLenum16 DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
103
104 /**
105 * Number of components (1..4), or more.
106 * If the number of components is greater than 4,
107 * this parameter is part of a larger uniform like a GLSL matrix or array.
108 * The next program parameter's Size will be Size-4 of this parameter.
109 */
110 GLushort Size;
111 /**
112 * A sequence of STATE_* tokens and integers to identify GL state.
113 */
114 gl_state_index16 StateIndexes[STATE_LENGTH];
115
116 /**
117 * Index of this parameter's uniform storage.
118 */
119 uint32_t UniformStorageIndex;
120
121 /**
122 * Index of the first uniform storage that is associated with the same
123 * variable as this parameter.
124 */
125 uint32_t MainUniformStorageIndex;
126 };
127
128
129 /**
130 * List of gl_program_parameter instances.
131 */
132 struct gl_program_parameter_list
133 {
134 GLuint Size; /**< allocated size of Parameters, ParameterValues */
135 GLuint NumParameters; /**< number of used parameters in array */
136 unsigned NumParameterValues; /**< number of used parameter values array */
137 struct gl_program_parameter *Parameters; /**< Array [Size] */
138 unsigned *ParameterValueOffset;
139 gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */
140 GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
141 might invalidate ParameterValues[] */
142 };
143
144
145 extern struct gl_program_parameter_list *
146 _mesa_new_parameter_list(void);
147
148 extern struct gl_program_parameter_list *
149 _mesa_new_parameter_list_sized(unsigned size);
150
151 extern void
152 _mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
153
154 extern void
155 _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
156 unsigned reserve_slots);
157
158 extern GLint
159 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
160 gl_register_file type, const char *name,
161 GLuint size, GLenum datatype,
162 const gl_constant_value *values,
163 const gl_state_index16 state[STATE_LENGTH],
164 bool pad_and_align);
165
166 extern GLint
167 _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
168 const gl_constant_value values[4], GLuint size,
169 GLenum datatype, GLuint *swizzleOut);
170
171 static inline GLint
172 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
173 const gl_constant_value values[4], GLuint size,
174 GLuint *swizzleOut)
175 {
176 return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
177 swizzleOut);
178 }
179
180 extern GLint
181 _mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList,
182 const gl_state_index16 stateTokens[STATE_LENGTH],
183 const unsigned size, bool pad_and_align);
184
185 extern GLint
186 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
187 const gl_state_index16 stateTokens[]);
188
189
190 static inline GLint
191 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
192 const char *name)
193 {
194 if (!paramList)
195 return -1;
196
197 /* name must be null-terminated */
198 for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) {
199 if (paramList->Parameters[i].Name &&
200 strcmp(paramList->Parameters[i].Name, name) == 0)
201 return i;
202 }
203
204 return -1;
205 }
206
207 static inline bool
208 _mesa_gl_datatype_is_64bit(GLenum datatype)
209 {
210 switch (datatype) {
211 case GL_DOUBLE:
212 case GL_DOUBLE_VEC2:
213 case GL_DOUBLE_VEC3:
214 case GL_DOUBLE_VEC4:
215 case GL_DOUBLE_MAT2:
216 case GL_DOUBLE_MAT2x3:
217 case GL_DOUBLE_MAT2x4:
218 case GL_DOUBLE_MAT3:
219 case GL_DOUBLE_MAT3x2:
220 case GL_DOUBLE_MAT3x4:
221 case GL_DOUBLE_MAT4:
222 case GL_DOUBLE_MAT4x2:
223 case GL_DOUBLE_MAT4x3:
224 case GL_INT64_ARB:
225 case GL_INT64_VEC2_ARB:
226 case GL_INT64_VEC3_ARB:
227 case GL_INT64_VEC4_ARB:
228 case GL_UNSIGNED_INT64_ARB:
229 case GL_UNSIGNED_INT64_VEC2_ARB:
230 case GL_UNSIGNED_INT64_VEC3_ARB:
231 case GL_UNSIGNED_INT64_VEC4_ARB:
232 return true;
233 default:
234 return false;
235 }
236 }
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* PROG_PARAMETER_H */