aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/shader
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-02-20 14:03:43 -0700
committerBrian <[email protected]>2007-02-20 14:03:43 -0700
commit243c2dd7469fb3e6af7206b1a6e60bfe6134fb71 (patch)
tree4437bd0367aec4a11bd2c45f15732d4c0266e261 /src/mesa/shader
parent48d65aabbc1e679fbf56fb7c4f7d4d702d43501a (diff)
implement support for pre-defined uniform structs (state vars)
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/slang/slang_builtin.c232
-rw-r--r--src/mesa/shader/slang/slang_builtin.h45
-rw-r--r--src/mesa/shader/slang/slang_codegen.c80
-rw-r--r--src/mesa/shader/slang/slang_emit.c34
4 files changed, 327 insertions, 64 deletions
diff --git a/src/mesa/shader/slang/slang_builtin.c b/src/mesa/shader/slang/slang_builtin.c
new file mode 100644
index 00000000000..a92efa875b6
--- /dev/null
+++ b/src/mesa/shader/slang/slang_builtin.c
@@ -0,0 +1,232 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.3
+ *
+ * Copyright (C) 2005-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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file slang_builtin.c
+ * Resolve built-in uniform vars.
+ * \author Brian Paul
+ */
+
+#include "imports.h"
+#include "macros.h"
+#include "slang_builtin.h"
+#include "slang_typeinfo.h"
+#include "slang_codegen.h"
+#include "slang_compile.h"
+#include "slang_ir.h"
+#include "mtypes.h"
+#include "program.h"
+#include "prog_instruction.h"
+#include "prog_parameter.h"
+#include "prog_statevars.h"
+#include "slang_print.h"
+
+
+
+/**
+ * XXX we might consider moving much of this into the prog_statevars.c file
+ */
+
+
+/**
+ * Determine if 'name' is a state variable (pre-defined uniform).
+ * If so, create a new program parameter for it, and return the
+ * param's index.
+ *
+ * \param swizzleOut returns the swizzle needed to access 'float' values
+ * \return the state value's position in the parameter list, or -1 if error
+ */
+GLint
+_slang_lookup_statevar(const char *name, GLint index,
+ struct gl_program_parameter_list *paramList,
+ GLuint *swizzleOut)
+{
+ struct state_info {
+ const char *Name;
+ const GLuint NumRows; /** for matrices */
+ const GLuint Swizzle;
+ const GLint Indexes[STATE_LENGTH];
+ };
+ static const struct state_info state[] = {
+ { "gl_ModelViewMatrix", 4, SWIZZLE_NOOP,
+ { STATE_MATRIX, STATE_MODELVIEW, 0, 0, 0, 0 } },
+ { "gl_NormalMatrix", 3, SWIZZLE_NOOP,
+ { STATE_MATRIX, STATE_MODELVIEW, 0, 0, 0, 0 } },
+ { "gl_ProjectionMatrix", 4, SWIZZLE_NOOP,
+ { STATE_MATRIX, STATE_PROJECTION, 0, 0, 0, 0 } },
+ { "gl_ModelViewProjectionMatrix", 4, SWIZZLE_NOOP,
+ { STATE_MATRIX, STATE_MVP, 0, 0, 0, 0 } },
+ { "gl_TextureMatrix", 4, SWIZZLE_NOOP,
+ { STATE_MATRIX, STATE_TEXTURE, 0, 0, 0, 0 } },
+ { "gl_NormalScale", 1, SWIZZLE_NOOP,
+ { STATE_INTERNAL, STATE_NORMAL_SCALE, 0, 0, 0, 0} },
+
+ /* For aggregate/structs we need entries for both the base name
+ * and base.field.
+ */
+ { "gl_DepthRange", 1, SWIZZLE_NOOP,
+ { STATE_DEPTH_RANGE, 0, 0, 0, 0, 0 } },
+ { "gl_DepthRange.near", 1, SWIZZLE_XXXX,
+ { STATE_DEPTH_RANGE, 0, 0, 0, 0, 0 } },
+ { "gl_DepthRange.far", 1, SWIZZLE_YYYY,
+ { STATE_DEPTH_RANGE, 0, 0, 0, 0, 0 } },
+ { "gl_DepthRange.diff", 1, SWIZZLE_ZZZZ,
+ { STATE_DEPTH_RANGE, 0, 0, 0, 0, 0 } },
+
+ { "gl_Point", 1, SWIZZLE_NOOP,
+ { STATE_POINT_SIZE, 0, 0, 0, 0, 0 } },
+ { "gl_Point.size", 1, SWIZZLE_XXXX,
+ { STATE_POINT_SIZE, 0, 0, 0, 0, 0 } },
+ { "gl_Point.sizeMin", 1, SWIZZLE_YYYY,
+ { STATE_POINT_SIZE, 0, 0, 0, 0, 0 } },
+ { "gl_Point.sizeMax", 1, SWIZZLE_ZZZZ,
+ { STATE_POINT_SIZE, 0, 0, 0, 0, 0 } },
+ { "gl_Point.fadeThresholdSize", 1, SWIZZLE_WWWW,
+ { STATE_POINT_SIZE, 0, 0, 0, 0, 0 } },
+ { "gl_Point.distanceConstantAttenuation", 1, SWIZZLE_XXXX,
+ { STATE_POINT_ATTENUATION, 0, 0, 0, 0, 0 } },
+ { "gl_Point.distanceLinearAttenuation", 1, SWIZZLE_YYYY,
+ { STATE_POINT_ATTENUATION, 0, 0, 0, 0, 0 } },
+ { "gl_Point.distanceQuadraticAttenuation", 1, SWIZZLE_ZZZZ,
+ { STATE_POINT_ATTENUATION, 0, 0, 0, 0, 0 } },
+
+ { "gl_FrontMaterial", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 0, STATE_EMISSION, 0, 0, 0 } },
+ { "gl_FrontMaterial.emission", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 0, STATE_EMISSION, 0, 0, 0 } },
+ { "gl_FrontMaterial.ambient", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 0, STATE_AMBIENT, 0, 0, 0 } },
+ { "gl_FrontMaterial.diffuse", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 0, STATE_DIFFUSE, 0, 0, 0 } },
+ { "gl_FrontMaterial.specular", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 0, STATE_SPECULAR, 0, 0, 0 } },
+ { "gl_FrontMaterial.shininess", 1, SWIZZLE_XXXX,
+ { STATE_MATERIAL, 0, STATE_SHININESS, 0, 0, 0 } },
+
+ { "gl_BackMaterial", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 1, STATE_EMISSION, 0, 0, 0 } },
+ { "gl_BackMaterial.emission", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 1, STATE_EMISSION, 0, 0, 0 } },
+ { "gl_BackMaterial.ambient", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 1, STATE_AMBIENT, 0, 0, 0 } },
+ { "gl_BackMaterial.diffuse", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 1, STATE_DIFFUSE, 0, 0, 0 } },
+ { "gl_BackMaterial.specular", 1, SWIZZLE_NOOP,
+ { STATE_MATERIAL, 1, STATE_SPECULAR, 0, 0, 0 } },
+ { "gl_BackMaterial.shininess", 1, SWIZZLE_XXXX,
+ { STATE_MATERIAL, 1, STATE_SHININESS, 0, 0, 0 } },
+
+ { "gl_LightModel", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_AMBIENT, 0, 0, 0, 0, 0 } },
+ { "gl_LightModel.ambient", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_AMBIENT, 0, 0, 0, 0, 0 } },
+
+ { "gl_FrontLightModelProduct", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_SCENECOLOR, 0, 0, 0, 0, 0 } },
+ { "gl_FrontLightModelProduct.sceneColor", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_SCENECOLOR, 0, 0, 0, 0, 0 } },
+
+ { "gl_BackLightModelProduct", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_SCENECOLOR, 1, 0, 0, 0, 0 } },
+ { "gl_BackLightModelProduct.sceneColor", 1, SWIZZLE_NOOP,
+ { STATE_LIGHTMODEL_SCENECOLOR, 1, 0, 0, 0, 0 } },
+
+ { "gl_Fog", 1, SWIZZLE_NOOP,
+ { STATE_FOG_COLOR, 0, 0, 0, 0, 0 } },
+ { "gl_Fog.color", 1, SWIZZLE_NOOP,
+ { STATE_FOG_COLOR, 0, 0, 0, 0, 0 } },
+ { "gl_Fog.density", 1, SWIZZLE_XXXX,
+ { STATE_FOG_PARAMS, 0, 0, 0, 0, 0 } },
+ { "gl_Fog.start", 1, SWIZZLE_YYYY,
+ { STATE_FOG_PARAMS, 0, 0, 0, 0, 0 } },
+ { "gl_Fog.end", 1, SWIZZLE_ZZZZ,
+ { STATE_FOG_PARAMS, 0, 0, 0, 0, 0 } },
+ { "gl_Fog.scale", 1, SWIZZLE_WWWW,
+ { STATE_FOG_PARAMS, 0, 0, 0, 0, 0 } },
+
+
+ { NULL, 0, 0, {0, 0, 0, 0, 0, 0} }
+ };
+ GLuint i;
+
+ for (i = 0; state[i].Name; i++) {
+ if (strcmp(state[i].Name, name) == 0) {
+ /* found */
+ *swizzleOut = state[i].Swizzle;
+ if (paramList) {
+ if (state[i].NumRows > 1) {
+ /* a matrix */
+ GLuint j;
+ GLint pos[4], indexesCopy[STATE_LENGTH];
+ /* make copy of state tokens */
+ for (j = 0; j < STATE_LENGTH; j++)
+ indexesCopy[j] = state[i].Indexes[j];
+ /* load rows */
+ for (j = 0; j < state[i].NumRows; j++) {
+ indexesCopy[3] = indexesCopy[4] = j; /* jth row of matrix */
+ pos[j] = _mesa_add_state_reference(paramList, indexesCopy);
+ assert(pos[j] >= 0);
+ }
+ return pos[0];
+ }
+ else {
+ /* non-matrix state */
+ GLint pos
+ = _mesa_add_state_reference(paramList, state[i].Indexes);
+ assert(pos >= 0);
+ return pos;
+ }
+ }
+ }
+ }
+ return -1;
+}
+
+
+GLint
+_slang_lookup_statevar_field(const char *base, const char *field,
+ struct gl_program_parameter_list *paramList,
+ GLuint *swizzleOut)
+{
+ GLint pos = -1;
+ const GLint len = _mesa_strlen(base)
+ + _mesa_strlen(field) + 2;
+ char *name = (char *) _mesa_malloc(len);
+
+ if (!name)
+ return -1;
+
+ _mesa_strcpy(name, base);
+ /*_mesa_*/strcat(name, ".");
+ /*_mesa_*/strcat(name, field);
+ printf("FULL NAME: %s\n", name);
+
+ pos = _slang_lookup_statevar(name, 0, paramList, swizzleOut);
+
+ _mesa_free(name);
+
+ return pos;
+}
+
+
diff --git a/src/mesa/shader/slang/slang_builtin.h b/src/mesa/shader/slang/slang_builtin.h
new file mode 100644
index 00000000000..a521e73eb93
--- /dev/null
+++ b/src/mesa/shader/slang/slang_builtin.h
@@ -0,0 +1,45 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5.3
+ *
+ * Copyright (C) 2005-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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef SLANG_BUILTIN_H
+#define SLANG_BUILTIN_H
+
+#include "prog_parameter.h"
+#include "slang_utility.h"
+
+
+extern GLint
+_slang_lookup_statevar(const char *name, GLint index,
+ struct gl_program_parameter_list *paramList,
+ GLuint *swizzleOut);
+
+
+extern GLint
+_slang_lookup_statevar_field(const char *base, const char *field,
+ struct gl_program_parameter_list *paramList,
+ GLuint *swizzleOut);
+
+
+#endif /* SLANG_BUILTIN_H */
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index a36a2d7bc94..4088720fdbc 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -31,6 +31,7 @@
#include "imports.h"
#include "macros.h"
#include "slang_typeinfo.h"
+#include "slang_builtin.h"
#include "slang_codegen.h"
#include "slang_compile.h"
#include "slang_storage.h"
@@ -76,68 +77,6 @@ slang_lookup_constant(const char *name,
}
-/**
- * Determine if 'name' is a state variable. If so, create a new program
- * parameter for it, and return the param's index. Else, return -1.
- */
-static GLint
-slang_lookup_statevar(const char *name, GLint index,
- struct gl_program_parameter_list *paramList)
-{
- struct state_info {
- const char *Name;
- const GLuint NumRows; /** for matrices */
- const GLuint Swizzle;
- const GLint Indexes[STATE_LENGTH];
- };
- static const struct state_info state[] = {
- { "gl_ModelViewMatrix", 4, SWIZZLE_NOOP,
- { STATE_MATRIX, STATE_MODELVIEW, 0, 0, 0, 0 } },
- { "gl_NormalMatrix", 3, SWIZZLE_NOOP,
- { STATE_MATRIX, STATE_MODELVIEW, 0, 0, 0, 0 } },
- { "gl_ProjectionMatrix", 4, SWIZZLE_NOOP,
- { STATE_MATRIX, STATE_PROJECTION, 0, 0, 0, 0 } },
- { "gl_ModelViewProjectionMatrix", 4, SWIZZLE_NOOP,
- { STATE_MATRIX, STATE_MVP, 0, 0, 0, 0 } },
- { "gl_TextureMatrix", 4, SWIZZLE_NOOP,
- { STATE_MATRIX, STATE_TEXTURE, 0, 0, 0, 0 } },
- { NULL, 0, 0, {0, 0, 0, 0, 0, 0} }
- };
- GLuint i;
-
- for (i = 0; state[i].Name; i++) {
- if (strcmp(state[i].Name, name) == 0) {
- /* found */
- if (paramList) {
- if (state[i].NumRows > 1) {
- /* a matrix */
- GLuint j;
- GLint pos[4], indexesCopy[STATE_LENGTH];
- /* make copy of state tokens */
- for (j = 0; j < STATE_LENGTH; j++)
- indexesCopy[j] = state[i].Indexes[j];
- /* load rows */
- for (j = 0; j < state[i].NumRows; j++) {
- indexesCopy[3] = indexesCopy[4] = j; /* jth row of matrix */
- pos[j] = _mesa_add_state_reference(paramList, indexesCopy);
- assert(pos[j] >= 0);
- }
- return pos[0];
- }
- else {
- /* non-matrix state */
- GLint pos
- = _mesa_add_state_reference(paramList, state[i].Indexes);
- assert(pos >= 0);
- return pos;
- }
- }
- }
- }
- return -1;
-}
-
-
static GLboolean
is_sampler_type(const slang_fully_specified_type *t)
{
@@ -270,7 +209,8 @@ slang_allocate_storage(slang_assemble_ctx *A, slang_ir_node *n)
* used to avoid wasting registers.
*/
if (n->Store->File == PROGRAM_STATE_VAR) {
- GLint i = slang_lookup_statevar(varName, 0, prog->Parameters);
+ GLint i = _slang_lookup_statevar(varName, 0, prog->Parameters,
+ &n->Store->Swizzle);
assert(i >= 0);
n->Store->Index = i;
}
@@ -2241,8 +2181,20 @@ _slang_gen_field(slang_assemble_ctx * A, slang_operation *oper)
/* the field is a structure member (base.field) */
/* oper->children[0] is the base */
/* oper->a_id is the field name */
+ slang_ir_node *base, *n;
+
+ base = _slang_gen_operation(A, &oper->children[0]);
+
+ n = new_node1(IR_FIELD, base);
+ if (n) {
+ n->Target = (char *) oper->a_id;
+ }
+ return n;
+
+#if 0
_mesa_problem(NULL, "glsl structs/fields not supported yet");
return NULL;
+#endif
}
}
@@ -2644,7 +2596,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
GLboolean success = GL_TRUE;
GLint texIndex;
slang_ir_storage *store = NULL;
- int dbg = 0;
+ int dbg = 1;
texIndex = sampler_to_texture_index(var->type.specifier.type);
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 955f428b95b..67cf9c32d4a 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -35,6 +35,7 @@
#include "prog_instruction.h"
#include "prog_parameter.h"
#include "prog_print.h"
+#include "slang_builtin.h"
#include "slang_emit.h"
#include "slang_error.h"
@@ -1307,6 +1308,36 @@ emit_swizzle(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
}
+/**
+ * Resolve storage for accessing a structure field.
+ */
+static struct prog_instruction *
+emit_field(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
+{
+ /* field of a struct */
+ if (n->Children[0]->Store->File == PROGRAM_STATE_VAR) {
+ /* state variable sub-field */
+ GLint pos;
+ GLuint swizzle;
+ pos = _slang_lookup_statevar_field((char *) n->Children[0]->Var->a_name,
+ n->Target,
+ prog->Parameters, &swizzle);
+ if (pos < 0) {
+ RETURN_ERROR2("Undefined structure member", n->Target, 0);
+ }
+
+ n->Store = _slang_new_ir_storage(PROGRAM_STATE_VAR, pos, 4);/*XXX size*/
+ if (n->Store)
+ n->Store->Swizzle = swizzle;
+ }
+
+ /*
+ _mesa_problem(NULL, "glsl structs/fields not supported yet");
+ */
+ return NULL;
+}
+
+
static struct prog_instruction *
emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
{
@@ -1391,6 +1422,9 @@ emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog)
}
return NULL; /* no instruction */
+ case IR_FIELD:
+ return emit_field(vt, n, prog);
+
case IR_SWIZZLE:
return emit_swizzle(vt, n, prog);