Commit 42582ada authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Read complete shader instructions at a time.

parent f2437c2b
...@@ -204,6 +204,13 @@ struct wined3d_sm1_data ...@@ -204,6 +204,13 @@ struct wined3d_sm1_data
{ {
struct wined3d_shader_version shader_version; struct wined3d_shader_version shader_version;
const struct wined3d_sm1_opcode_info *opcode_table; const struct wined3d_sm1_opcode_info *opcode_table;
struct wined3d_shader_src_param src_rel_addr[4];
struct wined3d_shader_src_param pred_rel_addr;
struct wined3d_shader_src_param dst_rel_addr;
struct wined3d_shader_src_param src_param[4];
struct wined3d_shader_src_param pred_param;
struct wined3d_shader_dst_param dst_param;
}; };
/* This table is not order or position dependent. */ /* This table is not order or position dependent. */
...@@ -568,36 +575,9 @@ static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d ...@@ -568,36 +575,9 @@ static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d
*shader_version = priv->shader_version; *shader_version = priv->shader_version;
} }
static void shader_sm1_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, static void shader_sm1_read_src_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
UINT *param_size) struct wined3d_shader_src_param *src_param, struct wined3d_shader_src_param *src_rel_addr)
{ {
struct wined3d_sm1_data *priv = data;
const struct wined3d_sm1_opcode_info *opcode_info;
DWORD opcode_token;
opcode_token = *(*ptr)++;
opcode_info = shader_get_opcode(priv, opcode_token);
if (!opcode_info)
{
FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
ins->handler_idx = WINED3DSIH_TABLE_SIZE;
*param_size = shader_skip_unrecognized(priv, *ptr);
return;
}
ins->handler_idx = opcode_info->handler_idx;
ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
ins->coissue = opcode_token & WINED3DSI_COISSUE;
ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED;
ins->dst_count = opcode_info->dst_count ? 1 : 0;
ins->src_count = opcode_info->param_count - opcode_info->dst_count;
*param_size = shader_skip_opcode(priv, opcode_info, opcode_token);
}
static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
struct wined3d_shader_src_param *src_rel_addr)
{
struct wined3d_sm1_data *priv = data;
DWORD token, addr_token; DWORD token, addr_token;
*ptr += shader_get_param(priv, *ptr, &token, &addr_token); *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
...@@ -612,10 +592,9 @@ static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wine ...@@ -612,10 +592,9 @@ static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wine
} }
} }
static void shader_sm1_read_dst_param(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param, static void shader_sm1_read_dst_param(struct wined3d_sm1_data *priv, const DWORD **ptr,
struct wined3d_shader_src_param *dst_rel_addr) struct wined3d_shader_dst_param *dst_param, struct wined3d_shader_src_param *dst_rel_addr)
{ {
struct wined3d_sm1_data *priv = data;
DWORD token, addr_token; DWORD token, addr_token;
*ptr += shader_get_param(priv, *ptr, &token, &addr_token); *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
...@@ -641,6 +620,84 @@ static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_se ...@@ -641,6 +620,84 @@ static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_se
shader_parse_dst_param(dst_token, NULL, &semantic->reg); shader_parse_dst_param(dst_token, NULL, &semantic->reg);
} }
static void shader_sm1_read_immconst(const DWORD **ptr, struct wined3d_shader_src_param *src_param,
enum wined3d_immconst_type type)
{
UINT count = type == WINED3D_IMMCONST_VEC4 ? 4 : 1;
src_param->reg.type = WINED3DSPR_IMMCONST;
src_param->reg.idx = ~0U;
src_param->reg.array_idx = ~0U;
src_param->reg.rel_addr = NULL;
src_param->reg.immconst_type = type;
memcpy(src_param->reg.immconst_data, *ptr, count * sizeof(DWORD));
src_param->swizzle = WINED3DSP_NOSWIZZLE;
src_param->modifiers = 0;
*ptr += count;
}
static void shader_sm1_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
{
const struct wined3d_sm1_opcode_info *opcode_info;
struct wined3d_sm1_data *priv = data;
DWORD opcode_token;
unsigned int i;
const DWORD *p;
opcode_token = *(*ptr)++;
if (!(opcode_info = shader_get_opcode(priv, opcode_token)))
{
FIXME("Unrecognized opcode: token=0x%08x.\n", opcode_token);
ins->handler_idx = WINED3DSIH_TABLE_SIZE;
*ptr += shader_skip_unrecognized(priv, *ptr);
return;
}
ins->handler_idx = opcode_info->handler_idx;
ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
ins->coissue = opcode_token & WINED3DSI_COISSUE;
ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED ? &priv->pred_param : NULL;
ins->dst_count = opcode_info->dst_count ? 1 : 0;
ins->dst = &priv->dst_param;
ins->src_count = opcode_info->param_count - opcode_info->dst_count;
ins->src = priv->src_param;
p = *ptr;
*ptr += shader_skip_opcode(priv, opcode_info, opcode_token);
if (ins->handler_idx == WINED3DSIH_DCL)
{
shader_sm1_read_semantic(&p, &ins->semantic);
}
else if (ins->handler_idx == WINED3DSIH_DEF
|| 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);
}
else if (ins->handler_idx == WINED3DSIH_DEFB)
{
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);
}
else
{
/* Destination token */
if (ins->dst_count)
shader_sm1_read_dst_param(priv, &p, &priv->dst_param, &priv->dst_rel_addr);
/* Predication token */
if (ins->predicate)
shader_sm1_read_src_param(priv, &p, &priv->pred_param, &priv->pred_rel_addr);
/* Other source tokens */
for (i = 0; i < ins->src_count; ++i)
{
shader_sm1_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]);
}
}
}
static void shader_sm1_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size) static void shader_sm1_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size)
{ {
DWORD token = **ptr; DWORD token = **ptr;
...@@ -674,10 +731,7 @@ const struct wined3d_shader_frontend sm1_shader_frontend = ...@@ -674,10 +731,7 @@ const struct wined3d_shader_frontend sm1_shader_frontend =
shader_sm1_init, shader_sm1_init,
shader_sm1_free, shader_sm1_free,
shader_sm1_read_header, shader_sm1_read_header,
shader_sm1_read_opcode, shader_sm1_read_instruction,
shader_sm1_read_src_param,
shader_sm1_read_dst_param,
shader_sm1_read_semantic,
shader_sm1_read_comment, shader_sm1_read_comment,
shader_sm1_is_end, shader_sm1_is_end,
}; };
...@@ -122,6 +122,11 @@ struct wined3d_sm4_data ...@@ -122,6 +122,11 @@ struct wined3d_sm4_data
struct wined3d_shader_version shader_version; struct wined3d_shader_version shader_version;
const DWORD *end; const DWORD *end;
const struct wined3d_shader_signature *output_signature; const struct wined3d_shader_signature *output_signature;
struct wined3d_shader_src_param src_rel_addr[5];
struct wined3d_shader_src_param dst_rel_addr[2];
struct wined3d_shader_src_param src_param[5];
struct wined3d_shader_dst_param dst_param[2];
}; };
struct wined3d_sm4_opcode_info struct wined3d_sm4_opcode_info
...@@ -333,41 +338,9 @@ static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d ...@@ -333,41 +338,9 @@ static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d
*shader_version = priv->shader_version; *shader_version = priv->shader_version;
} }
static void shader_sm4_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, static void shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
UINT *param_size) struct wined3d_shader_src_param *src_param, struct wined3d_shader_src_param *src_rel_addr)
{ {
const struct wined3d_sm4_opcode_info *opcode_info;
DWORD token = *(*ptr)++;
DWORD opcode = token & WINED3D_SM4_OPCODE_MASK;
*param_size = ((token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
opcode_info = get_opcode_info(opcode);
if (!opcode_info)
{
FIXME("Unrecognized opcode %#x, token 0x%08x\n", opcode, token);
ins->handler_idx = WINED3DSIH_TABLE_SIZE;
return;
}
ins->handler_idx = opcode_info->handler_idx;
ins->flags = 0;
ins->coissue = 0;
ins->predicate = 0;
ins->dst_count = opcode_info->dst_count;
ins->src_count = opcode_info->src_count;
if (token & WINED3D_SM4_INSTRUCTION_MODIFIER)
{
DWORD modifier = *(*ptr)++;
FIXME("Skipping modifier 0x%08x.\n", modifier);
}
}
static void shader_sm4_read_src_param(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
struct wined3d_shader_src_param *src_rel_addr)
{
struct wined3d_sm4_data *priv = data;
DWORD token = *(*ptr)++; DWORD token = *(*ptr)++;
enum wined3d_sm4_register_type register_type; enum wined3d_sm4_register_type register_type;
DWORD order; DWORD order;
...@@ -456,10 +429,9 @@ static void shader_sm4_read_src_param(void *data, const DWORD **ptr, struct wine ...@@ -456,10 +429,9 @@ static void shader_sm4_read_src_param(void *data, const DWORD **ptr, struct wine
map_register(priv, &src_param->reg); map_register(priv, &src_param->reg);
} }
static void shader_sm4_read_dst_param(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param, static void shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
struct wined3d_shader_src_param *dst_rel_addr) struct wined3d_shader_dst_param *dst_param, struct wined3d_shader_src_param *dst_rel_addr)
{ {
struct wined3d_sm4_data *priv = data;
DWORD token = *(*ptr)++; DWORD token = *(*ptr)++;
enum wined3d_sm4_register_type register_type; enum wined3d_sm4_register_type register_type;
DWORD order; DWORD order;
...@@ -493,9 +465,53 @@ static void shader_sm4_read_dst_param(void *data, const DWORD **ptr, struct wine ...@@ -493,9 +465,53 @@ static void shader_sm4_read_dst_param(void *data, const DWORD **ptr, struct wine
map_register(priv, &dst_param->reg); map_register(priv, &dst_param->reg);
} }
static void shader_sm4_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic) static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
{ {
FIXME("ptr %p, semantic %p stub!\n", ptr, semantic); const struct wined3d_sm4_opcode_info *opcode_info;
struct wined3d_sm4_data *priv = data;
DWORD opcode_token, opcode;
const DWORD *p;
UINT i, len;
opcode_token = *(*ptr)++;
opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT) - 1;
if (!(opcode_info = get_opcode_info(opcode)))
{
FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode, opcode_token);
ins->handler_idx = WINED3DSIH_TABLE_SIZE;
*ptr += len;
return;
}
ins->handler_idx = opcode_info->handler_idx;
ins->flags = 0;
ins->coissue = 0;
ins->predicate = NULL;
ins->dst_count = opcode_info->dst_count;
ins->dst = priv->dst_param;
ins->src_count = opcode_info->src_count;
ins->src = priv->src_param;
p = *ptr;
*ptr += len;
if (opcode_token & WINED3D_SM4_INSTRUCTION_MODIFIER)
{
DWORD modifier = *p++;
FIXME("Skipping modifier 0x%08x.\n", modifier);
}
for (i = 0; i < ins->dst_count; ++i)
{
shader_sm4_read_dst_param(priv, &p, &priv->dst_param[i], &priv->dst_rel_addr[i]);
}
for (i = 0; i < ins->src_count; ++i)
{
shader_sm4_read_src_param(priv, &p, &priv->src_param[i], &priv->src_rel_addr[i]);
}
} }
static void shader_sm4_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size) static void shader_sm4_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size)
...@@ -515,10 +531,7 @@ const struct wined3d_shader_frontend sm4_shader_frontend = ...@@ -515,10 +531,7 @@ const struct wined3d_shader_frontend sm4_shader_frontend =
shader_sm4_init, shader_sm4_init,
shader_sm4_free, shader_sm4_free,
shader_sm4_read_header, shader_sm4_read_header,
shader_sm4_read_opcode, shader_sm4_read_instruction,
shader_sm4_read_src_param,
shader_sm4_read_dst_param,
shader_sm4_read_semantic,
shader_sm4_read_comment, shader_sm4_read_comment,
shader_sm4_is_end, shader_sm4_is_end,
}; };
...@@ -634,25 +634,26 @@ struct wined3d_shader_src_param ...@@ -634,25 +634,26 @@ struct wined3d_shader_src_param
enum wined3d_shader_src_modifier modifiers; enum wined3d_shader_src_modifier modifiers;
}; };
struct wined3d_shader_semantic
{
enum wined3d_decl_usage usage;
UINT usage_idx;
enum wined3d_sampler_texture_type sampler_type;
struct wined3d_shader_dst_param reg;
};
struct wined3d_shader_instruction struct wined3d_shader_instruction
{ {
const struct wined3d_shader_context *ctx; const struct wined3d_shader_context *ctx;
enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx; enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
DWORD flags; DWORD flags;
BOOL coissue; BOOL coissue;
DWORD predicate; const struct wined3d_shader_src_param *predicate;
UINT dst_count; UINT dst_count;
const struct wined3d_shader_dst_param *dst; const struct wined3d_shader_dst_param *dst;
UINT src_count; UINT src_count;
const struct wined3d_shader_src_param *src; const struct wined3d_shader_src_param *src;
}; struct wined3d_shader_semantic semantic;
struct wined3d_shader_semantic
{
enum wined3d_decl_usage usage;
UINT usage_idx;
enum wined3d_sampler_texture_type sampler_type;
struct wined3d_shader_dst_param reg;
}; };
struct wined3d_shader_attribute struct wined3d_shader_attribute
...@@ -673,12 +674,7 @@ struct wined3d_shader_frontend ...@@ -673,12 +674,7 @@ struct wined3d_shader_frontend
void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature); void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature);
void (*shader_free)(void *data); void (*shader_free)(void *data);
void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version); void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
void (*shader_read_opcode)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size); void (*shader_read_instruction)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins);
void (*shader_read_src_param)(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
struct wined3d_shader_src_param *src_rel_addr);
void (*shader_read_dst_param)(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
struct wined3d_shader_src_param *dst_rel_addr);
void (*shader_read_semantic)(const DWORD **ptr, struct wined3d_shader_semantic *semantic);
void (*shader_read_comment)(const DWORD **ptr, const char **comment, UINT *comment_size); void (*shader_read_comment)(const DWORD **ptr, const char **comment, UINT *comment_size);
BOOL (*shader_is_end)(void *data, const DWORD **ptr); BOOL (*shader_is_end)(void *data, const DWORD **ptr);
}; };
......
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