wined3d: Clean up SM1 frontend.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2016-05-25 10:51:19 +02:00 committed by Alexandre Julliard
parent 3ab205ef94
commit 8d48454a36
1 changed files with 27 additions and 31 deletions

View File

@ -202,8 +202,8 @@ enum wined3d_sm1_opcode
struct wined3d_sm1_opcode_info struct wined3d_sm1_opcode_info
{ {
enum wined3d_sm1_opcode opcode; enum wined3d_sm1_opcode opcode;
UINT dst_count; unsigned int dst_count;
UINT param_count; unsigned int param_count;
enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx; enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
DWORD min_version; DWORD min_version;
DWORD max_version; DWORD max_version;
@ -398,9 +398,10 @@ static const enum wined3d_shader_resource_type resource_type_table[] =
/* Read a parameter opcode from the input stream, /* Read a parameter opcode from the input stream,
* and possibly a relative addressing token. * and possibly a relative addressing token.
* Return the number of tokens read */ * Return the number of tokens read */
static int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token) static unsigned int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr,
DWORD *token, DWORD *addr_token)
{ {
UINT count = 1; unsigned int count = 1;
*token = *ptr; *token = *ptr;
@ -427,15 +428,15 @@ static int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *pt
return count; return count;
} }
static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD code) static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD token)
{ {
DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor); DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table; const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table;
DWORD i = 0; unsigned int i = 0;
while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE) while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE)
{ {
if ((code & WINED3D_SM1_OPCODE_MASK) == opcode_table[i].opcode if ((token & WINED3D_SM1_OPCODE_MASK) == opcode_table[i].opcode
&& shader_version >= opcode_table[i].min_version && shader_version >= opcode_table[i].min_version
&& (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version)) && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
{ {
@ -444,19 +445,20 @@ static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wine
++i; ++i;
} }
FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n", FIXME("Unsupported opcode %#x, token 0x%08x, shader version %#x.\n",
code, code, code & WINED3D_SM1_OPCODE_MASK, shader_version); token & WINED3D_SM1_OPCODE_MASK, token, shader_version);
return NULL; return NULL;
} }
/* Return the number of parameters to skip for an opcode */ /* Return the number of parameters to skip for an opcode */
static int shader_skip_opcode(const struct wined3d_sm1_data *priv, static unsigned int shader_skip_opcode(const struct wined3d_sm1_data *priv,
const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token) const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
{ {
unsigned int length;
/* Shaders >= 2.0 may contain address tokens, but fortunately they /* Shaders >= 2.0 may contain address tokens, but fortunately they
* have a useful length mask - use it here. Shaders 1.0 contain no such tokens */ * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
DWORD length = (opcode_token & WINED3D_SM1_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM1_INSTRUCTION_LENGTH_SHIFT; length = (opcode_token & WINED3D_SM1_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM1_INSTRUCTION_LENGTH_SHIFT;
return (priv->shader_version.major >= 2) ? length : opcode_info->param_count; return (priv->shader_version.major >= 2) ? length : opcode_info->param_count;
} }
@ -495,10 +497,9 @@ static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_
* Note: This function assumes source or destination token format. * Note: This function assumes source or destination token format.
* It will not work with specially-formatted tokens like DEF or DCL, * It will not work with specially-formatted tokens like DEF or DCL,
* but hopefully those would be recognized */ * but hopefully those would be recognized */
static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr) static unsigned int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
{ {
int tokens_read = 0; unsigned int tokens_read = 0, i = 0;
int i = 0;
/* TODO: Think of a good name for 0x80000000 and replace it with a constant */ /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
while (*ptr & 0x80000000) while (*ptr & 0x80000000)
@ -509,9 +510,10 @@ static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const D
tokens_read += shader_get_param(priv, ptr, &token, &addr_token); tokens_read += shader_get_param(priv, ptr, &token, &addr_token);
ptr += tokens_read; ptr += tokens_read;
FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x name=", token, addr_token); FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x.\n", token, addr_token);
if (token & WINED3D_SM1_ADDRESS_MODE_RELATIVE) shader_parse_src_param(addr_token, NULL, &rel_addr); if (token & WINED3D_SM1_ADDRESS_MODE_RELATIVE)
shader_parse_src_param(addr_token, NULL, &rel_addr);
if (!i) if (!i)
{ {
@ -525,7 +527,6 @@ static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const D
shader_parse_src_param(token, token & WINED3D_SM1_ADDRESS_MODE_RELATIVE ? &rel_addr : NULL, &src); shader_parse_src_param(token, token & WINED3D_SM1_ADDRESS_MODE_RELATIVE ? &rel_addr : NULL, &src);
} }
FIXME("\n");
++i; ++i;
} }
return tokens_read; return tokens_read;
@ -544,14 +545,11 @@ static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader
return NULL; return NULL;
} }
priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv)); if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
if (!priv)
return NULL; return NULL;
if (output_signature->element_count) if (output_signature->element_count)
{
FIXME("SM 1-3 shader shouldn't have output signatures.\n"); FIXME("SM 1-3 shader shouldn't have output signatures.\n");
}
switch (*byte_code >> 16) switch (*byte_code >> 16)
{ {
@ -566,7 +564,7 @@ static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader
break; break;
default: default:
FIXME("Unrecognized shader type %#x\n", *byte_code >> 16); FIXME("Unrecognized shader type %#x.\n", *byte_code >> 16);
HeapFree(GetProcessHeap(), 0, priv); HeapFree(GetProcessHeap(), 0, priv);
return NULL; return NULL;
} }
@ -585,7 +583,7 @@ static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d
DWORD version_token; DWORD version_token;
version_token = *(*ptr)++; version_token = *(*ptr)++;
TRACE("version: 0x%08x\n", version_token); TRACE("Version: 0x%08x.\n", version_token);
priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(version_token); priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(version_token);
priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(version_token); priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(version_token);
@ -651,7 +649,7 @@ static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_se
static void shader_sm1_read_immconst(const DWORD **ptr, struct wined3d_shader_src_param *src_param, static void shader_sm1_read_immconst(const DWORD **ptr, struct wined3d_shader_src_param *src_param,
enum wined3d_immconst_type type, enum wined3d_data_type data_type) enum wined3d_immconst_type type, enum wined3d_data_type data_type)
{ {
UINT count = type == WINED3D_IMMCONST_VEC4 ? 4 : 1; unsigned int count = type == WINED3D_IMMCONST_VEC4 ? 4 : 1;
src_param->reg.type = WINED3DSPR_IMMCONST; src_param->reg.type = WINED3DSPR_IMMCONST;
src_param->reg.data_type = data_type; src_param->reg.data_type = data_type;
src_param->reg.idx[0].offset = ~0U; src_param->reg.idx[0].offset = ~0U;
@ -762,16 +760,16 @@ static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wi
shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr); shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_FLOAT); shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_FLOAT);
} }
else if (ins->handler_idx == WINED3DSIH_DEFI)
{
shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_INT);
}
else if (ins->handler_idx == WINED3DSIH_DEFB) else if (ins->handler_idx == WINED3DSIH_DEFB)
{ {
shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr); shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_SCALAR, WINED3D_DATA_UINT); shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_SCALAR, WINED3D_DATA_UINT);
} }
else if (ins->handler_idx == WINED3DSIH_DEFI)
{
shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
shader_sm1_read_immconst(&p, &priv->src_param[0], WINED3D_IMMCONST_VEC4, WINED3D_DATA_INT);
}
else else
{ {
/* Destination token */ /* Destination token */
@ -784,9 +782,7 @@ static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wi
/* Other source tokens */ /* Other source tokens */
for (i = 0; i < ins->src_count; ++i) for (i = 0; i < ins->src_count; ++i)
{
shader_sm1_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]); shader_sm1_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]);
}
} }
shader_sm1_validate_instruction(ins); shader_sm1_validate_instruction(ins);