summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/slang
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-12-15 16:44:55 -0700
committerBrian Paul <[email protected]>2009-01-06 09:12:52 -0700
commitbe620a66eb7b9b0512c31d9a026fa6f8a7ab05a6 (patch)
tree3811fc97196e2c0db41174d1f0ec13a1fa13398d /src/mesa/shader/slang
parentd0a39f3d65aeb04d750dfb0885e87da1185a9296 (diff)
mesa: checkpoint: handle uniform vars in _slang_gen_var_decl()
This allows uniform declarations with scalar/array initializers. The code is rough though, and will be cleaned up. (cherry picked from commit aa1b90463676ea71f24c1956dcf51deec1bf664c)
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c77
1 files changed, 59 insertions, 18 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 57d4d0e5a27..f3e56bb8609 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -2714,6 +2714,8 @@ static slang_ir_node *
_slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
slang_operation *initializer)
{
+ const char *varName = (const char *) var->a_name;
+ const GLenum datatype = _slang_gltype_from_specifier(&var->type.specifier);
slang_ir_node *varDecl, *n;
slang_ir_storage *store;
@@ -2733,29 +2735,24 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
assert(store == varDecl->Store);
- /* determine GPU storage file */
- /* XXX if the variable is const, use PROGRAM_CONSTANT */
+ /* determine GPU register file for simple cases */
if (is_sampler_type(&var->type)) {
store->File = PROGRAM_SAMPLER;
}
+ else if (var->type.qualifier == SLANG_QUAL_UNIFORM) {
+ store->File = PROGRAM_UNIFORM;
+ }
else {
store->File = PROGRAM_TEMPORARY;
}
store->Size = _slang_sizeof_type_specifier(&varDecl->Var->type.specifier);
-
if (store->Size <= 0) {
slang_info_log_error(A->log, "invalid declaration for '%s'",
(char*) var->a_name);
return NULL;
}
-#if 0
- printf("%s var %p %s store=%p index=%d size=%d\n",
- __FUNCTION__, (void *) var, (char *) var->a_name,
- (void *) store, store->Index, store->Size);
-#endif
-
if (var->type.array_len > 0) {
/* the type is an array, ex: float[4] x; */
GLint sz = (store->Size + 3) & ~3;
@@ -2775,7 +2772,6 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
/* if there's an initializer, generate IR for the expression */
if (initializer) {
- const char *varName = (const char *) var->a_name;
slang_ir_node *varRef, *init;
if (var->type.qualifier == SLANG_QUAL_CONST) {
@@ -2801,14 +2797,39 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
/* constant-folding, etc here */
_slang_simplify(initializer, &A->space, A->atoms);
- if ((var->type.qualifier == SLANG_QUAL_CONST ||
- var->type.qualifier == SLANG_QUAL_UNIFORM) &&
- initializer->type == SLANG_OPER_CALL &&
- initializer->array_constructor) {
- printf("Constant array initializer\n");
- make_constant_array(A, var, initializer);
- n = varRef;
- return n;
+ /* look for simple constant-valued variables and uniforms */
+ if (var->type.qualifier == SLANG_QUAL_CONST ||
+ var->type.qualifier == SLANG_QUAL_UNIFORM) {
+
+ if (initializer->type == SLANG_OPER_CALL &&
+ initializer->array_constructor) {
+ /* array initializer */
+ make_constant_array(A, var, initializer);
+ return varRef;
+ }
+ else if (initializer->type == SLANG_OPER_LITERAL_FLOAT ||
+ initializer->type == SLANG_OPER_LITERAL_INT) {
+ /* simple float/vector initializer */
+ if (store->File == PROGRAM_UNIFORM) {
+ store->Index = _mesa_add_uniform(A->program->Parameters,
+ varName,
+ store->Size, datatype,
+ initializer->literal);
+ /* XXX fix store->Swizzle here */
+ return varRef;
+ }
+#if 0
+ else {
+ store->File = PROGRAM_CONSTANT;
+ store->Index = _mesa_add_named_constant(A->program->Parameters,
+ varName,
+ initializer->literal,
+ store->Size);
+ /* XXX fix swizzle here */
+ return varRef;
+ }
+#endif
+ }
}
/* IR for initializer */
@@ -2831,6 +2852,19 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
n = varDecl;
}
+ if (store->File == PROGRAM_UNIFORM && store->Index < 0) {
+ /* */
+ store->Index = _mesa_add_uniform(A->program->Parameters, varName,
+ store->Size, datatype, NULL);
+ store->Swizzle = _slang_var_swizzle(store->Size, 0);
+ }
+
+#if 0
+ printf("%s var %p %s store=%p index=%d size=%d\n",
+ __FUNCTION__, (void *) var, (char *) varName,
+ (void *) store, store->Index, store->Size);
+#endif
+
return n;
}
@@ -4021,6 +4055,12 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
}
}
else {
+ /* non-struct uniform */
+#if 01
+ if (!_slang_gen_var_decl(A, var, var->initializer))
+ return GL_FALSE;
+ store = var->store;
+#else
GLint uniformLoc;
const GLfloat *initialValues = NULL;
#if 0
@@ -4049,6 +4089,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
totalSize, datatype, initialValues);
store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
totalSize, swizzle);
+#endif
}
}
else {