Generate DCLs for temporaries.
authorBrian <brian.paul@tungstengraphics.com>
Tue, 9 Oct 2007 22:28:01 +0000 (16:28 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 9 Oct 2007 22:28:01 +0000 (16:28 -0600)
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c

index 66b8db0..750314f 100644 (file)
@@ -498,6 +498,54 @@ make_output_decl(
 }\r
 \r
 \r
+static struct tgsi_full_declaration\r
+make_temp_decl(GLuint index)\r
+{\r
+   struct tgsi_full_declaration decl;\r
+   decl = tgsi_default_full_declaration();\r
+   decl.Declaration.File = TGSI_FILE_TEMPORARY;\r
+   decl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
+   decl.u.DeclarationRange.First = index;\r
+   decl.u.DeclarationRange.Last = index;\r
+   return decl;\r
+}\r
+\r
+\r
+/**\r
+ * Find the temporaries which are used in the given program.\r
+ * Put the indices of the temporaries in 'tempsUsed'.\r
+ * \return number of temporaries used\r
+ */\r
+static GLuint\r
+find_temporaries(const struct gl_program *program,\r
+                 GLuint tempsUsed[MAX_PROGRAM_TEMPS])\r
+{\r
+   GLuint i, j, count;\r
+\r
+   for (i = 0; i < MAX_PROGRAM_TEMPS; i++)\r
+      tempsUsed[i] = GL_FALSE;\r
+\r
+   for (i = 0; i < program->NumInstructions; i++) {\r
+      const struct prog_instruction *inst = program->Instructions + i;\r
+      const GLuint n = _mesa_num_inst_src_regs( inst->Opcode );\r
+      for (j = 0; j < n; j++) {\r
+         if (inst->SrcReg[j].File == PROGRAM_TEMPORARY)\r
+            tempsUsed[inst->SrcReg[j].Index] = GL_TRUE;\r
+         if (inst->DstReg.File == PROGRAM_TEMPORARY)\r
+            tempsUsed[inst->DstReg.Index] = GL_TRUE;\r
+      }\r
+   }\r
+\r
+   /* convert flags to list of indices */\r
+   count = 0;\r
+   for (i = 0; i < MAX_PROGRAM_TEMPS; i++) {\r
+      if (tempsUsed[i])\r
+         tempsUsed[count++] = i;\r
+   }\r
+   return count;\r
+}\r
+\r
+\r
 /**\r
  * Convert Mesa fragment program to TGSI format.\r
  * \param inputMapping  maps Mesa fragment program inputs to TGSI generic\r
@@ -527,7 +575,6 @@ tgsi_mesa_compile_fp_program(
    GLuint ti;  /* token index */\r
    struct tgsi_header *header;\r
    struct tgsi_processor *processor;\r
-   struct tgsi_full_declaration fulldecl;\r
    struct tgsi_full_instruction fullinst;\r
    GLuint preamble_size = 0;\r
 \r
@@ -542,6 +589,7 @@ tgsi_mesa_compile_fp_program(
    ti = 3;\r
 \r
    for (i = 0; i < numInputs; i++) {\r
+      struct tgsi_full_declaration fulldecl;\r
       switch (inputSemanticName[i]) {\r
       case TGSI_SEMANTIC_POSITION:\r
          /* Fragment XY pos */\r
@@ -584,6 +632,7 @@ tgsi_mesa_compile_fp_program(
     * Declare output attributes.\r
     */\r
    for (i = 0; i < numOutputs; i++) {\r
+      struct tgsi_full_declaration fulldecl;\r
       switch (outputSemanticName[i]) {\r
       case TGSI_SEMANTIC_POSITION:\r
          fulldecl = make_output_decl(i,\r
@@ -610,6 +659,20 @@ tgsi_mesa_compile_fp_program(
       }\r
    }\r
 \r
+   {\r
+      GLuint tempsUsed[MAX_PROGRAM_TEMPS];\r
+      uint numTemps = find_temporaries(&program->Base, tempsUsed);\r
+      for (i = 0; i < numTemps; i++) {\r
+         struct tgsi_full_declaration fulldecl;\r
+         fulldecl = make_temp_decl(tempsUsed[i]);\r
+         ti += tgsi_build_full_declaration(\r
+                                           &fulldecl,\r
+                                           &tokens[ti],\r
+                                           header,\r
+                                           maxTokens - ti );\r
+      }\r
+   }\r
+\r
    /*\r
     * Copy fragment z if the shader does not write it.\r
     */\r
@@ -714,6 +777,19 @@ tgsi_mesa_compile_vp_program(
                                         maxTokens - ti );\r
    }\r
 \r
+   {\r
+      GLuint tempsUsed[MAX_PROGRAM_TEMPS];\r
+      uint numTemps = find_temporaries(&program->Base, tempsUsed);\r
+      for (i = 0; i < numTemps; i++) {\r
+         struct tgsi_full_declaration fulldecl;\r
+         fulldecl = make_temp_decl(tempsUsed[i]);\r
+         ti += tgsi_build_full_declaration(\r
+                                           &fulldecl,\r
+                                           &tokens[ti],\r
+                                           header,\r
+                                           maxTokens - ti );\r
+      }\r
+   }\r
 \r
    for( i = 0; i < program->Base.NumInstructions; i++ ) {\r
       compile_instruction(\r