Add declaration_semantic token to TGSI.
authormichal <michal@michal-laptop.(none)>
Wed, 15 Aug 2007 12:55:22 +0000 (13:55 +0100)
committermichal <michal@michal-laptop.(none)>
Wed, 15 Aug 2007 12:55:22 +0000 (13:55 +0100)
Cosmetic changes, GLuint -> unsigned.
Preserve mesa gl_fragment_program DEPTH and COLOR semantics.

src/mesa/pipe/tgsi/core/tgsi_build.c
src/mesa/pipe/tgsi/core/tgsi_build.h
src/mesa/pipe/tgsi/core/tgsi_dump.c
src/mesa/pipe/tgsi/core/tgsi_parse.c
src/mesa/pipe/tgsi/core/tgsi_parse.h
src/mesa/pipe/tgsi/core/tgsi_token.h
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c

index bbf4a89..d9c9a45 100644 (file)
@@ -35,8 +35,8 @@ tgsi_build_header( void )
 static void
 header_headersize_grow( struct tgsi_header *header )
 {
-   assert (header->HeaderSize < 0xFF);
-   assert (header->BodySize == 0);
+   assert( header->HeaderSize < 0xFF );
+   assert( header->BodySize == 0 );
 
    header->HeaderSize++;
 }
@@ -44,7 +44,7 @@ header_headersize_grow( struct tgsi_header *header )
 static void
 header_bodysize_grow( struct tgsi_header *header )
 {
-   assert (header->BodySize < 0xFFFFFF);
+   assert( header->BodySize < 0xFFFFFF );
 
    header->BodySize++;
 }
@@ -62,7 +62,7 @@ tgsi_default_processor( void )
 
 struct tgsi_processor
 tgsi_build_processor(
-   GLuint type,
+   unsigned type,
    struct tgsi_header *header )
 {
    struct tgsi_processor processor;
@@ -89,6 +89,7 @@ tgsi_default_declaration( void )
    declaration.File = TGSI_FILE_NULL;
    declaration.Declare = TGSI_DECLARE_RANGE;
    declaration.Interpolate = 0;
+   declaration.Semantic = 0;
    declaration.Padding = 0;
    declaration.Extended = 0;
 
@@ -97,20 +98,22 @@ tgsi_default_declaration( void )
 
 struct tgsi_declaration
 tgsi_build_declaration(
-   GLuint file,
-   GLuint declare,
-   GLuint interpolate,
+   unsigned file,
+   unsigned declare,
+   unsigned interpolate,
+   unsigned semantic,
    struct tgsi_header *header )
 {
    struct tgsi_declaration declaration;
 
-   assert (file <= TGSI_FILE_IMMEDIATE);
-   assert (declare <= TGSI_DECLARE_MASK);
+   assert( file <= TGSI_FILE_IMMEDIATE );
+   assert( declare <= TGSI_DECLARE_MASK );
 
    declaration = tgsi_default_declaration();
    declaration.File = file;
    declaration.Declare = declare;
    declaration.Interpolate = interpolate;
+   declaration.Semantic = semantic;
 
    header_bodysize_grow( header );
 
@@ -122,7 +125,7 @@ declaration_grow(
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
-   assert (declaration->Size < 0xFF);
+   assert( declaration->Size < 0xFF );
 
    declaration->Size++;
 
@@ -136,18 +139,19 @@ tgsi_default_full_declaration( void )
 
    full_declaration.Declaration  = tgsi_default_declaration();
    full_declaration.Interpolation = tgsi_default_declaration_interpolation();
+   full_declaration.Semantic = tgsi_default_declaration_semantic();
 
    return full_declaration;
 }
 
-GLuint
+unsigned
 tgsi_build_full_declaration(
-   const struct   tgsi_full_declaration *full_decl,
+   const struct tgsi_full_declaration *full_decl,
    struct tgsi_token *tokens,
    struct tgsi_header *header,
-   GLuint maxsize )
+   unsigned maxsize )
 {
-   GLuint size = 0;
+   unsigned size = 0;
    struct tgsi_declaration *declaration;
 
    if( maxsize <= size )
@@ -159,14 +163,15 @@ tgsi_build_full_declaration(
       full_decl->Declaration.File,
       full_decl->Declaration.Declare,
       full_decl->Declaration.Interpolate,
+      full_decl->Declaration.Semantic,
       header );
 
    switch( full_decl->Declaration.Declare )  {
-   case  TGSI_DECLARE_RANGE:
+   case TGSI_DECLARE_RANGE:
    {
       struct tgsi_declaration_range *dr;
 
-      if( maxsize <=   size )
+      if( maxsize <= size )
          return 0;
       dr = (struct tgsi_declaration_range *) &tokens[size];
       size++;
@@ -179,11 +184,11 @@ tgsi_build_full_declaration(
       break;
     }
 
-   case  TGSI_DECLARE_MASK:
+   case TGSI_DECLARE_MASK:
    {
-      struct  tgsi_declaration_mask *dm;
+      struct tgsi_declaration_mask *dm;
 
-      if( maxsize <=   size )
+      if( maxsize <= size )
          return 0;
       dm = (struct tgsi_declaration_mask  *) &tokens[size];
       size++;
@@ -213,20 +218,35 @@ tgsi_build_full_declaration(
          header );
    }
 
+   if( full_decl->Declaration.Semantic ) {
+      struct tgsi_declaration_semantic *ds;
+
+      if( maxsize <= size )
+         return  0;
+      ds = (struct tgsi_declaration_semantic *) &tokens[size];
+      size++;
+
+      *ds = tgsi_build_declaration_semantic(
+         full_decl->Semantic.SemanticName,
+         full_decl->Semantic.SemanticIndex,
+         declaration,
+         header );
+   }
+
    return size;
 }
 
 struct tgsi_declaration_range
 tgsi_build_declaration_range(
-   GLuint first,
-   GLuint last,
+   unsigned first,
+   unsigned last,
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
    struct tgsi_declaration_range declaration_range;
 
-   assert (last >=   first);
-   assert (last <=   0xFFFF);
+   assert( last >= first );
+   assert( last <= 0xFFFF );
 
    declaration_range.First = first;
    declaration_range.Last = last;
@@ -238,7 +258,7 @@ tgsi_build_declaration_range(
 
 struct tgsi_declaration_mask
 tgsi_build_declaration_mask(
-   GLuint mask,
+   unsigned mask,
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
@@ -264,7 +284,7 @@ tgsi_default_declaration_interpolation( void )
 
 struct tgsi_declaration_interpolation
 tgsi_build_declaration_interpolation(
-   GLuint interpolate,
+   unsigned interpolate,
    struct tgsi_declaration *declaration,
    struct tgsi_header *header )
 {
@@ -280,6 +300,39 @@ tgsi_build_declaration_interpolation(
    return di;
 }
 
+struct tgsi_declaration_semantic
+tgsi_default_declaration_semantic( void )
+{
+   struct tgsi_declaration_semantic ds;
+
+   ds.SemanticName = TGSI_SEMANTIC_DEPTH;
+   ds.SemanticIndex = 0;
+   ds.Padding = 0;
+
+   return ds;
+}
+
+struct tgsi_declaration_semantic
+tgsi_build_declaration_semantic(
+   unsigned semantic_name,
+   unsigned semantic_index,
+   struct tgsi_declaration *declaration,
+   struct tgsi_header *header )
+{
+   struct tgsi_declaration_semantic ds;
+
+   assert( semantic_name <= TGSI_SEMANTIC_COLOR );
+   assert( semantic_index <= 0xFFFF );
+
+   ds = tgsi_default_declaration_semantic();
+   ds.SemanticName = semantic_name;
+   ds.SemanticIndex = semantic_index;
+
+   declaration_grow( declaration, header );
+
+   return ds;
+}
+
 /*
  * immediate
  */
index 8b5db56..b3eb071 100644 (file)
@@ -39,6 +39,7 @@ tgsi_build_declaration(
    unsigned file,
    unsigned declare,
    unsigned interpolate,
+   unsigned semantic,
    struct tgsi_header *header );
 
 struct tgsi_full_declaration
@@ -73,6 +74,16 @@ tgsi_build_declaration_interpolation(
    struct tgsi_declaration *declaration,
    struct tgsi_header *header );
 
+struct tgsi_declaration_semantic
+tgsi_default_declaration_semantic( void );
+
+struct tgsi_declaration_semantic
+tgsi_build_declaration_semantic(
+   unsigned semantic_name,
+   unsigned semantic_index,
+   struct tgsi_declaration *declaration,
+   struct tgsi_header *header );
+
 /*
  * immediate
  */
index 51d3bb7..5a9f920 100644 (file)
@@ -199,6 +199,18 @@ static const char *TGSI_INTERPOLATES_SHORT[] =
    "PERSPECTIVE"
 };
 
+static const char *TGSI_SEMANTICS[] =
+{
+   "SEMANTIC_DEPTH",
+   "SEMANTIC_COLOR"
+};
+
+static const char *TGSI_SEMANTICS_SHORT[] =
+{
+   "DEPTH",
+   "COLOR"
+};
+
 static const char *TGSI_IMMS[] =
 {
    "IMM_FLOAT32"
@@ -625,6 +637,14 @@ dump_declaration_short(
       TXT( ", " );
       ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES_SHORT );
    }
+
+   if( decl->Declaration.Semantic ) {
+      TXT( ", " );
+      ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS_SHORT );
+      CHR( '[' );
+      UID( decl->Semantic.SemanticIndex );
+      CHR( ']' );
+   }
 }
 
 static void
@@ -643,6 +663,10 @@ dump_declaration_verbose(
       TXT( "\nInterpolate: " );
       UID( decl->Declaration.Interpolate );
    }
+   if( deflt || fd->Declaration.Semantic != decl->Declaration.Semantic ) {
+      TXT( "\nSemantic   : " );
+      UID( decl->Declaration.Semantic );
+   }
    if( ignored ) {
       TXT( "\nPadding    : " );
       UIX( decl->Declaration.Padding );
@@ -675,6 +699,18 @@ dump_declaration_verbose(
          UIX( decl->Interpolation.Padding );
       }
    }
+
+   if( decl->Declaration.Semantic ) {
+      CHR( '\n' );
+      TXT( "\nSemanticName : " );
+      ENM( decl->Semantic.SemanticName, TGSI_SEMANTICS );
+      TXT( "\nSemanticIndex: " );
+      UID( decl->Semantic.SemanticIndex );
+      if( ignored ) {
+         TXT( "\nPadding      : " );
+         UIX( decl->Semantic.Padding );
+      }
+   }
 }
 
 static void
index df34fa7..a6724d7 100644 (file)
@@ -16,7 +16,7 @@ tgsi_full_token_free(
       free( full_token->FullImmediate.u.Pointer );
 }
 
-GLuint
+unsigned
 tgsi_parse_init(
    struct tgsi_parse_context *ctx,
    const struct tgsi_token *tokens )
@@ -72,7 +72,7 @@ tgsi_parse_token(
    struct tgsi_parse_context *ctx )
 {
    struct tgsi_token token;
-   GLuint i;
+   unsigned i;
 
    tgsi_full_token_free( &ctx->FullToken );
    tgsi_full_token_init( &ctx->FullToken );
@@ -104,6 +104,10 @@ tgsi_parse_token(
          next_token( ctx, &decl->Interpolation );
       }
 
+      if( decl->Declaration.Semantic ) {
+         next_token( ctx, &decl->Semantic );
+      }
+
       break;
    }
 
@@ -135,7 +139,7 @@ tgsi_parse_token(
    case TGSI_TOKEN_TYPE_INSTRUCTION:
    {
       struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction;
-      GLuint extended;
+      unsigned extended;
 
       *inst = tgsi_default_full_instruction();
       inst->Instruction = *(struct tgsi_instruction *) &token;
@@ -173,7 +177,7 @@ tgsi_parse_token(
       assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS );
 
       for(  i = 0; i < inst->Instruction.NumDstRegs; i++ ) {
-         GLuint extended;
+         unsigned extended;
 
          next_token( ctx, &inst->FullDstRegisters[i].DstRegister );
 
@@ -212,7 +216,7 @@ tgsi_parse_token(
       assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS );
 
       for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) {
-         GLuint extended;
+         unsigned extended;
 
          next_token( ctx, &inst->FullSrcRegisters[i].SrcRegister );
 
index bba0143..56a8c25 100644 (file)
@@ -42,6 +42,7 @@ struct tgsi_full_declaration
       struct tgsi_declaration_mask  DeclarationMask;
    } u;
    struct tgsi_declaration_interpolation  Interpolation;
+   struct tgsi_declaration_semantic       Semantic;
 };
 
 struct tgsi_full_immediate
@@ -86,7 +87,7 @@ tgsi_full_token_free(
 struct tgsi_parse_context
 {
    const struct tgsi_token    *Tokens;
-   unsigned                     Position;
+   unsigned                   Position;
    struct tgsi_full_version   FullVersion;
    struct tgsi_full_header    FullHeader;
    union tgsi_full_token      FullToken;
index dc9301e..f72c7dc 100644 (file)
@@ -54,13 +54,14 @@ struct tgsi_token
 
 struct tgsi_declaration
 {
-   unsigned Type          : 4;  /* TGSI_TOKEN_TYPE_DECLARATION */
-   unsigned Size          : 8;  /* UINT */
-   unsigned File          : 4;  /* TGSI_FILE_ */
-   unsigned Declare       : 4;  /* TGSI_DECLARE_ */
-   unsigned Interpolate   : 1;  /* BOOL */
-   unsigned Padding       : 10;
-   unsigned Extended      : 1;  /* BOOL */
+   unsigned Type        : 4;  /* TGSI_TOKEN_TYPE_DECLARATION */
+   unsigned Size        : 8;  /* UINT */
+   unsigned File        : 4;  /* TGSI_FILE_ */
+   unsigned Declare     : 4;  /* TGSI_DECLARE_ */
+   unsigned Interpolate : 1;  /* BOOL */
+   unsigned Semantic    : 1;  /* BOOL */
+   unsigned Padding     : 9;
+   unsigned Extended    : 1;  /* BOOL */
 };
 
 struct tgsi_declaration_range
@@ -84,6 +85,16 @@ struct tgsi_declaration_interpolation
    unsigned Padding       : 28;
 };
 
+#define TGSI_SEMANTIC_DEPTH   0
+#define TGSI_SEMANTIC_COLOR   1
+
+struct tgsi_declaration_semantic
+{
+   unsigned SemanticName   : 8;  /* TGSI_SEMANTIC_ */
+   unsigned SemanticIndex  : 16; /* UINT */
+   unsigned Padding        : 8;
+};
+
 #define TGSI_IMM_FLOAT32   0
 
 struct tgsi_immediate
@@ -1261,16 +1272,16 @@ struct tgsi_instruction_ext_predicate
 
 struct tgsi_src_register
 {
-   unsigned File         : 4;    /* TGSI_FILE_ */
-   unsigned SwizzleX     : 2;    /* TGSI_SWIZZLE_ */
-   unsigned SwizzleY     : 2;    /* TGSI_SWIZZLE_ */
-   unsigned SwizzleZ     : 2;    /* TGSI_SWIZZLE_ */
-   unsigned SwizzleW     : 2;    /* TGSI_SWIZZLE_ */
-   unsigned Negate       : 1;    /* BOOL */
-   unsigned Indirect     : 1;    /* BOOL */
-   unsigned Dimension    : 1;    /* BOOL */
-   int  Index        : 16;   /* SINT */
-   unsigned Extended     : 1;    /* BOOL */
+   unsigned File        : 4;  /* TGSI_FILE_ */
+   unsigned SwizzleX    : 2;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleY    : 2;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleZ    : 2;  /* TGSI_SWIZZLE_ */
+   unsigned SwizzleW    : 2;  /* TGSI_SWIZZLE_ */
+   unsigned Negate      : 1;  /* BOOL */
+   unsigned Indirect    : 1;  /* BOOL */
+   unsigned Dimension   : 1;  /* BOOL */
+   int      Index       : 16; /* SINT */
+   unsigned Extended    : 1;  /* BOOL */
 };
 
 /*
@@ -1364,22 +1375,22 @@ struct tgsi_src_register_ext_mod
 
 struct tgsi_dimension
 {
-   unsigned Indirect     : 1;    /* BOOL */
-   unsigned Dimension    : 1;    /* BOOL */
-   unsigned Padding      : 13;
-   int  Index        : 16;   /* SINT */
-   unsigned Extended     : 1;    /* BOOL */
+   unsigned Indirect    : 1;  /* BOOL */
+   unsigned Dimension   : 1;  /* BOOL */
+   unsigned Padding     : 13;
+   int      Index       : 16; /* SINT */
+   unsigned Extended    : 1;  /* BOOL */
 };
 
 struct tgsi_dst_register
 {
-   unsigned File         : 4;    /* TGSI_FILE_ */
-   unsigned WriteMask    : 4;    /* TGSI_WRITEMASK_ */
-   unsigned Indirect     : 1;    /* BOOL */
-   unsigned Dimension    : 1;    /* BOOL */
-   int  Index        : 16;   /* SINT */
-   unsigned Padding      : 5;
-   unsigned Extended     : 1;    /* BOOL */
+   unsigned File        : 4;  /* TGSI_FILE_ */
+   unsigned WriteMask   : 4;  /* TGSI_WRITEMASK_ */
+   unsigned Indirect    : 1;  /* BOOL */
+   unsigned Dimension   : 1;  /* BOOL */
+   int      Index       : 16; /* SINT */
+   unsigned Padding     : 5;
+   unsigned Extended    : 1;  /* BOOL */
 };
 
 /*
index 690339b..609d329 100644 (file)
@@ -464,25 +464,39 @@ compile_instruction(
 }\r
 \r
 static struct tgsi_full_declaration\r
-make_declaration(\r
-   GLuint file,\r
+make_frag_input_decl(\r
    GLuint first,\r
    GLuint last,\r
-   GLboolean do_interpolate,\r
    GLuint interpolate )\r
 {\r
    struct tgsi_full_declaration decl;\r
 \r
    decl = tgsi_default_full_declaration();\r
-   decl.Declaration.File = file;\r
+   decl.Declaration.File = TGSI_FILE_INPUT;\r
    decl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
+   decl.Declaration.Interpolate = 1;\r
    decl.u.DeclarationRange.First = first;\r
    decl.u.DeclarationRange.Last = last;\r
+   decl.Interpolation.Interpolate = interpolate;\r
 \r
-   if( do_interpolate ) {\r
-      decl.Declaration.Interpolate = 1;\r
-      decl.Interpolation.Interpolate = interpolate;\r
-   }\r
+   return decl;\r
+}\r
+\r
+static struct tgsi_full_declaration\r
+make_frag_output_decl(\r
+   GLuint index,\r
+   GLuint semantic_name )\r
+{\r
+   struct tgsi_full_declaration decl;\r
+\r
+   decl = tgsi_default_full_declaration();\r
+   decl.Declaration.File = TGSI_FILE_OUTPUT;\r
+   decl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
+   decl.Declaration.Semantic = 1;\r
+   decl.u.DeclarationRange.First = index;\r
+   decl.u.DeclarationRange.Last = index;\r
+   decl.Semantic.SemanticName = semantic_name;\r
+   decl.Semantic.SemanticIndex = 0;\r
 \r
    return decl;\r
 }\r
@@ -518,11 +532,9 @@ tgsi_mesa_compile_fp_program(
    /*\r
     * Declare input attributes. Note that we do not interpolate fragment position.\r
     */\r
-   fulldecl = make_declaration(\r
-      TGSI_FILE_INPUT,\r
+   fulldecl = make_frag_input_decl(\r
       0,\r
       0,\r
-      GL_TRUE,\r
       TGSI_INTERPOLATE_CONSTANT );\r
    ti += tgsi_build_full_declaration(\r
       &fulldecl,\r
@@ -537,11 +549,9 @@ tgsi_mesa_compile_fp_program(
       }\r
    }\r
    if( count > 0 ) {\r
-      fulldecl = make_declaration(\r
-         TGSI_FILE_INPUT,\r
+      fulldecl = make_frag_input_decl(\r
          1,\r
-         count + 1,\r
-         GL_TRUE,\r
+         1 + count - 1,\r
          TGSI_INTERPOLATE_LINEAR );\r
       ti += tgsi_build_full_declaration(\r
          &fulldecl,\r
@@ -557,12 +567,9 @@ tgsi_mesa_compile_fp_program(
       program->Base.OutputsWritten ==\r
       (program->Base.OutputsWritten & ((1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR))) );\r
 \r
-   fulldecl = make_declaration(\r
-      TGSI_FILE_OUTPUT,\r
-      0,\r
+   fulldecl = make_frag_output_decl(\r
       0,\r
-      GL_FALSE,\r
-      0 );\r
+      TGSI_SEMANTIC_DEPTH );\r
    ti += tgsi_build_full_declaration(\r
       &fulldecl,\r
       &tokens[ti],\r
@@ -570,12 +577,9 @@ tgsi_mesa_compile_fp_program(
       maxTokens - ti );\r
 \r
    if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) {\r
-      fulldecl = make_declaration(\r
-         TGSI_FILE_OUTPUT,\r
-         1,\r
+      fulldecl = make_frag_output_decl(\r
          1,\r
-         GL_FALSE,\r
-         0 );\r
+         TGSI_SEMANTIC_COLOR );\r
       ti += tgsi_build_full_declaration(\r
          &fulldecl,\r
          &tokens[ti],\r