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 **************************************************************************/
32 #include "shader/program.h"
33 #include "shader/prog_parameter.h"
34 #include "shader/prog_cache.h"
35 #include "shader/prog_instruction.h"
36 #include "shader/prog_print.h"
37 #include "shader/prog_statevars.h"
38 #include "shader/programopt.h"
39 #include "texenvprogram.h"
43 * Note on texture units:
45 * The number of texture units supported by fixed-function fragment
46 * processing is MAX_TEXTURE_COORD_UNITS, not MAX_TEXTURE_IMAGE_UNITS.
47 * That's because there's a one-to-one correspondence between texture
48 * coordinates and samplers in fixed-function processing.
50 * Since fixed-function vertex processing is limited to MAX_TEXTURE_COORD_UNITS
51 * sets of texcoords, so is fixed-function fragment processing.
53 * We can safely use ctx->Const.MaxTextureUnits for loop bounds.
57 struct texenvprog_cache_item
61 struct gl_fragment_program
*data
;
62 struct texenvprog_cache_item
*next
;
66 texenv_doing_secondary_color(GLcontext
*ctx
)
68 if (ctx
->Light
.Enabled
&&
69 (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
))
72 if (ctx
->Fog
.ColorSumEnabled
)
79 * Up to nine instructions per tex unit, plus fog, specular color.
81 #define MAX_INSTRUCTIONS ((MAX_TEXTURE_COORD_UNITS * 9) + 12)
83 #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
86 GLuint Source
:4; /**< SRC_x */
87 GLuint Operand
:3; /**< OPR_x */
91 GLuint nr_enabled_units
:8;
92 GLuint enabled_units
:8;
93 GLuint separate_specular
:1;
95 GLuint fog_mode
:2; /**< FOG_x */
96 GLuint inputs_available
:12;
100 GLuint source_index
:3; /**< TEXTURE_x_INDEX */
102 GLuint ScaleShiftRGB
:2;
103 GLuint ScaleShiftA
:2;
105 GLuint NumArgsRGB
:3; /**< up to MAX_COMBINER_TERMS */
106 GLuint ModeRGB
:5; /**< MODE_x */
107 struct mode_opt OptRGB
[MAX_COMBINER_TERMS
];
109 GLuint NumArgsA
:3; /**< up to MAX_COMBINER_TERMS */
110 GLuint ModeA
:5; /**< MODE_x */
111 struct mode_opt OptA
[MAX_COMBINER_TERMS
];
112 } unit
[MAX_TEXTURE_UNITS
];
118 #define FOG_UNKNOWN 3
120 static GLuint
translate_fog_mode( GLenum mode
)
123 case GL_LINEAR
: return FOG_LINEAR
;
124 case GL_EXP
: return FOG_EXP
;
125 case GL_EXP2
: return FOG_EXP2
;
126 default: return FOG_UNKNOWN
;
130 #define OPR_SRC_COLOR 0
131 #define OPR_ONE_MINUS_SRC_COLOR 1
132 #define OPR_SRC_ALPHA 2
133 #define OPR_ONE_MINUS_SRC_ALPHA 3
136 #define OPR_UNKNOWN 7
138 static GLuint
translate_operand( GLenum operand
)
141 case GL_SRC_COLOR
: return OPR_SRC_COLOR
;
142 case GL_ONE_MINUS_SRC_COLOR
: return OPR_ONE_MINUS_SRC_COLOR
;
143 case GL_SRC_ALPHA
: return OPR_SRC_ALPHA
;
144 case GL_ONE_MINUS_SRC_ALPHA
: return OPR_ONE_MINUS_SRC_ALPHA
;
145 case GL_ZERO
: return OPR_ZERO
;
146 case GL_ONE
: return OPR_ONE
;
153 #define SRC_TEXTURE 0
154 #define SRC_TEXTURE0 1
155 #define SRC_TEXTURE1 2
156 #define SRC_TEXTURE2 3
157 #define SRC_TEXTURE3 4
158 #define SRC_TEXTURE4 5
159 #define SRC_TEXTURE5 6
160 #define SRC_TEXTURE6 7
161 #define SRC_TEXTURE7 8
162 #define SRC_CONSTANT 9
163 #define SRC_PRIMARY_COLOR 10
164 #define SRC_PREVIOUS 11
166 #define SRC_UNKNOWN 15
168 static GLuint
translate_source( GLenum src
)
171 case GL_TEXTURE
: return SRC_TEXTURE
;
179 case GL_TEXTURE7
: return SRC_TEXTURE0
+ (src
- GL_TEXTURE0
);
180 case GL_CONSTANT
: return SRC_CONSTANT
;
181 case GL_PRIMARY_COLOR
: return SRC_PRIMARY_COLOR
;
182 case GL_PREVIOUS
: return SRC_PREVIOUS
;
191 #define MODE_REPLACE 0 /* r = a0 */
192 #define MODE_MODULATE 1 /* r = a0 * a1 */
193 #define MODE_ADD 2 /* r = a0 + a1 */
194 #define MODE_ADD_SIGNED 3 /* r = a0 + a1 - 0.5 */
195 #define MODE_INTERPOLATE 4 /* r = a0 * a2 + a1 * (1 - a2) */
196 #define MODE_SUBTRACT 5 /* r = a0 - a1 */
197 #define MODE_DOT3_RGB 6 /* r = a0 . a1 */
198 #define MODE_DOT3_RGB_EXT 7 /* r = a0 . a1 */
199 #define MODE_DOT3_RGBA 8 /* r = a0 . a1 */
200 #define MODE_DOT3_RGBA_EXT 9 /* r = a0 . a1 */
201 #define MODE_MODULATE_ADD_ATI 10 /* r = a0 * a2 + a1 */
202 #define MODE_MODULATE_SIGNED_ADD_ATI 11 /* r = a0 * a2 + a1 - 0.5 */
203 #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */
204 #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */
205 #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */
206 #define MODE_BUMP_ENVMAP_ATI 15 /* special */
207 #define MODE_UNKNOWN 16
210 * Translate GL combiner state into a MODE_x value
212 static GLuint
translate_mode( GLenum envMode
, GLenum mode
)
215 case GL_REPLACE
: return MODE_REPLACE
;
216 case GL_MODULATE
: return MODE_MODULATE
;
218 if (envMode
== GL_COMBINE4_NV
)
219 return MODE_ADD_PRODUCTS
;
223 if (envMode
== GL_COMBINE4_NV
)
224 return MODE_ADD_PRODUCTS_SIGNED
;
226 return MODE_ADD_SIGNED
;
227 case GL_INTERPOLATE
: return MODE_INTERPOLATE
;
228 case GL_SUBTRACT
: return MODE_SUBTRACT
;
229 case GL_DOT3_RGB
: return MODE_DOT3_RGB
;
230 case GL_DOT3_RGB_EXT
: return MODE_DOT3_RGB_EXT
;
231 case GL_DOT3_RGBA
: return MODE_DOT3_RGBA
;
232 case GL_DOT3_RGBA_EXT
: return MODE_DOT3_RGBA_EXT
;
233 case GL_MODULATE_ADD_ATI
: return MODE_MODULATE_ADD_ATI
;
234 case GL_MODULATE_SIGNED_ADD_ATI
: return MODE_MODULATE_SIGNED_ADD_ATI
;
235 case GL_MODULATE_SUBTRACT_ATI
: return MODE_MODULATE_SUBTRACT_ATI
;
236 case GL_BUMP_ENVMAP_ATI
: return MODE_BUMP_ENVMAP_ATI
;
245 * Translate TEXTURE_x_BIT to TEXTURE_x_INDEX.
247 static GLuint
translate_tex_src_bit( GLbitfield bit
)
250 return _mesa_ffs(bit
) - 1;
254 #define VERT_BIT_TEX_ANY (0xff << VERT_ATTRIB_TEX0)
255 #define VERT_RESULT_TEX_ANY (0xff << VERT_RESULT_TEX0)
258 * Identify all possible varying inputs. The fragment program will
259 * never reference non-varying inputs, but will track them via state
262 * This function figures out all the inputs that the fragment program
263 * has access to. The bitmask is later reduced to just those which
264 * are actually referenced.
266 static GLbitfield
get_fp_input_mask( GLcontext
*ctx
)
269 const GLboolean vertexShader
= (ctx
->Shader
.CurrentProgram
&&
270 ctx
->Shader
.CurrentProgram
->LinkStatus
&&
271 ctx
->Shader
.CurrentProgram
->VertexProgram
);
272 const GLboolean vertexProgram
= ctx
->VertexProgram
._Enabled
;
273 GLbitfield fp_inputs
= 0x0;
275 if (ctx
->VertexProgram
._Overriden
) {
276 /* Somebody's messing with the vertex program and we don't have
277 * a clue what's happening. Assume that it could be producing
278 * all possible outputs.
282 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
283 /* _NEW_RENDERMODE */
284 fp_inputs
= (FRAG_BIT_COL0
| FRAG_BIT_TEX0
);
286 else if (!(vertexProgram
|| vertexShader
) ||
287 !ctx
->VertexProgram
._Current
) {
288 /* Fixed function vertex logic */
290 GLbitfield varying_inputs
= ctx
->varying_vp_inputs
;
292 /* These get generated in the setup routine regardless of the
296 if (ctx
->Point
.PointSprite
)
297 varying_inputs
|= FRAG_BITS_TEX_ANY
;
299 /* First look at what values may be computed by the generated
303 if (ctx
->Light
.Enabled
) {
304 fp_inputs
|= FRAG_BIT_COL0
;
306 if (texenv_doing_secondary_color(ctx
))
307 fp_inputs
|= FRAG_BIT_COL1
;
311 fp_inputs
|= (ctx
->Texture
._TexGenEnabled
|
312 ctx
->Texture
._TexMatEnabled
) << FRAG_ATTRIB_TEX0
;
314 /* Then look at what might be varying as a result of enabled
317 if (varying_inputs
& VERT_BIT_COLOR0
)
318 fp_inputs
|= FRAG_BIT_COL0
;
319 if (varying_inputs
& VERT_BIT_COLOR1
)
320 fp_inputs
|= FRAG_BIT_COL1
;
322 fp_inputs
|= (((varying_inputs
& VERT_BIT_TEX_ANY
) >> VERT_ATTRIB_TEX0
)
323 << FRAG_ATTRIB_TEX0
);
327 /* calculate from vp->outputs */
328 struct gl_vertex_program
*vprog
;
329 GLbitfield vp_outputs
;
331 /* Choose GLSL vertex shader over ARB vertex program. Need this
332 * since vertex shader state validation comes after fragment state
333 * validation (see additional comments in state.c).
336 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
338 vprog
= ctx
->VertexProgram
.Current
;
340 vp_outputs
= vprog
->Base
.OutputsWritten
;
342 /* These get generated in the setup routine regardless of the
346 if (ctx
->Point
.PointSprite
)
347 vp_outputs
|= FRAG_BITS_TEX_ANY
;
349 if (vp_outputs
& (1 << VERT_RESULT_COL0
))
350 fp_inputs
|= FRAG_BIT_COL0
;
351 if (vp_outputs
& (1 << VERT_RESULT_COL1
))
352 fp_inputs
|= FRAG_BIT_COL1
;
354 fp_inputs
|= (((vp_outputs
& VERT_RESULT_TEX_ANY
) >> VERT_RESULT_TEX0
)
355 << FRAG_ATTRIB_TEX0
);
363 * Examine current texture environment state and generate a unique
364 * key to identify it.
366 static void make_state_key( GLcontext
*ctx
, struct state_key
*key
)
369 GLbitfield inputs_referenced
= FRAG_BIT_COL0
;
370 const GLbitfield inputs_available
= get_fp_input_mask( ctx
);
372 memset(key
, 0, sizeof(*key
));
375 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
376 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
377 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
378 const struct gl_tex_env_combine_state
*comb
= texUnit
->_CurrentCombine
;
381 if (!texUnit
->_ReallyEnabled
|| !texUnit
->Enabled
)
384 format
= texObj
->Image
[0][texObj
->BaseLevel
]->_BaseFormat
;
386 key
->unit
[i
].enabled
= 1;
387 key
->enabled_units
|= (1<<i
);
388 key
->nr_enabled_units
= i
+1;
389 inputs_referenced
|= FRAG_BIT_TEX(i
);
391 key
->unit
[i
].source_index
=
392 translate_tex_src_bit(texUnit
->_ReallyEnabled
);
394 key
->unit
[i
].shadow
= ((texObj
->CompareMode
== GL_COMPARE_R_TO_TEXTURE
) &&
395 ((format
== GL_DEPTH_COMPONENT
) ||
396 (format
== GL_DEPTH_STENCIL_EXT
)));
398 key
->unit
[i
].NumArgsRGB
= comb
->_NumArgsRGB
;
399 key
->unit
[i
].NumArgsA
= comb
->_NumArgsA
;
401 key
->unit
[i
].ModeRGB
=
402 translate_mode(texUnit
->EnvMode
, comb
->ModeRGB
);
404 translate_mode(texUnit
->EnvMode
, comb
->ModeA
);
406 key
->unit
[i
].ScaleShiftRGB
= comb
->ScaleShiftRGB
;
407 key
->unit
[i
].ScaleShiftA
= comb
->ScaleShiftA
;
409 for (j
= 0; j
< MAX_COMBINER_TERMS
; j
++) {
410 key
->unit
[i
].OptRGB
[j
].Operand
= translate_operand(comb
->OperandRGB
[j
]);
411 key
->unit
[i
].OptA
[j
].Operand
= translate_operand(comb
->OperandA
[j
]);
412 key
->unit
[i
].OptRGB
[j
].Source
= translate_source(comb
->SourceRGB
[j
]);
413 key
->unit
[i
].OptA
[j
].Source
= translate_source(comb
->SourceA
[j
]);
416 if (key
->unit
[i
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
417 /* requires some special translation */
418 key
->unit
[i
].NumArgsRGB
= 2;
419 key
->unit
[i
].ScaleShiftRGB
= 0;
420 key
->unit
[i
].OptRGB
[0].Operand
= OPR_SRC_COLOR
;
421 key
->unit
[i
].OptRGB
[0].Source
= SRC_TEXTURE
;
422 key
->unit
[i
].OptRGB
[1].Operand
= OPR_SRC_COLOR
;
423 key
->unit
[i
].OptRGB
[1].Source
= texUnit
->BumpTarget
- GL_TEXTURE0
+ SRC_TEXTURE0
;
427 /* _NEW_LIGHT | _NEW_FOG */
428 if (texenv_doing_secondary_color(ctx
)) {
429 key
->separate_specular
= 1;
430 inputs_referenced
|= FRAG_BIT_COL1
;
434 if (ctx
->Fog
.Enabled
) {
435 key
->fog_enabled
= 1;
436 key
->fog_mode
= translate_fog_mode(ctx
->Fog
.Mode
);
437 inputs_referenced
|= FRAG_BIT_FOGC
; /* maybe */
440 key
->inputs_available
= (inputs_available
& inputs_referenced
);
444 * Use uregs to represent registers internally, translate to Mesa's
445 * expected formats on emit.
447 * NOTE: These are passed by value extensively in this file rather
448 * than as usual by pointer reference. If this disturbs you, try
449 * remembering they are just 32bits in size.
451 * GCC is smart enough to deal with these dword-sized structures in
452 * much the same way as if I had defined them as dwords and was using
453 * macros to access and set the fields. This is much nicer and easier
465 static const struct ureg undef
= {
475 /** State used to build the fragment program:
477 struct texenv_fragment_program
{
478 struct gl_fragment_program
*program
;
480 struct state_key
*state
;
482 GLbitfield alu_temps
; /**< Track texture indirections, see spec. */
483 GLbitfield temps_output
; /**< Track texture indirections, see spec. */
484 GLbitfield temp_in_use
; /**< Tracks temporary regs which are in use. */
487 struct ureg src_texture
[MAX_TEXTURE_COORD_UNITS
];
488 /* Reg containing each texture unit's sampled texture color,
492 struct ureg texcoord_tex
[MAX_TEXTURE_COORD_UNITS
];
493 /* Reg containing texcoord for a texture unit,
494 * needed for bump mapping, else undef.
497 struct ureg src_previous
; /**< Reg containing color from previous
498 * stage. May need to be decl'd.
501 GLuint last_tex_stage
; /**< Number of last enabled texture unit */
510 static struct ureg
make_ureg(GLuint file
, GLuint idx
)
517 reg
.swz
= SWIZZLE_NOOP
;
522 static struct ureg
swizzle( struct ureg reg
, int x
, int y
, int z
, int w
)
524 reg
.swz
= MAKE_SWIZZLE4(GET_SWZ(reg
.swz
, x
),
527 GET_SWZ(reg
.swz
, w
));
532 static struct ureg
swizzle1( struct ureg reg
, int x
)
534 return swizzle(reg
, x
, x
, x
, x
);
537 static struct ureg
negate( struct ureg reg
)
543 static GLboolean
is_undef( struct ureg reg
)
545 return reg
.file
== PROGRAM_UNDEFINED
;
549 static struct ureg
get_temp( struct texenv_fragment_program
*p
)
553 /* First try and reuse temps which have been used already:
555 bit
= _mesa_ffs( ~p
->temp_in_use
& p
->alu_temps
);
557 /* Then any unused temporary:
560 bit
= _mesa_ffs( ~p
->temp_in_use
);
563 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
567 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
568 p
->program
->Base
.NumTemporaries
= bit
;
570 p
->temp_in_use
|= 1<<(bit
-1);
571 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
574 static struct ureg
get_tex_temp( struct texenv_fragment_program
*p
)
578 /* First try to find available temp not previously used (to avoid
579 * starting a new texture indirection). According to the spec, the
580 * ~p->temps_output isn't necessary, but will keep it there for
583 bit
= _mesa_ffs( ~p
->temp_in_use
& ~p
->alu_temps
& ~p
->temps_output
);
585 /* Then any unused temporary:
588 bit
= _mesa_ffs( ~p
->temp_in_use
);
591 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
595 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
596 p
->program
->Base
.NumTemporaries
= bit
;
598 p
->temp_in_use
|= 1<<(bit
-1);
599 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
603 /** Mark a temp reg as being no longer allocatable. */
604 static void reserve_temp( struct texenv_fragment_program
*p
, struct ureg r
)
606 if (r
.file
== PROGRAM_TEMPORARY
)
607 p
->temps_output
|= (1 << r
.idx
);
611 static void release_temps(GLcontext
*ctx
, struct texenv_fragment_program
*p
)
613 GLuint max_temp
= ctx
->Const
.FragmentProgram
.MaxTemps
;
615 /* KW: To support tex_env_crossbar, don't release the registers in
618 if (max_temp
>= sizeof(int) * 8)
619 p
->temp_in_use
= p
->temps_output
;
621 p
->temp_in_use
= ~((1<<max_temp
)-1) | p
->temps_output
;
625 static struct ureg
register_param5( struct texenv_fragment_program
*p
,
632 gl_state_index tokens
[STATE_LENGTH
];
639 idx
= _mesa_add_state_reference( p
->program
->Base
.Parameters
, tokens
);
640 return make_ureg(PROGRAM_STATE_VAR
, idx
);
644 #define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
645 #define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
646 #define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
647 #define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
649 static GLuint
frag_to_vert_attrib( GLuint attrib
)
652 case FRAG_ATTRIB_COL0
: return VERT_ATTRIB_COLOR0
;
653 case FRAG_ATTRIB_COL1
: return VERT_ATTRIB_COLOR1
;
655 assert(attrib
>= FRAG_ATTRIB_TEX0
);
656 assert(attrib
<= FRAG_ATTRIB_TEX7
);
657 return attrib
- FRAG_ATTRIB_TEX0
+ VERT_ATTRIB_TEX0
;
662 static struct ureg
register_input( struct texenv_fragment_program
*p
, GLuint input
)
664 if (p
->state
->inputs_available
& (1<<input
)) {
665 p
->program
->Base
.InputsRead
|= (1 << input
);
666 return make_ureg(PROGRAM_INPUT
, input
);
669 GLuint idx
= frag_to_vert_attrib( input
);
670 return register_param3( p
, STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, idx
);
675 static void emit_arg( struct prog_src_register
*reg
,
678 reg
->File
= ureg
.file
;
679 reg
->Index
= ureg
.idx
;
680 reg
->Swizzle
= ureg
.swz
;
681 reg
->Negate
= ureg
.negatebase
? NEGATE_XYZW
: NEGATE_NONE
;
685 static void emit_dst( struct prog_dst_register
*dst
,
686 struct ureg ureg
, GLuint mask
)
688 dst
->File
= ureg
.file
;
689 dst
->Index
= ureg
.idx
;
690 dst
->WriteMask
= mask
;
691 dst
->CondMask
= COND_TR
; /* always pass cond test */
692 dst
->CondSwizzle
= SWIZZLE_NOOP
;
695 static struct prog_instruction
*
696 emit_op(struct texenv_fragment_program
*p
,
705 const GLuint nr
= p
->program
->Base
.NumInstructions
++;
706 struct prog_instruction
*inst
= &p
->program
->Base
.Instructions
[nr
];
708 assert(nr
< MAX_INSTRUCTIONS
);
710 _mesa_init_instructions(inst
, 1);
713 emit_arg( &inst
->SrcReg
[0], src0
);
714 emit_arg( &inst
->SrcReg
[1], src1
);
715 emit_arg( &inst
->SrcReg
[2], src2
);
717 inst
->SaturateMode
= saturate
? SATURATE_ZERO_ONE
: SATURATE_OFF
;
719 emit_dst( &inst
->DstReg
, dest
, mask
);
722 /* Accounting for indirection tracking:
724 if (dest
.file
== PROGRAM_TEMPORARY
)
725 p
->temps_output
|= 1 << dest
.idx
;
732 static struct ureg
emit_arith( struct texenv_fragment_program
*p
,
741 emit_op(p
, op
, dest
, mask
, saturate
, src0
, src1
, src2
);
743 /* Accounting for indirection tracking:
745 if (src0
.file
== PROGRAM_TEMPORARY
)
746 p
->alu_temps
|= 1 << src0
.idx
;
748 if (!is_undef(src1
) && src1
.file
== PROGRAM_TEMPORARY
)
749 p
->alu_temps
|= 1 << src1
.idx
;
751 if (!is_undef(src2
) && src2
.file
== PROGRAM_TEMPORARY
)
752 p
->alu_temps
|= 1 << src2
.idx
;
754 if (dest
.file
== PROGRAM_TEMPORARY
)
755 p
->alu_temps
|= 1 << dest
.idx
;
757 p
->program
->Base
.NumAluInstructions
++;
761 static struct ureg
emit_texld( struct texenv_fragment_program
*p
,
770 struct prog_instruction
*inst
= emit_op( p
, op
,
772 GL_FALSE
, /* don't saturate? */
777 inst
->TexSrcTarget
= tex_idx
;
778 inst
->TexSrcUnit
= tex_unit
;
779 inst
->TexShadow
= tex_shadow
;
781 p
->program
->Base
.NumTexInstructions
++;
783 /* Accounting for indirection tracking:
785 reserve_temp(p
, dest
);
788 /* Is this a texture indirection?
790 if ((coord
.file
== PROGRAM_TEMPORARY
&&
791 (p
->temps_output
& (1<<coord
.idx
))) ||
792 (dest
.file
== PROGRAM_TEMPORARY
&&
793 (p
->alu_temps
& (1<<dest
.idx
)))) {
794 p
->program
->Base
.NumTexIndirections
++;
795 p
->temps_output
= 1<<coord
.idx
;
797 assert(0); /* KW: texture env crossbar */
805 static struct ureg
register_const4f( struct texenv_fragment_program
*p
,
818 idx
= _mesa_add_unnamed_constant( p
->program
->Base
.Parameters
, values
, 4,
820 r
= make_ureg(PROGRAM_CONSTANT
, idx
);
825 #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
826 #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
827 #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
828 #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
831 static struct ureg
get_one( struct texenv_fragment_program
*p
)
833 if (is_undef(p
->one
))
834 p
->one
= register_scalar_const(p
, 1.0);
838 static struct ureg
get_half( struct texenv_fragment_program
*p
)
840 if (is_undef(p
->half
))
841 p
->half
= register_scalar_const(p
, 0.5);
845 static struct ureg
get_zero( struct texenv_fragment_program
*p
)
847 if (is_undef(p
->zero
))
848 p
->zero
= register_scalar_const(p
, 0.0);
853 static void program_error( struct texenv_fragment_program
*p
, const char *msg
)
855 _mesa_problem(NULL
, msg
);
859 static struct ureg
get_source( struct texenv_fragment_program
*p
,
860 GLuint src
, GLuint unit
)
864 assert(!is_undef(p
->src_texture
[unit
]));
865 return p
->src_texture
[unit
];
875 assert(!is_undef(p
->src_texture
[src
- SRC_TEXTURE0
]));
876 return p
->src_texture
[src
- SRC_TEXTURE0
];
879 return register_param2(p
, STATE_TEXENV_COLOR
, unit
);
881 case SRC_PRIMARY_COLOR
:
882 return register_input(p
, FRAG_ATTRIB_COL0
);
888 if (is_undef(p
->src_previous
))
889 return register_input(p
, FRAG_ATTRIB_COL0
);
891 return p
->src_previous
;
899 static struct ureg
emit_combine_source( struct texenv_fragment_program
*p
,
905 struct ureg arg
, src
, one
;
907 src
= get_source(p
, source
, unit
);
910 case OPR_ONE_MINUS_SRC_COLOR
:
912 * Emit tmp = 1.0 - arg.xyzw
916 return emit_arith( p
, OPCODE_SUB
, arg
, mask
, 0, one
, src
, undef
);
919 if (mask
== WRITEMASK_W
)
922 return swizzle1( src
, SWIZZLE_W
);
923 case OPR_ONE_MINUS_SRC_ALPHA
:
925 * Emit tmp = 1.0 - arg.wwww
929 return emit_arith(p
, OPCODE_SUB
, arg
, mask
, 0,
930 one
, swizzle1(src
, SWIZZLE_W
), undef
);
944 * Check if the RGB and Alpha sources and operands match for the given
945 * texture unit's combinder state. When the RGB and A sources and
946 * operands match, we can emit fewer instructions.
948 static GLboolean
args_match( const struct state_key
*key
, GLuint unit
)
950 GLuint i
, numArgs
= key
->unit
[unit
].NumArgsRGB
;
952 for (i
= 0 ; i
< numArgs
; i
++) {
953 if (key
->unit
[unit
].OptA
[i
].Source
!= key
->unit
[unit
].OptRGB
[i
].Source
)
956 switch (key
->unit
[unit
].OptA
[i
].Operand
) {
958 switch (key
->unit
[unit
].OptRGB
[i
].Operand
) {
966 case OPR_ONE_MINUS_SRC_ALPHA
:
967 switch (key
->unit
[unit
].OptRGB
[i
].Operand
) {
968 case OPR_ONE_MINUS_SRC_COLOR
:
969 case OPR_ONE_MINUS_SRC_ALPHA
:
976 return GL_FALSE
; /* impossible */
983 static struct ureg
emit_combine( struct texenv_fragment_program
*p
,
990 const struct mode_opt
*opt
)
992 struct ureg src
[MAX_COMBINER_TERMS
];
993 struct ureg tmp
, half
;
996 assert(nr
<= MAX_COMBINER_TERMS
);
998 tmp
= undef
; /* silence warning (bug 5318) */
1000 for (i
= 0; i
< nr
; i
++)
1001 src
[i
] = emit_combine_source( p
, mask
, unit
, opt
[i
].Source
, opt
[i
].Operand
);
1005 if (mask
== WRITEMASK_XYZW
&& !saturate
)
1008 return emit_arith( p
, OPCODE_MOV
, dest
, mask
, saturate
, src
[0], undef
, undef
);
1010 return emit_arith( p
, OPCODE_MUL
, dest
, mask
, saturate
,
1011 src
[0], src
[1], undef
);
1013 return emit_arith( p
, OPCODE_ADD
, dest
, mask
, saturate
,
1014 src
[0], src
[1], undef
);
1015 case MODE_ADD_SIGNED
:
1016 /* tmp = arg0 + arg1
1020 tmp
= get_temp( p
);
1021 emit_arith( p
, OPCODE_ADD
, tmp
, mask
, 0, src
[0], src
[1], undef
);
1022 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp
, half
, undef
);
1024 case MODE_INTERPOLATE
:
1025 /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered:
1027 return emit_arith( p
, OPCODE_LRP
, dest
, mask
, saturate
, src
[2], src
[0], src
[1] );
1030 return emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, src
[0], src
[1], undef
);
1032 case MODE_DOT3_RGBA
:
1033 case MODE_DOT3_RGBA_EXT
:
1034 case MODE_DOT3_RGB_EXT
:
1035 case MODE_DOT3_RGB
: {
1036 struct ureg tmp0
= get_temp( p
);
1037 struct ureg tmp1
= get_temp( p
);
1038 struct ureg neg1
= register_scalar_const(p
, -1);
1039 struct ureg two
= register_scalar_const(p
, 2);
1041 /* tmp0 = 2*src0 - 1
1044 * dst = tmp0 dot3 tmp1
1046 emit_arith( p
, OPCODE_MAD
, tmp0
, WRITEMASK_XYZW
, 0,
1049 if (_mesa_memcmp(&src
[0], &src
[1], sizeof(struct ureg
)) == 0)
1052 emit_arith( p
, OPCODE_MAD
, tmp1
, WRITEMASK_XYZW
, 0,
1054 emit_arith( p
, OPCODE_DP3
, dest
, mask
, saturate
, tmp0
, tmp1
, undef
);
1057 case MODE_MODULATE_ADD_ATI
:
1058 /* Arg0 * Arg2 + Arg1 */
1059 return emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
,
1060 src
[0], src
[2], src
[1] );
1061 case MODE_MODULATE_SIGNED_ADD_ATI
: {
1062 /* Arg0 * Arg2 + Arg1 - 0.5 */
1063 struct ureg tmp0
= get_temp(p
);
1065 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[0], src
[2], src
[1] );
1066 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1069 case MODE_MODULATE_SUBTRACT_ATI
:
1070 /* Arg0 * Arg2 - Arg1 */
1071 emit_arith( p
, OPCODE_MAD
, dest
, mask
, 0, src
[0], src
[2], negate(src
[1]) );
1073 case MODE_ADD_PRODUCTS
:
1074 /* Arg0 * Arg1 + Arg2 * Arg3 */
1076 struct ureg tmp0
= get_temp(p
);
1077 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1078 emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
, src
[2], src
[3], tmp0
);
1081 case MODE_ADD_PRODUCTS_SIGNED
:
1082 /* Arg0 * Arg1 + Arg2 * Arg3 - 0.5 */
1084 struct ureg tmp0
= get_temp(p
);
1086 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1087 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[2], src
[3], tmp0
);
1088 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1091 case MODE_BUMP_ENVMAP_ATI
:
1092 /* special - not handled here */
1103 * Generate instructions for one texture unit's env/combiner mode.
1106 emit_texenv(struct texenv_fragment_program
*p
, GLuint unit
)
1108 const struct state_key
*key
= p
->state
;
1110 GLuint rgb_shift
, alpha_shift
;
1111 struct ureg out
, dest
;
1113 if (!key
->unit
[unit
].enabled
) {
1114 return get_source(p
, SRC_PREVIOUS
, 0);
1116 if (key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1117 /* this isn't really a env stage delivering a color and handled elsewhere */
1118 return get_source(p
, SRC_PREVIOUS
, 0);
1121 switch (key
->unit
[unit
].ModeRGB
) {
1122 case MODE_DOT3_RGB_EXT
:
1123 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1126 case MODE_DOT3_RGBA_EXT
:
1131 rgb_shift
= key
->unit
[unit
].ScaleShiftRGB
;
1132 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1136 /* If we'll do rgb/alpha shifting don't saturate in emit_combine().
1137 * We don't want to clamp twice.
1139 saturate
= !(rgb_shift
|| alpha_shift
);
1141 /* If this is the very last calculation, emit direct to output reg:
1143 if (key
->separate_specular
||
1144 unit
!= p
->last_tex_stage
||
1147 dest
= get_temp( p
);
1149 dest
= make_ureg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1151 /* Emit the RGB and A combine ops
1153 if (key
->unit
[unit
].ModeRGB
== key
->unit
[unit
].ModeA
&&
1154 args_match(key
, unit
)) {
1155 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1157 key
->unit
[unit
].NumArgsRGB
,
1158 key
->unit
[unit
].ModeRGB
,
1159 key
->unit
[unit
].OptRGB
);
1161 else if (key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA_EXT
||
1162 key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA
) {
1163 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1165 key
->unit
[unit
].NumArgsRGB
,
1166 key
->unit
[unit
].ModeRGB
,
1167 key
->unit
[unit
].OptRGB
);
1170 /* Need to do something to stop from re-emitting identical
1171 * argument calculations here:
1173 out
= emit_combine( p
, dest
, WRITEMASK_XYZ
, saturate
,
1175 key
->unit
[unit
].NumArgsRGB
,
1176 key
->unit
[unit
].ModeRGB
,
1177 key
->unit
[unit
].OptRGB
);
1178 out
= emit_combine( p
, dest
, WRITEMASK_W
, saturate
,
1180 key
->unit
[unit
].NumArgsA
,
1181 key
->unit
[unit
].ModeA
,
1182 key
->unit
[unit
].OptA
);
1185 /* Deal with the final shift:
1187 if (alpha_shift
|| rgb_shift
) {
1190 saturate
= GL_TRUE
; /* always saturate at this point */
1192 if (rgb_shift
== alpha_shift
) {
1193 shift
= register_scalar_const(p
, (GLfloat
)(1<<rgb_shift
));
1196 shift
= register_const4f(p
,
1197 (GLfloat
)(1<<rgb_shift
),
1198 (GLfloat
)(1<<rgb_shift
),
1199 (GLfloat
)(1<<rgb_shift
),
1200 (GLfloat
)(1<<alpha_shift
));
1202 return emit_arith( p
, OPCODE_MUL
, dest
, WRITEMASK_XYZW
,
1203 saturate
, out
, shift
, undef
);
1211 * Generate instruction for getting a texture source term.
1213 static void load_texture( struct texenv_fragment_program
*p
, GLuint unit
)
1215 if (is_undef(p
->src_texture
[unit
])) {
1216 const GLuint texTarget
= p
->state
->unit
[unit
].source_index
;
1217 struct ureg texcoord
;
1218 struct ureg tmp
= get_tex_temp( p
);
1220 if (is_undef(p
->texcoord_tex
[unit
])) {
1221 texcoord
= register_input(p
, FRAG_ATTRIB_TEX0
+unit
);
1224 /* might want to reuse this reg for tex output actually */
1225 texcoord
= p
->texcoord_tex
[unit
];
1228 /* TODO: Use D0_MASK_XY where possible.
1230 if (p
->state
->unit
[unit
].enabled
) {
1231 GLboolean shadow
= GL_FALSE
;
1233 if (p
->state
->unit
[unit
].shadow
) {
1234 p
->program
->Base
.ShadowSamplers
|= 1 << unit
;
1238 p
->src_texture
[unit
] = emit_texld( p
, OPCODE_TXP
,
1239 tmp
, WRITEMASK_XYZW
,
1240 unit
, texTarget
, shadow
,
1243 p
->program
->Base
.SamplersUsed
|= (1 << unit
);
1244 /* This identity mapping should already be in place
1245 * (see _mesa_init_program_struct()) but let's be safe.
1247 p
->program
->Base
.SamplerUnits
[unit
] = unit
;
1250 p
->src_texture
[unit
] = get_zero(p
);
1254 static GLboolean
load_texenv_source( struct texenv_fragment_program
*p
,
1255 GLuint src
, GLuint unit
)
1259 load_texture(p
, unit
);
1270 load_texture(p
, src
- SRC_TEXTURE0
);
1274 /* not a texture src - do nothing */
1283 * Generate instructions for loading all texture source terms.
1286 load_texunit_sources( struct texenv_fragment_program
*p
, int unit
)
1288 const struct state_key
*key
= p
->state
;
1291 for (i
= 0; i
< key
->unit
[unit
].NumArgsRGB
; i
++) {
1292 load_texenv_source( p
, key
->unit
[unit
].OptRGB
[i
].Source
, unit
);
1295 for (i
= 0; i
< key
->unit
[unit
].NumArgsA
; i
++) {
1296 load_texenv_source( p
, key
->unit
[unit
].OptA
[i
].Source
, unit
);
1303 * Generate instructions for loading bump map textures.
1306 load_texunit_bumpmap( struct texenv_fragment_program
*p
, int unit
)
1308 const struct state_key
*key
= p
->state
;
1309 GLuint bumpedUnitNr
= key
->unit
[unit
].OptRGB
[1].Source
- SRC_TEXTURE0
;
1310 struct ureg texcDst
, bumpMapRes
;
1311 struct ureg constdudvcolor
= register_const4f(p
, 0.0, 0.0, 0.0, 1.0);
1312 struct ureg texcSrc
= register_input(p
, FRAG_ATTRIB_TEX0
+ bumpedUnitNr
);
1313 struct ureg rotMat0
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_0
, unit
);
1314 struct ureg rotMat1
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_1
, unit
);
1316 load_texenv_source( p
, unit
+ SRC_TEXTURE0
, unit
);
1318 bumpMapRes
= get_source(p
, key
->unit
[unit
].OptRGB
[0].Source
, unit
);
1319 texcDst
= get_tex_temp( p
);
1320 p
->texcoord_tex
[bumpedUnitNr
] = texcDst
;
1322 /* apply rot matrix and add coords to be available in next phase */
1323 /* dest = (Arg0.xxxx * rotMat0 + Arg1) + (Arg0.yyyy * rotMat1) */
1324 /* note only 2 coords are affected the rest are left unchanged (mul by 0) */
1325 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1326 swizzle1(bumpMapRes
, SWIZZLE_X
), rotMat0
, texcSrc
);
1327 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1328 swizzle1(bumpMapRes
, SWIZZLE_Y
), rotMat1
, texcDst
);
1330 /* move 0,0,0,1 into bumpmap src if someone (crossbar) is foolish
1331 enough to access this later, should optimize away */
1332 emit_arith( p
, OPCODE_MOV
, bumpMapRes
, WRITEMASK_XYZW
, 0, constdudvcolor
, undef
, undef
);
1338 * Generate a new fragment program which implements the context's
1339 * current texture env/combine mode.
1342 create_new_program(GLcontext
*ctx
, struct state_key
*key
,
1343 struct gl_fragment_program
*program
)
1345 struct prog_instruction instBuffer
[MAX_INSTRUCTIONS
];
1346 struct texenv_fragment_program p
;
1348 struct ureg cf
, out
;
1350 _mesa_memset(&p
, 0, sizeof(p
));
1353 p
.program
= program
;
1355 /* During code generation, use locally-allocated instruction buffer,
1356 * then alloc dynamic storage below.
1358 p
.program
->Base
.Instructions
= instBuffer
;
1359 p
.program
->Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
1360 p
.program
->Base
.NumTexIndirections
= 1;
1361 p
.program
->Base
.NumTexInstructions
= 0;
1362 p
.program
->Base
.NumAluInstructions
= 0;
1363 p
.program
->Base
.String
= NULL
;
1364 p
.program
->Base
.NumInstructions
=
1365 p
.program
->Base
.NumTemporaries
=
1366 p
.program
->Base
.NumParameters
=
1367 p
.program
->Base
.NumAttributes
= p
.program
->Base
.NumAddressRegs
= 0;
1368 p
.program
->Base
.Parameters
= _mesa_new_parameter_list();
1370 p
.program
->Base
.InputsRead
= 0;
1371 p
.program
->Base
.OutputsWritten
= 1 << FRAG_RESULT_COLOR
;
1373 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
1374 p
.src_texture
[unit
] = undef
;
1375 p
.texcoord_tex
[unit
] = undef
;
1378 p
.src_previous
= undef
;
1383 p
.last_tex_stage
= 0;
1384 release_temps(ctx
, &p
);
1386 if (key
->enabled_units
) {
1387 GLboolean needbumpstage
= GL_FALSE
;
1388 /* Zeroth pass - bump map textures first */
1389 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1390 if (key
->unit
[unit
].enabled
&& key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1391 needbumpstage
= GL_TRUE
;
1392 load_texunit_bumpmap( &p
, unit
);
1395 p
.program
->Base
.NumTexIndirections
++;
1397 /* First pass - to support texture_env_crossbar, first identify
1398 * all referenced texture sources and emit texld instructions
1401 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1402 if (key
->unit
[unit
].enabled
) {
1403 load_texunit_sources( &p
, unit
);
1404 p
.last_tex_stage
= unit
;
1407 /* Second pass - emit combine instructions to build final color:
1409 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1410 if (key
->enabled_units
& (1<<unit
)) {
1411 p
.src_previous
= emit_texenv( &p
, unit
);
1412 reserve_temp(&p
, p
.src_previous
); /* don't re-use this temp reg */
1413 release_temps(ctx
, &p
); /* release all temps */
1417 cf
= get_source( &p
, SRC_PREVIOUS
, 0 );
1418 out
= make_ureg( PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1420 if (key
->separate_specular
) {
1421 /* Emit specular add.
1423 struct ureg s
= register_input(&p
, FRAG_ATTRIB_COL1
);
1424 emit_arith( &p
, OPCODE_ADD
, out
, WRITEMASK_XYZ
, 0, cf
, s
, undef
);
1425 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_W
, 0, cf
, undef
, undef
);
1427 else if (_mesa_memcmp(&cf
, &out
, sizeof(cf
)) != 0) {
1428 /* Will wind up in here if no texture enabled or a couple of
1429 * other scenarios (GL_REPLACE for instance).
1431 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_XYZW
, 0, cf
, undef
, undef
);
1436 emit_arith( &p
, OPCODE_END
, undef
, WRITEMASK_XYZW
, 0, undef
, undef
, undef
);
1438 if (key
->fog_enabled
) {
1439 /* Pull fog mode from GLcontext, the value in the state key is
1440 * a reduced value and not what is expected in FogOption
1442 p
.program
->FogOption
= ctx
->Fog
.Mode
;
1443 p
.program
->Base
.InputsRead
|= FRAG_BIT_FOGC
; /* XXX new */
1445 p
.program
->FogOption
= GL_NONE
;
1447 if (p
.program
->Base
.NumTexIndirections
> ctx
->Const
.FragmentProgram
.MaxTexIndirections
)
1448 program_error(&p
, "Exceeded max nr indirect texture lookups");
1450 if (p
.program
->Base
.NumTexInstructions
> ctx
->Const
.FragmentProgram
.MaxTexInstructions
)
1451 program_error(&p
, "Exceeded max TEX instructions");
1453 if (p
.program
->Base
.NumAluInstructions
> ctx
->Const
.FragmentProgram
.MaxAluInstructions
)
1454 program_error(&p
, "Exceeded max ALU instructions");
1456 ASSERT(p
.program
->Base
.NumInstructions
<= MAX_INSTRUCTIONS
);
1458 /* Allocate final instruction array */
1459 p
.program
->Base
.Instructions
1460 = _mesa_alloc_instructions(p
.program
->Base
.NumInstructions
);
1461 if (!p
.program
->Base
.Instructions
) {
1462 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1463 "generating tex env program");
1466 _mesa_copy_instructions(p
.program
->Base
.Instructions
, instBuffer
,
1467 p
.program
->Base
.NumInstructions
);
1469 if (p
.program
->FogOption
) {
1470 _mesa_append_fog_code(ctx
, p
.program
);
1471 p
.program
->FogOption
= GL_NONE
;
1475 /* Notify driver the fragment program has (actually) changed.
1477 if (ctx
->Driver
.ProgramStringNotify
) {
1478 ctx
->Driver
.ProgramStringNotify( ctx
, GL_FRAGMENT_PROGRAM_ARB
,
1483 _mesa_print_program(&p
.program
->Base
);
1490 * Return a fragment program which implements the current
1491 * fixed-function texture, fog and color-sum operations.
1493 struct gl_fragment_program
*
1494 _mesa_get_fixed_func_fragment_program(GLcontext
*ctx
)
1496 struct gl_fragment_program
*prog
;
1497 struct state_key key
;
1499 make_state_key(ctx
, &key
);
1501 prog
= (struct gl_fragment_program
*)
1502 _mesa_search_program_cache(ctx
->FragmentProgram
.Cache
,
1506 prog
= (struct gl_fragment_program
*)
1507 ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
1509 create_new_program(ctx
, &key
, prog
);
1511 _mesa_program_cache_insert(ctx
, ctx
->FragmentProgram
.Cache
,
1512 &key
, sizeof(key
), &prog
->Base
);