[Mesa-dev] [PATCH v2 03/12] tgsi/build: always generate two-dimensional constant file accesses

Nicolai Hähnle nhaehnle at gmail.com
Mon Aug 28 08:58:11 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/auxiliary/tgsi/tgsi_build.c     | 11 +++++
 src/gallium/auxiliary/tgsi/tgsi_transform.h | 65 +++++++++++++++--------------
 2 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c
index 144a0177689..0c4ec8d1cf9 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_build.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_build.c
@@ -156,20 +156,30 @@ static struct tgsi_declaration_range
 tgsi_default_declaration_range( void )
 {
    struct tgsi_declaration_range dr;
 
    dr.First = 0;
    dr.Last = 0;
 
    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,
    unsigned last,
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
    struct tgsi_declaration_range declaration_range;
 
    assert( last >= first );
@@ -374,20 +384,21 @@ tgsi_build_declaration_array(unsigned arrayid,
    return da;
 }
 
 struct tgsi_full_declaration
 tgsi_default_full_declaration( void )
 {
    struct tgsi_full_declaration  full_declaration;
 
    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.Image = tgsi_default_declaration_image();
    full_declaration.SamplerView = tgsi_default_declaration_sampler_view();
    full_declaration.Array = tgsi_default_declaration_array();
 
    return full_declaration;
 }
 
 unsigned
diff --git a/src/gallium/auxiliary/tgsi/tgsi_transform.h b/src/gallium/auxiliary/tgsi/tgsi_transform.h
index 7ea82066fcf..e4da0f5debc 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_transform.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_transform.h
@@ -117,20 +117,22 @@ tgsi_transform_temp_decl(struct tgsi_transform_context *ctx,
 static inline void
 tgsi_transform_const_decl(struct tgsi_transform_context *ctx,
                           unsigned firstIdx, unsigned lastIdx)
 {
    struct tgsi_full_declaration decl;
 
    decl = tgsi_default_full_declaration();
    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);
 }
  
 static inline void
 tgsi_transform_input_decl(struct tgsi_transform_context *ctx,
                           unsigned index,
                           unsigned sem_name, unsigned sem_index,
                           unsigned interp)
 {
    struct tgsi_full_declaration decl;
@@ -224,28 +226,44 @@ tgsi_transform_immediate_decl(struct tgsi_transform_context *ctx,
 static inline void
 tgsi_transform_dst_reg(struct tgsi_full_dst_register *reg,
                        unsigned file, unsigned index, unsigned writemask)
 {
    reg->Register.File = file;
    reg->Register.Index = index;
    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, 
                        unsigned swizzleX, unsigned swizzleY,
                        unsigned swizzleZ, unsigned swizzleW)
 {
    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; 
 }
 
 /**
  * Helper for emitting 1-operand instructions.
  */
 static inline void
 tgsi_transform_op1_inst(struct tgsi_transform_context *ctx,
@@ -258,22 +276,21 @@ tgsi_transform_op1_inst(struct tgsi_transform_context *ctx,
 {
    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 = 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);
 }
 
 
 static inline void
 tgsi_transform_op2_inst(struct tgsi_transform_context *ctx,
                         unsigned opcode,
                         unsigned dst_file,
                         unsigned dst_index,
@@ -286,24 +303,22 @@ tgsi_transform_op2_inst(struct tgsi_transform_context *ctx,
 {
    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 = 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,
@@ -318,26 +333,23 @@ tgsi_transform_op3_inst(struct tgsi_transform_context *ctx,
 {
    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;
-   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;
-   inst.Src[2].Register.File = src2_file;
-   inst.Src[2].Register.Index = src2_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);
+   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,
                             unsigned dst_file,
@@ -349,22 +361,21 @@ tgsi_transform_op1_swz_inst(struct tgsi_transform_context *ctx,
 {
    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 = 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;
       break;
    case TGSI_WRITEMASK_Y:
       inst.Src[0].Register.SwizzleY = src0_swizzle;
       break;
    case TGSI_WRITEMASK_Z:
       inst.Src[0].Register.SwizzleZ = src0_swizzle;
       break;
@@ -395,24 +406,22 @@ tgsi_transform_op2_swz_inst(struct tgsi_transform_context *ctx,
 {
    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 = 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;
       inst.Src[1].Register.SwizzleX = src1_swizzle;
       break;
    case TGSI_WRITEMASK_Y:
       inst.Src[0].Register.SwizzleY = src0_swizzle;
       inst.Src[1].Register.SwizzleY = src1_swizzle;
       break;
@@ -451,27 +460,24 @@ tgsi_transform_op3_swz_inst(struct tgsi_transform_context *ctx,
 {
    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;
-   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;
       inst.Src[1].Register.SwizzleX = src1_swizzle;
       inst.Src[2].Register.SwizzleX = src2_swizzle;
       break;
    case TGSI_WRITEMASK_Y:
       inst.Src[0].Register.SwizzleY = src0_swizzle;
       inst.Src[1].Register.SwizzleY = src1_swizzle;
       inst.Src[2].Register.SwizzleY = src2_swizzle;
@@ -500,22 +506,21 @@ tgsi_transform_kill_inst(struct tgsi_transform_context *ctx,
                          unsigned src_index,
                          unsigned src_swizzle,
                          boolean negate)
 {
    struct tgsi_full_instruction inst;
 
    inst = tgsi_default_full_instruction();
    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 =
    inst.Src[0].Register.SwizzleW = src_swizzle;
    inst.Src[0].Register.Negate = negate;
 
    ctx->emit_instruction(ctx, &inst);
 }
 
 
@@ -533,24 +538,22 @@ tgsi_transform_tex_inst(struct tgsi_transform_context *ctx,
    assert(tex_target < TGSI_TEXTURE_COUNT);
 
    inst = tgsi_default_full_instruction();
    inst.Instruction.Opcode = TGSI_OPCODE_TEX;
    inst.Instruction.NumDstRegs = 1;
    inst.Dst[0].Register.File = dst_file;
    inst.Dst[0].Register.Index = dst_index;
    inst.Instruction.NumSrcRegs = 2;
    inst.Instruction.Texture = TRUE;
    inst.Texture.Texture = tex_target;
-   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;
+   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);
 }
 
 
 extern int
 tgsi_transform_shader(const struct tgsi_token *tokens_in,
                       struct tgsi_token *tokens_out,
                       uint max_tokens_out,
                       struct tgsi_transform_context *ctx);
-- 
2.11.0



More information about the mesa-dev mailing list