tgsi: fix regression in indexed const lookups
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_build.c
index 050b448fe7c2e329a8eb81b17fad1523cc161d6a..d272533d63c764b365317270cf983363f0aee398 100644 (file)
@@ -25,8 +25,7 @@
  * 
  **************************************************************************/
 
-#include "pipe/p_debug.h"
-#include "pipe/p_util.h"
+#include "util/u_debug.h"
 #include "pipe/p_shader_tokens.h"
 #include "tgsi_build.h"
 #include "tgsi_parse.h"
@@ -115,11 +114,13 @@ tgsi_default_declaration( void )
    struct tgsi_declaration declaration;
 
    declaration.Type = TGSI_TOKEN_TYPE_DECLARATION;
-   declaration.Size = 1;
+   declaration.NrTokens = 1;
    declaration.File = TGSI_FILE_NULL;
    declaration.UsageMask = TGSI_WRITEMASK_XYZW;
    declaration.Interpolate = TGSI_INTERPOLATE_CONSTANT;
    declaration.Semantic = 0;
+   declaration.Centroid = 0;
+   declaration.Invariant = 0;
    declaration.Padding = 0;
    declaration.Extended = 0;
 
@@ -132,18 +133,22 @@ tgsi_build_declaration(
    unsigned usage_mask,
    unsigned interpolate,
    unsigned semantic,
+   unsigned centroid,
+   unsigned invariant,
    struct tgsi_header *header )
 {
    struct tgsi_declaration declaration;
 
-   assert( file <= TGSI_FILE_IMMEDIATE );
-   assert( interpolate <= TGSI_INTERPOLATE_PERSPECTIVE );
+   assert( file < TGSI_FILE_COUNT );
+   assert( interpolate < TGSI_INTERPOLATE_COUNT );
 
    declaration = tgsi_default_declaration();
    declaration.File = file;
    declaration.UsageMask = usage_mask;
    declaration.Interpolate = interpolate;
    declaration.Semantic = semantic;
+   declaration.Centroid = centroid;
+   declaration.Invariant = invariant;
 
    header_bodysize_grow( header );
 
@@ -155,9 +160,9 @@ declaration_grow(
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
-   assert( declaration->Size < 0xFF );
+   assert( declaration->NrTokens < 0xFF );
 
-   declaration->Size++;
+   declaration->NrTokens++;
 
    header_bodysize_grow( header );
 }
@@ -195,6 +200,8 @@ tgsi_build_full_declaration(
       full_decl->Declaration.UsageMask,
       full_decl->Declaration.Interpolate,
       full_decl->Declaration.Semantic,
+      full_decl->Declaration.Centroid,
+      full_decl->Declaration.Invariant,
       header );
 
    if (maxsize <= size)
@@ -301,7 +308,7 @@ tgsi_default_immediate( void )
    struct tgsi_immediate immediate;
 
    immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
-   immediate.Size = 1;
+   immediate.NrTokens = 1;
    immediate.DataType = TGSI_IMM_FLOAT32;
    immediate.Padding = 0;
    immediate.Extended = 0;
@@ -338,9 +345,9 @@ immediate_grow(
    struct tgsi_immediate *immediate,
    struct tgsi_header *header )
 {
-   assert( immediate->Size < 0xFF );
+   assert( immediate->NrTokens < 0xFF );
 
-   immediate->Size++;
+   immediate->NrTokens++;
 
    header_bodysize_grow( header );
 }
@@ -377,7 +384,7 @@ tgsi_build_full_immediate(
 
    *immediate = tgsi_build_immediate( header );
 
-   for( i = 0; i < full_imm->Immediate.Size - 1; i++ ) {
+   for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) {
       struct tgsi_immediate_float32 *if32;
 
       if( maxsize <= size )
@@ -404,7 +411,7 @@ tgsi_default_instruction( void )
    struct tgsi_instruction instruction;
 
    instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
-   instruction.Size = 1;
+   instruction.NrTokens = 1;
    instruction.Opcode = TGSI_OPCODE_MOV;
    instruction.Saturate = TGSI_SAT_NONE;
    instruction.NumDstRegs = 1;
@@ -446,9 +453,9 @@ instruction_grow(
    struct tgsi_instruction *instruction,
    struct tgsi_header *header )
 {
-   assert (instruction->Size <   0xFF);
+   assert (instruction->NrTokens <   0xFF);
 
-   instruction->Size++;
+   instruction->NrTokens++;
 
    header_bodysize_grow( header );
 }
@@ -577,6 +584,7 @@ tgsi_build_full_instruction(
       *dst_register = tgsi_build_dst_register(
          reg->DstRegister.File,
          reg->DstRegister.WriteMask,
+         reg->DstRegister.Indirect,
          reg->DstRegister.Index,
          instruction,
          header );
@@ -624,6 +632,28 @@ tgsi_build_full_instruction(
             header );
          prev_token = (struct tgsi_token  *) dst_register_ext_modulate;
       }
+
+      if( reg->DstRegister.Indirect ) {
+         struct tgsi_src_register *ind;
+
+         if( maxsize <= size )
+            return 0;
+         ind = (struct tgsi_src_register *) &tokens[size];
+         size++;
+
+         *ind = tgsi_build_src_register(
+            reg->DstRegisterInd.File,
+            reg->DstRegisterInd.SwizzleX,
+            reg->DstRegisterInd.SwizzleY,
+            reg->DstRegisterInd.SwizzleZ,
+            reg->DstRegisterInd.SwizzleW,
+            reg->DstRegisterInd.Negate,
+            reg->DstRegisterInd.Indirect,
+            reg->DstRegisterInd.Dimension,
+            reg->DstRegisterInd.Index,
+            instruction,
+            header );
+      }
    }
 
    for( i = 0;  i < full_inst->Instruction.NumSrcRegs; i++ ) {
@@ -794,10 +824,14 @@ tgsi_default_instruction_ext_nv( void )
    return instruction_ext_nv;
 }
 
-union token_u32
+
+/** test for inequality of 32-bit values pointed to by a and b */
+static INLINE boolean
+compare32(const void *a, const void *b)
 {
-   unsigned u32;
-};
+   return *((uint32_t *) a) != *((uint32_t *) b);
+}
+
 
 unsigned
 tgsi_compare_instruction_ext_nv(
@@ -806,7 +840,7 @@ tgsi_compare_instruction_ext_nv(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_instruction_ext_nv
@@ -865,7 +899,7 @@ tgsi_compare_instruction_ext_label(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_instruction_ext_label
@@ -906,7 +940,7 @@ tgsi_compare_instruction_ext_texture(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_instruction_ext_texture
@@ -962,7 +996,7 @@ tgsi_build_src_register(
 {
    struct tgsi_src_register   src_register;
 
-   assert( file <= TGSI_FILE_IMMEDIATE );
+   assert( file < TGSI_FILE_COUNT );
    assert( swizzle_x <= TGSI_SWIZZLE_W );
    assert( swizzle_y <= TGSI_SWIZZLE_W );
    assert( swizzle_z <= TGSI_SWIZZLE_W );
@@ -1028,7 +1062,7 @@ tgsi_compare_src_register_ext_swz(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_src_register_ext_swz
@@ -1096,7 +1130,7 @@ tgsi_compare_src_register_ext_mod(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_src_register_ext_mod
@@ -1183,13 +1217,14 @@ struct tgsi_dst_register
 tgsi_build_dst_register(
    unsigned file,
    unsigned mask,
+   unsigned indirect,
    int index,
    struct tgsi_instruction *instruction,
    struct tgsi_header *header )
 {
    struct tgsi_dst_register dst_register;
 
-   assert( file <= TGSI_FILE_IMMEDIATE );
+   assert( file < TGSI_FILE_COUNT );
    assert( mask <= TGSI_WRITEMASK_XYZW );
    assert( index >= -32768 && index <= 32767 );
 
@@ -1197,6 +1232,7 @@ tgsi_build_dst_register(
    dst_register.File = file;
    dst_register.WriteMask = mask;
    dst_register.Index = index;
+   dst_register.Indirect = indirect;
 
    instruction_grow( instruction, header );
 
@@ -1209,6 +1245,7 @@ tgsi_default_full_dst_register( void )
    struct tgsi_full_dst_register full_dst_register;
 
    full_dst_register.DstRegister = tgsi_default_dst_register();
+   full_dst_register.DstRegisterInd = tgsi_default_src_register();
    full_dst_register.DstRegisterExtConcode =
       tgsi_default_dst_register_ext_concode();
    full_dst_register.DstRegisterExtModulate =
@@ -1242,7 +1279,7 @@ tgsi_compare_dst_register_ext_concode(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_dst_register_ext_concode
@@ -1300,7 +1337,7 @@ tgsi_compare_dst_register_ext_modulate(
 {
    a.Padding = b.Padding = 0;
    a.Extended = b.Extended = 0;
-   return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
+   return compare32(&a, &b);
 }
 
 struct tgsi_dst_register_ext_modulate