Commit 8ab0237e authored by Ivan Gyurdiev's avatar Ivan Gyurdiev Committed by Alexandre Julliard

wined3d: Reorganize shaders code a bit.

parent cedf0ab4
...@@ -1101,8 +1101,37 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha ...@@ -1101,8 +1101,37 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha
/* if the token isn't supported by this cross compiler then skip it and its parameters */ /* if the token isn't supported by this cross compiler then skip it and its parameters */
FIXME("Token %s requires greater functionality than Fragment_Progarm_ARB supports\n", curOpcode->name); FIXME("Token %s requires greater functionality than Fragment_Progarm_ARB supports\n", curOpcode->name);
pToken += curOpcode->num_params; pToken += curOpcode->num_params;
} else if (D3DSIO_DEF == curOpcode->opcode) {
/* Handle definitions here, they don't fit well with the
* other instructions below [for now ] */
DWORD reg = *pToken & REGMASK;
TRACE("Found opcode D3D:%s GL:%s, PARAMS:%d, \n",
curOpcode->name, curOpcode->glname, curOpcode->num_params);
sprintf(tmpLine, "PARAM C%lu = { %f, %f, %f, %f };\n", reg,
*((const float *)(pToken + 1)),
*((const float *)(pToken + 2)),
*((const float *)(pToken + 3)),
*((const float *)(pToken + 4)) );
addline(&lineNum, pgmStr, &pgmLength, tmpLine);
This->constants[reg] = 1;
pToken += 5;
continue;
} else { } else {
TRACE("Found opcode %s %s\n", curOpcode->name, curOpcode->glname);
/* Common processing: [inst] [dst] [src]* */
TRACE("Found opcode D3D:%s GL:%s, PARAMS:%d, \n",
curOpcode->name, curOpcode->glname, curOpcode->num_params);
saturate = FALSE; saturate = FALSE;
/* Build opcode for GL vertex_program */ /* Build opcode for GL vertex_program */
...@@ -1137,22 +1166,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha ...@@ -1137,22 +1166,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha
TRACE("Appending glname %s to tmpLine\n", curOpcode->glname); TRACE("Appending glname %s to tmpLine\n", curOpcode->glname);
strcpy(tmpLine, curOpcode->glname); strcpy(tmpLine, curOpcode->glname);
break; break;
case D3DSIO_DEF:
{
DWORD reg = *pToken & REGMASK;
sprintf(tmpLine, "PARAM C%lu = { %f, %f, %f, %f };\n", reg,
*((const float *)(pToken + 1)),
*((const float *)(pToken + 2)),
*((const float *)(pToken + 3)),
*((const float *)(pToken + 4)) );
addline(&lineNum, pgmStr, &pgmLength, tmpLine);
This->constants[reg] = 1;
pToken += 5;
continue;
}
break;
case D3DSIO_TEX: case D3DSIO_TEX:
{ {
char tmp[20]; char tmp[20];
...@@ -1396,7 +1409,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha ...@@ -1396,7 +1409,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha
char swzstring[20]; char swzstring[20];
int saturate = 0; int saturate = 0;
char tmpOp[256]; char tmpOp[256];
TRACE("(%p): Opcode has %d params\n", This, curOpcode->num_params);
/* Generate lines that handle input modifier computation */ /* Generate lines that handle input modifier computation */
for (i = 1; i < curOpcode->num_params; ++i) { for (i = 1; i < curOpcode->num_params; ++i) {
......
...@@ -1072,6 +1072,7 @@ inline static void vshader_program_add_param(IWineD3DVertexShaderImpl *This, con ...@@ -1072,6 +1072,7 @@ inline static void vshader_program_add_param(IWineD3DVertexShaderImpl *This, con
DWORD MacroExpansion[4*4]; DWORD MacroExpansion[4*4];
int ExpandMxMacro(DWORD macro_opcode, const DWORD* args) { int ExpandMxMacro(DWORD macro_opcode, const DWORD* args) {
int i; int i;
int nComponents = 0; int nComponents = 0;
DWORD opcode =0; DWORD opcode =0;
...@@ -1500,56 +1501,36 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS ...@@ -1500,56 +1501,36 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS
FIXME("Token %s requires greater functionality than Vertex_Progarm_ARB supports\n", curOpcode->name); FIXME("Token %s requires greater functionality than Vertex_Progarm_ARB supports\n", curOpcode->name);
pToken += curOpcode->num_params; pToken += curOpcode->num_params;
} else {
/* Build opcode for GL vertex_program */ } else if (D3DSIO_DEF == curOpcode->opcode) {
switch (curOpcode->opcode) {
case D3DSIO_NOP: /* Handle definitions here, they don't fit well with the
continue; * other instructions below [for now ] */
case D3DSIO_MOV:
/* Address registers must be loaded with the ARL instruction */ char tmpChar[80];
if ((((*pToken) & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) == D3DSPR_ADDR) { sprintf(tmpLine, "PARAM const%lu = {", *pToken & 0xFF);
if (((*pToken) & 0x00001FFF) < nUseAddressRegister) { sprintf(tmpChar,"%f ,", *(float *) (pToken + 1));
strcpy(tmpLine, "ARL"); strcat(tmpLine, tmpChar);
break; sprintf(tmpChar,"%f ,", *(float *) (pToken + 2));
} else strcat(tmpLine, tmpChar);
FIXME("(%p) Try to load A%ld an undeclared address register!\n", This, ((*pToken) & 0x00001FFF)); sprintf(tmpChar,"%f ,", *(float *) (pToken + 3));
} strcat(tmpLine, tmpChar);
/* fall through */ sprintf(tmpChar,"%f}", *(float *) (pToken + 4));
case D3DSIO_ADD: strcat(tmpLine, tmpChar);
case D3DSIO_SUB:
case D3DSIO_MAD: strcat(tmpLine,";\n");
case D3DSIO_MUL: ++lineNum;
case D3DSIO_RCP: TRACE("GL HW (%u, %u) : %s", lineNum, pgmLength, tmpLine); /* Don't add \n to this line as already in tmpLine */
case D3DSIO_RSQ: PNSTRCAT(pgmStr, tmpLine);
case D3DSIO_DP3:
case D3DSIO_DP4: pToken += 5;
case D3DSIO_MIN:
case D3DSIO_MAX:
case D3DSIO_SLT:
case D3DSIO_SGE:
case D3DSIO_LIT:
case D3DSIO_DST:
case D3DSIO_FRC:
case D3DSIO_EXPP:
case D3DSIO_LOGP:
case D3DSIO_EXP:
case D3DSIO_LOG:
strcpy(tmpLine, curOpcode->glname);
break;
case D3DSIO_M4x4:
case D3DSIO_M4x3:
case D3DSIO_M3x4:
case D3DSIO_M3x3:
case D3DSIO_M3x2:
/* Expand the macro and get nusprintf(tmpLine,mber of generated instruction */
nRemInstr = ExpandMxMacro(curOpcode->opcode, pToken);
/* Save point to next instruction */
pSavedToken = pToken + 3;
/* Execute expanded macro */
pToken = MacroExpansion;
continue; continue;
/* dcl and def are handeled in the first pass */
case D3DSIO_DCL: } else if (D3DSIO_DCL == curOpcode->opcode) {
/* Handle declarations here, they don't fit well with the
* other instructions below [for now ] */
if (This->namedArrays) { if (This->namedArrays) {
const char* attribName = "undefined"; const char* attribName = "undefined";
switch(*pToken & 0xFFFF) { switch(*pToken & 0xFFFF) {
...@@ -1614,6 +1595,7 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS ...@@ -1614,6 +1595,7 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS
++pToken; ++pToken;
sprintf(tmpLine, "ATTRIB "); sprintf(tmpLine, "ATTRIB ");
vshader_program_add_param(This, *pToken, FALSE, tmpLine); vshader_program_add_param(This, *pToken, FALSE, tmpLine);
sprintf(tmpChar," = %s", attribName); sprintf(tmpChar," = %s", attribName);
strcat(tmpLine, tmpChar); strcat(tmpLine, tmpChar);
strcat(tmpLine,";\n"); strcat(tmpLine,";\n");
...@@ -1632,31 +1614,58 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS ...@@ -1632,31 +1614,58 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS
} }
++pToken; ++pToken;
continue; continue;
case D3DSIO_DEF:
{
char tmpChar[80];
sprintf(tmpLine, "PARAM const%lu = {", *pToken & 0xFF);
++pToken;
sprintf(tmpChar,"%f ,", *(float *)pToken);
strcat(tmpLine, tmpChar);
++pToken;
sprintf(tmpChar,"%f ,", *(float *)pToken);
strcat(tmpLine, tmpChar);
++pToken;
sprintf(tmpChar,"%f ,", *(float *)pToken);
strcat(tmpLine, tmpChar);
++pToken;
sprintf(tmpChar,"%f}", *(float *)pToken);
strcat(tmpLine, tmpChar);
strcat(tmpLine,";\n"); } else {
++lineNum;
TRACE("GL HW (%u, %u) : %s", lineNum, pgmLength, tmpLine); /* Don't add \n to this line as already in tmpLine */
PNSTRCAT(pgmStr, tmpLine);
++pToken; /* Common Processing: ([instr] [dst] [src]*) */
switch (curOpcode->opcode) {
case D3DSIO_NOP:
continue; continue;
case D3DSIO_MOV:
/* Address registers must be loaded with the ARL instruction */
if ((((*pToken) & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) == D3DSPR_ADDR) {
if (((*pToken) & 0x00001FFF) < nUseAddressRegister) {
strcpy(tmpLine, "ARL");
break;
} else
FIXME("(%p) Try to load A%ld an undeclared address register!\n", This, ((*pToken) & 0x00001FFF));
} }
/* fall through */
case D3DSIO_ADD:
case D3DSIO_SUB:
case D3DSIO_MAD:
case D3DSIO_MUL:
case D3DSIO_RCP:
case D3DSIO_RSQ:
case D3DSIO_DP3:
case D3DSIO_DP4:
case D3DSIO_MIN:
case D3DSIO_MAX:
case D3DSIO_SLT:
case D3DSIO_SGE:
case D3DSIO_LIT:
case D3DSIO_DST:
case D3DSIO_FRC:
case D3DSIO_EXPP:
case D3DSIO_LOGP:
case D3DSIO_EXP:
case D3DSIO_LOG:
strcpy(tmpLine, curOpcode->glname);
break;
case D3DSIO_M4x4:
case D3DSIO_M4x3:
case D3DSIO_M3x4:
case D3DSIO_M3x3:
case D3DSIO_M3x2:
/* Expand the macro and get nusprintf(tmpLine,mber of generated instruction */
nRemInstr = ExpandMxMacro(curOpcode->opcode, pToken);
/* Save point to next instruction */
pSavedToken = pToken + 3;
/* Execute expanded macro */
pToken = MacroExpansion;
continue;
default: default:
if (curOpcode->glname == GLNAME_REQUIRE_GLSL) { if (curOpcode->glname == GLNAME_REQUIRE_GLSL) {
FIXME("Opcode %s requires Gl Shader languange 1.0\n", curOpcode->name); FIXME("Opcode %s requires Gl Shader languange 1.0\n", curOpcode->name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment