13464ebd5Sriastradh/*
23464ebd5Sriastradh * Mesa 3-D graphics library
33464ebd5Sriastradh *
43464ebd5Sriastradh * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
83464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
93464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
103464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
113464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions:
123464ebd5Sriastradh *
133464ebd5Sriastradh * The above copyright notice and this permission notice shall be included
143464ebd5Sriastradh * in all copies or substantial portions of the Software.
153464ebd5Sriastradh *
163464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
173464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
233464ebd5Sriastradh */
243464ebd5Sriastradh
253464ebd5Sriastradh/**
263464ebd5Sriastradh * \file prog_parameter.c
273464ebd5Sriastradh * Program parameter lists and functions.
283464ebd5Sriastradh * \author Brian Paul
293464ebd5Sriastradh */
303464ebd5Sriastradh
313464ebd5Sriastradh#ifndef PROG_PARAMETER_H
323464ebd5Sriastradh#define PROG_PARAMETER_H
333464ebd5Sriastradh
347ec681f3Smrg#include <stdbool.h>
357ec681f3Smrg#include <stdint.h>
363464ebd5Sriastradh#include "prog_statevars.h"
373464ebd5Sriastradh
3801e04c3fSmrg#include <string.h>
393464ebd5Sriastradh
40af69d88dSmrg#ifdef __cplusplus
41af69d88dSmrgextern "C" {
42af69d88dSmrg#endif
43af69d88dSmrg
4401e04c3fSmrg/**
4501e04c3fSmrg * Names of the various vertex/fragment program register files, etc.
4601e04c3fSmrg *
4701e04c3fSmrg * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
4801e04c3fSmrg * All values should fit in a 4-bit field.
4901e04c3fSmrg *
5001e04c3fSmrg * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
5101e04c3fSmrg * considered to be "uniform" variables since they can only be set outside
5201e04c3fSmrg * glBegin/End.  They're also all stored in the same Parameters array.
5301e04c3fSmrg */
5401e04c3fSmrgtypedef enum
5501e04c3fSmrg{
5601e04c3fSmrg   PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
5701e04c3fSmrg   PROGRAM_ARRAY,       /**< Arrays & Matrixes */
5801e04c3fSmrg   PROGRAM_INPUT,       /**< machine->Inputs[] */
5901e04c3fSmrg   PROGRAM_OUTPUT,      /**< machine->Outputs[] */
6001e04c3fSmrg   PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
6101e04c3fSmrg   PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
6201e04c3fSmrg   PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
6301e04c3fSmrg   PROGRAM_WRITE_ONLY,  /**< A dummy, write-only register */
6401e04c3fSmrg   PROGRAM_ADDRESS,     /**< machine->AddressReg */
6501e04c3fSmrg   PROGRAM_SAMPLER,     /**< for shader samplers, compile-time only */
6601e04c3fSmrg   PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
6701e04c3fSmrg   PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
6801e04c3fSmrg   PROGRAM_IMMEDIATE,   /**< Immediate value, used by TGSI */
6901e04c3fSmrg   PROGRAM_BUFFER,      /**< for shader buffers, compile-time only */
7001e04c3fSmrg   PROGRAM_MEMORY,      /**< for shared, global and local memory */
7101e04c3fSmrg   PROGRAM_IMAGE,       /**< for shader images, compile-time only */
7201e04c3fSmrg   PROGRAM_HW_ATOMIC,   /**< for hw atomic counters, compile-time only */
7301e04c3fSmrg   PROGRAM_FILE_MAX
7401e04c3fSmrg} gl_register_file;
7501e04c3fSmrg
76af69d88dSmrg
773464ebd5Sriastradh/**
78af69d88dSmrg * Actual data for constant values of parameters.
793464ebd5Sriastradh */
80af69d88dSmrgtypedef union gl_constant_value
81af69d88dSmrg{
82af69d88dSmrg   GLfloat f;
83af69d88dSmrg   GLint b;
84af69d88dSmrg   GLint i;
85af69d88dSmrg   GLuint u;
86af69d88dSmrg} gl_constant_value;
873464ebd5Sriastradh
883464ebd5Sriastradh
893464ebd5Sriastradh/**
903464ebd5Sriastradh * Program parameter.
913464ebd5Sriastradh * Used by shaders/programs for uniforms, constants, varying vars, etc.
923464ebd5Sriastradh */
933464ebd5Sriastradhstruct gl_program_parameter
943464ebd5Sriastradh{
953464ebd5Sriastradh   const char *Name;        /**< Null-terminated string */
967ec681f3Smrg   gl_register_file Type:5;  /**< PROGRAM_CONSTANT or STATE_VAR */
977ec681f3Smrg
987ec681f3Smrg   /**
997ec681f3Smrg    * We need to keep track of whether the param is padded for use in the
1007ec681f3Smrg    * shader cache.
1017ec681f3Smrg    */
1027ec681f3Smrg   bool Padded:1;
1037ec681f3Smrg
10401e04c3fSmrg   GLenum16 DataType;         /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
1057ec681f3Smrg
1063464ebd5Sriastradh   /**
1073464ebd5Sriastradh    * Number of components (1..4), or more.
1083464ebd5Sriastradh    * If the number of components is greater than 4,
1093464ebd5Sriastradh    * this parameter is part of a larger uniform like a GLSL matrix or array.
1103464ebd5Sriastradh    */
11101e04c3fSmrg   GLushort Size;
1123464ebd5Sriastradh   /**
1133464ebd5Sriastradh    * A sequence of STATE_* tokens and integers to identify GL state.
1143464ebd5Sriastradh    */
11501e04c3fSmrg   gl_state_index16 StateIndexes[STATE_LENGTH];
116993e1d59Smrg
117993e1d59Smrg   /**
1187ec681f3Smrg    * Offset within ParameterValues where this parameter is stored.
1197ec681f3Smrg    */
1207ec681f3Smrg   unsigned ValueOffset;
1217ec681f3Smrg
1227ec681f3Smrg   /**
1237ec681f3Smrg    * Index of this parameter's uniform storage.
1247ec681f3Smrg    */
1257ec681f3Smrg   uint32_t UniformStorageIndex;
1267ec681f3Smrg
1277ec681f3Smrg   /**
1287ec681f3Smrg    * Index of the first uniform storage that is associated with the same
1297ec681f3Smrg    * variable as this parameter.
130993e1d59Smrg    */
1317ec681f3Smrg   uint32_t MainUniformStorageIndex;
1323464ebd5Sriastradh};
1333464ebd5Sriastradh
1343464ebd5Sriastradh
1353464ebd5Sriastradh/**
1363464ebd5Sriastradh * List of gl_program_parameter instances.
1373464ebd5Sriastradh */
1383464ebd5Sriastradhstruct gl_program_parameter_list
1393464ebd5Sriastradh{
1407ec681f3Smrg   unsigned Size;           /**< allocated size of Parameters */
1417ec681f3Smrg   unsigned SizeValues;     /**< alllocate size of ParameterValues */
14201e04c3fSmrg   GLuint NumParameters;  /**< number of used parameters in array */
14301e04c3fSmrg   unsigned NumParameterValues;  /**< number of used parameter values array */
1443464ebd5Sriastradh   struct gl_program_parameter *Parameters; /**< Array [Size] */
14501e04c3fSmrg   gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */
1463464ebd5Sriastradh   GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
1473464ebd5Sriastradh                               might invalidate ParameterValues[] */
1487ec681f3Smrg   bool DisallowRealloc;
1497ec681f3Smrg
1507ec681f3Smrg   /* Parameters are optionally sorted as follows. Uniforms and constants
1517ec681f3Smrg    * are first, then state vars. This should be true in all cases except
1527ec681f3Smrg    * ir_to_mesa, which adds constants at the end, and ARB_vp with ARL,
1537ec681f3Smrg    * which can't sort parameters.
1547ec681f3Smrg    */
1557ec681f3Smrg   int UniformBytes;
1567ec681f3Smrg   int FirstStateVarIndex;
1577ec681f3Smrg   int LastStateVarIndex;
1583464ebd5Sriastradh};
1593464ebd5Sriastradh
1603464ebd5Sriastradh
1613464ebd5Sriastradhextern struct gl_program_parameter_list *
1623464ebd5Sriastradh_mesa_new_parameter_list(void);
1633464ebd5Sriastradh
1643464ebd5Sriastradhextern struct gl_program_parameter_list *
1653464ebd5Sriastradh_mesa_new_parameter_list_sized(unsigned size);
1663464ebd5Sriastradh
1673464ebd5Sriastradhextern void
1683464ebd5Sriastradh_mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
1693464ebd5Sriastradh
17001e04c3fSmrgextern void
17101e04c3fSmrg_mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
1727ec681f3Smrg                                unsigned reserve_params,
1737ec681f3Smrg                                unsigned reserve_values);
1747ec681f3Smrg
1757ec681f3Smrgextern void
1767ec681f3Smrg_mesa_disallow_parameter_storage_realloc(struct gl_program_parameter_list *paramList);
1773464ebd5Sriastradh
1783464ebd5Sriastradhextern GLint
1793464ebd5Sriastradh_mesa_add_parameter(struct gl_program_parameter_list *paramList,
1803464ebd5Sriastradh                    gl_register_file type, const char *name,
181af69d88dSmrg                    GLuint size, GLenum datatype,
182af69d88dSmrg                    const gl_constant_value *values,
18301e04c3fSmrg                    const gl_state_index16 state[STATE_LENGTH],
18401e04c3fSmrg                    bool pad_and_align);
1853464ebd5Sriastradh
1863464ebd5Sriastradhextern GLint
187af69d88dSmrg_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
1887ec681f3Smrg                           const gl_constant_value *values, GLuint size,
189af69d88dSmrg                           GLenum datatype, GLuint *swizzleOut);
1903464ebd5Sriastradh
19101e04c3fSmrgstatic inline GLint
192af69d88dSmrg_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
1937ec681f3Smrg                           const gl_constant_value *values, GLuint size,
19401e04c3fSmrg                           GLuint *swizzleOut)
19501e04c3fSmrg{
19601e04c3fSmrg   return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
19701e04c3fSmrg                                           swizzleOut);
19801e04c3fSmrg}
19901e04c3fSmrg
20001e04c3fSmrgextern GLint
20101e04c3fSmrg_mesa_add_sized_state_reference(struct gl_program_parameter_list *paramList,
20201e04c3fSmrg                                const gl_state_index16 stateTokens[STATE_LENGTH],
20301e04c3fSmrg                                const unsigned size, bool pad_and_align);
2043464ebd5Sriastradh
2053464ebd5Sriastradhextern GLint
2063464ebd5Sriastradh_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
2077ec681f3Smrg                          const gl_state_index16 stateTokens[STATE_LENGTH]);
2083464ebd5Sriastradh
2093464ebd5Sriastradh
21001e04c3fSmrgstatic inline GLint
2113464ebd5Sriastradh_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
21201e04c3fSmrg                             const char *name)
21301e04c3fSmrg{
21401e04c3fSmrg   if (!paramList)
21501e04c3fSmrg      return -1;
21601e04c3fSmrg
21701e04c3fSmrg   /* name must be null-terminated */
21801e04c3fSmrg   for (GLint i = 0; i < (GLint) paramList->NumParameters; i++) {
21901e04c3fSmrg      if (paramList->Parameters[i].Name &&
22001e04c3fSmrg         strcmp(paramList->Parameters[i].Name, name) == 0)
22101e04c3fSmrg         return i;
22201e04c3fSmrg   }
2233464ebd5Sriastradh
22401e04c3fSmrg   return -1;
22501e04c3fSmrg}
2263464ebd5Sriastradh
227b9abf16eSmayastatic inline bool
228b9abf16eSmaya_mesa_gl_datatype_is_64bit(GLenum datatype)
229b9abf16eSmaya{
230b9abf16eSmaya   switch (datatype) {
231b9abf16eSmaya   case GL_DOUBLE:
232b9abf16eSmaya   case GL_DOUBLE_VEC2:
233b9abf16eSmaya   case GL_DOUBLE_VEC3:
234b9abf16eSmaya   case GL_DOUBLE_VEC4:
235b9abf16eSmaya   case GL_DOUBLE_MAT2:
236b9abf16eSmaya   case GL_DOUBLE_MAT2x3:
237b9abf16eSmaya   case GL_DOUBLE_MAT2x4:
238b9abf16eSmaya   case GL_DOUBLE_MAT3:
239b9abf16eSmaya   case GL_DOUBLE_MAT3x2:
240b9abf16eSmaya   case GL_DOUBLE_MAT3x4:
241b9abf16eSmaya   case GL_DOUBLE_MAT4:
242b9abf16eSmaya   case GL_DOUBLE_MAT4x2:
243b9abf16eSmaya   case GL_DOUBLE_MAT4x3:
244b9abf16eSmaya   case GL_INT64_ARB:
245b9abf16eSmaya   case GL_INT64_VEC2_ARB:
246b9abf16eSmaya   case GL_INT64_VEC3_ARB:
247b9abf16eSmaya   case GL_INT64_VEC4_ARB:
248b9abf16eSmaya   case GL_UNSIGNED_INT64_ARB:
249b9abf16eSmaya   case GL_UNSIGNED_INT64_VEC2_ARB:
250b9abf16eSmaya   case GL_UNSIGNED_INT64_VEC3_ARB:
251b9abf16eSmaya   case GL_UNSIGNED_INT64_VEC4_ARB:
252b9abf16eSmaya      return true;
253b9abf16eSmaya   default:
254b9abf16eSmaya      return false;
255b9abf16eSmaya   }
256b9abf16eSmaya}
257b9abf16eSmaya
2587ec681f3Smrgvoid
2597ec681f3Smrg_mesa_recompute_parameter_bounds(struct gl_program_parameter_list *list);
2607ec681f3Smrg
261af69d88dSmrg#ifdef __cplusplus
262af69d88dSmrg}
263af69d88dSmrg#endif
2643464ebd5Sriastradh
2653464ebd5Sriastradh#endif /* PROG_PARAMETER_H */
266