From: michal Date: Wed, 15 Aug 2007 12:55:22 +0000 (+0100) Subject: Add declaration_semantic token to TGSI. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b9eeb8dccff3b440a299f19a0868a3ff1cda1e09;p=mesa.git Add declaration_semantic token to TGSI. Cosmetic changes, GLuint -> unsigned. Preserve mesa gl_fragment_program DEPTH and COLOR semantics. --- diff --git a/src/mesa/pipe/tgsi/core/tgsi_build.c b/src/mesa/pipe/tgsi/core/tgsi_build.c index bbf4a89a5e3..d9c9a45532d 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_build.c +++ b/src/mesa/pipe/tgsi/core/tgsi_build.c @@ -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 */ diff --git a/src/mesa/pipe/tgsi/core/tgsi_build.h b/src/mesa/pipe/tgsi/core/tgsi_build.h index 8b5db5662c9..b3eb0715eef 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_build.h +++ b/src/mesa/pipe/tgsi/core/tgsi_build.h @@ -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 */ diff --git a/src/mesa/pipe/tgsi/core/tgsi_dump.c b/src/mesa/pipe/tgsi/core/tgsi_dump.c index 51d3bb703dc..5a9f92004ed 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_dump.c +++ b/src/mesa/pipe/tgsi/core/tgsi_dump.c @@ -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 diff --git a/src/mesa/pipe/tgsi/core/tgsi_parse.c b/src/mesa/pipe/tgsi/core/tgsi_parse.c index df34fa7d7ef..a6724d762c7 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_parse.c +++ b/src/mesa/pipe/tgsi/core/tgsi_parse.c @@ -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 ); diff --git a/src/mesa/pipe/tgsi/core/tgsi_parse.h b/src/mesa/pipe/tgsi/core/tgsi_parse.h index bba01431fac..56a8c254c29 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_parse.h +++ b/src/mesa/pipe/tgsi/core/tgsi_parse.h @@ -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; diff --git a/src/mesa/pipe/tgsi/core/tgsi_token.h b/src/mesa/pipe/tgsi/core/tgsi_token.h index dc9301ed374..f72c7dc4be4 100644 --- a/src/mesa/pipe/tgsi/core/tgsi_token.h +++ b/src/mesa/pipe/tgsi/core/tgsi_token.h @@ -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 */ }; /* diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index 690339bc660..609d3292428 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -464,25 +464,39 @@ compile_instruction( } static struct tgsi_full_declaration -make_declaration( - GLuint file, +make_frag_input_decl( GLuint first, GLuint last, - GLboolean do_interpolate, GLuint interpolate ) { struct tgsi_full_declaration decl; decl = tgsi_default_full_declaration(); - decl.Declaration.File = file; + decl.Declaration.File = TGSI_FILE_INPUT; decl.Declaration.Declare = TGSI_DECLARE_RANGE; + decl.Declaration.Interpolate = 1; decl.u.DeclarationRange.First = first; decl.u.DeclarationRange.Last = last; + decl.Interpolation.Interpolate = interpolate; - if( do_interpolate ) { - decl.Declaration.Interpolate = 1; - decl.Interpolation.Interpolate = interpolate; - } + return decl; +} + +static struct tgsi_full_declaration +make_frag_output_decl( + GLuint index, + GLuint semantic_name ) +{ + struct tgsi_full_declaration decl; + + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_OUTPUT; + decl.Declaration.Declare = TGSI_DECLARE_RANGE; + decl.Declaration.Semantic = 1; + decl.u.DeclarationRange.First = index; + decl.u.DeclarationRange.Last = index; + decl.Semantic.SemanticName = semantic_name; + decl.Semantic.SemanticIndex = 0; return decl; } @@ -518,11 +532,9 @@ tgsi_mesa_compile_fp_program( /* * Declare input attributes. Note that we do not interpolate fragment position. */ - fulldecl = make_declaration( - TGSI_FILE_INPUT, + fulldecl = make_frag_input_decl( 0, 0, - GL_TRUE, TGSI_INTERPOLATE_CONSTANT ); ti += tgsi_build_full_declaration( &fulldecl, @@ -537,11 +549,9 @@ tgsi_mesa_compile_fp_program( } } if( count > 0 ) { - fulldecl = make_declaration( - TGSI_FILE_INPUT, + fulldecl = make_frag_input_decl( 1, - count + 1, - GL_TRUE, + 1 + count - 1, TGSI_INTERPOLATE_LINEAR ); ti += tgsi_build_full_declaration( &fulldecl, @@ -557,12 +567,9 @@ tgsi_mesa_compile_fp_program( program->Base.OutputsWritten == (program->Base.OutputsWritten & ((1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR))) ); - fulldecl = make_declaration( - TGSI_FILE_OUTPUT, - 0, + fulldecl = make_frag_output_decl( 0, - GL_FALSE, - 0 ); + TGSI_SEMANTIC_DEPTH ); ti += tgsi_build_full_declaration( &fulldecl, &tokens[ti], @@ -570,12 +577,9 @@ tgsi_mesa_compile_fp_program( maxTokens - ti ); if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) { - fulldecl = make_declaration( - TGSI_FILE_OUTPUT, - 1, + fulldecl = make_frag_output_decl( 1, - GL_FALSE, - 0 ); + TGSI_SEMANTIC_COLOR ); ti += tgsi_build_full_declaration( &fulldecl, &tokens[ti],