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"
46 * Note on texture units:
48 * The number of texture units supported by fixed-function fragment
49 * processing is MAX_TEXTURE_COORD_UNITS, not MAX_TEXTURE_IMAGE_UNITS.
50 * That's because there's a one-to-one correspondence between texture
51 * coordinates and samplers in fixed-function processing.
53 * Since fixed-function vertex processing is limited to MAX_TEXTURE_COORD_UNITS
54 * sets of texcoords, so is fixed-function fragment processing.
56 * We can safely use ctx->Const.MaxTextureUnits for loop bounds.
60 struct texenvprog_cache_item
64 struct gl_fragment_program
*data
;
65 struct texenvprog_cache_item
*next
;
70 * Up to nine instructions per tex unit, plus fog, specular color.
72 #define MAX_INSTRUCTIONS ((MAX_TEXTURE_COORD_UNITS * 9) + 12)
74 #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM)
82 GLuint nr_enabled_units
:8;
83 GLuint enabled_units
:8;
84 GLuint separate_specular
:1;
87 GLuint inputs_available
:12;
91 GLuint source_index
:3; /* one of TEXTURE_1D/2D/3D/CUBE/RECT_INDEX */
93 GLuint ScaleShiftRGB
:2;
98 struct mode_opt OptRGB
[MAX_TERMS
];
102 struct mode_opt OptA
[MAX_TERMS
];
109 #define FOG_UNKNOWN 3
111 static GLuint
translate_fog_mode( GLenum mode
)
114 case GL_LINEAR
: return FOG_LINEAR
;
115 case GL_EXP
: return FOG_EXP
;
116 case GL_EXP2
: return FOG_EXP2
;
117 default: return FOG_UNKNOWN
;
121 #define OPR_SRC_COLOR 0
122 #define OPR_ONE_MINUS_SRC_COLOR 1
123 #define OPR_SRC_ALPHA 2
124 #define OPR_ONE_MINUS_SRC_ALPHA 3
127 #define OPR_UNKNOWN 7
129 static GLuint
translate_operand( GLenum operand
)
132 case GL_SRC_COLOR
: return OPR_SRC_COLOR
;
133 case GL_ONE_MINUS_SRC_COLOR
: return OPR_ONE_MINUS_SRC_COLOR
;
134 case GL_SRC_ALPHA
: return OPR_SRC_ALPHA
;
135 case GL_ONE_MINUS_SRC_ALPHA
: return OPR_ONE_MINUS_SRC_ALPHA
;
136 case GL_ZERO
: return OPR_ZERO
;
137 case GL_ONE
: return OPR_ONE
;
144 #define SRC_TEXTURE 0
145 #define SRC_TEXTURE0 1
146 #define SRC_TEXTURE1 2
147 #define SRC_TEXTURE2 3
148 #define SRC_TEXTURE3 4
149 #define SRC_TEXTURE4 5
150 #define SRC_TEXTURE5 6
151 #define SRC_TEXTURE6 7
152 #define SRC_TEXTURE7 8
153 #define SRC_CONSTANT 9
154 #define SRC_PRIMARY_COLOR 10
155 #define SRC_PREVIOUS 11
157 #define SRC_UNKNOWN 15
159 static GLuint
translate_source( GLenum src
)
162 case GL_TEXTURE
: return SRC_TEXTURE
;
170 case GL_TEXTURE7
: return SRC_TEXTURE0
+ (src
- GL_TEXTURE0
);
171 case GL_CONSTANT
: return SRC_CONSTANT
;
172 case GL_PRIMARY_COLOR
: return SRC_PRIMARY_COLOR
;
173 case GL_PREVIOUS
: return SRC_PREVIOUS
;
182 #define MODE_REPLACE 0 /* r = a0 */
183 #define MODE_MODULATE 1 /* r = a0 * a1 */
184 #define MODE_ADD 2 /* r = a0 + a1 */
185 #define MODE_ADD_SIGNED 3 /* r = a0 + a1 - 0.5 */
186 #define MODE_INTERPOLATE 4 /* r = a0 * a2 + a1 * (1 - a2) */
187 #define MODE_SUBTRACT 5 /* r = a0 - a1 */
188 #define MODE_DOT3_RGB 6 /* r = a0 . a1 */
189 #define MODE_DOT3_RGB_EXT 7 /* r = a0 . a1 */
190 #define MODE_DOT3_RGBA 8 /* r = a0 . a1 */
191 #define MODE_DOT3_RGBA_EXT 9 /* r = a0 . a1 */
192 #define MODE_MODULATE_ADD_ATI 10 /* r = a0 * a2 + a1 */
193 #define MODE_MODULATE_SIGNED_ADD_ATI 11 /* r = a0 * a2 + a1 - 0.5 */
194 #define MODE_MODULATE_SUBTRACT_ATI 12 /* r = a0 * a2 - a1 */
195 #define MODE_ADD_PRODUCTS 13 /* r = a0 * a1 + a2 * a3 */
196 #define MODE_ADD_PRODUCTS_SIGNED 14 /* r = a0 * a1 + a2 * a3 - 0.5 */
197 #define MODE_BUMP_ENVMAP_ATI 15 /* special */
198 #define MODE_UNKNOWN 16
201 * Translate GL combiner state into a MODE_x value
203 static GLuint
translate_mode( GLenum envMode
, GLenum mode
)
206 case GL_REPLACE
: return MODE_REPLACE
;
207 case GL_MODULATE
: return MODE_MODULATE
;
209 if (envMode
== GL_COMBINE4_NV
)
210 return MODE_ADD_PRODUCTS
;
214 if (envMode
== GL_COMBINE4_NV
)
215 return MODE_ADD_PRODUCTS_SIGNED
;
217 return MODE_ADD_SIGNED
;
218 case GL_INTERPOLATE
: return MODE_INTERPOLATE
;
219 case GL_SUBTRACT
: return MODE_SUBTRACT
;
220 case GL_DOT3_RGB
: return MODE_DOT3_RGB
;
221 case GL_DOT3_RGB_EXT
: return MODE_DOT3_RGB_EXT
;
222 case GL_DOT3_RGBA
: return MODE_DOT3_RGBA
;
223 case GL_DOT3_RGBA_EXT
: return MODE_DOT3_RGBA_EXT
;
224 case GL_MODULATE_ADD_ATI
: return MODE_MODULATE_ADD_ATI
;
225 case GL_MODULATE_SIGNED_ADD_ATI
: return MODE_MODULATE_SIGNED_ADD_ATI
;
226 case GL_MODULATE_SUBTRACT_ATI
: return MODE_MODULATE_SUBTRACT_ATI
;
227 case GL_BUMP_ENVMAP_ATI
: return MODE_BUMP_ENVMAP_ATI
;
234 #define TEXTURE_UNKNOWN_INDEX 7
235 static GLuint
translate_tex_src_bit( GLbitfield bit
)
237 /* make sure number of switch cases is correct */
238 assert(NUM_TEXTURE_TARGETS
== 7);
240 case TEXTURE_1D_BIT
: return TEXTURE_1D_INDEX
;
241 case TEXTURE_2D_BIT
: return TEXTURE_2D_INDEX
;
242 case TEXTURE_RECT_BIT
: return TEXTURE_RECT_INDEX
;
243 case TEXTURE_3D_BIT
: return TEXTURE_3D_INDEX
;
244 case TEXTURE_CUBE_BIT
: return TEXTURE_CUBE_INDEX
;
245 case TEXTURE_1D_ARRAY_BIT
: return TEXTURE_1D_ARRAY_INDEX
;
246 case TEXTURE_2D_ARRAY_BIT
: return TEXTURE_2D_ARRAY_INDEX
;
249 return TEXTURE_UNKNOWN_INDEX
;
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
)
267 const GLboolean vertexShader
= (ctx
->Shader
.CurrentProgram
&&
268 ctx
->Shader
.CurrentProgram
->VertexProgram
);
269 const GLboolean vertexProgram
= ctx
->VertexProgram
._Enabled
;
270 GLbitfield fp_inputs
= 0x0;
272 if (ctx
->VertexProgram
._Overriden
) {
273 /* Somebody's messing with the vertex program and we don't have
274 * a clue what's happening. Assume that it could be producing
275 * all possible outputs.
279 else if (ctx
->RenderMode
== GL_FEEDBACK
) {
280 fp_inputs
= (FRAG_BIT_COL0
| FRAG_BIT_TEX0
);
282 else if (!(vertexProgram
|| vertexShader
) ||
283 !ctx
->VertexProgram
._Current
) {
284 /* Fixed function vertex logic */
285 GLbitfield varying_inputs
= ctx
->varying_vp_inputs
;
287 /* These get generated in the setup routine regardless of the
290 if (ctx
->Point
.PointSprite
)
291 varying_inputs
|= FRAG_BITS_TEX_ANY
;
293 /* First look at what values may be computed by the generated
296 if (ctx
->Light
.Enabled
) {
297 fp_inputs
|= FRAG_BIT_COL0
;
299 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
)
300 fp_inputs
|= FRAG_BIT_COL1
;
303 fp_inputs
|= (ctx
->Texture
._TexGenEnabled
|
304 ctx
->Texture
._TexMatEnabled
) << FRAG_ATTRIB_TEX0
;
306 /* Then look at what might be varying as a result of enabled
309 if (varying_inputs
& VERT_BIT_COLOR0
) fp_inputs
|= FRAG_BIT_COL0
;
310 if (varying_inputs
& VERT_BIT_COLOR1
) fp_inputs
|= FRAG_BIT_COL1
;
312 fp_inputs
|= (((varying_inputs
& VERT_BIT_TEX_ANY
) >> VERT_ATTRIB_TEX0
)
313 << FRAG_ATTRIB_TEX0
);
317 /* calculate from vp->outputs */
318 struct gl_vertex_program
*vprog
;
319 GLbitfield vp_outputs
;
321 /* Choose GLSL vertex shader over ARB vertex program. Need this
322 * since vertex shader state validation comes after fragment state
323 * validation (see additional comments in state.c).
326 vprog
= ctx
->Shader
.CurrentProgram
->VertexProgram
;
328 vprog
= ctx
->VertexProgram
._Current
;
330 vp_outputs
= vprog
->Base
.OutputsWritten
;
332 /* These get generated in the setup routine regardless of the
335 if (ctx
->Point
.PointSprite
)
336 vp_outputs
|= FRAG_BITS_TEX_ANY
;
338 if (vp_outputs
& (1 << VERT_RESULT_COL0
)) fp_inputs
|= FRAG_BIT_COL0
;
339 if (vp_outputs
& (1 << VERT_RESULT_COL1
)) fp_inputs
|= FRAG_BIT_COL1
;
341 fp_inputs
|= (((vp_outputs
& VERT_RESULT_TEX_ANY
) >> VERT_RESULT_TEX0
)
342 << FRAG_ATTRIB_TEX0
);
350 * Examine current texture environment state and generate a unique
351 * key to identify it.
353 static void make_state_key( GLcontext
*ctx
, struct state_key
*key
)
356 GLbitfield inputs_referenced
= FRAG_BIT_COL0
;
357 GLbitfield inputs_available
= get_fp_input_mask( ctx
);
359 memset(key
, 0, sizeof(*key
));
361 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
362 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
365 if (!texUnit
->_ReallyEnabled
|| !texUnit
->Enabled
)
368 format
= texUnit
->_Current
->Image
[0][texUnit
->_Current
->BaseLevel
]->_BaseFormat
;
370 key
->unit
[i
].enabled
= 1;
371 key
->enabled_units
|= (1<<i
);
372 key
->nr_enabled_units
= i
+1;
373 inputs_referenced
|= FRAG_BIT_TEX(i
);
375 key
->unit
[i
].source_index
=
376 translate_tex_src_bit(texUnit
->_ReallyEnabled
);
377 key
->unit
[i
].shadow
= ((texUnit
->_Current
->CompareMode
== GL_COMPARE_R_TO_TEXTURE
) &&
378 ((format
== GL_DEPTH_COMPONENT
) ||
379 (format
== GL_DEPTH_STENCIL_EXT
)));
381 key
->unit
[i
].NumArgsRGB
= texUnit
->_CurrentCombine
->_NumArgsRGB
;
382 key
->unit
[i
].NumArgsA
= texUnit
->_CurrentCombine
->_NumArgsA
;
384 key
->unit
[i
].ModeRGB
=
385 translate_mode(texUnit
->EnvMode
, texUnit
->_CurrentCombine
->ModeRGB
);
387 translate_mode(texUnit
->EnvMode
, texUnit
->_CurrentCombine
->ModeA
);
389 key
->unit
[i
].ScaleShiftRGB
= texUnit
->_CurrentCombine
->ScaleShiftRGB
;
390 key
->unit
[i
].ScaleShiftA
= texUnit
->_CurrentCombine
->ScaleShiftA
;
392 for (j
= 0; j
< MAX_TERMS
; j
++) {
393 key
->unit
[i
].OptRGB
[j
].Operand
=
394 translate_operand(texUnit
->_CurrentCombine
->OperandRGB
[j
]);
395 key
->unit
[i
].OptA
[j
].Operand
=
396 translate_operand(texUnit
->_CurrentCombine
->OperandA
[j
]);
397 key
->unit
[i
].OptRGB
[j
].Source
=
398 translate_source(texUnit
->_CurrentCombine
->SourceRGB
[j
]);
399 key
->unit
[i
].OptA
[j
].Source
=
400 translate_source(texUnit
->_CurrentCombine
->SourceA
[j
]);
403 if (key
->unit
[i
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
404 /* requires some special translation */
405 key
->unit
[i
].NumArgsRGB
= 2;
406 key
->unit
[i
].ScaleShiftRGB
= 0;
407 key
->unit
[i
].OptRGB
[0].Operand
= OPR_SRC_COLOR
;
408 key
->unit
[i
].OptRGB
[0].Source
= SRC_TEXTURE
;
409 key
->unit
[i
].OptRGB
[1].Operand
= OPR_SRC_COLOR
;
410 key
->unit
[i
].OptRGB
[1].Source
= texUnit
->BumpTarget
- GL_TEXTURE0
+ SRC_TEXTURE0
;
414 if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) {
415 key
->separate_specular
= 1;
416 inputs_referenced
|= FRAG_BIT_COL1
;
419 if (ctx
->Fog
.Enabled
) {
420 key
->fog_enabled
= 1;
421 key
->fog_mode
= translate_fog_mode(ctx
->Fog
.Mode
);
422 inputs_referenced
|= FRAG_BIT_FOGC
; /* maybe */
425 key
->inputs_available
= (inputs_available
& inputs_referenced
);
429 * Use uregs to represent registers internally, translate to Mesa's
430 * expected formats on emit.
432 * NOTE: These are passed by value extensively in this file rather
433 * than as usual by pointer reference. If this disturbs you, try
434 * remembering they are just 32bits in size.
436 * GCC is smart enough to deal with these dword-sized structures in
437 * much the same way as if I had defined them as dwords and was using
438 * macros to access and set the fields. This is much nicer and easier
451 static const struct ureg undef
= {
462 /** State used to build the fragment program:
464 struct texenv_fragment_program
{
465 struct gl_fragment_program
*program
;
467 struct state_key
*state
;
469 GLbitfield alu_temps
; /**< Track texture indirections, see spec. */
470 GLbitfield temps_output
; /**< Track texture indirections, see spec. */
471 GLbitfield temp_in_use
; /**< Tracks temporary regs which are in use. */
474 struct ureg src_texture
[MAX_TEXTURE_COORD_UNITS
];
475 /* Reg containing each texture unit's sampled texture color,
479 struct ureg texcoord_tex
[MAX_TEXTURE_COORD_UNITS
];
480 /* Reg containing texcoord for a texture unit,
481 * needed for bump mapping, else undef.
484 struct ureg src_previous
; /**< Reg containing color from previous
485 * stage. May need to be decl'd.
488 GLuint last_tex_stage
; /**< Number of last enabled texture unit */
497 static struct ureg
make_ureg(GLuint file
, GLuint idx
)
505 reg
.swz
= SWIZZLE_NOOP
;
510 static struct ureg
swizzle( struct ureg reg
, int x
, int y
, int z
, int w
)
512 reg
.swz
= MAKE_SWIZZLE4(GET_SWZ(reg
.swz
, x
),
515 GET_SWZ(reg
.swz
, w
));
520 static struct ureg
swizzle1( struct ureg reg
, int x
)
522 return swizzle(reg
, x
, x
, x
, x
);
525 static struct ureg
negate( struct ureg reg
)
531 static GLboolean
is_undef( struct ureg reg
)
533 return reg
.file
== PROGRAM_UNDEFINED
;
537 static struct ureg
get_temp( struct texenv_fragment_program
*p
)
541 /* First try and reuse temps which have been used already:
543 bit
= _mesa_ffs( ~p
->temp_in_use
& p
->alu_temps
);
545 /* Then any unused temporary:
548 bit
= _mesa_ffs( ~p
->temp_in_use
);
551 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
555 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
556 p
->program
->Base
.NumTemporaries
= bit
;
558 p
->temp_in_use
|= 1<<(bit
-1);
559 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
562 static struct ureg
get_tex_temp( struct texenv_fragment_program
*p
)
566 /* First try to find available temp not previously used (to avoid
567 * starting a new texture indirection). According to the spec, the
568 * ~p->temps_output isn't necessary, but will keep it there for
571 bit
= _mesa_ffs( ~p
->temp_in_use
& ~p
->alu_temps
& ~p
->temps_output
);
573 /* Then any unused temporary:
576 bit
= _mesa_ffs( ~p
->temp_in_use
);
579 _mesa_problem(NULL
, "%s: out of temporaries\n", __FILE__
);
583 if ((GLuint
) bit
> p
->program
->Base
.NumTemporaries
)
584 p
->program
->Base
.NumTemporaries
= bit
;
586 p
->temp_in_use
|= 1<<(bit
-1);
587 return make_ureg(PROGRAM_TEMPORARY
, (bit
-1));
591 /** Mark a temp reg as being no longer allocatable. */
592 static void reserve_temp( struct texenv_fragment_program
*p
, struct ureg r
)
594 if (r
.file
== PROGRAM_TEMPORARY
)
595 p
->temps_output
|= (1 << r
.idx
);
599 static void release_temps(GLcontext
*ctx
, struct texenv_fragment_program
*p
)
601 GLuint max_temp
= ctx
->Const
.FragmentProgram
.MaxTemps
;
603 /* KW: To support tex_env_crossbar, don't release the registers in
606 if (max_temp
>= sizeof(int) * 8)
607 p
->temp_in_use
= p
->temps_output
;
609 p
->temp_in_use
= ~((1<<max_temp
)-1) | p
->temps_output
;
613 static struct ureg
register_param5( struct texenv_fragment_program
*p
,
620 gl_state_index tokens
[STATE_LENGTH
];
627 idx
= _mesa_add_state_reference( p
->program
->Base
.Parameters
, tokens
);
628 return make_ureg(PROGRAM_STATE_VAR
, idx
);
632 #define register_param1(p,s0) register_param5(p,s0,0,0,0,0)
633 #define register_param2(p,s0,s1) register_param5(p,s0,s1,0,0,0)
634 #define register_param3(p,s0,s1,s2) register_param5(p,s0,s1,s2,0,0)
635 #define register_param4(p,s0,s1,s2,s3) register_param5(p,s0,s1,s2,s3,0)
637 static GLuint
frag_to_vert_attrib( GLuint attrib
)
640 case FRAG_ATTRIB_COL0
: return VERT_ATTRIB_COLOR0
;
641 case FRAG_ATTRIB_COL1
: return VERT_ATTRIB_COLOR1
;
643 assert(attrib
>= FRAG_ATTRIB_TEX0
);
644 assert(attrib
<= FRAG_ATTRIB_TEX7
);
645 return attrib
- FRAG_ATTRIB_TEX0
+ VERT_ATTRIB_TEX0
;
650 static struct ureg
register_input( struct texenv_fragment_program
*p
, GLuint input
)
652 if (p
->state
->inputs_available
& (1<<input
)) {
653 p
->program
->Base
.InputsRead
|= (1 << input
);
654 return make_ureg(PROGRAM_INPUT
, input
);
657 GLuint idx
= frag_to_vert_attrib( input
);
658 return register_param3( p
, STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, idx
);
663 static void emit_arg( struct prog_src_register
*reg
,
666 reg
->File
= ureg
.file
;
667 reg
->Index
= ureg
.idx
;
668 reg
->Swizzle
= ureg
.swz
;
669 reg
->NegateBase
= ureg
.negatebase
? 0xf : 0x0;
671 reg
->NegateAbs
= ureg
.negateabs
;
674 static void emit_dst( struct prog_dst_register
*dst
,
675 struct ureg ureg
, GLuint mask
)
677 dst
->File
= ureg
.file
;
678 dst
->Index
= ureg
.idx
;
679 dst
->WriteMask
= mask
;
680 dst
->CondMask
= COND_TR
; /* always pass cond test */
681 dst
->CondSwizzle
= SWIZZLE_NOOP
;
684 static struct prog_instruction
*
685 emit_op(struct texenv_fragment_program
*p
,
694 GLuint nr
= p
->program
->Base
.NumInstructions
++;
695 struct prog_instruction
*inst
= &p
->program
->Base
.Instructions
[nr
];
697 assert(nr
< MAX_INSTRUCTIONS
);
699 _mesa_init_instructions(inst
, 1);
702 emit_arg( &inst
->SrcReg
[0], src0
);
703 emit_arg( &inst
->SrcReg
[1], src1
);
704 emit_arg( &inst
->SrcReg
[2], src2
);
706 inst
->SaturateMode
= saturate
? SATURATE_ZERO_ONE
: SATURATE_OFF
;
708 emit_dst( &inst
->DstReg
, dest
, mask
);
711 /* Accounting for indirection tracking:
713 if (dest
.file
== PROGRAM_TEMPORARY
)
714 p
->temps_output
|= 1 << dest
.idx
;
721 static struct ureg
emit_arith( struct texenv_fragment_program
*p
,
730 emit_op(p
, op
, dest
, mask
, saturate
, src0
, src1
, src2
);
732 /* Accounting for indirection tracking:
734 if (src0
.file
== PROGRAM_TEMPORARY
)
735 p
->alu_temps
|= 1 << src0
.idx
;
737 if (!is_undef(src1
) && src1
.file
== PROGRAM_TEMPORARY
)
738 p
->alu_temps
|= 1 << src1
.idx
;
740 if (!is_undef(src2
) && src2
.file
== PROGRAM_TEMPORARY
)
741 p
->alu_temps
|= 1 << src2
.idx
;
743 if (dest
.file
== PROGRAM_TEMPORARY
)
744 p
->alu_temps
|= 1 << dest
.idx
;
746 p
->program
->Base
.NumAluInstructions
++;
750 static struct ureg
emit_texld( struct texenv_fragment_program
*p
,
759 struct prog_instruction
*inst
= emit_op( p
, op
,
761 GL_FALSE
, /* don't saturate? */
766 inst
->TexSrcTarget
= tex_idx
;
767 inst
->TexSrcUnit
= tex_unit
;
768 inst
->TexShadow
= tex_shadow
;
770 p
->program
->Base
.NumTexInstructions
++;
772 /* Accounting for indirection tracking:
774 reserve_temp(p
, dest
);
777 /* Is this a texture indirection?
779 if ((coord
.file
== PROGRAM_TEMPORARY
&&
780 (p
->temps_output
& (1<<coord
.idx
))) ||
781 (dest
.file
== PROGRAM_TEMPORARY
&&
782 (p
->alu_temps
& (1<<dest
.idx
)))) {
783 p
->program
->Base
.NumTexIndirections
++;
784 p
->temps_output
= 1<<coord
.idx
;
786 assert(0); /* KW: texture env crossbar */
794 static struct ureg
register_const4f( struct texenv_fragment_program
*p
,
807 idx
= _mesa_add_unnamed_constant( p
->program
->Base
.Parameters
, values
, 4,
809 r
= make_ureg(PROGRAM_CONSTANT
, idx
);
814 #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0)
815 #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1)
816 #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1)
817 #define register_const3f(p, s0, s1, s2) register_const4f(p, s0, s1, s2, 1)
820 static struct ureg
get_one( struct texenv_fragment_program
*p
)
822 if (is_undef(p
->one
))
823 p
->one
= register_scalar_const(p
, 1.0);
827 static struct ureg
get_half( struct texenv_fragment_program
*p
)
829 if (is_undef(p
->half
))
830 p
->half
= register_scalar_const(p
, 0.5);
834 static struct ureg
get_zero( struct texenv_fragment_program
*p
)
836 if (is_undef(p
->zero
))
837 p
->zero
= register_scalar_const(p
, 0.0);
842 static void program_error( struct texenv_fragment_program
*p
, const char *msg
)
844 _mesa_problem(NULL
, msg
);
848 static struct ureg
get_source( struct texenv_fragment_program
*p
,
849 GLuint src
, GLuint unit
)
853 assert(!is_undef(p
->src_texture
[unit
]));
854 return p
->src_texture
[unit
];
864 assert(!is_undef(p
->src_texture
[src
- SRC_TEXTURE0
]));
865 return p
->src_texture
[src
- SRC_TEXTURE0
];
868 return register_param2(p
, STATE_TEXENV_COLOR
, unit
);
870 case SRC_PRIMARY_COLOR
:
871 return register_input(p
, FRAG_ATTRIB_COL0
);
877 if (is_undef(p
->src_previous
))
878 return register_input(p
, FRAG_ATTRIB_COL0
);
880 return p
->src_previous
;
887 static struct ureg
emit_combine_source( struct texenv_fragment_program
*p
,
893 struct ureg arg
, src
, one
;
895 src
= get_source(p
, source
, unit
);
898 case OPR_ONE_MINUS_SRC_COLOR
:
900 * Emit tmp = 1.0 - arg.xyzw
904 return emit_arith( p
, OPCODE_SUB
, arg
, mask
, 0, one
, src
, undef
);
907 if (mask
== WRITEMASK_W
)
910 return swizzle1( src
, SWIZZLE_W
);
911 case OPR_ONE_MINUS_SRC_ALPHA
:
913 * Emit tmp = 1.0 - arg.wwww
917 return emit_arith(p
, OPCODE_SUB
, arg
, mask
, 0,
918 one
, swizzle1(src
, SWIZZLE_W
), undef
);
931 static GLboolean
args_match( struct state_key
*key
, GLuint unit
)
933 GLuint i
, nr
= key
->unit
[unit
].NumArgsRGB
;
935 for (i
= 0 ; i
< nr
; i
++) {
936 if (key
->unit
[unit
].OptA
[i
].Source
!= key
->unit
[unit
].OptRGB
[i
].Source
)
939 switch(key
->unit
[unit
].OptA
[i
].Operand
) {
941 switch(key
->unit
[unit
].OptRGB
[i
].Operand
) {
949 case OPR_ONE_MINUS_SRC_ALPHA
:
950 switch(key
->unit
[unit
].OptRGB
[i
].Operand
) {
951 case OPR_ONE_MINUS_SRC_COLOR
:
952 case OPR_ONE_MINUS_SRC_ALPHA
:
959 return GL_FALSE
; /* impossible */
966 static struct ureg
emit_combine( struct texenv_fragment_program
*p
,
973 const struct mode_opt
*opt
)
975 struct ureg src
[MAX_TERMS
];
976 struct ureg tmp
, half
;
979 assert(nr
<= MAX_TERMS
);
981 tmp
= undef
; /* silence warning (bug 5318) */
983 for (i
= 0; i
< nr
; i
++)
984 src
[i
] = emit_combine_source( p
, mask
, unit
, opt
[i
].Source
, opt
[i
].Operand
);
988 if (mask
== WRITEMASK_XYZW
&& !saturate
)
991 return emit_arith( p
, OPCODE_MOV
, dest
, mask
, saturate
, src
[0], undef
, undef
);
993 return emit_arith( p
, OPCODE_MUL
, dest
, mask
, saturate
,
994 src
[0], src
[1], undef
);
996 return emit_arith( p
, OPCODE_ADD
, dest
, mask
, saturate
,
997 src
[0], src
[1], undef
);
998 case MODE_ADD_SIGNED
:
1003 tmp
= get_temp( p
);
1004 emit_arith( p
, OPCODE_ADD
, tmp
, mask
, 0, src
[0], src
[1], undef
);
1005 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp
, half
, undef
);
1007 case MODE_INTERPOLATE
:
1008 /* Arg0 * (Arg2) + Arg1 * (1-Arg2) -- note arguments are reordered:
1010 return emit_arith( p
, OPCODE_LRP
, dest
, mask
, saturate
, src
[2], src
[0], src
[1] );
1013 return emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, src
[0], src
[1], undef
);
1015 case MODE_DOT3_RGBA
:
1016 case MODE_DOT3_RGBA_EXT
:
1017 case MODE_DOT3_RGB_EXT
:
1018 case MODE_DOT3_RGB
: {
1019 struct ureg tmp0
= get_temp( p
);
1020 struct ureg tmp1
= get_temp( p
);
1021 struct ureg neg1
= register_scalar_const(p
, -1);
1022 struct ureg two
= register_scalar_const(p
, 2);
1024 /* tmp0 = 2*src0 - 1
1027 * dst = tmp0 dot3 tmp1
1029 emit_arith( p
, OPCODE_MAD
, tmp0
, WRITEMASK_XYZW
, 0,
1032 if (_mesa_memcmp(&src
[0], &src
[1], sizeof(struct ureg
)) == 0)
1035 emit_arith( p
, OPCODE_MAD
, tmp1
, WRITEMASK_XYZW
, 0,
1037 emit_arith( p
, OPCODE_DP3
, dest
, mask
, saturate
, tmp0
, tmp1
, undef
);
1040 case MODE_MODULATE_ADD_ATI
:
1041 /* Arg0 * Arg2 + Arg1 */
1042 return emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
,
1043 src
[0], src
[2], src
[1] );
1044 case MODE_MODULATE_SIGNED_ADD_ATI
: {
1045 /* Arg0 * Arg2 + Arg1 - 0.5 */
1046 struct ureg tmp0
= get_temp(p
);
1048 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[0], src
[2], src
[1] );
1049 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1052 case MODE_MODULATE_SUBTRACT_ATI
:
1053 /* Arg0 * Arg2 - Arg1 */
1054 emit_arith( p
, OPCODE_MAD
, dest
, mask
, 0, src
[0], src
[2], negate(src
[1]) );
1056 case MODE_ADD_PRODUCTS
:
1057 /* Arg0 * Arg1 + Arg2 * Arg3 */
1059 struct ureg tmp0
= get_temp(p
);
1060 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1061 emit_arith( p
, OPCODE_MAD
, dest
, mask
, saturate
, src
[2], src
[3], tmp0
);
1064 case MODE_ADD_PRODUCTS_SIGNED
:
1065 /* Arg0 * Arg1 + Arg2 * Arg3 - 0.5 */
1067 struct ureg tmp0
= get_temp(p
);
1069 emit_arith( p
, OPCODE_MUL
, tmp0
, mask
, 0, src
[0], src
[1], undef
);
1070 emit_arith( p
, OPCODE_MAD
, tmp0
, mask
, 0, src
[2], src
[3], tmp0
);
1071 emit_arith( p
, OPCODE_SUB
, dest
, mask
, saturate
, tmp0
, half
, undef
);
1074 case MODE_BUMP_ENVMAP_ATI
:
1075 /* special - not handled here */
1086 * Generate instructions for one texture unit's env/combiner mode.
1089 emit_texenv(struct texenv_fragment_program
*p
, GLuint unit
)
1091 struct state_key
*key
= p
->state
;
1092 GLboolean saturate
= (unit
< p
->last_tex_stage
);
1093 GLuint rgb_shift
, alpha_shift
;
1094 struct ureg out
, shift
;
1097 if (!key
->unit
[unit
].enabled
) {
1098 return get_source(p
, SRC_PREVIOUS
, 0);
1100 if (key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1101 /* this isn't really a env stage delivering a color and handled elsewhere */
1102 return get_source(p
, SRC_PREVIOUS
, 0);
1105 switch (key
->unit
[unit
].ModeRGB
) {
1106 case MODE_DOT3_RGB_EXT
:
1107 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1110 case MODE_DOT3_RGBA_EXT
:
1115 rgb_shift
= key
->unit
[unit
].ScaleShiftRGB
;
1116 alpha_shift
= key
->unit
[unit
].ScaleShiftA
;
1120 /* If this is the very last calculation, emit direct to output reg:
1122 if (key
->separate_specular
||
1123 unit
!= p
->last_tex_stage
||
1126 dest
= get_temp( p
);
1128 dest
= make_ureg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1130 /* Emit the RGB and A combine ops
1132 if (key
->unit
[unit
].ModeRGB
== key
->unit
[unit
].ModeA
&&
1133 args_match(key
, unit
)) {
1134 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1136 key
->unit
[unit
].NumArgsRGB
,
1137 key
->unit
[unit
].ModeRGB
,
1138 key
->unit
[unit
].OptRGB
);
1140 else if (key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA_EXT
||
1141 key
->unit
[unit
].ModeRGB
== MODE_DOT3_RGBA
) {
1143 out
= emit_combine( p
, dest
, WRITEMASK_XYZW
, saturate
,
1145 key
->unit
[unit
].NumArgsRGB
,
1146 key
->unit
[unit
].ModeRGB
,
1147 key
->unit
[unit
].OptRGB
);
1150 /* Need to do something to stop from re-emitting identical
1151 * argument calculations here:
1153 out
= emit_combine( p
, dest
, WRITEMASK_XYZ
, saturate
,
1155 key
->unit
[unit
].NumArgsRGB
,
1156 key
->unit
[unit
].ModeRGB
,
1157 key
->unit
[unit
].OptRGB
);
1158 out
= emit_combine( p
, dest
, WRITEMASK_W
, saturate
,
1160 key
->unit
[unit
].NumArgsA
,
1161 key
->unit
[unit
].ModeA
,
1162 key
->unit
[unit
].OptA
);
1165 /* Deal with the final shift:
1167 if (alpha_shift
|| rgb_shift
) {
1168 if (rgb_shift
== alpha_shift
) {
1169 shift
= register_scalar_const(p
, (GLfloat
)(1<<rgb_shift
));
1172 shift
= register_const4f(p
,
1173 (GLfloat
)(1<<rgb_shift
),
1174 (GLfloat
)(1<<rgb_shift
),
1175 (GLfloat
)(1<<rgb_shift
),
1176 (GLfloat
)(1<<alpha_shift
));
1178 return emit_arith( p
, OPCODE_MUL
, dest
, WRITEMASK_XYZW
,
1179 saturate
, out
, shift
, undef
);
1187 * Generate instruction for getting a texture source term.
1189 static void load_texture( struct texenv_fragment_program
*p
, GLuint unit
)
1191 if (is_undef(p
->src_texture
[unit
])) {
1192 GLuint texTarget
= p
->state
->unit
[unit
].source_index
;
1193 struct ureg texcoord
;
1194 struct ureg tmp
= get_tex_temp( p
);
1196 if (is_undef(p
->texcoord_tex
[unit
])) {
1197 texcoord
= register_input(p
, FRAG_ATTRIB_TEX0
+unit
);
1200 /* might want to reuse this reg for tex output actually */
1201 texcoord
= p
->texcoord_tex
[unit
];
1204 if (texTarget
== TEXTURE_UNKNOWN_INDEX
)
1205 program_error(p
, "TexSrcBit");
1207 /* TODO: Use D0_MASK_XY where possible.
1209 if (p
->state
->unit
[unit
].enabled
) {
1210 GLboolean shadow
= GL_FALSE
;
1212 if (p
->state
->unit
[unit
].shadow
) {
1213 p
->program
->Base
.ShadowSamplers
|= 1 << unit
;
1217 p
->src_texture
[unit
] = emit_texld( p
, OPCODE_TXP
,
1218 tmp
, WRITEMASK_XYZW
,
1219 unit
, texTarget
, shadow
,
1222 p
->program
->Base
.SamplersUsed
|= (1 << unit
);
1223 /* This identity mapping should already be in place
1224 * (see _mesa_init_program_struct()) but let's be safe.
1226 p
->program
->Base
.SamplerUnits
[unit
] = unit
;
1229 p
->src_texture
[unit
] = get_zero(p
);
1233 static GLboolean
load_texenv_source( struct texenv_fragment_program
*p
,
1234 GLuint src
, GLuint unit
)
1238 load_texture(p
, unit
);
1249 load_texture(p
, src
- SRC_TEXTURE0
);
1253 /* not a texture src - do nothing */
1262 * Generate instructions for loading all texture source terms.
1265 load_texunit_sources( struct texenv_fragment_program
*p
, int unit
)
1267 struct state_key
*key
= p
->state
;
1270 for (i
= 0; i
< key
->unit
[unit
].NumArgsRGB
; i
++) {
1271 load_texenv_source( p
, key
->unit
[unit
].OptRGB
[i
].Source
, unit
);
1274 for (i
= 0; i
< key
->unit
[unit
].NumArgsA
; i
++) {
1275 load_texenv_source( p
, key
->unit
[unit
].OptA
[i
].Source
, unit
);
1282 * Generate instructions for loading bump map textures.
1285 load_texunit_bumpmap( struct texenv_fragment_program
*p
, int unit
)
1287 struct state_key
*key
= p
->state
;
1288 GLuint bumpedUnitNr
= key
->unit
[unit
].OptRGB
[1].Source
- SRC_TEXTURE0
;
1289 struct ureg texcDst
, bumpMapRes
;
1290 struct ureg constdudvcolor
= register_const4f(p
, 0.0, 0.0, 0.0, 1.0);
1291 struct ureg texcSrc
= register_input(p
, FRAG_ATTRIB_TEX0
+ bumpedUnitNr
);
1292 struct ureg rotMat0
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_0
, unit
);
1293 struct ureg rotMat1
= register_param3( p
, STATE_INTERNAL
, STATE_ROT_MATRIX_1
, unit
);
1295 load_texenv_source( p
, unit
+ SRC_TEXTURE0
, unit
);
1297 bumpMapRes
= get_source(p
, key
->unit
[unit
].OptRGB
[0].Source
, unit
);
1298 texcDst
= get_tex_temp( p
);
1299 p
->texcoord_tex
[bumpedUnitNr
] = texcDst
;
1301 /* apply rot matrix and add coords to be available in next phase */
1302 /* dest = (Arg0.xxxx * rotMat0 + Arg1) + (Arg0.yyyy * rotMat1) */
1303 /* note only 2 coords are affected the rest are left unchanged (mul by 0) */
1304 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1305 swizzle1(bumpMapRes
, SWIZZLE_X
), rotMat0
, texcSrc
);
1306 emit_arith( p
, OPCODE_MAD
, texcDst
, WRITEMASK_XYZW
, 0,
1307 swizzle1(bumpMapRes
, SWIZZLE_Y
), rotMat1
, texcDst
);
1309 /* move 0,0,0,1 into bumpmap src if someone (crossbar) is foolish
1310 enough to access this later, should optimize away */
1311 emit_arith( p
, OPCODE_MOV
, bumpMapRes
, WRITEMASK_XYZW
, 0, constdudvcolor
, undef
, undef
);
1317 * Generate a new fragment program which implements the context's
1318 * current texture env/combine mode.
1321 create_new_program(GLcontext
*ctx
, struct state_key
*key
,
1322 struct gl_fragment_program
*program
)
1324 struct prog_instruction instBuffer
[MAX_INSTRUCTIONS
];
1325 struct texenv_fragment_program p
;
1327 struct ureg cf
, out
;
1329 _mesa_memset(&p
, 0, sizeof(p
));
1332 p
.program
= program
;
1334 /* During code generation, use locally-allocated instruction buffer,
1335 * then alloc dynamic storage below.
1337 p
.program
->Base
.Instructions
= instBuffer
;
1338 p
.program
->Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
1339 p
.program
->Base
.NumTexIndirections
= 1;
1340 p
.program
->Base
.NumTexInstructions
= 0;
1341 p
.program
->Base
.NumAluInstructions
= 0;
1342 p
.program
->Base
.String
= NULL
;
1343 p
.program
->Base
.NumInstructions
=
1344 p
.program
->Base
.NumTemporaries
=
1345 p
.program
->Base
.NumParameters
=
1346 p
.program
->Base
.NumAttributes
= p
.program
->Base
.NumAddressRegs
= 0;
1347 p
.program
->Base
.Parameters
= _mesa_new_parameter_list();
1349 p
.program
->Base
.InputsRead
= 0;
1350 p
.program
->Base
.OutputsWritten
= 1 << FRAG_RESULT_COLOR
;
1352 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
1353 p
.src_texture
[unit
] = undef
;
1354 p
.texcoord_tex
[unit
] = undef
;
1357 p
.src_previous
= undef
;
1362 p
.last_tex_stage
= 0;
1363 release_temps(ctx
, &p
);
1365 if (key
->enabled_units
) {
1366 GLboolean needbumpstage
= GL_FALSE
;
1367 /* Zeroth pass - bump map textures first */
1368 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1369 if (key
->unit
[unit
].enabled
&& key
->unit
[unit
].ModeRGB
== MODE_BUMP_ENVMAP_ATI
) {
1370 needbumpstage
= GL_TRUE
;
1371 load_texunit_bumpmap( &p
, unit
);
1374 p
.program
->Base
.NumTexIndirections
++;
1376 /* First pass - to support texture_env_crossbar, first identify
1377 * all referenced texture sources and emit texld instructions
1380 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1381 if (key
->unit
[unit
].enabled
) {
1382 load_texunit_sources( &p
, unit
);
1383 p
.last_tex_stage
= unit
;
1386 /* Second pass - emit combine instructions to build final color:
1388 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++)
1389 if (key
->enabled_units
& (1<<unit
)) {
1390 p
.src_previous
= emit_texenv( &p
, unit
);
1391 reserve_temp(&p
, p
.src_previous
); /* don't re-use this temp reg */
1392 release_temps(ctx
, &p
); /* release all temps */
1396 cf
= get_source( &p
, SRC_PREVIOUS
, 0 );
1397 out
= make_ureg( PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
1399 if (key
->separate_specular
) {
1400 /* Emit specular add.
1402 struct ureg s
= register_input(&p
, FRAG_ATTRIB_COL1
);
1403 emit_arith( &p
, OPCODE_ADD
, out
, WRITEMASK_XYZ
, 0, cf
, s
, undef
);
1404 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_W
, 0, cf
, undef
, undef
);
1406 else if (_mesa_memcmp(&cf
, &out
, sizeof(cf
)) != 0) {
1407 /* Will wind up in here if no texture enabled or a couple of
1408 * other scenarios (GL_REPLACE for instance).
1410 emit_arith( &p
, OPCODE_MOV
, out
, WRITEMASK_XYZW
, 0, cf
, undef
, undef
);
1415 emit_arith( &p
, OPCODE_END
, undef
, WRITEMASK_XYZW
, 0, undef
, undef
, undef
);
1417 if (key
->fog_enabled
) {
1418 /* Pull fog mode from GLcontext, the value in the state key is
1419 * a reduced value and not what is expected in FogOption
1421 p
.program
->FogOption
= ctx
->Fog
.Mode
;
1422 p
.program
->Base
.InputsRead
|= FRAG_BIT_FOGC
; /* XXX new */
1424 p
.program
->FogOption
= GL_NONE
;
1426 if (p
.program
->Base
.NumTexIndirections
> ctx
->Const
.FragmentProgram
.MaxTexIndirections
)
1427 program_error(&p
, "Exceeded max nr indirect texture lookups");
1429 if (p
.program
->Base
.NumTexInstructions
> ctx
->Const
.FragmentProgram
.MaxTexInstructions
)
1430 program_error(&p
, "Exceeded max TEX instructions");
1432 if (p
.program
->Base
.NumAluInstructions
> ctx
->Const
.FragmentProgram
.MaxAluInstructions
)
1433 program_error(&p
, "Exceeded max ALU instructions");
1435 ASSERT(p
.program
->Base
.NumInstructions
<= MAX_INSTRUCTIONS
);
1437 /* Allocate final instruction array */
1438 p
.program
->Base
.Instructions
1439 = _mesa_alloc_instructions(p
.program
->Base
.NumInstructions
);
1440 if (!p
.program
->Base
.Instructions
) {
1441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
1442 "generating tex env program");
1445 _mesa_copy_instructions(p
.program
->Base
.Instructions
, instBuffer
,
1446 p
.program
->Base
.NumInstructions
);
1448 if (p
.program
->FogOption
) {
1449 _mesa_append_fog_code(ctx
, p
.program
);
1450 p
.program
->FogOption
= GL_NONE
;
1454 /* Notify driver the fragment program has (actually) changed.
1456 if (ctx
->Driver
.ProgramStringNotify
) {
1457 ctx
->Driver
.ProgramStringNotify( ctx
, GL_FRAGMENT_PROGRAM_ARB
,
1462 _mesa_print_program(&p
.program
->Base
);
1469 * Return a fragment program which implements the current
1470 * fixed-function texture, fog and color-sum operations.
1472 struct gl_fragment_program
*
1473 _mesa_get_fixed_func_fragment_program(GLcontext
*ctx
)
1475 struct gl_fragment_program
*prog
;
1476 struct state_key key
;
1478 make_state_key(ctx
, &key
);
1480 prog
= (struct gl_fragment_program
*)
1481 _mesa_search_program_cache(ctx
->FragmentProgram
.Cache
,
1485 prog
= (struct gl_fragment_program
*)
1486 ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
1488 create_new_program(ctx
, &key
, prog
);
1490 _mesa_program_cache_insert(ctx
, ctx
->FragmentProgram
.Cache
,
1491 &key
, sizeof(key
), &prog
->Base
);