Fwd: wined3d: Move DCL,
DEF operations out of GenerateProgramArbHW and into separate
functions
Jason Green
jave27 at gmail.com
Mon May 1 15:49:12 CDT 2006
Yet again, this time with patch.
---------- Forwarded message ----------
This No-op patch moves the D3DSIO_DCL and D3DSIO_DEF cases out of the
giant switch/case in GenerateProgramArbHW (for both Vertex and Pixel
shaders) and into their own separate functions. This also removes a
duplicate TRACE() which is already reported prior to this function.
The purpose is to make the GenerateProgram function smaller and more
readable. I have tested this with 2 apps that use these calls in
either their pixel or vertex shaders, and the arguments in the traces
are the same.
This applies into Mike's git tree.
-------------- next part --------------
diff --git a/dlls/wined3d/pixelshader.c b/dlls/wined3d/pixelshader.c
index 0a8f568..0e75020 100644
--- a/dlls/wined3d/pixelshader.c
+++ b/dlls/wined3d/pixelshader.c
@@ -616,6 +616,7 @@ void pshader_hw_texcoord(SHADER_OPCODE_A
void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg);
void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg);
void pshader_hw_texbem(SHADER_OPCODE_ARG* arg);
+void pshader_hw_def(SHADER_OPCODE_ARG* arg);
/**
* log, exp, frc, m*x* seems to be macros ins ... to see
@@ -692,7 +693,7 @@ CONST SHADER_OPCODE IWineD3DPixelShaderI
{D3DSIO_LABEL, "label", GLNAME_REQUIRE_GLSL, 1, pshader_label, NULL, 0, 0},
/* Constant definitions */
- {D3DSIO_DEF, "def", "undefined", 5, pshader_def, NULL, 0, 0},
+ {D3DSIO_DEF, "def", "undefined", 5, pshader_def, pshader_hw_def, 0, 0},
{D3DSIO_DEFB, "defb", GLNAME_REQUIRE_GLSL, 2, pshader_defb, NULL, 0, 0},
{D3DSIO_DEFI, "defi", GLNAME_REQUIRE_GLSL, 2, pshader_defi, NULL, 0, 0},
@@ -1164,6 +1165,22 @@ void pshader_hw_texbem(SHADER_OPCODE_ARG
shader_addline(buffer, "TEX T%lu, TMP, texture[%lu], 2D;\n", reg1, reg1);
}
+void pshader_hw_def(SHADER_OPCODE_ARG* arg) {
+
+ IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
+ DWORD reg = arg->dst & D3DSP_REGNUM_MASK;
+ SHADER_BUFFER* buffer = arg->buffer;
+
+ shader_addline(buffer,
+ "PARAM C%lu = { %f, %f, %f, %f };\n", reg,
+ *((float*) (arg->src + 0)),
+ *((float*) (arg->src + 1)),
+ *((float*) (arg->src + 2)),
+ *((float*) (arg->src + 3)) );
+
+ shader->constants[reg] = 1;
+}
+
/* NOTE: A description of how to parse tokens can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/graphics/hh/graphics/usermodedisplaydriver_shader_cc8e4e05-f5c3-4ec0-8853-8ce07c1551b2.xml.asp */
inline static VOID IWineD3DPixelShaderImpl_GenerateProgramArbHW(IWineD3DPixelShader *iface, CONST DWORD *pFunction) {
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
@@ -1276,27 +1293,6 @@ inline static VOID IWineD3DPixelShaderIm
"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 & D3DSP_REGNUM_MASK;
-
- TRACE("Found opcode D3D:%s GL:%s, PARAMS:%d, \n",
- curOpcode->name, curOpcode->glname, curOpcode->num_params);
-
- shader_addline(&buffer,
- "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)) );
-
- This->constants[reg] = 1;
- pToken += 5;
- continue;
-
/* If a generator function is set, use it */
} else if (curOpcode->hw_fct != NULL) {
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index d31ab0d..39f1a04 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -474,6 +474,8 @@ void vshader_texldl(WINED3DSHADERVECTOR*
/* Prototype */
void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg);
+void vshader_hw_dcl(SHADER_OPCODE_ARG* arg);
+void vshader_hw_def(SHADER_OPCODE_ARG* arg);
/**
* log, exp, frc, m*x* seems to be macros ins ... to see
@@ -531,10 +533,10 @@ CONST SHADER_OPCODE IWineD3DVertexShader
{D3DSIO_M3x2, "m3x2", "undefined", 3, vshader_m3x2, NULL, 0, 0},
/* Declare registers */
- {D3DSIO_DCL, "dcl", NULL, 2, vshader_dcl, NULL, 0, 0},
+ {D3DSIO_DCL, "dcl", NULL, 2, vshader_dcl, vshader_hw_dcl, 0, 0},
/* Constant definitions */
- {D3DSIO_DEF, "def", NULL, 5, vshader_def, NULL, 0, 0},
+ {D3DSIO_DEF, "def", NULL, 5, vshader_def, vshader_hw_def, 0, 0},
{D3DSIO_DEFB, "defb", GLNAME_REQUIRE_GLSL, 2, vshader_defb, NULL, 0, 0},
{D3DSIO_DEFI, "defi", GLNAME_REQUIRE_GLSL, 2, vshader_defi, NULL, 0, 0},
@@ -1027,6 +1029,97 @@ void vshader_hw_map2gl(SHADER_OPCODE_ARG
shader_addline(buffer, "%s;\n", tmpLine);
}
+void vshader_hw_dcl(SHADER_OPCODE_ARG* arg) {
+
+ DWORD dst = arg->dst;
+ IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl*) arg->shader;
+ char tmpLine[256];
+ SHADER_BUFFER* buffer = arg->buffer;
+
+ if (This->namedArrays) {
+ const char* attribName = "undefined";
+ switch(dst & 0xFFFF) {
+ case D3DDECLUSAGE_POSITION:
+ attribName = "vertex.position";
+ break;
+ case D3DDECLUSAGE_BLENDINDICES:
+ /* not supported by openGL */
+ attribName = "vertex.blend";
+ break;
+ case D3DDECLUSAGE_BLENDWEIGHT:
+ attribName = "vertex.weight";
+ break;
+ case D3DDECLUSAGE_NORMAL:
+ attribName = "vertex.normal";
+ break;
+ case D3DDECLUSAGE_PSIZE:
+ attribName = "vertex.psize";
+ break;
+ case D3DDECLUSAGE_COLOR:
+ if((dst & 0xF0000) >> 16 == 0) {
+ attribName = "vertex.color";
+ } else {
+ attribName = "vertex.color.secondary";
+ }
+ break;
+ case D3DDECLUSAGE_TEXCOORD:
+ {
+ char tmpChar[100];
+ tmpChar[0] = 0;
+ sprintf(tmpChar,"vertex.texcoord[%lu]",(dst & 0xF0000) >> 16);
+ attribName = tmpChar;
+ break;
+ }
+ /* The following aren't directly supported by openGL, so shouldn't come up using namedarrays. */
+ case D3DDECLUSAGE_TANGENT:
+ attribName = "vertex.tangent";
+ break;
+ case D3DDECLUSAGE_BINORMAL:
+ attribName = "vertex.binormal";
+ break;
+ case D3DDECLUSAGE_TESSFACTOR:
+ attribName = "vertex.tessfactor";
+ break;
+ case D3DDECLUSAGE_POSITIONT:
+ attribName = "vertex.possitionT";
+ break;
+ case D3DDECLUSAGE_FOG:
+ attribName = "vertex.fogcoord";
+ break;
+ case D3DDECLUSAGE_DEPTH:
+ attribName = "vertex.depth";
+ break;
+ case D3DDECLUSAGE_SAMPLE:
+ attribName = "vertex.sample";
+ break;
+ default:
+ FIXME("Unrecognised dcl %08lx", dst & 0xFFFF);
+ }
+ {
+ sprintf(tmpLine, "ATTRIB ");
+ vshader_program_add_param(This, dst, FALSE, tmpLine);
+ if (This->namedArrays)
+ shader_addline(buffer, "%s = %s;\n", tmpLine, attribName);
+ }
+ }
+}
+
+void vshader_hw_def(SHADER_OPCODE_ARG* arg) {
+
+ IWineD3DVertexShaderImpl* shader = (IWineD3DVertexShaderImpl*) arg->shader;
+ SHADER_BUFFER* buffer = arg->buffer;
+ DWORD reg = arg->dst;
+
+ shader_addline(buffer,
+ "PARAM const%lu = { %f, %f, %f, %f };\n", reg & 0xFF,
+ *((const float *)(arg->src + 0)),
+ *((const float *)(arg->src + 1)),
+ *((const float *)(arg->src + 2)),
+ *((const float *)(arg->src + 3)) );
+
+ shader->constantsUsedBitmap[reg & 0xFF] = VS_CONSTANT_CONSTANT;
+}
+
/**
* Function parser ...
*/
@@ -1134,100 +1227,6 @@ inline static VOID IWineD3DVertexShaderI
"Vertex_Program_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 ] */
-
- shader_addline(&buffer,
- "PARAM const%lu = { %f, %f, %f, %f };\n", *pToken & 0xFF,
- *(float *) (pToken + 1),
- *(float *) (pToken + 2),
- *(float *) (pToken + 3),
- *(float *) (pToken + 4));
-
- This->constantsUsedBitmap[*pToken & 0xFF] = VS_CONSTANT_CONSTANT;
- pToken += 5;
- continue;
-
- } 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) {
- case D3DDECLUSAGE_POSITION:
- attribName = "vertex.position";
- break;
- case D3DDECLUSAGE_BLENDINDICES:
- /* not supported by openGL */
- attribName = "vertex.blend";
- break;
- case D3DDECLUSAGE_BLENDWEIGHT:
- attribName = "vertex.weight";
- break;
- case D3DDECLUSAGE_NORMAL:
- attribName = "vertex.normal";
- break;
- case D3DDECLUSAGE_PSIZE:
- attribName = "vertex.psize";
- break;
- case D3DDECLUSAGE_COLOR:
- if((*pToken & 0xF0000) >> 16 == 0) {
- attribName = "vertex.color";
- } else {
- attribName = "vertex.color.secondary";
- }
- break;
- case D3DDECLUSAGE_TEXCOORD:
- {
- char tmpChar[100];
- tmpChar[0] = 0;
- sprintf(tmpChar,"vertex.texcoord[%lu]",(*pToken & 0xF0000) >> 16);
- attribName = tmpChar;
- break;
- }
- /* The following aren't directly supported by openGL, so shouldn't come up using namedarrays. */
- case D3DDECLUSAGE_TANGENT:
- attribName = "vertex.tangent";
- break;
- case D3DDECLUSAGE_BINORMAL:
- attribName = "vertex.binormal";
- break;
- case D3DDECLUSAGE_TESSFACTOR:
- attribName = "vertex.tessfactor";
- break;
- case D3DDECLUSAGE_POSITIONT:
- attribName = "vertex.possitionT";
- break;
- case D3DDECLUSAGE_FOG:
- attribName = "vertex.fogcoord";
- break;
- case D3DDECLUSAGE_DEPTH:
- attribName = "vertex.depth";
- break;
- case D3DDECLUSAGE_SAMPLE:
- attribName = "vertex.sample";
- break;
- default:
- FIXME("Unrecognised dcl %08lx", *pToken & 0xFFFF);
- }
- {
- ++pToken;
- sprintf(tmpLine, "ATTRIB ");
- vshader_program_add_param(This, *pToken, FALSE, tmpLine);
- if (This->namedArrays)
- shader_addline(&buffer, "%s = %s;\n", tmpLine, attribName);
- }
- } else {
- /* eat the token so it doesn't generate a warning */
- ++pToken;
- }
- ++pToken;
- continue;
-
/* If a generator function is set, use it */
} else if (curOpcode->hw_fct != NULL) {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
More information about the wine-patches
mailing list