/**\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
}\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
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
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
* \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
\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