svga: move some svga/tgsi functions

Move some functions from the svga_tgsi_insn.h header into the
svga_tgsi_insn.c file since they're only used there.  Plus, add
comments and fix formatting.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
This commit is contained in:
Brian Paul 2013-06-19 10:39:43 -06:00
parent 3abd9285be
commit 1f57349e20
3 changed files with 149 additions and 125 deletions

View file

@ -491,6 +491,26 @@ vs30_output(struct svga_shader_emitter *emit,
}
/** Translate PIPE_TEXTURE_x to SVGA3DSAMP_x */
static ubyte
svga_tgsi_sampler_type(const struct svga_shader_emitter *emit, int idx)
{
switch (emit->key.fkey.tex[idx].texture_target) {
case PIPE_TEXTURE_1D:
return SVGA3DSAMP_2D;
case PIPE_TEXTURE_2D:
case PIPE_TEXTURE_RECT:
return SVGA3DSAMP_2D;
case PIPE_TEXTURE_3D:
return SVGA3DSAMP_VOLUME;
case PIPE_TEXTURE_CUBE:
return SVGA3DSAMP_CUBE;
}
return SVGA3DSAMP_UNKNOWN;
}
static boolean
ps30_sampler( struct svga_shader_emitter *emit,
struct tgsi_declaration_semantic semantic,

View file

@ -146,30 +146,6 @@ boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit,
const struct tgsi_full_declaration *decl );
static INLINE boolean emit_dst( struct svga_shader_emitter *emit,
SVGA3dShaderDestToken dest )
{
assert(dest.reserved0);
assert(dest.mask);
return svga_shader_emit_dword( emit, dest.value );
}
static INLINE boolean emit_src( struct svga_shader_emitter *emit,
const struct src_register src )
{
if (src.base.relAddr) {
assert(src.base.reserved0);
assert(src.indirect.reserved0);
return (svga_shader_emit_dword( emit, src.base.value ) &&
svga_shader_emit_dword( emit, src.indirect.value ));
}
else {
assert(src.base.reserved0);
return svga_shader_emit_dword( emit, src.base.value );
}
}
static INLINE boolean emit_instruction( struct svga_shader_emitter *emit,
SVGA3dShaderInstToken opcode )
{
@ -177,60 +153,6 @@ static INLINE boolean emit_instruction( struct svga_shader_emitter *emit,
}
static INLINE boolean emit_op1( struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0 )
{
return (emit_instruction( emit, inst ) &&
emit_dst( emit, dest ) &&
emit_src( emit, src0 ));
}
static INLINE boolean emit_op2( struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1 )
{
return (emit_instruction( emit, inst ) &&
emit_dst( emit, dest ) &&
emit_src( emit, src0 ) &&
emit_src( emit, src1 ));
}
static INLINE boolean emit_op3( struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1,
struct src_register src2 )
{
return (emit_instruction( emit, inst ) &&
emit_dst( emit, dest ) &&
emit_src( emit, src0 ) &&
emit_src( emit, src1 ) &&
emit_src( emit, src2 ));
}
static INLINE boolean emit_op4( struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1,
struct src_register src2,
struct src_register src3)
{
return (emit_instruction( emit, inst ) &&
emit_dst( emit, dest ) &&
emit_src( emit, src0 ) &&
emit_src( emit, src1 ) &&
emit_src( emit, src2 ) &&
emit_src( emit, src3 ));
}
#define TRANSLATE_SWIZZLE(x,y,z,w) ((x) | ((y) << 2) | ((z) << 4) | ((w) << 6))
#define SWIZZLE_XYZW \
TRANSLATE_SWIZZLE(TGSI_SWIZZLE_X,TGSI_SWIZZLE_Y,TGSI_SWIZZLE_Z,TGSI_SWIZZLE_W)
@ -319,36 +241,6 @@ src_token( unsigned file, int number )
}
static INLINE struct src_register
absolute( struct src_register src )
{
src.base.srcMod = SVGA3DSRCMOD_ABS;
return src;
}
static INLINE struct src_register
negate( struct src_register src )
{
switch (src.base.srcMod) {
case SVGA3DSRCMOD_ABS:
src.base.srcMod = SVGA3DSRCMOD_ABSNEG;
break;
case SVGA3DSRCMOD_ABSNEG:
src.base.srcMod = SVGA3DSRCMOD_ABS;
break;
case SVGA3DSRCMOD_NEG:
src.base.srcMod = SVGA3DSRCMOD_NONE;
break;
case SVGA3DSRCMOD_NONE:
src.base.srcMod = SVGA3DSRCMOD_NEG;
break;
}
return src;
}
static INLINE struct src_register
src_register( unsigned file, int number )
{
@ -372,22 +264,5 @@ static INLINE struct src_register src( SVGA3dShaderDestToken dst )
dst.num );
}
static INLINE ubyte svga_tgsi_sampler_type( struct svga_shader_emitter *emit,
int idx )
{
switch (emit->key.fkey.tex[idx].texture_target) {
case PIPE_TEXTURE_1D:
return SVGA3DSAMP_2D;
case PIPE_TEXTURE_2D:
case PIPE_TEXTURE_RECT:
return SVGA3DSAMP_2D;
case PIPE_TEXTURE_3D:
return SVGA3DSAMP_VOLUME;
case PIPE_TEXTURE_CUBE:
return SVGA3DSAMP_CUBE;
}
return SVGA3DSAMP_UNKNOWN;
}
#endif

View file

@ -292,6 +292,135 @@ reset_temp_regs(struct svga_shader_emitter *emit)
}
/** Emit bytecode for a src_register */
static boolean
emit_src(struct svga_shader_emitter *emit, const struct src_register src)
{
if (src.base.relAddr) {
assert(src.base.reserved0);
assert(src.indirect.reserved0);
return (svga_shader_emit_dword( emit, src.base.value ) &&
svga_shader_emit_dword( emit, src.indirect.value ));
}
else {
assert(src.base.reserved0);
return svga_shader_emit_dword( emit, src.base.value );
}
}
/** Emit bytecode for a dst_register */
static boolean
emit_dst(struct svga_shader_emitter *emit, SVGA3dShaderDestToken dest)
{
assert(dest.reserved0);
assert(dest.mask);
return svga_shader_emit_dword( emit, dest.value );
}
/** Emit bytecode for a 1-operand instruction */
static boolean
emit_op1(struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0)
{
return (emit_instruction(emit, inst) &&
emit_dst(emit, dest) &&
emit_src(emit, src0));
}
/** Emit bytecode for a 2-operand instruction */
static boolean
emit_op2(struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1)
{
return (emit_instruction(emit, inst) &&
emit_dst(emit, dest) &&
emit_src(emit, src0) &&
emit_src(emit, src1));
}
/** Emit bytecode for a 3-operand instruction */
static boolean
emit_op3(struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1,
struct src_register src2)
{
return (emit_instruction(emit, inst) &&
emit_dst(emit, dest) &&
emit_src(emit, src0) &&
emit_src(emit, src1) &&
emit_src(emit, src2));
}
/** Emit bytecode for a 4-operand instruction */
static boolean
emit_op4(struct svga_shader_emitter *emit,
SVGA3dShaderInstToken inst,
SVGA3dShaderDestToken dest,
struct src_register src0,
struct src_register src1,
struct src_register src2,
struct src_register src3)
{
return (emit_instruction(emit, inst) &&
emit_dst(emit, dest) &&
emit_src(emit, src0) &&
emit_src(emit, src1) &&
emit_src(emit, src2) &&
emit_src(emit, src3));
}
/**
* Apply the absolute value modifier to the given src_register, returning
* a new src_register.
*/
static struct src_register
absolute(struct src_register src)
{
src.base.srcMod = SVGA3DSRCMOD_ABS;
return src;
}
/**
* Apply the negation modifier to the given src_register, returning
* a new src_register.
*/
static struct src_register
negate(struct src_register src)
{
switch (src.base.srcMod) {
case SVGA3DSRCMOD_ABS:
src.base.srcMod = SVGA3DSRCMOD_ABSNEG;
break;
case SVGA3DSRCMOD_ABSNEG:
src.base.srcMod = SVGA3DSRCMOD_ABS;
break;
case SVGA3DSRCMOD_NEG:
src.base.srcMod = SVGA3DSRCMOD_NONE;
break;
case SVGA3DSRCMOD_NONE:
src.base.srcMod = SVGA3DSRCMOD_NEG;
break;
}
return src;
}
/* Replace the src with the temporary specified in the dst, but copying
* only the necessary channels, and preserving the original swizzle (which is
* important given that several opcodes have constraints in the allowed