91 case ARB_ZERO:
return "ps_helper_const.x";
92 case ARB_ONE:
return "ps_helper_const.y";
93 case ARB_TWO:
return "coefmul.x";
94 case ARB_0001:
return "ps_helper_const.xxxy";
95 case ARB_EPS:
return "ps_helper_const.z";
103 case ARB_ZERO:
return "helper_const.x";
104 case ARB_ONE:
return "helper_const.y";
105 case ARB_TWO:
return "helper_const.z";
106 case ARB_EPS:
return "helper_const.w";
107 case ARB_0001:
return "helper_const.xxxy";
111 FIXME(
"Unmanaged %s shader helper constant requested: %u.\n",
118 case ARB_0001:
return "{0.0, 0.0, 0.0, 1.0}";
120 default:
return "bad";
126 return context->lowest_disabled_stage < 7;
338 if (reg_maps->
fog)
return TRUE;
345 unsigned int ret = 1;
365 unsigned int ret,
i,
j;
369 for (
i = 0;
i < max_constants; ++
i)
371 if (!dirty_consts[
i])
386 for (;
i <
min(8, max_constants); ++
i)
388 if (!dirty_consts[
i])
395 lcl_const[0] = -1.0f;
402 lcl_const[1] = -1.0f;
409 lcl_const[2] = -1.0f;
416 lcl_const[3] = -1.0f;
439 for (;
i < max_constants; ++
i)
441 if (!dirty_consts[
i])
447 for (++
i; (
i < max_constants) && dirty_consts[
i]; ++
i)
457 for (;
i < max_constants; ++
i)
469 if (
shader->load_local_constsF)
476 TRACE_(d3d_constants)(
"Loading local constants %i: %f, %f, %f, %f\n", lconst->
idx,
484 dirty_consts[lconst->
idx] = 1;
507 for (
i = 0; active; active >>= 1, ++
i)
511 GLfloat *tex_dim = &np2fixup_constants[(
idx >> 1) * 4];
518 ERR(
"Nonexistent texture is flagged for NP2 texcoord fixup.\n");
534 for (
i = 0;
i < fixup->
super.num_consts; ++
i)
537 fixup->
offset +
i, &np2fixup_constants[
i * 4]));
580 val[1] =
context->render_offscreen ? 1.0f : -1.0f;
610 float position_fixup[4];
647 BOOL usePixelShader,
BOOL useVertexShader,
BOOL from_shader_select)
652 if (!from_shader_select)
658 && (vshader->
reg_maps.boolean_constants
660 && (vshader->
reg_maps.integer_constants & ~vshader->
reg_maps.local_int_consts))))
662 TRACE(
"bool/integer vertex shader constants potentially modified, forcing shader reselection.\n");
666 && (pshader->
reg_maps.boolean_constants
668 && (pshader->
reg_maps.integer_constants & ~pshader->
reg_maps.local_int_consts))))
670 TRACE(
"bool/integer pixel shader constants potentially modified, forcing shader reselection.\n");
703 UINT rt_height =
state->fb->render_targets[0]->height;
772 unsigned max_constantsF;
787 max_constantsF = gl_info->
limits.arb_ps_native_constants;
789 if (max_constantsF < 24)
790 max_constantsF = gl_info->
limits.arb_ps_float_constants;
795 max_constantsF = gl_info->
limits.arb_vs_native_constants;
799 if (max_constantsF < 96)
800 max_constantsF = gl_info->
limits.arb_vs_float_constants;
804 DWORD highest_constf = 0, clip_limit;
810 for (
i = 0;
i <
shader->limits->constant_float; ++
i)
820 if(
ctx->cur_vs_args->super.clip_enabled)
821 clip_limit = gl_info->
limits.user_clip_distances;
827 unsigned int mask =
ctx->cur_vs_args->clip.boolclip.clipplane_mask;
830 *num_clipplanes =
min(clip_limit, max_constantsF - highest_constf - 1);
831 max_constantsF -= *num_clipplanes;
832 if(*num_clipplanes < clip_limit)
834 WARN(
"Only %u clip planes out of %u enabled.\n", *num_clipplanes,
835 gl_info->
limits.user_clip_distances);
840 if (
ctx->target_version >= NV2)
841 *num_clipplanes = gl_info->
limits.user_clip_distances;
843 *num_clipplanes =
min(gl_info->
limits.user_clip_distances, 4);
865 if (!
shader->load_local_constsF)
882 max_constantsF =
min(max_constantsF, gl_info->
limits.arb_ps_float_constants);
886 max_constantsF =
min(max_constantsF, gl_info->
limits.arb_vs_float_constants);
890 max_constantsF =
min(max_constantsF,
shader->limits->constant_float);
902 max_constantsF, max_constantsF - 1);
906 for (
i = 0;
i < max_constantsF; ++
i)
938 char *
ptr = write_mask;
957 const char *swizzle_chars = fixup ?
"zyxw" :
"xyzw";
958 char *
ptr = swizzle_str;
972 if (swizzle_x == swizzle_y && swizzle_x == swizzle_z && swizzle_x == swizzle_w) {
973 *
ptr++ = swizzle_chars[swizzle_x];
975 *
ptr++ = swizzle_chars[swizzle_x];
976 *
ptr++ = swizzle_chars[swizzle_y];
977 *
ptr++ = swizzle_chars[swizzle_z];
978 *
ptr++ = swizzle_chars[swizzle_w];
1003 static const char *
const rastout_reg_names[] = {
"TMP_OUT",
"TMP_FOGCOORD",
"result.pointsize"};
1014 sprintf(register_name,
"R%u",
reg->idx[0].offset);
1022 if (!
reg->idx[0].offset)
1023 strcpy(register_name,
"fragment.color.primary");
1025 strcpy(register_name,
"fragment.color.secondary");
1029 if (
reg->idx[0].rel_addr)
1043 ERR(
"Pixel shader input register out of bounds: %u\n",
idx);
1044 sprintf(register_name,
"out_of_bounds_%u",
idx);
1059 FIXME(
"Relative input register addressing with more than 8 registers\n");
1062 sprintf(register_name,
"fragment.texcoord[%s + %u]",
rel_reg,
reg->idx[0].offset);
1073 FIXME(
"Non-vertex shader varying input with indirect addressing\n");
1074 sprintf(register_name,
"fragment.texcoord[%s + %u]",
rel_reg,
reg->idx[0].offset);
1081 sprintf(register_name,
"fragment.texcoord[%s + %u]",
rel_reg,
reg->idx[0].offset);
1088 strcpy(register_name,
ctx->ps_input[
reg->idx[0].offset]);
1092 ERR(
"Pixel shader input register out of bounds: %u\n",
reg->idx[0].offset);
1093 sprintf(register_name,
"out_of_bounds_%u",
reg->idx[0].offset);
1100 if (
ctx->cur_vs_args->super.swizzle_map & (1u <<
reg->idx[0].offset))
1102 sprintf(register_name,
"vertex.attrib[%u]",
reg->idx[0].offset);
1107 if (!pshader &&
reg->idx[0].rel_addr)
1120 if (
ctx->target_version == ARB)
1132 sprintf(register_name,
"C[%u]",
ctx->aL +
reg->idx[0].offset);
1141 sprintf(register_name,
"C[%u]",
reg->idx[0].offset);
1143 sprintf(register_name,
"C%u",
reg->idx[0].offset);
1156 sprintf(register_name,
"T%u",
reg->idx[0].offset);
1159 sprintf(register_name,
"fragment.texcoord[%u]",
reg->idx[0].offset);
1164 sprintf(register_name,
"A%u",
reg->idx[0].offset);
1166 sprintf(register_name,
"A%u_SHADOW",
reg->idx[0].offset);
1171 if (
ctx->ps_post_process && !
reg->idx[0].offset)
1173 strcpy(register_name,
"TMP_COLOR");
1177 if (
ctx->cur_ps_args->super.srgb_correction)
1178 FIXME(
"sRGB correction on higher render targets.\n");
1180 sprintf(register_name,
"result.color[%u]",
reg->idx[0].offset);
1182 strcpy(register_name,
"result.color");
1187 if (
reg->idx[0].offset == 1)
1188 sprintf(register_name,
"%s",
ctx->fog_output);
1190 sprintf(register_name,
"%s", rastout_reg_names[
reg->idx[0].offset]);
1194 strcpy(register_name,
"result.depth");
1200 sprintf(register_name,
"oD[%u]",
reg->idx[0].offset);
1202 strcpy(register_name,
ctx->color_output[
reg->idx[0].offset]);
1207 sprintf(register_name,
"oT[%u]",
reg->idx[0].offset);
1209 strcpy(register_name,
ctx->texcrd_output[
reg->idx[0].offset]);
1211 strcpy(register_name,
ctx->vs_output[
reg->idx[0].offset]);
1215 if(
ctx->target_version >= NV2)
1218 if(pshader)
sprintf(register_name,
"A0.x");
1219 else sprintf(register_name,
"aL.y");
1229 sprintf(register_name,
"**aL_emul**");
1235 sprintf(register_name,
"I%u",
reg->idx[0].offset);
1239 if (!
reg->idx[0].offset)
1240 sprintf(register_name,
"vpos");
1241 else if (
reg->idx[0].offset == 1)
1242 sprintf(register_name,
"fragment.facing.x");
1244 FIXME(
"Unknown MISCTYPE register index %u.\n",
reg->idx[0].offset);
1248 FIXME(
"Unhandled register type %#x[%u].\n",
reg->type,
reg->idx[0].offset);
1249 sprintf(register_name,
"unrecognized_register[%u]",
reg->idx[0].offset);
1257 char register_name[255];
1270 switch(channel_source)
1279 FIXME(
"Unhandled channel source %#x\n", channel_source);
1309 masks.source &= dst_mask;
1311 if (fixup.x_sign_fixup)
1313 if (fixup.y_sign_fixup)
1315 if (fixup.z_sign_fixup)
1317 if (fixup.w_sign_fixup)
1319 masks.sign &= dst_mask;
1325 const char *
src,
const char *
one,
const char *
two,
1328 const char *sign_fixup_src =
dst;
1333 sign_fixup_src =
"TA";
1339 else if (
masks.sign)
1341 sign_fixup_src =
src;
1347 char *
ptr = reg_mask;
1373 mod = ins->
dst[0].modifiers;
1380 FIXME(
"Unhandled modifier WINED3DSPDM_MSAMPCENTROID\n");
1381 mod &= ~WINED3DSPDM_MSAMPCENTROID;
1399 FIXME(
"Unknown modifiers 0x%08x\n",
mod);
1407#define TEX_DERIV 0x10
1410 const char *dst_str,
const char *coord_reg,
WORD flags,
const char *dsx,
const char *dsy)
1422 const char *tex_dst = dst_str;
1428 switch (resource_type)
1437 gl_info = &
device->adapter->gl_info;
1439 if (pshader && priv->
cur_ps_args->super.np2_fixup & (1u << sampler_idx)
1448 if (
flags)
FIXME(
"Only ordinary sampling from NP2 textures is supported.\n");
1449 else np2_fixup =
TRUE;
1463 ERR(
"Unexpected resource type %#x.\n", resource_type);
1482 ins->
dst[0].write_mask);
1492 shader_addline(
buffer,
"TXD%s %s, %s, %s, %s, texture[%u], %s;\n",
mod, tex_dst, coord_reg,
1519 (
idx % 2) ?
"zwxy" :
"xyzw", coord_reg);
1555 switch (
src->modifiers)
1558 sprintf(outregstr,
"%s%s", regstr, swzstr);
1559 insert_line =
FALSE;
1562 sprintf(outregstr,
"-%s%s", regstr, swzstr);
1563 insert_line =
FALSE;
1595 if(
ctx->target_version >=
NV2) {
1596 sprintf(outregstr,
"|%s%s|", regstr, swzstr);
1597 insert_line =
FALSE;
1603 if(
ctx->target_version >=
NV2) {
1604 sprintf(outregstr,
"-|%s%s|", regstr, swzstr);
1607 sprintf(outregstr,
"-T%c%s",
'A' + tmpreg, swzstr);
1609 insert_line =
FALSE;
1612 sprintf(outregstr,
"%s%s", regstr, swzstr);
1613 insert_line =
FALSE;
1618 sprintf(outregstr,
"T%c%s",
'A' + tmpreg, swzstr);
1625 DWORD sampler_code =
dst->reg.idx[0].offset;
1627 char src_name[2][50];
1666 FIXME(
"Unknown modifier %u\n",
mod);
1675 char src_name[3][50];
1677 ins->
ctx->reg_maps->shader_version.minor);
1699 dst_name, src_name[1], src_name[2]);
1708 char src_name[3][50];
1718 dst_name, src_name[0], src_name[2], src_name[1]);
1728 char src_name[3][50];
1735 if(
ctx->target_version >=
NV3)
1740 dst_name, src_name[0], src_name[1], src_name[2]);
1742 else if(
ctx->target_version >=
NV2)
1761 dst_name, src_name[2], src_name[0], src_name[1]);
1781 char arguments[256], dst_str[50];
1812 arguments[0] =
'\0';
1819 strcat(arguments, operand);
1828 return ((
swizzle >> 2 * component) & 0x3) * 0x55;
1842 char src0_param[256];
1850 if(
ctx->target_version >= NV2) {
1886 src0_param[0] =
'\0';
1908 if (
ctx->ps_post_process &&
shader->u.ps.color0_mov)
1932 if (ins->
ctx->reg_maps->shader_version.major >= 2)
1934 const char *kilsrc =
"TA";
1948 char x =
'0',
y =
'0',
z =
'0',
w =
'0';
1953 shader_addline(
buffer,
"SWZ TA, %s, %c, %c, %c, %c;\n", reg_dest,
x,
y,
z,
w);
1965 if (ins->
ctx->reg_maps->shader_version.minor <= 3)
1966 sprintf(reg_dest,
"fragment.texcoord[%u]",
dst->reg.idx[0].offset);
1979 ins->
ctx->reg_maps->shader_version.minor);
1984 DWORD reg_sampler_code;
1994 reg_sampler_code =
dst->reg.idx[0].offset;
1996 reg_sampler_code = ins->
src[1].reg.idx[0].offset;
2001 sprintf(reg_coord,
"fragment.texcoord[%u]", reg_sampler_code);
2024 swizzle_coord =
TRUE;
2032 swizzle_coord =
TRUE;
2058 ins->
ctx->reg_maps->shader_version.minor);
2081 DWORD reg1 = ins->
dst[0].reg.idx[0].offset;
2103 DWORD reg1 = ins->
dst[0].reg.idx[0].offset;
2117 DWORD reg1 = ins->
dst[0].reg.idx[0].offset;
2132 char reg_coord[40], dst_reg[50], src_reg[50];
2133 DWORD reg_dest_code;
2138 reg_dest_code =
dst->reg.idx[0].offset;
2141 sprintf(reg_coord,
"fragment.texcoord[%u]", reg_dest_code);
2177 src_reg, reg_dest_code, reg_dest_code);
2186 char src0_name[50], dst_name[50];
2194 tmp_reg.
idx[0].offset =
reg + 1;
2225 char src0_name[50], dst_name[50];
2250 char src0_name[50], dst_name[50];
2382 DWORD sampler_idx = ins->
dst[0].reg.idx[0].offset;
2415 char dst_str[50], dst_name[50];
2435 char src0[50], dst_name[50];
2459 int nComponents = 0;
2464 memset(&tmp_ins, 0,
sizeof(tmp_ins));
2469 tmp_ins.
dst = &tmp_dst;
2471 tmp_ins.
src = tmp_src;
2500 tmp_dst = ins->
dst[0];
2501 tmp_src[0] = ins->
src[0];
2502 tmp_src[1] = ins->
src[1];
2503 for (
i = 0;
i < nComponents; ++
i)
2507 ++tmp_src[1].
reg.idx[0].offset;
2531 FIXME(
"Unknown modifier %u\n",
mod);
2550 if (ins->
ctx->reg_maps->shader_version.major < 2)
2644 char src_name[3][50];
2659 dst_name, src_name[0], src_name[2]);
2672 char src_name0[50], src_name1[50], src_name2[50];
2780 if(
ctx->target_version >=
NV2) {
2797 if(
strstr(src_name,
"TA"))
2831 char src0[50], src1[50],
dst[50];
2978 ERR(
"Could not find loop for break\n");
3009 FIXME(
"Unrecognized operator %#x.\n",
op);
3025 FIXME(
"Unrecognized operator %#x.\n",
op);
3134 DWORD sampler_idx = ins->
src[1].reg.idx[0].offset;
3136 char reg_src[3][40];
3152 DWORD sampler_idx = ins->
src[1].reg.idx[0].offset;
3217 if (
args->super.clip_enabled)
3225 else if (
args->clip.boolclip.clip_texcoord)
3227 static const char component[4] = {
'x',
'y',
'z',
'w'};
3228 unsigned int cur_clip = 0;
3231 for (
i = 0;
i < gl_info->
limits.user_clip_distances; ++
i)
3233 if (
args->clip.boolclip.clipplane_mask & (1u <<
i))
3236 component[cur_clip++],
i);
3255 args->clip.boolclip.clip_texcoord - 1);
3333 FIXME_(d3d_shader)(
"Program error at position %d: %s\n\n",
pos,
3337 FIXME_(d3d_shader)(
"\n");
3348 WARN_(d3d_perf)(
"Program exceeds native resource limits.\n");
3355 const char *tmp1,
const char *tmp2,
const char *tmp3,
const char *tmp4,
BOOL condcode)
3415 static const char *
const texcoords[8] =
3417 "fragment.texcoord[0]",
"fragment.texcoord[1]",
"fragment.texcoord[2]",
"fragment.texcoord[3]",
3418 "fragment.texcoord[4]",
"fragment.texcoord[5]",
"fragment.texcoord[6]",
"fragment.texcoord[7]"
3425 switch(
args->super.vp_mode)
3437 for (
i = 0;
i <
shader->input_signature.element_count; ++
i)
3447 priv->
ps_input[
input->register_idx] =
"fragment.color.primary";
3449 priv->
ps_input[
input->register_idx] =
"fragment.color.secondary";
3476 TRACE(
"v%u, semantic %s%u is %s\n",
input->register_idx,
3485 for(
i = 0;
i < 8;
i++)
3489 priv->
ps_input[8] =
"fragment.color.primary";
3490 priv->
ps_input[9] =
"fragment.color.secondary";
3496 const char *fragcolor,
const char *tmp)
3511 DWORD next_local = 0;
3521 unsigned int i, found = 0;
3526 || (
shader->u.ps.color0_mov &&
i ==
shader->u.ps.color0_reg)
3532 if (found == 4)
break;
3560 memset(&priv_ctx, 0,
sizeof(priv_ctx));
3582 want_nv_prog =
TRUE;
3601 ERR(
"The shader requires instructions that are not available in plain GL_ARB_fragment_program\n");
3614 switch (
args->super.fog)
3621 custom_linear_fog =
TRUE;
3657 if (
shader->u.ps.color0_mov)
3664 strcpy(fragcolor,
"TMP_COLOR");
3667 strcpy(fragcolor,
"result.color");
3671 if (
args->super.srgb_correction)
3686 unsigned char bump_const;
3688 if (!(
map & 1))
continue;
3728 control_values[0], control_values[1], control_values[2]);