1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include "shader/prog_instruction.h"
33 #include "shader/prog_parameter.h"
34 #include "shader/program.h"
35 #include "shader/programopt.h"
38 #include "tnl/t_context.h"
40 #include "intel_batchbuffer.h"
43 #include "i915_context.h"
44 #include "i915_program.h"
48 /* 1, -1/3!, 1/5!, -1/7! */
49 static const GLfloat sin_constants
[4] = { 1.0,
51 1.0 / (5 * 4 * 3 * 2 * 1),
52 -1.0 / (7 * 6 * 5 * 4 * 3 * 2 * 1)
55 /* 1, -1/2!, 1/4!, -1/6! */
56 static const GLfloat cos_constants
[4] = { 1.0,
58 1.0 / (4 * 3 * 2 * 1),
59 -1.0 / (6 * 5 * 4 * 3 * 2 * 1)
63 * Retrieve a ureg for the given source register. Will emit
64 * constants, apply swizzling and negation as needed.
67 src_vector(struct i915_fragment_program
*p
,
68 const struct prog_src_register
*source
,
69 const struct gl_fragment_program
*program
)
73 switch (source
->File
) {
77 case PROGRAM_TEMPORARY
:
78 if (source
->Index
>= I915_MAX_TEMPORARY
) {
79 i915_program_error(p
, "Exceeded max temporary reg");
82 src
= UREG(REG_TYPE_R
, source
->Index
);
85 switch (source
->Index
) {
86 case FRAG_ATTRIB_WPOS
:
87 src
= i915_emit_decl(p
, REG_TYPE_T
, p
->wpos_tex
, D0_CHANNEL_ALL
);
89 case FRAG_ATTRIB_COL0
:
90 src
= i915_emit_decl(p
, REG_TYPE_T
, T_DIFFUSE
, D0_CHANNEL_ALL
);
92 case FRAG_ATTRIB_COL1
:
93 src
= i915_emit_decl(p
, REG_TYPE_T
, T_SPECULAR
, D0_CHANNEL_XYZ
);
94 src
= swizzle(src
, X
, Y
, Z
, ONE
);
96 case FRAG_ATTRIB_FOGC
:
97 src
= i915_emit_decl(p
, REG_TYPE_T
, T_FOG_W
, D0_CHANNEL_W
);
98 src
= swizzle(src
, W
, W
, W
, W
);
100 case FRAG_ATTRIB_TEX0
:
101 case FRAG_ATTRIB_TEX1
:
102 case FRAG_ATTRIB_TEX2
:
103 case FRAG_ATTRIB_TEX3
:
104 case FRAG_ATTRIB_TEX4
:
105 case FRAG_ATTRIB_TEX5
:
106 case FRAG_ATTRIB_TEX6
:
107 case FRAG_ATTRIB_TEX7
:
108 src
= i915_emit_decl(p
, REG_TYPE_T
,
109 T_TEX0
+ (source
->Index
- FRAG_ATTRIB_TEX0
),
114 i915_program_error(p
, "Bad source->Index");
119 /* Various paramters and env values. All emitted to
120 * hardware as program constants.
122 case PROGRAM_LOCAL_PARAM
:
123 src
= i915_emit_param4fv(p
, program
->Base
.LocalParams
[source
->Index
]);
126 case PROGRAM_ENV_PARAM
:
128 i915_emit_param4fv(p
,
129 p
->ctx
->FragmentProgram
.Parameters
[source
->
133 case PROGRAM_CONSTANT
:
134 case PROGRAM_STATE_VAR
:
135 case PROGRAM_NAMED_PARAM
:
137 i915_emit_param4fv(p
,
138 program
->Base
.Parameters
->ParameterValues
[source
->
143 i915_program_error(p
, "Bad source->File");
148 GET_SWZ(source
->Swizzle
, 0),
149 GET_SWZ(source
->Swizzle
, 1),
150 GET_SWZ(source
->Swizzle
, 2), GET_SWZ(source
->Swizzle
, 3));
152 if (source
->NegateBase
)
154 GET_BIT(source
->NegateBase
, 0),
155 GET_BIT(source
->NegateBase
, 1),
156 GET_BIT(source
->NegateBase
, 2),
157 GET_BIT(source
->NegateBase
, 3));
164 get_result_vector(struct i915_fragment_program
*p
,
165 const struct prog_instruction
*inst
)
167 switch (inst
->DstReg
.File
) {
169 switch (inst
->DstReg
.Index
) {
170 case FRAG_RESULT_COLR
:
171 return UREG(REG_TYPE_OC
, 0);
172 case FRAG_RESULT_DEPR
:
173 p
->depth_written
= 1;
174 return UREG(REG_TYPE_OD
, 0);
176 i915_program_error(p
, "Bad inst->DstReg.Index");
179 case PROGRAM_TEMPORARY
:
180 return UREG(REG_TYPE_R
, inst
->DstReg
.Index
);
182 i915_program_error(p
, "Bad inst->DstReg.File");
188 get_result_flags(const struct prog_instruction
*inst
)
192 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
193 flags
|= A0_DEST_SATURATE
;
194 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
)
195 flags
|= A0_DEST_CHANNEL_X
;
196 if (inst
->DstReg
.WriteMask
& WRITEMASK_Y
)
197 flags
|= A0_DEST_CHANNEL_Y
;
198 if (inst
->DstReg
.WriteMask
& WRITEMASK_Z
)
199 flags
|= A0_DEST_CHANNEL_Z
;
200 if (inst
->DstReg
.WriteMask
& WRITEMASK_W
)
201 flags
|= A0_DEST_CHANNEL_W
;
207 translate_tex_src_target(struct i915_fragment_program
*p
, GLubyte bit
)
210 case TEXTURE_1D_INDEX
:
211 return D0_SAMPLE_TYPE_2D
;
212 case TEXTURE_2D_INDEX
:
213 return D0_SAMPLE_TYPE_2D
;
214 case TEXTURE_RECT_INDEX
:
215 return D0_SAMPLE_TYPE_2D
;
216 case TEXTURE_3D_INDEX
:
217 return D0_SAMPLE_TYPE_VOLUME
;
218 case TEXTURE_CUBE_INDEX
:
219 return D0_SAMPLE_TYPE_CUBE
;
221 i915_program_error(p
, "TexSrcBit");
226 #define EMIT_TEX( OP ) \
228 GLuint dim = translate_tex_src_target( p, inst->TexSrcTarget ); \
229 GLuint sampler = i915_emit_decl(p, REG_TYPE_S, \
230 inst->TexSrcUnit, dim); \
231 GLuint coord = src_vector( p, &inst->SrcReg[0], program); \
234 i915_emit_texld( p, \
235 get_result_vector( p, inst ), \
236 get_result_flags( inst ), \
242 #define EMIT_ARITH( OP, N ) \
244 i915_emit_arith( p, \
246 get_result_vector( p, inst ), \
247 get_result_flags( inst ), 0, \
248 (N<1)?0:src_vector( p, &inst->SrcReg[0], program), \
249 (N<2)?0:src_vector( p, &inst->SrcReg[1], program), \
250 (N<3)?0:src_vector( p, &inst->SrcReg[2], program)); \
253 #define EMIT_1ARG_ARITH( OP ) EMIT_ARITH( OP, 1 )
254 #define EMIT_2ARG_ARITH( OP ) EMIT_ARITH( OP, 2 )
255 #define EMIT_3ARG_ARITH( OP ) EMIT_ARITH( OP, 3 )
258 /* Possible concerns:
260 * SIN, COS -- could use another taylor step?
261 * LIT -- results seem a little different to sw mesa
262 * LOG -- different to mesa on negative numbers, but this is conformant.
264 * Parse failures -- Mesa doesn't currently give a good indication
265 * internally whether a particular program string parsed or not. This
266 * can lead to confusion -- hopefully we cope with it ok now.
270 upload_program(struct i915_fragment_program
*p
)
272 const struct gl_fragment_program
*program
=
273 p
->ctx
->FragmentProgram
._Current
;
274 const struct prog_instruction
*inst
= program
->Base
.Instructions
;
276 /* _mesa_debug_fp_inst(program->Base.NumInstructions, inst); */
278 /* Is this a parse-failed program? Ensure a valid program is
279 * loaded, as the flagging of an error isn't sufficient to stop
280 * this being uploaded to hardware.
282 if (inst
[0].Opcode
== OPCODE_END
) {
283 GLuint tmp
= i915_get_utemp(p
);
286 UREG(REG_TYPE_OC
, 0),
287 A0_DEST_CHANNEL_ALL
, 0,
288 swizzle(tmp
, ONE
, ZERO
, ONE
, ONE
), 0, 0);
293 GLuint src0
, src1
, src2
, flags
;
296 switch (inst
->Opcode
) {
298 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
301 get_result_vector(p
, inst
),
302 get_result_flags(inst
), 0,
303 src0
, negate(src0
, 1, 1, 1, 1), 0);
307 EMIT_2ARG_ARITH(A0_ADD
);
311 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
312 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
313 src2
= src_vector(p
, &inst
->SrcReg
[2], program
);
314 i915_emit_arith(p
, A0_CMP
, get_result_vector(p
, inst
), get_result_flags(inst
), 0, src0
, src2
, src1
); /* NOTE: order of src2, src1 */
318 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
319 tmp
= i915_get_utemp(p
);
323 tmp
, A0_DEST_CHANNEL_X
, 0,
324 src0
, i915_emit_const1f(p
, 1.0 / (M_PI
)), 0);
326 i915_emit_arith(p
, A0_MOD
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, 0, 0);
328 /* By choosing different taylor constants, could get rid of this mul:
332 tmp
, A0_DEST_CHANNEL_X
, 0,
333 tmp
, i915_emit_const1f(p
, (M_PI
)), 0);
336 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
337 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, 1
338 * t0 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1
339 * result = DP4 t0, cos_constants
343 tmp
, A0_DEST_CHANNEL_XY
, 0,
344 swizzle(tmp
, X
, X
, ONE
, ONE
),
345 swizzle(tmp
, X
, ONE
, ONE
, ONE
), 0);
349 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
350 swizzle(tmp
, X
, Y
, X
, ONE
),
351 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
355 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
356 swizzle(tmp
, X
, X
, Z
, ONE
),
357 swizzle(tmp
, Z
, ONE
, ONE
, ONE
), 0);
361 get_result_vector(p
, inst
),
362 get_result_flags(inst
), 0,
363 swizzle(tmp
, ONE
, Z
, Y
, X
),
364 i915_emit_const4fv(p
, cos_constants
), 0);
369 EMIT_2ARG_ARITH(A0_DP3
);
373 EMIT_2ARG_ARITH(A0_DP4
);
377 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
378 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
382 get_result_vector(p
, inst
),
383 get_result_flags(inst
), 0,
384 swizzle(src0
, X
, Y
, Z
, ONE
), src1
, 0);
388 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
389 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
391 /* result[0] = 1 * 1;
392 * result[1] = a[1] * b[1];
393 * result[2] = a[2] * 1;
394 * result[3] = 1 * b[3];
398 get_result_vector(p
, inst
),
399 get_result_flags(inst
), 0,
400 swizzle(src0
, ONE
, Y
, Z
, ONE
),
401 swizzle(src1
, ONE
, Y
, ONE
, W
), 0);
405 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
409 get_result_vector(p
, inst
),
410 get_result_flags(inst
), 0,
411 swizzle(src0
, X
, X
, X
, X
), 0, 0);
415 EMIT_1ARG_ARITH(A0_FLR
);
419 EMIT_1ARG_ARITH(A0_FRC
);
423 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
424 tmp
= i915_get_utemp(p
);
426 i915_emit_texld(p
, tmp
, A0_DEST_CHANNEL_ALL
, /* use a dummy dest reg */
427 0, src0
, T0_TEXKILL
);
431 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
435 get_result_vector(p
, inst
),
436 get_result_flags(inst
), 0,
437 swizzle(src0
, X
, X
, X
, X
), 0, 0);
441 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
442 tmp
= i915_get_utemp(p
);
444 /* tmp = max( a.xyzw, a.00zw )
445 * XXX: Clamp tmp.w to -128..128
447 * tmp.y = tmp.w * tmp.y
449 * result = cmp (a.11-x1, a.1x01, a.1xy1 )
451 i915_emit_arith(p
, A0_MAX
, tmp
, A0_DEST_CHANNEL_ALL
, 0,
452 src0
, swizzle(src0
, ZERO
, ZERO
, Z
, W
), 0);
454 i915_emit_arith(p
, A0_LOG
, tmp
, A0_DEST_CHANNEL_Y
, 0,
455 swizzle(tmp
, Y
, Y
, Y
, Y
), 0, 0);
457 i915_emit_arith(p
, A0_MUL
, tmp
, A0_DEST_CHANNEL_Y
, 0,
458 swizzle(tmp
, ZERO
, Y
, ZERO
, ZERO
),
459 swizzle(tmp
, ZERO
, W
, ZERO
, ZERO
), 0);
461 i915_emit_arith(p
, A0_EXP
, tmp
, A0_DEST_CHANNEL_Y
, 0,
462 swizzle(tmp
, Y
, Y
, Y
, Y
), 0, 0);
464 i915_emit_arith(p
, A0_CMP
,
465 get_result_vector(p
, inst
),
466 get_result_flags(inst
), 0,
467 negate(swizzle(tmp
, ONE
, ONE
, X
, ONE
), 0, 0, 1, 0),
468 swizzle(tmp
, ONE
, X
, ZERO
, ONE
),
469 swizzle(tmp
, ONE
, X
, Y
, ONE
));
474 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
475 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
476 src2
= src_vector(p
, &inst
->SrcReg
[2], program
);
477 flags
= get_result_flags(inst
);
478 tmp
= i915_get_utemp(p
);
485 * result = (-c)*a + tmp
487 i915_emit_arith(p
, A0_MAD
, tmp
,
488 flags
& A0_DEST_CHANNEL_ALL
, 0, src1
, src0
, src2
);
490 i915_emit_arith(p
, A0_MAD
,
491 get_result_vector(p
, inst
),
492 flags
, 0, negate(src2
, 1, 1, 1, 1), src0
, tmp
);
496 EMIT_3ARG_ARITH(A0_MAD
);
500 EMIT_2ARG_ARITH(A0_MAX
);
504 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
505 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
506 tmp
= i915_get_utemp(p
);
507 flags
= get_result_flags(inst
);
511 tmp
, flags
& A0_DEST_CHANNEL_ALL
, 0,
512 negate(src0
, 1, 1, 1, 1),
513 negate(src1
, 1, 1, 1, 1), 0);
517 get_result_vector(p
, inst
),
518 flags
, 0, negate(tmp
, 1, 1, 1, 1), 0, 0);
522 EMIT_1ARG_ARITH(A0_MOV
);
526 EMIT_2ARG_ARITH(A0_MUL
);
530 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
531 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
532 tmp
= i915_get_utemp(p
);
533 flags
= get_result_flags(inst
);
535 /* XXX: masking on intermediate values, here and elsewhere.
539 tmp
, A0_DEST_CHANNEL_X
, 0,
540 swizzle(src0
, X
, X
, X
, X
), 0, 0);
542 i915_emit_arith(p
, A0_MUL
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, src1
, 0);
547 get_result_vector(p
, inst
),
548 flags
, 0, swizzle(tmp
, X
, X
, X
, X
), 0, 0);
553 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
557 get_result_vector(p
, inst
),
558 get_result_flags(inst
), 0,
559 swizzle(src0
, X
, X
, X
, X
), 0, 0);
564 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
568 get_result_vector(p
, inst
),
569 get_result_flags(inst
), 0,
570 swizzle(src0
, X
, X
, X
, X
), 0, 0);
574 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
575 tmp
= i915_get_utemp(p
);
578 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
579 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
580 * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x
581 * scs.x = DP4 t1, sin_constants
582 * t1 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1
583 * scs.y = DP4 t1, cos_constants
587 tmp
, A0_DEST_CHANNEL_XY
, 0,
588 swizzle(src0
, X
, X
, ONE
, ONE
),
589 swizzle(src0
, X
, ONE
, ONE
, ONE
), 0);
593 tmp
, A0_DEST_CHANNEL_ALL
, 0,
594 swizzle(tmp
, X
, Y
, X
, Y
),
595 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
597 if (inst
->DstReg
.WriteMask
& WRITEMASK_Y
) {
600 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
)
601 tmp1
= i915_get_utemp(p
);
607 tmp1
, A0_DEST_CHANNEL_ALL
, 0,
608 swizzle(tmp
, X
, Y
, Y
, W
),
609 swizzle(tmp
, X
, Z
, ONE
, ONE
), 0);
613 get_result_vector(p
, inst
),
614 A0_DEST_CHANNEL_Y
, 0,
615 swizzle(tmp1
, W
, Z
, Y
, X
),
616 i915_emit_const4fv(p
, sin_constants
), 0);
619 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
) {
622 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
623 swizzle(tmp
, X
, X
, Z
, ONE
),
624 swizzle(tmp
, Z
, ONE
, ONE
, ONE
), 0);
628 get_result_vector(p
, inst
),
629 A0_DEST_CHANNEL_X
, 0,
630 swizzle(tmp
, ONE
, Z
, Y
, X
),
631 i915_emit_const4fv(p
, cos_constants
), 0);
636 EMIT_2ARG_ARITH(A0_SGE
);
640 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
641 tmp
= i915_get_utemp(p
);
645 tmp
, A0_DEST_CHANNEL_X
, 0,
646 src0
, i915_emit_const1f(p
, 1.0 / (M_PI
)), 0);
648 i915_emit_arith(p
, A0_MOD
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, 0, 0);
650 /* By choosing different taylor constants, could get rid of this mul:
654 tmp
, A0_DEST_CHANNEL_X
, 0,
655 tmp
, i915_emit_const1f(p
, (M_PI
)), 0);
658 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
659 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
660 * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x
661 * result = DP4 t1.wzyx, sin_constants
665 tmp
, A0_DEST_CHANNEL_XY
, 0,
666 swizzle(tmp
, X
, X
, ONE
, ONE
),
667 swizzle(tmp
, X
, ONE
, ONE
, ONE
), 0);
671 tmp
, A0_DEST_CHANNEL_ALL
, 0,
672 swizzle(tmp
, X
, Y
, X
, Y
),
673 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
677 tmp
, A0_DEST_CHANNEL_ALL
, 0,
678 swizzle(tmp
, X
, Y
, Y
, W
),
679 swizzle(tmp
, X
, Z
, ONE
, ONE
), 0);
683 get_result_vector(p
, inst
),
684 get_result_flags(inst
), 0,
685 swizzle(tmp
, W
, Z
, Y
, X
),
686 i915_emit_const4fv(p
, sin_constants
), 0);
690 EMIT_2ARG_ARITH(A0_SLT
);
694 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
695 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
699 get_result_vector(p
, inst
),
700 get_result_flags(inst
), 0,
701 src0
, negate(src1
, 1, 1, 1, 1), 0);
705 EMIT_1ARG_ARITH(A0_MOV
); /* extended swizzle handled natively */
722 * result.x = src0.y * src1.z - src0.z * src1.y;
723 * result.y = src0.z * src1.x - src0.x * src1.z;
724 * result.z = src0.x * src1.y - src0.y * src1.x;
727 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
728 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
729 tmp
= i915_get_utemp(p
);
733 tmp
, A0_DEST_CHANNEL_ALL
, 0,
734 swizzle(src0
, Z
, X
, Y
, ONE
),
735 swizzle(src1
, Y
, Z
, X
, ONE
), 0);
739 get_result_vector(p
, inst
),
740 get_result_flags(inst
), 0,
741 swizzle(src0
, Y
, Z
, X
, ONE
),
742 swizzle(src1
, Z
, X
, Y
, ONE
),
743 negate(tmp
, 1, 1, 1, 0));
750 i915_program_error(p
, "bad opcode");
755 i915_release_utemps(p
);
759 /* Rather than trying to intercept and jiggle depth writes during
760 * emit, just move the value into its correct position at the end of
764 fixup_depth_write(struct i915_fragment_program
*p
)
766 if (p
->depth_written
) {
767 GLuint depth
= UREG(REG_TYPE_OD
, 0);
771 depth
, A0_DEST_CHANNEL_W
, 0,
772 swizzle(depth
, X
, Y
, Z
, Z
), 0, 0);
778 check_wpos(struct i915_fragment_program
*p
)
780 GLuint inputs
= p
->FragProg
.Base
.InputsRead
;
785 for (i
= 0; i
< p
->ctx
->Const
.MaxTextureCoordUnits
; i
++) {
786 if (inputs
& FRAG_BIT_TEX(i
))
788 else if (inputs
& FRAG_BIT_WPOS
) {
790 inputs
&= ~FRAG_BIT_WPOS
;
794 if (inputs
& FRAG_BIT_WPOS
) {
795 i915_program_error(p
, "No free texcoord for wpos value");
801 translate_program(struct i915_fragment_program
*p
)
803 struct i915_context
*i915
= I915_CONTEXT(p
->ctx
);
805 i915_init_program(i915
, p
);
808 fixup_depth_write(p
);
809 i915_fini_program(p
);
816 track_params(struct i915_fragment_program
*p
)
821 _mesa_load_state_parameters(p
->ctx
, p
->FragProg
.Base
.Parameters
);
823 for (i
= 0; i
< p
->nr_params
; i
++) {
824 GLint reg
= p
->param
[i
].reg
;
825 COPY_4V(p
->constant
[reg
], p
->param
[i
].values
);
828 p
->params_uptodate
= 1;
829 p
->on_hardware
= 0; /* overkill */
834 i915BindProgram(GLcontext
* ctx
, GLenum target
, struct gl_program
*prog
)
836 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
837 struct i915_context
*i915
= I915_CONTEXT(ctx
);
838 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
840 if (i915
->current_program
== p
)
843 if (i915
->current_program
) {
844 i915
->current_program
->on_hardware
= 0;
845 i915
->current_program
->params_uptodate
= 0;
848 i915
->current_program
= p
;
850 assert(p
->on_hardware
== 0);
851 assert(p
->params_uptodate
== 0);
856 static struct gl_program
*
857 i915NewProgram(GLcontext
* ctx
, GLenum target
, GLuint id
)
860 case GL_VERTEX_PROGRAM_ARB
:
861 return _mesa_init_vertex_program(ctx
, CALLOC_STRUCT(gl_vertex_program
),
864 case GL_FRAGMENT_PROGRAM_ARB
:{
865 struct i915_fragment_program
*prog
=
866 CALLOC_STRUCT(i915_fragment_program
);
868 i915_init_program(I915_CONTEXT(ctx
), prog
);
870 return _mesa_init_fragment_program(ctx
, &prog
->FragProg
,
880 return _mesa_new_program(ctx
, target
, id
);
885 i915DeleteProgram(GLcontext
* ctx
, struct gl_program
*prog
)
887 if (prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
888 struct i915_context
*i915
= I915_CONTEXT(ctx
);
889 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
891 if (i915
->current_program
== p
)
892 i915
->current_program
= 0;
895 _mesa_delete_program(ctx
, prog
);
900 i915IsProgramNative(GLcontext
* ctx
, GLenum target
, struct gl_program
*prog
)
902 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
903 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
906 translate_program(p
);
915 i915ProgramStringNotify(GLcontext
* ctx
,
916 GLenum target
, struct gl_program
*prog
)
918 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
919 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
922 /* Hack: make sure fog is correctly enabled according to this
923 * fragment program's fog options.
925 if (p
->FragProg
.FogOption
) {
926 /* add extra instructions to do fog, then turn off FogOption field */
927 _mesa_append_fog_code(ctx
, &p
->FragProg
);
928 p
->FragProg
.FogOption
= GL_NONE
;
932 _tnl_program_string(ctx
, target
, prog
);
937 i915ValidateFragmentProgram(struct i915_context
*i915
)
939 GLcontext
*ctx
= &i915
->intel
.ctx
;
940 struct intel_context
*intel
= intel_context(ctx
);
941 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
942 struct vertex_buffer
*VB
= &tnl
->vb
;
944 struct i915_fragment_program
*p
=
945 (struct i915_fragment_program
*) ctx
->FragmentProgram
._Current
;
947 const GLuint inputsRead
= p
->FragProg
.Base
.InputsRead
;
948 GLuint s4
= i915
->state
.Ctx
[I915_CTXREG_LIS4
] & ~S4_VFMT_MASK
;
949 GLuint s2
= S2_TEXCOORD_NONE
;
952 if (i915
->current_program
!= p
) {
953 if (i915
->current_program
) {
954 i915
->current_program
->on_hardware
= 0;
955 i915
->current_program
->params_uptodate
= 0;
958 i915
->current_program
= p
;
964 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
967 translate_program(p
);
969 intel
->vertex_attr_count
= 0;
970 intel
->wpos_offset
= 0;
971 intel
->wpos_size
= 0;
972 intel
->coloroffset
= 0;
973 intel
->specoffset
= 0;
975 if (inputsRead
& FRAG_BITS_TEX_ANY
) {
976 EMIT_ATTR(_TNL_ATTRIB_POS
, EMIT_4F_VIEWPORT
, S4_VFMT_XYZW
, 16);
979 EMIT_ATTR(_TNL_ATTRIB_POS
, EMIT_3F_VIEWPORT
, S4_VFMT_XYZ
, 12);
982 if (inputsRead
& FRAG_BIT_COL0
) {
983 intel
->coloroffset
= offset
/ 4;
984 EMIT_ATTR(_TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_BGRA
, S4_VFMT_COLOR
, 4);
987 if ((inputsRead
& (FRAG_BIT_COL1
| FRAG_BIT_FOGC
)) ||
988 i915
->vertex_fog
!= I915_FOG_NONE
) {
990 if (inputsRead
& FRAG_BIT_COL1
) {
991 intel
->specoffset
= offset
/ 4;
992 EMIT_ATTR(_TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_BGR
, S4_VFMT_SPEC_FOG
, 3);
997 if ((inputsRead
& FRAG_BIT_FOGC
) || i915
->vertex_fog
!= I915_FOG_NONE
)
998 EMIT_ATTR(_TNL_ATTRIB_FOG
, EMIT_1UB_1F
, S4_VFMT_SPEC_FOG
, 1);
1003 /* XXX this was disabled, but enabling this code helped fix the Glean
1004 * tfragprog1 fog tests.
1007 if ((inputsRead
& FRAG_BIT_FOGC
) || i915
->vertex_fog
!= I915_FOG_NONE
) {
1008 EMIT_ATTR(_TNL_ATTRIB_FOG
, EMIT_1F
, S4_VFMT_FOG_PARAM
, 4);
1012 for (i
= 0; i
< p
->ctx
->Const
.MaxTextureCoordUnits
; i
++) {
1013 if (inputsRead
& FRAG_BIT_TEX(i
)) {
1014 int sz
= VB
->TexCoordPtr
[i
]->size
;
1016 s2
&= ~S2_TEXCOORD_FMT(i
, S2_TEXCOORD_FMT0_MASK
);
1017 s2
|= S2_TEXCOORD_FMT(i
, SZ_TO_HW(sz
));
1019 EMIT_ATTR(_TNL_ATTRIB_TEX0
+ i
, EMIT_SZ(sz
), 0, sz
* 4);
1021 else if (i
== p
->wpos_tex
) {
1023 /* If WPOS is required, duplicate the XYZ position data in an
1024 * unused texture coordinate:
1026 s2
&= ~S2_TEXCOORD_FMT(i
, S2_TEXCOORD_FMT0_MASK
);
1027 s2
|= S2_TEXCOORD_FMT(i
, SZ_TO_HW(3));
1029 intel
->wpos_offset
= offset
;
1030 intel
->wpos_size
= 3 * sizeof(GLuint
);
1032 EMIT_PAD(intel
->wpos_size
);
1036 if (s2
!= i915
->state
.Ctx
[I915_CTXREG_LIS2
] ||
1037 s4
!= i915
->state
.Ctx
[I915_CTXREG_LIS4
]) {
1040 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
1042 /* Must do this *after* statechange, so as not to affect
1043 * buffered vertices reliant on the old state:
1045 intel
->vertex_size
= _tnl_install_attrs(&intel
->ctx
,
1046 intel
->vertex_attrs
,
1047 intel
->vertex_attr_count
,
1048 intel
->ViewportMatrix
.m
, 0);
1050 intel
->vertex_size
>>= 2;
1052 i915
->state
.Ctx
[I915_CTXREG_LIS2
] = s2
;
1053 i915
->state
.Ctx
[I915_CTXREG_LIS4
] = s4
;
1055 k
= intel
->vtbl
.check_vertex_size(intel
, intel
->vertex_size
);
1059 if (!p
->params_uptodate
)
1062 if (!p
->on_hardware
)
1063 i915_upload_program(i915
, p
);
1067 i915InitFragProgFuncs(struct dd_function_table
*functions
)
1069 functions
->BindProgram
= i915BindProgram
;
1070 functions
->NewProgram
= i915NewProgram
;
1071 functions
->DeleteProgram
= i915DeleteProgram
;
1072 functions
->IsProgramNative
= i915IsProgramNative
;
1073 functions
->ProgramStringNotify
= i915ProgramStringNotify
;