From 8ab0237e2158d6a783c7781bb9aba53b3b442627 Mon Sep 17 00:00:00 2001 From: Ivan Gyurdiev Date: Tue, 11 Apr 2006 14:44:03 -0400 Subject: [PATCH] wined3d: Reorganize shaders code a bit. --- dlls/wined3d/pixelshader.c | 48 ++++++++------ dlls/wined3d/vertexshader.c | 149 +++++++++++++++++++++++--------------------- 2 files changed, 109 insertions(+), 88 deletions(-) diff --git a/dlls/wined3d/pixelshader.c b/dlls/wined3d/pixelshader.c index 8e80c89a8b3..d3c2619a3ee 100644 --- a/dlls/wined3d/pixelshader.c +++ b/dlls/wined3d/pixelshader.c @@ -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 */ FIXME("Token %s requires greater functionality than Fragment_Progarm_ARB supports\n", curOpcode->name); 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 { - 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; /* Build opcode for GL vertex_program */ @@ -1137,22 +1166,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha TRACE("Appending glname %s to tmpLine\n", curOpcode->glname); strcpy(tmpLine, curOpcode->glname); 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: { char tmp[20]; @@ -1396,7 +1409,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelSha char swzstring[20]; int saturate = 0; char tmpOp[256]; - TRACE("(%p): Opcode has %d params\n", This, curOpcode->num_params); /* Generate lines that handle input modifier computation */ for (i = 1; i < curOpcode->num_params; ++i) { diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c index 88648b54943..ff334163c42 100644 --- a/dlls/wined3d/vertexshader.c +++ b/dlls/wined3d/vertexshader.c @@ -1072,6 +1072,7 @@ inline static void vshader_program_add_param(IWineD3DVertexShaderImpl *This, con DWORD MacroExpansion[4*4]; int ExpandMxMacro(DWORD macro_opcode, const DWORD* args) { + int i; int nComponents = 0; DWORD opcode =0; @@ -1500,56 +1501,36 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS FIXME("Token %s requires greater functionality than Vertex_Progarm_ARB supports\n", curOpcode->name); pToken += curOpcode->num_params; - } else { - /* Build opcode for GL vertex_program */ - switch (curOpcode->opcode) { - case D3DSIO_NOP: - 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; + + } else if (D3DSIO_DEF == curOpcode->opcode) { + + /* Handle definitions here, they don't fit well with the + * other instructions below [for now ] */ + + char tmpChar[80]; + sprintf(tmpLine, "PARAM const%lu = {", *pToken & 0xFF); + sprintf(tmpChar,"%f ,", *(float *) (pToken + 1)); + strcat(tmpLine, tmpChar); + sprintf(tmpChar,"%f ,", *(float *) (pToken + 2)); + strcat(tmpLine, tmpChar); + sprintf(tmpChar,"%f ,", *(float *) (pToken + 3)); + strcat(tmpLine, tmpChar); + sprintf(tmpChar,"%f}", *(float *) (pToken + 4)); + strcat(tmpLine, tmpChar); + + strcat(tmpLine,";\n"); + ++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 += 5; 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) { const char* attribName = "undefined"; switch(*pToken & 0xFFFF) { @@ -1614,6 +1595,7 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS ++pToken; sprintf(tmpLine, "ATTRIB "); vshader_program_add_param(This, *pToken, FALSE, tmpLine); + sprintf(tmpChar," = %s", attribName); strcat(tmpLine, tmpChar); strcat(tmpLine,";\n"); @@ -1632,31 +1614,58 @@ inline static VOID IWineD3DVertexShaderImpl_GenerateProgramArbHW(IWineD3DVertexS } ++pToken; 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"); - ++lineNum; - TRACE("GL HW (%u, %u) : %s", lineNum, pgmLength, tmpLine); /* Don't add \n to this line as already in tmpLine */ - PNSTRCAT(pgmStr, tmpLine); + } else { - ++pToken; + /* Common Processing: ([instr] [dst] [src]*) */ + + switch (curOpcode->opcode) { + case D3DSIO_NOP: 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: if (curOpcode->glname == GLNAME_REQUIRE_GLSL) { FIXME("Opcode %s requires Gl Shader languange 1.0\n", curOpcode->name); -- 2.11.4.GIT