Add declaration_semantic token to TGSI.

Cosmetic changes, GLuint -> unsigned.
Preserve mesa gl_fragment_program DEPTH and COLOR semantics.
This commit is contained in:
michal
2007-08-15 13:55:22 +01:00
parent 6504dc3178
commit b9eeb8dccf
7 changed files with 205 additions and 85 deletions

View File

@@ -35,8 +35,8 @@ tgsi_build_header( void )
static void static void
header_headersize_grow( struct tgsi_header *header ) header_headersize_grow( struct tgsi_header *header )
{ {
assert (header->HeaderSize < 0xFF); assert( header->HeaderSize < 0xFF );
assert (header->BodySize == 0); assert( header->BodySize == 0 );
header->HeaderSize++; header->HeaderSize++;
} }
@@ -44,7 +44,7 @@ header_headersize_grow( struct tgsi_header *header )
static void static void
header_bodysize_grow( struct tgsi_header *header ) header_bodysize_grow( struct tgsi_header *header )
{ {
assert (header->BodySize < 0xFFFFFF); assert( header->BodySize < 0xFFFFFF );
header->BodySize++; header->BodySize++;
} }
@@ -62,7 +62,7 @@ tgsi_default_processor( void )
struct tgsi_processor struct tgsi_processor
tgsi_build_processor( tgsi_build_processor(
GLuint type, unsigned type,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
struct tgsi_processor processor; struct tgsi_processor processor;
@@ -89,6 +89,7 @@ tgsi_default_declaration( void )
declaration.File = TGSI_FILE_NULL; declaration.File = TGSI_FILE_NULL;
declaration.Declare = TGSI_DECLARE_RANGE; declaration.Declare = TGSI_DECLARE_RANGE;
declaration.Interpolate = 0; declaration.Interpolate = 0;
declaration.Semantic = 0;
declaration.Padding = 0; declaration.Padding = 0;
declaration.Extended = 0; declaration.Extended = 0;
@@ -97,20 +98,22 @@ tgsi_default_declaration( void )
struct tgsi_declaration struct tgsi_declaration
tgsi_build_declaration( tgsi_build_declaration(
GLuint file, unsigned file,
GLuint declare, unsigned declare,
GLuint interpolate, unsigned interpolate,
unsigned semantic,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
struct tgsi_declaration declaration; struct tgsi_declaration declaration;
assert (file <= TGSI_FILE_IMMEDIATE); assert( file <= TGSI_FILE_IMMEDIATE );
assert (declare <= TGSI_DECLARE_MASK); assert( declare <= TGSI_DECLARE_MASK );
declaration = tgsi_default_declaration(); declaration = tgsi_default_declaration();
declaration.File = file; declaration.File = file;
declaration.Declare = declare; declaration.Declare = declare;
declaration.Interpolate = interpolate; declaration.Interpolate = interpolate;
declaration.Semantic = semantic;
header_bodysize_grow( header ); header_bodysize_grow( header );
@@ -122,7 +125,7 @@ declaration_grow(
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
assert (declaration->Size < 0xFF); assert( declaration->Size < 0xFF );
declaration->Size++; declaration->Size++;
@@ -136,18 +139,19 @@ tgsi_default_full_declaration( void )
full_declaration.Declaration = tgsi_default_declaration(); full_declaration.Declaration = tgsi_default_declaration();
full_declaration.Interpolation = tgsi_default_declaration_interpolation(); full_declaration.Interpolation = tgsi_default_declaration_interpolation();
full_declaration.Semantic = tgsi_default_declaration_semantic();
return full_declaration; return full_declaration;
} }
GLuint unsigned
tgsi_build_full_declaration( tgsi_build_full_declaration(
const struct tgsi_full_declaration *full_decl, const struct tgsi_full_declaration *full_decl,
struct tgsi_token *tokens, struct tgsi_token *tokens,
struct tgsi_header *header, struct tgsi_header *header,
GLuint maxsize ) unsigned maxsize )
{ {
GLuint size = 0; unsigned size = 0;
struct tgsi_declaration *declaration; struct tgsi_declaration *declaration;
if( maxsize <= size ) if( maxsize <= size )
@@ -159,14 +163,15 @@ tgsi_build_full_declaration(
full_decl->Declaration.File, full_decl->Declaration.File,
full_decl->Declaration.Declare, full_decl->Declaration.Declare,
full_decl->Declaration.Interpolate, full_decl->Declaration.Interpolate,
full_decl->Declaration.Semantic,
header ); header );
switch( full_decl->Declaration.Declare ) { switch( full_decl->Declaration.Declare ) {
case TGSI_DECLARE_RANGE: case TGSI_DECLARE_RANGE:
{ {
struct tgsi_declaration_range *dr; struct tgsi_declaration_range *dr;
if( maxsize <= size ) if( maxsize <= size )
return 0; return 0;
dr = (struct tgsi_declaration_range *) &tokens[size]; dr = (struct tgsi_declaration_range *) &tokens[size];
size++; size++;
@@ -179,11 +184,11 @@ tgsi_build_full_declaration(
break; 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; return 0;
dm = (struct tgsi_declaration_mask *) &tokens[size]; dm = (struct tgsi_declaration_mask *) &tokens[size];
size++; size++;
@@ -213,20 +218,35 @@ tgsi_build_full_declaration(
header ); 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; return size;
} }
struct tgsi_declaration_range struct tgsi_declaration_range
tgsi_build_declaration_range( tgsi_build_declaration_range(
GLuint first, unsigned first,
GLuint last, unsigned last,
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
struct tgsi_declaration_range declaration_range; struct tgsi_declaration_range declaration_range;
assert (last >= first); assert( last >= first );
assert (last <= 0xFFFF); assert( last <= 0xFFFF );
declaration_range.First = first; declaration_range.First = first;
declaration_range.Last = last; declaration_range.Last = last;
@@ -238,7 +258,7 @@ tgsi_build_declaration_range(
struct tgsi_declaration_mask struct tgsi_declaration_mask
tgsi_build_declaration_mask( tgsi_build_declaration_mask(
GLuint mask, unsigned mask,
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
@@ -264,7 +284,7 @@ tgsi_default_declaration_interpolation( void )
struct tgsi_declaration_interpolation struct tgsi_declaration_interpolation
tgsi_build_declaration_interpolation( tgsi_build_declaration_interpolation(
GLuint interpolate, unsigned interpolate,
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header ) struct tgsi_header *header )
{ {
@@ -280,6 +300,39 @@ tgsi_build_declaration_interpolation(
return di; 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 * immediate
*/ */

View File

@@ -39,6 +39,7 @@ tgsi_build_declaration(
unsigned file, unsigned file,
unsigned declare, unsigned declare,
unsigned interpolate, unsigned interpolate,
unsigned semantic,
struct tgsi_header *header ); struct tgsi_header *header );
struct tgsi_full_declaration struct tgsi_full_declaration
@@ -73,6 +74,16 @@ tgsi_build_declaration_interpolation(
struct tgsi_declaration *declaration, struct tgsi_declaration *declaration,
struct tgsi_header *header ); 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 * immediate
*/ */

View File

@@ -199,6 +199,18 @@ static const char *TGSI_INTERPOLATES_SHORT[] =
"PERSPECTIVE" "PERSPECTIVE"
}; };
static const char *TGSI_SEMANTICS[] =
{
"SEMANTIC_DEPTH",
"SEMANTIC_COLOR"
};
static const char *TGSI_SEMANTICS_SHORT[] =
{
"DEPTH",
"COLOR"
};
static const char *TGSI_IMMS[] = static const char *TGSI_IMMS[] =
{ {
"IMM_FLOAT32" "IMM_FLOAT32"
@@ -625,6 +637,14 @@ dump_declaration_short(
TXT( ", " ); TXT( ", " );
ENM( decl->Interpolation.Interpolate, TGSI_INTERPOLATES_SHORT ); 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 static void
@@ -643,6 +663,10 @@ dump_declaration_verbose(
TXT( "\nInterpolate: " ); TXT( "\nInterpolate: " );
UID( decl->Declaration.Interpolate ); UID( decl->Declaration.Interpolate );
} }
if( deflt || fd->Declaration.Semantic != decl->Declaration.Semantic ) {
TXT( "\nSemantic : " );
UID( decl->Declaration.Semantic );
}
if( ignored ) { if( ignored ) {
TXT( "\nPadding : " ); TXT( "\nPadding : " );
UIX( decl->Declaration.Padding ); UIX( decl->Declaration.Padding );
@@ -675,6 +699,18 @@ dump_declaration_verbose(
UIX( decl->Interpolation.Padding ); 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 static void

View File

@@ -16,7 +16,7 @@ tgsi_full_token_free(
free( full_token->FullImmediate.u.Pointer ); free( full_token->FullImmediate.u.Pointer );
} }
GLuint unsigned
tgsi_parse_init( tgsi_parse_init(
struct tgsi_parse_context *ctx, struct tgsi_parse_context *ctx,
const struct tgsi_token *tokens ) const struct tgsi_token *tokens )
@@ -72,7 +72,7 @@ tgsi_parse_token(
struct tgsi_parse_context *ctx ) struct tgsi_parse_context *ctx )
{ {
struct tgsi_token token; struct tgsi_token token;
GLuint i; unsigned i;
tgsi_full_token_free( &ctx->FullToken ); tgsi_full_token_free( &ctx->FullToken );
tgsi_full_token_init( &ctx->FullToken ); tgsi_full_token_init( &ctx->FullToken );
@@ -104,6 +104,10 @@ tgsi_parse_token(
next_token( ctx, &decl->Interpolation ); next_token( ctx, &decl->Interpolation );
} }
if( decl->Declaration.Semantic ) {
next_token( ctx, &decl->Semantic );
}
break; break;
} }
@@ -135,7 +139,7 @@ tgsi_parse_token(
case TGSI_TOKEN_TYPE_INSTRUCTION: case TGSI_TOKEN_TYPE_INSTRUCTION:
{ {
struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction; struct tgsi_full_instruction *inst = &ctx->FullToken.FullInstruction;
GLuint extended; unsigned extended;
*inst = tgsi_default_full_instruction(); *inst = tgsi_default_full_instruction();
inst->Instruction = *(struct tgsi_instruction *) &token; inst->Instruction = *(struct tgsi_instruction *) &token;
@@ -173,7 +177,7 @@ tgsi_parse_token(
assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS ); assert( inst->Instruction.NumDstRegs <= TGSI_FULL_MAX_DST_REGISTERS );
for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) { for( i = 0; i < inst->Instruction.NumDstRegs; i++ ) {
GLuint extended; unsigned extended;
next_token( ctx, &inst->FullDstRegisters[i].DstRegister ); next_token( ctx, &inst->FullDstRegisters[i].DstRegister );
@@ -212,7 +216,7 @@ tgsi_parse_token(
assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS ); assert( inst->Instruction.NumSrcRegs <= TGSI_FULL_MAX_SRC_REGISTERS );
for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) { for( i = 0; i < inst->Instruction.NumSrcRegs; i++ ) {
GLuint extended; unsigned extended;
next_token( ctx, &inst->FullSrcRegisters[i].SrcRegister ); next_token( ctx, &inst->FullSrcRegisters[i].SrcRegister );

View File

@@ -42,6 +42,7 @@ struct tgsi_full_declaration
struct tgsi_declaration_mask DeclarationMask; struct tgsi_declaration_mask DeclarationMask;
} u; } u;
struct tgsi_declaration_interpolation Interpolation; struct tgsi_declaration_interpolation Interpolation;
struct tgsi_declaration_semantic Semantic;
}; };
struct tgsi_full_immediate struct tgsi_full_immediate
@@ -86,7 +87,7 @@ tgsi_full_token_free(
struct tgsi_parse_context struct tgsi_parse_context
{ {
const struct tgsi_token *Tokens; const struct tgsi_token *Tokens;
unsigned Position; unsigned Position;
struct tgsi_full_version FullVersion; struct tgsi_full_version FullVersion;
struct tgsi_full_header FullHeader; struct tgsi_full_header FullHeader;
union tgsi_full_token FullToken; union tgsi_full_token FullToken;

View File

@@ -54,13 +54,14 @@ struct tgsi_token
struct tgsi_declaration struct tgsi_declaration
{ {
unsigned Type : 4; /* TGSI_TOKEN_TYPE_DECLARATION */ unsigned Type : 4; /* TGSI_TOKEN_TYPE_DECLARATION */
unsigned Size : 8; /* UINT */ unsigned Size : 8; /* UINT */
unsigned File : 4; /* TGSI_FILE_ */ unsigned File : 4; /* TGSI_FILE_ */
unsigned Declare : 4; /* TGSI_DECLARE_ */ unsigned Declare : 4; /* TGSI_DECLARE_ */
unsigned Interpolate : 1; /* BOOL */ unsigned Interpolate : 1; /* BOOL */
unsigned Padding : 10; unsigned Semantic : 1; /* BOOL */
unsigned Extended : 1; /* BOOL */ unsigned Padding : 9;
unsigned Extended : 1; /* BOOL */
}; };
struct tgsi_declaration_range struct tgsi_declaration_range
@@ -84,6 +85,16 @@ struct tgsi_declaration_interpolation
unsigned Padding : 28; 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 #define TGSI_IMM_FLOAT32 0
struct tgsi_immediate struct tgsi_immediate
@@ -1261,16 +1272,16 @@ struct tgsi_instruction_ext_predicate
struct tgsi_src_register struct tgsi_src_register
{ {
unsigned File : 4; /* TGSI_FILE_ */ unsigned File : 4; /* TGSI_FILE_ */
unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */ unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */
unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */ unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */
unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */ unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */
unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */ unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */
unsigned Negate : 1; /* BOOL */ unsigned Negate : 1; /* BOOL */
unsigned Indirect : 1; /* BOOL */ unsigned Indirect : 1; /* BOOL */
unsigned Dimension : 1; /* BOOL */ unsigned Dimension : 1; /* BOOL */
int Index : 16; /* SINT */ int Index : 16; /* SINT */
unsigned Extended : 1; /* BOOL */ unsigned Extended : 1; /* BOOL */
}; };
/* /*
@@ -1364,22 +1375,22 @@ struct tgsi_src_register_ext_mod
struct tgsi_dimension struct tgsi_dimension
{ {
unsigned Indirect : 1; /* BOOL */ unsigned Indirect : 1; /* BOOL */
unsigned Dimension : 1; /* BOOL */ unsigned Dimension : 1; /* BOOL */
unsigned Padding : 13; unsigned Padding : 13;
int Index : 16; /* SINT */ int Index : 16; /* SINT */
unsigned Extended : 1; /* BOOL */ unsigned Extended : 1; /* BOOL */
}; };
struct tgsi_dst_register struct tgsi_dst_register
{ {
unsigned File : 4; /* TGSI_FILE_ */ unsigned File : 4; /* TGSI_FILE_ */
unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */ unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */
unsigned Indirect : 1; /* BOOL */ unsigned Indirect : 1; /* BOOL */
unsigned Dimension : 1; /* BOOL */ unsigned Dimension : 1; /* BOOL */
int Index : 16; /* SINT */ int Index : 16; /* SINT */
unsigned Padding : 5; unsigned Padding : 5;
unsigned Extended : 1; /* BOOL */ unsigned Extended : 1; /* BOOL */
}; };
/* /*

View File

@@ -464,25 +464,39 @@ compile_instruction(
} }
static struct tgsi_full_declaration static struct tgsi_full_declaration
make_declaration( make_frag_input_decl(
GLuint file,
GLuint first, GLuint first,
GLuint last, GLuint last,
GLboolean do_interpolate,
GLuint interpolate ) GLuint interpolate )
{ {
struct tgsi_full_declaration decl; struct tgsi_full_declaration decl;
decl = tgsi_default_full_declaration(); decl = tgsi_default_full_declaration();
decl.Declaration.File = file; decl.Declaration.File = TGSI_FILE_INPUT;
decl.Declaration.Declare = TGSI_DECLARE_RANGE; decl.Declaration.Declare = TGSI_DECLARE_RANGE;
decl.Declaration.Interpolate = 1;
decl.u.DeclarationRange.First = first; decl.u.DeclarationRange.First = first;
decl.u.DeclarationRange.Last = last; decl.u.DeclarationRange.Last = last;
decl.Interpolation.Interpolate = interpolate;
if( do_interpolate ) { return decl;
decl.Declaration.Interpolate = 1; }
decl.Interpolation.Interpolate = interpolate;
} 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; return decl;
} }
@@ -518,11 +532,9 @@ tgsi_mesa_compile_fp_program(
/* /*
* Declare input attributes. Note that we do not interpolate fragment position. * Declare input attributes. Note that we do not interpolate fragment position.
*/ */
fulldecl = make_declaration( fulldecl = make_frag_input_decl(
TGSI_FILE_INPUT,
0, 0,
0, 0,
GL_TRUE,
TGSI_INTERPOLATE_CONSTANT ); TGSI_INTERPOLATE_CONSTANT );
ti += tgsi_build_full_declaration( ti += tgsi_build_full_declaration(
&fulldecl, &fulldecl,
@@ -537,11 +549,9 @@ tgsi_mesa_compile_fp_program(
} }
} }
if( count > 0 ) { if( count > 0 ) {
fulldecl = make_declaration( fulldecl = make_frag_input_decl(
TGSI_FILE_INPUT,
1, 1,
count + 1, 1 + count - 1,
GL_TRUE,
TGSI_INTERPOLATE_LINEAR ); TGSI_INTERPOLATE_LINEAR );
ti += tgsi_build_full_declaration( ti += tgsi_build_full_declaration(
&fulldecl, &fulldecl,
@@ -557,12 +567,9 @@ tgsi_mesa_compile_fp_program(
program->Base.OutputsWritten == program->Base.OutputsWritten ==
(program->Base.OutputsWritten & ((1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR))) ); (program->Base.OutputsWritten & ((1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR))) );
fulldecl = make_declaration( fulldecl = make_frag_output_decl(
TGSI_FILE_OUTPUT,
0, 0,
0, TGSI_SEMANTIC_DEPTH );
GL_FALSE,
0 );
ti += tgsi_build_full_declaration( ti += tgsi_build_full_declaration(
&fulldecl, &fulldecl,
&tokens[ti], &tokens[ti],
@@ -570,12 +577,9 @@ tgsi_mesa_compile_fp_program(
maxTokens - ti ); maxTokens - ti );
if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) { if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) {
fulldecl = make_declaration( fulldecl = make_frag_output_decl(
TGSI_FILE_OUTPUT,
1, 1,
1, TGSI_SEMANTIC_COLOR );
GL_FALSE,
0 );
ti += tgsi_build_full_declaration( ti += tgsi_build_full_declaration(
&fulldecl, &fulldecl,
&tokens[ti], &tokens[ti],