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 41extern "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 */ 54typedef 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_WRITE_ONLY, /**< A dummy, write-only register */ 63 PROGRAM_ADDRESS, /**< machine->AddressReg */ 64 PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */ 65 PROGRAM_UNDEFINED, /**< Invalid/TBD value */ 66 PROGRAM_FILE_MAX 67} gl_register_file; 68 69 70/** 71 * Actual data for constant values of parameters. 72 */ 73typedef union gl_constant_value 74{ 75 GLfloat f; 76 GLint b; 77 GLint i; 78 GLuint u; 79} gl_constant_value; 80 81 82/** 83 * Program parameter. 84 * Used by shaders/programs for uniforms, constants, varying vars, etc. 85 */ 86struct gl_program_parameter 87{ 88 const char *Name; /**< Null-terminated string */ 89 gl_register_file Type:5; /**< PROGRAM_CONSTANT or STATE_VAR */ 90 91 /** 92 * We need to keep track of whether the param is padded for use in the 93 * shader cache. 94 */ 95 bool Padded:1; 96 97 GLenum16 DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */ 98 99 /** 100 * Number of components (1..4), or more. 101 * If the number of components is greater than 4, 102 * this parameter is part of a larger uniform like a GLSL matrix or array. 103 */ 104 GLushort Size; 105 /** 106 * A sequence of STATE_* tokens and integers to identify GL state. 107 */ 108 gl_state_index16 StateIndexes[STATE_LENGTH]; 109 110 /** 111 * Offset within ParameterValues where this parameter is stored. 112 */ 113 unsigned ValueOffset; 114 115 /** 116 * Index of this parameter's uniform storage. 117 */ 118 uint32_t UniformStorageIndex; 119 120 /** 121 * Index of the first uniform storage that is associated with the same 122 * variable as this parameter. 123 */ 124 uint32_t MainUniformStorageIndex; 125}; 126 127 128/** 129 * List of gl_program_parameter instances. 130 */ 131struct gl_program_parameter_list 132{ 133 unsigned Size; /**< allocated size of Parameters */ 134 unsigned SizeValues; /**< alllocate size of 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 gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */ 139 GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes 140 might invalidate ParameterValues[] */ 141 bool DisallowRealloc; 142 143 /* Parameters are optionally sorted as follows. Uniforms and constants 144 * are first, then state vars. This should be true in all cases except 145 * ir_to_mesa, which adds constants at the end, and ARB_vp with ARL, 146 * which can't sort parameters. 147 */ 148 int UniformBytes; 149 int FirstStateVarIndex; 150 int LastStateVarIndex; 151}; 152 153 154extern struct gl_program_parameter_list * 155_mesa_new_parameter_list(void); 156 157extern struct gl_program_parameter_list * 158_mesa_new_parameter_list_sized(unsigned size); 159 160extern void 161_mesa_free_parameter_list(struct gl_program_parameter_list *paramList); 162 163extern void 164_mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList, 165 unsigned reserve_params, 166 unsigned reserve_values); 167 168extern void 169_mesa_disallow_parameter_storage_realloc(struct gl_program_parameter_list *paramList); 170 171extern GLint 172_mesa_add_parameter(struct gl_program_parameter_list *paramList, 173 gl_register_file type, const char *name, 174 GLuint size, GLenum datatype, 175 const gl_constant_value *values, 176 const gl_state_index16 state[STATE_LENGTH], 177 bool pad_and_align); 178 179extern GLint 180_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, 181 const gl_constant_value *values, GLuint size, 182 GLenum datatype, GLuint *swizzleOut); 183 184static inline GLint 185_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, 186 const gl_constant_value *values, GLuint size, 187 GLuint *swizzleOut) 188{ 189 return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE, 190 swizzleOut); 191} 192 193extern GLint 194_mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList, 195 const gl_state_index16 stateTokens[STATE_LENGTH], 196 const unsigned size, bool pad_and_align); 197 198extern GLint 199_mesa_add_state_reference(struct gl_program_parameter_list *paramList, 200 const gl_state_index16 stateTokens[STATE_LENGTH]); 201 202 203static inline GLint 204_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, 205 const char *name) 206{ 207 if (!paramList) 208 return -1; 209 210 /* name must be null-terminated */ 211 for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) { 212 if (paramList->Parameters[i].Name && 213 strcmp(paramList->Parameters[i].Name, name) == 0) 214 return i; 215 } 216 217 return -1; 218} 219 220static inline bool 221_mesa_gl_datatype_is_64bit(GLenum datatype) 222{ 223 switch (datatype) { 224 case GL_DOUBLE: 225 case GL_DOUBLE_VEC2: 226 case GL_DOUBLE_VEC3: 227 case GL_DOUBLE_VEC4: 228 case GL_DOUBLE_MAT2: 229 case GL_DOUBLE_MAT2x3: 230 case GL_DOUBLE_MAT2x4: 231 case GL_DOUBLE_MAT3: 232 case GL_DOUBLE_MAT3x2: 233 case GL_DOUBLE_MAT3x4: 234 case GL_DOUBLE_MAT4: 235 case GL_DOUBLE_MAT4x2: 236 case GL_DOUBLE_MAT4x3: 237 case GL_INT64_ARB: 238 case GL_INT64_VEC2_ARB: 239 case GL_INT64_VEC3_ARB: 240 case GL_INT64_VEC4_ARB: 241 case GL_UNSIGNED_INT64_ARB: 242 case GL_UNSIGNED_INT64_VEC2_ARB: 243 case GL_UNSIGNED_INT64_VEC3_ARB: 244 case GL_UNSIGNED_INT64_VEC4_ARB: 245 return true; 246 default: 247 return false; 248 } 249} 250 251void 252_mesa_recompute_parameter_bounds(struct gl_program_parameter_list *list); 253 254#ifdef __cplusplus 255} 256#endif 257 258#endif /* PROG_PARAMETER_H */ 259