mesa: allow user to set MESA_NO_ERROR=0
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_transform.h
index 27e6179c9ee349874c917e928ea18de3cdbee1e4..e4da0f5debca760c2fe799f3c92cc153c16fdf7a 100644 (file)
@@ -124,6 +124,8 @@ tgsi_transform_const_decl(struct tgsi_transform_context *ctx,
    decl.Declaration.File = TGSI_FILE_CONSTANT;
    decl.Range.First = firstIdx;
    decl.Range.Last = lastIdx;
+   decl.Declaration.Dimension = 1;
+   /* Dim.Index2D is already 0 */
    ctx->emit_declaration(ctx, &decl);
 }
  
@@ -230,6 +232,18 @@ tgsi_transform_dst_reg(struct tgsi_full_dst_register *reg,
    reg->Register.WriteMask = writemask;
 }
 
+static inline void
+tgsi_transform_src_reg_xyzw(struct tgsi_full_src_register *reg,
+                            unsigned file, unsigned index)
+{
+   reg->Register.File = file;
+   reg->Register.Index = index;
+   if (file == TGSI_FILE_CONSTANT) {
+      reg->Register.Dimension = 1;
+      reg->Dimension.Index = 0;
+   }
+}
+
 static inline void
 tgsi_transform_src_reg(struct tgsi_full_src_register *reg,
                        unsigned file, unsigned index, 
@@ -238,7 +252,11 @@ tgsi_transform_src_reg(struct tgsi_full_src_register *reg,
 {
    reg->Register.File = file;
    reg->Register.Index = index;
-   reg->Register.SwizzleX = swizzleX; 
+   if (file == TGSI_FILE_CONSTANT) {
+      reg->Register.Dimension = 1;
+      reg->Dimension.Index = 0;
+   }
+   reg->Register.SwizzleX = swizzleX;
    reg->Register.SwizzleY = swizzleY; 
    reg->Register.SwizzleZ = swizzleZ; 
    reg->Register.SwizzleW = swizzleW; 
@@ -265,8 +283,7 @@ tgsi_transform_op1_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Dst[0].Register.WriteMask = dst_writemask;
    inst.Instruction.NumSrcRegs = 1;
-   inst.Src[0].Register.File = src0_file;
-   inst.Src[0].Register.Index = src0_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
 
    ctx->emit_instruction(ctx, &inst);
 }
@@ -281,7 +298,8 @@ tgsi_transform_op2_inst(struct tgsi_transform_context *ctx,
                         unsigned src0_file,
                         unsigned src0_index,
                         unsigned src1_file,
-                        unsigned src1_index)
+                        unsigned src1_index,
+                        bool src1_negate)
 {
    struct tgsi_full_instruction inst;
 
@@ -292,15 +310,45 @@ tgsi_transform_op2_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Dst[0].Register.WriteMask = dst_writemask;
    inst.Instruction.NumSrcRegs = 2;
-   inst.Src[0].Register.File = src0_file;
-   inst.Src[0].Register.Index = src0_index;
-   inst.Src[1].Register.File = src1_file;
-   inst.Src[1].Register.Index = src1_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[1], src1_file, src1_index);
+   inst.Src[1].Register.Negate = src1_negate;
+
+   ctx->emit_instruction(ctx, &inst);
+}
+
+
+static inline void
+tgsi_transform_op3_inst(struct tgsi_transform_context *ctx,
+                        unsigned opcode,
+                        unsigned dst_file,
+                        unsigned dst_index,
+                        unsigned dst_writemask,
+                        unsigned src0_file,
+                        unsigned src0_index,
+                        unsigned src1_file,
+                        unsigned src1_index,
+                        unsigned src2_file,
+                        unsigned src2_index)
+{
+   struct tgsi_full_instruction inst;
+
+   inst = tgsi_default_full_instruction();
+   inst.Instruction.Opcode = opcode;
+   inst.Instruction.NumDstRegs = 1;
+   inst.Dst[0].Register.File = dst_file,
+   inst.Dst[0].Register.Index = dst_index;
+   inst.Dst[0].Register.WriteMask = dst_writemask;
+   inst.Instruction.NumSrcRegs = 3;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[1], src1_file, src1_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[2], src2_file, src2_index);
 
    ctx->emit_instruction(ctx, &inst);
 }
 
 
+
 static inline void
 tgsi_transform_op1_swz_inst(struct tgsi_transform_context *ctx,
                             unsigned opcode,
@@ -320,8 +368,7 @@ tgsi_transform_op1_swz_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Dst[0].Register.WriteMask = dst_writemask;
    inst.Instruction.NumSrcRegs = 1;
-   inst.Src[0].Register.File = src0_file;
-   inst.Src[0].Register.Index = src0_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
    switch (dst_writemask) {
    case TGSI_WRITEMASK_X:
       inst.Src[0].Register.SwizzleX = src0_swizzle;
@@ -354,7 +401,8 @@ tgsi_transform_op2_swz_inst(struct tgsi_transform_context *ctx,
                             unsigned src0_swizzle,
                             unsigned src1_file,
                             unsigned src1_index,
-                            unsigned src1_swizzle)
+                            unsigned src1_swizzle,
+                            bool src1_negate)
 {
    struct tgsi_full_instruction inst;
 
@@ -365,10 +413,9 @@ tgsi_transform_op2_swz_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Dst[0].Register.WriteMask = dst_writemask;
    inst.Instruction.NumSrcRegs = 2;
-   inst.Src[0].Register.File = src0_file;
-   inst.Src[0].Register.Index = src0_index;
-   inst.Src[1].Register.File = src1_file;
-   inst.Src[1].Register.Index = src1_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[1], src1_file, src1_index);
+   inst.Src[1].Register.Negate = src1_negate;
    switch (dst_writemask) {
    case TGSI_WRITEMASK_X:
       inst.Src[0].Register.SwizzleX = src0_swizzle;
@@ -420,13 +467,10 @@ tgsi_transform_op3_swz_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Dst[0].Register.WriteMask = dst_writemask;
    inst.Instruction.NumSrcRegs = 3;
-   inst.Src[0].Register.File = src0_file;
-   inst.Src[0].Register.Index = src0_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src0_file, src0_index);
    inst.Src[0].Register.Negate = src0_negate;
-   inst.Src[1].Register.File = src1_file;
-   inst.Src[1].Register.Index = src1_index;
-   inst.Src[2].Register.File = src2_file;
-   inst.Src[2].Register.Index = src2_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[1], src1_file, src1_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[2], src2_file, src2_index);
    switch (dst_writemask) {
    case TGSI_WRITEMASK_X:
       inst.Src[0].Register.SwizzleX = src0_swizzle;
@@ -469,8 +513,7 @@ tgsi_transform_kill_inst(struct tgsi_transform_context *ctx,
    inst.Instruction.Opcode = TGSI_OPCODE_KILL_IF;
    inst.Instruction.NumDstRegs = 0;
    inst.Instruction.NumSrcRegs = 1;
-   inst.Src[0].Register.File = src_file;
-   inst.Src[0].Register.Index = src_index;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src_file, src_index);
    inst.Src[0].Register.SwizzleX =
    inst.Src[0].Register.SwizzleY =
    inst.Src[0].Register.SwizzleZ =
@@ -482,15 +525,18 @@ tgsi_transform_kill_inst(struct tgsi_transform_context *ctx,
 
 
 static inline void
-tgsi_transform_tex_2d_inst(struct tgsi_transform_context *ctx,
-                           unsigned dst_file,
-                           unsigned dst_index,
-                           unsigned src_file,
-                           unsigned src_index,
-                           unsigned sampler_index)
+tgsi_transform_tex_inst(struct tgsi_transform_context *ctx,
+                        unsigned dst_file,
+                        unsigned dst_index,
+                        unsigned src_file,
+                        unsigned src_index,
+                        unsigned tex_target,
+                        unsigned sampler_index)
 {
    struct tgsi_full_instruction inst;
 
+   assert(tex_target < TGSI_TEXTURE_COUNT);
+
    inst = tgsi_default_full_instruction();
    inst.Instruction.Opcode = TGSI_OPCODE_TEX;
    inst.Instruction.NumDstRegs = 1;
@@ -498,11 +544,9 @@ tgsi_transform_tex_2d_inst(struct tgsi_transform_context *ctx,
    inst.Dst[0].Register.Index = dst_index;
    inst.Instruction.NumSrcRegs = 2;
    inst.Instruction.Texture = TRUE;
-   inst.Texture.Texture = TGSI_TEXTURE_2D;
-   inst.Src[0].Register.File = src_file;
-   inst.Src[0].Register.Index = src_index;
-   inst.Src[1].Register.File = TGSI_FILE_SAMPLER;
-   inst.Src[1].Register.Index = sampler_index;
+   inst.Texture.Texture = tex_target;
+   tgsi_transform_src_reg_xyzw(&inst.Src[0], src_file, src_index);
+   tgsi_transform_src_reg_xyzw(&inst.Src[1], TGSI_FILE_SAMPLER, sampler_index);
 
    ctx->emit_instruction(ctx, &inst);
 }