softpipe: add indirect store buffer/image unit
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_build.c
index cb7b9b2cccc9de55ab611edc9877edb677b9dec2..3db117ac3db94e4a9e47b2e5f946632cef9a0db7 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -109,6 +109,9 @@ tgsi_default_declaration( void )
    declaration.Semantic = 0;
    declaration.Invariant = 0;
    declaration.Local = 0;
+   declaration.Array = 0;
+   declaration.Atomic = 0;
+   declaration.MemType = TGSI_MEMORY_TYPE_GLOBAL;
    declaration.Padding = 0;
 
    return declaration;
@@ -123,6 +126,9 @@ tgsi_build_declaration(
    unsigned semantic,
    unsigned invariant,
    unsigned local,
+   unsigned array,
+   unsigned atomic,
+   unsigned mem_type,
    struct tgsi_header *header )
 {
    struct tgsi_declaration declaration;
@@ -138,7 +144,9 @@ tgsi_build_declaration(
    declaration.Semantic = semantic;
    declaration.Invariant = invariant;
    declaration.Local = local;
-
+   declaration.Array = array;
+   declaration.Atomic = atomic;
+   declaration.MemType = mem_type;
    header_bodysize_grow( header );
 
    return declaration;
@@ -155,6 +163,16 @@ tgsi_default_declaration_range( void )
    return dr;
 }
 
+static struct tgsi_declaration_dimension
+tgsi_default_declaration_dimension()
+{
+   struct tgsi_declaration_dimension dim;
+
+   dim.Index2D = 0;
+
+   return dim;
+}
+
 static struct tgsi_declaration_range
 tgsi_build_declaration_range(
    unsigned first,
@@ -198,7 +216,7 @@ tgsi_default_declaration_interp( void )
    struct tgsi_declaration_interp di;
 
    di.Interpolate = TGSI_INTERPOLATE_CONSTANT;
-   di.Centroid = 0;
+   di.Location = TGSI_INTERPOLATE_LOC_CENTER;
    di.CylindricalWrap = 0;
    di.Padding = 0;
 
@@ -207,7 +225,7 @@ tgsi_default_declaration_interp( void )
 
 static struct tgsi_declaration_interp
 tgsi_build_declaration_interp(unsigned interpolate,
-                              unsigned centroid,
+                              unsigned interpolate_location,
                               unsigned cylindrical_wrap,
                               struct tgsi_declaration *declaration,
                               struct tgsi_header *header)
@@ -215,7 +233,7 @@ tgsi_build_declaration_interp(unsigned interpolate,
    struct tgsi_declaration_interp di;
 
    di.Interpolate = interpolate;
-   di.Centroid = centroid;
+   di.Location = interpolate_location;
    di.CylindricalWrap = cylindrical_wrap;
    di.Padding = 0;
 
@@ -231,7 +249,10 @@ tgsi_default_declaration_semantic( void )
 
    ds.Name = TGSI_SEMANTIC_POSITION;
    ds.Index = 0;
-   ds.Padding = 0;
+   ds.StreamX = 0;
+   ds.StreamY = 0;
+   ds.StreamZ = 0;
+   ds.StreamW = 0;
 
    return ds;
 }
@@ -240,6 +261,10 @@ static struct tgsi_declaration_semantic
 tgsi_build_declaration_semantic(
    unsigned semantic_name,
    unsigned semantic_index,
+   unsigned streamx,
+   unsigned streamy,
+   unsigned streamz,
+   unsigned streamw,
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
@@ -250,43 +275,49 @@ tgsi_build_declaration_semantic(
 
    ds.Name = semantic_name;
    ds.Index = semantic_index;
-   ds.Padding = 0;
+   ds.StreamX = streamx;
+   ds.StreamY = streamy;
+   ds.StreamZ = streamz;
+   ds.StreamW = streamw;
 
    declaration_grow( declaration, header );
 
    return ds;
 }
 
-static struct tgsi_declaration_resource
-tgsi_default_declaration_resource(void)
+static struct tgsi_declaration_image
+tgsi_default_declaration_image(void)
 {
-   struct tgsi_declaration_resource dr;
+   struct tgsi_declaration_image di;
 
-   dr.Resource = TGSI_TEXTURE_BUFFER;
-   dr.Raw = 0;
-   dr.Writable = 0;
-   dr.Padding = 0;
+   di.Resource = TGSI_TEXTURE_BUFFER;
+   di.Raw = 0;
+   di.Writable = 0;
+   di.Format = 0;
+   di.Padding = 0;
 
-   return dr;
+   return di;
 }
 
-static struct tgsi_declaration_resource
-tgsi_build_declaration_resource(unsigned texture,
-                                unsigned raw,
-                                unsigned writable,
-                                struct tgsi_declaration *declaration,
-                                struct tgsi_header *header)
+static struct tgsi_declaration_image
+tgsi_build_declaration_image(unsigned texture,
+                             unsigned format,
+                             unsigned raw,
+                             unsigned writable,
+                             struct tgsi_declaration *declaration,
+                             struct tgsi_header *header)
 {
-   struct tgsi_declaration_resource dr;
+   struct tgsi_declaration_image di;
 
-   dr = tgsi_default_declaration_resource();
-   dr.Resource = texture;
-   dr.Raw = raw;
-   dr.Writable = writable;
+   di = tgsi_default_declaration_image();
+   di.Resource = texture;
+   di.Format = format;
+   di.Raw = raw;
+   di.Writable = writable;
 
    declaration_grow(declaration, header);
 
-   return dr;
+   return di;
 }
 
 static struct tgsi_declaration_sampler_view
@@ -295,10 +326,10 @@ tgsi_default_declaration_sampler_view(void)
    struct tgsi_declaration_sampler_view dsv;
 
    dsv.Resource = TGSI_TEXTURE_BUFFER;
-   dsv.ReturnTypeX = PIPE_TYPE_UNORM;
-   dsv.ReturnTypeY = PIPE_TYPE_UNORM;
-   dsv.ReturnTypeZ = PIPE_TYPE_UNORM;
-   dsv.ReturnTypeW = PIPE_TYPE_UNORM;
+   dsv.ReturnTypeX = TGSI_RETURN_TYPE_UNORM;
+   dsv.ReturnTypeY = TGSI_RETURN_TYPE_UNORM;
+   dsv.ReturnTypeZ = TGSI_RETURN_TYPE_UNORM;
+   dsv.ReturnTypeW = TGSI_RETURN_TYPE_UNORM;
 
    return dsv;
 }
@@ -327,6 +358,32 @@ tgsi_build_declaration_sampler_view(unsigned texture,
 }
 
 
+static struct tgsi_declaration_array
+tgsi_default_declaration_array( void )
+{
+   struct tgsi_declaration_array a;
+
+   a.ArrayID = 0;
+   a.Padding = 0;
+
+   return a;
+}
+
+static struct tgsi_declaration_array
+tgsi_build_declaration_array(unsigned arrayid,
+                             struct tgsi_declaration *declaration,
+                             struct tgsi_header *header)
+{
+   struct tgsi_declaration_array da;
+
+   da = tgsi_default_declaration_array();
+   da.ArrayID = arrayid;
+
+   declaration_grow(declaration, header);
+
+   return da;
+}
+
 struct tgsi_full_declaration
 tgsi_default_full_declaration( void )
 {
@@ -334,11 +391,12 @@ tgsi_default_full_declaration( void )
 
    full_declaration.Declaration  = tgsi_default_declaration();
    full_declaration.Range = tgsi_default_declaration_range();
+   full_declaration.Dim = tgsi_default_declaration_dimension();
    full_declaration.Semantic = tgsi_default_declaration_semantic();
    full_declaration.Interp = tgsi_default_declaration_interp();
-   full_declaration.ImmediateData.u = NULL;
-   full_declaration.Resource = tgsi_default_declaration_resource();
+   full_declaration.Image = tgsi_default_declaration_image();
    full_declaration.SamplerView = tgsi_default_declaration_sampler_view();
+   full_declaration.Array = tgsi_default_declaration_array();
 
    return full_declaration;
 }
@@ -367,6 +425,9 @@ tgsi_build_full_declaration(
       full_decl->Declaration.Semantic,
       full_decl->Declaration.Invariant,
       full_decl->Declaration.Local,
+      full_decl->Declaration.Array,
+      full_decl->Declaration.Atomic,
+      full_decl->Declaration.MemType,
       header );
 
    if (maxsize <= size)
@@ -404,7 +465,7 @@ tgsi_build_full_declaration(
       size++;
 
       *di = tgsi_build_declaration_interp(full_decl->Interp.Interpolate,
-                                          full_decl->Interp.Centroid,
+                                          full_decl->Interp.Location,
                                           full_decl->Interp.CylindricalWrap,
                                           declaration,
                                           header);
@@ -421,42 +482,29 @@ tgsi_build_full_declaration(
       *ds = tgsi_build_declaration_semantic(
          full_decl->Semantic.Name,
          full_decl->Semantic.Index,
+         full_decl->Semantic.StreamX,
+         full_decl->Semantic.StreamY,
+         full_decl->Semantic.StreamZ,
+         full_decl->Semantic.StreamW,
          declaration,
          header );
    }
 
-   if (full_decl->Declaration.File == TGSI_FILE_IMMEDIATE_ARRAY) {
-      unsigned i, j;
-      union tgsi_immediate_data *data;
-
-      for (i = 0; i <= dr->Last; ++i) {
-         for (j = 0; j < 4; ++j) {
-            unsigned idx = i*4 + j;
-            if (maxsize <= size)
-               return 0;
-            data = (union tgsi_immediate_data *) &tokens[size];
-            ++size;
-
-            *data = full_decl->ImmediateData.u[idx];
-            declaration_grow( declaration, header );
-         }
-      }
-   }
-
-   if (full_decl->Declaration.File == TGSI_FILE_RESOURCE) {
-      struct tgsi_declaration_resource *dr;
+   if (full_decl->Declaration.File == TGSI_FILE_IMAGE) {
+      struct tgsi_declaration_image *di;
 
       if (maxsize <= size) {
          return  0;
       }
-      dr = (struct tgsi_declaration_resource *)&tokens[size];
+      di = (struct tgsi_declaration_image *)&tokens[size];
       size++;
 
-      *dr = tgsi_build_declaration_resource(full_decl->Resource.Resource,
-                                            full_decl->Resource.Raw,
-                                            full_decl->Resource.Writable,
-                                            declaration,
-                                            header);
+      *di = tgsi_build_declaration_image(full_decl->Image.Resource,
+                                         full_decl->Image.Format,
+                                         full_decl->Image.Raw,
+                                         full_decl->Image.Writable,
+                                         declaration,
+                                         header);
    }
 
    if (full_decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
@@ -478,6 +526,19 @@ tgsi_build_full_declaration(
          header);
    }
 
+   if (full_decl->Declaration.Array) {
+      struct tgsi_declaration_array *da;
+
+      if (maxsize <= size) {
+         return 0;
+      }
+      da = (struct tgsi_declaration_array *)&tokens[size];
+      size++;
+      *da = tgsi_build_declaration_array(
+         full_decl->Array.ArrayID,
+         declaration,
+         header);
+   }
    return size;
 }
 
@@ -546,7 +607,8 @@ tgsi_build_full_immediate(
    struct tgsi_header *header,
    unsigned maxsize )
 {
-   unsigned size = 0, i;
+   unsigned size = 0;
+   int i;
    struct tgsi_immediate *immediate;
 
    if( maxsize <= size )
@@ -586,21 +648,22 @@ tgsi_default_instruction( void )
    instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
    instruction.NrTokens = 0;
    instruction.Opcode = TGSI_OPCODE_MOV;
-   instruction.Saturate = TGSI_SAT_NONE;
-   instruction.Predicate = 0;
+   instruction.Saturate = 0;
    instruction.NumDstRegs = 1;
    instruction.NumSrcRegs = 1;
    instruction.Label = 0;
    instruction.Texture = 0;
-   instruction.Padding  = 0;
+   instruction.Memory = 0;
+   instruction.Precise = 0;
+   instruction.Padding = 0;
 
    return instruction;
 }
 
 static struct tgsi_instruction
-tgsi_build_instruction(unsigned opcode,
+tgsi_build_instruction(enum tgsi_opcode opcode,
                        unsigned saturate,
-                       unsigned predicate,
+                       unsigned precise,
                        unsigned num_dst_regs,
                        unsigned num_src_regs,
                        struct tgsi_header *header)
@@ -608,14 +671,14 @@ tgsi_build_instruction(unsigned opcode,
    struct tgsi_instruction instruction;
 
    assert (opcode <= TGSI_OPCODE_LAST);
-   assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE);
+   assert (saturate <= 1);
    assert (num_dst_regs <= 3);
    assert (num_src_regs <= 15);
 
    instruction = tgsi_default_instruction();
    instruction.Opcode = opcode;
    instruction.Saturate = saturate;
-   instruction.Predicate = predicate;
+   instruction.Precise = precise;
    instruction.NumDstRegs = num_dst_regs;
    instruction.NumSrcRegs = num_src_regs;
 
@@ -636,47 +699,6 @@ instruction_grow(
    header_bodysize_grow( header );
 }
 
-struct tgsi_instruction_predicate
-tgsi_default_instruction_predicate(void)
-{
-   struct tgsi_instruction_predicate instruction_predicate;
-
-   instruction_predicate.SwizzleX = TGSI_SWIZZLE_X;
-   instruction_predicate.SwizzleY = TGSI_SWIZZLE_Y;
-   instruction_predicate.SwizzleZ = TGSI_SWIZZLE_Z;
-   instruction_predicate.SwizzleW = TGSI_SWIZZLE_W;
-   instruction_predicate.Negate = 0;
-   instruction_predicate.Index = 0;
-   instruction_predicate.Padding = 0;
-
-   return instruction_predicate;
-}
-
-static struct tgsi_instruction_predicate
-tgsi_build_instruction_predicate(int index,
-                                 unsigned negate,
-                                 unsigned swizzleX,
-                                 unsigned swizzleY,
-                                 unsigned swizzleZ,
-                                 unsigned swizzleW,
-                                 struct tgsi_instruction *instruction,
-                                 struct tgsi_header *header)
-{
-   struct tgsi_instruction_predicate instruction_predicate;
-
-   instruction_predicate = tgsi_default_instruction_predicate();
-   instruction_predicate.SwizzleX = swizzleX;
-   instruction_predicate.SwizzleY = swizzleY;
-   instruction_predicate.SwizzleZ = swizzleZ;
-   instruction_predicate.SwizzleW = swizzleW;
-   instruction_predicate.Negate = negate;
-   instruction_predicate.Index = index;
-
-   instruction_grow(instruction, header);
-
-   return instruction_predicate;
-}
-
 static struct tgsi_instruction_label
 tgsi_default_instruction_label( void )
 {
@@ -691,7 +713,6 @@ tgsi_default_instruction_label( void )
 static struct tgsi_instruction_label
 tgsi_build_instruction_label(
    unsigned label,
-   struct tgsi_token  *prev_token,
    struct tgsi_instruction *instruction,
    struct tgsi_header *header )
 {
@@ -713,6 +734,7 @@ tgsi_default_instruction_texture( void )
 
    instruction_texture.Texture = TGSI_TEXTURE_UNKNOWN;
    instruction_texture.NumOffsets = 0;
+   instruction_texture.ReturnType = TGSI_RETURN_TYPE_UNKNOWN;
    instruction_texture.Padding = 0;
 
    return instruction_texture;
@@ -722,7 +744,7 @@ static struct tgsi_instruction_texture
 tgsi_build_instruction_texture(
    unsigned texture,
    unsigned num_offsets,
-   struct tgsi_token *prev_token,
+   unsigned return_type,
    struct tgsi_instruction *instruction,
    struct tgsi_header *header )
 {
@@ -730,6 +752,7 @@ tgsi_build_instruction_texture(
 
    instruction_texture.Texture = texture;
    instruction_texture.NumOffsets = num_offsets;
+   instruction_texture.ReturnType = return_type;
    instruction_texture.Padding = 0;
    instruction->Texture = 1;
 
@@ -738,6 +761,39 @@ tgsi_build_instruction_texture(
    return instruction_texture;
 }
 
+static struct tgsi_instruction_memory
+tgsi_default_instruction_memory( void )
+{
+   struct tgsi_instruction_memory instruction_memory;
+
+   instruction_memory.Qualifier = 0;
+   instruction_memory.Texture = 0;
+   instruction_memory.Format = 0;
+   instruction_memory.Padding = 0;
+
+   return instruction_memory;
+}
+
+static struct tgsi_instruction_memory
+tgsi_build_instruction_memory(
+   unsigned qualifier,
+   unsigned texture,
+   unsigned format,
+   struct tgsi_instruction *instruction,
+   struct tgsi_header *header )
+{
+   struct tgsi_instruction_memory instruction_memory;
+
+   instruction_memory.Qualifier = qualifier;
+   instruction_memory.Texture = texture;
+   instruction_memory.Format = format;
+   instruction_memory.Padding = 0;
+   instruction->Memory = 1;
+
+   instruction_grow( instruction, header );
+
+   return instruction_memory;
+}
 
 static struct tgsi_texture_offset
 tgsi_default_texture_offset( void )
@@ -757,7 +813,6 @@ tgsi_default_texture_offset( void )
 static struct tgsi_texture_offset
 tgsi_build_texture_offset(
    int index, int file, int swizzle_x, int swizzle_y, int swizzle_z,
-   struct tgsi_token *prev_token,
    struct tgsi_instruction *instruction,
    struct tgsi_header *header )
 {
@@ -835,6 +890,44 @@ tgsi_build_src_register(
    return src_register;
 }
 
+static struct tgsi_ind_register
+tgsi_default_ind_register( void )
+{
+   struct tgsi_ind_register ind_register;
+
+   ind_register.File = TGSI_FILE_NULL;
+   ind_register.Index = 0;
+   ind_register.Swizzle = TGSI_SWIZZLE_X;
+   ind_register.ArrayID = 0;
+
+   return ind_register;
+}
+
+static struct tgsi_ind_register
+tgsi_build_ind_register(
+   unsigned file,
+   unsigned swizzle,
+   int index,
+   unsigned arrayid,
+   struct tgsi_instruction *instruction,
+   struct tgsi_header *header )
+{
+   struct tgsi_ind_register   ind_register;
+
+   assert( file < TGSI_FILE_COUNT );
+   assert( swizzle <= TGSI_SWIZZLE_W );
+   assert( index >= -0x8000 && index <= 0x7FFF );
+
+   ind_register.File = file;
+   ind_register.Swizzle = swizzle;
+   ind_register.Index = index;
+   ind_register.ArrayID = arrayid;
+
+   instruction_grow( instruction, header );
+
+   return ind_register;
+}
+
 static struct tgsi_dimension
 tgsi_default_dimension( void )
 {
@@ -854,9 +947,9 @@ tgsi_default_full_src_register( void )
    struct tgsi_full_src_register full_src_register;
 
    full_src_register.Register = tgsi_default_src_register();
-   full_src_register.Indirect = tgsi_default_src_register();
+   full_src_register.Indirect = tgsi_default_ind_register();
    full_src_register.Dimension = tgsi_default_dimension();
-   full_src_register.DimIndirect = tgsi_default_src_register();
+   full_src_register.DimIndirect = tgsi_default_ind_register();
 
    return full_src_register;
 }
@@ -929,9 +1022,9 @@ tgsi_default_full_dst_register( void )
    struct tgsi_full_dst_register full_dst_register;
 
    full_dst_register.Register = tgsi_default_dst_register();
-   full_dst_register.Indirect = tgsi_default_src_register();
+   full_dst_register.Indirect = tgsi_default_ind_register();
    full_dst_register.Dimension = tgsi_default_dimension();
-   full_dst_register.DimIndirect = tgsi_default_src_register();
+   full_dst_register.DimIndirect = tgsi_default_ind_register();
 
    return full_dst_register;
 }
@@ -943,9 +1036,9 @@ tgsi_default_full_instruction( void )
    unsigned i;
 
    full_instruction.Instruction = tgsi_default_instruction();
-   full_instruction.Predicate = tgsi_default_instruction_predicate();
    full_instruction.Label = tgsi_default_instruction_label();
    full_instruction.Texture = tgsi_default_instruction_texture();
+   full_instruction.Memory = tgsi_default_instruction_memory();
    for( i = 0;  i < TGSI_FULL_MAX_TEX_OFFSETS; i++ ) {
       full_instruction.TexOffsets[i] = tgsi_default_texture_offset();
    }
@@ -969,7 +1062,6 @@ tgsi_build_full_instruction(
    unsigned size = 0;
    unsigned i;
    struct tgsi_instruction *instruction;
-   struct tgsi_token *prev_token;
 
    if( maxsize <= size )
       return 0;
@@ -978,31 +1070,10 @@ tgsi_build_full_instruction(
 
    *instruction = tgsi_build_instruction(full_inst->Instruction.Opcode,
                                          full_inst->Instruction.Saturate,
-                                         full_inst->Instruction.Predicate,
+                                         full_inst->Instruction.Precise,
                                          full_inst->Instruction.NumDstRegs,
                                          full_inst->Instruction.NumSrcRegs,
                                          header);
-   prev_token = (struct tgsi_token  *) instruction;
-
-   if (full_inst->Instruction.Predicate) {
-      struct tgsi_instruction_predicate *instruction_predicate;
-
-      if (maxsize <= size) {
-         return 0;
-      }
-      instruction_predicate = (struct tgsi_instruction_predicate *)&tokens[size];
-      size++;
-
-      *instruction_predicate =
-         tgsi_build_instruction_predicate(full_inst->Predicate.Index,
-                                          full_inst->Predicate.Negate,
-                                          full_inst->Predicate.SwizzleX,
-                                          full_inst->Predicate.SwizzleY,
-                                          full_inst->Predicate.SwizzleZ,
-                                          full_inst->Predicate.SwizzleW,
-                                          instruction,
-                                          header);
-   }
 
    if (full_inst->Instruction.Label) {
       struct tgsi_instruction_label *instruction_label;
@@ -1015,10 +1086,8 @@ tgsi_build_full_instruction(
 
       *instruction_label = tgsi_build_instruction_label(
          full_inst->Label.Label,
-         prev_token,
          instruction,
-         header );
-      prev_token = (struct tgsi_token  *) instruction_label;
+        header );
    }
 
    if (full_inst->Instruction.Texture) {
@@ -1032,11 +1101,10 @@ tgsi_build_full_instruction(
 
       *instruction_texture = tgsi_build_instruction_texture(
          full_inst->Texture.Texture,
-        full_inst->Texture.NumOffsets,
-         prev_token,
+         full_inst->Texture.NumOffsets,
+         full_inst->Texture.ReturnType,
          instruction,
          header   );
-      prev_token = (struct tgsi_token  *) instruction_texture;
 
       for (i = 0; i < full_inst->Texture.NumOffsets; i++) {
          struct tgsi_texture_offset *texture_offset;
@@ -1051,12 +1119,28 @@ tgsi_build_full_instruction(
             full_inst->TexOffsets[i].SwizzleX,
             full_inst->TexOffsets[i].SwizzleY,
             full_inst->TexOffsets[i].SwizzleZ,
-            prev_token,
             instruction,
             header);
-         prev_token = (struct tgsi_token *) texture_offset;
       }
    }
+
+   if (full_inst->Instruction.Memory) {
+      struct tgsi_instruction_memory *instruction_memory;
+
+      if( maxsize <= size )
+         return 0;
+      instruction_memory =
+         (struct  tgsi_instruction_memory *) &tokens[size];
+      size++;
+
+      *instruction_memory = tgsi_build_instruction_memory(
+         full_inst->Memory.Qualifier,
+         full_inst->Memory.Texture,
+         full_inst->Memory.Format,
+         instruction,
+         header );
+   }
+
    for( i = 0;  i <   full_inst->Instruction.NumDstRegs; i++ ) {
       const struct tgsi_full_dst_register *reg = &full_inst->Dst[i];
       struct tgsi_dst_register *dst_register;
@@ -1076,24 +1160,18 @@ tgsi_build_full_instruction(
          header );
 
       if( reg->Register.Indirect ) {
-         struct tgsi_src_register *ind;
+         struct tgsi_ind_register *ind;
 
          if( maxsize <= size )
             return 0;
-         ind = (struct tgsi_src_register *) &tokens[size];
+         ind = (struct tgsi_ind_register *) &tokens[size];
          size++;
 
-         *ind = tgsi_build_src_register(
+         *ind = tgsi_build_ind_register(
             reg->Indirect.File,
-            reg->Indirect.SwizzleX,
-            reg->Indirect.SwizzleY,
-            reg->Indirect.SwizzleZ,
-            reg->Indirect.SwizzleW,
-            reg->Indirect.Negate,
-            reg->Indirect.Absolute,
-            reg->Indirect.Indirect,
-            reg->Indirect.Dimension,
+            reg->Indirect.Swizzle,
             reg->Indirect.Index,
+            reg->Indirect.ArrayID,
             instruction,
             header );
       }
@@ -1115,24 +1193,18 @@ tgsi_build_full_instruction(
             header );
 
          if( reg->Dimension.Indirect ) {
-            struct tgsi_src_register *ind;
+            struct tgsi_ind_register *ind;
 
             if( maxsize <= size )
                return 0;
-            ind = (struct tgsi_src_register *) &tokens[size];
+            ind = (struct tgsi_ind_register *) &tokens[size];
             size++;
 
-            *ind = tgsi_build_src_register(
+            *ind = tgsi_build_ind_register(
                reg->DimIndirect.File,
-               reg->DimIndirect.SwizzleX,
-               reg->DimIndirect.SwizzleY,
-               reg->DimIndirect.SwizzleZ,
-               reg->DimIndirect.SwizzleW,
-               reg->DimIndirect.Negate,
-               reg->DimIndirect.Absolute,
-               reg->DimIndirect.Indirect,
-               reg->DimIndirect.Dimension,
+               reg->DimIndirect.Swizzle,
                reg->DimIndirect.Index,
+               reg->DimIndirect.ArrayID,
                instruction,
                header );
          }
@@ -1163,24 +1235,18 @@ tgsi_build_full_instruction(
          header );
 
       if( reg->Register.Indirect ) {
-         struct  tgsi_src_register *ind;
+         struct  tgsi_ind_register *ind;
 
          if( maxsize <= size )
             return 0;
-         ind = (struct tgsi_src_register *) &tokens[size];
+         ind = (struct tgsi_ind_register *) &tokens[size];
          size++;
 
-         *ind = tgsi_build_src_register(
+         *ind = tgsi_build_ind_register(
             reg->Indirect.File,
-            reg->Indirect.SwizzleX,
-            reg->Indirect.SwizzleY,
-            reg->Indirect.SwizzleZ,
-            reg->Indirect.SwizzleW,
-            reg->Indirect.Negate,
-            reg->Indirect.Absolute,
-            reg->Indirect.Indirect,
-            reg->Indirect.Dimension,
+            reg->Indirect.Swizzle,
             reg->Indirect.Index,
+            reg->Indirect.ArrayID,
             instruction,
             header );
       }
@@ -1202,24 +1268,18 @@ tgsi_build_full_instruction(
             header );
 
          if( reg->Dimension.Indirect ) {
-            struct tgsi_src_register *ind;
+            struct tgsi_ind_register *ind;
 
             if( maxsize <= size )
                return 0;
-            ind = (struct tgsi_src_register *) &tokens[size];
+            ind = (struct tgsi_ind_register *) &tokens[size];
             size++;
 
-            *ind = tgsi_build_src_register(
+            *ind = tgsi_build_ind_register(
                reg->DimIndirect.File,
-               reg->DimIndirect.SwizzleX,
-               reg->DimIndirect.SwizzleY,
-               reg->DimIndirect.SwizzleZ,
-               reg->DimIndirect.SwizzleW,
-               reg->DimIndirect.Negate,
-               reg->DimIndirect.Absolute,
-               reg->DimIndirect.Indirect,
-               reg->DimIndirect.Dimension,
+               reg->DimIndirect.Swizzle,
                reg->DimIndirect.Index,
+               reg->DimIndirect.ArrayID,
                instruction,
                header );
          }
@@ -1303,7 +1363,8 @@ tgsi_build_full_property(
    struct tgsi_header *header,
    unsigned maxsize )
 {
-   unsigned size = 0, i;
+   unsigned size = 0;
+   int i;
    struct tgsi_property *property;
 
    if( maxsize <= size )
@@ -1333,3 +1394,18 @@ tgsi_build_full_property(
 
    return size;
 }
+
+struct tgsi_full_src_register
+tgsi_full_src_register_from_dst(const struct tgsi_full_dst_register *dst)
+{
+   struct tgsi_full_src_register src;
+   src.Register = tgsi_default_src_register();
+   src.Register.File = dst->Register.File;
+   src.Register.Indirect = dst->Register.Indirect;
+   src.Register.Dimension = dst->Register.Dimension;
+   src.Register.Index = dst->Register.Index;
+   src.Indirect = dst->Indirect;
+   src.Dimension = dst->Dimension;
+   src.DimIndirect = dst->DimIndirect;
+   return src;
+}