Lines Matching defs:ins
1364 static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins,
1441 char *register_name, BOOL *is_color, const struct wined3d_shader_instruction *ins)
1446 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
1447 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
1462 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
1478 shader_glsl_add_src_param(ins, reg->rel_addr, WINED3DSP_WRITEMASK_0, &rel_param);
1533 shader_glsl_add_src_param(ins, reg->rel_addr, WINED3DSP_WRITEMASK_0, &rel_param);
1731 static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins,
1741 shader_glsl_get_register_name(&wined3d_src->reg, glsl_src->reg_name, &is_color, ins);
1749 static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction *ins,
1757 shader_glsl_get_register_name(&wined3d_dst->reg, glsl_dst->reg_name, &is_color, ins);
1763 const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst)
1768 mask = shader_glsl_add_dst_param(ins, dst, &glsl_dst);
1775 static DWORD shader_glsl_append_dst(struct wined3d_shader_buffer *buffer, const struct wined3d_shader_instruction *ins)
1777 return shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0]);
1781 static void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins)
1786 if (!ins->dst_count) return;
1788 modifiers = ins->dst[0].modifiers;
1791 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
1796 shader_addline(ins->ctx->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name,
1996 static void shader_glsl_color_correction(const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup)
2009 mask &= ins->dst[0].write_mask;
2022 dst = ins->dst[0];
2024 shader_glsl_add_dst_param(ins, &dst, &dst_param);
2051 shader_addline(ins->ctx->buffer, "%s%s = vec%u(%s);\n",
2056 shader_addline(ins->ctx->buffer, "%s%s = %s;\n", dst_param.reg_name, dst_param.mask_str, arguments);
2060 static void PRINTF_ATTR(8, 9) shader_glsl_gen_sample_code(const struct wined3d_shader_instruction *ins,
2072 shader_glsl_swizzle_to_str(swizzle, FALSE, ins->dst[0].write_mask, dst_swizzle);
2074 if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
2076 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
2090 if (ins->ctx->reg_maps->sampler_type[sampler]==WINED3DSTT_2D)
2095 shader_glsl_add_src_param(ins, &ins->src[0], sample_function->coord_mask, &coord_param);
2097 if (ins->src[0].reg.type != WINED3DSPR_INPUT)
2099 shader_addline(ins->ctx->buffer, "%s.y=1.0-%s.y;\n",
2105 shader_addline(ins->ctx->buffer, "tmp0.xy=vec2(%s.x, 1.0-%s.y).xy;\n",
2121 shader_glsl_append_dst(ins->ctx->buffer, ins);
2123 shader_addline(ins->ctx->buffer, "%s(%s%u, ", sample_function->name, sampler_base, sampler);
2127 shader_addline(ins->ctx->buffer, "%s", "tmp0.xy");
2132 shader_vaddline(ins->ctx->buffer, coord_reg_fmt, args);
2137 shader_addline(ins->ctx->buffer, ", %s)%s);\n", bias, dst_swizzle);
2140 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
2143 shader_addline(ins->ctx->buffer, " * PsamplerNP2Fixup[%u].%s)%s);\n", idx >> 1,
2146 shader_addline(ins->ctx->buffer, ", %s, %s)%s);\n", dx, dy, dst_swizzle);
2148 shader_addline(ins->ctx->buffer, ")%s);\n", dst_swizzle);
2153 shader_glsl_color_correction(ins, fixup);
2162 static void shader_glsl_arith(const struct wined3d_shader_instruction *ins)
2164 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2171 switch (ins->handler_idx)
2178 FIXME("Opcode %#x not yet handled in GLSL\n", ins->handler_idx);
2182 write_mask = shader_glsl_append_dst(buffer, ins);
2183 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2184 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2189 static void shader_glsl_mov_impl(const struct wined3d_shader_instruction *ins, int p0_idx);
2192 static void shader_glsl_mov(const struct wined3d_shader_instruction *ins)
2194 if (ins->predicate)
2197 DWORD dst_mask = ins->dst[0].write_mask;
2198 struct wined3d_shader_dst_param *dst = (struct wined3d_shader_dst_param *)&ins->dst[0];
2206 shader_glsl_mov_impl(ins, i);
2212 shader_glsl_mov_impl(ins, 0);
2216 static void shader_glsl_mov_impl(const struct wined3d_shader_instruction *ins, int p0_idx)
2220 static void shader_glsl_mov(const struct wined3d_shader_instruction *ins)
2223 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
2224 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2229 if (ins->predicate)
2235 write_mask = shader_glsl_append_dst(buffer, ins);
2236 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2240 if (ins->ctx->reg_maps->shader_version.major == 1
2241 && !shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type)
2242 && ins->dst[0].reg.type == WINED3DSPR_ADDR)
2252 else if(ins->handler_idx == WINED3DSIH_MOVA)
2279 if (ins->predicate)
2287 static void shader_glsl_dot(const struct wined3d_shader_instruction *ins)
2289 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2295 dst_write_mask = shader_glsl_append_dst(buffer, ins);
2299 if (ins->handler_idx == WINED3DSIH_DP4)
2306 shader_glsl_add_src_param(ins, &ins->src[0], src_write_mask, &src0_param);
2307 shader_glsl_add_src_param(ins, &ins->src[1], src_write_mask, &src1_param);
2318 static void shader_glsl_cross(const struct wined3d_shader_instruction *ins)
2325 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
2326 shader_glsl_append_dst(ins->ctx->buffer, ins);
2327 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
2328 shader_glsl_add_src_param(ins, &ins->src[1], src_mask, &src1_param);
2329 shader_addline(ins->ctx->buffer, "cross(%s, %s)%s);\n", src0_param.param_str, src1_param.param_str, dst_mask);
2335 static void shader_glsl_pow(const struct wined3d_shader_instruction *ins)
2337 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2343 dst_write_mask = shader_glsl_append_dst(buffer, ins);
2346 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
2347 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
2359 static void shader_glsl_log(const struct wined3d_shader_instruction *ins)
2361 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2366 dst_write_mask = shader_glsl_append_dst(buffer, ins);
2369 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
2384 static void shader_glsl_map2gl(const struct wined3d_shader_instruction *ins)
2386 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2394 switch (ins->handler_idx)
2404 FIXME("Opcode %#x not yet handled in GLSL\n", ins->handler_idx);
2408 write_mask = shader_glsl_append_dst(buffer, ins);
2412 if (ins->src_count)
2414 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
2416 for (i = 1; i < ins->src_count; ++i)
2418 shader_glsl_add_src_param(ins, &ins->src[i], write_mask, &src_param);
2426 static void shader_glsl_nrm(const struct wined3d_shader_instruction *ins)
2428 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2434 write_mask = shader_glsl_get_write_mask(ins->dst, dst_mask);
2436 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
2439 shader_glsl_append_dst(buffer, ins);
2461 static void shader_glsl_expp(const struct wined3d_shader_instruction *ins)
2465 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param);
2467 if (ins->ctx->reg_maps->shader_version.major < 2)
2471 shader_addline(ins->ctx->buffer, "tmp0.x = exp2(floor(%s));\n", src_param.param_str);
2472 shader_addline(ins->ctx->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str);
2473 shader_addline(ins->ctx->buffer, "tmp0.z = exp2(%s);\n", src_param.param_str);
2474 shader_addline(ins->ctx->buffer, "tmp0.w = 1.0;\n");
2476 shader_glsl_append_dst(ins->ctx->buffer, ins);
2477 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
2478 shader_addline(ins->ctx->buffer, "tmp0%s);\n", dst_mask);
2483 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2487 shader_addline(ins->ctx->buffer, "vec%d(exp2(%s)));\n", mask_size, src_param.param_str);
2489 shader_addline(ins->ctx->buffer, "exp2(%s));\n", src_param.param_str);
2495 static void shader_glsl_rcp(const struct wined3d_shader_instruction *ins)
2501 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2503 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &src_param);
2507 shader_addline(ins->ctx->buffer, "vec%d(%s == 0.0 ? FLT_MAX : 1.0 / %s));\n",
2512 shader_addline(ins->ctx->buffer, "%s == 0.0 ? FLT_MAX : 1.0 / %s);\n",
2517 static void shader_glsl_rsq(const struct wined3d_shader_instruction *ins)
2519 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2524 write_mask = shader_glsl_append_dst(buffer, ins);
2527 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &src_param);
2542 static void shader_glsl_setp(const struct wined3d_shader_instruction *ins)
2544 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
2549 DWORD dst_mask = ins->dst[0].write_mask;
2550 struct wined3d_shader_dst_param dst = ins->dst[0];
2559 write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst);
2562 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param1);
2563 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src_param2);
2566 src_param1.param_str, shader_get_comp_op(ins->flags), src_param2.param_str);
2573 static void shader_glsl_compare(const struct wined3d_shader_instruction *ins)
2580 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2582 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2583 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2588 switch(ins->handler_idx)
2593 FIXME("Can't handle opcode %#x\n", ins->handler_idx);
2596 shader_addline(ins->ctx->buffer, "vec%d(%s(%s, %s)));\n", mask_size, compare,
2599 switch(ins->handler_idx)
2609 shader_addline(ins->ctx->buffer, "(%s < %s) ? 1.0 : 0.0);\n",
2614 shader_addline(ins->ctx->buffer, "step(%s, %s));\n", src1_param.param_str, src0_param.param_str);
2617 FIXME("Can't handle opcode %#x\n", ins->handler_idx);
2624 static void shader_glsl_cmp(const struct wined3d_shader_instruction *ins)
2634 if (shader_is_scalar(&ins->src[0].reg))
2636 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2638 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
2639 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2640 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2642 shader_addline(ins->ctx->buffer, "%s >= 0.0 ? %s : %s);\n",
2645 DWORD dst_mask = ins->dst[0].write_mask;
2646 struct wined3d_shader_dst_param dst = ins->dst[0];
2653 if (((ins->src[0].swizzle >> (2 * j)) & 0x3) == i)
2665 if ((ins->src[0].reg.idx == ins->dst[0].reg.idx
2666 && ins->src[0].reg.type == ins->dst[0].reg.type)
2667 || (ins->src[1].reg.idx == ins->dst[0].reg.idx
2668 && ins->src[1].reg.type == ins->dst[0].reg.type)
2669 || (ins->src[2].reg.idx == ins->dst[0].reg.idx
2670 && ins->src[2].reg.type == ins->dst[0].reg.type))
2674 shader_addline(ins->ctx->buffer, "tmp0%s = (", mask_char);
2677 write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst);
2681 shader_glsl_add_src_param(ins, &ins->src[0], cmp_channel, &src0_param);
2682 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2683 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2685 shader_addline(ins->ctx->buffer, "%s >= 0.0 ? %s : %s);\n",
2690 shader_glsl_get_write_mask(&ins->dst[0], mask_char);
2691 shader_glsl_append_dst(ins->ctx->buffer, ins);
2692 shader_addline(ins->ctx->buffer, "tmp0%s);\n", mask_char);
2701 static void shader_glsl_cnd(const struct wined3d_shader_instruction *ins)
2710 DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
2711 ins->ctx->reg_maps->shader_version.minor);
2715 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2716 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
2717 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2718 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2721 if (ins->coissue)
2723 shader_addline(ins->ctx->buffer, "%s /* COISSUE! */);\n", src1_param.param_str);
2725 shader_addline(ins->ctx->buffer, "%s > 0.5 ? %s : %s);\n",
2731 dst_mask = ins->dst[0].write_mask;
2732 dst = ins->dst[0];
2737 if (((ins->src[0].swizzle >> (2 * j)) & 0x3) == i)
2745 write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst);
2748 shader_glsl_add_src_param(ins, &ins->src[0], cmp_channel, &src0_param);
2749 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2750 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2752 shader_addline(ins->ctx->buffer, "%s > 0.5 ? %s : %s);\n",
2758 static void shader_glsl_mad(const struct wined3d_shader_instruction *ins)
2765 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2766 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2767 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2768 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2769 shader_addline(ins->ctx->buffer, "(%s * %s) + %s);\n",
2775 static void shader_glsl_mnxn(const struct wined3d_shader_instruction *ins)
2786 tmp_ins.ctx = ins->ctx;
2792 switch(ins->handler_idx)
2818 tmp_dst = ins->dst[0];
2819 tmp_src[0] = ins->src[0];
2820 tmp_src[1] = ins->src[1];
2835 static void shader_glsl_lrp(const struct wined3d_shader_instruction *ins)
2842 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2844 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2845 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
2846 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
2848 shader_addline(ins->ctx->buffer, "mix(%s, %s, %s));\n",
2858 static void shader_glsl_lit(const struct wined3d_shader_instruction *ins)
2865 shader_glsl_append_dst(ins->ctx->buffer, ins);
2866 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
2868 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
2869 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_1, &src1_param);
2870 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &src3_param);
2893 shader_addline(ins->ctx->buffer,
2904 static void shader_glsl_dst(const struct wined3d_shader_instruction *ins)
2912 shader_glsl_append_dst(ins->ctx->buffer, ins);
2913 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
2915 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_1, &src0y_param);
2916 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &src0z_param);
2917 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_1, &src1y_param);
2918 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_3, &src1w_param);
2920 shader_addline(ins->ctx->buffer, "vec4(1.0, %s * %s, %s, %s))%s;\n",
2933 static void shader_glsl_sincos(const struct wined3d_shader_instruction *ins)
2938 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2939 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
2943 shader_addline(ins->ctx->buffer, "cos(%s));\n", src0_param.param_str);
2947 shader_addline(ins->ctx->buffer, "sin(%s));\n", src0_param.param_str);
2951 shader_addline(ins->ctx->buffer, "vec2(cos(%s), sin(%s)));\n", src0_param.param_str, src0_param.param_str);
2964 static void shader_glsl_sgn(const struct wined3d_shader_instruction *ins)
2969 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
2970 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
2972 shader_addline(ins->ctx->buffer, "sign(%s));\n", src0_param.param_str);
2981 static void shader_glsl_loop(const struct wined3d_shader_instruction *ins)
2984 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
2988 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_ALL, &src1_param);
2995 if (ins->src[1].reg.type == WINED3DSPR_CONSTINT)
2998 if (constant->idx == ins->src[1].reg.idx)
3015 shader_addline(ins->ctx->buffer, "for (aL%u = %u; aL%u < (%u * %d + %u); aL%u += %d) {\n",
3022 shader_addline(ins->ctx->buffer, "for (aL%u = %u; aL%u > (%u * %d + %u); aL%u += %d) {\n",
3029 shader_addline(ins->ctx->buffer, "for (aL%u = %u, tmpInt%u = 0; tmpInt%u < %u; tmpInt%u++) {\n",
3035 shader_addline(ins->ctx->buffer,
3046 static void shader_glsl_end(const struct wined3d_shader_instruction *ins)
3048 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3050 shader_addline(ins->ctx->buffer, "}\n");
3052 if (ins->handler_idx == WINED3DSIH_ENDLOOP)
3058 if (ins->handler_idx == WINED3DSIH_ENDREP)
3064 static void shader_glsl_rep(const struct wined3d_shader_instruction *ins)
3066 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3072 if (ins->src[0].reg.type == WINED3DSPR_CONSTINT)
3076 if (constant->idx == ins->src[0].reg.idx)
3085 shader_addline(ins->ctx->buffer, "for (tmpInt%d = 0; tmpInt%d < %d; tmpInt%d++) {\n",
3089 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
3090 shader_addline(ins->ctx->buffer, "for (tmpInt%d = 0; tmpInt%d < %s; tmpInt%d++) {\n",
3097 static void shader_glsl_if(const struct wined3d_shader_instruction *ins)
3101 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
3102 shader_addline(ins->ctx->buffer, "if (%s) {\n", src0_param.param_str);
3105 static void shader_glsl_ifc(const struct wined3d_shader_instruction *ins)
3110 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
3111 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
3113 shader_addline(ins->ctx->buffer, "if (%s %s %s) {\n",
3114 src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str);
3117 static void shader_glsl_else(const struct wined3d_shader_instruction *ins)
3119 shader_addline(ins->ctx->buffer, "} else {\n");
3122 static void shader_glsl_break(const struct wined3d_shader_instruction *ins)
3124 shader_addline(ins->ctx->buffer, "break;\n");
3128 static void shader_glsl_breakc(const struct wined3d_shader_instruction *ins)
3133 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
3134 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
3136 shader_addline(ins->ctx->buffer, "if (%s %s %s) break;\n",
3137 src0_param.param_str, shader_get_comp_op(ins->flags), src1_param.param_str);
3140 static void shader_glsl_label(const struct wined3d_shader_instruction *ins)
3142 shader_addline(ins->ctx->buffer, "}\n");
3143 shader_addline(ins->ctx->buffer, "void subroutine%u () {\n", ins->src[0].reg.idx);
3146 static void shader_glsl_call(const struct wined3d_shader_instruction *ins)
3148 shader_addline(ins->ctx->buffer, "subroutine%u();\n", ins->src[0].reg.idx);
3151 static void shader_glsl_callnz(const struct wined3d_shader_instruction *ins)
3155 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
3156 shader_addline(ins->ctx->buffer, "if (%s) subroutine%u();\n", src1_param.param_str, ins->src[0].reg.idx);
3159 static void shader_glsl_ret(const struct wined3d_shader_instruction *ins)
3169 static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
3171 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3173 DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
3174 ins->ctx->reg_maps->shader_version.minor);
3175 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3184 if (shader_version < WINED3D_SHADER_VERSION(2,0)) sampler_idx = ins->dst[0].reg.idx;
3185 else sampler_idx = ins->src[1].reg.idx;
3186 sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3190 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
3208 DWORD src_mod = ins->src[0].modifiers;
3218 if (ins->flags & WINED3DSI_TEXLD_PROJECT)
3235 else swizzle = ins->src[1].swizzle;
3243 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, NULL,
3247 shader_glsl_add_src_param(ins, &ins->src[0], mask, &coord_param);
3248 if (ins->flags & WINED3DSI_TEXLD_BIAS)
3251 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &bias);
3252 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
3255 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, NULL,
3261 static void shader_glsl_texldd(const struct wined3d_shader_instruction *ins)
3263 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3265 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3271 DWORD swizzle = ins->src[1].swizzle;
3276 shader_glsl_tex(ins);
3280 sampler_idx = ins->src[1].reg.idx;
3281 sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3288 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
3289 shader_glsl_add_src_param(ins, &ins->src[2], sample_function.coord_mask, &dx_param);
3290 shader_glsl_add_src_param(ins, &ins->src[3], sample_function.coord_mask, &dy_param);
3292 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, dx_param.param_str, dy_param.param_str, NULL,
3296 static void shader_glsl_texldl(const struct wined3d_shader_instruction *ins)
3298 IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3300 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3306 DWORD swizzle = ins->src[1].swizzle;
3308 sampler_idx = ins->src[1].reg.idx;
3309 sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3315 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
3317 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &lod_param);
3320 && shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
3326 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, lod_param.param_str,
3330 static void shader_glsl_texcoord(const struct wined3d_shader_instruction *ins)
3333 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3334 DWORD write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
3336 if (!(ins->ctx->reg_maps->shader_version.major == 1 && ins->ctx->reg_maps->shader_version.minor == 4))
3340 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
3342 ins->dst[0].reg.idx, dst_mask);
3344 DWORD reg = ins->src[0].reg.idx;
3345 DWORD src_mod = ins->src[0].modifiers;
3348 shader_glsl_get_swizzle(&ins->src[0], FALSE, write_mask, dst_swizzle);
3353 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &div_param);
3363 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &div_param);
3379 static void shader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins)
3381 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3384 DWORD sampler_idx = ins->dst[0].reg.idx;
3386 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3389 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3402 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3407 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3412 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3424 static void shader_glsl_texdp3(const struct wined3d_shader_instruction *ins)
3427 DWORD dstreg = ins->dst[0].reg.idx;
3432 dst_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
3434 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3437 shader_addline(ins->ctx->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str);
3439 shader_addline(ins->ctx->buffer, "dot(T%u.xyz, %s));\n", dstreg, src0_param.param_str);
3445 static void shader_glsl_texdepth(const struct wined3d_shader_instruction *ins)
3449 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
3457 shader_addline(ins->ctx->buffer, "gl_FragDepth = clamp((%s.x / min(%s.y, 1.0)), 0.0, 1.0);\n",
3466 static void shader_glsl_texm3x2depth(const struct wined3d_shader_instruction *ins)
3469 DWORD dstreg = ins->dst[0].reg.idx;
3472 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3474 shader_addline(ins->ctx->buffer, "tmp0.y = dot(T%u.xyz, %s);\n", dstreg, src0_param.param_str);
3475 shader_addline(ins->ctx->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n");
3480 static void shader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins)
3483 DWORD reg = ins->dst[0].reg.idx;
3484 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3487 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3493 static void shader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins)
3495 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3497 DWORD reg = ins->dst[0].reg.idx;
3498 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3502 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3507 static void shader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins)
3509 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3511 DWORD reg = ins->dst[0].reg.idx;
3512 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3514 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[reg];
3517 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3523 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xy");
3528 static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
3531 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3533 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3535 DWORD reg = ins->dst[0].reg.idx;
3536 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[reg];
3539 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3540 shader_addline(ins->ctx->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
3546 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
3553 static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins)
3556 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3560 DWORD reg = ins->dst[0].reg.idx;
3562 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3564 shader_glsl_append_dst(ins->ctx->buffer, ins);
3565 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
3566 shader_addline(ins->ctx->buffer, "vec4(tmp0.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask);
3573 static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins)
3575 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3576 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3577 DWORD reg = ins->dst[0].reg.idx;
3580 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3582 WINED3DSAMPLER_TEXTURE_TYPE stype = ins->ctx->reg_maps->sampler_type[reg];
3586 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3587 shader_glsl_add_src_param(ins, &ins->src[1], src_mask, &src1_param);
3598 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
3605 static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *ins)
3607 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3608 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3609 DWORD reg = ins->dst[0].reg.idx;
3610 struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
3614 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[reg];
3617 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
3631 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, "tmp0.xyz");
3640 static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins)
3642 IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
3644 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3645 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
3654 sampler_idx = ins->dst[0].reg.idx;
3658 sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3679 shader_addline(ins->ctx->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask);
3682 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &coord_param);
3684 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3688 if (ins->handler_idx == WINED3DSIH_TEXBEML)
3693 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &luminance_param);
3694 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
3696 shader_addline(ins->ctx->buffer, "%s%s *= (%s * luminancescale%d + luminanceoffset%d);\n",
3702 static void shader_glsl_bem(const struct wined3d_shader_instruction *ins)
3705 DWORD sampler_idx = ins->dst[0].reg.idx;
3707 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param);
3708 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param);
3710 shader_glsl_append_dst(ins->ctx->buffer, ins);
3711 shader_addline(ins->ctx->buffer, "%s + bumpenvmat%d * %s);\n",
3717 static void shader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins)
3719 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3721 DWORD sampler_idx = ins->dst[0].reg.idx;
3722 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3725 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
3728 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3734 static void shader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins)
3736 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3738 DWORD sampler_idx = ins->dst[0].reg.idx;
3739 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3742 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_ALL, &src0_param);
3745 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3751 static void shader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins)
3753 const struct wined3d_gl_info *gl_info = ins->ctx->gl_info;
3755 DWORD sampler_idx = ins->dst[0].reg.idx;
3756 WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
3761 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &src0_param);
3763 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
3769 static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins)
3774 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
3775 if (ins->ctx->reg_maps->shader_version.major >= 2)
3778 shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name);
3784 shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name);
3790 static void shader_glsl_dp2add(const struct wined3d_shader_instruction *ins)
3798 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
3801 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src0_param);
3802 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1, &src1_param);
3803 shader_glsl_add_src_param(ins, &ins->src[2], WINED3DSP_WRITEMASK_0, &src2_param);
3806 shader_addline(ins->ctx->buffer, "vec%d(dot(%s, %s) + %s));\n",
3809 shader_addline(ins->ctx->buffer, "dot(%s, %s) + %s);\n",
5451 static void shader_glsl_handle_instruction(const struct wined3d_shader_instruction *ins) {
5455 hw_fct = shader_glsl_instruction_handler_table[ins->handler_idx];
5460 FIXME("Backend can't handle opcode %#x\n", ins->handler_idx);
5463 hw_fct(ins);
5465 shader_glsl_add_instruction_modifiers(ins);