prog_parameter.h revision 993e1d59
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 39extern "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 */ 52typedef 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 */ 78typedef 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 */ 91struct gl_program_parameter 92{ 93 const char *Name; /**< Null-terminated string */ 94 gl_register_file Type:16; /**< PROGRAM_CONSTANT or STATE_VAR */ 95 GLenum16 DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */ 96 /** 97 * Number of components (1..4), or more. 98 * If the number of components is greater than 4, 99 * this parameter is part of a larger uniform like a GLSL matrix or array. 100 * The next program parameter's Size will be Size-4 of this parameter. 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 * We need to keep track of whether the param is padded for use in the 110 * shader cache. 111 */ 112 bool Padded; 113}; 114 115 116/** 117 * List of gl_program_parameter instances. 118 */ 119struct gl_program_parameter_list 120{ 121 GLuint Size; /**< allocated size of Parameters, ParameterValues */ 122 GLuint NumParameters; /**< number of used parameters in array */ 123 unsigned NumParameterValues; /**< number of used parameter values array */ 124 struct gl_program_parameter *Parameters; /**< Array [Size] */ 125 unsigned *ParameterValueOffset; 126 gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */ 127 GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes 128 might invalidate ParameterValues[] */ 129}; 130 131 132extern struct gl_program_parameter_list * 133_mesa_new_parameter_list(void); 134 135extern struct gl_program_parameter_list * 136_mesa_new_parameter_list_sized(unsigned size); 137 138extern void 139_mesa_free_parameter_list(struct gl_program_parameter_list *paramList); 140 141extern void 142_mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList, 143 unsigned reserve_slots); 144 145extern GLint 146_mesa_add_parameter(struct gl_program_parameter_list *paramList, 147 gl_register_file type, const char *name, 148 GLuint size, GLenum datatype, 149 const gl_constant_value *values, 150 const gl_state_index16 state[STATE_LENGTH], 151 bool pad_and_align); 152 153extern GLint 154_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, 155 const gl_constant_value values[4], GLuint size, 156 GLenum datatype, GLuint *swizzleOut); 157 158static inline GLint 159_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, 160 const gl_constant_value values[4], GLuint size, 161 GLuint *swizzleOut) 162{ 163 return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE, 164 swizzleOut); 165} 166 167extern GLint 168_mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList, 169 const gl_state_index16 stateTokens[STATE_LENGTH], 170 const unsigned size, bool pad_and_align); 171 172extern GLint 173_mesa_add_state_reference(struct gl_program_parameter_list *paramList, 174 const gl_state_index16 stateTokens[]); 175 176 177static inline GLint 178_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, 179 const char *name) 180{ 181 if (!paramList) 182 return -1; 183 184 /* name must be null-terminated */ 185 for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) { 186 if (paramList->Parameters[i].Name && 187 strcmp(paramList->Parameters[i].Name, name) == 0) 188 return i; 189 } 190 191 return -1; 192} 193 194#ifdef __cplusplus 195} 196#endif 197 198#endif /* PROG_PARAMETER_H */ 199