Commit 8a4a76f9 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move "parse_state" to wined3d_shader_context.

parent de417974
......@@ -2117,8 +2117,7 @@ static void pshader_hw_texm3x2tex(const struct wined3d_shader_instruction *ins)
static void pshader_hw_texm3x3pad(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
char src0_name[50], dst_name[50];
......@@ -2129,20 +2128,19 @@ static void pshader_hw_texm3x3pad(const struct wined3d_shader_instruction *ins)
* incrementing ins->dst[0].register_idx numbers. So the pad instruction already knows the final destination
* register, and this register is uninitialized(otherwise the assembler complains that it is 'redeclared')
*/
tmp_reg.idx = reg + 2 - current_state->current_row;
tmp_reg.idx = reg + 2 - tex_mx->current_row;
shader_arb_get_register_name(ins, &tmp_reg, dst_name, &is_color);
shader_arb_get_src_param(ins, &ins->src[0], 0, src0_name);
shader_addline(buffer, "DP3 %s.%c, fragment.texcoord[%u], %s;\n",
dst_name, 'x' + current_state->current_row, reg, src0_name);
current_state->texcoord_w[current_state->current_row++] = reg;
dst_name, 'x' + tex_mx->current_row, reg, src0_name);
tex_mx->texcoord_w[tex_mx->current_row++] = reg;
}
static void pshader_hw_texm3x3tex(const struct wined3d_shader_instruction *ins)
{
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
DWORD flags;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
......@@ -2158,14 +2156,13 @@ static void pshader_hw_texm3x3tex(const struct wined3d_shader_instruction *ins)
shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0;
shader_hw_sample(ins, reg, dst_str, dst_name, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
current_state->current_row = 0;
tex_mx->current_row = 0;
}
static void pshader_hw_texm3x3vspec(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
DWORD flags;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
......@@ -2182,8 +2179,8 @@ static void pshader_hw_texm3x3vspec(const struct wined3d_shader_instruction *ins
shader_addline(buffer, "DP3 %s.z, fragment.texcoord[%u], %s;\n", dst_reg, reg, src0_name);
/* Construct the eye-ray vector from w coordinates */
shader_addline(buffer, "MOV TB.x, fragment.texcoord[%u].w;\n", current_state->texcoord_w[0]);
shader_addline(buffer, "MOV TB.y, fragment.texcoord[%u].w;\n", current_state->texcoord_w[1]);
shader_addline(buffer, "MOV TB.x, fragment.texcoord[%u].w;\n", tex_mx->texcoord_w[0]);
shader_addline(buffer, "MOV TB.y, fragment.texcoord[%u].w;\n", tex_mx->texcoord_w[1]);
shader_addline(buffer, "MOV TB.z, fragment.texcoord[%u].w;\n", reg);
/* Calculate reflection vector
......@@ -2200,14 +2197,13 @@ static void pshader_hw_texm3x3vspec(const struct wined3d_shader_instruction *ins
shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0;
shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
current_state->current_row = 0;
tex_mx->current_row = 0;
}
static void pshader_hw_texm3x3spec(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
DWORD flags;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
......@@ -2242,7 +2238,7 @@ static void pshader_hw_texm3x3spec(const struct wined3d_shader_instruction *ins)
shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
flags = reg < MAX_TEXTURES ? priv->cur_ps_args->super.tex_transform >> reg * WINED3D_PSARGS_TEXTRANSFORM_SHIFT : 0;
shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
current_state->current_row = 0;
tex_mx->current_row = 0;
}
static void pshader_hw_texdepth(const struct wined3d_shader_instruction *ins)
......
......@@ -3327,16 +3327,15 @@ static void shader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins)
* Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
static void shader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
glsl_src_param_t src0_param;
shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + current_state->current_row, reg, src0_param.param_str);
current_state->texcoord_w[current_state->current_row++] = reg;
shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + tex_mx->current_row, reg, src0_param.param_str);
tex_mx->texcoord_w[tex_mx->current_row++] = reg;
}
static void shader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins)
......@@ -3361,8 +3360,7 @@ static void shader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins)
static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
{
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
glsl_src_param_t src0_param;
DWORD reg = ins->dst[0].reg.idx;
glsl_sample_function_t sample_function;
......@@ -3376,7 +3374,7 @@ static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
/* Sample the texture using the calculated coordinates */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
current_state->current_row = 0;
tex_mx->current_row = 0;
}
/** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
......@@ -3384,8 +3382,7 @@ static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins)
{
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
SHADER_PARSE_STATE *current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
glsl_src_param_t src0_param;
char dst_mask[6];
DWORD reg = ins->dst[0].reg.idx;
......@@ -3396,19 +3393,18 @@ static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins)
shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
shader_addline(ins->ctx->buffer, "vec4(tmp0.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask);
current_state->current_row = 0;
tex_mx->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
DWORD reg = ins->dst[0].reg.idx;
glsl_src_param_t src0_param;
glsl_src_param_t src1_param;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
glsl_sample_function_t sample_function;
......@@ -3426,17 +3422,16 @@ static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins
/* Sample the texture */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
current_state->current_row = 0;
tex_mx->current_row = 0;
}
/* Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL
* Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *ins)
{
IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
DWORD reg = ins->dst[0].reg.idx;
struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
glsl_src_param_t src0_param;
DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
glsl_sample_function_t sample_function;
......@@ -3448,7 +3443,7 @@ static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *in
/* Construct the eye-ray vector from w coordinates */
shader_addline(buffer, "tmp1.xyz = normalize(vec3(gl_TexCoord[%u].w, gl_TexCoord[%u].w, gl_TexCoord[%u].w));\n",
current_state->texcoord_w[0], current_state->texcoord_w[1], reg);
tex_mx->texcoord_w[0], tex_mx->texcoord_w[1], reg);
shader_addline(buffer, "tmp0.xyz = -reflect(tmp1.xyz, normalize(tmp0.xyz));\n");
/* Dependent read, not valid with conditional NP2 */
......@@ -3457,7 +3452,7 @@ static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *in
/* Sample the texture using the calculated coordinates */
shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
current_state->current_row = 0;
tex_mx->current_row = 0;
}
/** Process the WINED3DSIO_TEXBEM instruction in GLSL.
......
......@@ -1191,21 +1191,24 @@ void shader_generate_main(IWineD3DBaseShader *iface, struct wined3d_shader_buffe
struct wined3d_shader_src_param src_param[4];
struct wined3d_shader_version shader_version;
struct wined3d_shader_instruction ins;
struct wined3d_shader_tex_mx tex_mx;
struct wined3d_shader_context ctx;
const DWORD *ptr = byte_code;
DWORD i;
/* Initialize current parsing state. */
tex_mx.current_row = 0;
ctx.shader = iface;
ctx.gl_info = &device->adapter->gl_info;
ctx.reg_maps = reg_maps;
ctx.buffer = buffer;
ctx.tex_mx = &tex_mx;
ctx.backend_data = backend_ctx;
ins.ctx = &ctx;
ins.dst = dst_param;
ins.src = src_param;
shader->baseShader.parse_state.current_row = 0;
fe->shader_read_header(fe_data, &ptr, &shader_version);
......
......@@ -565,12 +565,21 @@ typedef struct shader_reg_maps
} shader_reg_maps;
/* Keeps track of details for TEX_M#x# instructions which need to maintain
* state information between multiple instructions. */
struct wined3d_shader_tex_mx
{
unsigned int current_row;
DWORD texcoord_w[2];
};
struct wined3d_shader_context
{
IWineD3DBaseShader *shader;
const struct wined3d_gl_info *gl_info;
const struct shader_reg_maps *reg_maps;
struct wined3d_shader_buffer *buffer;
struct wined3d_shader_tex_mx *tex_mx;
void *backend_data;
};
......@@ -2715,13 +2724,6 @@ typedef struct SHADER_LIMITS {
unsigned int label;
} SHADER_LIMITS;
/* Keeps track of details for TEX_M#x# shader opcodes which need to
* maintain state information between multiple codes */
typedef struct SHADER_PARSE_STATE {
unsigned int current_row;
DWORD texcoord_w[2];
} SHADER_PARSE_STATE;
#ifdef __GNUC__
#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
#else
......@@ -2743,7 +2745,6 @@ typedef struct IWineD3DBaseShaderClass
{
LONG ref;
SHADER_LIMITS limits;
SHADER_PARSE_STATE parse_state;
DWORD *function;
UINT functionLength;
UINT cur_loop_depth, cur_loop_regno;
......
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