diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index ca0671d5769..94535498187 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -382,10 +382,11 @@ static const char * const shift_tab[] = { "coefdiv.x" /* 15 (d2) */ }; -static void shader_arb_get_write_mask(const SHADER_OPCODE_ARG *arg, const DWORD param, char *write_mask) +static void shader_arb_get_write_mask(const struct wined3d_shader_instruction *ins, + const DWORD param, char *write_mask) { char *ptr = write_mask; - char vshader = shader_is_vshader_version(arg->reg_maps->shader_version); + char vshader = shader_is_vshader_version(ins->reg_maps->shader_version); if(vshader && shader_get_regtype(param) == WINED3DSPR_ADDR) { *ptr++ = '.'; @@ -486,9 +487,10 @@ static void pshader_get_register_name(IWineD3DBaseShader* iface, } /* TODO: merge with pixel shader */ -static void vshader_program_add_param(const SHADER_OPCODE_ARG *arg, const DWORD param, BOOL is_input, char *hwLine) +static void vshader_program_add_param(const struct wined3d_shader_instruction *ins, + const DWORD param, BOOL is_input, char *hwLine) { - IWineD3DVertexShaderImpl* This = (IWineD3DVertexShaderImpl*) arg->shader; + IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)ins->shader; /* oPos, oFog and oPts in D3D */ static const char * const hwrastout_reg_names[] = { "TMP_OUT", "result.fogcoord", "result.pointsize" }; @@ -559,7 +561,7 @@ static void vshader_program_add_param(const SHADER_OPCODE_ARG *arg, const DWORD if (!is_input) { char write_mask[6]; - shader_arb_get_write_mask(arg, param, write_mask); + shader_arb_get_write_mask(ins, param, write_mask); strcat(hwLine, write_mask); } else { char swizzle[6]; @@ -636,13 +638,13 @@ static void gen_color_correction(SHADER_BUFFER *buffer, const char *reg, DWORD d } } -static void shader_hw_sample(const SHADER_OPCODE_ARG *arg, DWORD sampler_idx, const char *dst_str, - const char *coord_reg, BOOL projected, BOOL bias) +static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD sampler_idx, + const char *dst_str, const char *coord_reg, BOOL projected, BOOL bias) { - SHADER_BUFFER* buffer = arg->buffer; - DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + SHADER_BUFFER *buffer = ins->buffer; + DWORD sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; const char *tex_type; - IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *) arg->shader; + IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->shader; IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; switch(sampler_type) { @@ -683,9 +685,10 @@ static void shader_hw_sample(const SHADER_OPCODE_ARG *arg, DWORD sampler_idx, co shader_addline(buffer, "TEX %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type); } - if(shader_is_pshader_version(arg->reg_maps->shader_version)) { - IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) arg->shader; - gen_color_correction(buffer, dst_str, arg->dst & WINED3DSP_WRITEMASK_ALL, "one", "coefmul.x", + if (shader_is_pshader_version(ins->reg_maps->shader_version)) + { + IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *)ins->shader; + gen_color_correction(buffer, dst_str, ins->dst & WINED3DSP_WRITEMASK_ALL, "one", "coefmul.x", ps->cur_args->color_fixup[sampler_idx]); } } @@ -765,15 +768,14 @@ static inline void pshader_gen_output_modifier_line(SHADER_BUFFER *buffer, int s regstr, write_mask, regstr, shift_tab[shift]); } -static void pshader_hw_bem(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_bem(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; - - SHADER_BUFFER* buffer = arg->buffer; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; + SHADER_BUFFER *buffer = ins->buffer; char dst_name[50]; char src_name[2][50]; char dst_wmask[20]; - DWORD sampler_code = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_code = ins->dst & WINED3DSP_REGNUM_MASK; BOOL has_bumpmat = FALSE; int i; @@ -786,12 +788,12 @@ static void pshader_hw_bem(const SHADER_OPCODE_ARG *arg) } } - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); strcat(dst_name, dst_wmask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name[0]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[1], 1, src_name[1]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name[0]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[1], 1, src_name[1]); if(has_bumpmat) { /* Sampling the perturbation map in Tsrc was done already, including the signedness correction if needed */ @@ -806,28 +808,28 @@ static void pshader_hw_bem(const SHADER_OPCODE_ARG *arg) } } -static void pshader_hw_cnd(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_cnd(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_wmask[20]; char dst_name[50]; char src_name[3][50]; - BOOL sat = (arg->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; - DWORD shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; + BOOL sat = (ins->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; + DWORD shift = (ins->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; /* FIXME: support output modifiers */ /* Handle output register */ - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); /* Generate input register names (with modifiers) */ - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name[0]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[1], 1, src_name[1]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[2], 2, src_name[2]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name[0]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[1], 1, src_name[1]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[2], 2, src_name[2]); /* The coissue flag changes the semantic of the cnd instruction in <= 1.3 shaders */ - if (arg->reg_maps->shader_version <= WINED3DPS_VERSION(1, 3) && arg->coissue) + if (ins->reg_maps->shader_version <= WINED3DPS_VERSION(1, 3) && ins->coissue) { shader_addline(buffer, "MOV%s %s%s, %s;\n", sat ? "_SAT" : "", dst_name, dst_wmask, src_name[1]); } else { @@ -839,25 +841,25 @@ static void pshader_hw_cnd(const SHADER_OPCODE_ARG *arg) pshader_gen_output_modifier_line(buffer, FALSE, dst_wmask, shift, dst_name); } -static void pshader_hw_cmp(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_cmp(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_wmask[20]; char dst_name[50]; char src_name[3][50]; - DWORD shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; - BOOL sat = (arg->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; + DWORD shift = (ins->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; + BOOL sat = (ins->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; /* FIXME: support output modifiers */ /* Handle output register */ - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); /* Generate input register names (with modifiers) */ - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name[0]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[1], 1, src_name[1]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[2], 2, src_name[2]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name[0]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[1], 1, src_name[1]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[2], 2, src_name[2]); shader_addline(buffer, "CMP%s %s%s, %s, %s, %s;\n", sat ? "_SAT" : "", dst_name, dst_wmask, src_name[0], src_name[2], src_name[1]); @@ -868,21 +870,21 @@ static void pshader_hw_cmp(const SHADER_OPCODE_ARG *arg) /** Process the WINED3DSIO_DP2ADD instruction in ARB. * dst = dot2(src0, src1) + src2 */ -static void pshader_hw_dp2add(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_dp2add(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_wmask[20]; char dst_name[50]; char src_name[3][50]; - DWORD shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; - BOOL sat = (arg->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; + DWORD shift = (ins->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; + BOOL sat = (ins->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name[0]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[1], 1, src_name[1]); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[2], 2, src_name[2]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name[0]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[1], 1, src_name[1]); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[2], 2, src_name[2]); /* Emulate a DP2 with a DP3 and 0.0 */ shader_addline(buffer, "MOV TMP, %s;\n", src_name[0]); @@ -895,12 +897,12 @@ static void pshader_hw_dp2add(const SHADER_OPCODE_ARG *arg) } /* Map the opcode 1-to-1 to the GL code */ -static void shader_hw_map2gl(const SHADER_OPCODE_ARG *arg) +static void shader_hw_map2gl(const struct wined3d_shader_instruction *ins) { - CONST SHADER_OPCODE* curOpcode = arg->opcode; - SHADER_BUFFER* buffer = arg->buffer; - DWORD dst = arg->dst; - const DWORD *src = arg->src; + CONST SHADER_OPCODE *curOpcode = ins->opcode; + SHADER_BUFFER *buffer = ins->buffer; + DWORD dst = ins->dst; + const DWORD *src = ins->src; const char *instruction; char arguments[256]; unsigned int i; @@ -935,7 +937,7 @@ static void shader_hw_map2gl(const SHADER_OPCODE_ARG *arg) break; } - if (shader_is_pshader_version(arg->reg_maps->shader_version)) + if (shader_is_pshader_version(ins->reg_maps->shader_version)) { /* Output token related */ char output_rname[256]; @@ -973,12 +975,12 @@ static void shader_hw_map2gl(const SHADER_OPCODE_ARG *arg) /* Generate input register names (with modifiers) */ for (i = 1; i < curOpcode->num_params; ++i) - pshader_gen_input_modifier_line(arg->shader, buffer, src[i-1], i-1, operands[i]); + pshader_gen_input_modifier_line(ins->shader, buffer, src[i-1], i-1, operands[i]); /* Handle output register */ - pshader_get_register_name(arg->shader, dst, output_rname); + pshader_get_register_name(ins->shader, dst, output_rname); strcpy(operands[0], output_rname); - shader_arb_get_write_mask(arg, dst, output_wmask); + shader_arb_get_write_mask(ins, dst, output_wmask); strcat(operands[0], output_wmask); arguments[0] = '\0'; @@ -998,36 +1000,36 @@ static void shader_hw_map2gl(const SHADER_OPCODE_ARG *arg) arguments[0] = '\0'; if (curOpcode->num_params > 0) { - vshader_program_add_param(arg, dst, FALSE, arguments); + vshader_program_add_param(ins, dst, FALSE, arguments); for (i = 1; i < curOpcode->num_params; ++i) { strcat(arguments, ","); - vshader_program_add_param(arg, src[i-1], TRUE, arguments); + vshader_program_add_param(ins, src[i-1], TRUE, arguments); } } shader_addline(buffer, "%s%s;\n", instruction, arguments); } } -static void shader_hw_mov(const SHADER_OPCODE_ARG *arg) +static void shader_hw_mov(const struct wined3d_shader_instruction *ins) { - IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl*)arg->shader; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; - if ((WINED3DSHADER_VERSION_MAJOR(arg->reg_maps->shader_version) == 1 - && !shader_is_pshader_version(arg->reg_maps->shader_version) - && shader_get_regtype(arg->dst) == WINED3DSPR_ADDR) - || arg->opcode->opcode == WINED3DSIO_MOVA) + if ((WINED3DSHADER_VERSION_MAJOR(ins->reg_maps->shader_version) == 1 + && !shader_is_pshader_version(ins->reg_maps->shader_version) + && shader_get_regtype(ins->dst) == WINED3DSPR_ADDR) + || ins->opcode->opcode == WINED3DSIO_MOVA) { - SHADER_BUFFER *buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char src0_param[256]; - if (arg->opcode->opcode == WINED3DSIO_MOVA) + if (ins->opcode->opcode == WINED3DSIO_MOVA) FIXME("mova should round\n"); src0_param[0] = '\0'; if (((IWineD3DVertexShaderImpl *)shader)->rel_offset) { - vshader_program_add_param(arg, arg->src[0], TRUE, src0_param); + vshader_program_add_param(ins, ins->src[0], TRUE, src0_param); shader_addline(buffer, "ADD TMP.x, %s, helper_const.z;\n", src0_param); shader_addline(buffer, "ARL A0.x, TMP.x;\n"); } @@ -1037,35 +1039,35 @@ static void shader_hw_mov(const SHADER_OPCODE_ARG *arg) * with more than one component. Thus replicate the first source argument over all * 4 components. For example, .xyzw -> .x (or better: .xxxx), .zwxy -> .z, etc) */ - DWORD parm = arg->src[0] & ~(WINED3DVS_SWIZZLE_MASK); - if((arg->src[0] & WINED3DVS_X_W) == WINED3DVS_X_W) + DWORD parm = ins->src[0] & ~(WINED3DVS_SWIZZLE_MASK); + if((ins->src[0] & WINED3DVS_X_W) == WINED3DVS_X_W) parm |= WINED3DVS_X_W | WINED3DVS_Y_W | WINED3DVS_Z_W | WINED3DVS_W_W; - else if((arg->src[0] & WINED3DVS_X_Z) == WINED3DVS_X_Z) + else if((ins->src[0] & WINED3DVS_X_Z) == WINED3DVS_X_Z) parm |= WINED3DVS_X_Z | WINED3DVS_Y_Z | WINED3DVS_Z_Z | WINED3DVS_W_Z; - else if((arg->src[0] & WINED3DVS_X_Y) == WINED3DVS_X_Y) + else if((ins->src[0] & WINED3DVS_X_Y) == WINED3DVS_X_Y) parm |= WINED3DVS_X_Y | WINED3DVS_Y_Y | WINED3DVS_Z_Y | WINED3DVS_W_Y; - else if((arg->src[0] & WINED3DVS_X_X) == WINED3DVS_X_X) + else if((ins->src[0] & WINED3DVS_X_X) == WINED3DVS_X_X) parm |= WINED3DVS_X_X | WINED3DVS_Y_X | WINED3DVS_Z_X | WINED3DVS_W_X; - vshader_program_add_param(arg, parm, TRUE, src0_param); + vshader_program_add_param(ins, parm, TRUE, src0_param); shader_addline(buffer, "ARL A0.x, %s;\n", src0_param); } } else { - shader_hw_map2gl(arg); + shader_hw_map2gl(ins); } } -static void pshader_hw_texkill(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texkill(const struct wined3d_shader_instruction *ins) { - DWORD shader_version = arg->reg_maps->shader_version; - SHADER_BUFFER* buffer = arg->buffer; + DWORD shader_version = ins->reg_maps->shader_version; + SHADER_BUFFER *buffer = ins->buffer; char reg_dest[40]; /* No swizzles are allowed in d3d's texkill. PS 1.x ignores the 4th component as documented, * but >= 2.0 honors it(undocumented, but tested by the d3d9 testsuit) */ - pshader_get_register_name(arg->shader, arg->dst, reg_dest); + pshader_get_register_name(ins->shader, ins->dst, reg_dest); if (shader_version >= WINED3DPS_VERSION(2,0)) { @@ -1081,15 +1083,15 @@ static void pshader_hw_texkill(const SHADER_OPCODE_ARG *arg) } } -static void pshader_hw_tex(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_tex(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; - DWORD dst = arg->dst; - const DWORD *src = arg->src; - SHADER_BUFFER* buffer = arg->buffer; - DWORD shader_version = arg->reg_maps->shader_version; + DWORD dst = ins->dst; + const DWORD *src = ins->src; + SHADER_BUFFER* buffer = ins->buffer; + DWORD shader_version = ins->reg_maps->shader_version; BOOL projected = FALSE, bias = FALSE; char reg_dest[40]; @@ -1099,14 +1101,14 @@ static void pshader_hw_tex(const SHADER_OPCODE_ARG *arg) /* All versions have a destination register */ reg_dest_code = dst & WINED3DSP_REGNUM_MASK; - pshader_get_register_name(arg->shader, dst, reg_dest); + pshader_get_register_name(ins->shader, dst, reg_dest); /* 1.0-1.3: Use destination register as coordinate source. 1.4+: Use provided coordinate source register. */ if (shader_version < WINED3DPS_VERSION(1,4)) strcpy(reg_coord, reg_dest); else - pshader_gen_input_modifier_line(arg->shader, buffer, src[0], 0, reg_coord); + pshader_gen_input_modifier_line(ins->shader, buffer, src[0], 0, reg_coord); /* 1.0-1.4: Use destination register number as texture code. 2.0+: Use provided sampler number as texure code. */ @@ -1132,27 +1134,27 @@ static void pshader_hw_tex(const SHADER_OPCODE_ARG *arg) } else if (shader_version < WINED3DPS_VERSION(2,0)) { - DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK; + DWORD src_mod = ins->src[0] & WINED3DSP_SRCMOD_MASK; if (src_mod == WINED3DSPSM_DZ) { projected = TRUE; } else if(src_mod == WINED3DSPSM_DW) { projected = TRUE; } } else { - if (arg->flags & WINED3DSI_TEXLD_PROJECT) projected = TRUE; - if (arg->flags & WINED3DSI_TEXLD_BIAS) bias = TRUE; + if (ins->flags & WINED3DSI_TEXLD_PROJECT) projected = TRUE; + if (ins->flags & WINED3DSI_TEXLD_BIAS) bias = TRUE; } - shader_hw_sample(arg, reg_sampler_code, reg_dest, reg_coord, projected, bias); + shader_hw_sample(ins, reg_sampler_code, reg_dest, reg_coord, projected, bias); } -static void pshader_hw_texcoord(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texcoord(const struct wined3d_shader_instruction *ins) { - DWORD dst = arg->dst; - SHADER_BUFFER* buffer = arg->buffer; + DWORD dst = ins->dst; + SHADER_BUFFER *buffer = ins->buffer; char tmp[20]; - shader_arb_get_write_mask(arg, dst, tmp); - if (arg->reg_maps->shader_version != WINED3DPS_VERSION(1,4)) + shader_arb_get_write_mask(ins, dst, tmp); + if (ins->reg_maps->shader_version != WINED3DPS_VERSION(1,4)) { DWORD reg = dst & WINED3DSP_REGNUM_MASK; shader_addline(buffer, "MOV_SAT T%u%s, fragment.texcoord[%u];\n", reg, tmp, reg); @@ -1160,67 +1162,67 @@ static void pshader_hw_texcoord(const SHADER_OPCODE_ARG *arg) DWORD reg1 = dst & WINED3DSP_REGNUM_MASK; char reg_src[40]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, reg_src); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, reg_src); shader_addline(buffer, "MOV R%u%s, %s;\n", reg1, tmp, reg_src); } } -static void pshader_hw_texreg2ar(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texreg2ar(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + SHADER_BUFFER *buffer = ins->buffer; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; DWORD flags; - DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD reg1 = ins->dst & WINED3DSP_REGNUM_MASK; char dst_str[8]; char src_str[50]; sprintf(dst_str, "T%u", reg1); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_str); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_str); shader_addline(buffer, "MOV TMP.x, %s.w;\n", src_str); shader_addline(buffer, "MOV TMP.y, %s.x;\n", src_str); flags = reg1 < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg1][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0; - shader_hw_sample(arg, reg1, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg1, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); } -static void pshader_hw_texreg2gb(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texreg2gb(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; - DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD reg1 = ins->dst & WINED3DSP_REGNUM_MASK; char dst_str[8]; char src_str[50]; sprintf(dst_str, "T%u", reg1); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_str); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_str); shader_addline(buffer, "MOV TMP.x, %s.y;\n", src_str); shader_addline(buffer, "MOV TMP.y, %s.z;\n", src_str); - shader_hw_sample(arg, reg1, dst_str, "TMP", FALSE, FALSE); + shader_hw_sample(ins, reg1, dst_str, "TMP", FALSE, FALSE); } -static void pshader_hw_texreg2rgb(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texreg2rgb(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; - DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; + DWORD reg1 = ins->dst & WINED3DSP_REGNUM_MASK; char dst_str[8]; char src_str[50]; sprintf(dst_str, "T%u", reg1); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_str); - shader_hw_sample(arg, reg1, dst_str, src_str, FALSE, FALSE); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_str); + shader_hw_sample(ins, reg1, dst_str, src_str, FALSE, FALSE); } -static void pshader_hw_texbem(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texbem(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; BOOL has_bumpmat = FALSE; BOOL has_luminance = FALSE; int i; - DWORD dst = arg->dst; - DWORD src = arg->src[0] & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD dst = ins->dst; + DWORD src = ins->src[0] & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER* buffer = ins->buffer; char reg_coord[40]; DWORD reg_dest_code; @@ -1228,7 +1230,7 @@ static void pshader_hw_texbem(const SHADER_OPCODE_ARG *arg) /* All versions have a destination register */ reg_dest_code = dst & WINED3DSP_REGNUM_MASK; /* Can directly use the name because texbem is only valid for <= 1.3 shaders */ - pshader_get_register_name(arg->shader, dst, reg_coord); + pshader_get_register_name(ins->shader, dst, reg_coord); for(i = 0; i < This->numbumpenvmatconsts; i++) { if (This->bumpenvmatconst[i].const_num != WINED3D_CONST_NUM_UNUSED @@ -1267,9 +1269,10 @@ static void pshader_hw_texbem(const SHADER_OPCODE_ARG *arg) shader_addline(buffer, "ADD TMP.xy, TMP, %s;\n", reg_coord); } - shader_hw_sample(arg, reg_dest_code, reg_coord, "TMP", FALSE, FALSE); + shader_hw_sample(ins, reg_dest_code, reg_coord, "TMP", FALSE, FALSE); - if(arg->opcode->opcode == WINED3DSIO_TEXBEML && has_luminance) { + if (ins->opcode->opcode == WINED3DSIO_TEXBEML && has_luminance) + { shader_addline(buffer, "MAD TMP, T%u.z, luminance%d.x, luminance%d.y;\n", src, reg_dest_code, reg_dest_code); shader_addline(buffer, "MUL %s, %s, TMP;\n", reg_coord, reg_coord); @@ -1283,83 +1286,83 @@ static void pshader_hw_texbem(const SHADER_OPCODE_ARG *arg) tf = 0; } /* Without a bump matrix loaded, just sample with the unmodified coordinates */ - shader_hw_sample(arg, reg_dest_code, reg_coord, reg_coord, tf & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg_dest_code, reg_coord, reg_coord, tf & WINED3DTTFF_PROJECTED, FALSE); } } -static void pshader_hw_texm3x2pad(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x2pad(const struct wined3d_shader_instruction *ins) { - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; char src0_name[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.x, T%u, %s;\n", reg, src0_name); } -static void pshader_hw_texm3x2tex(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x2tex(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; DWORD flags; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; char dst_str[8]; char src0_name[50]; sprintf(dst_str, "T%u", reg); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.y, T%u, %s;\n", reg, src0_name); flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0; - shader_hw_sample(arg, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); } -static void pshader_hw_texm3x3pad(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x3pad(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; char src0_name[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.%c, T%u, %s;\n", 'x' + current_state->current_row, reg, src0_name); current_state->texcoord_w[current_state->current_row++] = reg; } -static void pshader_hw_texm3x3tex(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x3tex(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; DWORD flags; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; char dst_str[8]; char src0_name[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.z, T%u, %s;\n", reg, src0_name); /* Sample the texture using the calculated coordinates */ sprintf(dst_str, "T%u", reg); flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0; - shader_hw_sample(arg, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); current_state->current_row = 0; } -static void pshader_hw_texm3x3vspec(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x3vspec(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; DWORD flags; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; char dst_str[8]; char src0_name[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.z, T%u, %s;\n", reg, src0_name); /* Construct the eye-ray vector from w coordinates */ @@ -1380,23 +1383,23 @@ static void pshader_hw_texm3x3vspec(const SHADER_OPCODE_ARG *arg) /* Sample the texture using the calculated coordinates */ sprintf(dst_str, "T%u", reg); flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0; - shader_hw_sample(arg, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); current_state->current_row = 0; } -static void pshader_hw_texm3x3spec(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x3spec(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; DWORD flags; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - DWORD reg3 = arg->src[1] & WINED3DSP_REGNUM_MASK; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + DWORD reg3 = ins->src[1] & WINED3DSP_REGNUM_MASK; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_str[8]; char src0_name[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0_name); shader_addline(buffer, "DP3 TMP.z, T%u, %s;\n", reg, src0_name); /* Calculate reflection vector. @@ -1417,13 +1420,13 @@ static void pshader_hw_texm3x3spec(const SHADER_OPCODE_ARG *arg) /* Sample the texture using the calculated coordinates */ sprintf(dst_str, "T%u", reg); flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0; - shader_hw_sample(arg, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); + shader_hw_sample(ins, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE); current_state->current_row = 0; } -static void pshader_hw_texdepth(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texdepth(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_name[50]; /* texdepth has an implicit destination, the fragment depth value. It's only parameter, @@ -1431,7 +1434,7 @@ static void pshader_hw_texdepth(const SHADER_OPCODE_ARG *arg) * parameter. According to the msdn, this must be register r5, but let's keep it more flexible * here */ - pshader_get_register_name(arg->shader, arg->dst, dst_name); + pshader_get_register_name(ins->shader, ins->dst, dst_name); /* According to the msdn, the source register(must be r5) is unusable after * the texdepth instruction, so we're free to modify it @@ -1451,36 +1454,36 @@ static void pshader_hw_texdepth(const SHADER_OPCODE_ARG *arg) /** Process the WINED3DSIO_TEXDP3TEX instruction in ARB: * Take a 3-component dot product of the TexCoord[dstreg] and src, * then perform a 1D texture lookup from stage dstregnum, place into dst. */ -static void pshader_hw_texdp3tex(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texdp3tex(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; char src0[50]; char dst_str[8]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0); shader_addline(buffer, "MOV TMP, 0.0;\n"); shader_addline(buffer, "DP3 TMP.x, T%u, %s;\n", sampler_idx, src0); sprintf(dst_str, "T%u", sampler_idx); - shader_hw_sample(arg, sampler_idx, dst_str, "TMP", FALSE /* Only one coord, can't be projected */, FALSE); + shader_hw_sample(ins, sampler_idx, dst_str, "TMP", FALSE /* Only one coord, can't be projected */, FALSE); } /** Process the WINED3DSIO_TEXDP3 instruction in ARB: * Take a 3-component dot product of the TexCoord[dstreg] and src. */ -static void pshader_hw_texdp3(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texdp3(const struct wined3d_shader_instruction *ins) { char src0[50]; char dst_str[50]; char dst_mask[6]; - DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD dstreg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; /* Handle output register */ - pshader_get_register_name(arg->shader, arg->dst, dst_str); - shader_arb_get_write_mask(arg, arg->dst, dst_mask); + pshader_get_register_name(ins->shader, ins->dst, dst_str); + shader_arb_get_write_mask(ins, ins->dst, dst_mask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0); shader_addline(buffer, "DP3 %s%s, T%u, %s;\n", dst_str, dst_mask, dstreg, src0); /* TODO: Handle output modifiers */ @@ -1488,18 +1491,18 @@ static void pshader_hw_texdp3(const SHADER_OPCODE_ARG *arg) /** Process the WINED3DSIO_TEXM3X3 instruction in ARB * Perform the 3rd row of a 3x3 matrix multiply */ -static void pshader_hw_texm3x3(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x3(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_str[50]; char dst_mask[6]; char src0[50]; - DWORD dst_reg = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD dst_reg = ins->dst & WINED3DSP_REGNUM_MASK; - pshader_get_register_name(arg->shader, arg->dst, dst_str); - shader_arb_get_write_mask(arg, arg->dst, dst_mask); + pshader_get_register_name(ins->shader, ins->dst, dst_str); + shader_arb_get_write_mask(ins, ins->dst, dst_mask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0); shader_addline(buffer, "DP3 TMP.z, T%u, %s;\n", dst_reg, src0); shader_addline(buffer, "MOV %s%s, TMP;\n", dst_str, dst_mask); @@ -1511,13 +1514,13 @@ static void pshader_hw_texm3x3(const SHADER_OPCODE_ARG *arg) * Calculate tmp0.y = TexCoord[dstreg] . src.xyz; (tmp0.x has already been calculated) * depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y */ -static void pshader_hw_texm3x2depth(const SHADER_OPCODE_ARG *arg) +static void pshader_hw_texm3x2depth(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; - DWORD dst_reg = arg->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; + DWORD dst_reg = ins->dst & WINED3DSP_REGNUM_MASK; char src0[50]; - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src0); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src0); shader_addline(buffer, "DP3 TMP.y, T%u, %s;\n", dst_reg, src0); /* How to deal with the special case dst_name.g == 0? if r != 0, then @@ -1532,63 +1535,64 @@ static void pshader_hw_texm3x2depth(const SHADER_OPCODE_ARG *arg) /** Handles transforming all WINED3DSIO_M?x? opcodes for Vertex/Pixel shaders to ARB_vertex_program codes */ -static void shader_hw_mnxn(const SHADER_OPCODE_ARG *arg) +static void shader_hw_mnxn(const struct wined3d_shader_instruction *ins) { int i; int nComponents = 0; - SHADER_OPCODE_ARG tmpArg; - IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)arg->shader; + struct wined3d_shader_instruction tmp_ins; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; const SHADER_OPCODE *opcode_table = shader->baseShader.shader_ins; - DWORD shader_version = arg->reg_maps->shader_version; + DWORD shader_version = ins->reg_maps->shader_version; - memset(&tmpArg, 0, sizeof(SHADER_OPCODE_ARG)); + memset(&tmp_ins, 0, sizeof(tmp_ins)); /* Set constants for the temporary argument */ - tmpArg.shader = arg->shader; - tmpArg.buffer = arg->buffer; - tmpArg.src[0] = arg->src[0]; - tmpArg.src_addr[0] = arg->src_addr[0]; - tmpArg.src_addr[1] = arg->src_addr[1]; - tmpArg.reg_maps = arg->reg_maps; + tmp_ins.shader = ins->shader; + tmp_ins.buffer = ins->buffer; + tmp_ins.src[0] = ins->src[0]; + tmp_ins.src_addr[0] = ins->src_addr[0]; + tmp_ins.src_addr[1] = ins->src_addr[1]; + tmp_ins.reg_maps = ins->reg_maps; - switch(arg->opcode->opcode) { + switch(ins->opcode->opcode) + { case WINED3DSIO_M4x4: nComponents = 4; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); break; case WINED3DSIO_M4x3: nComponents = 3; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); break; case WINED3DSIO_M3x4: nComponents = 4; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; case WINED3DSIO_M3x3: nComponents = 3; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; case WINED3DSIO_M3x2: nComponents = 2; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; default: break; } for (i = 0; i < nComponents; i++) { - tmpArg.dst = ((arg->dst) & ~WINED3DSP_WRITEMASK_ALL)|(WINED3DSP_WRITEMASK_0<src[1]+i; - shader_hw_map2gl(&tmpArg); + tmp_ins.dst = ((ins->dst) & ~WINED3DSP_WRITEMASK_ALL)|(WINED3DSP_WRITEMASK_0<src[1]+i; + shader_hw_map2gl(&tmp_ins); } } -static void vshader_hw_rsq_rcp(const SHADER_OPCODE_ARG *arg) +static void vshader_hw_rsq_rcp(const struct wined3d_shader_instruction *ins) { - CONST SHADER_OPCODE* curOpcode = arg->opcode; - SHADER_BUFFER* buffer = arg->buffer; - DWORD dst = arg->dst; - DWORD src = arg->src[0]; + CONST SHADER_OPCODE *curOpcode = ins->opcode; + SHADER_BUFFER *buffer = ins->buffer; + DWORD dst = ins->dst; + DWORD src = ins->src[0]; DWORD swizzle = (src & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT; const char *instruction; @@ -1604,9 +1608,9 @@ static void vshader_hw_rsq_rcp(const SHADER_OPCODE_ARG *arg) } strcpy(tmpLine, instruction); - vshader_program_add_param(arg, dst, FALSE, tmpLine); /* Destination */ + vshader_program_add_param(ins, dst, FALSE, tmpLine); /* Destination */ strcat(tmpLine, ","); - vshader_program_add_param(arg, src, TRUE, tmpLine); + vshader_program_add_param(ins, src, TRUE, tmpLine); if ((WINED3DSP_NOSWIZZLE >> WINED3DSP_SWIZZLE_SHIFT) == swizzle) { /* Dx sdk says .x is used if no swizzle is given, but our test shows that * .w is used @@ -1617,19 +1621,19 @@ static void vshader_hw_rsq_rcp(const SHADER_OPCODE_ARG *arg) shader_addline(buffer, "%s;\n", tmpLine); } -static void shader_hw_nrm(const SHADER_OPCODE_ARG *arg) +static void shader_hw_nrm(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_name[50]; char src_name[50]; char dst_wmask[20]; - DWORD shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; - BOOL sat = (arg->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; + DWORD shift = (ins->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; + BOOL sat = (ins->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name); shader_addline(buffer, "DP3 TMP, %s, %s;\n", src_name, src_name); shader_addline(buffer, "RSQ TMP, TMP.x;\n"); /* dst.w = src[0].w * 1 / (src.x^2 + src.y^2 + src.z^2)^(1/2) according to msdn*/ @@ -1640,23 +1644,23 @@ static void shader_hw_nrm(const SHADER_OPCODE_ARG *arg) pshader_gen_output_modifier_line(buffer, FALSE, dst_wmask, shift, dst_name); } -static void shader_hw_sincos(const SHADER_OPCODE_ARG *arg) +static void shader_hw_sincos(const struct wined3d_shader_instruction *ins) { /* This instruction exists in ARB, but the d3d instruction takes two extra parameters which * must contain fixed constants. So we need a separate function to filter those constants and * can't use map2gl */ - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; char dst_name[50]; char src_name[50]; char dst_wmask[20]; - DWORD shift = (arg->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; - BOOL sat = (arg->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; + DWORD shift = (ins->dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; + BOOL sat = (ins->dst & WINED3DSP_DSTMOD_MASK) & WINED3DSPDM_SATURATE; - pshader_get_register_name(arg->shader, arg->dst, dst_name); - shader_arb_get_write_mask(arg, arg->dst, dst_wmask); + pshader_get_register_name(ins->shader, ins->dst, dst_name); + shader_arb_get_write_mask(ins, ins->dst, dst_wmask); - pshader_gen_input_modifier_line(arg->shader, buffer, arg->src[0], 0, src_name); + pshader_gen_input_modifier_line(ins->shader, buffer, ins->src[0], 0, src_name); shader_addline(buffer, "SCS%s %s%s, %s;\n", sat ? "_SAT" : "", dst_name, dst_wmask, src_name); diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c index 65b2709bcc2..f28128a9008 100644 --- a/dlls/wined3d/baseshader.c +++ b/dlls/wined3d/baseshader.c @@ -771,16 +771,16 @@ void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer, const SHADER_OPCODE *opcode_table = This->baseShader.shader_ins; const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table; DWORD shader_version = reg_maps->shader_version; + struct wined3d_shader_instruction ins; const DWORD *pToken = pFunction; const SHADER_OPCODE *curOpcode; SHADER_HANDLER hw_fct; DWORD i; - SHADER_OPCODE_ARG hw_arg; /* Initialize current parsing state */ - hw_arg.shader = iface; - hw_arg.buffer = buffer; - hw_arg.reg_maps = reg_maps; + ins.shader = iface; + ins.buffer = buffer; + ins.reg_maps = reg_maps; This->baseShader.parse_state.current_row = 0; while (WINED3DPS_END() != *pToken) @@ -838,39 +838,39 @@ void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER* buffer, continue; } - hw_arg.opcode = curOpcode; + ins.opcode = curOpcode; - hw_arg.flags = opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK; - hw_arg.coissue = opcode_token & WINED3DSI_COISSUE; + ins.flags = opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK; + ins.coissue = opcode_token & WINED3DSI_COISSUE; /* Destination token */ if (curOpcode->dst_token) { DWORD param, addr_token = 0; pToken += shader_get_param(pToken, shader_version, ¶m, &addr_token); - hw_arg.dst = param; - hw_arg.dst_addr = addr_token; + ins.dst = param; + ins.dst_addr = addr_token; } /* Predication token */ - if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) hw_arg.predicate = *pToken++; + if (opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED) ins.predicate = *pToken++; /* Other source tokens */ for (i = 0; i < (curOpcode->num_params - curOpcode->dst_token); ++i) { DWORD param, addr_token = 0; pToken += shader_get_param(pToken, shader_version, ¶m, &addr_token); - hw_arg.src[i] = param; - hw_arg.src_addr[i] = addr_token; + ins.src[i] = param; + ins.src_addr[i] = addr_token; } /* Call appropriate function for output target */ - hw_fct(&hw_arg); + hw_fct(&ins); /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */ /* FIXME: This should be internal to the shader backend. * Also, right now this is the only reason "shader_mode" exists. */ - if (This->baseShader.shader_mode == SHADER_GLSL) shader_glsl_add_instruction_modifiers(&hw_arg); + if (This->baseShader.shader_mode == SHADER_GLSL) shader_glsl_add_instruction_modifiers(&ins); } } diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 9cdab018d0a..ae9aa7fde4e 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -910,7 +910,7 @@ static void shader_generate_glsl_declarations(IWineD3DBaseShader *iface, const s ****************************************************************************/ /* Prototypes */ -static void shader_glsl_add_src_param(const SHADER_OPCODE_ARG *arg, const DWORD param, +static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins, const DWORD param, const DWORD addr_token, DWORD mask, glsl_src_param_t *src_param); /** Used for opcode modifiers - They multiply the result by the specified amount */ @@ -993,14 +993,14 @@ static void shader_glsl_gen_modifier ( /** Writes the GLSL variable name that corresponds to the register that the * DX opcode parameter is trying to access */ static void shader_glsl_get_register_name(const DWORD param, const DWORD addr_token, - char *regstr, BOOL *is_color, const SHADER_OPCODE_ARG *arg) + char *regstr, BOOL *is_color, const struct wined3d_shader_instruction *ins) { /* oPos, oFog and oPts in D3D */ static const char * const hwrastout_reg_names[] = { "gl_Position", "gl_FogFragCoord", "gl_PointSize" }; DWORD reg = param & WINED3DSP_REGNUM_MASK; DWORD regtype = shader_get_regtype(param); - IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) arg->shader; + IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; const WineD3D_GL_Info* gl_info = &deviceImpl->adapter->gl_info; DWORD shader_version = This->baseShader.reg_maps.shader_version; @@ -1022,7 +1022,7 @@ static void shader_glsl_get_register_name(const DWORD param, const DWORD addr_to if (param & WINED3DSHADER_ADDRMODE_RELATIVE) { glsl_src_param_t rel_param; - shader_glsl_add_src_param(arg, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param); + shader_glsl_add_src_param(ins, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param); /* Removing a + 0 would be an obvious optimization, but macos doesn't see the NOP * operation there @@ -1079,7 +1079,7 @@ static void shader_glsl_get_register_name(const DWORD param, const DWORD addr_to if (WINED3DSHADER_VERSION_MAJOR(shader_version) >= 2) { glsl_src_param_t rel_param; - shader_glsl_add_src_param(arg, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param); + shader_glsl_add_src_param(ins, addr_token, 0, WINED3DSP_WRITEMASK_0, &rel_param); if(reg) { sprintf(tmpStr, "%cC[%s + %u]", prefix, rel_param.param_str, reg); } else { @@ -1236,8 +1236,8 @@ static void shader_glsl_get_swizzle(const DWORD param, BOOL fixup, DWORD mask, c /* From a given parameter token, generate the corresponding GLSL string. * Also, return the actual register name and swizzle in case the * caller needs this information as well. */ -static void shader_glsl_add_src_param(const SHADER_OPCODE_ARG *arg, const DWORD param, - const DWORD addr_token, DWORD mask, glsl_src_param_t *src_param) +static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins, + const DWORD param, const DWORD addr_token, DWORD mask, glsl_src_param_t *src_param) { BOOL is_color = FALSE; char swizzle_str[6]; @@ -1246,7 +1246,7 @@ static void shader_glsl_add_src_param(const SHADER_OPCODE_ARG *arg, const DWORD src_param->param_str[0] = '\0'; swizzle_str[0] = '\0'; - shader_glsl_get_register_name(param, addr_token, src_param->reg_name, &is_color, arg); + shader_glsl_get_register_name(param, addr_token, src_param->reg_name, &is_color, ins); shader_glsl_get_swizzle(param, is_color, mask, swizzle_str); shader_glsl_gen_modifier(param, src_param->reg_name, swizzle_str, src_param->param_str); @@ -1255,26 +1255,27 @@ static void shader_glsl_add_src_param(const SHADER_OPCODE_ARG *arg, const DWORD /* From a given parameter token, generate the corresponding GLSL string. * Also, return the actual register name and swizzle in case the * caller needs this information as well. */ -static DWORD shader_glsl_add_dst_param(const SHADER_OPCODE_ARG* arg, const DWORD param, - const DWORD addr_token, glsl_dst_param_t *dst_param) +static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction *ins, + const DWORD param, const DWORD addr_token, glsl_dst_param_t *dst_param) { BOOL is_color = FALSE; dst_param->mask_str[0] = '\0'; dst_param->reg_name[0] = '\0'; - shader_glsl_get_register_name(param, addr_token, dst_param->reg_name, &is_color, arg); + shader_glsl_get_register_name(param, addr_token, dst_param->reg_name, &is_color, ins); return shader_glsl_get_write_mask(param, dst_param->mask_str); } /* Append the destination part of the instruction to the buffer, return the effective write mask */ -static DWORD shader_glsl_append_dst_ext(SHADER_BUFFER *buffer, const SHADER_OPCODE_ARG *arg, const DWORD param) +static DWORD shader_glsl_append_dst_ext(SHADER_BUFFER *buffer, + const struct wined3d_shader_instruction *ins, const DWORD param) { glsl_dst_param_t dst_param; DWORD mask; int shift; - mask = shader_glsl_add_dst_param(arg, param, arg->dst_addr, &dst_param); + mask = shader_glsl_add_dst_param(ins, param, ins->dst_addr, &dst_param); if(mask) { shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT; @@ -1285,24 +1286,25 @@ static DWORD shader_glsl_append_dst_ext(SHADER_BUFFER *buffer, const SHADER_OPCO } /* Append the destination part of the instruction to the buffer, return the effective write mask */ -static DWORD shader_glsl_append_dst(SHADER_BUFFER *buffer, const SHADER_OPCODE_ARG *arg) +static DWORD shader_glsl_append_dst(SHADER_BUFFER *buffer, const struct wined3d_shader_instruction *ins) { - return shader_glsl_append_dst_ext(buffer, arg, arg->dst); + return shader_glsl_append_dst_ext(buffer, ins, ins->dst); } /** Process GLSL instruction modifiers */ -void shader_glsl_add_instruction_modifiers(const SHADER_OPCODE_ARG* arg) +void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins) { - DWORD mask = arg->dst & WINED3DSP_DSTMOD_MASK; - - if (arg->opcode->dst_token && mask != 0) { + DWORD mask = ins->dst & WINED3DSP_DSTMOD_MASK; + + if (ins->opcode->dst_token && mask) + { glsl_dst_param_t dst_param; - shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param); + shader_glsl_add_dst_param(ins, ins->dst, 0, &dst_param); if (mask & WINED3DSPDM_SATURATE) { /* _SAT means to clamp the value of the register to between 0 and 1 */ - shader_addline(arg->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name, + shader_addline(ins->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name, dst_param.mask_str, dst_param.reg_name, dst_param.mask_str); } if (mask & WINED3DSPDM_MSAMPCENTROID) { @@ -1428,7 +1430,7 @@ static void shader_glsl_append_fixup_arg(char *arguments, const char *reg_name, if (sign_fixup) strcat(arguments, " * 2.0 - 1.0"); } -static void shader_glsl_color_correction(const struct SHADER_OPCODE_ARG *arg, struct color_fixup_desc fixup) +static void shader_glsl_color_correction(const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup) { unsigned int mask_size, remaining; glsl_dst_param_t dst_param; @@ -1441,7 +1443,7 @@ static void shader_glsl_color_correction(const struct SHADER_OPCODE_ARG *arg, st if (fixup.y_sign_fixup || fixup.y_source != CHANNEL_SOURCE_Y) mask |= WINED3DSP_WRITEMASK_1; if (fixup.z_sign_fixup || fixup.z_source != CHANNEL_SOURCE_Z) mask |= WINED3DSP_WRITEMASK_2; if (fixup.w_sign_fixup || fixup.w_source != CHANNEL_SOURCE_W) mask |= WINED3DSP_WRITEMASK_3; - mask &= arg->dst; + mask &= ins->dst; if (!mask) return; /* Nothing to do */ @@ -1458,7 +1460,7 @@ static void shader_glsl_color_correction(const struct SHADER_OPCODE_ARG *arg, st shader_glsl_get_write_mask(mask, dst_param.mask_str); dst_param.reg_name[0] = '\0'; - shader_glsl_get_register_name(arg->dst, arg->dst_addr, dst_param.reg_name, &dummy, arg); + shader_glsl_get_register_name(ins->dst, ins->dst_addr, dst_param.reg_name, &dummy, ins); arguments[0] = '\0'; remaining = mask_size; @@ -1485,16 +1487,16 @@ static void shader_glsl_color_correction(const struct SHADER_OPCODE_ARG *arg, st if (mask_size > 1) { - shader_addline(arg->buffer, "%s%s = vec%u(%s);\n", + shader_addline(ins->buffer, "%s%s = vec%u(%s);\n", dst_param.reg_name, dst_param.mask_str, mask_size, arguments); } else { - shader_addline(arg->buffer, "%s%s = %s;\n", dst_param.reg_name, dst_param.mask_str, arguments); + shader_addline(ins->buffer, "%s%s = %s;\n", dst_param.reg_name, dst_param.mask_str, arguments); } } -static void PRINTF_ATTR(6, 7) shader_glsl_gen_sample_code(const SHADER_OPCODE_ARG *arg, +static void PRINTF_ATTR(6, 7) shader_glsl_gen_sample_code(const struct wined3d_shader_instruction *ins, DWORD sampler, const glsl_sample_function_t *sample_function, DWORD swizzle, const char *bias, const char *coord_reg_fmt, ...) { @@ -1504,10 +1506,11 @@ static void PRINTF_ATTR(6, 7) shader_glsl_gen_sample_code(const SHADER_OPCODE_AR BOOL rect_fixup = FALSE; va_list args; - shader_glsl_get_swizzle(swizzle, FALSE, arg->dst, dst_swizzle); + shader_glsl_get_swizzle(swizzle, FALSE, ins->dst, dst_swizzle); - if(shader_is_pshader_version(arg->reg_maps->shader_version)) { - IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *) arg->shader; + if (shader_is_pshader_version(ins->reg_maps->shader_version)) + { + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; fixup = This->cur_args->color_fixup[sampler]; sampler_base = "Psampler"; @@ -1523,26 +1526,26 @@ static void PRINTF_ATTR(6, 7) shader_glsl_gen_sample_code(const SHADER_OPCODE_AR fixup = COLOR_FIXUP_IDENTITY; /* FIXME: Vshader color fixup */ } - shader_glsl_append_dst(arg->buffer, arg); + shader_glsl_append_dst(ins->buffer, ins); - shader_addline(arg->buffer, "%s(%s%u, ", sample_function->name, sampler_base, sampler); + shader_addline(ins->buffer, "%s(%s%u, ", sample_function->name, sampler_base, sampler); va_start(args, coord_reg_fmt); - shader_vaddline(arg->buffer, coord_reg_fmt, args); + shader_vaddline(ins->buffer, coord_reg_fmt, args); va_end(args); if(bias) { - shader_addline(arg->buffer, ", %s)%s);\n", bias, dst_swizzle); + shader_addline(ins->buffer, ", %s)%s);\n", bias, dst_swizzle); } else { if (rect_fixup) { - shader_addline(arg->buffer, " * PsamplerRectFixup%u)%s);\n", sampler, dst_swizzle); + shader_addline(ins->buffer, " * PsamplerRectFixup%u)%s);\n", sampler, dst_swizzle); } else { - shader_addline(arg->buffer, ")%s);\n", dst_swizzle); + shader_addline(ins->buffer, ")%s);\n", dst_swizzle); } } if(!is_identity_fixup(fixup)) { - shader_glsl_color_correction(arg, fixup); + shader_glsl_color_correction(ins, fixup); } } @@ -1553,10 +1556,10 @@ static void PRINTF_ATTR(6, 7) shader_glsl_gen_sample_code(const SHADER_OPCODE_AR ****************************************************************************/ /* Generate GLSL arithmetic functions (dst = src1 + src2) */ -static void shader_glsl_arith(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_arith(const struct wined3d_shader_instruction *ins) { - CONST SHADER_OPCODE* curOpcode = arg->opcode; - SHADER_BUFFER* buffer = arg->buffer; + CONST SHADER_OPCODE* curOpcode = ins->opcode; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; glsl_src_param_t src1_param; DWORD write_mask; @@ -1573,27 +1576,27 @@ static void shader_glsl_arith(const SHADER_OPCODE_ARG *arg) break; } - write_mask = shader_glsl_append_dst(buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); + write_mask = shader_glsl_append_dst(buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); shader_addline(buffer, "%s %c %s);\n", src0_param.param_str, op, src1_param.param_str); } /* Process the WINED3DSIO_MOV opcode using GLSL (dst = src) */ -static void shader_glsl_mov(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_mov(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; DWORD write_mask; - write_mask = shader_glsl_append_dst(buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param); + write_mask = shader_glsl_append_dst(buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src0_param); /* In vs_1_1 WINED3DSIO_MOV can write to the address register. In later * shader versions WINED3DSIO_MOVA is used for this. */ - if ((WINED3DSHADER_VERSION_MAJOR(arg->reg_maps->shader_version) == 1 - && !shader_is_pshader_version(arg->reg_maps->shader_version) - && shader_get_regtype(arg->dst) == WINED3DSPR_ADDR)) + if ((WINED3DSHADER_VERSION_MAJOR(ins->reg_maps->shader_version) == 1 + && !shader_is_pshader_version(ins->reg_maps->shader_version) + && shader_get_regtype(ins->dst) == WINED3DSPR_ADDR)) { /* This is a simple floor() */ unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); @@ -1602,7 +1605,9 @@ static void shader_glsl_mov(const SHADER_OPCODE_ARG *arg) } else { shader_addline(buffer, "int(floor(%s)));\n", src0_param.param_str); } - } else if(arg->opcode->opcode == WINED3DSIO_MOVA) { + } + else if(ins->opcode->opcode == WINED3DSIO_MOVA) + { /* We need to *round* to the nearest int here. */ unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); if (mask_size > 1) { @@ -1616,16 +1621,16 @@ static void shader_glsl_mov(const SHADER_OPCODE_ARG *arg) } /* Process the dot product operators DP3 and DP4 in GLSL (dst = dot(src0, src1)) */ -static void shader_glsl_dot(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_dot(const struct wined3d_shader_instruction *ins) { - CONST SHADER_OPCODE* curOpcode = arg->opcode; - SHADER_BUFFER* buffer = arg->buffer; + CONST SHADER_OPCODE *curOpcode = ins->opcode; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; glsl_src_param_t src1_param; DWORD dst_write_mask, src_write_mask; unsigned int dst_size = 0; - dst_write_mask = shader_glsl_append_dst(buffer, arg); + dst_write_mask = shader_glsl_append_dst(buffer, ins); dst_size = shader_glsl_get_write_mask_size(dst_write_mask); /* dp3 works on vec3, dp4 on vec4 */ @@ -1635,8 +1640,8 @@ static void shader_glsl_dot(const SHADER_OPCODE_ARG *arg) src_write_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; } - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_write_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_write_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], src_write_mask, &src1_param); if (dst_size > 1) { shader_addline(buffer, "vec%d(dot(%s, %s)));\n", dst_size, src0_param.param_str, src1_param.param_str); @@ -1647,36 +1652,36 @@ static void shader_glsl_dot(const SHADER_OPCODE_ARG *arg) /* Note that this instruction has some restrictions. The destination write mask * can't contain the w component, and the source swizzles have to be .xyzw */ -static void shader_glsl_cross(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_cross(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; glsl_src_param_t src0_param; glsl_src_param_t src1_param; char dst_mask[6]; - shader_glsl_get_write_mask(arg->dst, dst_mask); - shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_mask, &src1_param); - shader_addline(arg->buffer, "cross(%s, %s)%s);\n", src0_param.param_str, src1_param.param_str, dst_mask); + shader_glsl_get_write_mask(ins->dst, dst_mask); + shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], src_mask, &src1_param); + shader_addline(ins->buffer, "cross(%s, %s)%s);\n", src0_param.param_str, src1_param.param_str, dst_mask); } /* Process the WINED3DSIO_POW instruction in GLSL (dst = |src0|^src1) * Src0 and src1 are scalars. Note that D3D uses the absolute of src0, while * GLSL uses the value as-is. */ -static void shader_glsl_pow(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_pow(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER *buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; glsl_src_param_t src1_param; DWORD dst_write_mask; unsigned int dst_size; - dst_write_mask = shader_glsl_append_dst(buffer, arg); + dst_write_mask = shader_glsl_append_dst(buffer, ins); dst_size = shader_glsl_get_write_mask_size(dst_write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); if (dst_size > 1) { shader_addline(buffer, "vec%d(pow(abs(%s), %s)));\n", dst_size, src0_param.param_str, src1_param.param_str); @@ -1688,17 +1693,17 @@ static void shader_glsl_pow(const SHADER_OPCODE_ARG *arg) /* Process the WINED3DSIO_LOG instruction in GLSL (dst = log2(|src0|)) * Src0 is a scalar. Note that D3D uses the absolute of src0, while * GLSL uses the value as-is. */ -static void shader_glsl_log(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_log(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER *buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; DWORD dst_write_mask; unsigned int dst_size; - dst_write_mask = shader_glsl_append_dst(buffer, arg); + dst_write_mask = shader_glsl_append_dst(buffer, ins); dst_size = shader_glsl_get_write_mask_size(dst_write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); if (dst_size > 1) { shader_addline(buffer, "vec%d(log2(abs(%s))));\n", dst_size, src0_param.param_str); @@ -1708,10 +1713,10 @@ static void shader_glsl_log(const SHADER_OPCODE_ARG *arg) } /* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */ -static void shader_glsl_map2gl(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_map2gl(const struct wined3d_shader_instruction *ins) { - CONST SHADER_OPCODE* curOpcode = arg->opcode; - SHADER_BUFFER* buffer = arg->buffer; + CONST SHADER_OPCODE *curOpcode = ins->opcode; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src_param; const char *instruction; DWORD write_mask; @@ -1734,15 +1739,15 @@ static void shader_glsl_map2gl(const SHADER_OPCODE_ARG *arg) break; } - write_mask = shader_glsl_append_dst(buffer, arg); + write_mask = shader_glsl_append_dst(buffer, ins); shader_addline(buffer, "%s(", instruction); if (curOpcode->num_params > 0) { - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src_param); shader_addline(buffer, "%s", src_param.param_str); for (i = 2; i < curOpcode->num_params; ++i) { - shader_glsl_add_src_param(arg, arg->src[i-1], arg->src_addr[i-1], write_mask, &src_param); + shader_glsl_add_src_param(ins, ins->src[i-1], ins->src_addr[i-1], write_mask, &src_param); shader_addline(buffer, ", %s", src_param.param_str); } } @@ -1759,68 +1764,68 @@ static void shader_glsl_map2gl(const SHADER_OPCODE_ARG *arg) * For 2.0 shaders, just do this (honoring writemask and swizzle): * dst = 2^src; (partial precision is allowed, but optional) */ -static void shader_glsl_expp(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_expp(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src_param); - if (arg->reg_maps->shader_version < WINED3DPS_VERSION(2,0)) + if (ins->reg_maps->shader_version < WINED3DPS_VERSION(2,0)) { char dst_mask[6]; - shader_addline(arg->buffer, "tmp0.x = exp2(floor(%s));\n", src_param.param_str); - shader_addline(arg->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str); - shader_addline(arg->buffer, "tmp0.z = exp2(%s);\n", src_param.param_str); - shader_addline(arg->buffer, "tmp0.w = 1.0;\n"); + shader_addline(ins->buffer, "tmp0.x = exp2(floor(%s));\n", src_param.param_str); + shader_addline(ins->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str); + shader_addline(ins->buffer, "tmp0.z = exp2(%s);\n", src_param.param_str); + shader_addline(ins->buffer, "tmp0.w = 1.0;\n"); - shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_get_write_mask(arg->dst, dst_mask); - shader_addline(arg->buffer, "tmp0%s);\n", dst_mask); + shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_get_write_mask(ins->dst, dst_mask); + shader_addline(ins->buffer, "tmp0%s);\n", dst_mask); } else { DWORD write_mask; unsigned int mask_size; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); mask_size = shader_glsl_get_write_mask_size(write_mask); if (mask_size > 1) { - shader_addline(arg->buffer, "vec%d(exp2(%s)));\n", mask_size, src_param.param_str); + shader_addline(ins->buffer, "vec%d(exp2(%s)));\n", mask_size, src_param.param_str); } else { - shader_addline(arg->buffer, "exp2(%s));\n", src_param.param_str); + shader_addline(ins->buffer, "exp2(%s));\n", src_param.param_str); } } } /** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */ -static void shader_glsl_rcp(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_rcp(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src_param; DWORD write_mask; unsigned int mask_size; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &src_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &src_param); if (mask_size > 1) { - shader_addline(arg->buffer, "vec%d(1.0 / %s));\n", mask_size, src_param.param_str); + shader_addline(ins->buffer, "vec%d(1.0 / %s));\n", mask_size, src_param.param_str); } else { - shader_addline(arg->buffer, "1.0 / %s);\n", src_param.param_str); + shader_addline(ins->buffer, "1.0 / %s);\n", src_param.param_str); } } -static void shader_glsl_rsq(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_rsq(const struct wined3d_shader_instruction *ins) { - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src_param; DWORD write_mask; unsigned int mask_size; - write_mask = shader_glsl_append_dst(buffer, arg); + write_mask = shader_glsl_append_dst(buffer, ins); mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &src_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &src_param); if (mask_size > 1) { shader_addline(buffer, "vec%d(inversesqrt(%s)));\n", mask_size, src_param.param_str); @@ -1830,32 +1835,34 @@ static void shader_glsl_rsq(const SHADER_OPCODE_ARG *arg) } /** Process signed comparison opcodes in GLSL. */ -static void shader_glsl_compare(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_compare(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; DWORD write_mask; unsigned int mask_size; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); if (mask_size > 1) { const char *compare; - switch(arg->opcode->opcode) { + switch(ins->opcode->opcode) + { case WINED3DSIO_SLT: compare = "lessThan"; break; case WINED3DSIO_SGE: compare = "greaterThanEqual"; break; default: compare = ""; - FIXME("Can't handle opcode %s\n", arg->opcode->name); + FIXME("Can't handle opcode %s\n", ins->opcode->name); } - shader_addline(arg->buffer, "vec%d(%s(%s, %s)));\n", mask_size, compare, + shader_addline(ins->buffer, "vec%d(%s(%s, %s)));\n", mask_size, compare, src0_param.param_str, src1_param.param_str); } else { - switch(arg->opcode->opcode) { + switch(ins->opcode->opcode) + { case WINED3DSIO_SLT: /* Step(src0, src1) is not suitable here because if src0 == src1 SLT is supposed, * to return 0.0 but step returns 1.0 because step is not < x @@ -1864,21 +1871,21 @@ static void shader_glsl_compare(const SHADER_OPCODE_ARG *arg) * issue. Playing with not() is not possible either because not() does not accept * a scalar. */ - shader_addline(arg->buffer, "(%s < %s) ? 1.0 : 0.0);\n", src0_param.param_str, src1_param.param_str); + shader_addline(ins->buffer, "(%s < %s) ? 1.0 : 0.0);\n", src0_param.param_str, src1_param.param_str); break; case WINED3DSIO_SGE: /* Here we can use the step() function and safe a conditional */ - shader_addline(arg->buffer, "step(%s, %s));\n", src1_param.param_str, src0_param.param_str); + shader_addline(ins->buffer, "step(%s, %s));\n", src1_param.param_str, src0_param.param_str); break; default: - FIXME("Can't handle opcode %s\n", arg->opcode->name); + FIXME("Can't handle opcode %s\n", ins->opcode->name); } } } /** Process CMP instruction in GLSL (dst = src0 >= 0.0 ? src1 : src2), per channel */ -static void shader_glsl_cmp(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_cmp(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; @@ -1888,31 +1895,33 @@ static void shader_glsl_cmp(const SHADER_OPCODE_ARG *arg) char mask_char[6]; BOOL temp_destination = FALSE; - if(shader_is_scalar(arg->src[0])) { - write_mask = shader_glsl_append_dst(arg->buffer, arg); + if (shader_is_scalar(ins->src[0])) + { + write_mask = shader_glsl_append_dst(ins->buffer, ins); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); - shader_addline(arg->buffer, "%s >= 0.0 ? %s : %s);\n", + shader_addline(ins->buffer, "%s >= 0.0 ? %s : %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); } else { - DWORD src0reg = arg->src[0] & WINED3DSP_REGNUM_MASK; - DWORD src1reg = arg->src[1] & WINED3DSP_REGNUM_MASK; - DWORD src2reg = arg->src[2] & WINED3DSP_REGNUM_MASK; - DWORD src0regtype = shader_get_regtype(arg->src[0]); - DWORD src1regtype = shader_get_regtype(arg->src[1]); - DWORD src2regtype = shader_get_regtype(arg->src[2]); - DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK; - DWORD dstregtype = shader_get_regtype(arg->dst); + DWORD src0reg = ins->src[0] & WINED3DSP_REGNUM_MASK; + DWORD src1reg = ins->src[1] & WINED3DSP_REGNUM_MASK; + DWORD src2reg = ins->src[2] & WINED3DSP_REGNUM_MASK; + DWORD src0regtype = shader_get_regtype(ins->src[0]); + DWORD src1regtype = shader_get_regtype(ins->src[1]); + DWORD src2regtype = shader_get_regtype(ins->src[2]); + DWORD dstreg = ins->dst & WINED3DSP_REGNUM_MASK; + DWORD dstregtype = shader_get_regtype(ins->dst); /* Cycle through all source0 channels */ for (i=0; i<4; i++) { write_mask = 0; /* Find the destination channels which use the current source0 channel */ for (j=0; j<4; j++) { - if ( ((arg->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2*j)) & 0x3) == i ) { + if (((ins->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2 * j)) & 0x3) == i) + { write_mask |= WINED3DSP_WRITEMASK_0 << j; cmp_channel = WINED3DSP_WRITEMASK_0 << j; } @@ -1926,27 +1935,28 @@ static void shader_glsl_cmp(const SHADER_OPCODE_ARG *arg) (src1reg == dstreg && src1regtype == dstregtype) || (src2reg == dstreg && src2regtype == dstregtype)) { - write_mask = shader_glsl_get_write_mask(arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask), mask_char); + write_mask = shader_glsl_get_write_mask(ins->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask), mask_char); if (!write_mask) continue; - shader_addline(arg->buffer, "tmp0%s = (", mask_char); + shader_addline(ins->buffer, "tmp0%s = (", mask_char); temp_destination = TRUE; } else { - write_mask = shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask)); + write_mask = shader_glsl_append_dst_ext(ins->buffer, ins, + ins->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask)); if (!write_mask) continue; } - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], cmp_channel, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], cmp_channel, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); - shader_addline(arg->buffer, "%s >= 0.0 ? %s : %s);\n", + shader_addline(ins->buffer, "%s >= 0.0 ? %s : %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); } if(temp_destination) { - shader_glsl_get_write_mask(arg->dst, mask_char); - shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst); - shader_addline(arg->buffer, "tmp0%s);\n", mask_char); + shader_glsl_get_write_mask(ins->dst, mask_char); + shader_glsl_append_dst_ext(ins->buffer, ins, ins->dst); + shader_addline(ins->buffer, "tmp0%s);\n", mask_char); } } @@ -1955,7 +1965,7 @@ static void shader_glsl_cmp(const SHADER_OPCODE_ARG *arg) /** Process the CND opcode in GLSL (dst = (src0 > 0.5) ? src1 : src2) */ /* For ps 1.1-1.3, only a single component of src0 is used. For ps 1.4 * the compare is done per component of src0. */ -static void shader_glsl_cnd(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_cnd(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; @@ -1963,19 +1973,19 @@ static void shader_glsl_cnd(const SHADER_OPCODE_ARG *arg) DWORD write_mask, cmp_channel = 0; unsigned int i, j; - if (arg->reg_maps->shader_version < WINED3DPS_VERSION(1, 4)) + if (ins->reg_maps->shader_version < WINED3DPS_VERSION(1, 4)) { - write_mask = shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); + write_mask = shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); /* Fun: The D3DSI_COISSUE flag changes the semantic of the cnd instruction for < 1.4 shaders */ - if (arg->coissue) + if (ins->coissue) { - shader_addline(arg->buffer, "%s /* COISSUE! */);\n", src1_param.param_str); + shader_addline(ins->buffer, "%s /* COISSUE! */);\n", src1_param.param_str); } else { - shader_addline(arg->buffer, "%s > 0.5 ? %s : %s);\n", + shader_addline(ins->buffer, "%s > 0.5 ? %s : %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); } return; @@ -1985,89 +1995,92 @@ static void shader_glsl_cnd(const SHADER_OPCODE_ARG *arg) write_mask = 0; /* Find the destination channels which use the current source0 channel */ for (j=0; j<4; j++) { - if ( ((arg->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2*j)) & 0x3) == i ) { + if (((ins->src[0] >> (WINED3DSP_SWIZZLE_SHIFT + 2 * j)) & 0x3) == i) + { write_mask |= WINED3DSP_WRITEMASK_0 << j; cmp_channel = WINED3DSP_WRITEMASK_0 << j; } } - write_mask = shader_glsl_append_dst_ext(arg->buffer, arg, arg->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask)); + write_mask = shader_glsl_append_dst_ext(ins->buffer, ins, ins->dst & (~WINED3DSP_SWIZZLE_MASK | write_mask)); if (!write_mask) continue; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], cmp_channel, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], cmp_channel, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); - shader_addline(arg->buffer, "%s > 0.5 ? %s : %s);\n", + shader_addline(ins->buffer, "%s > 0.5 ? %s : %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); } } /** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */ -static void shader_glsl_mad(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_mad(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; glsl_src_param_t src2_param; DWORD write_mask; - write_mask = shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); - shader_addline(arg->buffer, "(%s * %s) + %s);\n", + write_mask = shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); + shader_addline(ins->buffer, "(%s * %s) + %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); } /** Handles transforming all WINED3DSIO_M?x? opcodes for Vertex shaders to GLSL codes */ -static void shader_glsl_mnxn(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_mnxn(const struct wined3d_shader_instruction *ins) { - IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)arg->shader; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; const SHADER_OPCODE *opcode_table = shader->baseShader.shader_ins; - DWORD shader_version = arg->reg_maps->shader_version; + DWORD shader_version = ins->reg_maps->shader_version; int i; int nComponents = 0; - SHADER_OPCODE_ARG tmpArg; - - memset(&tmpArg, 0, sizeof(SHADER_OPCODE_ARG)); + struct wined3d_shader_instruction tmp_ins; + + memset(&tmp_ins, 0, sizeof(tmp_ins)); /* Set constants for the temporary argument */ - tmpArg.shader = arg->shader; - tmpArg.buffer = arg->buffer; - tmpArg.src[0] = arg->src[0]; - tmpArg.src_addr[0] = arg->src_addr[0]; - tmpArg.src_addr[1] = arg->src_addr[1]; - tmpArg.reg_maps = arg->reg_maps; - - switch(arg->opcode->opcode) { + tmp_ins.shader = ins->shader; + tmp_ins.buffer = ins->buffer; + tmp_ins.src[0] = ins->src[0]; + tmp_ins.src_addr[0] = ins->src_addr[0]; + tmp_ins.src_addr[1] = ins->src_addr[1]; + tmp_ins.reg_maps = ins->reg_maps; + + switch(ins->opcode->opcode) + { case WINED3DSIO_M4x4: nComponents = 4; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); break; case WINED3DSIO_M4x3: nComponents = 3; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP4); break; case WINED3DSIO_M3x4: nComponents = 4; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; case WINED3DSIO_M3x3: nComponents = 3; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; case WINED3DSIO_M3x2: nComponents = 2; - tmpArg.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); + tmp_ins.opcode = shader_get_opcode(opcode_table, shader_version, WINED3DSIO_DP3); break; default: break; } - for (i = 0; i < nComponents; i++) { - tmpArg.dst = ((arg->dst) & ~WINED3DSP_WRITEMASK_ALL)|(WINED3DSP_WRITEMASK_0<src[1]+i; - shader_glsl_dot(&tmpArg); + for (i = 0; i < nComponents; ++i) + { + tmp_ins.dst = ((ins->dst) & ~WINED3DSP_WRITEMASK_ALL) | (WINED3DSP_WRITEMASK_0 << i); + tmp_ins.src[1] = ins->src[1] + i; + shader_glsl_dot(&tmp_ins); } } @@ -2077,20 +2090,20 @@ static void shader_glsl_mnxn(const SHADER_OPCODE_ARG *arg) blend factor. Equation: (dst = src2 + src0 * (src1 - src2)) This is equivalent to mix(src2, src1, src0); */ -static void shader_glsl_lrp(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_lrp(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; glsl_src_param_t src2_param; DWORD write_mask; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], write_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], write_mask, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], write_mask, &src2_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], write_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], write_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], write_mask, &src2_param); - shader_addline(arg->buffer, "mix(%s, %s, %s));\n", + shader_addline(ins->buffer, "mix(%s, %s, %s));\n", src2_param.param_str, src1_param.param_str, src0_param.param_str); } @@ -2100,19 +2113,19 @@ static void shader_glsl_lrp(const SHADER_OPCODE_ARG *arg) * dst.z = (src0.x > 0) ? ((src0.y > 0) ? pow(src0.y, src.w) : 0) : 0 * where src.w is clamped at +- 128 */ -static void shader_glsl_lit(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_lit(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; glsl_src_param_t src3_param; char dst_mask[6]; - shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_get_write_mask(arg->dst, dst_mask); + shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_get_write_mask(ins->dst, dst_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_1, &src1_param); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &src3_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_1, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &src3_param); /* The sdk specifies the instruction like this * dst.x = 1.0; @@ -2135,8 +2148,9 @@ static void shader_glsl_lit(const SHADER_OPCODE_ARG *arg) * which sets dst.z to 0. If y > 0, but x = 0.0, we get pow(y * 0.0, power), which results in 0 too. * if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to */ - shader_addline(arg->buffer, "vec4(1.0, max(%s, 0.0), pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n", - src0_param.param_str, src1_param.param_str, src0_param.param_str, src3_param.param_str, dst_mask); + shader_addline(ins->buffer, + "vec4(1.0, max(%s, 0.0), pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n", + src0_param.param_str, src1_param.param_str, src0_param.param_str, src3_param.param_str, dst_mask); } /** Process the WINED3DSIO_DST instruction in GLSL: @@ -2145,7 +2159,7 @@ static void shader_glsl_lit(const SHADER_OPCODE_ARG *arg) * dst.z = src0.z * dst.w = src1.w */ -static void shader_glsl_dst(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_dst(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0y_param; glsl_src_param_t src0z_param; @@ -2153,15 +2167,15 @@ static void shader_glsl_dst(const SHADER_OPCODE_ARG *arg) glsl_src_param_t src1w_param; char dst_mask[6]; - shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_get_write_mask(arg->dst, dst_mask); + shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_get_write_mask(ins->dst, dst_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_1, &src0y_param); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &src0z_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_1, &src1y_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_3, &src1w_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_1, &src0y_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_2, &src0z_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_1, &src1y_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_3, &src1w_param); - shader_addline(arg->buffer, "vec4(1.0, %s * %s, %s, %s))%s;\n", + shader_addline(ins->buffer, "vec4(1.0, %s * %s, %s, %s))%s;\n", src0y_param.param_str, src1y_param.param_str, src0z_param.param_str, src1w_param.param_str, dst_mask); } @@ -2174,25 +2188,25 @@ static void shader_glsl_dst(const SHADER_OPCODE_ARG *arg) * dst.z = dst.z * dst.w = dst.w */ -static void shader_glsl_sincos(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_sincos(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; DWORD write_mask; - write_mask = shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + write_mask = shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); switch (write_mask) { case WINED3DSP_WRITEMASK_0: - shader_addline(arg->buffer, "cos(%s));\n", src0_param.param_str); + shader_addline(ins->buffer, "cos(%s));\n", src0_param.param_str); break; case WINED3DSP_WRITEMASK_1: - shader_addline(arg->buffer, "sin(%s));\n", src0_param.param_str); + shader_addline(ins->buffer, "sin(%s));\n", src0_param.param_str); break; case (WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1): - shader_addline(arg->buffer, "vec2(cos(%s), sin(%s)));\n", src0_param.param_str, src0_param.param_str); + shader_addline(ins->buffer, "vec2(cos(%s), sin(%s)));\n", src0_param.param_str, src0_param.param_str); break; default: @@ -2207,16 +2221,16 @@ static void shader_glsl_sincos(const SHADER_OPCODE_ARG *arg) * Need to use a temporary variable for this operation. */ /* FIXME: I don't think nested loops will work correctly this way. */ -static void shader_glsl_loop(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_loop(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src1_param; - IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader; - DWORD regtype = shader_get_regtype(arg->src[1]); - DWORD reg = arg->src[1] & WINED3DSP_REGNUM_MASK; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; + DWORD regtype = shader_get_regtype(ins->src[1]); + DWORD reg = ins->src[1] & WINED3DSP_REGNUM_MASK; const DWORD *control_values = NULL; const local_constant *constant; - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_ALL, &src1_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_ALL, &src1_param); /* Try to hardcode the loop control parameters if possible. Direct3D 9 class hardware doesn't support real * varying indexing, but Microsoft designed this feature for Shader model 2.x+. If the loop control is @@ -2234,133 +2248,136 @@ static void shader_glsl_loop(const SHADER_OPCODE_ARG *arg) if(control_values) { if(control_values[2] > 0) { - shader_addline(arg->buffer, "for (aL%u = %d; aL%u < (%d * %d + %d); aL%u += %d) {\n", - shader->baseShader.cur_loop_depth, control_values[1], - shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1], - shader->baseShader.cur_loop_depth, control_values[2]); + shader_addline(ins->buffer, "for (aL%u = %d; aL%u < (%d * %d + %d); aL%u += %d) {\n", + shader->baseShader.cur_loop_depth, control_values[1], + shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1], + shader->baseShader.cur_loop_depth, control_values[2]); } else if(control_values[2] == 0) { - shader_addline(arg->buffer, "for (aL%u = %d, tmpInt%u = 0; tmpInt%u < %d; tmpInt%u++) {\n", - shader->baseShader.cur_loop_depth, control_values[1], shader->baseShader.cur_loop_depth, - shader->baseShader.cur_loop_depth, control_values[0], - shader->baseShader.cur_loop_depth); + shader_addline(ins->buffer, "for (aL%u = %d, tmpInt%u = 0; tmpInt%u < %d; tmpInt%u++) {\n", + shader->baseShader.cur_loop_depth, control_values[1], shader->baseShader.cur_loop_depth, + shader->baseShader.cur_loop_depth, control_values[0], + shader->baseShader.cur_loop_depth); } else { - shader_addline(arg->buffer, "for (aL%u = %d; aL%u > (%d * %d + %d); aL%u += %d) {\n", - shader->baseShader.cur_loop_depth, control_values[1], - shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1], - shader->baseShader.cur_loop_depth, control_values[2]); + shader_addline(ins->buffer, "for (aL%u = %d; aL%u > (%d * %d + %d); aL%u += %d) {\n", + shader->baseShader.cur_loop_depth, control_values[1], + shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1], + shader->baseShader.cur_loop_depth, control_values[2]); } } else { - shader_addline(arg->buffer, "for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z) {\n", - shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno, - src1_param.reg_name, shader->baseShader.cur_loop_depth, src1_param.reg_name, - shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno, src1_param.reg_name); + shader_addline(ins->buffer, "for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z) {\n", + shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno, + src1_param.reg_name, shader->baseShader.cur_loop_depth, src1_param.reg_name, + shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_regno, src1_param.reg_name); } shader->baseShader.cur_loop_depth++; shader->baseShader.cur_loop_regno++; } -static void shader_glsl_end(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_end(const struct wined3d_shader_instruction *ins) { - IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; - shader_addline(arg->buffer, "}\n"); + shader_addline(ins->buffer, "}\n"); - if(arg->opcode->opcode == WINED3DSIO_ENDLOOP) { + if (ins->opcode->opcode == WINED3DSIO_ENDLOOP) + { shader->baseShader.cur_loop_depth--; shader->baseShader.cur_loop_regno--; } - if(arg->opcode->opcode == WINED3DSIO_ENDREP) { + + if (ins->opcode->opcode == WINED3DSIO_ENDREP) + { shader->baseShader.cur_loop_depth--; } } -static void shader_glsl_rep(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_rep(const struct wined3d_shader_instruction *ins) { - IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader; + IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->shader; glsl_src_param_t src0_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_addline(arg->buffer, "for (tmpInt%d = 0; tmpInt%d < %s; tmpInt%d++) {\n", - shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_depth, - src0_param.param_str, shader->baseShader.cur_loop_depth); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_addline(ins->buffer, "for (tmpInt%d = 0; tmpInt%d < %s; tmpInt%d++) {\n", + shader->baseShader.cur_loop_depth, shader->baseShader.cur_loop_depth, + src0_param.param_str, shader->baseShader.cur_loop_depth); shader->baseShader.cur_loop_depth++; } -static void shader_glsl_if(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_if(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_addline(arg->buffer, "if (%s) {\n", src0_param.param_str); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_addline(ins->buffer, "if (%s) {\n", src0_param.param_str); } -static void shader_glsl_ifc(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_ifc(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); - shader_addline(arg->buffer, "if (%s %s %s) {\n", - src0_param.param_str, shader_get_comp_op(arg->flags), src1_param.param_str); + shader_addline(ins->buffer, "if (%s %s %s) {\n", + src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str); } -static void shader_glsl_else(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_else(const struct wined3d_shader_instruction *ins) { - shader_addline(arg->buffer, "} else {\n"); + shader_addline(ins->buffer, "} else {\n"); } -static void shader_glsl_break(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_break(const struct wined3d_shader_instruction *ins) { - shader_addline(arg->buffer, "break;\n"); + shader_addline(ins->buffer, "break;\n"); } /* FIXME: According to MSDN the compare is done per component. */ -static void shader_glsl_breakc(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_breakc(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); - shader_addline(arg->buffer, "if (%s %s %s) break;\n", - src0_param.param_str, shader_get_comp_op(arg->flags), src1_param.param_str); + shader_addline(ins->buffer, "if (%s %s %s) break;\n", + src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str); } -static void shader_glsl_label(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_label(const struct wined3d_shader_instruction *ins) { - DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK; - shader_addline(arg->buffer, "}\n"); - shader_addline(arg->buffer, "void subroutine%u () {\n", snum); + DWORD snum = (ins->src[0]) & WINED3DSP_REGNUM_MASK; + shader_addline(ins->buffer, "}\n"); + shader_addline(ins->buffer, "void subroutine%u () {\n", snum); } -static void shader_glsl_call(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_call(const struct wined3d_shader_instruction *ins) { - DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK; - shader_addline(arg->buffer, "subroutine%u();\n", snum); + DWORD snum = (ins->src[0]) & WINED3DSP_REGNUM_MASK; + shader_addline(ins->buffer, "subroutine%u();\n", snum); } -static void shader_glsl_callnz(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_callnz(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src1_param; - DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK; - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); - shader_addline(arg->buffer, "if (%s) subroutine%u();\n", src1_param.param_str, snum); + DWORD snum = (ins->src[0]) & WINED3DSP_REGNUM_MASK; + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], WINED3DSP_WRITEMASK_0, &src1_param); + shader_addline(ins->buffer, "if (%s) subroutine%u();\n", src1_param.param_str, snum); } /********************************************* * Pixel Shader Specific Code begins here ********************************************/ -static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_tex(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; - DWORD shader_version = arg->reg_maps->shader_version; + DWORD shader_version = ins->reg_maps->shader_version; glsl_sample_function_t sample_function; DWORD sample_flags = 0; DWORD sampler_type; @@ -2369,9 +2386,9 @@ static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) /* 1.0-1.4: Use destination register as sampler source. * 2.0+: Use provided sampler source. */ - if (shader_version < WINED3DPS_VERSION(2,0)) sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; - else sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK; - sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + if (shader_version < WINED3DPS_VERSION(2,0)) sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; + else sampler_idx = ins->src[1] & WINED3DSP_REGNUM_MASK; + sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; if (shader_version < WINED3DPS_VERSION(1,4)) { @@ -2391,7 +2408,7 @@ static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) } else if (shader_version < WINED3DPS_VERSION(2,0)) { - DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK; + DWORD src_mod = ins->src[0] & WINED3DSP_SRCMOD_MASK; if (src_mod == WINED3DSPSM_DZ) { sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED; @@ -2401,7 +2418,7 @@ static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) mask = WINED3DSP_WRITEMASK_3; } } else { - if (arg->flags & WINED3DSI_TEXLD_PROJECT) + if (ins->flags & WINED3DSI_TEXLD_PROJECT) { /* ps 2.0 texldp instruction always divides by the fourth component. */ sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED; @@ -2418,7 +2435,7 @@ static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) mask |= sample_function.coord_mask; if (shader_version < WINED3DPS_VERSION(2,0)) swizzle = WINED3DVS_NOSWIZZLE; - else swizzle = arg->src[1] & WINED3DSP_SWIZZLE_MASK; + else swizzle = ins->src[1] & WINED3DSP_SWIZZLE_MASK; /* 1.0-1.3: Use destination register as coordinate source. 1.4+: Use provided coordinate source register. */ @@ -2426,81 +2443,81 @@ static void pshader_glsl_tex(const SHADER_OPCODE_ARG *arg) { char coord_mask[6]; shader_glsl_get_write_mask(mask, coord_mask); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, swizzle, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, "T%u%s", sampler_idx, coord_mask); } else { glsl_src_param_t coord_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], mask, &coord_param); - if (arg->flags & WINED3DSI_TEXLD_BIAS) + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], mask, &coord_param); + if (ins->flags & WINED3DSI_TEXLD_BIAS) { glsl_src_param_t bias; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &bias); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, swizzle, bias.param_str, + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &bias); + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, bias.param_str, "%s", coord_param.param_str); } else { - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, swizzle, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, "%s", coord_param.param_str); } } } -static void shader_glsl_texldl(const SHADER_OPCODE_ARG *arg) +static void shader_glsl_texldl(const struct wined3d_shader_instruction *ins) { - IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*)arg->shader; + IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; glsl_sample_function_t sample_function; glsl_src_param_t coord_param, lod_param; DWORD sample_flags = WINED3D_GLSL_SAMPLE_LOD; DWORD sampler_type; DWORD sampler_idx; - DWORD swizzle = arg->src[1] & WINED3DSP_SWIZZLE_MASK; + DWORD swizzle = ins->src[1] & WINED3DSP_SWIZZLE_MASK; - sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK; - sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + sampler_idx = ins->src[1] & WINED3DSP_REGNUM_MASK; + sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; if(deviceImpl->stateBlock->textures[sampler_idx] && IWineD3DBaseTexture_GetTextureDimensions(deviceImpl->stateBlock->textures[sampler_idx]) == GL_TEXTURE_RECTANGLE_ARB) { sample_flags |= WINED3D_GLSL_SAMPLE_RECT; } shader_glsl_get_sample_function(sampler_type, sample_flags, &sample_function); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], sample_function.coord_mask, &coord_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], sample_function.coord_mask, &coord_param); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &lod_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &lod_param); - if (shader_is_pshader_version(arg->reg_maps->shader_version)) + if (shader_is_pshader_version(ins->reg_maps->shader_version)) { /* The GLSL spec claims the Lod sampling functions are only supported in vertex shaders. * However, they seem to work just fine in fragment shaders as well. */ WARN("Using %s in fragment shader.\n", sample_function.name); } - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, swizzle, lod_param.param_str, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, lod_param.param_str, "%s", coord_param.param_str); } -static void pshader_glsl_texcoord(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texcoord(const struct wined3d_shader_instruction *ins) { /* FIXME: Make this work for more than just 2D textures */ - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; DWORD write_mask; char dst_mask[6]; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); shader_glsl_get_write_mask(write_mask, dst_mask); - if (arg->reg_maps->shader_version != WINED3DPS_VERSION(1,4)) + if (ins->reg_maps->shader_version != WINED3DPS_VERSION(1,4)) { - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; shader_addline(buffer, "clamp(gl_TexCoord[%u], 0.0, 1.0)%s);\n", reg, dst_mask); } else { - DWORD reg = arg->src[0] & WINED3DSP_REGNUM_MASK; - DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK; + DWORD reg = ins->src[0] & WINED3DSP_REGNUM_MASK; + DWORD src_mod = ins->src[0] & WINED3DSP_SRCMOD_MASK; char dst_swizzle[6]; - shader_glsl_get_swizzle(arg->src[0], FALSE, write_mask, dst_swizzle); + shader_glsl_get_swizzle(ins->src[0], FALSE, write_mask, dst_swizzle); if (src_mod == WINED3DSPSM_DZ) { glsl_src_param_t div_param; unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &div_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_2, &div_param); if (mask_size > 1) { shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str); @@ -2510,7 +2527,7 @@ static void pshader_glsl_texcoord(const SHADER_OPCODE_ARG *arg) } else if (src_mod == WINED3DSPSM_DW) { glsl_src_param_t div_param; unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_3, &div_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_3, &div_param); if (mask_size > 1) { shader_addline(buffer, "gl_TexCoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str); @@ -2526,16 +2543,16 @@ static void pshader_glsl_texcoord(const SHADER_OPCODE_ARG *arg) /** Process the WINED3DSIO_TEXDP3TEX instruction in GLSL: * Take a 3-component dot product of the TexCoord[dstreg] and src, * then perform a 1D texture lookup from stage dstregnum, place into dst. */ -static void pshader_glsl_texdp3tex(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_sample_function_t sample_function; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; UINT mask_size; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); /* Do I have to take care about the projected bit? I don't think so, since the dp3 returns only one * scalar, and projected sampling would require 4. @@ -2548,17 +2565,17 @@ static void pshader_glsl_texdp3tex(const SHADER_OPCODE_ARG *arg) switch(mask_size) { case 1: - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "dot(gl_TexCoord[%u].xyz, %s)", sampler_idx, src0_param.param_str); break; case 2: - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "vec2(dot(gl_TexCoord[%u].xyz, %s), 0.0)", sampler_idx, src0_param.param_str); break; case 3: - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "vec3(dot(gl_TexCoord[%u].xyz, %s), 0.0, 0.0)", sampler_idx, src0_param.param_str); break; @@ -2570,32 +2587,32 @@ static void pshader_glsl_texdp3tex(const SHADER_OPCODE_ARG *arg) /** Process the WINED3DSIO_TEXDP3 instruction in GLSL: * Take a 3-component dot product of the TexCoord[dstreg] and src. */ -static void pshader_glsl_texdp3(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texdp3(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; - DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD dstreg = ins->dst & WINED3DSP_REGNUM_MASK; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; DWORD dst_mask; unsigned int mask_size; - dst_mask = shader_glsl_append_dst(arg->buffer, arg); + dst_mask = shader_glsl_append_dst(ins->buffer, ins); mask_size = shader_glsl_get_write_mask_size(dst_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); if (mask_size > 1) { - shader_addline(arg->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str); + shader_addline(ins->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str); } else { - shader_addline(arg->buffer, "dot(T%u.xyz, %s));\n", dstreg, src0_param.param_str); + shader_addline(ins->buffer, "dot(T%u.xyz, %s));\n", dstreg, src0_param.param_str); } } /** Process the WINED3DSIO_TEXDEPTH instruction in GLSL: * Calculate the depth as dst.x / dst.y */ -static void pshader_glsl_texdepth(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texdepth(const struct wined3d_shader_instruction *ins) { glsl_dst_param_t dst_param; - shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param); + shader_glsl_add_dst_param(ins, ins->dst, 0, &dst_param); /* Tests show that texdepth never returns anything below 0.0, and that r5.y is clamped to 1.0. * Negative input is accepted, -0.25 / -0.5 returns 0.5. GL should clamp gl_FragDepth to [0;1], but @@ -2603,7 +2620,8 @@ static void pshader_glsl_texdepth(const SHADER_OPCODE_ARG *arg) * too is irrelevant, since if x = 0, any y value < 1.0 (and > 1.0 is not allowed) results in a result * >= 1.0 or < 0.0 */ - shader_addline(arg->buffer, "gl_FragDepth = clamp((%s.x / min(%s.y, 1.0)), 0.0, 1.0);\n", dst_param.reg_name, dst_param.reg_name); + shader_addline(ins->buffer, "gl_FragDepth = clamp((%s.x / min(%s.y, 1.0)), 0.0, 1.0);\n", + dst_param.reg_name, dst_param.reg_name); } /** Process the WINED3DSIO_TEXM3X2DEPTH instruction in GLSL: @@ -2611,125 +2629,125 @@ static void pshader_glsl_texdepth(const SHADER_OPCODE_ARG *arg) * Calculate tmp0.y = TexCoord[dstreg] . src.xyz; (tmp0.x has already been calculated) * depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y */ -static void pshader_glsl_texm3x2depth(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x2depth(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD dstreg = ins->dst & WINED3DSP_REGNUM_MASK; glsl_src_param_t src0_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); - shader_addline(arg->buffer, "tmp0.y = dot(T%u.xyz, %s);\n", dstreg, src0_param.param_str); - shader_addline(arg->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n"); + shader_addline(ins->buffer, "tmp0.y = dot(T%u.xyz, %s);\n", dstreg, src0_param.param_str); + shader_addline(ins->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n"); } /** Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL * Calculate the 1st of a 2-row matrix multiplication. */ -static void pshader_glsl_texm3x2pad(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); shader_addline(buffer, "tmp0.x = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); } /** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL * Calculate the 1st or 2nd row of a 3-row matrix multiplication. */ -static void pshader_glsl_texm3x3pad(const SHADER_OPCODE_ARG* arg) +static void pshader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->shader; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state; glsl_src_param_t src0_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[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; } -static void pshader_glsl_texm3x2tex(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; glsl_src_param_t src0_param; - DWORD sampler_type = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_type = ins->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); shader_addline(buffer, "tmp0.y = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); shader_glsl_get_sample_function(sampler_type, 0, &sample_function); /* Sample the texture using the calculated coordinates */ - shader_glsl_gen_sample_code(arg, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xy"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xy"); } /** Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL * Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates */ -static void pshader_glsl_texm3x3tex(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; glsl_src_param_t src0_param; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; - DWORD sampler_type = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_type = ins->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); - shader_addline(arg->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); + shader_addline(ins->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(sampler_type, 0, &sample_function); /* Sample the texture using the calculated coordinates */ - shader_glsl_gen_sample_code(arg, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); current_state->current_row = 0; } /** Process the WINED3DSIO_TEXM3X3 instruction in GLSL * Perform the 3rd row of a 3x3 matrix multiply */ -static void pshader_glsl_texm3x3(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x3(const struct wined3d_shader_instruction *ins) { DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; glsl_src_param_t src0_param; char dst_mask[6]; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); - shader_glsl_append_dst(arg->buffer, arg); - shader_glsl_get_write_mask(arg->dst, dst_mask); - shader_addline(arg->buffer, "vec4(tmp0.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask); + shader_glsl_append_dst(ins->buffer, ins); + shader_glsl_get_write_mask(ins->dst, dst_mask); + shader_addline(ins->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; } /** Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */ -static void pshader_glsl_texm3x3spec(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; + IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->shader; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; glsl_src_param_t src0_param; glsl_src_param_t src1_param; - SHADER_BUFFER* buffer = arg->buffer; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state; - DWORD stype = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; + DWORD stype = ins->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], src_mask, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], src_mask, &src1_param); /* Perform the last matrix multiply operation */ shader_addline(buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str); @@ -2740,25 +2758,25 @@ static void pshader_glsl_texm3x3spec(const SHADER_OPCODE_ARG *arg) shader_glsl_get_sample_function(stype, 0, &sample_function); /* Sample the texture */ - shader_glsl_gen_sample_code(arg, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); current_state->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 pshader_glsl_texm3x3vspec(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader; - DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK; - SHADER_BUFFER* buffer = arg->buffer; + IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->shader; + DWORD reg = ins->dst & WINED3DSP_REGNUM_MASK; + SHADER_BUFFER *buffer = ins->buffer; SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state; glsl_src_param_t src0_param; DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2; - DWORD sampler_type = arg->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_type = ins->reg_maps->samplers[reg] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], src_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], src_mask, &src0_param); /* Perform the last matrix multiply operation */ shader_addline(buffer, "tmp0.z = dot(vec3(T%u), vec3(%s));\n", reg, src0_param.param_str); @@ -2772,7 +2790,7 @@ static void pshader_glsl_texm3x3vspec(const SHADER_OPCODE_ARG *arg) shader_glsl_get_sample_function(sampler_type, 0, &sample_function); /* Sample the texture using the calculated coordinates */ - shader_glsl_gen_sample_code(arg, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); + shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "tmp0.xyz"); current_state->current_row = 0; } @@ -2781,9 +2799,9 @@ static void pshader_glsl_texm3x3vspec(const SHADER_OPCODE_ARG *arg) * Apply a fake bump map transform. * texbem is pshader <= 1.3 only, this saves a few version checks */ -static void pshader_glsl_texbem(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texbem(const struct wined3d_shader_instruction *ins) { - IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader; + IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->shader; IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device; glsl_sample_function_t sample_function; glsl_src_param_t coord_param; @@ -2793,10 +2811,10 @@ static void pshader_glsl_texbem(const SHADER_OPCODE_ARG *arg) DWORD flags; char coord_mask[6]; - sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; + sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS]; - sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(sampler_type, 0, &sample_function); mask = sample_function.coord_mask; @@ -2817,114 +2835,118 @@ static void pshader_glsl_texbem(const SHADER_OPCODE_ARG *arg) case WINED3DTTFF_DISABLE: div_mask = WINED3DSP_WRITEMASK_3; break; } shader_glsl_get_write_mask(div_mask, coord_div_mask); - shader_addline(arg->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask); + shader_addline(ins->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask); } - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0|WINED3DSP_WRITEMASK_1, &coord_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], + WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &coord_param); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "T%u%s + vec4(bumpenvmat%d * %s, 0.0, 0.0)%s", sampler_idx, coord_mask, sampler_idx, coord_param.param_str, coord_mask); - if(arg->opcode->opcode == WINED3DSIO_TEXBEML) { + if (ins->opcode->opcode == WINED3DSIO_TEXBEML) + { glsl_src_param_t luminance_param; glsl_dst_param_t dst_param; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_2, &luminance_param); - shader_glsl_add_dst_param(arg, arg->dst, arg->dst_addr, &dst_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_2, &luminance_param); + shader_glsl_add_dst_param(ins, ins->dst, ins->dst_addr, &dst_param); - shader_addline(arg->buffer, "%s%s *= (%s * luminancescale%d + luminanceoffset%d);\n", - dst_param.reg_name, dst_param.mask_str, - luminance_param.param_str, sampler_idx, sampler_idx); + shader_addline(ins->buffer, "%s%s *= (%s * luminancescale%d + luminanceoffset%d);\n", + dst_param.reg_name, dst_param.mask_str, + luminance_param.param_str, sampler_idx, sampler_idx); } } -static void pshader_glsl_bem(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_bem(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param, src1_param; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0|WINED3DSP_WRITEMASK_1, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0|WINED3DSP_WRITEMASK_1, &src1_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], + WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], + WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param); - shader_glsl_append_dst(arg->buffer, arg); - shader_addline(arg->buffer, "%s + bumpenvmat%d * %s);\n", - src0_param.param_str, sampler_idx, src1_param.param_str); + shader_glsl_append_dst(ins->buffer, ins); + shader_addline(ins->buffer, "%s + bumpenvmat%d * %s);\n", + src0_param.param_str, sampler_idx, src1_param.param_str); } /** Process the WINED3DSIO_TEXREG2AR instruction in GLSL * Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */ -static void pshader_glsl_texreg2ar(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; - DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); shader_glsl_get_sample_function(sampler_type, 0, &sample_function); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "%s.wx", src0_param.reg_name); } /** Process the WINED3DSIO_TEXREG2GB instruction in GLSL * Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */ -static void pshader_glsl_texreg2gb(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; - DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], WINED3DSP_WRITEMASK_ALL, &src0_param); shader_glsl_get_sample_function(sampler_type, 0, &sample_function); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "%s.yz", src0_param.reg_name); } /** Process the WINED3DSIO_TEXREG2RGB instruction in GLSL * Sample texture at dst using the rgb (xyz) components of src as texture coordinates */ -static void pshader_glsl_texreg2rgb(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; - DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK; - DWORD sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; + DWORD sampler_idx = ins->dst & WINED3DSP_REGNUM_MASK; + DWORD sampler_type = ins->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK; glsl_sample_function_t sample_function; /* Dependent read, not valid with conditional NP2 */ shader_glsl_get_sample_function(sampler_type, 0, &sample_function); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], sample_function.coord_mask, &src0_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], sample_function.coord_mask, &src0_param); - shader_glsl_gen_sample_code(arg, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, + shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DVS_NOSWIZZLE, NULL, "%s", src0_param.param_str); } /** Process the WINED3DSIO_TEXKILL instruction in GLSL. * If any of the first 3 components are < 0, discard this pixel */ -static void pshader_glsl_texkill(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_texkill(const struct wined3d_shader_instruction *ins) { glsl_dst_param_t dst_param; /* The argument is a destination parameter, and no writemasks are allowed */ - shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param); - if ((arg->reg_maps->shader_version >= WINED3DPS_VERSION(2,0))) + shader_glsl_add_dst_param(ins, ins->dst, 0, &dst_param); + if ((ins->reg_maps->shader_version >= WINED3DPS_VERSION(2,0))) { /* 2.0 shaders compare all 4 components in texkill */ - shader_addline(arg->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name); + shader_addline(ins->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name); } else { /* 1.X shaders only compare the first 3 components, probably due to the nature of the texkill * instruction as a tex* instruction, and phase, which kills all a / w components. Even if all * 4 components are defined, only the first 3 are used */ - shader_addline(arg->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name); + shader_addline(ins->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name); } } /** Process the WINED3DSIO_DP2ADD instruction in GLSL. * dst = dot2(src0, src1) + src2 */ -static void pshader_glsl_dp2add(const SHADER_OPCODE_ARG *arg) +static void pshader_glsl_dp2add(const struct wined3d_shader_instruction *ins) { glsl_src_param_t src0_param; glsl_src_param_t src1_param; @@ -2932,17 +2954,22 @@ static void pshader_glsl_dp2add(const SHADER_OPCODE_ARG *arg) DWORD write_mask; unsigned int mask_size; - write_mask = shader_glsl_append_dst(arg->buffer, arg); + write_mask = shader_glsl_append_dst(ins->buffer, ins); mask_size = shader_glsl_get_write_mask_size(write_mask); - shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param); - shader_glsl_add_src_param(arg, arg->src[1], arg->src_addr[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param); - shader_glsl_add_src_param(arg, arg->src[2], arg->src_addr[2], WINED3DSP_WRITEMASK_0, &src2_param); + shader_glsl_add_src_param(ins, ins->src[0], ins->src_addr[0], + WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param); + shader_glsl_add_src_param(ins, ins->src[1], ins->src_addr[1], + WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param); + shader_glsl_add_src_param(ins, ins->src[2], ins->src_addr[2], + WINED3DSP_WRITEMASK_0, &src2_param); if (mask_size > 1) { - shader_addline(arg->buffer, "vec%d(dot(%s, %s) + %s));\n", mask_size, src0_param.param_str, src1_param.param_str, src2_param.param_str); + shader_addline(ins->buffer, "vec%d(dot(%s, %s) + %s));\n", + mask_size, src0_param.param_str, src1_param.param_str, src2_param.param_str); } else { - shader_addline(arg->buffer, "dot(%s, %s) + %s);\n", src0_param.param_str, src1_param.param_str, src2_param.param_str); + shader_addline(ins->buffer, "dot(%s, %s) + %s);\n", + src0_param.param_str, src1_param.param_str, src2_param.param_str); } } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 779df72c3f4..9e28adc84fd 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -450,7 +450,7 @@ typedef struct SHADER_OPCODE DWORD max_version; } SHADER_OPCODE; -typedef struct SHADER_OPCODE_ARG +struct wined3d_shader_instruction { IWineD3DBaseShader *shader; const shader_reg_maps *reg_maps; @@ -463,9 +463,9 @@ typedef struct SHADER_OPCODE_ARG DWORD src[4]; DWORD src_addr[4]; SHADER_BUFFER *buffer; -} SHADER_OPCODE_ARG; +}; -typedef void (*SHADER_HANDLER)(const struct SHADER_OPCODE_ARG *); +typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *); struct shader_caps { DWORD VertexShaderVersion; @@ -2300,7 +2300,7 @@ extern BOOL vshader_get_input( extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object); /* GLSL helper functions */ -extern void shader_glsl_add_instruction_modifiers(const SHADER_OPCODE_ARG *arg); +extern void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins); /***************************************************************************** * IDirect3DBaseShader implementation structure