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

wined3d: Shaders: share dump_param function, version functions.

parent 7757d7bc
......@@ -30,12 +30,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
#define GLNAME_REQUIRE_GLSL ((const char *)1)
inline static BOOL shader_is_version_token(DWORD token) {
return 0xFFFF0000 == (token & 0xFFFF0000) ||
0xFFFE0000 == (token & 0xFFFF0000);
}
inline static BOOL shader_is_comment_token(DWORD token) {
return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
return shader_is_pshader_version(token) ||
shader_is_vshader_version(token);
}
int shader_addline(
......@@ -119,7 +115,7 @@ void shader_get_registers_used(
continue;
/* Skip comments */
} else if (shader_is_comment_token(*pToken)) {
} else if (shader_is_comment(*pToken)) {
DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
++pToken;
pToken += comment_len;
......@@ -238,6 +234,146 @@ void shader_program_dump_decl_usage(
}
}
void shader_dump_param(
IWineD3DBaseShader *iface,
const DWORD param,
int input) {
IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
static const char* rastout_reg_names[] = { "oPos", "oFog", "oPts" };
char swizzle_reg_chars[4];
DWORD reg = param & D3DSP_REGNUM_MASK;
DWORD regtype = shader_get_regtype(param);
/* There are some minor differences between pixel and vertex shaders */
BOOL pshader = shader_is_pshader_version(This->baseShader.hex_version);
/* For one, we'd prefer color components to be shown for pshaders.
* FIXME: use the swizzle function for this */
swizzle_reg_chars[0] = pshader? 'r': 'x';
swizzle_reg_chars[1] = pshader? 'g': 'y';
swizzle_reg_chars[2] = pshader? 'b': 'z';
swizzle_reg_chars[3] = pshader? 'a': 'w';
if (input) {
if ( ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_BIASNEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_SIGNNEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_X2NEG) )
TRACE("-");
else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_COMP)
TRACE("1-");
}
switch (regtype) {
case D3DSPR_TEMP:
TRACE("r%lu", reg);
break;
case D3DSPR_INPUT:
TRACE("v%lu", reg);
break;
case D3DSPR_CONST:
TRACE("c%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_TEXTURE: /* vs: case D3DSPR_ADDR */
TRACE("%c%lu", (pshader? 't':'a'), reg);
break;
case D3DSPR_RASTOUT:
TRACE("%s", rastout_reg_names[reg]);
break;
case D3DSPR_COLOROUT:
TRACE("oC%lu", reg);
break;
case D3DSPR_DEPTHOUT:
TRACE("oDepth");
break;
case D3DSPR_ATTROUT:
TRACE("oD%lu", reg);
break;
case D3DSPR_TEXCRDOUT:
TRACE("oT%lu", reg);
break;
case D3DSPR_CONSTINT:
TRACE("i%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_CONSTBOOL:
TRACE("b%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_LABEL:
TRACE("l%lu", reg);
break;
case D3DSPR_LOOP:
TRACE("aL%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_SAMPLER:
TRACE("s%lu", reg);
break;
default:
TRACE("unhandled_rtype(%lx)", regtype);
break;
}
if (!input) {
/* operand output (for modifiers and shift, see dump_ins_modifiers) */
if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
TRACE(".");
if (param & D3DSP_WRITEMASK_0) TRACE("%c", swizzle_reg_chars[0]);
if (param & D3DSP_WRITEMASK_1) TRACE("%c", swizzle_reg_chars[1]);
if (param & D3DSP_WRITEMASK_2) TRACE("%c", swizzle_reg_chars[2]);
if (param & D3DSP_WRITEMASK_3) TRACE("%c", swizzle_reg_chars[3]);
}
} else {
/** operand input */
DWORD swizzle = (param & D3DSP_SWIZZLE_MASK) >> D3DSP_SWIZZLE_SHIFT;
DWORD swizzle_r = swizzle & 0x03;
DWORD swizzle_g = (swizzle >> 2) & 0x03;
DWORD swizzle_b = (swizzle >> 4) & 0x03;
DWORD swizzle_a = (swizzle >> 6) & 0x03;
if (0 != (param & D3DSP_SRCMOD_MASK)) {
DWORD mask = param & D3DSP_SRCMOD_MASK;
/*TRACE("_modifier(0x%08lx) ", mask);*/
switch (mask) {
case D3DSPSM_NONE: break;
case D3DSPSM_NEG: break;
case D3DSPSM_BIAS: TRACE("_bias"); break;
case D3DSPSM_BIASNEG: TRACE("_bias"); break;
case D3DSPSM_SIGN: TRACE("_bx2"); break;
case D3DSPSM_SIGNNEG: TRACE("_bx2"); break;
case D3DSPSM_COMP: break;
case D3DSPSM_X2: TRACE("_x2"); break;
case D3DSPSM_X2NEG: TRACE("_x2"); break;
case D3DSPSM_DZ: TRACE("_dz"); break;
case D3DSPSM_DW: TRACE("_dw"); break;
default:
TRACE("_unknown(0x%08lx)", mask);
}
}
/**
* swizzle bits fields:
* RRGGBBAA
*/
if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
if (swizzle_r == swizzle_g &&
swizzle_r == swizzle_b &&
swizzle_r == swizzle_a) {
TRACE(".%c", swizzle_reg_chars[swizzle_r]);
} else {
TRACE(".%c%c%c%c",
swizzle_reg_chars[swizzle_r],
swizzle_reg_chars[swizzle_g],
swizzle_reg_chars[swizzle_b],
swizzle_reg_chars[swizzle_a]);
}
}
}
}
/** Generate the variable & register declarations for the ARB_vertex_program
output target */
void generate_arb_declarations(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer) {
......@@ -320,7 +456,7 @@ void generate_base_shader(
}
/* Skip comment tokens */
if (shader_is_comment_token(*pToken)) {
if (shader_is_comment(*pToken)) {
DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
++pToken;
TRACE("#%s\n", (char*)pToken);
......
......@@ -738,15 +738,6 @@ CONST SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[] = {
{0, NULL, NULL, 0, NULL, NULL, 0, 0}
};
inline static BOOL pshader_is_version_token(DWORD token) {
return 0xFFFF0000 == (token & 0xFFFF0000);
}
inline static BOOL pshader_is_comment_token(DWORD token) {
return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
}
inline static void get_register_name(const DWORD param, char* regstr, char constants[WINED3D_PSHADER_MAX_CONSTANTS]) {
static const char* rastout_reg_names[] = { "oC0", "oC1", "oC2", "oC3", "oDepth" };
......@@ -1370,124 +1361,6 @@ inline static VOID IWineD3DPixelShaderImpl_GenerateShader(
#endif
}
inline static void pshader_program_dump_ps_param(const DWORD param, int input) {
static const char* rastout_reg_names[] = { "oC0", "oC1", "oC2", "oC3", "oDepth" };
static const char swizzle_reg_chars[] = "rgba";
DWORD reg = param & D3DSP_REGNUM_MASK;
DWORD regtype = shader_get_regtype(param);
if (input) {
if ( ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_BIASNEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_SIGNNEG) ||
((param & D3DSP_SRCMOD_MASK) == D3DSPSM_X2NEG) )
TRACE("-");
else if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_COMP)
TRACE("1-");
}
switch (regtype) {
case D3DSPR_TEMP:
TRACE("r%lu", reg);
break;
case D3DSPR_INPUT:
TRACE("v%lu", reg);
break;
case D3DSPR_CONST:
TRACE("c%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_TEXTURE: /* case D3DSPR_ADDR: */
TRACE("t%lu", reg);
break;
case D3DSPR_RASTOUT:
TRACE("%s", rastout_reg_names[reg]);
break;
case D3DSPR_ATTROUT:
TRACE("oD%lu", reg);
break;
case D3DSPR_TEXCRDOUT:
TRACE("oT%lu", reg);
break;
case D3DSPR_CONSTINT:
TRACE("i%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_CONSTBOOL:
TRACE("b%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_LABEL:
TRACE("l%lu", reg);
break;
case D3DSPR_LOOP:
TRACE("aL%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_SAMPLER:
TRACE("s%lu", reg);
break;
default:
TRACE("unhandled_rtype(%lx)", regtype);
break;
}
if (!input) {
/* operand output (for modifiers and shift, see dump_ins_modifiers) */
if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
TRACE(".");
if (param & D3DSP_WRITEMASK_0) TRACE(".r");
if (param & D3DSP_WRITEMASK_1) TRACE(".g");
if (param & D3DSP_WRITEMASK_2) TRACE(".b");
if (param & D3DSP_WRITEMASK_3) TRACE(".a");
}
} else {
/** operand input */
DWORD swizzle = (param & D3DSP_SWIZZLE_MASK) >> D3DSP_SWIZZLE_SHIFT;
DWORD swizzle_r = swizzle & 0x03;
DWORD swizzle_g = (swizzle >> 2) & 0x03;
DWORD swizzle_b = (swizzle >> 4) & 0x03;
DWORD swizzle_a = (swizzle >> 6) & 0x03;
if (0 != (param & D3DSP_SRCMOD_MASK)) {
DWORD mask = param & D3DSP_SRCMOD_MASK;
/*TRACE("_modifier(0x%08lx) ", mask);*/
switch (mask) {
case D3DSPSM_NONE: break;
case D3DSPSM_NEG: break;
case D3DSPSM_BIAS: TRACE("_bias"); break;
case D3DSPSM_BIASNEG: TRACE("_bias"); break;
case D3DSPSM_SIGN: TRACE("_bx2"); break;
case D3DSPSM_SIGNNEG: TRACE("_bx2"); break;
case D3DSPSM_COMP: break;
case D3DSPSM_X2: TRACE("_x2"); break;
case D3DSPSM_X2NEG: TRACE("_x2"); break;
case D3DSPSM_DZ: TRACE("_dz"); break;
case D3DSPSM_DW: TRACE("_dw"); break;
default:
TRACE("_unknown(0x%08lx)", mask);
}
}
/**
* swizzle bits fields:
* RRGGBBAA
*/
if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
if (swizzle_r == swizzle_g &&
swizzle_r == swizzle_b &&
swizzle_r == swizzle_a) {
TRACE(".%c", swizzle_reg_chars[swizzle_r]);
} else {
TRACE(".%c%c%c%c",
swizzle_reg_chars[swizzle_r],
swizzle_reg_chars[swizzle_g],
swizzle_reg_chars[swizzle_b],
swizzle_reg_chars[swizzle_a]);
}
}
}
}
HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, CONST DWORD *pFunction) {
IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
const DWORD* pToken = pFunction;
......@@ -1498,13 +1371,13 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
if (NULL != pToken) {
while (D3DPS_END() != *pToken) {
if (pshader_is_version_token(*pToken)) { /** version */
if (shader_is_pshader_version(*pToken)) { /** version */
pshader_set_version(This, *pToken);
++pToken;
++len;
continue;
}
if (pshader_is_comment_token(*pToken)) { /** comment */
if (shader_is_comment(*pToken)) { /** comment */
DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
++pToken;
TRACE("//%s\n", (char*)pToken);
......@@ -1545,7 +1418,7 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
shader_dump_ins_modifiers(param);
TRACE(" ");
pshader_program_dump_ps_param(param, 0);
shader_dump_param((IWineD3DBaseShader*) This, param, 0);
pToken += 2;
len += 2;
......@@ -1571,12 +1444,12 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface, C
if (curOpcode->num_params > 0) {
shader_dump_ins_modifiers(*pToken);
TRACE(" ");
pshader_program_dump_ps_param(*pToken, 0);
shader_dump_param((IWineD3DBaseShader*) This, *pToken, 0);
++pToken;
++len;
for (i = 1; i < curOpcode->num_params; ++i) {
TRACE(", ");
pshader_program_dump_ps_param(*pToken, 1);
shader_dump_param((IWineD3DBaseShader*) This, *pToken, 1);
++pToken;
++len;
}
......
......@@ -564,100 +564,6 @@ CONST SHADER_OPCODE IWineD3DVertexShaderImpl_shader_ins[] = {
{0, NULL, NULL, 0, NULL, NULL, 0, 0}
};
inline static void vshader_program_dump_vs_param(const DWORD param, int input) {
static const char* rastout_reg_names[] = { "oPos", "oFog", "oPts" };
static const char swizzle_reg_chars[] = "xyzw";
DWORD reg = param & D3DSP_REGNUM_MASK;
DWORD regtype = shader_get_regtype(param);
if ((param & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG) TRACE("-");
switch (regtype) {
case D3DSPR_TEMP:
TRACE("r%lu", reg);
break;
case D3DSPR_INPUT:
TRACE("v%lu", reg);
break;
case D3DSPR_CONST:
TRACE("c%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_ADDR: /*case D3DSPR_TEXTURE:*/
TRACE("a%lu", reg);
break;
case D3DSPR_RASTOUT:
TRACE("%s", rastout_reg_names[reg]);
break;
case D3DSPR_ATTROUT:
TRACE("oD%lu", reg);
break;
case D3DSPR_TEXCRDOUT:
TRACE("oT%lu", reg);
break;
case D3DSPR_CONSTINT:
TRACE("i%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_CONSTBOOL:
TRACE("b%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_LABEL:
TRACE("l%lu", reg);
break;
case D3DSPR_LOOP:
TRACE("aL%s%lu", (param & D3DVS_ADDRMODE_RELATIVE) ? "a0.x + " : "", reg);
break;
case D3DSPR_SAMPLER:
TRACE("s%lu", reg);
break;
default:
FIXME("Unknown %lu reg %lu\n",regtype, reg);
break;
}
if (!input) {
/** operand output */
if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
if (param & D3DSP_WRITEMASK_0) TRACE(".x");
if (param & D3DSP_WRITEMASK_1) TRACE(".y");
if (param & D3DSP_WRITEMASK_2) TRACE(".z");
if (param & D3DSP_WRITEMASK_3) TRACE(".w");
}
} else {
/** operand input */
DWORD swizzle = (param & D3DVS_SWIZZLE_MASK) >> D3DVS_SWIZZLE_SHIFT;
DWORD swizzle_x = swizzle & 0x03;
DWORD swizzle_y = (swizzle >> 2) & 0x03;
DWORD swizzle_z = (swizzle >> 4) & 0x03;
DWORD swizzle_w = (swizzle >> 6) & 0x03;
/**
* swizzle bits fields:
* WWZZYYXX
*/
if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) != swizzle) { /* ! D3DVS_NOSWIZZLE == 0xE4 << D3DVS_SWIZZLE_SHIFT */
if (swizzle_x == swizzle_y &&
swizzle_x == swizzle_z &&
swizzle_x == swizzle_w) {
TRACE(".%c", swizzle_reg_chars[swizzle_x]);
} else {
TRACE(".%c%c%c%c",
swizzle_reg_chars[swizzle_x],
swizzle_reg_chars[swizzle_y],
swizzle_reg_chars[swizzle_z],
swizzle_reg_chars[swizzle_w]);
}
}
}
}
inline static BOOL vshader_is_version_token(DWORD token) {
return 0xFFFE0000 == (token & 0xFFFE0000);
}
inline static BOOL vshader_is_comment_token(DWORD token) {
return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
}
inline static void vshader_program_add_output_param_swizzle(const DWORD param, int is_color, char *hwLine) {
/** operand output */
if ((param & D3DSP_WRITEMASK_ALL) != D3DSP_WRITEMASK_ALL) {
......@@ -1254,11 +1160,11 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_ExecuteSW(IWineD3DVertexShader* iface, W
/* the first dword is the version tag */
/* TODO: parse it */
if (vshader_is_version_token(*pToken)) { /** version */
if (shader_is_vshader_version(*pToken)) { /** version */
++pToken;
}
while (D3DVS_END() != *pToken) {
if (vshader_is_comment_token(*pToken)) { /** comment */
if (shader_is_comment(*pToken)) { /** comment */
DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
++pToken;
pToken += comment_len;
......@@ -1275,7 +1181,7 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_ExecuteSW(IWineD3DVertexShader* iface, W
FIXME("unrecognized opcode: pos=%d token=%08lX\n", (pToken - 1) - This->baseShader.function, *(pToken - 1));
}
FIXME("unrecognized opcode param: pos=%d token=%08lX what=", pToken - This->baseShader.function, *pToken);
vshader_program_dump_vs_param(*pToken, i);
shader_dump_param((IWineD3DBaseShader*) This, *pToken, i);
TRACE("\n");
++i;
++pToken;
......@@ -1606,13 +1512,13 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
if (NULL != pToken) {
while (D3DVS_END() != *pToken) {
if (vshader_is_version_token(*pToken)) { /** version */
if (shader_is_vshader_version(*pToken)) { /** version */
vshader_set_version(This, *pToken);
++pToken;
++len;
continue;
}
if (vshader_is_comment_token(*pToken)) { /** comment */
if (shader_is_comment(*pToken)) { /** comment */
DWORD comment_len = (*pToken & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT;
++pToken;
TRACE("//%s\n", (char*)pToken);
......@@ -1643,7 +1549,7 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
shader_program_dump_decl_usage(usage, param);
shader_dump_ins_modifiers(param);
TRACE(" ");
vshader_program_dump_vs_param(param, 0);
shader_dump_param((IWineD3DBaseShader*) This, param, 0);
pToken += 2;
len += 2;
......@@ -1669,12 +1575,12 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
if (curOpcode->num_params > 0) {
shader_dump_ins_modifiers(*pToken);
TRACE(" ");
vshader_program_dump_vs_param(*pToken, 0);
shader_dump_param((IWineD3DBaseShader*) This, *pToken, 0);
++pToken;
++len;
for (i = 1; i < curOpcode->num_params; ++i) {
TRACE(", ");
vshader_program_dump_vs_param(*pToken, 1);
shader_dump_param((IWineD3DBaseShader*) This, *pToken, 1);
++pToken;
++len;
}
......
......@@ -1367,11 +1367,28 @@ extern void generate_base_shader(
extern void shader_dump_ins_modifiers(
const DWORD output);
extern void shader_dump_param(
IWineD3DBaseShader *iface,
const DWORD param,
int input);
inline static int shader_get_regtype(const DWORD param) {
return (((param & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) |
((param & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2));
}
inline static BOOL shader_is_pshader_version(DWORD token) {
return 0xFFFF0000 == (token & 0xFFFF0000);
}
inline static BOOL shader_is_vshader_version(DWORD token) {
return 0xFFFE0000 == (token & 0xFFFF0000);
}
inline static BOOL shader_is_comment(DWORD token) {
return D3DSIO_COMMENT == (token & D3DSI_OPCODE_MASK);
}
/*****************************************************************************
* IDirect3DVertexShader implementation structure
*/
......
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