d3dx9: Add instruction modifiers (sm 2.0+) support to the shader assembler.

This commit is contained in:
Matteo Bruni 2010-04-21 16:15:46 +02:00 committed by Alexandre Julliard
parent 9019267bfa
commit 004a30a5c3
6 changed files with 89 additions and 1 deletions

View File

@ -50,7 +50,8 @@ static void asmparser_instr(struct asm_parser *This, DWORD opcode,
if(!This->shader) return;
TRACE_(parsed_shader)("%s ", debug_print_opcode(opcode));
TRACE_(parsed_shader)("%s%s ", debug_print_opcode(opcode),
debug_print_dstmod(mod));
if(dst) {
TRACE_(parsed_shader)("%s", debug_print_dstreg(dst, This->shader->type));
firstreg = FALSE;

View File

@ -119,6 +119,11 @@ ps_3_0 {return VER_PS30; }
return COMPONENT;
}
/* Output modifiers */
\_sat {return MOD_SAT; }
\_pp {return MOD_PP; }
\_centroid {return MOD_CENTROID; }
{COMMA} {return yytext[0]; }
- {return yytext[0]; }
\( {return yytext[0]; }

View File

@ -88,6 +88,11 @@ void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
%token VER_PS2X
%token VER_PS30
/* Output modifiers */
%token MOD_SAT
%token MOD_PP
%token MOD_CENTROID
/* Misc stuff */
%token <component> COMPONENT
@ -100,6 +105,7 @@ void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
%type <swizzle> swizzle
%type <sw_components> sw_components
%type <modshift> omods
%type <modshift> omodifier
%type <rel_reg> rel_reg
%type <sregs> sregs
@ -313,6 +319,34 @@ omods: /* Empty */
$$.mod = 0;
$$.shift = 0;
}
| omods omodifier
{
$$.mod = $1.mod | $2.mod;
if($1.shift && $2.shift) {
asmparser_message(&asm_ctx, "Line %u: More than one shift flag\n",
asm_ctx.line_no);
set_parse_status(&asm_ctx, PARSE_ERR);
$$.shift = $1.shift;
} else {
$$.shift = $1.shift | $2.shift;
}
}
omodifier: MOD_SAT
{
$$.mod = BWRITERSPDM_SATURATE;
$$.shift = 0;
}
| MOD_PP
{
$$.mod = BWRITERSPDM_PARTIALPRECISION;
$$.shift = 0;
}
| MOD_CENTROID
{
$$.mod = BWRITERSPDM_MSAMPCENTROID;
$$.shift = 0;
}
sregs: sreg
{

View File

@ -68,6 +68,16 @@ DWORD d3d9_writemask(DWORD bwriter_writemask) {
return ret;
}
DWORD d3d9_dstmod(DWORD bwriter_mod) {
DWORD ret = 0;
if(bwriter_mod & BWRITERSPDM_SATURATE) ret |= D3DSPDM_SATURATE;
if(bwriter_mod & BWRITERSPDM_PARTIALPRECISION) ret |= D3DSPDM_PARTIALPRECISION;
if(bwriter_mod & BWRITERSPDM_MSAMPCENTROID) ret |= D3DSPDM_MSAMPCENTROID;
return ret;
}
DWORD d3d9_register(DWORD bwriter_register) {
if(bwriter_register == BWRITERSPR_TEMP) return D3DSPR_TEMP;
if(bwriter_register == BWRITERSPR_CONST) return D3DSPR_CONST;
@ -89,6 +99,33 @@ DWORD d3d9_opcode(DWORD bwriter_opcode) {
}
}
const char *debug_print_dstmod(DWORD mod) {
switch(mod) {
case 0:
return "";
case BWRITERSPDM_SATURATE:
return "_sat";
case BWRITERSPDM_PARTIALPRECISION:
return "_pp";
case BWRITERSPDM_MSAMPCENTROID:
return "_centroid";
case BWRITERSPDM_SATURATE | BWRITERSPDM_PARTIALPRECISION:
return "_sat_pp";
case BWRITERSPDM_SATURATE | BWRITERSPDM_MSAMPCENTROID:
return "_sat_centroid";
case BWRITERSPDM_PARTIALPRECISION | BWRITERSPDM_MSAMPCENTROID:
return "_pp_centroid";
case BWRITERSPDM_SATURATE | BWRITERSPDM_PARTIALPRECISION | BWRITERSPDM_MSAMPCENTROID:
return "_sat_pp_centroid";
default:
return "Unexpected modifier\n";
}
}
static const char *get_regname(const struct shader_reg *reg, shader_type st) {
switch(reg->type) {
case BWRITERSPR_TEMP:

View File

@ -233,6 +233,8 @@ static void sm_3_dstreg(struct bc_writer *This,
token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2;
token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */
token |= d3d9_dstmod(mod);
token |= d3d9_writemask(reg->writemask);
put_dword(buffer, token);
}

View File

@ -340,6 +340,7 @@ struct bc_writer {
};
/* Debug utility routines */
const char *debug_print_dstmod(DWORD mod);
const char *debug_print_dstreg(const struct shader_reg *reg, shader_type st);
const char *debug_print_srcreg(const struct shader_reg *reg, shader_type st);
const char *debug_print_swizzle(DWORD swizzle);
@ -349,6 +350,7 @@ const char *debug_print_opcode(DWORD opcode);
/* Utilities for internal->d3d constant mapping */
DWORD d3d9_swizzle(DWORD bwriter_swizzle);
DWORD d3d9_writemask(DWORD bwriter_writemask);
DWORD d3d9_dstmod(DWORD bwriter_mod);
DWORD d3d9_register(DWORD bwriter_register);
DWORD d3d9_opcode(DWORD bwriter_opcode);
@ -377,6 +379,13 @@ typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE {
#define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
#define BWRITERSP_WRITEMASK_ALL 0xf /* all */
typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE {
BWRITERSPDM_NONE = 0,
BWRITERSPDM_SATURATE = 1,
BWRITERSPDM_PARTIALPRECISION = 2,
BWRITERSPDM_MSAMPCENTROID = 4,
} BWRITERSHADER_PARAM_DSTMOD_TYPE;
typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE {
BWRITERSPSM_NONE = 0,
} BWRITERSHADER_PARAM_SRCMOD_TYPE;