1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Copyright 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 #include "shader/program.h"
32 #include "shader/prog_parameter.h"
33 #include "shader/prog_cache.h"
34 #include "shader/prog_instruction.h"
35 #include "shader/prog_print.h"
36 #include "shader/prog_statevars.h"
37 #include "shader/programopt.h"
38 #include "texenvprogram.h"
42 * Note on texture units:
44 * The number of texture units supported by fixed-function fragment
45 * processing is MAX_TEXTURE_COORD_UNITS, not MAX_TEXTURE_IMAGE_UNITS.
46 * That's because there's a one-to-one correspondence between texture
47 * coordinates and samplers in fixed-function processing.
49 * Since fixed-function vertex processing is limited to MAX_TEXTURE_COORD_UNITS
50 * sets of texcoords, so is fixed-function fragment processing.
52 * We can safely use ctx->Const.MaxTextureUnits for loop bounds.
56 struct texenvprog_cache_item
60 struct gl_fragment_program
*data
;
61 struct texenvprog_cache_item
*next
;
65 texenv_doing_secondary_color(GLcontext
*ctx
)
67 if (ctx
->Light
.Enabled
&&
68 (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
))
71 if (ctx
->Fog
.ColorSumEnabled
)
78 * Up to nine instructions per tex unit, plus fog, specular color.
80 #define MAX_INSTRUCTIONS ((MAX_TEXTURE_COORD_UNITS * 9) + 12)
82 #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
85 GLuint Source
:4; /**< SRC_x */
86 GLuint Operand
:3; /**< OPR_x */
90 GLuint nr_enabled_units
:8;
91 GLuint enabled_units
:8;
92 GLuint separate_specular
:1;
94 GLuint fog_mode
:2; /**< FOG_x */
95 GLuint inputs_available
:12;
99 GLuint source_index
:3; /**< TEXTURE_x_INDEX */
101 GLuint ScaleShiftRGB
:2;
102 GLuint ScaleShiftA
:2;
104 GLuint NumArgsRGB
:3; /**< up to MAX_COMBINER_TERMS */
105 GLuint ModeRGB
:5; /**< MODE_x */
106 struct mode_opt OptRGB
[MAX_COMBINER_TERMS
];
108 GLuint NumArgsA
:3; /**< up to MAX_COMBINER_TERMS */
109 GLuint ModeA
:5; /**< MODE_x */
110 struct mode_opt OptA
[MAX_COMBINER_TERMS
];
111 } unit
[MAX_TEXTURE_UNITS
];
117 #define FOG_UNKNOWN 3
119 static GLuint
translate_fog_mode( GLenum mode
)
122 case GL_LINEAR
: return FOG_LINEAR
;
123 case GL_EXP
: return FOG_EXP
;
124 case GL_EXP2
: return FOG_EXP2
;
125 default: return FOG_UNKNOWN
;
129 #define OPR_SRC_COLOR 0
130 #define OPR_ONE_MINUS_SRC_COLOR 1
131 #define OPR_SRC_ALPHA 2
132 #define OPR_ONE_MINUS_SRC_ALPHA 3
135 #define OPR_UNKNOWN 7
137 static GLuint
translate_operand( GLenum operand
)
140 case GL_SRC_COLOR
: return OPR_SRC_COLOR
;
141 case GL_ONE_MINUS_SRC_COLOR
: return OPR_ONE_MINUS_SRC_COLOR
;
142 case GL_SRC_ALPHA
: return OPR_SRC_ALPHA
;
143 case GL_ONE_MINUS_SRC_ALPHA
: return OPR_ONE_MINUS_SRC_ALPHA
;
144 case GL_ZERO
: return OPR_ZERO
;
145 case GL_ONE
: return OPR_ONE
;
152 #define SRC_TEXTURE 0
153 #define SRC_TEXTURE0 1
154 #define SRC_TEXTURE1 2
155 #define SRC_TEXTURE2 3
156 #define SRC_TEXTURE3 4
157 #define SRC_TEXTURE4 5
158 #define SRC_TEXTURE5 6
159 #define SRC_TEXTURE6 7
160 #define SRC_TEXTURE7 8
161 #define SRC_CONSTANT 9
162 #define SRC_PRIMARY_COLOR 10
163 #define SRC_PREVIOUS 11
165 #define SRC_UNKNOWN 15
167 static GLuint
translate_source( GLenum src
)
170 case GL_TEXTURE
: return SRC_TEXTURE
;
178 case GL_TEXTURE7
: return SRC_TEXTURE0
+ (src
- GL_TEXTURE0
);
179 case GL_CONSTANT
: return SRC_CONSTANT
;
180 case GL_PRIMARY_COLOR
: return SRC_PRIMARY_COLOR
;
181 case GL_PREVIOUS
: return SRC_PREVIOUS
;
190 #define MODE_REPLACE 0 /* r = a0 */
191 #define MODE_MODULATE 1 /* r = a0 * a1 */
192 #define MODE_ADD 2 /* r = a0 + a1 */
193 #define MODE_ADD_SIGNED 3 /* r = a0 + a1 - 0.5 */
194 #define MODE_INTERPOLATE 4 /* r = a0 * a2 + a1 * (1 - a2) */
195 #define MODE_SUBTRACT 5 /* r = a0 - a1 */
196 #define MODE_DOT3_RGB 6 /* r = a0 . a1 */
197 #define MODE_DOT3_RGB_EXT 7 /* r = a0 . a1 */
198 #define MODE_DOT3_RGBA 8 /* r = a0 . a1 */
199 #define MODE_DOT3_RGBA_EXT 9 /* r = a0 . a1 */
200 #define MODE_MODULATE_ADD_ATI 10 /* r = a0 * a2 + a1 */
201 #define MODE_MODULATE_SIGNED_ADD_ATI 11 /* r = a0 * a2 + a1 - 0.5 */
202 #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */
203 #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */
204 #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */
205 #define MODE_BUMP_ENVMAP_ATI 15 /* special */
206 #define MODE_UNKNOWN 16
209 * Translate GL combiner state into a MODE_x value
211 static GLuint
translate_mode( GLenum envMode
, GLenum mode
)
214 case GL_REPLACE
: return MODE_REPLACE
;
215 case GL_MODULATE
: return MODE_MODULATE
;
217 if (envMode
== GL_COMBINE4_NV
)
218 return MODE_ADD_PRODUCTS
;
222 if (envMode
== GL_COMBINE4_NV
)
223 return MODE_ADD_PRODUCTS_SIGNED
;
225 return MODE_ADD_SIGNED
;
226 case GL_INTERPOLATE
: return MODE_INTERPOLATE
;
227 case GL_SUBTRACT
: return MODE_SUBTRACT
;
228 case GL_DOT3_RGB
: return MODE_DOT3_RGB
;
229 case GL_DOT3_RGB_EXT
: return MODE_DOT3_RGB_EXT
;
230 case GL_DOT3_RGBA
: return MODE_DOT3_RGBA
;
231 case GL_DOT3_RGBA_EXT
: return MODE_DOT3_RGBA_EXT
;
232 case GL_MODULATE_ADD_ATI
: return MODE_MODULATE_ADD_ATI
;
233 case GL_MODULATE_SIGNED_ADD_ATI
: return MODE_MODULATE_SIGNED_ADD_ATI
;
234 case GL_MODULATE_SUBTRACT_ATI
: return MODE_MODULATE_SUBTRACT_ATI
;
235 case GL_BUMP_ENVMAP_ATI
: return MODE_BUMP_ENVMAP_ATI
;
244 * Translate TEXTURE_x_BIT to TEXTURE_x_INDEX.
246 static GLuint
translate_tex_src_bit( GLbitfield bit
)
249 return _mesa_ffs(bit
) - 1;
253 #define VERT_BIT_TEX_ANY (0xff << VERT_ATTRIB_TEX0)
254 #define VERT_RESULT_TEX_ANY (0xff << VERT_RESULT_TEX0)
257 * Identify all possible varying inputs. The fragment program will
258 * never reference non-varying inputs, but will track them via state
261 * This function figures out all the inputs that the fragment program
262 * has access to. The bitmask is later reduced to just those which
263 * are actually referenced.
265 static GLbitfield
get_fp_input_mask( GLcontext
*ctx
)
268 const GLboolean vertexShader
= (ctx
->Shader
.CurrentProgram
&&
269 ctx
->Shader
.CurrentProgram
->LinkStatus
&&
270 ctx
->Shader
.CurrentProgram
->VertexProgram
);
271 const GLboolean vertexProgram
= ctx
->VertexProgram
._Enabled
;
272 GLbitfield fp_inputs
= 0x0;
274 if (ctx
->VertexProgram
._Overriden
) {
275 /* Somebody's messing with the vertex program and we don't have
276 * a clue what's happening. Assume that it could be producing
277 * all possible outputs.
281 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
282 /* _NEW_RENDERMODE */
283 fp_inputs
= (FRAG_BIT_COL0
| FRAG_BIT_TEX0
);
285 else if (!(vertexProgram
|| vertexShader
) ||
286 !ctx
->VertexProgram
._Current
) {
287 /* Fixed function vertex logic */
289 GLbitfield varying_inputs
= ctx
->varying_vp_inputs
;
291 /* These get generated in the setup routine regardless of the
295 if (ctx
->Point
.PointSprite
)
296 varying_inputs
|= FRAG_BITS_TEX_ANY
;
298 /* First look at what values may be computed by the generated
302 if (ctx
->Light
.Enabled
) {
303 fp_inputs
|= FRAG_BIT_COL0
;
305 if (texenv_doing_secondary_color(ctx
))
306 fp_inputs
|= FRAG_BIT_COL1
;
310 fp_inputs
|= (ctx
->Texture
._TexGenEnabled
|
311 ctx
->Texture
._TexMatEnabled
) << FRAG_ATTRIB_TEX0
;
313 /* Then look at what might be varying as a result of enabled
316 if (varying_inputs
& VERT_BIT_COLOR0
)
317 fp_inputs
|= FRAG_BIT_COL0
;
318 if (varying_inputs
& VERT_BIT_COLOR1
)
319 fp_inputs
|= FRAG_BIT_COL1
;
321 fp_inputs
|= (((varying_inputs
& VERT_BIT_TEX_ANY
) >> VERT_ATTRIB_TEX0
)
322 << FRAG_ATTRIB_TEX0
);
326 /* calculate from vp->outputs */
327 struct gl_vertex_program
*vprog
;
328 GLbitfield vp_outputs
;
330 /* Choose GLSL vertex shader over ARB vertex program. Need this
331 * since vertex shader state validation comes after fragment state
332 * validation (see additional comments in state.c).
335 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
337 vprog
= ctx
->VertexProgram
.Current
;
339 vp_outputs
= vprog
->Base
.OutputsWritten
;
341 /* These get generated in the setup routine regardless of the
345 if (ctx
->Point
.PointSprite
)
346 vp_outputs
|= FRAG_BITS_TEX_ANY
;
348 if (vp_outputs
& (1 << VERT_RESULT_COL0
))
349 fp_inputs
|= FRAG_BIT_COL0
;
350 if (vp_outputs
& (1 << VERT_RESULT_COL1
))
351 fp_inputs
|= FRAG_BIT_COL1
;
353 fp_inputs
|= (((vp_outputs
& VERT_RESULT_TEX_ANY
) >> VERT_RESULT_TEX0
)
354 << FRAG_ATTRIB_TEX0
);
362 * Examine current texture environment state and generate a unique
363 * key to identify it.
365 static void make_state_key( GLcontext
*ctx
, struct state_key
*key
)
368 GLbitfield inputs_referenced
= FRAG_BIT_COL0
;
369 const GLbitfield inputs_available
= get_fp_input_mask( ctx
);
371 memset(key
, 0, sizeof(*key
));
374 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
375 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
376 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
377 const struct gl_tex_env_combine_state
*comb
= texUnit
->_CurrentCombine
;
380 if (!texUnit
->_ReallyEnabled
|| !texUnit
->Enabled
)
383 format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
385 key
->unit
[i
].enabled
= 1;
386 key
->enabled_units
|= (1<<i
);
387 key
->nr_enabled_units
= i
+1;
388 inputs_referenced
|= FRAG_BIT_TEX(i
);
390 key
->unit
[i
].source_index
=
391 translate_tex_src_bit(texUnit
->_ReallyEnabled
);
393 key
->unit
[i
].shadow
= ((texObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE
) &&
394 ((format
== GL_DEPTH_COMPONENT
) ||
395 (format
== GL_DEPTH_STENCIL_EXT
)));
397 key
->unit
[i
].NumArgsRGB
= comb
->_NumArgsRGB
;
398 key
->unit
[i
].NumArgsA
= comb
->_NumArgsA
;
400 key
->unit
[i
].ModeRGB
=
401 translate_mode(texUnit
->EnvMode
, comb
->ModeRGB
);
403 translate_mode(texUnit
->EnvMode
, comb
->ModeA
);
405 key
->unit
[i
].ScaleShiftRGB
= comb
->ScaleShiftRGB
;
406 key
->unit
[i
].ScaleShiftA
= comb
->ScaleShiftA
;
408 for (j
= 0; j
< MAX_COMBINER_TERMS
; j
++) {
409 key
->unit
[i
].OptRGB
[j
].Operand
= translate_operand(comb
->OperandRGB
[j
]);
410 key
->unit
[i
].OptA
[j
].Operand
= translate_operand(comb
->OperandA
[j
]);
411 key
->unit
[i
].OptRGB
[j
].Source
= translate_source(comb
->SourceRGB
[j
]);
412 key
->unit
[i
].OptA
[j
].Source
= translate_source(comb
->SourceA
[j
]);
415 if (key
->unit
[i
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
416 /* requires some special translation */
417 key
->unit
[i
].NumArgsRGB
= 2;
418 key
->unit
[i
].ScaleShiftRGB
= 0;
419 key
->unit
[i
].OptRGB
[0].Operand
= OPR_SRC_COLOR
;
420 key
->unit
[i
].OptRGB
[0].Source
= SRC_TEXTURE
;
421 key
->unit
[i
].OptRGB
[1].Operand
= OPR_SRC_COLOR
;
422 key
->unit
[i
].OptRGB
[1].Source
= texUnit
->BumpTarget
- GL_TEXTURE0
+ SRC_TEXTURE0
;
426 /* _NEW_LIGHT | _NEW_FOG */
427 if (texenv_doing_secondary_color(ctx
)) {
428 key
->separate_specular
= 1;
429 inputs_referenced
|= FRAG_BIT_COL1
;
433 if (ctx
->Fog
.Enabled
) {
434 key
->fog_enabled
= 1;
435 key
->fog_mode
= translate_fog_mode(ctx
->Fog
.Mode
);
436 inputs_referenced
|= FRAG_BIT_FOGC
; /* maybe */
439 key
->inputs_available
= (inputs_available
& inputs_referenced
);
443 * Use uregs to represent registers internally, translate to Mesa's
444 * expected formats on emit.
446 * NOTE: These are passed by value extensively in this file rather
447 * than as usual by pointer reference. If this disturbs you, try
448 * remembering they are just 32bits in size.
450 * GCC is smart enough to deal with these dword-sized structures in
451 * much the same way as if I had defined them as dwords and was using
452 * macros to access and set the fields. This is much nicer and easier
463 static const struct ureg undef
= {
472 /** State used to build the fragment program:
474 struct texenv_fragment_program
{
475 struct gl_fragment_program
*program
;
476 struct state_key
*state
;
478 GLbitfield alu_temps
; /**< Track texture indirections, see spec. */
479 GLbitfield temps_output
; /**< Track texture indirections, see spec. */
480 GLbitfield temp_in_use
; /**< Tracks temporary regs which are in use. */
483 struct ureg src_texture
[MAX_TEXTURE_COORD_UNITS
];
484 /* Reg containing each texture unit's sampled texture color,
488 struct ureg texcoord_tex
[MAX_TEXTURE_COORD_UNITS
];
489 /* Reg containing texcoord for a texture unit,
490 * needed for bump mapping, else undef.
493 struct ureg src_previous
; /**< Reg containing color from previous
494 * stage. May need to be decl'd.
497 GLuint last_tex_stage
; /**< Number of last enabled texture unit */
506 static struct ureg
make_ureg(GLuint file
, GLuint idx
)
512 reg
.swz
= SWIZZLE_NOOP
;
517 static struct ureg
swizzle( struct ureg reg
, int x
, int y
, int z
, int w
)
519 reg
.swz
= MAKE_SWIZZLE4(GET_SWZ(reg
.swz
, x
),
522 GET_SWZ(reg
.swz
, w
));
527 static struct ureg
swizzle1( struct ureg reg
, int x
)
529 return swizzle(reg
, x
, x
, x
, x
);
532 static struct ureg
negate( struct ureg reg
)
538 static GLboolean
is_undef( struct ureg reg
)
540 return reg
.file
== PROGRAM_UNDEFINED
;
544 static struct ureg
get_temp( struct texenv_fragment_program
*p
)
548 /* First try and reuse temps which have been used already:
550 bit
= _mesa_ffs( ~p
->temp_in_use
& p
->alu_temps
);
552 /* Then any unused temporary:
555 bit
= _mesa_ffs( ~p
->temp_in_use
);
558 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
562 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
563 p
->program
->Base
.NumTemporaries
= bit
;
565 p
->temp_in_use
|= 1<<(bit
-1);
566 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
569 static struct ureg
get_tex_temp( struct texenv_fragment_program
*p
)
573 /* First try to find available temp not previously used (to avoid
574 * starting a new texture indirection). According to the spec, the
575 * ~p->temps_output isn't necessary, but will keep it there for
578 bit
= _mesa_ffs( ~p
->temp_in_use
& ~p
->alu_temps
& ~p
->temps_output
);
580 /* Then any unused temporary:
583 bit
= _mesa_ffs( ~p
->temp_in_use
);
586 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
590 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
591 p
->program
->Base
.NumTemporaries
= bit
;
593 p
->temp_in_use
|= 1<<(bit
-1);
594 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
598 /** Mark a temp reg as being no longer allocatable. */
599 static void reserve_temp( struct texenv_fragment_program
*p
, struct ureg r
)
601 if (r
.file
== PROGRAM_TEMPORARY
)
602 p
->temps_output
|= (1 << r
.idx
);
606 static void release_temps(GLcontext
*ctx
, struct texenv_fragment_program
*p
)
608 GLuint max_temp
= ctx
->Const
.FragmentProgram
.MaxTemps
;
610 /* KW: To support tex_env_crossbar, don't release the registers in
613 if (max_temp
>= sizeof(int) * 8)
614 p
->temp_in_use
= p
->temps_output
;
616 p
->temp_in_use
= ~((1<<max_temp
)-1) | p
->temps_output
;
620 static struct ureg
register_param5( struct texenv_fragment_program
*p
,
627 gl_state_index tokens
[STATE_LENGTH
];
634 idx
= _mesa_add_state_reference( p
->program
->Base
.Parameters
, tokens
);
635 return make_ureg(PROGRAM_STATE_VAR
, idx
);
639 #define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
640 #define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
641 #define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
642 #define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
644 static GLuint
frag_to_vert_attrib( GLuint attrib
)
647 case FRAG_ATTRIB_COL0
: return VERT_ATTRIB_COLOR0
;
648 case FRAG_ATTRIB_COL1
: return VERT_ATTRIB_COLOR1
;
650 assert(attrib
>= FRAG_ATTRIB_TEX0
);
651 assert(attrib
<= FRAG_ATTRIB_TEX7
);
652 return attrib
- FRAG_ATTRIB_TEX0
+ VERT_ATTRIB_TEX0
;
657 static struct ureg
register_input( struct texenv_fragment_program
*p
, GLuint input
)
659 if (p
->state
->inputs_available
& (1<<input
)) {
660 p
->program
->Base
.InputsRead
|= (1 << input
);
661 return make_ureg(PROGRAM_INPUT
, input
);
664 GLuint idx
= frag_to_vert_attrib( input
);
665 return register_param3( p
, STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, idx
);
670 static void emit_arg( struct prog_src_register
*reg
,
673 reg
->File
= ureg
.file
;
674 reg
->Index
= ureg
.idx
;
675 reg
->Swizzle
= ureg
.swz
;
676 reg
->Negate
= ureg
.negatebase
? NEGATE_XYZW
: NEGATE_NONE
;
680 static void emit_dst( struct prog_dst_register
*dst
,
681 struct ureg ureg
, GLuint mask
)
683 dst
->File
= ureg
.file
;
684 dst
->Index
= ureg
.idx
;
685 dst
->WriteMask
= mask
;
686 dst
->CondMask
= COND_TR
; /* always pass cond test */
687 dst
->CondSwizzle
= SWIZZLE_NOOP
;
690 static struct prog_instruction
*
691 emit_op(struct texenv_fragment_program
*p
,
700 const GLuint nr
= p
->program
->Base
.NumInstructions
++;
701 struct prog_instruction
*inst
= &p
->program
->Base
.Instructions
[nr
];
703 assert(nr
< MAX_INSTRUCTIONS
);
705 _mesa_init_instructions(inst
, 1);
708 emit_arg( &inst
->SrcReg
[0], src0
);
709 emit_arg( &inst
->SrcReg
[1], src1
);
710 emit_arg( &inst
->SrcReg
[2], src2
);
712 inst
->SaturateMode
= saturate
? SATURATE_ZERO_ONE
: SATURATE_OFF
;
714 emit_dst( &inst
->DstReg
, dest
, mask
);
717 /* Accounting for indirection tracking:
719 if (dest
.file
== PROGRAM_TEMPORARY
)
720 p
->temps_output
|= 1 << dest
.idx
;
727 static struct ureg
emit_arith( struct texenv_fragment_program
*p
,
736 emit_op(p
, op
, dest
, mask
, saturate
, src0
, src1
, src2
);
738 /* Accounting for indirection tracking:
740 if (src0
.file
== PROGRAM_TEMPORARY
)
741 p
->alu_temps
|= 1 << src0
.idx
;
743 if (!is_undef(src1
) && src1
.file
== PROGRAM_TEMPORARY
)
744 p
->alu_temps
|= 1 << src1
.idx
;
746 if (!is_undef(src2
) && src2
.file
== PROGRAM_TEMPORARY
)
747 p
->alu_temps
|= 1 << src2
.idx
;
749 if (dest
.file
== PROGRAM_TEMPORARY
)
750 p
->alu_temps
|= 1 << dest
.idx
;
752 p
->program
->Base
.NumAluInstructions
++;
756 static struct ureg
emit_texld( struct texenv_fragment_program
*p
,
765 struct prog_instruction
*inst
= emit_op( p
, op
,
767 GL_FALSE
, /* don't saturate? */
772 inst
->TexSrcTarget
= tex_idx
;
773 inst
->TexSrcUnit
= tex_unit
;
774 inst
->TexShadow
= tex_shadow
;
776 p
->program
->Base
.NumTexInstructions
++;
778 /* Accounting for indirection tracking:
780 reserve_temp(p
, dest
);
783 /* Is this a texture indirection?
785 if ((coord
.file
== PROGRAM_TEMPORARY
&&
786 (p
->temps_output
& (1<<coord
.idx
))) ||
787 (dest
.file
== PROGRAM_TEMPORARY
&&
788 (p
->alu_temps
& (1<<dest
.idx
)))) {
789 p
->program
->Base
.NumTexIndirections
++;
790 p
->temps_output
= 1<<coord
.idx
;
792 assert(0); /* KW: texture env crossbar */
800 static struct ureg
register_const4f( struct texenv_fragment_program
*p
,
813 idx
= _mesa_add_unnamed_constant( p
->program
->Base
.Parameters
, values
, 4,
815 r
= make_ureg(PROGRAM_CONSTANT
, idx
);
820 #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
821 #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
822 #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
823 #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
826 static struct ureg
get_one( struct texenv_fragment_program
*p
)
828 if (is_undef(p
->one
))
829 p
->one
= register_scalar_const(p
, 1.0);
833 static struct ureg
get_half( struct texenv_fragment_program
*p
)
835 if (is_undef(p
->half
))
836 p
->half
= register_scalar_const(p
, 0.5);
840 static struct ureg
get_zero( struct texenv_fragment_program
*p
)
842 if (is_undef(p
->zero
))
843 p
->zero
= register_scalar_const(p
, 0.0);
848 static void program_error( struct texenv_fragment_program
*p
, const char *msg
)
850 _mesa_problem(NULL
, msg
);
854 static struct ureg
get_source( struct texenv_fragment_program
*p
,
855 GLuint src
, GLuint unit
)
859 assert(!is_undef(p
->src_texture
[unit
]));
860 return p
->src_texture
[unit
];
870 assert(!is_undef(p
->src_texture
[src
- SRC_TEXTURE0
]));
871 return p
->src_texture
[src
- SRC_TEXTURE0
];
874 return register_param2(p
, STATE_TEXENV_COLOR
, unit
);
876 case SRC_PRIMARY_COLOR
:
877 return register_input(p
, FRAG_ATTRIB_COL0
);
883 if (is_undef(p
->src_previous
))
884 return register_input(p
, FRAG_ATTRIB_COL0
);
886 return p
->src_previous
;
894 static struct ureg
emit_combine_source( struct texenv_fragment_program
*p
,
900 struct ureg arg
, src
, one
;
902 src
= get_source(p
, source
, unit
);
905 case OPR_ONE_MINUS_SRC_COLOR
:
907 * Emit tmp = 1.0 - arg.xyzw
911 return emit_arith( p
, OPCODE_SUB
, arg
, mask
, 0, one
, src
, undef
);
914 if (mask
== WRITEMASK_W
)
917 return swizzle1( src
, SWIZZLE_W
);
918 case OPR_ONE_MINUS_SRC_ALPHA
:
920 * Emit tmp = 1.0 - arg.wwww
924 return emit_arith(p
, OPCODE_SUB
, arg
, mask
, 0,
925 one
, swizzle1(src
, SWIZZLE_W
), undef
);
939 * Check if the RGB and Alpha sources and operands match for the given
940 * texture unit's combinder state. When the RGB and A sources and
941 * operands match, we can emit fewer instructions.
943 static GLboolean
args_match( const struct state_key
*key
, GLuint unit
)
945 GLuint i
, numArgs
= key
->unit
[unit
].NumArgsRGB
;
947 for (i
= 0 ; i
< numArgs
; i
++) {
948 if (key
->unit
[unit
].OptA
[i
].Source
!= key
->unit
[unit
].OptRGB
[i
].Source
)
951 switch (key
->unit
[unit
].OptA
[i
].Operand
) {
953 switch (key
->unit
[unit
].OptRGB
[i
].Operand
) {
961 case OPR_ONE_MINUS_SRC_ALPHA
:
962 switch (key
->unit
[unit
].OptRGB
[i
].Operand
) {
963 case OPR_ONE_MINUS_SRC_COLOR
:
964 case OPR_ONE_MINUS_SRC_ALPHA
:
971 return GL_FALSE
; /* impossible */
978 static struct ureg
emit_combine( struct texenv_fragment_program
*p
,
985 const struct mode_opt
*opt
)
987 struct ureg src
[MAX_COMBINER_TERMS
];
988 struct ureg tmp
, half
;
991 assert(nr
<= MAX_COMBINER_TERMS
);
993 tmp
= undef
; /* silence warning (bug 5318) */
995 for (i
= 0; i
< nr
; i
++)
996 src
[i
] = emit_combine_source( p
, mask
, unit
, opt
[i
].Source
, opt
[i
].Operand
);
1000 if (mask
== WRITEMASK_XYZW
&& !saturate
)
1003 return emit_arith( p
, OPCODE_MOV
, dest
, mask
, saturate
, src
[0], undef
, undef
);
1005 return emit_arith( p
, OPCODE_MUL
, dest
, mask
, saturate
,
1006 src
[0], src
[1], undef
);
1008 return emit_arith( p
, OPCODE_ADD
, dest
, mask
, saturate
,
1009 src
[0], src
[1], undef
);
1010 case MODE_ADD_SIGNED
:
1011 /* tmp = arg0 + arg1
1015 tmp
= get_temp( p
);
1016 emit_arith( p
, OPCODE_ADD
, tmp
, mask
, 0, src
[0], src
[1], undef
);
1017 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp
, half
, undef
);
1019 case MODE_INTERPOLATE
:
1020 /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered:
1022 return emit_arith( p
, OPCODE_LRP
, dest
, mask
, saturate
, src
[2], src
[0], src
[1] );
1025 return emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, src
[0], src
[1], undef
);
1027 case MODE_DOT3_RGBA
:
1028 case MODE_DOT3_RGBA_EXT
:
1029 case MODE_DOT3_RGB_EXT
:
1030 case MODE_DOT3_RGB
: {
1031 struct ureg tmp0
= get_temp( p
);
1032 struct ureg tmp1
= get_temp( p
);
1033 struct ureg neg1
= register_scalar_const(p
, -1);
1034 struct ureg two
= register_scalar_const(p
, 2);
1036 /* tmp0 = 2*src0 - 1
1039 * dst = tmp0 dot3 tmp1
1041 emit_arith( p
, OPCODE_MAD
, tmp0
, WRITEMASK_XYZW
, 0,
1044 if (_mesa_memcmp(&src
[0], &src
[1], sizeof(struct ureg
)) == 0)
1047 emit_arith( p
, OPCODE_MAD
, tmp1
, WRITEMASK_XYZW
, 0,
1049 emit_arith( p
, OPCODE_DP3
, dest
, mask
, saturate
, tmp0
, tmp1
, undef
);
1052 case MODE_MODULATE_ADD_ATI
:
1053 /* Arg0 * Arg2 + Arg1 */
1054 return emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
,
1055 src
[0], src
[2], src
[1] );
1056 case MODE_MODULATE_SIGNED_ADD_ATI
: {
1057 /* Arg0 * Arg2 + Arg1 - 0.5 */
1058 struct ureg tmp0
= get_temp(p
);
1060 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[0], src
[2], src
[1] );
1061 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1064 case MODE_MODULATE_SUBTRACT_ATI
:
1065 /* Arg0 * Arg2 - Arg1 */
1066 emit_arith( p
, OPCODE_MAD
, dest
, mask
, 0, src
[0], src
[2], negate(src
[1]) );
1068 case MODE_ADD_PRODUCTS
:
1069 /* Arg0 * Arg1 + Arg2 * Arg3 */
1071 struct ureg tmp0
= get_temp(p
);
1072 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1073 emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
, src
[2], src
[3], tmp0
);
1076 case MODE_ADD_PRODUCTS_SIGNED
:
1077 /* Arg0 * Arg1 + Arg2 * Arg3 - 0.5 */
1079 struct ureg tmp0
= get_temp(p
);
1081 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1082 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[2], src
[3], tmp0
);
1083 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1086 case MODE_BUMP_ENVMAP_ATI
:
1087 /* special - not handled here */
1098 * Generate instructions for one texture unit's env/combiner mode.
1101 emit_texenv(struct texenv_fragment_program
*p
, GLuint unit
)
1103 const struct state_key
*key
= p
->state
;
1105 GLuint rgb_shift
, alpha_shift
;
1106 struct ureg out
, dest
;
1108 if (!key
->unit
[unit
].enabled
) {
1109 return get_source(p
, SRC_PREVIOUS
, 0);
1111 if (key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1112 /* this isn't really a env stage delivering a color and handled elsewhere */
1113 return get_source(p
, SRC_PREVIOUS
, 0);
1116 switch (key
->unit
[unit
].ModeRGB
) {
1117 case MODE_DOT3_RGB_EXT
:
1118 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1121 case MODE_DOT3_RGBA_EXT
:
1126 rgb_shift
= key
->unit
[unit
].ScaleShiftRGB
;
1127 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1131 /* If we'll do rgb/alpha shifting don't saturate in emit_combine().
1132 * We don't want to clamp twice.
1134 saturate
= !(rgb_shift
|| alpha_shift
);
1136 /* If this is the very last calculation, emit direct to output reg:
1138 if (key
->separate_specular
||
1139 unit
!= p
->last_tex_stage
||
1142 dest
= get_temp( p
);
1144 dest
= make_ureg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1146 /* Emit the RGB and A combine ops
1148 if (key
->unit
[unit
].ModeRGB
== key
->unit
[unit
].ModeA
&&
1149 args_match(key
, unit
)) {
1150 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1152 key
->unit
[unit
].NumArgsRGB
,
1153 key
->unit
[unit
].ModeRGB
,
1154 key
->unit
[unit
].OptRGB
);
1156 else if (key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA_EXT
||
1157 key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA
) {
1158 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1160 key
->unit
[unit
].NumArgsRGB
,
1161 key
->unit
[unit
].ModeRGB
,
1162 key
->unit
[unit
].OptRGB
);
1165 /* Need to do something to stop from re-emitting identical
1166 * argument calculations here:
1168 out
= emit_combine( p
, dest
, WRITEMASK_XYZ
, saturate
,
1170 key
->unit
[unit
].NumArgsRGB
,
1171 key
->unit
[unit
].ModeRGB
,
1172 key
->unit
[unit
].OptRGB
);
1173 out
= emit_combine( p
, dest
, WRITEMASK_W
, saturate
,
1175 key
->unit
[unit
].NumArgsA
,
1176 key
->unit
[unit
].ModeA
,
1177 key
->unit
[unit
].OptA
);
1180 /* Deal with the final shift:
1182 if (alpha_shift
|| rgb_shift
) {
1185 saturate
= GL_TRUE
; /* always saturate at this point */
1187 if (rgb_shift
== alpha_shift
) {
1188 shift
= register_scalar_const(p
, (GLfloat
)(1<<rgb_shift
));
1191 shift
= register_const4f(p
,
1192 (GLfloat
)(1<<rgb_shift
),
1193 (GLfloat
)(1<<rgb_shift
),
1194 (GLfloat
)(1<<rgb_shift
),
1195 (GLfloat
)(1<<alpha_shift
));
1197 return emit_arith( p
, OPCODE_MUL
, dest
, WRITEMASK_XYZW
,
1198 saturate
, out
, shift
, undef
);
1206 * Generate instruction for getting a texture source term.
1208 static void load_texture( struct texenv_fragment_program
*p
, GLuint unit
)
1210 if (is_undef(p
->src_texture
[unit
])) {
1211 const GLuint texTarget
= p
->state
->unit
[unit
].source_index
;
1212 struct ureg texcoord
;
1213 struct ureg tmp
= get_tex_temp( p
);
1215 if (is_undef(p
->texcoord_tex
[unit
])) {
1216 texcoord
= register_input(p
, FRAG_ATTRIB_TEX0
+unit
);
1219 /* might want to reuse this reg for tex output actually */
1220 texcoord
= p
->texcoord_tex
[unit
];
1223 /* TODO: Use D0_MASK_XY where possible.
1225 if (p
->state
->unit
[unit
].enabled
) {
1226 GLboolean shadow
= GL_FALSE
;
1228 if (p
->state
->unit
[unit
].shadow
) {
1229 p
->program
->Base
.ShadowSamplers
|= 1 << unit
;
1233 p
->src_texture
[unit
] = emit_texld( p
, OPCODE_TXP
,
1234 tmp
, WRITEMASK_XYZW
,
1235 unit
, texTarget
, shadow
,
1238 p
->program
->Base
.SamplersUsed
|= (1 << unit
);
1239 /* This identity mapping should already be in place
1240 * (see _mesa_init_program_struct()) but let's be safe.
1242 p
->program
->Base
.SamplerUnits
[unit
] = unit
;
1245 p
->src_texture
[unit
] = get_zero(p
);
1249 static GLboolean
load_texenv_source( struct texenv_fragment_program
*p
,
1250 GLuint src
, GLuint unit
)
1254 load_texture(p
, unit
);
1265 load_texture(p
, src
- SRC_TEXTURE0
);
1269 /* not a texture src - do nothing */
1278 * Generate instructions for loading all texture source terms.
1281 load_texunit_sources( struct texenv_fragment_program
*p
, int unit
)
1283 const struct state_key
*key
= p
->state
;
1286 for (i
= 0; i
< key
->unit
[unit
].NumArgsRGB
; i
++) {
1287 load_texenv_source( p
, key
->unit
[unit
].OptRGB
[i
].Source
, unit
);
1290 for (i
= 0; i
< key
->unit
[unit
].NumArgsA
; i
++) {
1291 load_texenv_source( p
, key
->unit
[unit
].OptA
[i
].Source
, unit
);
1298 * Generate instructions for loading bump map textures.
1301 load_texunit_bumpmap( struct texenv_fragment_program
*p
, int unit
)
1303 const struct state_key
*key
= p
->state
;
1304 GLuint bumpedUnitNr
= key
->unit
[unit
].OptRGB
[1].Source
- SRC_TEXTURE0
;
1305 struct ureg texcDst
, bumpMapRes
;
1306 struct ureg constdudvcolor
= register_const4f(p
, 0.0, 0.0, 0.0, 1.0);
1307 struct ureg texcSrc
= register_input(p
, FRAG_ATTRIB_TEX0
+ bumpedUnitNr
);
1308 struct ureg rotMat0
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_0
, unit
);
1309 struct ureg rotMat1
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_1
, unit
);
1311 load_texenv_source( p
, unit
+ SRC_TEXTURE0
, unit
);
1313 bumpMapRes
= get_source(p
, key
->unit
[unit
].OptRGB
[0].Source
, unit
);
1314 texcDst
= get_tex_temp( p
);
1315 p
->texcoord_tex
[bumpedUnitNr
] = texcDst
;
1317 /* apply rot matrix and add coords to be available in next phase */
1318 /* dest = (Arg0.xxxx * rotMat0 + Arg1) + (Arg0.yyyy * rotMat1) */
1319 /* note only 2 coords are affected the rest are left unchanged (mul by 0) */
1320 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1321 swizzle1(bumpMapRes
, SWIZZLE_X
), rotMat0
, texcSrc
);
1322 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1323 swizzle1(bumpMapRes
, SWIZZLE_Y
), rotMat1
, texcDst
);
1325 /* move 0,0,0,1 into bumpmap src if someone (crossbar) is foolish
1326 enough to access this later, should optimize away */
1327 emit_arith( p
, OPCODE_MOV
, bumpMapRes
, WRITEMASK_XYZW
, 0, constdudvcolor
, undef
, undef
);
1333 * Generate a new fragment program which implements the context's
1334 * current texture env/combine mode.
1337 create_new_program(GLcontext
*ctx
, struct state_key
*key
,
1338 struct gl_fragment_program
*program
)
1340 struct prog_instruction instBuffer
[MAX_INSTRUCTIONS
];
1341 struct texenv_fragment_program p
;
1343 struct ureg cf
, out
;
1345 _mesa_memset(&p
, 0, sizeof(p
));
1347 p
.program
= program
;
1349 /* During code generation, use locally-allocated instruction buffer,
1350 * then alloc dynamic storage below.
1352 p
.program
->Base
.Instructions
= instBuffer
;
1353 p
.program
->Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
1354 p
.program
->Base
.NumTexIndirections
= 1;
1355 p
.program
->Base
.NumTexInstructions
= 0;
1356 p
.program
->Base
.NumAluInstructions
= 0;
1357 p
.program
->Base
.String
= NULL
;
1358 p
.program
->Base
.NumInstructions
=
1359 p
.program
->Base
.NumTemporaries
=
1360 p
.program
->Base
.NumParameters
=
1361 p
.program
->Base
.NumAttributes
= p
.program
->Base
.NumAddressRegs
= 0;
1362 p
.program
->Base
.Parameters
= _mesa_new_parameter_list();
1364 p
.program
->Base
.InputsRead
= 0;
1365 p
.program
->Base
.OutputsWritten
= 1 << FRAG_RESULT_COLOR
;
1367 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
1368 p
.src_texture
[unit
] = undef
;
1369 p
.texcoord_tex
[unit
] = undef
;
1372 p
.src_previous
= undef
;
1377 p
.last_tex_stage
= 0;
1378 release_temps(ctx
, &p
);
1380 if (key
->enabled_units
) {
1381 GLboolean needbumpstage
= GL_FALSE
;
1382 /* Zeroth pass - bump map textures first */
1383 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1384 if (key
->unit
[unit
].enabled
&& key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1385 needbumpstage
= GL_TRUE
;
1386 load_texunit_bumpmap( &p
, unit
);
1389 p
.program
->Base
.NumTexIndirections
++;
1391 /* First pass - to support texture_env_crossbar, first identify
1392 * all referenced texture sources and emit texld instructions
1395 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1396 if (key
->unit
[unit
].enabled
) {
1397 load_texunit_sources( &p
, unit
);
1398 p
.last_tex_stage
= unit
;
1401 /* Second pass - emit combine instructions to build final color:
1403 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1404 if (key
->unit
[unit
].enabled
) {
1405 p
.src_previous
= emit_texenv( &p
, unit
);
1406 reserve_temp(&p
, p
.src_previous
); /* don't re-use this temp reg */
1407 release_temps(ctx
, &p
); /* release all temps */
1411 cf
= get_source( &p
, SRC_PREVIOUS
, 0 );
1412 out
= make_ureg( PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1414 if (key
->separate_specular
) {
1415 /* Emit specular add.
1417 struct ureg s
= register_input(&p
, FRAG_ATTRIB_COL1
);
1418 emit_arith( &p
, OPCODE_ADD
, out
, WRITEMASK_XYZ
, 0, cf
, s
, undef
);
1419 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_W
, 0, cf
, undef
, undef
);
1421 else if (_mesa_memcmp(&cf
, &out
, sizeof(cf
)) != 0) {
1422 /* Will wind up in here if no texture enabled or a couple of
1423 * other scenarios (GL_REPLACE for instance).
1425 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_XYZW
, 0, cf
, undef
, undef
);
1430 emit_arith( &p
, OPCODE_END
, undef
, WRITEMASK_XYZW
, 0, undef
, undef
, undef
);
1432 if (key
->fog_enabled
) {
1433 /* Pull fog mode from GLcontext, the value in the state key is
1434 * a reduced value and not what is expected in FogOption
1436 p
.program
->FogOption
= ctx
->Fog
.Mode
;
1437 p
.program
->Base
.InputsRead
|= FRAG_BIT_FOGC
; /* XXX new */
1439 p
.program
->FogOption
= GL_NONE
;
1441 if (p
.program
->Base
.NumTexIndirections
> ctx
->Const
.FragmentProgram
.MaxTexIndirections
)
1442 program_error(&p
, "Exceeded max nr indirect texture lookups");
1444 if (p
.program
->Base
.NumTexInstructions
> ctx
->Const
.FragmentProgram
.MaxTexInstructions
)
1445 program_error(&p
, "Exceeded max TEX instructions");
1447 if (p
.program
->Base
.NumAluInstructions
> ctx
->Const
.FragmentProgram
.MaxAluInstructions
)
1448 program_error(&p
, "Exceeded max ALU instructions");
1450 ASSERT(p
.program
->Base
.NumInstructions
<= MAX_INSTRUCTIONS
);
1452 /* Allocate final instruction array */
1453 p
.program
->Base
.Instructions
1454 = _mesa_alloc_instructions(p
.program
->Base
.NumInstructions
);
1455 if (!p
.program
->Base
.Instructions
) {
1456 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1457 "generating tex env program");
1460 _mesa_copy_instructions(p
.program
->Base
.Instructions
, instBuffer
,
1461 p
.program
->Base
.NumInstructions
);
1463 if (p
.program
->FogOption
) {
1464 _mesa_append_fog_code(ctx
, p
.program
);
1465 p
.program
->FogOption
= GL_NONE
;
1469 /* Notify driver the fragment program has (actually) changed.
1471 if (ctx
->Driver
.ProgramStringNotify
) {
1472 ctx
->Driver
.ProgramStringNotify( ctx
, GL_FRAGMENT_PROGRAM_ARB
,
1477 _mesa_print_program(&p
.program
->Base
);
1484 * Return a fragment program which implements the current
1485 * fixed-function texture, fog and color-sum operations.
1487 struct gl_fragment_program
*
1488 _mesa_get_fixed_func_fragment_program(GLcontext
*ctx
)
1490 struct gl_fragment_program
*prog
;
1491 struct state_key key
;
1493 make_state_key(ctx
, &key
);
1495 prog
= (struct gl_fragment_program
*)
1496 _mesa_search_program_cache(ctx
->FragmentProgram
.Cache
,
1500 prog
= (struct gl_fragment_program
*)
1501 ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
1503 create_new_program(ctx
, &key
, prog
);
1505 _mesa_program_cache_insert(ctx
, ctx
->FragmentProgram
.Cache
,
1506 &key
, sizeof(key
), &prog
->Base
);