Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 21 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | #include <strings.h> |
| 29 | |
| 30 | #include "glheader.h" |
| 31 | #include "macros.h" |
| 32 | #include "enums.h" |
| 33 | #include "texenvprogram.h" |
| 34 | |
| 35 | #include "shader/program.h" |
| 36 | #include "shader/nvfragprog.h" |
| 37 | #include "shader/arbfragparse.h" |
| 38 | |
| 39 | |
Keith Whitwell | 8b88f62 | 2005-05-10 11:39:50 +0000 | [diff] [blame] | 40 | #define DISASSEM 0 |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 41 | |
| 42 | /* Use uregs to represent registers internally, translate to Mesa's |
| 43 | * expected formats on emit. |
| 44 | * |
| 45 | * NOTE: These are passed by value extensively in this file rather |
| 46 | * than as usual by pointer reference. If this disturbs you, try |
| 47 | * remembering they are just 32bits in size. |
| 48 | * |
| 49 | * GCC is smart enough to deal with these dword-sized structures in |
| 50 | * much the same way as if I had defined them as dwords and was using |
| 51 | * macros to access and set the fields. This is much nicer and easier |
| 52 | * to evolve. |
| 53 | */ |
| 54 | struct ureg { |
| 55 | GLuint file:4; |
| 56 | GLuint idx:8; |
| 57 | GLuint negatebase:1; |
| 58 | GLuint abs:1; |
| 59 | GLuint negateabs:1; |
| 60 | GLuint swz:12; |
| 61 | GLuint pad:5; |
| 62 | }; |
| 63 | |
| 64 | const static struct ureg undef = { |
| 65 | ~0, |
| 66 | ~0, |
| 67 | 0, |
| 68 | 0, |
| 69 | 0, |
| 70 | 0, |
| 71 | 0 |
| 72 | }; |
| 73 | |
| 74 | #define X 0 |
| 75 | #define Y 1 |
| 76 | #define Z 2 |
| 77 | #define W 3 |
| 78 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 79 | /* State used to build the fragment program: |
| 80 | */ |
| 81 | struct texenv_fragment_program { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 82 | struct fragment_program *program; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 83 | GLcontext *ctx; |
| 84 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 85 | GLuint temp_used_for_txp; /* Temps which have been the result of a texture |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 86 | * operation. |
| 87 | */ |
| 88 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 89 | GLuint temp_in_use; /* Tracks temporary regs which are in |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 90 | * use. |
| 91 | */ |
| 92 | |
| 93 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 94 | GLboolean error; |
| 95 | |
| 96 | struct ureg src_texture; /* Reg containing sampled texture color, |
| 97 | * else undef. |
| 98 | */ |
| 99 | |
| 100 | struct ureg src_previous; /* Reg containing color from previous |
| 101 | * stage. May need to be decl'd. |
| 102 | */ |
| 103 | |
| 104 | GLuint last_tex_stage; /* Number of last enabled texture unit */ |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | |
| 109 | static struct ureg make_ureg(GLuint file, GLuint idx) |
| 110 | { |
| 111 | struct ureg reg; |
| 112 | reg.file = file; |
| 113 | reg.idx = idx; |
| 114 | reg.negatebase = 0; |
| 115 | reg.abs = 0; |
| 116 | reg.negateabs = 0; |
| 117 | reg.swz = SWIZZLE_NOOP; |
| 118 | reg.pad = 0; |
| 119 | return reg; |
| 120 | } |
| 121 | |
| 122 | static struct ureg swizzle( struct ureg reg, int x, int y, int z, int w ) |
| 123 | { |
| 124 | reg.swz = MAKE_SWIZZLE4(GET_SWZ(reg.swz, x), |
| 125 | GET_SWZ(reg.swz, y), |
| 126 | GET_SWZ(reg.swz, z), |
| 127 | GET_SWZ(reg.swz, w)); |
| 128 | |
| 129 | return reg; |
| 130 | } |
| 131 | |
| 132 | static struct ureg swizzle1( struct ureg reg, int x ) |
| 133 | { |
| 134 | return swizzle(reg, x, x, x, x); |
| 135 | } |
| 136 | |
| 137 | static GLboolean is_undef( struct ureg reg ) |
| 138 | { |
| 139 | return reg.file == 0xf; |
| 140 | } |
| 141 | |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 142 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 143 | static struct ureg get_temp( struct texenv_fragment_program *p ) |
| 144 | { |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 145 | int bit; |
| 146 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 147 | /* First try and reuse temps which have been used for texture |
| 148 | * results: |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 149 | */ |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 150 | bit = ffs( ~p->temp_in_use & p->temp_used_for_txp ); |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 151 | |
| 152 | /* Then any unused temporary: |
| 153 | */ |
| 154 | if (!bit) |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 155 | bit = ffs( ~p->temp_in_use ); |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 156 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 157 | if (!bit) { |
| 158 | fprintf(stderr, "%s: out of temporaries\n", __FILE__); |
| 159 | exit(1); |
| 160 | } |
| 161 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 162 | p->temp_in_use |= 1<<(bit-1); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 163 | return make_ureg(PROGRAM_TEMPORARY, (bit-1)); |
| 164 | } |
| 165 | |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 166 | static struct ureg get_tex_temp( struct texenv_fragment_program *p ) |
| 167 | { |
| 168 | int bit; |
| 169 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 170 | /* First try to find availble temp not previously used as a texture |
| 171 | * result: |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 172 | */ |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 173 | bit = ffs( ~p->temp_in_use & ~p->temp_used_for_txp ); |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 174 | |
| 175 | /* Then any unused temporary: |
| 176 | */ |
Keith Whitwell | 586f2c5 | 2005-05-10 10:25:16 +0000 | [diff] [blame] | 177 | if (!bit) { |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 178 | bit = ffs( ~p->temp_in_use ); |
Keith Whitwell | 586f2c5 | 2005-05-10 10:25:16 +0000 | [diff] [blame] | 179 | p->program->NumTexIndirections++; |
| 180 | } |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 181 | |
| 182 | if (!bit) { |
| 183 | fprintf(stderr, "%s: out of temporaries\n", __FILE__); |
| 184 | exit(1); |
| 185 | } |
| 186 | |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 187 | p->temp_in_use |= 1<<(bit-1); |
| 188 | p->temp_used_for_txp |= 1<<(bit-1); |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 189 | return make_ureg(PROGRAM_TEMPORARY, (bit-1)); |
| 190 | } |
| 191 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 192 | |
| 193 | static void release_temps( struct texenv_fragment_program *p ) |
| 194 | { |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 195 | GLuint max_temp = p->ctx->Const.MaxFragmentProgramTemps; |
| 196 | |
| 197 | if (max_temp >= sizeof(int) * 8) |
| 198 | p->temp_in_use = 0; |
| 199 | else |
| 200 | p->temp_in_use = ~((1<<max_temp)-1); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 204 | static struct ureg register_param6( struct texenv_fragment_program *p, |
| 205 | GLint s0, |
| 206 | GLint s1, |
| 207 | GLint s2, |
| 208 | GLint s3, |
| 209 | GLint s4, |
| 210 | GLint s5) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 211 | { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 212 | GLint tokens[6]; |
| 213 | GLuint idx; |
| 214 | tokens[0] = s0; |
| 215 | tokens[1] = s1; |
| 216 | tokens[2] = s2; |
| 217 | tokens[3] = s3; |
| 218 | tokens[4] = s4; |
| 219 | tokens[5] = s5; |
| 220 | idx = _mesa_add_state_reference( p->program->Parameters, tokens ); |
| 221 | return make_ureg(PROGRAM_STATE_VAR, idx); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 224 | |
| 225 | #define register_param1(p,s0) register_param6(p,s0,0,0,0,0,0) |
| 226 | #define register_param2(p,s0,s1) register_param6(p,s0,s1,0,0,0,0) |
| 227 | #define register_param3(p,s0,s1,s2) register_param6(p,s0,s1,s2,0,0,0) |
| 228 | #define register_param4(p,s0,s1,s2,s3) register_param6(p,s0,s1,s2,s3,0,0) |
| 229 | |
| 230 | |
| 231 | static struct ureg register_input( struct texenv_fragment_program *p, GLuint input ) |
| 232 | { |
| 233 | p->program->InputsRead |= (1<<input); |
| 234 | return make_ureg(PROGRAM_INPUT, input); |
| 235 | } |
| 236 | |
| 237 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 238 | static void emit_arg( struct fp_src_register *reg, |
| 239 | struct ureg ureg ) |
| 240 | { |
| 241 | reg->File = ureg.file; |
| 242 | reg->Index = ureg.idx; |
| 243 | reg->Swizzle = ureg.swz; |
| 244 | reg->NegateBase = ureg.negatebase; |
| 245 | reg->Abs = ureg.abs; |
| 246 | reg->NegateAbs = ureg.negateabs; |
| 247 | } |
| 248 | |
| 249 | static void emit_dst( struct fp_dst_register *dst, |
| 250 | struct ureg ureg, GLuint mask ) |
| 251 | { |
| 252 | dst->File = ureg.file; |
| 253 | dst->Index = ureg.idx; |
| 254 | dst->WriteMask = mask; |
| 255 | dst->CondMask = 0; |
| 256 | dst->CondSwizzle = 0; |
| 257 | } |
| 258 | |
| 259 | static struct fp_instruction * |
| 260 | emit_op(struct texenv_fragment_program *p, |
| 261 | GLuint op, |
| 262 | struct ureg dest, |
| 263 | GLuint mask, |
| 264 | GLuint saturate, |
| 265 | struct ureg src0, |
| 266 | struct ureg src1, |
| 267 | struct ureg src2 ) |
| 268 | { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 269 | GLuint nr = p->program->Base.NumInstructions++; |
| 270 | struct fp_instruction *inst = &p->program->Instructions[nr]; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 271 | |
| 272 | memset(inst, 0, sizeof(*inst)); |
| 273 | inst->Opcode = op; |
| 274 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 275 | emit_arg( &inst->SrcReg[0], src0 ); |
| 276 | emit_arg( &inst->SrcReg[1], src1 ); |
| 277 | emit_arg( &inst->SrcReg[2], src2 ); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 278 | |
| 279 | inst->Saturate = saturate; |
| 280 | |
| 281 | emit_dst( &inst->DstReg, dest, mask ); |
| 282 | |
| 283 | return inst; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | static struct ureg emit_arith( struct texenv_fragment_program *p, |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 288 | GLuint op, |
| 289 | struct ureg dest, |
| 290 | GLuint mask, |
| 291 | GLuint saturate, |
| 292 | struct ureg src0, |
| 293 | struct ureg src1, |
| 294 | struct ureg src2 ) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 295 | { |
| 296 | emit_op(p, op, dest, mask, saturate, src0, src1, src2); |
| 297 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 298 | p->program->NumAluInstructions++; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 299 | return dest; |
| 300 | } |
| 301 | |
| 302 | static struct ureg emit_texld( struct texenv_fragment_program *p, |
| 303 | GLuint op, |
| 304 | struct ureg dest, |
| 305 | GLuint destmask, |
| 306 | GLuint tex_unit, |
| 307 | GLuint tex_idx, |
| 308 | struct ureg coord ) |
| 309 | { |
| 310 | struct fp_instruction *inst = emit_op( p, op, |
| 311 | dest, destmask, |
| 312 | 0, /* don't saturate? */ |
| 313 | coord, /* arg 0? */ |
| 314 | undef, |
| 315 | undef); |
| 316 | |
| 317 | inst->TexSrcIdx = tex_idx; |
| 318 | inst->TexSrcUnit = tex_unit; |
| 319 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 320 | p->program->NumTexInstructions++; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 321 | |
| 322 | if (coord.file != PROGRAM_INPUT && |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 323 | (coord.idx < FRAG_ATTRIB_TEX0 || |
| 324 | coord.idx > FRAG_ATTRIB_TEX7)) { |
| 325 | p->program->NumTexIndirections++; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | return dest; |
| 329 | } |
| 330 | |
| 331 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 332 | static struct ureg register_const4f( struct texenv_fragment_program *p, |
| 333 | GLfloat s0, |
| 334 | GLfloat s1, |
| 335 | GLfloat s2, |
| 336 | GLfloat s3) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 337 | { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 338 | GLfloat values[4]; |
| 339 | GLuint idx; |
| 340 | values[0] = s0; |
| 341 | values[1] = s1; |
| 342 | values[2] = s2; |
| 343 | values[3] = s3; |
| 344 | idx = _mesa_add_unnamed_constant( p->program->Parameters, values ); |
| 345 | return make_ureg(PROGRAM_STATE_VAR, idx); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 348 | #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1) |
| 349 | #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1) |
| 350 | #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 351 | |
| 352 | |
| 353 | |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | static void program_error( struct texenv_fragment_program *p, const char *msg ) |
| 360 | { |
| 361 | fprintf(stderr, "%s\n", msg); |
| 362 | p->error = 1; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | static GLuint translate_tex_src_bit( struct texenv_fragment_program *p, |
| 367 | GLuint bit ) |
| 368 | { |
| 369 | switch (bit) { |
| 370 | case TEXTURE_1D_BIT: return TEXTURE_1D_INDEX; |
| 371 | case TEXTURE_2D_BIT: return TEXTURE_2D_INDEX; |
| 372 | case TEXTURE_RECT_BIT: return TEXTURE_RECT_INDEX; |
| 373 | case TEXTURE_3D_BIT: return TEXTURE_3D_INDEX; |
| 374 | case TEXTURE_CUBE_BIT: return TEXTURE_CUBE_INDEX; |
| 375 | default: program_error(p, "TexSrcBit"); return 0; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | |
| 380 | static struct ureg get_source( struct texenv_fragment_program *p, |
| 381 | GLenum src, GLuint unit ) |
| 382 | { |
| 383 | switch (src) { |
| 384 | case GL_TEXTURE: |
| 385 | if (is_undef(p->src_texture)) { |
| 386 | |
| 387 | GLuint dim = translate_tex_src_bit( p, p->ctx->Texture.Unit[unit]._ReallyEnabled); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 388 | struct ureg texcoord = register_input(p, FRAG_ATTRIB_TEX0+unit); |
Keith Whitwell | ecb6bfc | 2005-05-10 08:58:44 +0000 | [diff] [blame] | 389 | struct ureg tmp = get_tex_temp( p ); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 390 | |
| 391 | /* TODO: Use D0_MASK_XY where possible. |
| 392 | */ |
| 393 | p->src_texture = emit_texld( p, FP_OPCODE_TXP, |
| 394 | tmp, WRITEMASK_XYZW, |
| 395 | unit, dim, texcoord ); |
| 396 | } |
| 397 | |
| 398 | return p->src_texture; |
| 399 | |
| 400 | /* Crossbar: */ |
| 401 | case GL_TEXTURE0: |
| 402 | case GL_TEXTURE1: |
| 403 | case GL_TEXTURE2: |
| 404 | case GL_TEXTURE3: |
| 405 | case GL_TEXTURE4: |
| 406 | case GL_TEXTURE5: |
| 407 | case GL_TEXTURE6: |
| 408 | case GL_TEXTURE7: { |
| 409 | return undef; |
| 410 | } |
| 411 | |
| 412 | case GL_CONSTANT: |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 413 | return register_param2(p, STATE_TEXENV_COLOR, unit); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 414 | case GL_PRIMARY_COLOR: |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 415 | return register_input(p, FRAG_ATTRIB_COL0); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 416 | case GL_PREVIOUS: |
| 417 | default: |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 418 | if (is_undef(p->src_previous)) |
| 419 | return register_input(p, FRAG_ATTRIB_COL0); |
| 420 | else |
| 421 | return p->src_previous; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | |
| 426 | static struct ureg emit_combine_source( struct texenv_fragment_program *p, |
| 427 | GLuint mask, |
| 428 | GLuint unit, |
| 429 | GLenum source, |
| 430 | GLenum operand ) |
| 431 | { |
| 432 | struct ureg arg, src, one; |
| 433 | |
| 434 | src = get_source(p, source, unit); |
| 435 | |
| 436 | switch (operand) { |
| 437 | case GL_ONE_MINUS_SRC_COLOR: |
| 438 | /* Get unused tmp, |
| 439 | * Emit tmp = 1.0 - arg.xyzw |
| 440 | */ |
| 441 | arg = get_temp( p ); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 442 | one = register_const1f(p, 1.0); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 443 | return emit_arith( p, FP_OPCODE_SUB, arg, mask, 0, one, src, undef); |
| 444 | |
| 445 | case GL_SRC_ALPHA: |
| 446 | if (mask == WRITEMASK_W) |
| 447 | return src; |
| 448 | else |
| 449 | return swizzle1( src, W ); |
| 450 | case GL_ONE_MINUS_SRC_ALPHA: |
| 451 | /* Get unused tmp, |
| 452 | * Emit tmp = 1.0 - arg.wwww |
| 453 | */ |
| 454 | arg = get_temp( p ); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 455 | one = register_const1f(p, 1.0); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 456 | return emit_arith( p, FP_OPCODE_SUB, arg, mask, 0, |
| 457 | one, swizzle1(src, W), undef); |
| 458 | case GL_SRC_COLOR: |
| 459 | default: |
| 460 | return src; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | |
| 465 | |
| 466 | static int nr_args( GLenum mode ) |
| 467 | { |
| 468 | switch (mode) { |
| 469 | case GL_REPLACE: return 1; |
| 470 | case GL_MODULATE: return 2; |
| 471 | case GL_ADD: return 2; |
| 472 | case GL_ADD_SIGNED: return 2; |
| 473 | case GL_INTERPOLATE: return 3; |
| 474 | case GL_SUBTRACT: return 2; |
| 475 | case GL_DOT3_RGB_EXT: return 2; |
| 476 | case GL_DOT3_RGBA_EXT: return 2; |
| 477 | case GL_DOT3_RGB: return 2; |
| 478 | case GL_DOT3_RGBA: return 2; |
| 479 | default: return 0; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | |
| 484 | static GLboolean args_match( struct gl_texture_unit *texUnit ) |
| 485 | { |
| 486 | int i, nr = nr_args(texUnit->_CurrentCombine->ModeRGB); |
| 487 | |
| 488 | for (i = 0 ; i < nr ; i++) { |
| 489 | if (texUnit->_CurrentCombine->SourceA[i] != texUnit->_CurrentCombine->SourceRGB[i]) |
| 490 | return GL_FALSE; |
| 491 | |
| 492 | switch(texUnit->_CurrentCombine->OperandA[i]) { |
| 493 | case GL_SRC_ALPHA: |
| 494 | switch(texUnit->_CurrentCombine->OperandRGB[i]) { |
| 495 | case GL_SRC_COLOR: |
| 496 | case GL_SRC_ALPHA: |
| 497 | break; |
| 498 | default: |
| 499 | return GL_FALSE; |
| 500 | } |
| 501 | break; |
| 502 | case GL_ONE_MINUS_SRC_ALPHA: |
| 503 | switch(texUnit->_CurrentCombine->OperandRGB[i]) { |
| 504 | case GL_ONE_MINUS_SRC_COLOR: |
| 505 | case GL_ONE_MINUS_SRC_ALPHA: |
| 506 | break; |
| 507 | default: |
| 508 | return GL_FALSE; |
| 509 | } |
| 510 | break; |
| 511 | default: |
| 512 | return GL_FALSE; /* impossible */ |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return GL_TRUE; |
| 517 | } |
| 518 | |
| 519 | |
| 520 | static struct ureg emit_combine( struct texenv_fragment_program *p, |
| 521 | struct ureg dest, |
| 522 | GLuint mask, |
| 523 | GLuint saturate, |
| 524 | GLuint unit, |
| 525 | GLenum mode, |
| 526 | const GLenum *source, |
| 527 | const GLenum *operand) |
| 528 | { |
| 529 | int nr = nr_args(mode); |
| 530 | struct ureg src[3]; |
| 531 | struct ureg tmp; |
| 532 | int i; |
| 533 | |
| 534 | for (i = 0; i < nr; i++) |
| 535 | src[i] = emit_combine_source( p, mask, unit, source[i], operand[i] ); |
| 536 | |
| 537 | switch (mode) { |
| 538 | case GL_REPLACE: |
| 539 | if (mask == WRITEMASK_XYZW && !saturate) |
| 540 | return src[0]; |
| 541 | else |
| 542 | return emit_arith( p, FP_OPCODE_MOV, dest, mask, saturate, src[0], undef, undef ); |
| 543 | case GL_MODULATE: |
| 544 | return emit_arith( p, FP_OPCODE_MUL, dest, mask, saturate, |
| 545 | src[0], src[1], undef ); |
| 546 | case GL_ADD: |
| 547 | return emit_arith( p, FP_OPCODE_ADD, dest, mask, saturate, |
| 548 | src[0], src[1], undef ); |
| 549 | case GL_ADD_SIGNED: |
| 550 | /* tmp = arg0 + arg1 |
| 551 | * result = tmp + -.5 |
| 552 | */ |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 553 | tmp = register_const1f(p, .5); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 554 | tmp = swizzle1(tmp,X); |
| 555 | emit_arith( p, FP_OPCODE_ADD, dest, mask, 0, src[0], src[1], undef ); |
| 556 | emit_arith( p, FP_OPCODE_SUB, dest, mask, saturate, dest, tmp, undef ); |
| 557 | return dest; |
| 558 | case GL_INTERPOLATE: |
| 559 | /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered: |
| 560 | */ |
| 561 | return emit_arith( p, FP_OPCODE_LRP, dest, mask, saturate, src[2], src[0], src[1] ); |
| 562 | |
| 563 | case GL_SUBTRACT: |
| 564 | return emit_arith( p, FP_OPCODE_SUB, dest, mask, saturate, src[0], src[1], undef ); |
| 565 | |
| 566 | case GL_DOT3_RGBA: |
| 567 | case GL_DOT3_RGBA_EXT: |
| 568 | case GL_DOT3_RGB_EXT: |
| 569 | case GL_DOT3_RGB: { |
| 570 | struct ureg tmp0 = get_temp( p ); |
| 571 | struct ureg tmp1 = get_temp( p ); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 572 | struct ureg neg1 = register_const1f(p, -1); |
| 573 | struct ureg two = register_const1f(p, 2); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 574 | |
| 575 | /* tmp0 = 2*src0 - 1 |
| 576 | * tmp1 = 2*src1 - 1 |
| 577 | * |
| 578 | * dst = tmp0 dot3 tmp1 |
| 579 | */ |
| 580 | emit_arith( p, FP_OPCODE_MAD, tmp0, WRITEMASK_XYZW, 0, |
| 581 | two, src[0], neg1); |
| 582 | |
| 583 | if (memcmp(&src[0], &src[1], sizeof(struct ureg)) == 0) |
| 584 | tmp1 = tmp0; |
| 585 | else |
| 586 | emit_arith( p, FP_OPCODE_MAD, tmp1, WRITEMASK_XYZW, 0, |
| 587 | two, src[1], neg1); |
| 588 | emit_arith( p, FP_OPCODE_DP3, dest, mask, saturate, tmp0, tmp1, undef); |
| 589 | return dest; |
| 590 | } |
| 591 | |
| 592 | default: |
| 593 | return src[0]; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | static struct ureg get_dest( struct texenv_fragment_program *p, int unit ) |
| 598 | { |
| 599 | if (p->ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) |
| 600 | return get_temp( p ); |
| 601 | else if (unit != p->last_tex_stage) |
| 602 | return get_temp( p ); |
| 603 | else |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 604 | return make_ureg(PROGRAM_OUTPUT, FRAG_OUTPUT_COLR); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | |
| 608 | |
| 609 | static struct ureg emit_texenv( struct texenv_fragment_program *p, int unit ) |
| 610 | { |
| 611 | struct gl_texture_unit *texUnit = &p->ctx->Texture.Unit[unit]; |
| 612 | GLuint saturate = (unit < p->last_tex_stage); |
| 613 | GLuint rgb_shift, alpha_shift; |
| 614 | struct ureg out, shift; |
| 615 | struct ureg dest = get_dest(p, unit); |
| 616 | |
| 617 | if (!texUnit->_ReallyEnabled) { |
| 618 | return get_source(p, GL_PREVIOUS, 0); |
| 619 | } |
| 620 | |
| 621 | switch (texUnit->_CurrentCombine->ModeRGB) { |
| 622 | case GL_DOT3_RGB_EXT: |
| 623 | alpha_shift = texUnit->_CurrentCombine->ScaleShiftA; |
| 624 | rgb_shift = 0; |
| 625 | break; |
| 626 | |
| 627 | case GL_DOT3_RGBA_EXT: |
| 628 | alpha_shift = 0; |
| 629 | rgb_shift = 0; |
| 630 | break; |
| 631 | |
| 632 | default: |
| 633 | rgb_shift = texUnit->_CurrentCombine->ScaleShiftRGB; |
| 634 | alpha_shift = texUnit->_CurrentCombine->ScaleShiftA; |
| 635 | break; |
| 636 | } |
| 637 | |
| 638 | |
| 639 | /* Emit the RGB and A combine ops |
| 640 | */ |
| 641 | if (texUnit->_CurrentCombine->ModeRGB == texUnit->_CurrentCombine->ModeA && |
| 642 | args_match( texUnit )) { |
| 643 | out = emit_combine( p, dest, WRITEMASK_XYZW, saturate, |
| 644 | unit, |
| 645 | texUnit->_CurrentCombine->ModeRGB, |
| 646 | texUnit->_CurrentCombine->SourceRGB, |
| 647 | texUnit->_CurrentCombine->OperandRGB ); |
| 648 | } |
| 649 | else if (texUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA_EXT || |
| 650 | texUnit->_CurrentCombine->ModeRGB == GL_DOT3_RGBA) { |
| 651 | |
| 652 | out = emit_combine( p, dest, WRITEMASK_XYZW, saturate, |
| 653 | unit, |
| 654 | texUnit->_CurrentCombine->ModeRGB, |
| 655 | texUnit->_CurrentCombine->SourceRGB, |
| 656 | texUnit->_CurrentCombine->OperandRGB ); |
| 657 | } |
| 658 | else { |
| 659 | /* Need to do something to stop from re-emitting identical |
| 660 | * argument calculations here: |
| 661 | */ |
| 662 | out = emit_combine( p, dest, WRITEMASK_XYZ, saturate, |
| 663 | unit, |
| 664 | texUnit->_CurrentCombine->ModeRGB, |
| 665 | texUnit->_CurrentCombine->SourceRGB, |
| 666 | texUnit->_CurrentCombine->OperandRGB ); |
| 667 | out = emit_combine( p, dest, WRITEMASK_W, saturate, |
| 668 | unit, |
| 669 | texUnit->_CurrentCombine->ModeA, |
| 670 | texUnit->_CurrentCombine->SourceA, |
| 671 | texUnit->_CurrentCombine->OperandA ); |
| 672 | } |
| 673 | |
| 674 | /* Deal with the final shift: |
| 675 | */ |
| 676 | if (alpha_shift || rgb_shift) { |
| 677 | if (rgb_shift == alpha_shift) { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 678 | shift = register_const1f(p, 1<<rgb_shift); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 679 | shift = swizzle1(shift,X); |
| 680 | } |
| 681 | else { |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 682 | shift = register_const2f(p, 1<<rgb_shift, 1<<alpha_shift); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 683 | shift = swizzle(shift,X,X,X,Y); |
| 684 | } |
| 685 | return emit_arith( p, FP_OPCODE_MUL, dest, WRITEMASK_XYZW, |
| 686 | saturate, out, shift, undef ); |
| 687 | } |
| 688 | else |
| 689 | return out; |
| 690 | } |
| 691 | |
| 692 | void _mesa_UpdateTexEnvProgram( GLcontext *ctx ) |
| 693 | { |
| 694 | struct texenv_fragment_program p; |
| 695 | GLuint unit; |
| 696 | struct ureg cf, out; |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 697 | GLuint db_NumInstructions; |
| 698 | struct fp_instruction *db_Instructions; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 699 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 700 | if (ctx->FragmentProgram._Enabled) |
| 701 | return; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 702 | |
Keith Whitwell | 8b88f62 | 2005-05-10 11:39:50 +0000 | [diff] [blame] | 703 | if (!ctx->_TexEnvProgram) |
| 704 | ctx->FragmentProgram._Current = ctx->_TexEnvProgram = |
| 705 | (struct fragment_program *) |
| 706 | ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); |
Keith Whitwell | 276330b | 2005-05-09 17:58:13 +0000 | [diff] [blame] | 707 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 708 | p.ctx = ctx; |
Keith Whitwell | 276330b | 2005-05-09 17:58:13 +0000 | [diff] [blame] | 709 | p.program = ctx->_TexEnvProgram; |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 710 | |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 711 | db_Instructions = p.program->Instructions; |
| 712 | db_NumInstructions = p.program->Base.NumInstructions; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 713 | |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 714 | p.program->Instructions = MALLOC(sizeof(struct fp_instruction) * 100); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 715 | p.program->Base.NumInstructions = 0; |
Keith Whitwell | 276330b | 2005-05-09 17:58:13 +0000 | [diff] [blame] | 716 | p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB; |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 717 | p.program->NumTexIndirections = 1; /* correct? */ |
| 718 | p.program->NumTexInstructions = 0; |
| 719 | p.program->NumAluInstructions = 0; |
Keith Whitwell | 9ca8815 | 2005-05-10 09:56:02 +0000 | [diff] [blame] | 720 | p.program->Base.String = 0; |
| 721 | p.program->Base.NumInstructions = |
| 722 | p.program->Base.NumTemporaries = |
| 723 | p.program->Base.NumParameters = |
| 724 | p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0; |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 725 | |
Keith Whitwell | 9ca8815 | 2005-05-10 09:56:02 +0000 | [diff] [blame] | 726 | if (p.program->Parameters) |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 727 | _mesa_free_parameters(p.program->Parameters); |
| 728 | else |
| 729 | p.program->Parameters = _mesa_new_parameter_list(); |
| 730 | |
Keith Whitwell | 9ca8815 | 2005-05-10 09:56:02 +0000 | [diff] [blame] | 731 | p.program->InputsRead = 0; |
| 732 | p.program->OutputsWritten = 0; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 733 | |
| 734 | p.src_texture = undef; |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 735 | p.src_previous = undef; |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 736 | p.last_tex_stage = 0; |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 737 | release_temps(&p); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 738 | |
| 739 | if (ctx->Texture._EnabledUnits) { |
| 740 | for (unit = 0 ; unit < ctx->Const.MaxTextureUnits ; unit++) |
| 741 | if (ctx->Texture.Unit[unit]._ReallyEnabled) { |
| 742 | p.last_tex_stage = unit; |
| 743 | } |
| 744 | |
| 745 | for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) |
| 746 | if (ctx->Texture.Unit[unit]._ReallyEnabled) { |
| 747 | p.src_previous = emit_texenv( &p, unit ); |
| 748 | p.src_texture = undef; |
Keith Whitwell | 93cd923 | 2005-05-11 08:30:23 +0000 | [diff] [blame] | 749 | release_temps(&p); /* release all temps */ |
| 750 | if (p.src_previous.file == PROGRAM_TEMPORARY) |
| 751 | p.temp_in_use |= 1 << p.src_previous.idx; /* except for this one */ |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
| 755 | cf = get_source( &p, GL_PREVIOUS, 0 ); |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 756 | out = make_ureg( PROGRAM_OUTPUT, FRAG_OUTPUT_COLR ); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 757 | |
| 758 | if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) { |
| 759 | /* Emit specular add. |
| 760 | */ |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 761 | struct ureg s = register_input(&p, FRAG_ATTRIB_COL1); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 762 | emit_arith( &p, FP_OPCODE_ADD, out, WRITEMASK_XYZ, 0, cf, s, undef ); |
| 763 | } |
| 764 | else if (memcmp(&cf, &out, sizeof(cf)) != 0) { |
| 765 | /* Will wind up in here if no texture enabled or a couple of |
| 766 | * other scenarios (GL_REPLACE for instance). |
| 767 | */ |
| 768 | emit_arith( &p, FP_OPCODE_MOV, out, WRITEMASK_XYZW, 0, cf, undef, undef ); |
| 769 | } |
| 770 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 771 | /* Finish up: |
| 772 | */ |
| 773 | emit_arith( &p, FP_OPCODE_END, undef, WRITEMASK_XYZW, 0, undef, undef, undef); |
| 774 | |
Keith Whitwell | 276330b | 2005-05-09 17:58:13 +0000 | [diff] [blame] | 775 | if (ctx->Fog.Enabled) |
| 776 | p.program->FogOption = ctx->Fog.Mode; |
| 777 | else |
| 778 | p.program->FogOption = GL_NONE; |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 779 | |
| 780 | if (p.program->NumTexIndirections > ctx->Const.MaxFragmentProgramTexIndirections) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 781 | program_error(&p, "Exceeded max nr indirect texture lookups"); |
| 782 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 783 | if (p.program->NumTexInstructions > ctx->Const.MaxFragmentProgramTexInstructions) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 784 | program_error(&p, "Exceeded max TEX instructions"); |
| 785 | |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 786 | if (p.program->NumAluInstructions > ctx->Const.MaxFragmentProgramAluInstructions) |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 787 | program_error(&p, "Exceeded max ALU instructions"); |
| 788 | |
| 789 | #if DISASSEM |
Keith Whitwell | 47b29f5 | 2005-05-04 11:44:44 +0000 | [diff] [blame] | 790 | _mesa_debug_fp_inst(p.program->NumTexInstructions + p.program->NumAluInstructions, |
| 791 | p.program->Instructions); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 792 | _mesa_printf("\n"); |
| 793 | #endif |
Keith Whitwell | 8b88f62 | 2005-05-10 11:39:50 +0000 | [diff] [blame] | 794 | |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 795 | /* Notify driver the fragment program has (actually) changed. |
Keith Whitwell | 8b88f62 | 2005-05-10 11:39:50 +0000 | [diff] [blame] | 796 | */ |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 797 | if (db_Instructions == NULL || |
| 798 | db_NumInstructions != p.program->Base.NumInstructions || |
| 799 | memcmp(db_Instructions, p.program->Instructions, |
| 800 | db_NumInstructions * sizeof(*db_Instructions)) != 0) { |
Keith Whitwell | dbeea25 | 2005-05-10 13:57:50 +0000 | [diff] [blame] | 801 | ctx->Driver.ProgramStringNotify( ctx, GL_FRAGMENT_PROGRAM_ARB, |
| 802 | &p.program->Base ); |
| 803 | } |
| 804 | |
| 805 | FREE(db_Instructions); |
Keith Whitwell | 15e75e0 | 2005-04-29 15:11:39 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |