2 * Fixed function pipeline replacement using GL_ATI_fragment_shader
4 * Copyright 2008 Stefan Dösinger(for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
30 WINE_DECLARE_DEBUG_CHANNEL(d3d);
32 /* GL locking for state handlers is done by the caller. */
34 /* Some private defines, Constant associations, etc.
35 * Env bump matrix and per stage constant should be independent,
36 * a stage that bump maps can't read the per state constant
38 #define ATI_FFP_CONST_BUMPMAT(i) (GL_CON_0_ATI + i)
39 #define ATI_FFP_CONST_CONSTANT0 GL_CON_0_ATI
40 #define ATI_FFP_CONST_CONSTANT1 GL_CON_1_ATI
41 #define ATI_FFP_CONST_CONSTANT2 GL_CON_2_ATI
42 #define ATI_FFP_CONST_CONSTANT3 GL_CON_3_ATI
43 #define ATI_FFP_CONST_CONSTANT4 GL_CON_4_ATI
44 #define ATI_FFP_CONST_CONSTANT5 GL_CON_5_ATI
45 #define ATI_FFP_CONST_TFACTOR GL_CON_6_ATI
47 /* GL_ATI_fragment_shader specific fixed function pipeline description. "Inherits" from the common one */
50 struct ffp_frag_desc parent;
52 unsigned int num_textures_used;
55 struct atifs_private_data
57 struct wine_rb_tree fragment_shaders; /* A rb-tree to track fragment pipeline replacement shaders */
60 static const char *debug_dstmod(GLuint mod) {
62 case GL_NONE: return "GL_NONE";
63 case GL_2X_BIT_ATI: return "GL_2X_BIT_ATI";
64 case GL_4X_BIT_ATI: return "GL_4X_BIT_ATI";
65 case GL_8X_BIT_ATI: return "GL_8X_BIT_ATI";
66 case GL_HALF_BIT_ATI: return "GL_HALF_BIT_ATI";
67 case GL_QUARTER_BIT_ATI: return "GL_QUARTER_BIT_ATI";
68 case GL_EIGHTH_BIT_ATI: return "GL_EIGHTH_BIT_ATI";
69 case GL_SATURATE_BIT_ATI: return "GL_SATURATE_BIT_ATI";
70 default: return "Unexpected modifier\n";
74 static const char *debug_argmod(GLuint mod) {
80 return "GL_2X_BIT_ATI";
82 return "GL_COMP_BIT_ATI";
83 case GL_NEGATE_BIT_ATI:
84 return "GL_NEGATE_BIT_ATI";
86 return "GL_BIAS_BIT_ATI";
88 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI:
89 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI";
90 case GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI:
91 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI";
92 case GL_2X_BIT_ATI | GL_BIAS_BIT_ATI:
93 return "GL_2X_BIT_ATI | GL_BIAS_BIT_ATI";
94 case GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI:
95 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
96 case GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI:
97 return "GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
98 case GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
99 return "GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
101 case GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
102 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
103 case GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
104 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
105 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI:
106 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
107 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI:
108 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
110 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
111 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
114 return "Unexpected argmod combination\n";
117 static const char *debug_register(GLuint reg) {
119 case GL_REG_0_ATI: return "GL_REG_0_ATI";
120 case GL_REG_1_ATI: return "GL_REG_1_ATI";
121 case GL_REG_2_ATI: return "GL_REG_2_ATI";
122 case GL_REG_3_ATI: return "GL_REG_3_ATI";
123 case GL_REG_4_ATI: return "GL_REG_4_ATI";
124 case GL_REG_5_ATI: return "GL_REG_5_ATI";
126 case GL_CON_0_ATI: return "GL_CON_0_ATI";
127 case GL_CON_1_ATI: return "GL_CON_1_ATI";
128 case GL_CON_2_ATI: return "GL_CON_2_ATI";
129 case GL_CON_3_ATI: return "GL_CON_3_ATI";
130 case GL_CON_4_ATI: return "GL_CON_4_ATI";
131 case GL_CON_5_ATI: return "GL_CON_5_ATI";
132 case GL_CON_6_ATI: return "GL_CON_6_ATI";
133 case GL_CON_7_ATI: return "GL_CON_7_ATI";
135 case GL_ZERO: return "GL_ZERO";
136 case GL_ONE: return "GL_ONE";
137 case GL_PRIMARY_COLOR: return "GL_PRIMARY_COLOR";
138 case GL_SECONDARY_INTERPOLATOR_ATI: return "GL_SECONDARY_INTERPOLATOR_ATI";
140 default: return "Unknown register\n";
144 static const char *debug_swizzle(GLuint swizzle) {
146 case GL_SWIZZLE_STR_ATI: return "GL_SWIZZLE_STR_ATI";
147 case GL_SWIZZLE_STQ_ATI: return "GL_SWIZZLE_STQ_ATI";
148 case GL_SWIZZLE_STR_DR_ATI: return "GL_SWIZZLE_STR_DR_ATI";
149 case GL_SWIZZLE_STQ_DQ_ATI: return "GL_SWIZZLE_STQ_DQ_ATI";
150 default: return "unknown swizzle";
154 static const char *debug_rep(GLuint rep) {
156 case GL_NONE: return "GL_NONE";
157 case GL_RED: return "GL_RED";
158 case GL_GREEN: return "GL_GREEN";
159 case GL_BLUE: return "GL_BLUE";
160 default: return "unknown argrep";
164 static const char *debug_op(GLuint op) {
166 case GL_MOV_ATI: return "GL_MOV_ATI";
167 case GL_ADD_ATI: return "GL_ADD_ATI";
168 case GL_MUL_ATI: return "GL_MUL_ATI";
169 case GL_SUB_ATI: return "GL_SUB_ATI";
170 case GL_DOT3_ATI: return "GL_DOT3_ATI";
171 case GL_DOT4_ATI: return "GL_DOT4_ATI";
172 case GL_MAD_ATI: return "GL_MAD_ATI";
173 case GL_LERP_ATI: return "GL_LERP_ATI";
174 case GL_CND_ATI: return "GL_CND_ATI";
175 case GL_CND0_ATI: return "GL_CND0_ATI";
176 case GL_DOT2_ADD_ATI: return "GL_DOT2_ADD_ATI";
177 default: return "unexpected op";
181 static const char *debug_mask(GLuint mask) {
183 case GL_NONE: return "GL_NONE";
184 case GL_RED_BIT_ATI: return "GL_RED_BIT_ATI";
185 case GL_GREEN_BIT_ATI: return "GL_GREEN_BIT_ATI";
186 case GL_BLUE_BIT_ATI: return "GL_BLUE_BIT_ATI";
187 case GL_RED_BIT_ATI | GL_GREEN_BIT_ATI: return "GL_RED_BIT_ATI | GL_GREEN_BIT_ATI";
188 case GL_RED_BIT_ATI | GL_BLUE_BIT_ATI: return "GL_RED_BIT_ATI | GL_BLUE_BIT_ATI";
189 case GL_GREEN_BIT_ATI | GL_BLUE_BIT_ATI:return "GL_GREEN_BIT_ATI | GL_BLUE_BIT_ATI";
190 case GL_RED_BIT_ATI | GL_GREEN_BIT_ATI | GL_BLUE_BIT_ATI:return "GL_RED_BIT_ATI | GL_GREEN_BIT_ATI | GL_BLUE_BIT_ATI";
191 default: return "Unexpected writemask";
195 static void wrap_op1(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
196 GLuint arg1, GLuint arg1Rep, GLuint arg1Mod)
198 if(dstMask == GL_ALPHA) {
199 TRACE("glAlphaFragmentOp1ATI(%s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst), debug_dstmod(dstMod),
200 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod));
201 GL_EXTCALL(glAlphaFragmentOp1ATI(op, dst, dstMod, arg1, arg1Rep, arg1Mod));
203 TRACE("glColorFragmentOp1ATI(%s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst),
204 debug_mask(dstMask), debug_dstmod(dstMod),
205 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod));
206 GL_EXTCALL(glColorFragmentOp1ATI(op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod));
210 static void wrap_op2(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
211 GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod)
213 if(dstMask == GL_ALPHA) {
214 TRACE("glAlphaFragmentOp2ATI(%s, %s, %s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst), debug_dstmod(dstMod),
215 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod),
216 debug_register(arg2), debug_rep(arg2Rep), debug_argmod(arg2Mod));
217 GL_EXTCALL(glAlphaFragmentOp2ATI(op, dst, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod));
219 TRACE("glColorFragmentOp2ATI(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst),
220 debug_mask(dstMask), debug_dstmod(dstMod),
221 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod),
222 debug_register(arg2), debug_rep(arg2Rep), debug_argmod(arg2Mod));
223 GL_EXTCALL(glColorFragmentOp2ATI(op, dst, dstMask, dstMod, arg1, arg1Rep, arg1Mod, arg2, arg2Rep, arg2Mod));
227 static void wrap_op3(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
228 GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod,
229 GLuint arg3, GLuint arg3Rep, GLuint arg3Mod)
231 if(dstMask == GL_ALPHA) {
232 /* Leave some free space to fit "GL_NONE, " in to align most alpha and color op lines */
233 TRACE("glAlphaFragmentOp3ATI(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst), debug_dstmod(dstMod),
234 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod),
235 debug_register(arg2), debug_rep(arg2Rep), debug_argmod(arg2Mod),
236 debug_register(arg3), debug_rep(arg3Rep), debug_argmod(arg3Mod));
237 GL_EXTCALL(glAlphaFragmentOp3ATI(op, dst, dstMod,
238 arg1, arg1Rep, arg1Mod,
239 arg2, arg2Rep, arg2Mod,
240 arg3, arg3Rep, arg3Mod));
242 TRACE("glColorFragmentOp3ATI(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst),
243 debug_mask(dstMask), debug_dstmod(dstMod),
244 debug_register(arg1), debug_rep(arg1Rep), debug_argmod(arg1Mod),
245 debug_register(arg2), debug_rep(arg2Rep), debug_argmod(arg2Mod),
246 debug_register(arg3), debug_rep(arg3Rep), debug_argmod(arg3Mod));
247 GL_EXTCALL(glColorFragmentOp3ATI(op, dst, dstMask, dstMod,
248 arg1, arg1Rep, arg1Mod,
249 arg2, arg2Rep, arg2Mod,
250 arg3, arg3Rep, arg3Mod));
254 static GLuint register_for_arg(DWORD arg, const struct wined3d_gl_info *gl_info,
255 unsigned int stage, GLuint *mod, GLuint *rep, GLuint tmparg)
259 if(mod) *mod = GL_NONE;
260 if(arg == ARG_UNUSED)
262 if (rep) *rep = GL_NONE;
263 return -1; /* This is the marker for unused registers */
266 switch(arg & WINED3DTA_SELECTMASK) {
267 case WINED3DTA_DIFFUSE:
268 ret = GL_PRIMARY_COLOR;
271 case WINED3DTA_CURRENT:
272 /* Note that using GL_REG_0_ATI for the passed on register is safe because
273 * texture0 is read at stage0, so in the worst case it is read in the
274 * instruction writing to reg0. Afterwards texture0 is not used any longer.
275 * If we're reading from current
277 ret = stage ? GL_REG_0_ATI : GL_PRIMARY_COLOR;
280 case WINED3DTA_TEXTURE:
281 ret = GL_REG_0_ATI + stage;
284 case WINED3DTA_TFACTOR:
285 ret = ATI_FFP_CONST_TFACTOR;
288 case WINED3DTA_SPECULAR:
289 ret = GL_SECONDARY_INTERPOLATOR_ATI;
296 case WINED3DTA_CONSTANT:
297 FIXME("Unhandled source argument WINED3DTA_TEMP\n");
302 FIXME("Unknown source argument %d\n", arg);
306 if(arg & WINED3DTA_COMPLEMENT) {
307 if(mod) *mod |= GL_COMP_BIT_ATI;
309 if(arg & WINED3DTA_ALPHAREPLICATE) {
310 if(rep) *rep = GL_ALPHA;
312 if(rep) *rep = GL_NONE;
317 static GLuint find_tmpreg(const struct texture_stage_op op[MAX_TEXTURES])
319 int lowest_read = -1;
320 int lowest_write = -1;
322 BOOL tex_used[MAX_TEXTURES];
324 memset(tex_used, 0, sizeof(tex_used));
325 for (i = 0; i < MAX_TEXTURES; ++i)
327 if (op[i].cop == WINED3D_TOP_DISABLE)
330 if(lowest_read == -1 &&
331 (op[i].carg1 == WINED3DTA_TEMP || op[i].carg2 == WINED3DTA_TEMP || op[i].carg0 == WINED3DTA_TEMP ||
332 op[i].aarg1 == WINED3DTA_TEMP || op[i].aarg2 == WINED3DTA_TEMP || op[i].aarg0 == WINED3DTA_TEMP)) {
336 if(lowest_write == -1 && op[i].dst == tempreg) {
340 if(op[i].carg1 == WINED3DTA_TEXTURE || op[i].carg2 == WINED3DTA_TEXTURE || op[i].carg0 == WINED3DTA_TEXTURE ||
341 op[i].aarg1 == WINED3DTA_TEXTURE || op[i].aarg2 == WINED3DTA_TEXTURE || op[i].aarg0 == WINED3DTA_TEXTURE) {
346 /* Temp reg not read? We don't need it, return GL_NONE */
347 if(lowest_read == -1) return GL_NONE;
349 if(lowest_write >= lowest_read) {
350 FIXME("Temp register read before being written\n");
353 if(lowest_write == -1) {
354 /* This needs a test. Maybe we are supposed to return 0.0/0.0/0.0/0.0, or fail drawprim, or whatever */
355 FIXME("Temp register read without being written\n");
357 } else if(lowest_write >= 1) {
358 /* If we're writing to the temp reg at earliest in stage 1, we can use register 1 for the temp result.
359 * there may be texture data stored in reg 1, but we do not need it any longer since stage 1 already
364 /* Search for a free texture register. We have 6 registers available. GL_REG_0_ATI is already used
365 * for the regular result
367 for(i = 1; i < 6; i++) {
369 return GL_REG_0_ATI + i;
372 /* What to do here? Report it in ValidateDevice? */
373 FIXME("Could not find a register for the temporary register\n");
378 static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], const struct wined3d_gl_info *gl_info)
380 GLuint ret = GL_EXTCALL(glGenFragmentShadersATI(1));
382 GLuint arg0, arg1, arg2, extrarg;
383 GLuint dstmod, argmod0, argmod1, argmod2, argmodextra;
384 GLuint rep0, rep1, rep2;
386 GLuint tmparg = find_tmpreg(op);
390 ERR("Failed to generate a GL_ATI_fragment_shader shader id\n");
393 GL_EXTCALL(glBindFragmentShaderATI(ret));
394 checkGLcall("GL_EXTCALL(glBindFragmentShaderATI(ret))");
396 TRACE("glBeginFragmentShaderATI()\n");
397 GL_EXTCALL(glBeginFragmentShaderATI());
398 checkGLcall("GL_EXTCALL(glBeginFragmentShaderATI())");
400 /* Pass 1: Generate sampling instructions for perturbation maps */
401 for (stage = 0; stage < gl_info->limits.textures; ++stage)
403 if (op[stage].cop == WINED3D_TOP_DISABLE)
405 if (op[stage].cop != WINED3D_TOP_BUMPENVMAP
406 && op[stage].cop != WINED3D_TOP_BUMPENVMAP_LUMINANCE)
409 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
411 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
412 GL_TEXTURE0_ARB + stage,
413 GL_SWIZZLE_STR_ATI));
414 if(op[stage + 1].projected == proj_none) {
415 swizzle = GL_SWIZZLE_STR_ATI;
416 } else if(op[stage + 1].projected == proj_count4) {
417 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
419 swizzle = GL_SWIZZLE_STR_DR_ATI;
421 TRACE("glPassTexCoordATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
422 stage + 1, stage + 1, debug_swizzle(swizzle));
423 GL_EXTCALL(glPassTexCoordATI(GL_REG_0_ATI + stage + 1,
424 GL_TEXTURE0_ARB + stage + 1,
428 /* Pass 2: Generate perturbation calculations */
429 for (stage = 0; stage < gl_info->limits.textures; ++stage)
431 GLuint argmodextra_x, argmodextra_y;
432 struct color_fixup_desc fixup;
434 if (op[stage].cop == WINED3D_TOP_DISABLE)
436 if (op[stage].cop != WINED3D_TOP_BUMPENVMAP
437 && op[stage].cop != WINED3D_TOP_BUMPENVMAP_LUMINANCE)
440 fixup = op[stage].color_fixup;
441 if (fixup.x_source != CHANNEL_SOURCE_X || fixup.y_source != CHANNEL_SOURCE_Y)
443 FIXME("Swizzles not implemented\n");
444 argmodextra_x = GL_NONE;
445 argmodextra_y = GL_NONE;
449 /* Nice thing, we get the color correction for free :-) */
450 argmodextra_x = fixup.x_sign_fixup ? GL_2X_BIT_ATI | GL_BIAS_BIT_ATI : GL_NONE;
451 argmodextra_y = fixup.y_sign_fixup ? GL_2X_BIT_ATI | GL_BIAS_BIT_ATI : GL_NONE;
454 wrap_op3(gl_info, GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_RED_BIT_ATI, GL_NONE,
455 GL_REG_0_ATI + stage, GL_NONE, argmodextra_x,
456 ATI_FFP_CONST_BUMPMAT(stage), GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
457 GL_REG_0_ATI + stage + 1, GL_RED, GL_NONE);
459 /* Don't use GL_DOT2_ADD_ATI here because we cannot configure it to read the blue and alpha
460 * component of the bump matrix. Instead do this with two MADs:
462 * coord.a = tex.r * bump.b + coord.g
463 * coord.g = tex.g * bump.a + coord.a
465 * The first instruction writes to alpha so it can be coissued with the above DOT2_ADD.
466 * coord.a is unused. If the perturbed texture is projected, this was already handled
467 * in the glPassTexCoordATI above.
469 wrap_op3(gl_info, GL_MAD_ATI, GL_REG_0_ATI + stage + 1, GL_ALPHA, GL_NONE,
470 GL_REG_0_ATI + stage, GL_RED, argmodextra_y,
471 ATI_FFP_CONST_BUMPMAT(stage), GL_BLUE, GL_NONE,
472 GL_REG_0_ATI + stage + 1, GL_GREEN, GL_NONE);
473 wrap_op3(gl_info, GL_MAD_ATI, GL_REG_0_ATI + stage + 1, GL_GREEN_BIT_ATI, GL_NONE,
474 GL_REG_0_ATI + stage, GL_GREEN, argmodextra_y,
475 ATI_FFP_CONST_BUMPMAT(stage), GL_ALPHA, GL_NONE,
476 GL_REG_0_ATI + stage + 1, GL_ALPHA, GL_NONE);
479 /* Pass 3: Generate sampling instructions for regular textures */
480 for (stage = 0; stage < gl_info->limits.textures; ++stage)
482 if (op[stage].cop == WINED3D_TOP_DISABLE)
485 if(op[stage].projected == proj_none) {
486 swizzle = GL_SWIZZLE_STR_ATI;
487 } else if(op[stage].projected == proj_count3) {
488 swizzle = GL_SWIZZLE_STR_DR_ATI;
490 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
493 if ((op[stage].carg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
494 || (op[stage].carg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
495 || (op[stage].carg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
496 || (op[stage].aarg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
497 || (op[stage].aarg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
498 || (op[stage].aarg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
499 || op[stage].cop == WINED3D_TOP_BLEND_TEXTURE_ALPHA)
502 && (op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP
503 || op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE))
505 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_REG_%d_ATI, GL_SWIZZLE_STR_ATI)\n",
507 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
508 GL_REG_0_ATI + stage,
509 GL_SWIZZLE_STR_ATI));
511 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
512 stage, stage, debug_swizzle(swizzle));
513 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
514 GL_TEXTURE0_ARB + stage,
520 /* Pass 4: Generate the arithmetic instructions */
521 for (stage = 0; stage < MAX_TEXTURES; ++stage)
523 if (op[stage].cop == WINED3D_TOP_DISABLE)
527 /* Handle complete texture disabling gracefully */
528 wrap_op1(gl_info, GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
529 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
530 wrap_op1(gl_info, GL_MOV_ATI, GL_REG_0_ATI, GL_ALPHA, GL_NONE,
531 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
536 if(op[stage].dst == tempreg) {
537 /* If we're writing to D3DTA_TEMP, but never reading from it we don't have to write there in the first place.
538 * skip the entire stage, this saves some GPU time
540 if(tmparg == GL_NONE) continue;
544 dstreg = GL_REG_0_ATI;
547 arg0 = register_for_arg(op[stage].carg0, gl_info, stage, &argmod0, &rep0, tmparg);
548 arg1 = register_for_arg(op[stage].carg1, gl_info, stage, &argmod1, &rep1, tmparg);
549 arg2 = register_for_arg(op[stage].carg2, gl_info, stage, &argmod2, &rep2, tmparg);
551 argmodextra = GL_NONE;
554 switch (op[stage].cop)
556 case WINED3D_TOP_SELECT_ARG2:
561 case WINED3D_TOP_SELECT_ARG1:
562 wrap_op1(gl_info, GL_MOV_ATI, dstreg, GL_NONE, GL_NONE,
563 arg1, rep1, argmod1);
566 case WINED3D_TOP_MODULATE_4X:
567 if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI;
569 case WINED3D_TOP_MODULATE_2X:
570 if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI;
571 dstmod |= GL_SATURATE_BIT_ATI;
573 case WINED3D_TOP_MODULATE:
574 wrap_op2(gl_info, GL_MUL_ATI, dstreg, GL_NONE, dstmod,
576 arg2, rep2, argmod2);
579 case WINED3D_TOP_ADD_SIGNED_2X:
580 dstmod = GL_2X_BIT_ATI;
582 case WINED3D_TOP_ADD_SIGNED:
583 argmodextra = GL_BIAS_BIT_ATI;
585 case WINED3D_TOP_ADD:
586 dstmod |= GL_SATURATE_BIT_ATI;
587 wrap_op2(gl_info, GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, dstmod,
589 arg2, rep2, argmodextra | argmod2);
592 case WINED3D_TOP_SUBTRACT:
593 dstmod |= GL_SATURATE_BIT_ATI;
594 wrap_op2(gl_info, GL_SUB_ATI, dstreg, GL_NONE, dstmod,
596 arg2, rep2, argmod2);
599 case WINED3D_TOP_ADD_SMOOTH:
600 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
601 /* Dst = arg1 + * arg2(1 -arg 1)
602 * = arg2 * (1 - arg1) + arg1
604 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
606 arg1, rep1, argmodextra,
607 arg1, rep1, argmod1);
610 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
611 if (extrarg == GL_NONE)
612 extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
614 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
615 if (extrarg == GL_NONE)
616 extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
618 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
619 if (extrarg == GL_NONE)
620 extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
622 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
623 if (extrarg == GL_NONE)
624 extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
625 wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
626 extrarg, GL_ALPHA, GL_NONE,
628 arg2, rep2, argmod2);
631 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
632 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
633 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_NONE,
635 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
636 arg1, rep1, argmod1);
639 /* D3DTOP_PREMODULATE ???? */
641 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
642 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
644 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
646 argmodextra = argmod1;
647 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
649 arg1, GL_ALPHA, argmodextra,
650 arg1, rep1, argmod1);
653 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
654 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
656 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
658 argmodextra = argmod1;
659 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
661 arg1, rep1, argmodextra,
662 arg1, GL_ALPHA, argmod1);
665 case WINED3D_TOP_DOTPRODUCT3:
666 wrap_op2(gl_info, GL_DOT3_ATI, dstreg, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
667 arg1, rep1, argmod1 | GL_BIAS_BIT_ATI,
668 arg2, rep2, argmod2 | GL_BIAS_BIT_ATI);
671 case WINED3D_TOP_MULTIPLY_ADD:
672 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
675 arg0, rep0, argmod0);
678 case WINED3D_TOP_LERP:
679 wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
682 arg2, rep2, argmod2);
685 case WINED3D_TOP_BUMPENVMAP:
686 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
687 /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */
690 default: FIXME("Unhandled color operation %d on stage %d\n", op[stage].cop, stage);
693 arg0 = register_for_arg(op[stage].aarg0, gl_info, stage, &argmod0, NULL, tmparg);
694 arg1 = register_for_arg(op[stage].aarg1, gl_info, stage, &argmod1, NULL, tmparg);
695 arg2 = register_for_arg(op[stage].aarg2, gl_info, stage, &argmod2, NULL, tmparg);
697 argmodextra = GL_NONE;
700 switch (op[stage].aop)
702 case WINED3D_TOP_DISABLE:
703 /* Get the primary color to the output if on stage 0, otherwise leave register 0 untouched */
706 wrap_op1(gl_info, GL_MOV_ATI, GL_REG_0_ATI, GL_ALPHA, GL_NONE,
707 GL_PRIMARY_COLOR, GL_NONE, GL_NONE);
711 case WINED3D_TOP_SELECT_ARG2:
715 case WINED3D_TOP_SELECT_ARG1:
716 wrap_op1(gl_info, GL_MOV_ATI, dstreg, GL_ALPHA, GL_NONE,
717 arg1, GL_NONE, argmod1);
720 case WINED3D_TOP_MODULATE_4X:
721 if (dstmod == GL_NONE)
722 dstmod = GL_4X_BIT_ATI;
724 case WINED3D_TOP_MODULATE_2X:
725 if (dstmod == GL_NONE)
726 dstmod = GL_2X_BIT_ATI;
727 dstmod |= GL_SATURATE_BIT_ATI;
729 case WINED3D_TOP_MODULATE:
730 wrap_op2(gl_info, GL_MUL_ATI, dstreg, GL_ALPHA, dstmod,
731 arg1, GL_NONE, argmod1,
732 arg2, GL_NONE, argmod2);
735 case WINED3D_TOP_ADD_SIGNED_2X:
736 dstmod = GL_2X_BIT_ATI;
738 case WINED3D_TOP_ADD_SIGNED:
739 argmodextra = GL_BIAS_BIT_ATI;
741 case WINED3D_TOP_ADD:
742 dstmod |= GL_SATURATE_BIT_ATI;
743 wrap_op2(gl_info, GL_ADD_ATI, dstreg, GL_ALPHA, dstmod,
744 arg1, GL_NONE, argmod1,
745 arg2, GL_NONE, argmodextra | argmod2);
748 case WINED3D_TOP_SUBTRACT:
749 dstmod |= GL_SATURATE_BIT_ATI;
750 wrap_op2(gl_info, GL_SUB_ATI, dstreg, GL_ALPHA, dstmod,
751 arg1, GL_NONE, argmod1,
752 arg2, GL_NONE, argmod2);
755 case WINED3D_TOP_ADD_SMOOTH:
756 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
757 /* Dst = arg1 + * arg2(1 -arg 1)
758 * = arg2 * (1 - arg1) + arg1
760 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_ALPHA, GL_SATURATE_BIT_ATI,
761 arg2, GL_NONE, argmod2,
762 arg1, GL_NONE, argmodextra,
763 arg1, GL_NONE, argmod1);
766 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
767 if (extrarg == GL_NONE)
768 extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
770 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
771 if (extrarg == GL_NONE)
772 extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
774 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
775 if (extrarg == GL_NONE)
776 extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
778 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
779 if (extrarg == GL_NONE)
780 extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
781 wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_ALPHA, GL_NONE,
782 extrarg, GL_ALPHA, GL_NONE,
783 arg1, GL_NONE, argmod1,
784 arg2, GL_NONE, argmod2);
787 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
788 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
789 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_ALPHA, GL_NONE,
790 arg2, GL_NONE, argmod2,
791 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
792 arg1, GL_NONE, argmod1);
795 /* D3DTOP_PREMODULATE ???? */
797 case WINED3D_TOP_DOTPRODUCT3:
798 wrap_op2(gl_info, GL_DOT3_ATI, dstreg, GL_ALPHA, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
799 arg1, GL_NONE, argmod1 | GL_BIAS_BIT_ATI,
800 arg2, GL_NONE, argmod2 | GL_BIAS_BIT_ATI);
803 case WINED3D_TOP_MULTIPLY_ADD:
804 wrap_op3(gl_info, GL_MAD_ATI, dstreg, GL_ALPHA, GL_SATURATE_BIT_ATI,
805 arg1, GL_NONE, argmod1,
806 arg2, GL_NONE, argmod2,
807 arg0, GL_NONE, argmod0);
810 case WINED3D_TOP_LERP:
811 wrap_op3(gl_info, GL_LERP_ATI, dstreg, GL_ALPHA, GL_SATURATE_BIT_ATI,
812 arg1, GL_NONE, argmod1,
813 arg2, GL_NONE, argmod2,
814 arg0, GL_NONE, argmod0);
817 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
818 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
819 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
820 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
821 case WINED3D_TOP_BUMPENVMAP:
822 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
823 ERR("Application uses an invalid alpha operation\n");
826 default: FIXME("Unhandled alpha operation %d on stage %d\n", op[stage].aop, stage);
830 TRACE("glEndFragmentShaderATI()\n");
831 GL_EXTCALL(glEndFragmentShaderATI());
832 checkGLcall("GL_EXTCALL(glEndFragmentShaderATI())");
836 static void set_tex_op_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
838 const struct wined3d_device *device = context->swapchain->device;
839 const struct wined3d_gl_info *gl_info = context->gl_info;
840 const struct atifs_ffp_desc *desc;
841 struct ffp_frag_settings settings;
842 struct atifs_private_data *priv = device->fragment_priv;
846 gen_ffp_frag_op(device, state, &settings, TRUE);
847 desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings);
849 struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc));
852 ERR("Out of memory\n");
855 new_desc->num_textures_used = 0;
856 for (i = 0; i < gl_info->limits.texture_stages; ++i)
858 if (settings.op[i].cop == WINED3D_TOP_DISABLE)
860 new_desc->num_textures_used = i;
863 memcpy(&new_desc->parent.settings, &settings, sizeof(settings));
864 new_desc->shader = gen_ati_shader(settings.op, gl_info);
865 add_ffp_frag_shader(&priv->fragment_shaders, &new_desc->parent);
866 TRACE("Allocated fixed function replacement shader descriptor %p\n", new_desc);
870 /* GL_ATI_fragment_shader depends on the GL_TEXTURE_xD enable settings. Update the texture stages
871 * used by this shader
873 for (i = 0; i < desc->num_textures_used; ++i)
875 mapped_stage = device->texUnitMap[i];
876 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
878 context_active_texture(context, gl_info, mapped_stage);
879 texture_activate_dimensions(state->textures[i], gl_info);
883 GL_EXTCALL(glBindFragmentShaderATI(desc->shader));
886 static void state_texfactor_atifs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
888 const struct wined3d_gl_info *gl_info = context->gl_info;
891 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col);
892 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col));
893 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)");
896 static void set_bumpmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
898 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
899 const struct wined3d_gl_info *gl_info = context->gl_info;
902 mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]);
903 mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]);
904 mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]);
905 mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]);
906 /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat
907 * constants can be in any range. While they should stay between [-1.0 and 1.0] because
908 * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally,
909 * for example by our d3d9 test. So to get negative values scale -1;1 to 0;1 and undo that in the
910 * shader(it is free). This might potentially reduce precision. However, if the hardware does
911 * support proper floats it shouldn't, and if it doesn't we can't get anything better anyway
913 mat[0][0] = (mat[0][0] + 1.0f) * 0.5f;
914 mat[1][0] = (mat[1][0] + 1.0f) * 0.5f;
915 mat[0][1] = (mat[0][1] + 1.0f) * 0.5f;
916 mat[1][1] = (mat[1][1] + 1.0f) * 0.5f;
917 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), (float *) mat));
918 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
921 static void textransform(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
923 if (!isStateDirty(context, STATE_PIXELSHADER))
924 set_tex_op_atifs(context, state, state_id);
927 static void atifs_apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
929 const struct wined3d_device *device = context->swapchain->device;
930 BOOL use_vshader = use_vs(state);
932 context->last_was_pshader = use_ps(state);
933 /* The ATIFS code does not support pixel shaders currently, but we have to
934 * provide a state handler to call shader_select to select a vertex shader
935 * if one is applied because the vertex shader state may defer calling the
936 * shader backend if the pshader state is dirty.
938 * In theory the application should not be able to mark the pixel shader
939 * dirty because it cannot create a shader, and thus has no way to set the
940 * state to something != NULL. However, a different pipeline part may link
941 * a different state to its pixelshader handler, thus a pshader state
942 * exists and can be dirtified. Also the pshader is always dirtified at
943 * startup, and blitting disables all shaders and dirtifies all shader
944 * states. If atifs can deal with this it keeps the rest of the code
946 if (!isStateDirty(context, context->state_table[STATE_VSHADER].representative))
948 device->shader_backend->shader_select(context, FALSE, use_vshader);
950 if (!isStateDirty(context, STATE_VERTEXSHADERCONSTANT) && use_vshader)
951 context_apply_state(context, state, STATE_VERTEXSHADERCONSTANT);
955 static void atifs_srgbwriteenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
957 if (state->render_states[WINED3D_RS_SRGBWRITEENABLE])
958 WARN("sRGB writes are not supported by this fragment pipe.\n");
961 static const struct StateEntryTemplate atifs_fragmentstate_template[] = {
962 {STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), state_texfactor_atifs }, WINED3D_GL_EXT_NONE },
963 {STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
964 {STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
965 {STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
966 {STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
967 {STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
968 {STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
969 {STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
970 {STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), atifs_srgbwriteenable }, WINED3D_GL_EXT_NONE },
971 {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), set_tex_op_atifs }, WINED3D_GL_EXT_NONE },
972 {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
973 {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
974 {STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
975 {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
976 {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
977 {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
978 {STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
979 {STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
980 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
981 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
982 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
983 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
984 {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
985 {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
986 {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
987 {STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
988 {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
989 {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
990 {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
991 {STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
992 {STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
993 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
994 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
995 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
996 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
997 {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
998 {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
999 {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1000 {STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1001 {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1002 {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1003 {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1004 {STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1005 {STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1006 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1007 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1008 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1009 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1010 {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1011 {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1012 {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1013 {STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1014 {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1015 {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1016 {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1017 {STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1018 {STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1019 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1020 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1021 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1022 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1023 {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1024 {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1025 {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1026 {STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1027 {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1028 {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1029 {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1030 {STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1031 {STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1032 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1033 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1034 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1035 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1036 {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1037 {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1038 {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1039 {STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1040 {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1041 {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1042 {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1043 {STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1044 {STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1045 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1046 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1047 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1048 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1049 {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1050 {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1051 {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1052 {STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1053 {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1054 {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1055 {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1056 {STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1057 {STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1058 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1059 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1060 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1061 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1062 {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1063 {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1064 {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1065 {STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1066 {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1067 {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1068 {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1069 {STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1070 {STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
1071 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), set_bumpmat }, WINED3D_GL_EXT_NONE },
1072 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1073 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1074 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, WINED3D_GL_EXT_NONE },
1075 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
1076 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
1077 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
1078 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
1079 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
1080 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
1081 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
1082 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
1083 {STATE_TEXTURESTAGE(0,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1084 {STATE_TEXTURESTAGE(1,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1085 {STATE_TEXTURESTAGE(2,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1086 {STATE_TEXTURESTAGE(3,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1087 {STATE_TEXTURESTAGE(4,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1088 {STATE_TEXTURESTAGE(5,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1089 {STATE_TEXTURESTAGE(6,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1090 {STATE_TEXTURESTAGE(7,WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), textransform }, WINED3D_GL_EXT_NONE },
1091 {STATE_PIXELSHADER, { STATE_PIXELSHADER, atifs_apply_pixelshader }, WINED3D_GL_EXT_NONE },
1092 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
1095 /* Context activation and GL locking are done by the caller. */
1096 static void atifs_enable(const struct wined3d_gl_info *gl_info, BOOL enable)
1100 gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_SHADER_ATI);
1101 checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
1105 gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_SHADER_ATI);
1106 checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
1110 static void atifs_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
1112 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_TSSARGTEMP;
1113 caps->TextureOpCaps = WINED3DTEXOPCAPS_DISABLE |
1114 WINED3DTEXOPCAPS_SELECTARG1 |
1115 WINED3DTEXOPCAPS_SELECTARG2 |
1116 WINED3DTEXOPCAPS_MODULATE4X |
1117 WINED3DTEXOPCAPS_MODULATE2X |
1118 WINED3DTEXOPCAPS_MODULATE |
1119 WINED3DTEXOPCAPS_ADDSIGNED2X |
1120 WINED3DTEXOPCAPS_ADDSIGNED |
1121 WINED3DTEXOPCAPS_ADD |
1122 WINED3DTEXOPCAPS_SUBTRACT |
1123 WINED3DTEXOPCAPS_ADDSMOOTH |
1124 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
1125 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
1126 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
1127 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1128 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
1129 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1130 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1131 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
1132 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
1133 WINED3DTEXOPCAPS_DOTPRODUCT3 |
1134 WINED3DTEXOPCAPS_MULTIPLYADD |
1135 WINED3DTEXOPCAPS_LERP |
1136 WINED3DTEXOPCAPS_BUMPENVMAP;
1138 /* TODO: Implement WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1139 and WINED3DTEXOPCAPS_PREMODULATE */
1141 /* GL_ATI_fragment_shader always supports 6 textures, which was the limit on r200 cards
1142 * which this extension is exclusively focused on(later cards have GL_ARB_fragment_program).
1143 * If the current card has more than 8 fixed function textures in OpenGL's regular fixed
1144 * function pipeline then the ATI_fragment_shader backend imposes a stricter limit. This
1145 * shouldn't be too hard since Nvidia cards have a limit of 4 textures with the default ffp
1146 * pipeline, and almost all games are happy with that. We can however support up to 8
1147 * texture stages because we have a 2nd pass limit of 8 instructions, and per stage we use
1148 * only 1 instruction.
1150 * The proper fix for this is not to use GL_ATI_fragment_shader on cards newer than the
1151 * r200 series and use an ARB or GLSL shader instead
1153 caps->MaxTextureBlendStages = 8;
1154 caps->MaxSimultaneousTextures = 6;
1157 static HRESULT atifs_alloc(struct wined3d_device *device)
1159 struct atifs_private_data *priv;
1161 device->fragment_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct atifs_private_data));
1162 if (!device->fragment_priv)
1164 ERR("Out of memory\n");
1165 return E_OUTOFMEMORY;
1167 priv = device->fragment_priv;
1168 if (wine_rb_init(&priv->fragment_shaders, &wined3d_ffp_frag_program_rb_functions) == -1)
1170 ERR("Failed to initialize rbtree.\n");
1171 HeapFree(GetProcessHeap(), 0, device->fragment_priv);
1172 return E_OUTOFMEMORY;
1177 /* Context activation is done by the caller. */
1178 static void atifs_free_ffpshader(struct wine_rb_entry *entry, void *context)
1180 struct wined3d_device *device = context;
1181 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
1182 struct atifs_ffp_desc *entry_ati = WINE_RB_ENTRY_VALUE(entry, struct atifs_ffp_desc, parent.entry);
1185 GL_EXTCALL(glDeleteFragmentShaderATI(entry_ati->shader));
1186 checkGLcall("glDeleteFragmentShaderATI(entry->shader)");
1187 HeapFree(GetProcessHeap(), 0, entry_ati);
1191 /* Context activation is done by the caller. */
1192 static void atifs_free(struct wined3d_device *device)
1194 struct atifs_private_data *priv = device->fragment_priv;
1196 wine_rb_destroy(&priv->fragment_shaders, atifs_free_ffpshader, device);
1198 HeapFree(GetProcessHeap(), 0, priv);
1199 device->fragment_priv = NULL;
1202 static BOOL atifs_color_fixup_supported(struct color_fixup_desc fixup)
1204 if (TRACE_ON(d3d_shader) && TRACE_ON(d3d))
1206 TRACE("Checking support for fixup:\n");
1207 dump_color_fixup_desc(fixup);
1210 /* We only support sign fixup of the first two channels. */
1211 if (fixup.x_source == CHANNEL_SOURCE_X && fixup.y_source == CHANNEL_SOURCE_Y
1212 && fixup.z_source == CHANNEL_SOURCE_Z && fixup.w_source == CHANNEL_SOURCE_W
1213 && !fixup.z_sign_fixup && !fixup.w_sign_fixup)
1219 TRACE("[FAILED]\n");
1223 const struct fragment_pipeline atifs_fragment_pipeline = {
1228 atifs_color_fixup_supported,
1229 atifs_fragmentstate_template,
1230 TRUE /* We can disable projected textures */