mesa: Prefix main includes with dir to avoid conflicts.
[mesa.git] / src / mesa / state_tracker / st_mesa_to_tgsi.c
index 325aa2017347532b784f76fd1dea3be8bfd49c97..9029f12056f4fbc7ed9cdc06e38d1a664efb03c8 100644 (file)
 
 #include "pipe/p_compiler.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/tgsi/util/tgsi_parse.h"
-#include "pipe/tgsi/util/tgsi_build.h"
-#include "pipe/tgsi/util/tgsi_util.h"
+#include "tgsi/util/tgsi_parse.h"
+#include "tgsi/util/tgsi_build.h"
+#include "tgsi/util/tgsi_util.h"
 #include "st_mesa_to_tgsi.h"
 #include "shader/prog_instruction.h"
 #include "shader/prog_parameter.h"
 
-#define TGSI_DEBUG 0
-
 
 /*
  * Map mesa register file to TGSI register file.
@@ -56,8 +54,8 @@ map_register_file(
       return TGSI_FILE_NULL;
    case PROGRAM_TEMPORARY:
       return TGSI_FILE_TEMPORARY;
-   //case PROGRAM_LOCAL_PARAM:
-   //case PROGRAM_ENV_PARAM:
+   /*case PROGRAM_LOCAL_PARAM:*/
+   /*case PROGRAM_ENV_PARAM:*/
 
       /* Because of the longstanding problem with mesa arb shaders
        * where constants, immediates and state variables are all
@@ -68,8 +66,8 @@ map_register_file(
    case PROGRAM_STATE_VAR:
    case PROGRAM_NAMED_PARAM:
    case PROGRAM_UNIFORM:
-      if (immediateMapping[index] != ~0) 
-        return TGSI_FILE_IMMEDIATE;
+      if (immediateMapping && immediateMapping[index] != ~0)
+         return TGSI_FILE_IMMEDIATE;
       else
         return TGSI_FILE_CONSTANT;
    case PROGRAM_CONSTANT:
@@ -230,21 +228,27 @@ compile_instruction(
          outputMapping,
          immediateMapping);
 
-      for( j = 0; j < 4; j++ ) {
-         GLuint swz;
-
-         swz = GET_SWZ( inst->SrcReg[i].Swizzle, j );
-         if( swz > SWIZZLE_W ) {
-            tgsi_util_set_src_register_extswizzle(
-               &fullsrc->SrcRegisterExtSwz,
-               swz,
-               j );
+      /* swizzle (ext swizzle also depends on negation) */
+      {
+         GLuint swz[4];
+         GLboolean extended = (inst->SrcReg[i].NegateBase != NEGATE_NONE &&
+                               inst->SrcReg[i].NegateBase != NEGATE_XYZW);
+         for( j = 0; j < 4; j++ ) {
+            swz[j] = GET_SWZ( inst->SrcReg[i].Swizzle, j );
+            if (swz[j] > SWIZZLE_W)
+               extended = GL_TRUE;
+         }
+         if (extended) {
+            for (j = 0; j < 4; j++) {
+               tgsi_util_set_src_register_extswizzle(&fullsrc->SrcRegisterExtSwz,
+                                                     swz[j], j);
+            }
          }
          else {
-            tgsi_util_set_src_register_swizzle(
-               &fullsrc->SrcRegister,
-               swz,
-               j );
+            for (j = 0; j < 4; j++) {
+               tgsi_util_set_src_register_swizzle(&fullsrc->SrcRegister,
+                                                  swz[j], j);
+            }
          }
       }
 
@@ -513,10 +517,9 @@ compile_instruction(
    case OPCODE_TXP:
       /* texture lookup with divide by Q component */
       /* convert to TEX w/ special flag for division */
-      fullinst->Instruction.Opcode = TGSI_OPCODE_TEX;
+      fullinst->Instruction.Opcode = TGSI_OPCODE_TXP;
       fullinst->Instruction.NumSrcRegs = 2;
       fullinst->InstructionExtTexture.Texture = map_texture_target( inst->TexSrcTarget );
-      fullinst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide = TGSI_EXTSWIZZLE_W;
       fullinst->FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
       fullinst->FullSrcRegisters[1].SrcRegister.Index = inst->TexSrcUnit;
       break;
@@ -551,18 +554,16 @@ make_input_decl(
 
    decl = tgsi_default_full_declaration();
    decl.Declaration.File = TGSI_FILE_INPUT;
-   decl.Declaration.Declare = TGSI_DECLARE_RANGE;
    decl.Declaration.UsageMask = usage_mask;
    decl.Declaration.Semantic = semantic_info;
-   decl.u.DeclarationRange.First = index;
-   decl.u.DeclarationRange.Last = index;
+   decl.DeclarationRange.First = index;
+   decl.DeclarationRange.Last = index;
    if (semantic_info) {
       decl.Semantic.SemanticName = semantic_name;
       decl.Semantic.SemanticIndex = semantic_index;
    }
    if (interpolate_info) {
-      decl.Declaration.Interpolate = 1;
-      decl.Interpolation.Interpolate = interpolate;
+      decl.Declaration.Interpolate = interpolate;
    }
 
    return decl;
@@ -584,11 +585,10 @@ make_output_decl(
 
    decl = tgsi_default_full_declaration();
    decl.Declaration.File = TGSI_FILE_OUTPUT;
-   decl.Declaration.Declare = TGSI_DECLARE_RANGE;
    decl.Declaration.UsageMask = usage_mask;
    decl.Declaration.Semantic = 1;
-   decl.u.DeclarationRange.First = index;
-   decl.u.DeclarationRange.Last = index;
+   decl.DeclarationRange.First = index;
+   decl.DeclarationRange.Last = index;
    decl.Semantic.SemanticName = semantic_name;
    decl.Semantic.SemanticIndex = semantic_index;
 
@@ -604,9 +604,8 @@ make_temp_decl(
    struct tgsi_full_declaration decl;
    decl = tgsi_default_full_declaration();
    decl.Declaration.File = TGSI_FILE_TEMPORARY;
-   decl.Declaration.Declare = TGSI_DECLARE_RANGE;
-   decl.u.DeclarationRange.First = start_index;
-   decl.u.DeclarationRange.Last = end_index;
+   decl.DeclarationRange.First = start_index;
+   decl.DeclarationRange.Last = end_index;
    return decl;
 }
 
@@ -617,9 +616,8 @@ make_sampler_decl(GLuint index)
    struct tgsi_full_declaration decl;
    decl = tgsi_default_full_declaration();
    decl.Declaration.File = TGSI_FILE_SAMPLER;
-   decl.Declaration.Declare = TGSI_DECLARE_RANGE;
-   decl.u.DeclarationRange.First = index;
-   decl.u.DeclarationRange.Last = index;
+   decl.DeclarationRange.First = index;
+   decl.DeclarationRange.Last = index;
    return decl;
 }
 
@@ -630,9 +628,8 @@ make_constant_decl(GLuint first, GLuint last)
    struct tgsi_full_declaration decl;
    decl = tgsi_default_full_declaration();
    decl.Declaration.File = TGSI_FILE_CONSTANT;
-   decl.Declaration.Declare = TGSI_DECLARE_RANGE;
-   decl.u.DeclarationRange.First = first;
-   decl.u.DeclarationRange.Last = last;
+   decl.DeclarationRange.First = first;
+   decl.DeclarationRange.Last = last;
    return decl;
 }
 
@@ -683,8 +680,9 @@ find_temporaries(const struct gl_program *program,
  * \param tokens  array to store translated tokens in
  * \param maxTokens  size of the tokens array
  *
+ * \return number of tokens placed in 'tokens' buffer, or zero if error
  */
-GLboolean
+GLuint
 tgsi_translate_mesa_program(
    uint procType,
    const struct gl_program *program,
@@ -767,16 +765,19 @@ tgsi_translate_mesa_program(
          switch (outputSemanticName[i]) {
          case TGSI_SEMANTIC_POSITION:
             fulldecl = make_output_decl(i,
-                                        TGSI_SEMANTIC_POSITION, 0, /* Z / Depth */
+                                        TGSI_SEMANTIC_POSITION, /* Z / Depth */
+                                        outputSemanticIndex[i],
                                         TGSI_WRITEMASK_Z );
             break;
          case TGSI_SEMANTIC_COLOR:
             fulldecl = make_output_decl(i,
-                                        TGSI_SEMANTIC_COLOR, 0,
+                                        TGSI_SEMANTIC_COLOR,
+                                        outputSemanticIndex[i],
                                         TGSI_WRITEMASK_XYZW );
             break;
          default:
-            abort();
+            assert(0);
+            return 0;
          }
          ti += tgsi_build_full_declaration(&fulldecl,
                                            &tokens[ti],
@@ -803,7 +804,7 @@ tgsi_translate_mesa_program(
    {
       GLboolean tempsUsed[MAX_PROGRAM_TEMPS + 1];
       GLboolean inside_range = GL_FALSE;
-      GLuint start_range;
+      GLuint start_range = 0;
 
       find_temporaries(program, tempsUsed);
       tempsUsed[MAX_PROGRAM_TEMPS] = GL_FALSE;
@@ -833,8 +834,7 @@ tgsi_translate_mesa_program(
         i++) {
       if (program->Parameters->Parameters[i].Type == PROGRAM_CONSTANT) {
          struct tgsi_full_immediate fullimm
-            = make_immediate(program->Parameters->ParameterValues[i],
-                             program->Parameters->Parameters[i].Size);
+            = make_immediate(program->Parameters->ParameterValues[i], 4);
          ti += tgsi_build_full_immediate(&fullimm,
                                          &tokens[ti],
                                          header,
@@ -918,6 +918,6 @@ tgsi_translate_mesa_program(
          maxTokens - ti );
    }
 
-   return GL_TRUE;
+   return ti;
 }