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