📄 vs1.0_inst.cpp
字号:
mask[4] = 0;
len = strlen( mask );
if ( len != 1 )
{
for ( i = len; i < 4; i++ )
src[0].mask[i] = src[0].mask[len-1];
}
break;
// Unary operations.
case VS10_FRC:
strncpy( mask, src[0].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 1 )
{
for ( i = len; i < 4; i++ )
src[0].mask[i] = src[0].mask[len-1];
}
break;
// Scalar operations.
case VS10_EXP:
case VS10_EXPP:
case VS10_LOG:
case VS10_LOGP:
strncpy( mask, src[0].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if( len != 1 )
{
sprintf( temp, "(%d) Error: source register has invalid mask: %s\n", line, mask );
errors.set( temp );
}
break;
case VS10_RCP:
case VS10_RSQ:
strncpy( mask, src[0].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if( len != 0 && len != 1 )
{
sprintf( temp, "(%d) Error: source register has invalid mask: %s\n", line, mask );
errors.set( temp );
}
if ( len == 0 )
{
strcpy( src[0].mask, "w" );
}
break;
// Binary operations.
case VS10_ADD:
case VS10_DP3:
case VS10_DP4:
case VS10_DST:
case VS10_SGE:
case VS10_SLT:
case VS10_SUB:
case VS10_M3X2:
case VS10_M3X3:
case VS10_M3X4:
case VS10_M4X3:
case VS10_M4X4:
case VS10_MAX:
case VS10_MIN:
case VS10_MUL:
strncpy( mask, src[0].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 0 && len != 1 )
{
for ( i = len; i < 4; i++ )
src[0].mask[i] = src[0].mask[len-1];
}
strncpy( mask, src[1].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 0 && len != 1 )
{
for ( i = len; i < 4; i++ )
src[1].mask[i] = src[1].mask[len-1];
}
break;
// Trinary operations.
case VS10_MAD:
strncpy( mask, src[0].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 0 && len != 1 )
{
for ( i = len; i < 4; i++ )
src[0].mask[i] = src[0].mask[len-1];
}
strncpy( mask, src[1].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 0 && len != 1 )
{
for ( i = len; i < 4; i++ )
src[1].mask[i] = src[1].mask[len-1];
}
strncpy( mask, src[2].mask, 4 );
mask[4] = 0;
len = strlen( mask );
if ( len != 0 && len != 1 )
{
for ( i = len; i < 4; i++ )
src[2].mask[i] = src[2].mask[len-1];
}
break;
default:
errors.set( "VS10Inst::ValidateSrcMasks() Internal Error: unknown instruction type\n" );
break;
}
}
void VS10Inst::ValidateDestWritable()
{
char temp[256];
switch ( dst.type )
{
case TYPE_TEMPORARY_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
break;
case TYPE_VERTEX_ATTRIB_REG:
case TYPE_CONSTANT_MEM_REG:
case TYPE_CONSTANT_A0_REG:
case TYPE_CONSTANT_A0_OFFSET_REG:
sprintf( temp, "(%d) Error: destination register is not writable\n", line );
errors.set( temp );
break;
case TYPE_ADDRESS_REG:
if ( instid != VS10_MOV )
{
sprintf( temp, "(%d) Error: destination register is not writable using this instruction\n", line );
errors.set( temp );
}
break;
default:
errors.set( "VS10Inst::ValidateDestWritable() Internal Error: unknown register type\n" );
}
if ( instid == VS10_FRC && dst.type != TYPE_TEMPORARY_REG )
{
sprintf( temp, "(%d) Error: destination register must be a temporary register\n", line );
errors.set( temp );
}
}
void VS10Inst::ValidateSrcReadable()
{
char temp[256];
// Source register.
switch( src[0].type )
{
case TYPE_TEMPORARY_REG:
case TYPE_VERTEX_ATTRIB_REG:
case TYPE_CONSTANT_MEM_REG:
case TYPE_CONSTANT_A0_REG:
case TYPE_CONSTANT_A0_OFFSET_REG:
break;
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
sprintf( temp, "(%d) Error: source register is not readable\n", line );
errors.set( temp );
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
}
switch( instid )
{
// Vector operations.
case VS10_MOV:
case VS10_LIT:
break;
// Unary operations.
case VS10_FRC:
break;
// Scalar operations.
case VS10_EXP:
case VS10_EXPP:
case VS10_LOG:
case VS10_LOGP:
case VS10_RCP:
case VS10_RSQ:
break;
// Binary operations.
case VS10_ADD:
case VS10_DP3:
case VS10_DP4:
case VS10_DST:
case VS10_SGE:
case VS10_SLT:
case VS10_SUB:
case VS10_M3X2:
case VS10_M3X3:
case VS10_M3X4:
case VS10_M4X3:
case VS10_M4X4:
case VS10_MAX:
case VS10_MIN:
case VS10_MUL:
switch( src[1].type )
{
case TYPE_TEMPORARY_REG:
case TYPE_VERTEX_ATTRIB_REG:
case TYPE_CONSTANT_MEM_REG:
case TYPE_CONSTANT_A0_REG:
case TYPE_CONSTANT_A0_OFFSET_REG:
break;
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
sprintf( temp, "(%d) Error: second source register is not readable\n", line );
errors.set( temp );
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
}
break;
// Trinary operations.
case VS10_MAD:
switch( src[1].type )
{
case TYPE_TEMPORARY_REG:
case TYPE_VERTEX_ATTRIB_REG:
case TYPE_CONSTANT_MEM_REG:
case TYPE_CONSTANT_A0_REG:
case TYPE_CONSTANT_A0_OFFSET_REG:
break;
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
sprintf( temp, "(%d) Error: second source register is not readable\n", line );
errors.set( temp );
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
}
switch( src[2].type )
{
case TYPE_TEMPORARY_REG:
case TYPE_VERTEX_ATTRIB_REG:
case TYPE_CONSTANT_MEM_REG:
case TYPE_CONSTANT_A0_REG:
case TYPE_CONSTANT_A0_OFFSET_REG:
break;
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
sprintf( temp, "(%d) Error: third source register is not readable\n", line );
errors.set( temp );
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
}
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
break;
}
}
void VS10Inst::ValidateReadPorts()
{
int constidx[3];
int attribidx[3];
int i;
int acount;
int ccount;
char temp[256];
switch( instid )
{
// Vector operations.
case VS10_MOV:
case VS10_LIT:
break;
// Unary operations.
case VS10_FRC:
break;
// Scalar operations.
case VS10_EXP:
case VS10_EXPP:
case VS10_LOG:
case VS10_LOGP:
case VS10_RCP:
case VS10_RSQ:
break;
// Binary operations.
case VS10_ADD:
case VS10_DP3:
case VS10_DP4:
case VS10_DST:
case VS10_SGE:
case VS10_SLT:
case VS10_SUB:
case VS10_M3X2:
case VS10_M3X3:
case VS10_M3X4:
case VS10_M4X3:
case VS10_M4X4:
case VS10_MAX:
case VS10_MIN:
case VS10_MUL:
acount = 0;
ccount = 0;
for ( i = 0; i < 2; i++ )
{
switch( src[i].type )
{
case TYPE_VERTEX_ATTRIB_REG:
attribidx[acount] = src[i].index;
acount++;
break;
case TYPE_CONSTANT_MEM_REG:
constidx[ccount] = src[i].index;
ccount++;
break;
case TYPE_CONSTANT_A0_REG:
constidx[ccount] = 100 + src[i].index;
ccount++;
break;
case TYPE_CONSTANT_A0_OFFSET_REG:
constidx[ccount] = 200 + src[i].index;
ccount++;
break;
case TYPE_TEMPORARY_REG:
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
break;
default:
errors.set( "VS10Inst::ValidateReadPorts() Internal Error: unknown register type\n" );
}
}
if ( acount == 2 )
{
if ( attribidx[0] != attribidx[1] )
{
sprintf( temp, "(%d) Error: multiple unique attribute registers accessed in this instruction\n", line );
errors.set( temp );
}
}
else if ( ccount == 2 )
{
if ( constidx[0] != constidx[1] )
{
sprintf( temp, "(%d) Error: multiple unique constant registers accessed in this instruction\n", line );
errors.set( temp );
}
}
break;
// Trinary operations.
case VS10_MAD:
acount = 0;
ccount = 0;
for ( i = 0; i < 3; i++ )
{
switch( src[i].type )
{
case TYPE_VERTEX_ATTRIB_REG:
attribidx[acount] = src[i].index;
acount++;
break;
case TYPE_CONSTANT_MEM_REG:
constidx[ccount] = src[i].index;
ccount++;
break;
case TYPE_CONSTANT_A0_REG:
constidx[ccount] = 100 + src[i].index;
ccount++;
break;
case TYPE_CONSTANT_A0_OFFSET_REG:
constidx[ccount] = 200 + src[i].index;
ccount++;
break;
case TYPE_TEMPORARY_REG:
case TYPE_ADDRESS_REG:
case TYPE_POSITION_RESULT_REG:
case TYPE_COLOR_RESULT_REG:
case TYPE_TEXTURE_RESULT_REG:
case TYPE_FOG_RESULT_REG:
case TYPE_POINTS_RESULT_REG:
break;
default:
errors.set( "VS10Inst::ValidateReadPorts() Internal Error: unknown register type\n" );
}
}
if ( acount == 3 )
{
if ( attribidx[0] != attribidx[1] || attribidx[1] != attribidx[2] )
{
sprintf( temp, "(%d) Error: multiple unique attribute registers accessed in this instruction\n", line );
errors.set( temp );
}
}
else if ( acount == 2 )
{
if ( attribidx[0] != attribidx[1] )
{
sprintf( temp, "(%d) Error: multiple unique attribute registers accessed in this instruction\n", line );
errors.set( temp );
}
}
else if ( ccount == 3 )
{
if ( constidx[0] != constidx[1] || constidx[1] != constidx[2] )
{
sprintf( temp, "(%d) Error: multiple unique constant registers accessed in this instruction\n", line );
errors.set( temp );
}
}
else if ( ccount == 2 )
{
if ( constidx[0] != constidx[1] )
{
sprintf( temp, "(%d) Error: multiple unique constant registers accessed in this instruction\n", line );
errors.set( temp );
}
}
break;
default:
errors.set( "VS10Inst::ValidateSrcReadable() Internal Error: unknown register type\n" );
break;
}
}
int VS10Inst::Translate()
{
int flag;
int ninstr;
#if DEBUGGING_PURPOSES
char mystr[16];
if ( instid == VS10_HEADER )
{
sprintf( mystr, "%d:\tvs.1.0 (skip)\n", line );
vs10_transstring.append( mystr );
return 0;
}
sprintf( mystr, "%d:\t", line );
vs10_transstring.append( mystr );
#endif
switch( instid )
{
case VS10_ADD:
vs10_transstring.append( "ADD " );
dst.Translate();
vs10_transstring.append( ", " );
src[0].Translate();
vs10_transstring.append( ", " );
src[1].Translate();
ninstr = 1;
break;
case VS10_DP3:
vs10_transstring.append( "DP3 " );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -