Merge tgsi_mesa_compile_fp_program() and tgsi_mesa_compile_vp_program() into tgsi_tra...
authorBrian <brian.paul@tungstengraphics.com>
Wed, 10 Oct 2007 15:44:54 +0000 (09:44 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 10 Oct 2007 15:44:54 +0000 (09:44 -0600)
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h
src/mesa/state_tracker/st_program.c

index 1bf3be40dd64dc3ae19eb4a171374e0c6d6f91c8..8975b4fd57225ffa96546e7c270ca79a50b2c9c4 100644 (file)
@@ -39,10 +39,10 @@ map_register_file(
 /**\r
  * Map mesa register file index to TGSI index.\r
  * Take special care when processing input and output indices.\r
- * \param processor  either TGSI_PROCESSOR_FRAGMENT or  TGSI_PROCESSOR_VERTEX\r
  * \param file  one of TGSI_FILE_x\r
  * \param index  the mesa register file index\r
- * \param usage_bitmask  ???\r
+ * \param inputMapping  maps Mesa input indexes to TGSI input indexes\r
+ * \param outputMapping  maps Mesa output indexes to TGSI output indexes\r
  */\r
 static GLuint\r
 map_register_file_index(\r
@@ -443,6 +443,9 @@ compile_instruction(
    }\r
 }\r
 \r
+/**\r
+ * \param usage_mask  bitfield of TGSI_WRITEMASK_{XYZW} tokens\r
+ */\r
 static struct tgsi_full_declaration\r
 make_input_decl(\r
    GLuint index,\r
@@ -450,7 +453,7 @@ make_input_decl(
    GLuint usage_mask,\r
    GLboolean semantic_info,\r
    GLuint semantic_name,\r
-   GLuint semantic_index )\r
+   GLbitfield semantic_index )\r
 {\r
    struct tgsi_full_declaration decl;\r
 \r
@@ -473,12 +476,15 @@ make_input_decl(
    return decl;\r
 }\r
 \r
+/**\r
+ * \param usage_mask  bitfield of TGSI_WRITEMASK_{XYZW} tokens\r
+ */\r
 static struct tgsi_full_declaration\r
 make_output_decl(\r
    GLuint index,\r
    GLuint semantic_name,\r
    GLuint semantic_index,\r
-   GLuint usage_mask )\r
+   GLbitfield usage_mask )\r
 {\r
    struct tgsi_full_declaration decl;\r
 \r
@@ -567,10 +573,9 @@ find_temporaries(const struct gl_program *program,
  * \param maxTokens  size of the tokens array\r
  *\r
  */\r
-#if 0\r
-static GLboolean\r
-tgsi_translate_program(\r
-                       uint procType,\r
+GLboolean\r
+tgsi_translate_mesa_program(\r
+   uint procType,\r
    const struct gl_program *program,\r
    GLuint numInputs,\r
    const GLuint inputMapping[],\r
@@ -736,271 +741,4 @@ tgsi_translate_program(
 \r
    return GL_TRUE;\r
 }\r
-#endif\r
-\r
-\r
-\r
-/**\r
- * Convert Mesa fragment program to TGSI format.\r
- * \param inputMapping  maps Mesa fragment program inputs to TGSI generic\r
- *                      input indexes\r
- * \param inputSemantic  the TGSI_SEMANTIC flag for each input\r
- * \param interpMode  the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input\r
- * \param outputMapping  maps Mesa fragment program outputs to TGSI\r
- *                       generic outputs\r
- *\r
- */\r
-GLboolean\r
-tgsi_mesa_compile_fp_program(\r
-   const struct gl_fragment_program *program,\r
-   GLuint numInputs,\r
-   const GLuint inputMapping[],\r
-   const ubyte inputSemanticName[],\r
-   const ubyte inputSemanticIndex[],\r
-   const GLuint interpMode[],\r
-   GLuint numOutputs,\r
-   const GLuint outputMapping[],\r
-   const ubyte outputSemanticName[],\r
-   const ubyte outputSemanticIndex[],\r
-   struct tgsi_token *tokens,\r
-   GLuint maxTokens )\r
-{\r
-   GLuint i;\r
-   GLuint ti;  /* token index */\r
-   struct tgsi_header *header;\r
-   struct tgsi_processor *processor;\r
-   struct tgsi_full_instruction fullinst;\r
-   GLuint preamble_size = 0;\r
-\r
-   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();\r
-\r
-   header = (struct tgsi_header *) &tokens[1];\r
-   *header = tgsi_build_header();\r
-\r
-   processor = (struct tgsi_processor *) &tokens[2];\r
-   *processor = tgsi_build_processor( TGSI_PROCESSOR_FRAGMENT, header );\r
-\r
-   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
-         fulldecl = make_input_decl(i,\r
-                                    TGSI_INTERPOLATE_CONSTANT,\r
-                                    TGSI_WRITEMASK_XY,\r
-                                    GL_TRUE, TGSI_SEMANTIC_POSITION, 0 );\r
-         ti += tgsi_build_full_declaration(\r
-                                           &fulldecl,\r
-                                           &tokens[ti],\r
-                                           header,\r
-                                           maxTokens - ti );\r
-         /* Fragment ZW pos */\r
-         fulldecl = make_input_decl(i,\r
-                                    TGSI_INTERPOLATE_LINEAR,\r
-                                    TGSI_WRITEMASK_ZW,\r
-                                    GL_TRUE, TGSI_SEMANTIC_POSITION, 0 );\r
-         ti += tgsi_build_full_declaration(\r
-                                           &fulldecl,\r
-                                           &tokens[ti],\r
-                                           header,\r
-                                           maxTokens - ti );\r
-         break;\r
-      default:\r
-         fulldecl = make_input_decl(i,\r
-                                    interpMode[i],\r
-                                    TGSI_WRITEMASK_XYZW,\r
-                                    GL_TRUE, inputSemanticName[i],\r
-                                    inputSemanticIndex[i]);\r
-         ti += tgsi_build_full_declaration(&fulldecl,\r
-                                           &tokens[ti],\r
-                                           header,\r
-                                           maxTokens - ti );\r
-         break;\r
-      }\r
-   }\r
-\r
-\r
-   /*\r
-    * 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
-                                     TGSI_SEMANTIC_POSITION, 0, /* Z / Depth */\r
-                                     TGSI_WRITEMASK_Z );\r
-         ti += tgsi_build_full_declaration(\r
-                                           &fulldecl,\r
-                                           &tokens[ti],\r
-                                           header,\r
-                                           maxTokens - ti );\r
-         break;\r
-      case TGSI_SEMANTIC_COLOR:\r
-         fulldecl = make_output_decl(i,\r
-                                     TGSI_SEMANTIC_COLOR, 0,\r
-                                     TGSI_WRITEMASK_XYZW );\r
-         ti += tgsi_build_full_declaration(\r
-                                           &fulldecl,\r
-                                           &tokens[ti],\r
-                                           header,\r
-                                           maxTokens - ti );\r
-         break;\r
-      default:\r
-         abort();\r
-      }\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
-#if 0\r
-   if( !(program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) ) {\r
-      fullinst = tgsi_default_full_instruction();\r
-\r
-      fullinst.Instruction.Opcode = TGSI_OPCODE_MOV;\r
-      fullinst.Instruction.NumDstRegs = 1;\r
-      fullinst.Instruction.NumSrcRegs = 1;\r
-\r
-      fulldst = &fullinst.FullDstRegisters[0];\r
-      fulldst->DstRegister.File = TGSI_FILE_OUTPUT;\r
-      fulldst->DstRegister.Index = 0;\r
-      fulldst->DstRegister.WriteMask = TGSI_WRITEMASK_Z;\r
-\r
-      fullsrc = &fullinst.FullSrcRegisters[0];\r
-      fullsrc->SrcRegister.File = TGSI_FILE_INPUT;\r
-      fullsrc->SrcRegister.Index = 0;\r
-\r
-      ti += tgsi_build_full_instruction(\r
-         &fullinst,\r
-         &tokens[ti],\r
-         header,\r
-         maxTokens - ti );\r
-      preamble_size++;\r
-   }\r
-#endif\r
-\r
-   for( i = 0; i < program->Base.NumInstructions; i++ ) {\r
-      compile_instruction(\r
-            &program->Base.Instructions[i],\r
-            &fullinst,\r
-            inputMapping,\r
-            outputMapping,\r
-            preamble_size,\r
-            TGSI_PROCESSOR_FRAGMENT );\r
-\r
-      ti += tgsi_build_full_instruction(\r
-         &fullinst,\r
-         &tokens[ti],\r
-         header,\r
-         maxTokens - ti );\r
-   }\r
-\r
-   return GL_TRUE;\r
-}\r
-\r
-GLboolean\r
-tgsi_mesa_compile_vp_program(\r
-   const struct gl_vertex_program *program,\r
-   GLuint numInputs,\r
-   const GLuint inputMapping[],\r
-   const ubyte inputSemanticName[],\r
-   const ubyte inputSemanticIndex[],\r
-   GLuint numOutputs,\r
-   const GLuint outputMapping[],\r
-   const ubyte outputSemanticName[],\r
-   const ubyte outputSemanticIndex[],\r
-   struct tgsi_token *tokens,\r
-   GLuint maxTokens)\r
-{\r
-   GLuint i, ti;\r
-   struct tgsi_header *header;\r
-   struct tgsi_processor *processor;\r
-   struct tgsi_full_instruction fullinst;\r
-\r
-   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();\r
-\r
-   header = (struct tgsi_header *) &tokens[1];\r
-   *header = tgsi_build_header();\r
-\r
-   processor = (struct tgsi_processor *) &tokens[2];\r
-   *processor = tgsi_build_processor( TGSI_PROCESSOR_VERTEX, header );\r
-\r
-   ti = 3;\r
-\r
-   /* input decls */\r
-   for (i = 0; i < numInputs; i++) {\r
-      struct tgsi_full_declaration fulldecl;\r
-      fulldecl = make_input_decl(i,\r
-                                 TGSI_INTERPOLATE_ATTRIB,\r
-                                 TGSI_WRITEMASK_XYZW,\r
-                                 GL_FALSE, inputSemanticName[i],\r
-                                 inputSemanticIndex[i]);\r
-      ti += tgsi_build_full_declaration(&fulldecl,\r
-                                        &tokens[ti],\r
-                                        header,\r
-                                        maxTokens - ti );\r
-   }\r
-\r
-   /* output decls */\r
-   for (i = 0; i < numOutputs; i++) {\r
-      struct tgsi_full_declaration fulldecl;\r
-      fulldecl = make_output_decl(i,\r
-                                  outputSemanticName[i],\r
-                                  outputSemanticIndex[i],\r
-                                  TGSI_WRITEMASK_XYZW );\r
-      ti += tgsi_build_full_declaration(&fulldecl,\r
-                                        &tokens[ti],\r
-                                        header,\r
-                                        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
-            &program->Base.Instructions[i],\r
-            &fullinst,\r
-            inputMapping,\r
-            outputMapping,\r
-            0,\r
-            TGSI_PROCESSOR_VERTEX );\r
-\r
-      ti += tgsi_build_full_instruction(\r
-         &fullinst,\r
-         &tokens[ti],\r
-         header,\r
-         maxTokens - ti );\r
-   }\r
-\r
-   return GL_TRUE;\r
-}\r
 \r
index 29e8053369022910abdf6fa7f31e2dfa64ffe7c6..13372d75fd318c9e5864d3394f695e5d9fa1c14a 100644 (file)
@@ -8,8 +8,9 @@ extern "C" {
 struct tgsi_token;\r
 \r
 GLboolean\r
-tgsi_mesa_compile_fp_program(\r
-   const struct gl_fragment_program *program,\r
+tgsi_translate_mesa_program(\r
+   uint procType,\r
+   const struct gl_program *program,\r
    GLuint numInputs,\r
    const GLuint inputMapping[],\r
    const ubyte inputSemanticName[],\r
@@ -22,20 +23,6 @@ tgsi_mesa_compile_fp_program(
    struct tgsi_token *tokens,\r
    GLuint maxTokens );\r
 \r
-GLboolean\r
-tgsi_mesa_compile_vp_program(\r
-   const struct gl_vertex_program *program,\r
-   GLuint numInputs,\r
-   const GLuint inputMapping[],\r
-   const ubyte inputSemanticName[],\r
-   const ubyte inputSemanticIndex[],\r
-   GLuint numOutputs,\r
-   const GLuint outputMapping[],\r
-   const ubyte outputSemanticName[],\r
-   const ubyte outputSemanticIndex[],\r
-   struct tgsi_token *tokens,\r
-   GLuint maxTokens );\r
-\r
 \r
 #if defined __cplusplus\r
 } // extern "C"\r
index 1c5af7b75faa82fd536a616ac906855ca799fc76..5b6fa70dff4f0eb35471106361b262d8e76f74b3 100644 (file)
@@ -233,19 +233,21 @@ st_translate_vertex_program(struct st_context *st,
 
    /* XXX: fix static allocation of tokens:
     */
-   tgsi_mesa_compile_vp_program( &stvp->Base,
-                                 /* inputs */
-                                 vs.num_inputs,
-                                 stvp->input_to_index,
-                                 vs.input_semantic_name,
-                                 vs.input_semantic_index,
-                                 /* outputs */
-                                 vs.num_outputs,
-                                 outputMapping,
-                                 vs.output_semantic_name,
+   tgsi_translate_mesa_program( TGSI_PROCESSOR_VERTEX,
+                                &stvp->Base.Base,
+                                /* inputs */
+                                vs.num_inputs,
+                                stvp->input_to_index,
+                                vs.input_semantic_name,
+                                vs.input_semantic_index,
+                                NULL,
+                                /* outputs */
+                                vs.num_outputs,
+                                outputMapping,
+                                vs.output_semantic_name,
                                  vs.output_semantic_index,
-                                 /* tokenized result */
-                                 tokensOut, maxTokens);
+                                /* tokenized result */
+                                tokensOut, maxTokens);
 
    vs.tokens = tokensOut;
    cso = st_cached_vs_state(st, &vs);
@@ -386,21 +388,21 @@ st_translate_fragment_program(struct st_context *st,
 
    /* XXX: fix static allocation of tokens:
     */
-   tgsi_mesa_compile_fp_program( &stfp->Base,
-                                 /* inputs */
-                                 fs.num_inputs,
-                                 inputMapping,
-                                 fs.input_semantic_name,
-                                 fs.input_semantic_index,
-                                 interpMode,
-                                 /* outputs */
-                                 fs.num_outputs,
-                                 outputMapping,
-                                 fs.output_semantic_name,
-                                 fs.output_semantic_index,
-                                 /* tokenized result */
-                                 tokensOut, maxTokens);
-
+   tgsi_translate_mesa_program( TGSI_PROCESSOR_FRAGMENT,
+                                &stfp->Base.Base,
+                                /* inputs */
+                                fs.num_inputs,
+                                inputMapping,
+                                fs.input_semantic_name,
+                                fs.input_semantic_index,
+                                interpMode,
+                                /* outputs */
+                                fs.num_outputs,
+                                outputMapping,
+                                fs.output_semantic_name,
+                                fs.output_semantic_index,
+                                /* tokenized result */
+                                tokensOut, maxTokens);
 
    fs.tokens = tokensOut;