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
;
67 * Up to nine instructions per tex unit, plus fog, specular color.
69 #define MAX_INSTRUCTIONS ((MAX_TEXTURE_COORD_UNITS * 9) + 12)
71 #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
79 GLuint nr_enabled_units
:8;
80 GLuint enabled_units
:8;
81 GLuint separate_specular
:1;
84 GLuint inputs_available
:12;
88 GLuint source_index
:3; /* one of TEXTURE_1D/2D/3D/CUBE/RECT_INDEX */
90 GLuint ScaleShiftRGB
:2;
95 struct mode_opt OptRGB
[MAX_COMBINER_TERMS
];
99 struct mode_opt OptA
[MAX_COMBINER_TERMS
];
106 #define FOG_UNKNOWN 3
108 static GLuint
translate_fog_mode( GLenum mode
)
111 case GL_LINEAR
: return FOG_LINEAR
;
112 case GL_EXP
: return FOG_EXP
;
113 case GL_EXP2
: return FOG_EXP2
;
114 default: return FOG_UNKNOWN
;
118 #define OPR_SRC_COLOR 0
119 #define OPR_ONE_MINUS_SRC_COLOR 1
120 #define OPR_SRC_ALPHA 2
121 #define OPR_ONE_MINUS_SRC_ALPHA 3
124 #define OPR_UNKNOWN 7
126 static GLuint
translate_operand( GLenum operand
)
129 case GL_SRC_COLOR
: return OPR_SRC_COLOR
;
130 case GL_ONE_MINUS_SRC_COLOR
: return OPR_ONE_MINUS_SRC_COLOR
;
131 case GL_SRC_ALPHA
: return OPR_SRC_ALPHA
;
132 case GL_ONE_MINUS_SRC_ALPHA
: return OPR_ONE_MINUS_SRC_ALPHA
;
133 case GL_ZERO
: return OPR_ZERO
;
134 case GL_ONE
: return OPR_ONE
;
141 #define SRC_TEXTURE 0
142 #define SRC_TEXTURE0 1
143 #define SRC_TEXTURE1 2
144 #define SRC_TEXTURE2 3
145 #define SRC_TEXTURE3 4
146 #define SRC_TEXTURE4 5
147 #define SRC_TEXTURE5 6
148 #define SRC_TEXTURE6 7
149 #define SRC_TEXTURE7 8
150 #define SRC_CONSTANT 9
151 #define SRC_PRIMARY_COLOR 10
152 #define SRC_PREVIOUS 11
154 #define SRC_UNKNOWN 15
156 static GLuint
translate_source( GLenum src
)
159 case GL_TEXTURE
: return SRC_TEXTURE
;
167 case GL_TEXTURE7
: return SRC_TEXTURE0
+ (src
- GL_TEXTURE0
);
168 case GL_CONSTANT
: return SRC_CONSTANT
;
169 case GL_PRIMARY_COLOR
: return SRC_PRIMARY_COLOR
;
170 case GL_PREVIOUS
: return SRC_PREVIOUS
;
179 #define MODE_REPLACE 0 /* r = a0 */
180 #define MODE_MODULATE 1 /* r = a0 * a1 */
181 #define MODE_ADD 2 /* r = a0 + a1 */
182 #define MODE_ADD_SIGNED 3 /* r = a0 + a1 - 0.5 */
183 #define MODE_INTERPOLATE 4 /* r = a0 * a2 + a1 * (1 - a2) */
184 #define MODE_SUBTRACT 5 /* r = a0 - a1 */
185 #define MODE_DOT3_RGB 6 /* r = a0 . a1 */
186 #define MODE_DOT3_RGB_EXT 7 /* r = a0 . a1 */
187 #define MODE_DOT3_RGBA 8 /* r = a0 . a1 */
188 #define MODE_DOT3_RGBA_EXT 9 /* r = a0 . a1 */
189 #define MODE_MODULATE_ADD_ATI 10 /* r = a0 * a2 + a1 */
190 #define MODE_MODULATE_SIGNED_ADD_ATI 11 /* r = a0 * a2 + a1 - 0.5 */
191 #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */
192 #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */
193 #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */
194 #define MODE_BUMP_ENVMAP_ATI 15 /* special */
195 #define MODE_UNKNOWN 16
198 * Translate GL combiner state into a MODE_x value
200 static GLuint
translate_mode( GLenum envMode
, GLenum mode
)
203 case GL_REPLACE
: return MODE_REPLACE
;
204 case GL_MODULATE
: return MODE_MODULATE
;
206 if (envMode
== GL_COMBINE4_NV
)
207 return MODE_ADD_PRODUCTS
;
211 if (envMode
== GL_COMBINE4_NV
)
212 return MODE_ADD_PRODUCTS_SIGNED
;
214 return MODE_ADD_SIGNED
;
215 case GL_INTERPOLATE
: return MODE_INTERPOLATE
;
216 case GL_SUBTRACT
: return MODE_SUBTRACT
;
217 case GL_DOT3_RGB
: return MODE_DOT3_RGB
;
218 case GL_DOT3_RGB_EXT
: return MODE_DOT3_RGB_EXT
;
219 case GL_DOT3_RGBA
: return MODE_DOT3_RGBA
;
220 case GL_DOT3_RGBA_EXT
: return MODE_DOT3_RGBA_EXT
;
221 case GL_MODULATE_ADD_ATI
: return MODE_MODULATE_ADD_ATI
;
222 case GL_MODULATE_SIGNED_ADD_ATI
: return MODE_MODULATE_SIGNED_ADD_ATI
;
223 case GL_MODULATE_SUBTRACT_ATI
: return MODE_MODULATE_SUBTRACT_ATI
;
224 case GL_BUMP_ENVMAP_ATI
: return MODE_BUMP_ENVMAP_ATI
;
231 #define TEXTURE_UNKNOWN_INDEX 7
232 static GLuint
translate_tex_src_bit( GLbitfield bit
)
234 /* make sure number of switch cases is correct */
235 assert(NUM_TEXTURE_TARGETS
== 7);
237 case TEXTURE_1D_BIT
: return TEXTURE_1D_INDEX
;
238 case TEXTURE_2D_BIT
: return TEXTURE_2D_INDEX
;
239 case TEXTURE_RECT_BIT
: return TEXTURE_RECT_INDEX
;
240 case TEXTURE_3D_BIT
: return TEXTURE_3D_INDEX
;
241 case TEXTURE_CUBE_BIT
: return TEXTURE_CUBE_INDEX
;
242 case TEXTURE_1D_ARRAY_BIT
: return TEXTURE_1D_ARRAY_INDEX
;
243 case TEXTURE_2D_ARRAY_BIT
: return TEXTURE_2D_ARRAY_INDEX
;
246 return TEXTURE_UNKNOWN_INDEX
;
250 #define VERT_BIT_TEX_ANY (0xff << VERT_ATTRIB_TEX0)
251 #define VERT_RESULT_TEX_ANY (0xff << VERT_RESULT_TEX0)
254 * Identify all possible varying inputs. The fragment program will
255 * never reference non-varying inputs, but will track them via state
258 * This function figures out all the inputs that the fragment program
259 * has access to. The bitmask is later reduced to just those which
260 * are actually referenced.
262 static GLbitfield
get_fp_input_mask( GLcontext
*ctx
)
264 const GLboolean vertexShader
= (ctx
->Shader
.CurrentProgram
&&
265 ctx
->Shader
.CurrentProgram
->VertexProgram
);
266 const GLboolean vertexProgram
= ctx
->VertexProgram
._Enabled
;
267 GLbitfield fp_inputs
= 0x0;
269 if (ctx
->VertexProgram
._Overriden
) {
270 /* Somebody's messing with the vertex program and we don't have
271 * a clue what's happening. Assume that it could be producing
272 * all possible outputs.
276 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
277 fp_inputs
= (FRAG_BIT_COL0
| FRAG_BIT_TEX0
);
279 else if (!(vertexProgram
|| vertexShader
) ||
280 !ctx
->VertexProgram
._Current
) {
281 /* Fixed function vertex logic */
282 GLbitfield varying_inputs
= ctx
->varying_vp_inputs
;
284 /* These get generated in the setup routine regardless of the
287 if (ctx
->Point
.PointSprite
)
288 varying_inputs
|= FRAG_BITS_TEX_ANY
;
290 /* First look at what values may be computed by the generated
293 if (ctx
->Light
.Enabled
) {
294 fp_inputs
|= FRAG_BIT_COL0
;
296 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
297 fp_inputs
|= FRAG_BIT_COL1
;
300 fp_inputs
|= (ctx
->Texture
._TexGenEnabled
|
301 ctx
->Texture
._TexMatEnabled
) << FRAG_ATTRIB_TEX0
;
303 /* Then look at what might be varying as a result of enabled
306 if (varying_inputs
& VERT_BIT_COLOR0
) fp_inputs
|= FRAG_BIT_COL0
;
307 if (varying_inputs
& VERT_BIT_COLOR1
) fp_inputs
|= FRAG_BIT_COL1
;
309 fp_inputs
|= (((varying_inputs
& VERT_BIT_TEX_ANY
) >> VERT_ATTRIB_TEX0
)
310 << FRAG_ATTRIB_TEX0
);
314 /* calculate from vp->outputs */
315 struct gl_vertex_program
*vprog
;
316 GLbitfield vp_outputs
;
318 /* Choose GLSL vertex shader over ARB vertex program. Need this
319 * since vertex shader state validation comes after fragment state
320 * validation (see additional comments in state.c).
323 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
325 vprog
= ctx
->VertexProgram
._Current
;
327 vp_outputs
= vprog
->Base
.OutputsWritten
;
329 /* These get generated in the setup routine regardless of the
332 if (ctx
->Point
.PointSprite
)
333 vp_outputs
|= FRAG_BITS_TEX_ANY
;
335 if (vp_outputs
& (1 << VERT_RESULT_COL0
)) fp_inputs
|= FRAG_BIT_COL0
;
336 if (vp_outputs
& (1 << VERT_RESULT_COL1
)) fp_inputs
|= FRAG_BIT_COL1
;
338 fp_inputs
|= (((vp_outputs
& VERT_RESULT_TEX_ANY
) >> VERT_RESULT_TEX0
)
339 << FRAG_ATTRIB_TEX0
);
347 * Examine current texture environment state and generate a unique
348 * key to identify it.
350 static void make_state_key( GLcontext
*ctx
, struct state_key
*key
)
353 GLbitfield inputs_referenced
= FRAG_BIT_COL0
;
354 GLbitfield inputs_available
= get_fp_input_mask( ctx
);
356 memset(key
, 0, sizeof(*key
));
358 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
359 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
362 if (!texUnit
->_ReallyEnabled
|| !texUnit
->Enabled
)
365 format
= texUnit
->_Current
->Image
[0][texUnit
->_Current
->BaseLevel
]->_BaseFormat
;
367 key
->unit
[i
].enabled
= 1;
368 key
->enabled_units
|= (1<<i
);
369 key
->nr_enabled_units
= i
+1;
370 inputs_referenced
|= FRAG_BIT_TEX(i
);
372 key
->unit
[i
].source_index
=
373 translate_tex_src_bit(texUnit
->_ReallyEnabled
);
374 key
->unit
[i
].shadow
= ((texUnit
->_Current
->CompareMode
== GL_COMPARE_R_TO_TEXTURE
) &&
375 ((format
== GL_DEPTH_COMPONENT
) ||
376 (format
== GL_DEPTH_STENCIL_EXT
)));
378 key
->unit
[i
].NumArgsRGB
= texUnit
->_CurrentCombine
->_NumArgsRGB
;
379 key
->unit
[i
].NumArgsA
= texUnit
->_CurrentCombine
->_NumArgsA
;
381 key
->unit
[i
].ModeRGB
=
382 translate_mode(texUnit
->EnvMode
, texUnit
->_CurrentCombine
->ModeRGB
);
384 translate_mode(texUnit
->EnvMode
, texUnit
->_CurrentCombine
->ModeA
);
386 key
->unit
[i
].ScaleShiftRGB
= texUnit
->_CurrentCombine
->ScaleShiftRGB
;
387 key
->unit
[i
].ScaleShiftA
= texUnit
->_CurrentCombine
->ScaleShiftA
;
389 for (j
= 0; j
< MAX_COMBINER_TERMS
; j
++) {
390 key
->unit
[i
].OptRGB
[j
].Operand
=
391 translate_operand(texUnit
->_CurrentCombine
->OperandRGB
[j
]);
392 key
->unit
[i
].OptA
[j
].Operand
=
393 translate_operand(texUnit
->_CurrentCombine
->OperandA
[j
]);
394 key
->unit
[i
].OptRGB
[j
].Source
=
395 translate_source(texUnit
->_CurrentCombine
->SourceRGB
[j
]);
396 key
->unit
[i
].OptA
[j
].Source
=
397 translate_source(texUnit
->_CurrentCombine
->SourceA
[j
]);
400 if (key
->unit
[i
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
401 /* requires some special translation */
402 key
->unit
[i
].NumArgsRGB
= 2;
403 key
->unit
[i
].ScaleShiftRGB
= 0;
404 key
->unit
[i
].OptRGB
[0].Operand
= OPR_SRC_COLOR
;
405 key
->unit
[i
].OptRGB
[0].Source
= SRC_TEXTURE
;
406 key
->unit
[i
].OptRGB
[1].Operand
= OPR_SRC_COLOR
;
407 key
->unit
[i
].OptRGB
[1].Source
= texUnit
->BumpTarget
- GL_TEXTURE0
+ SRC_TEXTURE0
;
411 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) {
412 key
->separate_specular
= 1;
413 inputs_referenced
|= FRAG_BIT_COL1
;
416 if (ctx
->Fog
.Enabled
) {
417 key
->fog_enabled
= 1;
418 key
->fog_mode
= translate_fog_mode(ctx
->Fog
.Mode
);
419 inputs_referenced
|= FRAG_BIT_FOGC
; /* maybe */
422 key
->inputs_available
= (inputs_available
& inputs_referenced
);
426 * Use uregs to represent registers internally, translate to Mesa's
427 * expected formats on emit.
429 * NOTE: These are passed by value extensively in this file rather
430 * than as usual by pointer reference. If this disturbs you, try
431 * remembering they are just 32bits in size.
433 * GCC is smart enough to deal with these dword-sized structures in
434 * much the same way as if I had defined them as dwords and was using
435 * macros to access and set the fields. This is much nicer and easier
448 static const struct ureg undef
= {
459 /** State used to build the fragment program:
461 struct texenv_fragment_program
{
462 struct gl_fragment_program
*program
;
464 struct state_key
*state
;
466 GLbitfield alu_temps
; /**< Track texture indirections, see spec. */
467 GLbitfield temps_output
; /**< Track texture indirections, see spec. */
468 GLbitfield temp_in_use
; /**< Tracks temporary regs which are in use. */
471 struct ureg src_texture
[MAX_TEXTURE_COORD_UNITS
];
472 /* Reg containing each texture unit's sampled texture color,
476 struct ureg texcoord_tex
[MAX_TEXTURE_COORD_UNITS
];
477 /* Reg containing texcoord for a texture unit,
478 * needed for bump mapping, else undef.
481 struct ureg src_previous
; /**< Reg containing color from previous
482 * stage. May need to be decl'd.
485 GLuint last_tex_stage
; /**< Number of last enabled texture unit */
494 static struct ureg
make_ureg(GLuint file
, GLuint idx
)
502 reg
.swz
= SWIZZLE_NOOP
;
507 static struct ureg
swizzle( struct ureg reg
, int x
, int y
, int z
, int w
)
509 reg
.swz
= MAKE_SWIZZLE4(GET_SWZ(reg
.swz
, x
),
512 GET_SWZ(reg
.swz
, w
));
517 static struct ureg
swizzle1( struct ureg reg
, int x
)
519 return swizzle(reg
, x
, x
, x
, x
);
522 static struct ureg
negate( struct ureg reg
)
528 static GLboolean
is_undef( struct ureg reg
)
530 return reg
.file
== PROGRAM_UNDEFINED
;
534 static struct ureg
get_temp( struct texenv_fragment_program
*p
)
538 /* First try and reuse temps which have been used already:
540 bit
= _mesa_ffs( ~p
->temp_in_use
& p
->alu_temps
);
542 /* Then any unused temporary:
545 bit
= _mesa_ffs( ~p
->temp_in_use
);
548 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
552 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
553 p
->program
->Base
.NumTemporaries
= bit
;
555 p
->temp_in_use
|= 1<<(bit
-1);
556 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
559 static struct ureg
get_tex_temp( struct texenv_fragment_program
*p
)
563 /* First try to find available temp not previously used (to avoid
564 * starting a new texture indirection). According to the spec, the
565 * ~p->temps_output isn't necessary, but will keep it there for
568 bit
= _mesa_ffs( ~p
->temp_in_use
& ~p
->alu_temps
& ~p
->temps_output
);
570 /* Then any unused temporary:
573 bit
= _mesa_ffs( ~p
->temp_in_use
);
576 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
580 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
581 p
->program
->Base
.NumTemporaries
= bit
;
583 p
->temp_in_use
|= 1<<(bit
-1);
584 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
588 /** Mark a temp reg as being no longer allocatable. */
589 static void reserve_temp( struct texenv_fragment_program
*p
, struct ureg r
)
591 if (r
.file
== PROGRAM_TEMPORARY
)
592 p
->temps_output
|= (1 << r
.idx
);
596 static void release_temps(GLcontext
*ctx
, struct texenv_fragment_program
*p
)
598 GLuint max_temp
= ctx
->Const
.FragmentProgram
.MaxTemps
;
600 /* KW: To support tex_env_crossbar, don't release the registers in
603 if (max_temp
>= sizeof(int) * 8)
604 p
->temp_in_use
= p
->temps_output
;
606 p
->temp_in_use
= ~((1<<max_temp
)-1) | p
->temps_output
;
610 static struct ureg
register_param5( struct texenv_fragment_program
*p
,
617 gl_state_index tokens
[STATE_LENGTH
];
624 idx
= _mesa_add_state_reference( p
->program
->Base
.Parameters
, tokens
);
625 return make_ureg(PROGRAM_STATE_VAR
, idx
);
629 #define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
630 #define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
631 #define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
632 #define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
634 static GLuint
frag_to_vert_attrib( GLuint attrib
)
637 case FRAG_ATTRIB_COL0
: return VERT_ATTRIB_COLOR0
;
638 case FRAG_ATTRIB_COL1
: return VERT_ATTRIB_COLOR1
;
640 assert(attrib
>= FRAG_ATTRIB_TEX0
);
641 assert(attrib
<= FRAG_ATTRIB_TEX7
);
642 return attrib
- FRAG_ATTRIB_TEX0
+ VERT_ATTRIB_TEX0
;
647 static struct ureg
register_input( struct texenv_fragment_program
*p
, GLuint input
)
649 if (p
->state
->inputs_available
& (1<<input
)) {
650 p
->program
->Base
.InputsRead
|= (1 << input
);
651 return make_ureg(PROGRAM_INPUT
, input
);
654 GLuint idx
= frag_to_vert_attrib( input
);
655 return register_param3( p
, STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, idx
);
660 static void emit_arg( struct prog_src_register
*reg
,
663 reg
->File
= ureg
.file
;
664 reg
->Index
= ureg
.idx
;
665 reg
->Swizzle
= ureg
.swz
;
666 reg
->Negate
= ureg
.negatebase
? NEGATE_XYZW
: NEGATE_NONE
;
670 static void emit_dst( struct prog_dst_register
*dst
,
671 struct ureg ureg
, GLuint mask
)
673 dst
->File
= ureg
.file
;
674 dst
->Index
= ureg
.idx
;
675 dst
->WriteMask
= mask
;
676 dst
->CondMask
= COND_TR
; /* always pass cond test */
677 dst
->CondSwizzle
= SWIZZLE_NOOP
;
680 static struct prog_instruction
*
681 emit_op(struct texenv_fragment_program
*p
,
690 GLuint nr
= p
->program
->Base
.NumInstructions
++;
691 struct prog_instruction
*inst
= &p
->program
->Base
.Instructions
[nr
];
693 assert(nr
< MAX_INSTRUCTIONS
);
695 _mesa_init_instructions(inst
, 1);
698 emit_arg( &inst
->SrcReg
[0], src0
);
699 emit_arg( &inst
->SrcReg
[1], src1
);
700 emit_arg( &inst
->SrcReg
[2], src2
);
702 inst
->SaturateMode
= saturate
? SATURATE_ZERO_ONE
: SATURATE_OFF
;
704 emit_dst( &inst
->DstReg
, dest
, mask
);
707 /* Accounting for indirection tracking:
709 if (dest
.file
== PROGRAM_TEMPORARY
)
710 p
->temps_output
|= 1 << dest
.idx
;
717 static struct ureg
emit_arith( struct texenv_fragment_program
*p
,
726 emit_op(p
, op
, dest
, mask
, saturate
, src0
, src1
, src2
);
728 /* Accounting for indirection tracking:
730 if (src0
.file
== PROGRAM_TEMPORARY
)
731 p
->alu_temps
|= 1 << src0
.idx
;
733 if (!is_undef(src1
) && src1
.file
== PROGRAM_TEMPORARY
)
734 p
->alu_temps
|= 1 << src1
.idx
;
736 if (!is_undef(src2
) && src2
.file
== PROGRAM_TEMPORARY
)
737 p
->alu_temps
|= 1 << src2
.idx
;
739 if (dest
.file
== PROGRAM_TEMPORARY
)
740 p
->alu_temps
|= 1 << dest
.idx
;
742 p
->program
->Base
.NumAluInstructions
++;
746 static struct ureg
emit_texld( struct texenv_fragment_program
*p
,
755 struct prog_instruction
*inst
= emit_op( p
, op
,
757 GL_FALSE
, /* don't saturate? */
762 inst
->TexSrcTarget
= tex_idx
;
763 inst
->TexSrcUnit
= tex_unit
;
764 inst
->TexShadow
= tex_shadow
;
766 p
->program
->Base
.NumTexInstructions
++;
768 /* Accounting for indirection tracking:
770 reserve_temp(p
, dest
);
773 /* Is this a texture indirection?
775 if ((coord
.file
== PROGRAM_TEMPORARY
&&
776 (p
->temps_output
& (1<<coord
.idx
))) ||
777 (dest
.file
== PROGRAM_TEMPORARY
&&
778 (p
->alu_temps
& (1<<dest
.idx
)))) {
779 p
->program
->Base
.NumTexIndirections
++;
780 p
->temps_output
= 1<<coord
.idx
;
782 assert(0); /* KW: texture env crossbar */
790 static struct ureg
register_const4f( struct texenv_fragment_program
*p
,
803 idx
= _mesa_add_unnamed_constant( p
->program
->Base
.Parameters
, values
, 4,
805 r
= make_ureg(PROGRAM_CONSTANT
, idx
);
810 #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
811 #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
812 #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
813 #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
816 static struct ureg
get_one( struct texenv_fragment_program
*p
)
818 if (is_undef(p
->one
))
819 p
->one
= register_scalar_const(p
, 1.0);
823 static struct ureg
get_half( struct texenv_fragment_program
*p
)
825 if (is_undef(p
->half
))
826 p
->half
= register_scalar_const(p
, 0.5);
830 static struct ureg
get_zero( struct texenv_fragment_program
*p
)
832 if (is_undef(p
->zero
))
833 p
->zero
= register_scalar_const(p
, 0.0);
838 static void program_error( struct texenv_fragment_program
*p
, const char *msg
)
840 _mesa_problem(NULL
, msg
);
844 static struct ureg
get_source( struct texenv_fragment_program
*p
,
845 GLuint src
, GLuint unit
)
849 assert(!is_undef(p
->src_texture
[unit
]));
850 return p
->src_texture
[unit
];
860 assert(!is_undef(p
->src_texture
[src
- SRC_TEXTURE0
]));
861 return p
->src_texture
[src
- SRC_TEXTURE0
];
864 return register_param2(p
, STATE_TEXENV_COLOR
, unit
);
866 case SRC_PRIMARY_COLOR
:
867 return register_input(p
, FRAG_ATTRIB_COL0
);
873 if (is_undef(p
->src_previous
))
874 return register_input(p
, FRAG_ATTRIB_COL0
);
876 return p
->src_previous
;
883 static struct ureg
emit_combine_source( struct texenv_fragment_program
*p
,
889 struct ureg arg
, src
, one
;
891 src
= get_source(p
, source
, unit
);
894 case OPR_ONE_MINUS_SRC_COLOR
:
896 * Emit tmp = 1.0 - arg.xyzw
900 return emit_arith( p
, OPCODE_SUB
, arg
, mask
, 0, one
, src
, undef
);
903 if (mask
== WRITEMASK_W
)
906 return swizzle1( src
, SWIZZLE_W
);
907 case OPR_ONE_MINUS_SRC_ALPHA
:
909 * Emit tmp = 1.0 - arg.wwww
913 return emit_arith(p
, OPCODE_SUB
, arg
, mask
, 0,
914 one
, swizzle1(src
, SWIZZLE_W
), undef
);
927 static GLboolean
args_match( struct state_key
*key
, GLuint unit
)
929 GLuint i
, nr
= key
->unit
[unit
].NumArgsRGB
;
931 for (i
= 0 ; i
< nr
; i
++) {
932 if (key
->unit
[unit
].OptA
[i
].Source
!= key
->unit
[unit
].OptRGB
[i
].Source
)
935 switch(key
->unit
[unit
].OptA
[i
].Operand
) {
937 switch(key
->unit
[unit
].OptRGB
[i
].Operand
) {
945 case OPR_ONE_MINUS_SRC_ALPHA
:
946 switch(key
->unit
[unit
].OptRGB
[i
].Operand
) {
947 case OPR_ONE_MINUS_SRC_COLOR
:
948 case OPR_ONE_MINUS_SRC_ALPHA
:
955 return GL_FALSE
; /* impossible */
962 static struct ureg
emit_combine( struct texenv_fragment_program
*p
,
969 const struct mode_opt
*opt
)
971 struct ureg src
[MAX_COMBINER_TERMS
];
972 struct ureg tmp
, half
;
975 assert(nr
<= MAX_COMBINER_TERMS
);
977 tmp
= undef
; /* silence warning (bug 5318) */
979 for (i
= 0; i
< nr
; i
++)
980 src
[i
] = emit_combine_source( p
, mask
, unit
, opt
[i
].Source
, opt
[i
].Operand
);
984 if (mask
== WRITEMASK_XYZW
&& !saturate
)
987 return emit_arith( p
, OPCODE_MOV
, dest
, mask
, saturate
, src
[0], undef
, undef
);
989 return emit_arith( p
, OPCODE_MUL
, dest
, mask
, saturate
,
990 src
[0], src
[1], undef
);
992 return emit_arith( p
, OPCODE_ADD
, dest
, mask
, saturate
,
993 src
[0], src
[1], undef
);
994 case MODE_ADD_SIGNED
:
1000 emit_arith( p
, OPCODE_ADD
, tmp
, mask
, 0, src
[0], src
[1], undef
);
1001 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp
, half
, undef
);
1003 case MODE_INTERPOLATE
:
1004 /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered:
1006 return emit_arith( p
, OPCODE_LRP
, dest
, mask
, saturate
, src
[2], src
[0], src
[1] );
1009 return emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, src
[0], src
[1], undef
);
1011 case MODE_DOT3_RGBA
:
1012 case MODE_DOT3_RGBA_EXT
:
1013 case MODE_DOT3_RGB_EXT
:
1014 case MODE_DOT3_RGB
: {
1015 struct ureg tmp0
= get_temp( p
);
1016 struct ureg tmp1
= get_temp( p
);
1017 struct ureg neg1
= register_scalar_const(p
, -1);
1018 struct ureg two
= register_scalar_const(p
, 2);
1020 /* tmp0 = 2*src0 - 1
1023 * dst = tmp0 dot3 tmp1
1025 emit_arith( p
, OPCODE_MAD
, tmp0
, WRITEMASK_XYZW
, 0,
1028 if (_mesa_memcmp(&src
[0], &src
[1], sizeof(struct ureg
)) == 0)
1031 emit_arith( p
, OPCODE_MAD
, tmp1
, WRITEMASK_XYZW
, 0,
1033 emit_arith( p
, OPCODE_DP3
, dest
, mask
, saturate
, tmp0
, tmp1
, undef
);
1036 case MODE_MODULATE_ADD_ATI
:
1037 /* Arg0 * Arg2 + Arg1 */
1038 return emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
,
1039 src
[0], src
[2], src
[1] );
1040 case MODE_MODULATE_SIGNED_ADD_ATI
: {
1041 /* Arg0 * Arg2 + Arg1 - 0.5 */
1042 struct ureg tmp0
= get_temp(p
);
1044 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[0], src
[2], src
[1] );
1045 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1048 case MODE_MODULATE_SUBTRACT_ATI
:
1049 /* Arg0 * Arg2 - Arg1 */
1050 emit_arith( p
, OPCODE_MAD
, dest
, mask
, 0, src
[0], src
[2], negate(src
[1]) );
1052 case MODE_ADD_PRODUCTS
:
1053 /* Arg0 * Arg1 + Arg2 * Arg3 */
1055 struct ureg tmp0
= get_temp(p
);
1056 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1057 emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
, src
[2], src
[3], tmp0
);
1060 case MODE_ADD_PRODUCTS_SIGNED
:
1061 /* Arg0 * Arg1 + Arg2 * Arg3 - 0.5 */
1063 struct ureg tmp0
= get_temp(p
);
1065 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1066 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[2], src
[3], tmp0
);
1067 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1070 case MODE_BUMP_ENVMAP_ATI
:
1071 /* special - not handled here */
1082 * Generate instructions for one texture unit's env/combiner mode.
1085 emit_texenv(struct texenv_fragment_program
*p
, GLuint unit
)
1087 struct state_key
*key
= p
->state
;
1088 GLboolean saturate
= (unit
< p
->last_tex_stage
);
1089 GLuint rgb_shift
, alpha_shift
;
1090 struct ureg out
, shift
;
1093 if (!key
->unit
[unit
].enabled
) {
1094 return get_source(p
, SRC_PREVIOUS
, 0);
1096 if (key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1097 /* this isn't really a env stage delivering a color and handled elsewhere */
1098 return get_source(p
, SRC_PREVIOUS
, 0);
1101 switch (key
->unit
[unit
].ModeRGB
) {
1102 case MODE_DOT3_RGB_EXT
:
1103 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1106 case MODE_DOT3_RGBA_EXT
:
1111 rgb_shift
= key
->unit
[unit
].ScaleShiftRGB
;
1112 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1116 /* If this is the very last calculation, emit direct to output reg:
1118 if (key
->separate_specular
||
1119 unit
!= p
->last_tex_stage
||
1122 dest
= get_temp( p
);
1124 dest
= make_ureg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1126 /* Emit the RGB and A combine ops
1128 if (key
->unit
[unit
].ModeRGB
== key
->unit
[unit
].ModeA
&&
1129 args_match(key
, unit
)) {
1130 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1132 key
->unit
[unit
].NumArgsRGB
,
1133 key
->unit
[unit
].ModeRGB
,
1134 key
->unit
[unit
].OptRGB
);
1136 else if (key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA_EXT
||
1137 key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA
) {
1139 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1141 key
->unit
[unit
].NumArgsRGB
,
1142 key
->unit
[unit
].ModeRGB
,
1143 key
->unit
[unit
].OptRGB
);
1146 /* Need to do something to stop from re-emitting identical
1147 * argument calculations here:
1149 out
= emit_combine( p
, dest
, WRITEMASK_XYZ
, saturate
,
1151 key
->unit
[unit
].NumArgsRGB
,
1152 key
->unit
[unit
].ModeRGB
,
1153 key
->unit
[unit
].OptRGB
);
1154 out
= emit_combine( p
, dest
, WRITEMASK_W
, saturate
,
1156 key
->unit
[unit
].NumArgsA
,
1157 key
->unit
[unit
].ModeA
,
1158 key
->unit
[unit
].OptA
);
1161 /* Deal with the final shift:
1163 if (alpha_shift
|| rgb_shift
) {
1164 if (rgb_shift
== alpha_shift
) {
1165 shift
= register_scalar_const(p
, (GLfloat
)(1<<rgb_shift
));
1168 shift
= register_const4f(p
,
1169 (GLfloat
)(1<<rgb_shift
),
1170 (GLfloat
)(1<<rgb_shift
),
1171 (GLfloat
)(1<<rgb_shift
),
1172 (GLfloat
)(1<<alpha_shift
));
1174 return emit_arith( p
, OPCODE_MUL
, dest
, WRITEMASK_XYZW
,
1175 saturate
, out
, shift
, undef
);
1183 * Generate instruction for getting a texture source term.
1185 static void load_texture( struct texenv_fragment_program
*p
, GLuint unit
)
1187 if (is_undef(p
->src_texture
[unit
])) {
1188 GLuint texTarget
= p
->state
->unit
[unit
].source_index
;
1189 struct ureg texcoord
;
1190 struct ureg tmp
= get_tex_temp( p
);
1192 if (is_undef(p
->texcoord_tex
[unit
])) {
1193 texcoord
= register_input(p
, FRAG_ATTRIB_TEX0
+unit
);
1196 /* might want to reuse this reg for tex output actually */
1197 texcoord
= p
->texcoord_tex
[unit
];
1200 if (texTarget
== TEXTURE_UNKNOWN_INDEX
)
1201 program_error(p
, "TexSrcBit");
1203 /* TODO: Use D0_MASK_XY where possible.
1205 if (p
->state
->unit
[unit
].enabled
) {
1206 GLboolean shadow
= GL_FALSE
;
1208 if (p
->state
->unit
[unit
].shadow
) {
1209 p
->program
->Base
.ShadowSamplers
|= 1 << unit
;
1213 p
->src_texture
[unit
] = emit_texld( p
, OPCODE_TXP
,
1214 tmp
, WRITEMASK_XYZW
,
1215 unit
, texTarget
, shadow
,
1218 p
->program
->Base
.SamplersUsed
|= (1 << unit
);
1219 /* This identity mapping should already be in place
1220 * (see _mesa_init_program_struct()) but let's be safe.
1222 p
->program
->Base
.SamplerUnits
[unit
] = unit
;
1225 p
->src_texture
[unit
] = get_zero(p
);
1229 static GLboolean
load_texenv_source( struct texenv_fragment_program
*p
,
1230 GLuint src
, GLuint unit
)
1234 load_texture(p
, unit
);
1245 load_texture(p
, src
- SRC_TEXTURE0
);
1249 /* not a texture src - do nothing */
1258 * Generate instructions for loading all texture source terms.
1261 load_texunit_sources( struct texenv_fragment_program
*p
, int unit
)
1263 struct state_key
*key
= p
->state
;
1266 for (i
= 0; i
< key
->unit
[unit
].NumArgsRGB
; i
++) {
1267 load_texenv_source( p
, key
->unit
[unit
].OptRGB
[i
].Source
, unit
);
1270 for (i
= 0; i
< key
->unit
[unit
].NumArgsA
; i
++) {
1271 load_texenv_source( p
, key
->unit
[unit
].OptA
[i
].Source
, unit
);
1278 * Generate instructions for loading bump map textures.
1281 load_texunit_bumpmap( struct texenv_fragment_program
*p
, int unit
)
1283 struct state_key
*key
= p
->state
;
1284 GLuint bumpedUnitNr
= key
->unit
[unit
].OptRGB
[1].Source
- SRC_TEXTURE0
;
1285 struct ureg texcDst
, bumpMapRes
;
1286 struct ureg constdudvcolor
= register_const4f(p
, 0.0, 0.0, 0.0, 1.0);
1287 struct ureg texcSrc
= register_input(p
, FRAG_ATTRIB_TEX0
+ bumpedUnitNr
);
1288 struct ureg rotMat0
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_0
, unit
);
1289 struct ureg rotMat1
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_1
, unit
);
1291 load_texenv_source( p
, unit
+ SRC_TEXTURE0
, unit
);
1293 bumpMapRes
= get_source(p
, key
->unit
[unit
].OptRGB
[0].Source
, unit
);
1294 texcDst
= get_tex_temp( p
);
1295 p
->texcoord_tex
[bumpedUnitNr
] = texcDst
;
1297 /* apply rot matrix and add coords to be available in next phase */
1298 /* dest = (Arg0.xxxx * rotMat0 + Arg1) + (Arg0.yyyy * rotMat1) */
1299 /* note only 2 coords are affected the rest are left unchanged (mul by 0) */
1300 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1301 swizzle1(bumpMapRes
, SWIZZLE_X
), rotMat0
, texcSrc
);
1302 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1303 swizzle1(bumpMapRes
, SWIZZLE_Y
), rotMat1
, texcDst
);
1305 /* move 0,0,0,1 into bumpmap src if someone (crossbar) is foolish
1306 enough to access this later, should optimize away */
1307 emit_arith( p
, OPCODE_MOV
, bumpMapRes
, WRITEMASK_XYZW
, 0, constdudvcolor
, undef
, undef
);
1313 * Generate a new fragment program which implements the context's
1314 * current texture env/combine mode.
1317 create_new_program(GLcontext
*ctx
, struct state_key
*key
,
1318 struct gl_fragment_program
*program
)
1320 struct prog_instruction instBuffer
[MAX_INSTRUCTIONS
];
1321 struct texenv_fragment_program p
;
1323 struct ureg cf
, out
;
1325 _mesa_memset(&p
, 0, sizeof(p
));
1328 p
.program
= program
;
1330 /* During code generation, use locally-allocated instruction buffer,
1331 * then alloc dynamic storage below.
1333 p
.program
->Base
.Instructions
= instBuffer
;
1334 p
.program
->Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
1335 p
.program
->Base
.NumTexIndirections
= 1;
1336 p
.program
->Base
.NumTexInstructions
= 0;
1337 p
.program
->Base
.NumAluInstructions
= 0;
1338 p
.program
->Base
.String
= NULL
;
1339 p
.program
->Base
.NumInstructions
=
1340 p
.program
->Base
.NumTemporaries
=
1341 p
.program
->Base
.NumParameters
=
1342 p
.program
->Base
.NumAttributes
= p
.program
->Base
.NumAddressRegs
= 0;
1343 p
.program
->Base
.Parameters
= _mesa_new_parameter_list();
1345 p
.program
->Base
.InputsRead
= 0;
1346 p
.program
->Base
.OutputsWritten
= 1 << FRAG_RESULT_COLOR
;
1348 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
1349 p
.src_texture
[unit
] = undef
;
1350 p
.texcoord_tex
[unit
] = undef
;
1353 p
.src_previous
= undef
;
1358 p
.last_tex_stage
= 0;
1359 release_temps(ctx
, &p
);
1361 if (key
->enabled_units
) {
1362 GLboolean needbumpstage
= GL_FALSE
;
1363 /* Zeroth pass - bump map textures first */
1364 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1365 if (key
->unit
[unit
].enabled
&& key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1366 needbumpstage
= GL_TRUE
;
1367 load_texunit_bumpmap( &p
, unit
);
1370 p
.program
->Base
.NumTexIndirections
++;
1372 /* First pass - to support texture_env_crossbar, first identify
1373 * all referenced texture sources and emit texld instructions
1376 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1377 if (key
->unit
[unit
].enabled
) {
1378 load_texunit_sources( &p
, unit
);
1379 p
.last_tex_stage
= unit
;
1382 /* Second pass - emit combine instructions to build final color:
1384 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1385 if (key
->enabled_units
& (1<<unit
)) {
1386 p
.src_previous
= emit_texenv( &p
, unit
);
1387 reserve_temp(&p
, p
.src_previous
); /* don't re-use this temp reg */
1388 release_temps(ctx
, &p
); /* release all temps */
1392 cf
= get_source( &p
, SRC_PREVIOUS
, 0 );
1393 out
= make_ureg( PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1395 if (key
->separate_specular
) {
1396 /* Emit specular add.
1398 struct ureg s
= register_input(&p
, FRAG_ATTRIB_COL1
);
1399 emit_arith( &p
, OPCODE_ADD
, out
, WRITEMASK_XYZ
, 0, cf
, s
, undef
);
1400 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_W
, 0, cf
, undef
, undef
);
1402 else if (_mesa_memcmp(&cf
, &out
, sizeof(cf
)) != 0) {
1403 /* Will wind up in here if no texture enabled or a couple of
1404 * other scenarios (GL_REPLACE for instance).
1406 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_XYZW
, 0, cf
, undef
, undef
);
1411 emit_arith( &p
, OPCODE_END
, undef
, WRITEMASK_XYZW
, 0, undef
, undef
, undef
);
1413 if (key
->fog_enabled
) {
1414 /* Pull fog mode from GLcontext, the value in the state key is
1415 * a reduced value and not what is expected in FogOption
1417 p
.program
->FogOption
= ctx
->Fog
.Mode
;
1418 p
.program
->Base
.InputsRead
|= FRAG_BIT_FOGC
; /* XXX new */
1420 p
.program
->FogOption
= GL_NONE
;
1422 if (p
.program
->Base
.NumTexIndirections
> ctx
->Const
.FragmentProgram
.MaxTexIndirections
)
1423 program_error(&p
, "Exceeded max nr indirect texture lookups");
1425 if (p
.program
->Base
.NumTexInstructions
> ctx
->Const
.FragmentProgram
.MaxTexInstructions
)
1426 program_error(&p
, "Exceeded max TEX instructions");
1428 if (p
.program
->Base
.NumAluInstructions
> ctx
->Const
.FragmentProgram
.MaxAluInstructions
)
1429 program_error(&p
, "Exceeded max ALU instructions");
1431 ASSERT(p
.program
->Base
.NumInstructions
<= MAX_INSTRUCTIONS
);
1433 /* Allocate final instruction array */
1434 p
.program
->Base
.Instructions
1435 = _mesa_alloc_instructions(p
.program
->Base
.NumInstructions
);
1436 if (!p
.program
->Base
.Instructions
) {
1437 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1438 "generating tex env program");
1441 _mesa_copy_instructions(p
.program
->Base
.Instructions
, instBuffer
,
1442 p
.program
->Base
.NumInstructions
);
1444 if (p
.program
->FogOption
) {
1445 _mesa_append_fog_code(ctx
, p
.program
);
1446 p
.program
->FogOption
= GL_NONE
;
1450 /* Notify driver the fragment program has (actually) changed.
1452 if (ctx
->Driver
.ProgramStringNotify
) {
1453 ctx
->Driver
.ProgramStringNotify( ctx
, GL_FRAGMENT_PROGRAM_ARB
,
1458 _mesa_print_program(&p
.program
->Base
);
1465 * Return a fragment program which implements the current
1466 * fixed-function texture, fog and color-sum operations.
1468 struct gl_fragment_program
*
1469 _mesa_get_fixed_func_fragment_program(GLcontext
*ctx
)
1471 struct gl_fragment_program
*prog
;
1472 struct state_key key
;
1474 make_state_key(ctx
, &key
);
1476 prog
= (struct gl_fragment_program
*)
1477 _mesa_search_program_cache(ctx
->FragmentProgram
.Cache
,
1481 prog
= (struct gl_fragment_program
*)
1482 ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
1484 create_new_program(ctx
, &key
, prog
);
1486 _mesa_program_cache_insert(ctx
, ctx
->FragmentProgram
.Cache
,
1487 &key
, sizeof(key
), &prog
->Base
);