1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg/** 26848b8605Smrg * \file prog_parameter.c 27848b8605Smrg * Program parameter lists and functions. 28848b8605Smrg * \author Brian Paul 29848b8605Smrg */ 30848b8605Smrg 31848b8605Smrg#ifndef PROG_PARAMETER_H 32848b8605Smrg#define PROG_PARAMETER_H 33848b8605Smrg 34848b8605Smrg#include "prog_statevars.h" 35848b8605Smrg 36b8e80941Smrg#include <string.h> 37848b8605Smrg 38848b8605Smrg#ifdef __cplusplus 39848b8605Smrgextern "C" { 40848b8605Smrg#endif 41848b8605Smrg 42b8e80941Smrg/** 43b8e80941Smrg * Names of the various vertex/fragment program register files, etc. 44b8e80941Smrg * 45b8e80941Smrg * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c) 46b8e80941Smrg * All values should fit in a 4-bit field. 47b8e80941Smrg * 48b8e80941Smrg * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be 49b8e80941Smrg * considered to be "uniform" variables since they can only be set outside 50b8e80941Smrg * glBegin/End. They're also all stored in the same Parameters array. 51b8e80941Smrg */ 52b8e80941Smrgtypedef enum 53b8e80941Smrg{ 54b8e80941Smrg PROGRAM_TEMPORARY, /**< machine->Temporary[] */ 55b8e80941Smrg PROGRAM_ARRAY, /**< Arrays & Matrixes */ 56b8e80941Smrg PROGRAM_INPUT, /**< machine->Inputs[] */ 57b8e80941Smrg PROGRAM_OUTPUT, /**< machine->Outputs[] */ 58b8e80941Smrg PROGRAM_STATE_VAR, /**< gl_program->Parameters[] */ 59b8e80941Smrg PROGRAM_CONSTANT, /**< gl_program->Parameters[] */ 60b8e80941Smrg PROGRAM_UNIFORM, /**< gl_program->Parameters[] */ 61b8e80941Smrg PROGRAM_WRITE_ONLY, /**< A dummy, write-only register */ 62b8e80941Smrg PROGRAM_ADDRESS, /**< machine->AddressReg */ 63b8e80941Smrg PROGRAM_SAMPLER, /**< for shader samplers, compile-time only */ 64b8e80941Smrg PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */ 65b8e80941Smrg PROGRAM_UNDEFINED, /**< Invalid/TBD value */ 66b8e80941Smrg PROGRAM_IMMEDIATE, /**< Immediate value, used by TGSI */ 67b8e80941Smrg PROGRAM_BUFFER, /**< for shader buffers, compile-time only */ 68b8e80941Smrg PROGRAM_MEMORY, /**< for shared, global and local memory */ 69b8e80941Smrg PROGRAM_IMAGE, /**< for shader images, compile-time only */ 70b8e80941Smrg PROGRAM_HW_ATOMIC, /**< for hw atomic counters, compile-time only */ 71b8e80941Smrg PROGRAM_FILE_MAX 72b8e80941Smrg} gl_register_file; 73b8e80941Smrg 74848b8605Smrg 75848b8605Smrg/** 76848b8605Smrg * Actual data for constant values of parameters. 77848b8605Smrg */ 78848b8605Smrgtypedef union gl_constant_value 79848b8605Smrg{ 80848b8605Smrg GLfloat f; 81848b8605Smrg GLint b; 82848b8605Smrg GLint i; 83848b8605Smrg GLuint u; 84848b8605Smrg} gl_constant_value; 85848b8605Smrg 86848b8605Smrg 87848b8605Smrg/** 88848b8605Smrg * Program parameter. 89848b8605Smrg * Used by shaders/programs for uniforms, constants, varying vars, etc. 90848b8605Smrg */ 91848b8605Smrgstruct gl_program_parameter 92848b8605Smrg{ 93848b8605Smrg const char *Name; /**< Null-terminated string */ 94b8e80941Smrg gl_register_file Type:16; /**< PROGRAM_CONSTANT or STATE_VAR */ 95b8e80941Smrg GLenum16 DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */ 96848b8605Smrg /** 97848b8605Smrg * Number of components (1..4), or more. 98848b8605Smrg * If the number of components is greater than 4, 99848b8605Smrg * this parameter is part of a larger uniform like a GLSL matrix or array. 100848b8605Smrg * The next program parameter's Size will be Size-4 of this parameter. 101848b8605Smrg */ 102b8e80941Smrg GLushort Size; 103848b8605Smrg /** 104848b8605Smrg * A sequence of STATE_* tokens and integers to identify GL state. 105848b8605Smrg */ 106b8e80941Smrg gl_state_index16 StateIndexes[STATE_LENGTH]; 107b8e80941Smrg 108b8e80941Smrg /** 109b8e80941Smrg * We need to keep track of whether the param is padded for use in the 110b8e80941Smrg * shader cache. 111b8e80941Smrg */ 112b8e80941Smrg bool Padded; 113848b8605Smrg}; 114848b8605Smrg 115848b8605Smrg 116848b8605Smrg/** 117848b8605Smrg * List of gl_program_parameter instances. 118848b8605Smrg */ 119848b8605Smrgstruct gl_program_parameter_list 120848b8605Smrg{ 121848b8605Smrg GLuint Size; /**< allocated size of Parameters, ParameterValues */ 122b8e80941Smrg GLuint NumParameters; /**< number of used parameters in array */ 123b8e80941Smrg unsigned NumParameterValues; /**< number of used parameter values array */ 124848b8605Smrg struct gl_program_parameter *Parameters; /**< Array [Size] */ 125b8e80941Smrg unsigned *ParameterValueOffset; 126b8e80941Smrg gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */ 127848b8605Smrg GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes 128848b8605Smrg might invalidate ParameterValues[] */ 129848b8605Smrg}; 130848b8605Smrg 131848b8605Smrg 132848b8605Smrgextern struct gl_program_parameter_list * 133848b8605Smrg_mesa_new_parameter_list(void); 134848b8605Smrg 135848b8605Smrgextern struct gl_program_parameter_list * 136848b8605Smrg_mesa_new_parameter_list_sized(unsigned size); 137848b8605Smrg 138848b8605Smrgextern void 139848b8605Smrg_mesa_free_parameter_list(struct gl_program_parameter_list *paramList); 140848b8605Smrg 141b8e80941Smrgextern void 142b8e80941Smrg_mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList, 143b8e80941Smrg unsigned reserve_slots); 144848b8605Smrg 145848b8605Smrgextern GLint 146848b8605Smrg_mesa_add_parameter(struct gl_program_parameter_list *paramList, 147848b8605Smrg gl_register_file type, const char *name, 148848b8605Smrg GLuint size, GLenum datatype, 149848b8605Smrg const gl_constant_value *values, 150b8e80941Smrg const gl_state_index16 state[STATE_LENGTH], 151b8e80941Smrg bool pad_and_align); 152848b8605Smrg 153848b8605Smrgextern GLint 154848b8605Smrg_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, 155848b8605Smrg const gl_constant_value values[4], GLuint size, 156848b8605Smrg GLenum datatype, GLuint *swizzleOut); 157848b8605Smrg 158b8e80941Smrgstatic inline GLint 159848b8605Smrg_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, 160848b8605Smrg const gl_constant_value values[4], GLuint size, 161b8e80941Smrg GLuint *swizzleOut) 162b8e80941Smrg{ 163b8e80941Smrg return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE, 164b8e80941Smrg swizzleOut); 165b8e80941Smrg} 166b8e80941Smrg 167b8e80941Smrgextern GLint 168b8e80941Smrg_mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList, 169b8e80941Smrg const gl_state_index16 stateTokens[STATE_LENGTH], 170b8e80941Smrg const unsigned size, bool pad_and_align); 171848b8605Smrg 172848b8605Smrgextern GLint 173848b8605Smrg_mesa_add_state_reference(struct gl_program_parameter_list *paramList, 174b8e80941Smrg const gl_state_index16 stateTokens[]); 175848b8605Smrg 176848b8605Smrg 177b8e80941Smrgstatic inline GLint 178848b8605Smrg_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, 179b8e80941Smrg const char *name) 180b8e80941Smrg{ 181b8e80941Smrg if (!paramList) 182b8e80941Smrg return -1; 183848b8605Smrg 184b8e80941Smrg /* name must be null-terminated */ 185b8e80941Smrg for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) { 186b8e80941Smrg if (paramList->Parameters[i].Name && 187b8e80941Smrg strcmp(paramList->Parameters[i].Name, name) == 0) 188b8e80941Smrg return i; 189b8e80941Smrg } 190b8e80941Smrg 191b8e80941Smrg return -1; 192b8e80941Smrg} 193b8e80941Smrg 194b8e80941Smrgstatic inline bool 195b8e80941Smrg_mesa_gl_datatype_is_64bit(GLenum datatype) 196b8e80941Smrg{ 197b8e80941Smrg switch (datatype) { 198b8e80941Smrg case GL_DOUBLE: 199b8e80941Smrg case GL_DOUBLE_VEC2: 200b8e80941Smrg case GL_DOUBLE_VEC3: 201b8e80941Smrg case GL_DOUBLE_VEC4: 202b8e80941Smrg case GL_DOUBLE_MAT2: 203b8e80941Smrg case GL_DOUBLE_MAT2x3: 204b8e80941Smrg case GL_DOUBLE_MAT2x4: 205b8e80941Smrg case GL_DOUBLE_MAT3: 206b8e80941Smrg case GL_DOUBLE_MAT3x2: 207b8e80941Smrg case GL_DOUBLE_MAT3x4: 208b8e80941Smrg case GL_DOUBLE_MAT4: 209b8e80941Smrg case GL_DOUBLE_MAT4x2: 210b8e80941Smrg case GL_DOUBLE_MAT4x3: 211b8e80941Smrg case GL_INT64_ARB: 212b8e80941Smrg case GL_INT64_VEC2_ARB: 213b8e80941Smrg case GL_INT64_VEC3_ARB: 214b8e80941Smrg case GL_INT64_VEC4_ARB: 215b8e80941Smrg case GL_UNSIGNED_INT64_ARB: 216b8e80941Smrg case GL_UNSIGNED_INT64_VEC2_ARB: 217b8e80941Smrg case GL_UNSIGNED_INT64_VEC3_ARB: 218b8e80941Smrg case GL_UNSIGNED_INT64_VEC4_ARB: 219b8e80941Smrg return true; 220b8e80941Smrg default: 221b8e80941Smrg return false; 222b8e80941Smrg } 223b8e80941Smrg} 224848b8605Smrg 225848b8605Smrg#ifdef __cplusplus 226848b8605Smrg} 227848b8605Smrg#endif 228848b8605Smrg 229848b8605Smrg#endif /* PROG_PARAMETER_H */ 230