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

@@ -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,9 +98,10 @@ 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;
@@ -111,6 +113,7 @@ tgsi_build_declaration(
declaration.File = file;
declaration.Declare = declare;
declaration.Interpolate = interpolate;
declaration.Semantic = semantic;
header_bodysize_grow( header );
@@ -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,
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,6 +163,7 @@ 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 ) {
@@ -213,13 +218,28 @@ 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 )
{
@@ -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
*/

View 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
*/

View 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

View 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 );

View 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

View File

@@ -59,7 +59,8 @@ struct tgsi_declaration
unsigned File : 4; /* TGSI_FILE_ */
unsigned Declare : 4; /* TGSI_DECLARE_ */
unsigned Interpolate : 1; /* BOOL */
unsigned Padding : 10;
unsigned Semantic : 1; /* BOOL */
unsigned Padding : 9;
unsigned Extended : 1; /* BOOL */
};
@@ -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

View File

@@ -464,26 +464,40 @@ 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;
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,
fulldecl = make_frag_output_decl(
0,
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,
fulldecl = make_frag_output_decl(
1,
1,
GL_FALSE,
0 );
TGSI_SEMANTIC_COLOR );
ti += tgsi_build_full_declaration(
&fulldecl,
&tokens[ti],