diff options
author | Brian <[email protected]> | 2007-02-02 12:01:29 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-02-02 12:01:29 -0700 |
commit | 70570d41996a3754be973ffdc34cd3ae4267878d (patch) | |
tree | 309e8ba0bf5525f31a81f627be7cc4dc2be3521e /src | |
parent | 5c2174778360bd493573951d378e29f7097abf5b (diff) |
Move guts of slang_lookup_constant() into a new function in slang_simplify.c
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 44 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_simplify.c | 58 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_simplify.h | 5 |
3 files changed, 73 insertions, 34 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index e384022cea8..5ce3e465784 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -29,7 +29,6 @@ */ #include "imports.h" -#include "get.h" #include "macros.h" #include "slang_assemble.h" #include "slang_codegen.h" @@ -61,41 +60,17 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper); * \return position of the constant in the paramList. */ static GLint -slang_lookup_constant(const char *name, GLint index, +slang_lookup_constant(const char *name, struct gl_program_parameter_list *paramList, GLuint *swizzleOut) { - struct constant_info { - const char *Name; - const GLenum Token; - }; - static const struct constant_info info[] = { - { "gl_MaxLights", GL_MAX_LIGHTS }, - { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES }, - { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS }, - { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS }, - { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS }, - { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS }, - { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS }, - { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS }, - { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS }, - { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS }, - { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS }, - { NULL, 0 } - }; - GLuint i; - - for (i = 0; info[i].Name; i++) { - if (strcmp(info[i].Name, name) == 0) { - /* found */ - GLfloat value = -1.0; - GLint pos; - _mesa_GetFloatv(info[i].Token, &value); - ASSERT(value >= 0.0); /* sanity check that glGetFloatv worked */ - /* XXX named constant! */ - pos = _mesa_add_unnamed_constant(paramList, &value, 1, swizzleOut); - return pos; - } + GLint value = _slang_lookup_constant(name); + if (value >= 0) { + /* XXX named constant! */ + GLfloat fvalue = (GLfloat) value; + GLint pos; + pos = _mesa_add_unnamed_constant(paramList, &fvalue, 1, swizzleOut); + return pos; } return -1; } @@ -300,7 +275,8 @@ slang_allocate_storage(slang_assemble_ctx *A, slang_ir_node *n) n->Store->Index = i; } else if (n->Store->File == PROGRAM_CONSTANT) { - GLint i = slang_lookup_constant(varName, 0, prog->Parameters, + /* XXX compile-time constants should be converted to literals */ + GLint i = slang_lookup_constant(varName, prog->Parameters, &n->Store->Swizzle); assert(i >= 0); assert(n->Store->Size == 1); diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c index c71313a7bb8..19e627489fd 100644 --- a/src/mesa/shader/slang/slang_simplify.c +++ b/src/mesa/shader/slang/slang_simplify.c @@ -30,12 +30,57 @@ #include "imports.h" #include "macros.h" +#include "get.h" #include "slang_compile.h" #include "slang_codegen.h" #include "slang_simplify.h" #include "slang_print.h" + + +/** + * Lookup the value of named constant, such as gl_MaxLights. + * \return value of constant, or -1 if unknown + */ +GLint +_slang_lookup_constant(const char *name) +{ + struct constant_info { + const char *Name; + const GLenum Token; + }; + static const struct constant_info info[] = { + { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES }, + { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS }, + { "gl_MaxDrawBuffers", GL_MAX_DRAW_BUFFERS }, + { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS }, + { "gl_MaxLights", GL_MAX_LIGHTS }, + { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS }, + { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS }, + { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS }, + { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS }, + { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS }, + { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS }, + { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS }, + { NULL, 0 } + }; + GLuint i; + + for (i = 0; info[i].Name; i++) { + if (strcmp(info[i].Name, name) == 0) { + /* found */ + GLint value = -1.0; + _mesa_GetIntegerv(info[i].Token, &value); + ASSERT(value >= 0); /* sanity check that glGetFloatv worked */ + return value; + } + } + return -1; +} + + + /** * Recursively traverse an AST tree, applying simplifications wherever * possible. @@ -52,6 +97,19 @@ _slang_simplify(slang_operation *oper, GLboolean isBool[4]; GLuint i, n; + if (oper->type == slang_oper_identifier) { + /* see if it's a named constant */ + GLint value = _slang_lookup_constant((char *) oper->a_id); + if (value >= 0) { + oper->literal[0] = + oper->literal[1] = + oper->literal[2] = + oper->literal[3] = value; + oper->type = slang_oper_literal_int; + return; + } + } + /* first, simplify children */ for (i = 0; i < oper->num_children; i++) { _slang_simplify(&oper->children[i], space, atoms); diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h index 5ff7292f0fb..b29740eaca6 100644 --- a/src/mesa/shader/slang/slang_simplify.h +++ b/src/mesa/shader/slang/slang_simplify.h @@ -2,6 +2,11 @@ #ifndef SLANG_SIMPLIFY_H #define SLANG_SIMPLIFY_H + +extern GLint +_slang_lookup_constant(const char *name); + + extern void _slang_simplify(slang_operation *oper, const slang_assembly_name_space * space, |