summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-01-09 19:17:17 -0700
committerBrian <[email protected]>2007-01-09 19:17:17 -0700
commitb7978af6936d186112727cb9858fe7740eef1a7c (patch)
tree3d0f266040ef09a8fbc52c27d37019d2abf0cf49 /src/mesa/shader
parentcc858bfa84d6a3525b1409db62f89bfd86c6948c (diff)
clean up a bunch of program parameter stuff
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/arbprogparse.c6
-rw-r--r--src/mesa/shader/prog_parameter.c77
-rw-r--r--src/mesa/shader/prog_parameter.h16
-rw-r--r--src/mesa/shader/prog_statevars.c6
-rw-r--r--src/mesa/shader/prog_statevars.h11
-rw-r--r--src/mesa/shader/shader_api.c6
-rw-r--r--src/mesa/shader/slang/slang_codegen.c11
-rw-r--r--src/mesa/shader/slang/slang_link2.c3
8 files changed, 85 insertions, 51 deletions
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index 2f74a5dc58e..991378f6d49 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.1
+ * Version: 6.5.3
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -1719,7 +1719,7 @@ parse_param_elements (GLcontext * ctx, const GLubyte ** inst,
{
GLint idx;
GLuint err = 0;
- GLint state_tokens[6];
+ GLint state_tokens[STATE_LENGTH];
GLfloat const_values[4];
switch (*(*inst)++) {
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index e543871ab79..8945f2d854c 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.2
+ * Version: 6.5.3
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -71,16 +71,18 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
* store all the values (in blocks of 4).
*
* \param paramList the list to add the parameter to
+ * \param type type of parameter, such as
* \param name the parameter name, will be duplicated/copied!
- * \param values initial parameter value, up to 4 GLfloats
* \param size number of elements in 'values' vector (1..4, or more)
- * \param type type of parameter, such as
+ * \param values initial parameter value, up to 4 GLfloats, or NULL
+ * \param state state indexes, or NULL
* \return index of new parameter in the list, or -1 if error (out of mem)
*/
GLint
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat *values, GLuint size,
- enum register_file type)
+ enum register_file type, const char *name,
+ GLuint size, const GLfloat *values,
+ const gl_state_index state[STATE_LENGTH])
{
const GLuint oldNum = paramList->NumParameters;
const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
@@ -131,6 +133,12 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
}
size -= 4;
}
+
+ if (state) {
+ for (i = 0; i < STATE_LENGTH; i++)
+ paramList->Parameters[oldNum].StateIndexes[i] = state[i];
+ }
+
return (GLint) oldNum;
}
}
@@ -144,7 +152,9 @@ GLint
_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
const char *name, const GLfloat values[4])
{
- return _mesa_add_parameter(paramList, name, values, 4, PROGRAM_NAMED_PARAM);
+ return _mesa_add_parameter(paramList, PROGRAM_NAMED_PARAM, name,
+ 4, values, NULL);
+
}
@@ -173,7 +183,9 @@ _mesa_add_named_constant(struct gl_program_parameter_list *paramList,
}
#endif
size = 4; /** XXX fix */
- return _mesa_add_parameter(paramList, name, values, size, PROGRAM_CONSTANT);
+ return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, name,
+ size, values, NULL);
+
}
@@ -202,7 +214,9 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
size, &pos, &swizzle)) {
return pos;
}
- return _mesa_add_parameter(paramList, NULL, values, size, PROGRAM_CONSTANT);
+ return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
+ size, values, NULL);
+
}
@@ -216,7 +230,9 @@ _mesa_add_uniform(struct gl_program_parameter_list *paramList,
return i;
}
else {
- i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_UNIFORM);
+ i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
+ size, NULL, NULL);
+
return i;
}
}
@@ -233,7 +249,8 @@ _mesa_add_sampler(struct gl_program_parameter_list *paramList,
}
else {
const GLint size = 1;
- i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_SAMPLER);
+ i = _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name,
+ size, NULL, NULL);
return i;
}
}
@@ -253,7 +270,8 @@ _mesa_add_varying(struct gl_program_parameter_list *paramList,
}
else {
assert(size == 4);
- i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_VARYING);
+ i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name,
+ size, NULL, NULL);
return i;
}
}
@@ -261,25 +279,28 @@ _mesa_add_varying(struct gl_program_parameter_list *paramList,
/**
* Add parameter representing a vertex program attribute.
+ * \param size size of attribute (in floats), may be -1 if unknown
+ * \param attrib the attribute index, or -1 if unknown
*/
GLint
_mesa_add_attribute(struct gl_program_parameter_list *paramList,
- const char *name, GLint attrib)
+ const char *name, GLint size, GLint attrib)
{
- GLint size = 4; /* XXX ok? */
GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
if (i >= 0) {
/* replace */
ASSERT(paramList->Parameters[i].StateIndexes[0] == STATE_USER_ATTRIB);
+ if (attrib < 0)
+ attrib = i;
paramList->Parameters[i].StateIndexes[1] = attrib;
}
else {
/* add */
- i = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_INPUT);
- if (i >= 0) {
- paramList->Parameters[i].StateIndexes[0] = STATE_USER_ATTRIB;
- paramList->Parameters[i].StateIndexes[1] = attrib;
- }
+ gl_state_index state[STATE_LENGTH];
+ state[0] = STATE_USER_ATTRIB;
+ state[1] = attrib;
+ i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name,
+ size, NULL, state);
}
return i;
}
@@ -315,12 +336,12 @@ sizeof_state_reference(const GLint *stateTokens)
* PARAM ambient = state.material.front.ambient;
*
* \param paramList the parameter list
- * \param state an array of 6 state tokens
+ * \param state an array of 6 (STATE_LENGTH) state tokens
* \return index of the new parameter.
*/
GLint
_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
- const GLint *stateTokens)
+ const GLint stateTokens[STATE_LENGTH])
{
const GLuint size = 4; /* XXX fix */
const char *name;
@@ -337,17 +358,19 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
break;
}
}
- if (match == 6) {
+ if (match == STATE_LENGTH) {
/* this state reference is already in the parameter list */
return index;
}
}
name = _mesa_program_state_string(stateTokens);
- index = _mesa_add_parameter(paramList, name, NULL, size, PROGRAM_STATE_VAR);
+ index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name,
+ size, NULL, NULL);
+
if (index >= 0) {
GLuint i;
- for (i = 0; i < 6; i++) {
+ for (i = 0; i < STATE_LENGTH; i++) {
paramList->Parameters[index].StateIndexes[i]
= (gl_state_index) stateTokens[i];
}
@@ -487,14 +510,14 @@ _mesa_clone_parameter_list(const struct gl_program_parameter_list *list)
for (i = 0; i < list->NumParameters; i++) {
struct gl_program_parameter *p = list->Parameters + i;
GLuint size = MIN2(p->Size, 4);
- GLint j = _mesa_add_parameter(clone, p->Name, list->ParameterValues[i],
- size, p->Type);
+ GLint j = _mesa_add_parameter(clone, p->Type, p->Name,
+ size, list->ParameterValues[i], NULL);
ASSERT(j >= 0);
/* copy state indexes */
if (p->Type == PROGRAM_STATE_VAR) {
GLint k;
struct gl_program_parameter *q = clone->Parameters + j;
- for (k = 0; k < 6; k++) {
+ for (k = 0; k < STATE_LENGTH; k++) {
q->StateIndexes[k] = p->StateIndexes[k];
}
}
diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h
index ab4d7300188..bfae071be05 100644
--- a/src/mesa/shader/prog_parameter.h
+++ b/src/mesa/shader/prog_parameter.h
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.2
+ * Version: 6.5.3
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -32,6 +32,7 @@
#define PROG_PARAMETER_H
#include "mtypes.h"
+#include "prog_statevars.h"
/**
@@ -49,7 +50,7 @@ struct gl_program_parameter
/**
* A sequence of STATE_* tokens and integers to identify GL state.
*/
- GLuint StateIndexes[6];
+ GLuint StateIndexes[STATE_LENGTH];
};
@@ -78,8 +79,9 @@ _mesa_clone_parameter_list(const struct gl_program_parameter_list *list);
extern GLint
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat *values, GLuint size,
- enum register_file type);
+ enum register_file type, const char *name,
+ GLuint size, const GLfloat *values,
+ const gl_state_index state[STATE_LENGTH]);
extern GLint
_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
@@ -109,11 +111,11 @@ _mesa_add_varying(struct gl_program_parameter_list *paramList,
extern GLint
_mesa_add_attribute(struct gl_program_parameter_list *paramList,
- const char *name, GLint attrib);
+ const char *name, GLint size, GLint attrib);
extern GLint
_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
- const GLint *stateTokens);
+ const GLint stateTokens[STATE_LENGTH]);
extern GLfloat *
_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c
index 7377c7d8210..a0a00cfb95d 100644
--- a/src/mesa/shader/prog_statevars.c
+++ b/src/mesa/shader/prog_statevars.c
@@ -2,7 +2,7 @@
* Mesa 3-D graphics library
* Version: 6.5.3
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -418,7 +418,7 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
* some GL state has changed.
*/
GLbitfield
-_mesa_program_state_flags(const GLint state[])
+_mesa_program_state_flags(const GLint state[STATE_LENGTH])
{
switch (state[0]) {
case STATE_MATERIAL:
@@ -661,7 +661,7 @@ append_index(char *dst, GLint index)
* Use _mesa_free() to deallocate the string.
*/
const char *
-_mesa_program_state_string(const GLint state[6])
+_mesa_program_state_string(const GLint state[STATE_LENGTH])
{
char str[1000] = "";
char tmp[30];
diff --git a/src/mesa/shader/prog_statevars.h b/src/mesa/shader/prog_statevars.h
index da672c9ec88..47ef615f9bc 100644
--- a/src/mesa/shader/prog_statevars.h
+++ b/src/mesa/shader/prog_statevars.h
@@ -29,6 +29,13 @@
/**
+ * Number of STATE_* values we need to address any GL state.
+ * Used to dimension arrays.
+ */
+#define STATE_LENGTH 6
+
+
+/**
* Used for describing GL state referenced from inside ARB vertex and
* fragment programs.
* A string such as "state.light[0].ambient" gets translated into a
@@ -109,11 +116,11 @@ _mesa_load_state_parameters(GLcontext *ctx,
extern GLbitfield
-_mesa_program_state_flags(const GLint state[]);
+_mesa_program_state_flags(const GLint state[STATE_LENGTH]);
extern const char *
-_mesa_program_state_string(const GLint state[6]);
+_mesa_program_state_string(const GLint state[STATE_LENGTH]);
#endif /* PROG_STATEVARS_H */
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index d1b0e21b949..397ce916ea2 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -278,8 +278,8 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
{
struct gl_shader_program *shProg
= _mesa_lookup_shader_program(ctx, program);
- GLint i;
- GLint oldIndex;
+ const GLint size = -1; /* unknown size */
+ GLint i, oldIndex;
if (!shProg) {
_mesa_error(ctx, GL_INVALID_VALUE, "glBindAttribLocation(program)");
@@ -298,7 +298,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
oldIndex = _mesa_get_attrib_location(ctx, program, name);
/* this will replace the current value if it's already in the list */
- i = _mesa_add_attribute(shProg->Attributes, name, index);
+ i = _mesa_add_attribute(shProg->Attributes, name, size, index);
if (i < 0) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
}
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index cc70d1de2a2..91e117367e2 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -119,7 +119,7 @@ slang_lookup_statevar(const char *name, GLint index,
const char *Name;
const GLuint NumRows; /** for matrices */
const GLuint Swizzle;
- const GLint Indexes[6];
+ const GLint Indexes[STATE_LENGTH];
};
static const struct state_info state[] = {
{ "gl_ModelViewMatrix", 4, SWIZZLE_NOOP,
@@ -143,9 +143,9 @@ slang_lookup_statevar(const char *name, GLint index,
if (state[i].NumRows > 1) {
/* a matrix */
GLuint j;
- GLint pos[4], indexesCopy[6];
+ GLint pos[4], indexesCopy[STATE_LENGTH];
/* make copy of state tokens */
- for (j = 0; j < 6; j++)
+ for (j = 0; j < STATE_LENGTH; j++)
indexesCopy[j] = state[i].Indexes[j];
/* load rows */
for (j = 0; j < state[i].NumRows; j++) {
@@ -554,8 +554,9 @@ _slang_codegen_global_variable(slang_variable *var, struct gl_program *prog,
if (prog) {
/* user-defined vertex attribute */
const GLint size = _slang_sizeof_type_specifier(&var->type.specifier);
- GLint index = _mesa_add_parameter(prog->Attributes, varName,
- NULL, size, PROGRAM_INPUT);
+ const GLint attr = -1; /* unknown */
+ GLint index = _mesa_add_attribute(prog->Attributes, varName,
+ size, attr);
assert(index >= 0);
store = _slang_new_ir_storage(PROGRAM_INPUT,
VERT_ATTRIB_GENERIC0 + index, size);
diff --git a/src/mesa/shader/slang/slang_link2.c b/src/mesa/shader/slang/slang_link2.c
index 0965f3e4c4e..da5ba5c2927 100644
--- a/src/mesa/shader/slang/slang_link2.c
+++ b/src/mesa/shader/slang/slang_link2.c
@@ -323,6 +323,7 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
{
GLuint i, j;
GLbitfield usedAttributes;
+ GLint size = 4; /* XXX fix */
assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
@@ -369,7 +370,7 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
/* too many! XXX record error log */
return GL_FALSE;
}
- _mesa_add_attribute(shProg->Attributes, name, attr);
+ _mesa_add_attribute(shProg->Attributes, name, size, attr);
}
inst->SrcReg[j].Index = VERT_ATTRIB_GENERIC0 + attr;