#include "tgsi_platform.h"\r
#include "tgsi_mesa.h"\r
\r
-#define TGSI_DEBUG 0\r
+#define TGSI_DEBUG 1\r
\r
/*\r
* Map mesa register file to SBIR register file.\r
return GL_FALSE;\r
}\r
\r
+static struct tgsi_full_declaration\r
+make_declaration(\r
+ GLuint file,\r
+ GLuint first,\r
+ GLuint last,\r
+ GLboolean do_interpolate,\r
+ GLuint interpolate )\r
+{\r
+ struct tgsi_full_declaration decl;\r
+\r
+ decl = tgsi_default_full_declaration();\r
+ decl.Declaration.File = file;\r
+ decl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
+ decl.u.DeclarationRange.First = first;\r
+ decl.u.DeclarationRange.Last = last;\r
+\r
+ if( do_interpolate ) {\r
+ decl.Declaration.Interpolate = 1;\r
+ decl.Interpolation.Interpolate = interpolate;\r
+ }\r
+\r
+ return decl;\r
+}\r
+\r
GLboolean\r
tgsi_mesa_compile_fp_program(\r
const struct gl_fragment_program *program,\r
struct tgsi_token *tokens,\r
GLuint maxTokens )\r
{\r
- GLuint i, ti;\r
+ GLuint i, ti, count;\r
struct tgsi_header *header;\r
struct tgsi_full_declaration fulldecl;\r
struct tgsi_full_instruction fullinst;\r
ti = 2;\r
\r
/*\r
- * Input 0 is always read, at least implicitly by the instruction generated\r
- * above, so mark it as used.\r
+ * Input 0 is always read, at least implicitly by the MOV instruction generated\r
+ * below, so mark it as used.\r
*/\r
inputs_read = program->Base.InputsRead | 1;\r
\r
/*\r
- * Declare input attributes.\r
+ * Declare input attributes. Note that we do not interpolate fragment position.\r
*/\r
- fulldecl = tgsi_default_full_declaration();\r
-\r
- fulldecl.Declaration.File = TGSI_FILE_INPUT;\r
- fulldecl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
- fulldecl.Declaration.Interpolate = 1;\r
-\r
- /*\r
- * Do not interpolate fragment position.\r
- */\r
- fulldecl.u.DeclarationRange.First = 0;\r
- fulldecl.u.DeclarationRange.Last = 0;\r
-\r
- fulldecl.Interpolation.Interpolate = TGSI_INTERPOLATE_CONSTANT;\r
-\r
+ fulldecl = make_declaration(\r
+ TGSI_FILE_INPUT,\r
+ 0,\r
+ 0,\r
+ GL_TRUE,\r
+ TGSI_INTERPOLATE_CONSTANT );\r
ti += tgsi_build_full_declaration(\r
&fulldecl,\r
&tokens[ti],\r
header,\r
maxTokens - ti );\r
\r
- /*\r
- * Interpolate generic attributes.\r
- */\r
- fulldecl.u.DeclarationRange.First = 1;\r
- fulldecl.u.DeclarationRange.Last = 1;\r
+ count = 0;\r
for( i = 1; i < 32; i++ ) {\r
if( inputs_read & (1 << i) ) {\r
- fulldecl.u.DeclarationRange.Last++;\r
+ count++;\r
}\r
}\r
+ if( count > 0 ) {\r
+ fulldecl = make_declaration(\r
+ TGSI_FILE_INPUT,\r
+ 1,\r
+ count + 1,\r
+ GL_TRUE,\r
+ TGSI_INTERPOLATE_LINEAR );\r
+ ti += tgsi_build_full_declaration(\r
+ &fulldecl,\r
+ &tokens[ti],\r
+ header,\r
+ maxTokens - ti );\r
+ }\r
\r
- fulldecl.Interpolation.Interpolate = TGSI_INTERPOLATE_LINEAR;\r
-\r
+ /*\r
+ * Declare output attributes.\r
+ */\r
+ assert(\r
+ program->Base.OutputsWritten ==\r
+ (program->Base.OutputsWritten & ((1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR))) );\r
+\r
+ fulldecl = make_declaration(\r
+ TGSI_FILE_OUTPUT,\r
+ 0,\r
+ 0,\r
+ GL_FALSE,\r
+ 0 );\r
ti += tgsi_build_full_declaration(\r
&fulldecl,\r
&tokens[ti],\r
header,\r
maxTokens - ti );\r
\r
+ if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) {\r
+ fulldecl = make_declaration(\r
+ TGSI_FILE_OUTPUT,\r
+ 1,\r
+ 1,\r
+ GL_FALSE,\r
+ 0 );\r
+ ti += tgsi_build_full_declaration(\r
+ &fulldecl,\r
+ &tokens[ti],\r
+ header,\r
+ maxTokens - ti );\r
+ }\r
+\r
/*\r
* Copy input fragment xyz to output xyz.\r
* If the shader writes depth, do not copy the z component.\r