mesa: fix double->float assignment warnings, int/uint comparison warnings
[mesa.git] / src / mesa / shader / slang / slang_codegen.c
index 2b7e781f98445c5c32fe82634bce205fd1e8113d..83098b7350eff67bd04c9bdb378567b8e8355246 100644 (file)
@@ -46,6 +46,7 @@
 #include "shader/prog_print.h"
 #include "shader/prog_statevars.h"
 #include "slang_typeinfo.h"
+#include "slang_builtin.h"
 #include "slang_codegen.h"
 #include "slang_compile.h"
 #include "slang_label.h"
@@ -342,109 +343,6 @@ slang_operation_identifier(slang_operation *oper,
 }
 
 
-#define SWIZZLE_ZWWW MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
-
-/**
- * Return the VERT_ATTRIB_* or FRAG_ATTRIB_* value that corresponds to
- * a vertex or fragment program input variable.  Return -1 if the input
- * name is invalid.
- * XXX return size too
- */
-static GLint
-_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
-{
-   struct input_info {
-      const char *Name;
-      GLuint Attrib;
-      GLuint Swizzle;
-   };
-   static const struct input_info vertInputs[] = {
-      { "gl_Vertex", VERT_ATTRIB_POS, SWIZZLE_NOOP },
-      { "gl_Normal", VERT_ATTRIB_NORMAL, SWIZZLE_NOOP },
-      { "gl_Color", VERT_ATTRIB_COLOR0, SWIZZLE_NOOP },
-      { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, SWIZZLE_NOOP },
-      { "gl_FogCoord", VERT_ATTRIB_FOG, SWIZZLE_XXXX },
-      { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, SWIZZLE_NOOP },
-      { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, SWIZZLE_NOOP },
-      { NULL, 0, SWIZZLE_NOOP }
-   };
-   static const struct input_info fragInputs[] = {
-      { "gl_FragCoord", FRAG_ATTRIB_WPOS, SWIZZLE_NOOP },
-      { "gl_Color", FRAG_ATTRIB_COL0, SWIZZLE_NOOP },
-      { "gl_SecondaryColor", FRAG_ATTRIB_COL1, SWIZZLE_NOOP },
-      { "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
-      /* note: we're packing several quantities into the fogcoord vector */
-      { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
-      { "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/
-      { "gl_PointCoord", FRAG_ATTRIB_FOGC, SWIZZLE_ZWWW },
-      { NULL, 0, SWIZZLE_NOOP }
-   };
-   GLuint i;
-   const struct input_info *inputs
-      = (target == GL_VERTEX_PROGRAM_ARB) ? vertInputs : fragInputs;
-
-   ASSERT(MAX_TEXTURE_COORD_UNITS == 8); /* if this fails, fix vertInputs above */
-
-   for (i = 0; inputs[i].Name; i++) {
-      if (strcmp(inputs[i].Name, name) == 0) {
-         /* found */
-         *swizzleOut = inputs[i].Swizzle;
-         return inputs[i].Attrib;
-      }
-   }
-   return -1;
-}
-
-
-/**
- * Return the VERT_RESULT_* or FRAG_RESULT_* value that corresponds to
- * a vertex or fragment program output variable.  Return -1 for an invalid
- * output name.
- */
-static GLint
-_slang_output_index(const char *name, GLenum target)
-{
-   struct output_info {
-      const char *Name;
-      GLuint Attrib;
-   };
-   static const struct output_info vertOutputs[] = {
-      { "gl_Position", VERT_RESULT_HPOS },
-      { "gl_FrontColor", VERT_RESULT_COL0 },
-      { "gl_BackColor", VERT_RESULT_BFC0 },
-      { "gl_FrontSecondaryColor", VERT_RESULT_COL1 },
-      { "gl_BackSecondaryColor", VERT_RESULT_BFC1 },
-      { "gl_TexCoord", VERT_RESULT_TEX0 },
-      { "gl_FogFragCoord", VERT_RESULT_FOGC },
-      { "gl_PointSize", VERT_RESULT_PSIZ },
-      { NULL, 0 }
-   };
-   static const struct output_info fragOutputs[] = {
-      { "gl_FragColor", FRAG_RESULT_COLOR },
-      { "gl_FragDepth", FRAG_RESULT_DEPTH },
-      { "gl_FragData", FRAG_RESULT_DATA0 },
-      { NULL, 0 }
-   };
-   GLuint i;
-   const struct output_info *outputs
-      = (target == GL_VERTEX_PROGRAM_ARB) ? vertOutputs : fragOutputs;
-
-   for (i = 0; outputs[i].Name; i++) {
-      if (strcmp(outputs[i].Name, name) == 0) {
-         /* found */
-         return outputs[i].Attrib;
-      }
-   }
-   return -1;
-}
-
-
 /**
  * Called when we begin code/IR generation for a new while/do/for loop.
  */
@@ -524,6 +422,7 @@ static slang_asm_info AsmInfo[] = {
    { "vec4_lrp", IR_LRP, 1, 3 },
    { "vec4_min", IR_MIN, 1, 2 },
    { "vec4_max", IR_MAX, 1, 2 },
+   { "vec4_cmp", IR_CMP, 1, 3 },
    { "vec4_clamp", IR_CLAMP, 1, 3 },
    { "vec4_seq", IR_SEQUAL, 1, 2 },
    { "vec4_sne", IR_SNEQUAL, 1, 2 },
@@ -1026,7 +925,7 @@ gen_return_with_expression(slang_assemble_ctx *A, slang_operation *oper)
       slang_operation_copy(rhs, &oper->children[0]);
    }
 
-   ///blockOper->locals->outer_scope = oper->locals->outer_scope;
+   /*blockOper->locals->outer_scope = oper->locals->outer_scope;*/
 
    /*slang_print_tree(blockOper, 0);*/
 
@@ -2877,7 +2776,7 @@ _slang_gen_while(slang_assemble_ctx * A, slang_operation *oper)
     *    body code (child[1])
     */
    slang_ir_node *loop, *breakIf, *body;
-   GLboolean isConst, constTrue;
+   GLboolean isConst, constTrue = GL_FALSE;
 
    if (!A->EmitContReturn) {
       /* We don't want to emit CONT instructions.  If this while-loop has
@@ -3297,7 +3196,7 @@ _slang_unroll_for_loop(slang_assemble_ctx * A, const slang_operation *oper)
          newOper = slang_operation_new(1);
          newOper->type = SLANG_OPER_LITERAL_INT;
          newOper->literal_size = 1;
-         newOper->literal[0] = iter;
+         newOper->literal[0] = (GLfloat) iter;
 
          /* replace instances of the loop variable with newOper */
          slang_substitute(A, body, 1, &oldVar, &newOper, GL_FALSE);
@@ -3864,6 +3763,14 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
 #endif
       }
 
+      if (var->type.qualifier == SLANG_QUAL_UNIFORM &&
+          !A->allow_uniform_initializers) {
+         slang_info_log_error(A->log,
+                              "initializer for uniform %s not allowed",
+                              varName);
+         return NULL;
+      }
+
       /* IR for the variable we're initializing */
       varRef = new_var(A, var);
       if (!varRef) {
@@ -4342,14 +4249,15 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
 
    if (oper->children[0].type == SLANG_OPER_IDENTIFIER) {
       /* Check that var is writeable */
+      const char *varName = (char *) oper->children[0].a_id;
       slang_variable *var
          = _slang_variable_locate(oper->children[0].locals,
                                   oper->children[0].a_id, GL_TRUE);
       if (!var) {
-         slang_info_log_error(A->log, "undefined variable '%s'",
-                              (char *) oper->children[0].a_id);
+         slang_info_log_error(A->log, "undefined variable '%s'", varName);
          return NULL;
       }
+
       if (var->type.qualifier == SLANG_QUAL_CONST ||
           var->type.qualifier == SLANG_QUAL_ATTRIBUTE ||
           var->type.qualifier == SLANG_QUAL_UNIFORM ||
@@ -4357,7 +4265,7 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
            A->program->Target == GL_FRAGMENT_PROGRAM_ARB)) {
          slang_info_log_error(A->log,
                               "illegal assignment to read-only variable '%s'",
-                              (char *) oper->children[0].a_id);
+                              varName);
          return NULL;
       }