d3dx9: Add DEFB instruction support in the shader assembler.

This completes vs_3_0 assembler language support.
This commit is contained in:
Matteo Bruni 2010-05-14 17:21:42 +02:00 committed by Alexandre Julliard
parent fa44f242b5
commit 1371e71f61
6 changed files with 79 additions and 4 deletions

View File

@ -48,6 +48,16 @@ static void asmparser_constF(struct asm_parser *This, DWORD reg, float x, float
}
}
static void asmparser_constB(struct asm_parser *This, DWORD reg, BOOL x) {
if(!This->shader) return;
TRACE("Adding boolean constant %u at pos %u\n", reg, This->shader->num_cb);
TRACE_(parsed_shader)("def b%u, %s\n", reg, x ? "true" : "false");
if(!add_constB(This->shader, reg, x)) {
ERR("Out of memory\n");
set_parse_status(This, PARSE_ERR);
}
}
static void asmparser_constI(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w) {
if(!This->shader) return;
TRACE("Adding integer constant %u at pos %u\n", reg, This->shader->num_ci);
@ -181,6 +191,7 @@ static void asmparser_coissue_unsupported(struct asm_parser *This) {
static const struct asmparser_backend parser_vs_3 = {
asmparser_constF,
asmparser_constI,
asmparser_constB,
asmparser_dstreg_vs_3,
asmparser_srcreg_vs_3,

View File

@ -139,6 +139,7 @@ m3x3 {return INSTR_M3x3; }
m3x2 {return INSTR_M3x2; }
dcl {return INSTR_DCL; }
def {return INSTR_DEF; }
defb {return INSTR_DEFB; }
defi {return INSTR_DEFI; }
rep {return INSTR_REP; }
endrep {return INSTR_ENDREP; }
@ -281,6 +282,14 @@ ps_3_0 {return VER_PS30; }
asmshader_lval.immval.integer = ((strstr(yytext, ".") == NULL) && (strstr(yytext, "f") == NULL));
return IMMVAL;
}
true {
asmshader_lval.immbool = TRUE;
return IMMBOOL;
}
false {
asmshader_lval.immbool = FALSE;
return IMMBOOL;
}
{COMMA} {return yytext[0]; }
- {return yytext[0]; }

View File

@ -60,6 +60,7 @@ void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
float val;
BOOL integer;
} immval;
BOOL immbool;
unsigned int regnum;
struct shader_reg reg;
DWORD srcmod;
@ -124,6 +125,7 @@ void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
%token INSTR_M3x2
%token INSTR_DCL
%token INSTR_DEF
%token INSTR_DEFB
%token INSTR_DEFI
%token INSTR_REP
%token INSTR_ENDREP
@ -226,6 +228,7 @@ void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
/* Misc stuff */
%token <component> COMPONENT
%token <immval> IMMVAL
%token <immbool> IMMBOOL
%type <reg> dreg_name
%type <reg> dreg
@ -583,6 +586,10 @@ instruction: INSTR_ADD omods dreg ',' sregs
{
asm_ctx.funcs->constI(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val);
}
| INSTR_DEFB REG_CONSTBOOL ',' IMMBOOL
{
asm_ctx.funcs->constB(&asm_ctx, $2, $4);
}
| INSTR_REP sregs
{
TRACE("REP\n");

View File

@ -189,6 +189,7 @@ DWORD d3d9_opcode(DWORD bwriter_opcode) {
case BWRITERSIO_BREAK: return D3DSIO_BREAK;
case BWRITERSIO_BREAKC: return D3DSIO_BREAKC;
case BWRITERSIO_MOVA: return D3DSIO_MOVA;
case BWRITERSIO_DEFB: return D3DSIO_DEFB;
case BWRITERSIO_DEFI: return D3DSIO_DEFI;
case BWRITERSIO_EXPP: return D3DSIO_EXPP;
case BWRITERSIO_LOGP: return D3DSIO_LOGP;
@ -456,6 +457,7 @@ const char *debug_print_opcode(DWORD opcode) {
case BWRITERSIO_BREAK: return "break";
case BWRITERSIO_BREAKC: return "breakc";
case BWRITERSIO_MOVA: return "mova";
case BWRITERSIO_DEFB: return "defb";
case BWRITERSIO_DEFI: return "defi";
case BWRITERSIO_EXPP: return "expp";
case BWRITERSIO_LOGP: return "logp";

View File

@ -176,6 +176,39 @@ BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, I
return TRUE;
}
BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) {
struct constant *newconst;
if(shader->num_cb) {
struct constant **newarray;
newarray = asm_realloc(shader->constB,
sizeof(*shader->constB) * (shader->num_cb + 1));
if(!newarray) {
ERR("Failed to grow the constants array\n");
return FALSE;
}
shader->constB = newarray;
} else {
shader->constB = asm_alloc(sizeof(*shader->constB));
if(!shader->constB) {
ERR("Failed to allocate the constants array\n");
return FALSE;
}
}
newconst = asm_alloc(sizeof(*newconst));
if(!newconst) {
ERR("Failed to allocate a new constant\n");
return FALSE;
}
newconst->regnum = reg;
newconst->value[0].b = x;
shader->constB[shader->num_cb] = newconst;
shader->num_cb++;
return TRUE;
}
BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx, BOOL output, DWORD regnum, DWORD writemask) {
unsigned int *num;
struct declaration **decl;
@ -343,7 +376,10 @@ static void write_const(struct constant **consts, int num, DWORD opcode, DWORD r
D3DSP_WRITEMASK_ALL;
if(len) {
instr_def |= 5 << D3DSI_INSTLENGTH_SHIFT;
if(opcode == D3DSIO_DEFB)
instr_def |= 2 << D3DSI_INSTLENGTH_SHIFT;
else
instr_def |= 5 << D3DSI_INSTLENGTH_SHIFT;
}
for(i = 0; i < num; i++) {
@ -352,9 +388,11 @@ static void write_const(struct constant **consts, int num, DWORD opcode, DWORD r
put_dword(buffer, reg | (consts[i]->regnum & D3DSP_REGNUM_MASK));
put_dword(buffer, consts[i]->value[0].d);
put_dword(buffer, consts[i]->value[1].d);
put_dword(buffer, consts[i]->value[2].d);
put_dword(buffer, consts[i]->value[3].d);
if(opcode != D3DSIO_DEFB) {
put_dword(buffer, consts[i]->value[1].d);
put_dword(buffer, consts[i]->value[2].d);
put_dword(buffer, consts[i]->value[3].d);
}
}
}
@ -405,6 +443,10 @@ static void instr_handler(struct bc_writer *This,
write_srcregs(This, instr, buffer);
}
static void write_constB(const struct bwriter_shader *shader, struct bytecode_buffer *buffer, BOOL len) {
write_const(shader->constB, shader->num_cb, D3DSIO_DEFB, D3DSPR_CONSTBOOL, buffer, len);
}
static void write_constI(const struct bwriter_shader *shader, struct bytecode_buffer *buffer, BOOL len) {
write_const(shader->constI, shader->num_ci, D3DSIO_DEFI, D3DSPR_CONSTINT, buffer, len);
}
@ -449,6 +491,7 @@ static void sm_3_header(struct bc_writer *This, const struct bwriter_shader *sha
write_declarations(buffer, TRUE, shader->inputs, shader->num_inputs, D3DSPR_INPUT);
write_declarations(buffer, TRUE, shader->outputs, shader->num_outputs, D3DSPR_OUTPUT);
write_constF(shader, buffer, TRUE);
write_constB(shader, buffer, TRUE);
write_constI(shader, buffer, TRUE);
write_samplers(shader, buffer);
return;

View File

@ -255,6 +255,7 @@ struct src_regs {
struct asmparser_backend {
void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
void (*dstreg)(struct asm_parser *This, struct instruction *instr,
const struct shader_reg *dst);
@ -283,6 +284,7 @@ struct instruction *alloc_instr(unsigned int srcs);
BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr);
BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w);
BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w);
BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x);
BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx, BOOL output, DWORD regnum, DWORD writemask);
BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD regnum);
@ -442,6 +444,7 @@ typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE {
BWRITERSIO_BREAK,
BWRITERSIO_BREAKC,
BWRITERSIO_MOVA,
BWRITERSIO_DEFB,
BWRITERSIO_DEFI,
BWRITERSIO_EXPP,