summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/slang/slang_simplify.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader/slang/slang_simplify.c')
-rw-r--r--src/mesa/shader/slang/slang_simplify.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c
index d45e71574c7..6ef95c48f91 100644
--- a/src/mesa/shader/slang/slang_simplify.c
+++ b/src/mesa/shader/slang/slang_simplify.c
@@ -27,6 +27,7 @@
* call casting.
*/
+
#include "main/imports.h"
#include "main/macros.h"
#include "main/get.h"
@@ -36,6 +37,15 @@
#include "slang_print.h"
+#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#endif
+#ifndef GL_MAX_VERTEX_UNIFORM_VECTORS
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#endif
+#ifndef GL_MAX_VARYING_VECTORS
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#endif
/**
@@ -62,6 +72,11 @@ _slang_lookup_constant(const char *name)
{ "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS },
{ "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS },
{ "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS },
+#if FEATURE_es2_glsl
+ { "gl_MaxVertexUniformVectors", GL_MAX_VERTEX_UNIFORM_VECTORS },
+ { "gl_MaxVaryingVectors", GL_MAX_VARYING_VECTORS },
+ { "gl_MaxFragmentUniformVectors", GL_MAX_FRAGMENT_UNIFORM_VECTORS },
+#endif
{ NULL, 0 }
};
GLuint i;
@@ -79,6 +94,15 @@ _slang_lookup_constant(const char *name)
}
+static slang_operation_type
+literal_type(slang_operation_type t1, slang_operation_type t2)
+{
+ if (t1 == SLANG_OPER_LITERAL_FLOAT || t2 == SLANG_OPER_LITERAL_FLOAT)
+ return SLANG_OPER_LITERAL_FLOAT;
+ else
+ return SLANG_OPER_LITERAL_INT;
+}
+
/**
* Recursively traverse an AST tree, applying simplifications wherever
@@ -99,6 +123,7 @@ _slang_simplify(slang_operation *oper,
if (oper->type == SLANG_OPER_IDENTIFIER) {
/* see if it's a named constant */
GLint value = _slang_lookup_constant((char *) oper->a_id);
+ /*printf("value[%s] = %d\n", (char*) oper->a_id, value);*/
if (value >= 0) {
oper->literal[0] =
oper->literal[1] =
@@ -107,6 +132,29 @@ _slang_simplify(slang_operation *oper,
oper->type = SLANG_OPER_LITERAL_INT;
return;
}
+ /* look for user-defined constant */
+ {
+ slang_variable *var;
+ var = _slang_locate_variable(oper->locals, oper->a_id, GL_TRUE);
+ if (var) {
+ if (var->type.qualifier == SLANG_QUAL_CONST &&
+ var->initializer &&
+ (var->initializer->type == SLANG_OPER_LITERAL_INT ||
+ var->initializer->type == SLANG_OPER_LITERAL_FLOAT)) {
+ oper->literal[0] = var->initializer->literal[0];
+ oper->literal[1] = var->initializer->literal[1];
+ oper->literal[2] = var->initializer->literal[2];
+ oper->literal[3] = var->initializer->literal[3];
+ oper->literal_size = var->initializer->literal_size;
+ oper->type = var->initializer->type;
+ /*
+ printf("value[%s] = %f\n",
+ (char*) oper->a_id, oper->literal[0]);
+ */
+ return;
+ }
+ }
+ }
}
/* first, simplify children */
@@ -131,8 +179,9 @@ _slang_simplify(slang_operation *oper,
= oper->children[0].literal[i] + oper->children[1].literal[i];
}
oper->literal_size = oper->children[0].literal_size;
- slang_operation_destruct(oper);
- oper->type = SLANG_OPER_LITERAL_FLOAT;
+ oper->type = literal_type(oper->children[0].type,
+ oper->children[1].type);
+ slang_operation_destruct(oper); /* frees unused children */
return;
case SLANG_OPER_SUBTRACT:
for (i = 0; i < 4; i++) {
@@ -140,8 +189,9 @@ _slang_simplify(slang_operation *oper,
= oper->children[0].literal[i] - oper->children[1].literal[i];
}
oper->literal_size = oper->children[0].literal_size;
+ oper->type = literal_type(oper->children[0].type,
+ oper->children[1].type);
slang_operation_destruct(oper);
- oper->type = SLANG_OPER_LITERAL_FLOAT;
return;
case SLANG_OPER_MULTIPLY:
for (i = 0; i < 4; i++) {
@@ -149,8 +199,9 @@ _slang_simplify(slang_operation *oper,
= oper->children[0].literal[i] * oper->children[1].literal[i];
}
oper->literal_size = oper->children[0].literal_size;
+ oper->type = literal_type(oper->children[0].type,
+ oper->children[1].type);
slang_operation_destruct(oper);
- oper->type = SLANG_OPER_LITERAL_FLOAT;
return;
case SLANG_OPER_DIVIDE:
for (i = 0; i < 4; i++) {
@@ -158,8 +209,9 @@ _slang_simplify(slang_operation *oper,
= oper->children[0].literal[i] / oper->children[1].literal[i];
}
oper->literal_size = oper->children[0].literal_size;
+ oper->type = literal_type(oper->children[0].type,
+ oper->children[1].type);
slang_operation_destruct(oper);
- oper->type = SLANG_OPER_LITERAL_FLOAT;
return;
default:
; /* nothing */