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 **************************************************************************/
33 #include "tnl/t_context.h"
34 #include "intel_batchbuffer.h"
37 #include "i915_context.h"
38 #include "i915_program.h"
40 #include "prog_instruction.h"
41 #include "prog_parameter.h"
43 #include "programopt.h"
47 /* 1, -1/3!, 1/5!, -1/7! */
48 static const GLfloat sin_constants
[4] = { 1.0,
50 1.0 / (5 * 4 * 3 * 2 * 1),
51 -1.0 / (7 * 6 * 5 * 4 * 3 * 2 * 1)
54 /* 1, -1/2!, 1/4!, -1/6! */
55 static const GLfloat cos_constants
[4] = { 1.0,
57 1.0 / (4 * 3 * 2 * 1),
58 -1.0 / (6 * 5 * 4 * 3 * 2 * 1)
62 * Retrieve a ureg for the given source register. Will emit
63 * constants, apply swizzling and negation as needed.
66 src_vector(struct i915_fragment_program
*p
,
67 const struct prog_src_register
*source
,
68 const struct gl_fragment_program
*program
)
72 switch (source
->File
) {
76 case PROGRAM_TEMPORARY
:
77 if (source
->Index
>= I915_MAX_TEMPORARY
) {
78 i915_program_error(p
, "Exceeded max temporary reg");
81 src
= UREG(REG_TYPE_R
, source
->Index
);
84 switch (source
->Index
) {
85 case FRAG_ATTRIB_WPOS
:
86 src
= i915_emit_decl(p
, REG_TYPE_T
, p
->wpos_tex
, D0_CHANNEL_ALL
);
88 case FRAG_ATTRIB_COL0
:
89 src
= i915_emit_decl(p
, REG_TYPE_T
, T_DIFFUSE
, D0_CHANNEL_ALL
);
91 case FRAG_ATTRIB_COL1
:
92 src
= i915_emit_decl(p
, REG_TYPE_T
, T_SPECULAR
, D0_CHANNEL_XYZ
);
93 src
= swizzle(src
, X
, Y
, Z
, ONE
);
95 case FRAG_ATTRIB_FOGC
:
96 src
= i915_emit_decl(p
, REG_TYPE_T
, T_FOG_W
, D0_CHANNEL_W
);
97 src
= swizzle(src
, W
, W
, W
, W
);
99 case FRAG_ATTRIB_TEX0
:
100 case FRAG_ATTRIB_TEX1
:
101 case FRAG_ATTRIB_TEX2
:
102 case FRAG_ATTRIB_TEX3
:
103 case FRAG_ATTRIB_TEX4
:
104 case FRAG_ATTRIB_TEX5
:
105 case FRAG_ATTRIB_TEX6
:
106 case FRAG_ATTRIB_TEX7
:
107 src
= i915_emit_decl(p
, REG_TYPE_T
,
108 T_TEX0
+ (source
->Index
- FRAG_ATTRIB_TEX0
),
113 i915_program_error(p
, "Bad source->Index");
118 /* Various paramters and env values. All emitted to
119 * hardware as program constants.
121 case PROGRAM_LOCAL_PARAM
:
122 src
= i915_emit_param4fv(p
, program
->Base
.LocalParams
[source
->Index
]);
125 case PROGRAM_ENV_PARAM
:
127 i915_emit_param4fv(p
,
128 p
->ctx
->FragmentProgram
.Parameters
[source
->
132 case PROGRAM_CONSTANT
:
133 case PROGRAM_STATE_VAR
:
134 case PROGRAM_NAMED_PARAM
:
136 i915_emit_param4fv(p
,
137 program
->Base
.Parameters
->ParameterValues
[source
->
142 i915_program_error(p
, "Bad source->File");
147 GET_SWZ(source
->Swizzle
, 0),
148 GET_SWZ(source
->Swizzle
, 1),
149 GET_SWZ(source
->Swizzle
, 2), GET_SWZ(source
->Swizzle
, 3));
151 if (source
->NegateBase
)
153 GET_BIT(source
->NegateBase
, 0),
154 GET_BIT(source
->NegateBase
, 1),
155 GET_BIT(source
->NegateBase
, 2),
156 GET_BIT(source
->NegateBase
, 3));
163 get_result_vector(struct i915_fragment_program
*p
,
164 const struct prog_instruction
*inst
)
166 switch (inst
->DstReg
.File
) {
168 switch (inst
->DstReg
.Index
) {
169 case FRAG_RESULT_COLR
:
170 return UREG(REG_TYPE_OC
, 0);
171 case FRAG_RESULT_DEPR
:
172 p
->depth_written
= 1;
173 return UREG(REG_TYPE_OD
, 0);
175 i915_program_error(p
, "Bad inst->DstReg.Index");
178 case PROGRAM_TEMPORARY
:
179 return UREG(REG_TYPE_R
, inst
->DstReg
.Index
);
181 i915_program_error(p
, "Bad inst->DstReg.File");
187 get_result_flags(const struct prog_instruction
*inst
)
191 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
192 flags
|= A0_DEST_SATURATE
;
193 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
)
194 flags
|= A0_DEST_CHANNEL_X
;
195 if (inst
->DstReg
.WriteMask
& WRITEMASK_Y
)
196 flags
|= A0_DEST_CHANNEL_Y
;
197 if (inst
->DstReg
.WriteMask
& WRITEMASK_Z
)
198 flags
|= A0_DEST_CHANNEL_Z
;
199 if (inst
->DstReg
.WriteMask
& WRITEMASK_W
)
200 flags
|= A0_DEST_CHANNEL_W
;
206 translate_tex_src_target(struct i915_fragment_program
*p
, GLubyte bit
)
209 case TEXTURE_1D_INDEX
:
210 return D0_SAMPLE_TYPE_2D
;
211 case TEXTURE_2D_INDEX
:
212 return D0_SAMPLE_TYPE_2D
;
213 case TEXTURE_RECT_INDEX
:
214 return D0_SAMPLE_TYPE_2D
;
215 case TEXTURE_3D_INDEX
:
216 return D0_SAMPLE_TYPE_VOLUME
;
217 case TEXTURE_CUBE_INDEX
:
218 return D0_SAMPLE_TYPE_CUBE
;
220 i915_program_error(p
, "TexSrcBit");
225 #define EMIT_TEX( OP ) \
227 GLuint dim = translate_tex_src_target( p, inst->TexSrcTarget ); \
228 GLuint sampler = i915_emit_decl(p, REG_TYPE_S, \
229 inst->TexSrcUnit, dim); \
230 GLuint coord = src_vector( p, &inst->SrcReg[0], program); \
233 i915_emit_texld( p, \
234 get_result_vector( p, inst ), \
235 get_result_flags( inst ), \
241 #define EMIT_ARITH( OP, N ) \
243 i915_emit_arith( p, \
245 get_result_vector( p, inst ), \
246 get_result_flags( inst ), 0, \
247 (N<1)?0:src_vector( p, &inst->SrcReg[0], program), \
248 (N<2)?0:src_vector( p, &inst->SrcReg[1], program), \
249 (N<3)?0:src_vector( p, &inst->SrcReg[2], program)); \
252 #define EMIT_1ARG_ARITH( OP ) EMIT_ARITH( OP, 1 )
253 #define EMIT_2ARG_ARITH( OP ) EMIT_ARITH( OP, 2 )
254 #define EMIT_3ARG_ARITH( OP ) EMIT_ARITH( OP, 3 )
257 /* Possible concerns:
259 * SIN, COS -- could use another taylor step?
260 * LIT -- results seem a little different to sw mesa
261 * LOG -- different to mesa on negative numbers, but this is conformant.
263 * Parse failures -- Mesa doesn't currently give a good indication
264 * internally whether a particular program string parsed or not. This
265 * can lead to confusion -- hopefully we cope with it ok now.
269 upload_program(struct i915_fragment_program
*p
)
271 const struct gl_fragment_program
*program
=
272 p
->ctx
->FragmentProgram
._Current
;
273 const struct prog_instruction
*inst
= program
->Base
.Instructions
;
275 /* _mesa_debug_fp_inst(program->Base.NumInstructions, inst); */
277 /* Is this a parse-failed program? Ensure a valid program is
278 * loaded, as the flagging of an error isn't sufficient to stop
279 * this being uploaded to hardware.
281 if (inst
[0].Opcode
== OPCODE_END
) {
282 GLuint tmp
= i915_get_utemp(p
);
285 UREG(REG_TYPE_OC
, 0),
286 A0_DEST_CHANNEL_ALL
, 0,
287 swizzle(tmp
, ONE
, ZERO
, ONE
, ONE
), 0, 0);
292 GLuint src0
, src1
, src2
, flags
;
295 switch (inst
->Opcode
) {
297 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
300 get_result_vector(p
, inst
),
301 get_result_flags(inst
), 0,
302 src0
, negate(src0
, 1, 1, 1, 1), 0);
306 EMIT_2ARG_ARITH(A0_ADD
);
310 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
311 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
312 src2
= src_vector(p
, &inst
->SrcReg
[2], program
);
313 i915_emit_arith(p
, A0_CMP
, get_result_vector(p
, inst
), get_result_flags(inst
), 0, src0
, src2
, src1
); /* NOTE: order of src2, src1 */
317 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
318 tmp
= i915_get_utemp(p
);
322 tmp
, A0_DEST_CHANNEL_X
, 0,
323 src0
, i915_emit_const1f(p
, 1.0 / (M_PI
* 2)), 0);
325 i915_emit_arith(p
, A0_MOD
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, 0, 0);
327 /* By choosing different taylor constants, could get rid of this mul:
331 tmp
, A0_DEST_CHANNEL_X
, 0,
332 tmp
, i915_emit_const1f(p
, (M_PI
* 2)), 0);
335 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
336 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, 1
337 * t0 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1
338 * result = DP4 t0, cos_constants
342 tmp
, A0_DEST_CHANNEL_XY
, 0,
343 swizzle(tmp
, X
, X
, ONE
, ONE
),
344 swizzle(tmp
, X
, ONE
, ONE
, ONE
), 0);
348 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
349 swizzle(tmp
, X
, Y
, X
, ONE
),
350 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
354 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
355 swizzle(tmp
, X
, X
, Z
, ONE
),
356 swizzle(tmp
, Z
, ONE
, ONE
, ONE
), 0);
360 get_result_vector(p
, inst
),
361 get_result_flags(inst
), 0,
362 swizzle(tmp
, ONE
, Z
, Y
, X
),
363 i915_emit_const4fv(p
, cos_constants
), 0);
368 EMIT_2ARG_ARITH(A0_DP3
);
372 EMIT_2ARG_ARITH(A0_DP4
);
376 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
377 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
381 get_result_vector(p
, inst
),
382 get_result_flags(inst
), 0,
383 swizzle(src0
, X
, Y
, Z
, ONE
), src1
, 0);
387 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
388 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
390 /* result[0] = 1 * 1;
391 * result[1] = a[1] * b[1];
392 * result[2] = a[2] * 1;
393 * result[3] = 1 * b[3];
397 get_result_vector(p
, inst
),
398 get_result_flags(inst
), 0,
399 swizzle(src0
, ONE
, Y
, Z
, ONE
),
400 swizzle(src1
, ONE
, Y
, ONE
, W
), 0);
404 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
408 get_result_vector(p
, inst
),
409 get_result_flags(inst
), 0,
410 swizzle(src0
, X
, X
, X
, X
), 0, 0);
414 EMIT_1ARG_ARITH(A0_FLR
);
418 EMIT_1ARG_ARITH(A0_FRC
);
422 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
423 tmp
= i915_get_utemp(p
);
425 i915_emit_texld(p
, tmp
, A0_DEST_CHANNEL_ALL
, /* use a dummy dest reg */
426 0, src0
, T0_TEXKILL
);
430 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
434 get_result_vector(p
, inst
),
435 get_result_flags(inst
), 0,
436 swizzle(src0
, X
, X
, X
, X
), 0, 0);
440 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
441 tmp
= i915_get_utemp(p
);
443 /* tmp = max( a.xyzw, a.00zw )
444 * XXX: Clamp tmp.w to -128..128
446 * tmp.y = tmp.w * tmp.y
448 * result = cmp (a.11-x1, a.1x01, a.1xy1 )
450 i915_emit_arith(p
, A0_MAX
, tmp
, A0_DEST_CHANNEL_ALL
, 0,
451 src0
, swizzle(src0
, ZERO
, ZERO
, Z
, W
), 0);
453 i915_emit_arith(p
, A0_LOG
, tmp
, A0_DEST_CHANNEL_Y
, 0,
454 swizzle(tmp
, Y
, Y
, Y
, Y
), 0, 0);
456 i915_emit_arith(p
, A0_MUL
, tmp
, A0_DEST_CHANNEL_Y
, 0,
457 swizzle(tmp
, ZERO
, Y
, ZERO
, ZERO
),
458 swizzle(tmp
, ZERO
, W
, ZERO
, ZERO
), 0);
460 i915_emit_arith(p
, A0_EXP
, tmp
, A0_DEST_CHANNEL_Y
, 0,
461 swizzle(tmp
, Y
, Y
, Y
, Y
), 0, 0);
463 i915_emit_arith(p
, A0_CMP
,
464 get_result_vector(p
, inst
),
465 get_result_flags(inst
), 0,
466 negate(swizzle(tmp
, ONE
, ONE
, X
, ONE
), 0, 0, 1, 0),
467 swizzle(tmp
, ONE
, X
, ZERO
, ONE
),
468 swizzle(tmp
, ONE
, X
, Y
, ONE
));
473 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
474 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
475 src2
= src_vector(p
, &inst
->SrcReg
[2], program
);
476 flags
= get_result_flags(inst
);
477 tmp
= i915_get_utemp(p
);
484 * result = (-c)*a + tmp
486 i915_emit_arith(p
, A0_MAD
, tmp
,
487 flags
& A0_DEST_CHANNEL_ALL
, 0, src1
, src0
, src2
);
489 i915_emit_arith(p
, A0_MAD
,
490 get_result_vector(p
, inst
),
491 flags
, 0, negate(src2
, 1, 1, 1, 1), src0
, tmp
);
495 EMIT_3ARG_ARITH(A0_MAD
);
499 EMIT_2ARG_ARITH(A0_MAX
);
503 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
504 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
505 tmp
= i915_get_utemp(p
);
506 flags
= get_result_flags(inst
);
510 tmp
, flags
& A0_DEST_CHANNEL_ALL
, 0,
511 negate(src0
, 1, 1, 1, 1),
512 negate(src1
, 1, 1, 1, 1), 0);
516 get_result_vector(p
, inst
),
517 flags
, 0, negate(tmp
, 1, 1, 1, 1), 0, 0);
521 EMIT_1ARG_ARITH(A0_MOV
);
525 EMIT_2ARG_ARITH(A0_MUL
);
529 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
530 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
531 tmp
= i915_get_utemp(p
);
532 flags
= get_result_flags(inst
);
534 /* XXX: masking on intermediate values, here and elsewhere.
538 tmp
, A0_DEST_CHANNEL_X
, 0,
539 swizzle(src0
, X
, X
, X
, X
), 0, 0);
541 i915_emit_arith(p
, A0_MUL
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, src1
, 0);
546 get_result_vector(p
, inst
),
547 flags
, 0, swizzle(tmp
, X
, X
, X
, X
), 0, 0);
552 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
556 get_result_vector(p
, inst
),
557 get_result_flags(inst
), 0,
558 swizzle(src0
, X
, X
, X
, X
), 0, 0);
563 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
567 get_result_vector(p
, inst
),
568 get_result_flags(inst
), 0,
569 swizzle(src0
, X
, X
, X
, X
), 0, 0);
573 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
574 tmp
= i915_get_utemp(p
);
577 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
578 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
579 * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x
580 * scs.x = DP4 t1, sin_constants
581 * t1 = MUL t0.xxz1 t0.z111 ; x^6 x^4 x^2 1
582 * scs.y = DP4 t1, cos_constants
586 tmp
, A0_DEST_CHANNEL_XY
, 0,
587 swizzle(src0
, X
, X
, ONE
, ONE
),
588 swizzle(src0
, X
, ONE
, ONE
, ONE
), 0);
592 tmp
, A0_DEST_CHANNEL_ALL
, 0,
593 swizzle(tmp
, X
, Y
, X
, Y
),
594 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
596 if (inst
->DstReg
.WriteMask
& WRITEMASK_Y
) {
599 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
)
600 tmp1
= i915_get_utemp(p
);
606 tmp1
, A0_DEST_CHANNEL_ALL
, 0,
607 swizzle(tmp
, X
, Y
, Y
, W
),
608 swizzle(tmp
, X
, Z
, ONE
, ONE
), 0);
612 get_result_vector(p
, inst
),
613 A0_DEST_CHANNEL_Y
, 0,
614 swizzle(tmp1
, W
, Z
, Y
, X
),
615 i915_emit_const4fv(p
, sin_constants
), 0);
618 if (inst
->DstReg
.WriteMask
& WRITEMASK_X
) {
621 tmp
, A0_DEST_CHANNEL_XYZ
, 0,
622 swizzle(tmp
, X
, X
, Z
, ONE
),
623 swizzle(tmp
, Z
, ONE
, ONE
, ONE
), 0);
627 get_result_vector(p
, inst
),
628 A0_DEST_CHANNEL_X
, 0,
629 swizzle(tmp
, ONE
, Z
, Y
, X
),
630 i915_emit_const4fv(p
, cos_constants
), 0);
635 EMIT_2ARG_ARITH(A0_SGE
);
639 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
640 tmp
= i915_get_utemp(p
);
644 tmp
, A0_DEST_CHANNEL_X
, 0,
645 src0
, i915_emit_const1f(p
, 1.0 / (M_PI
* 2)), 0);
647 i915_emit_arith(p
, A0_MOD
, tmp
, A0_DEST_CHANNEL_X
, 0, tmp
, 0, 0);
649 /* By choosing different taylor constants, could get rid of this mul:
653 tmp
, A0_DEST_CHANNEL_X
, 0,
654 tmp
, i915_emit_const1f(p
, (M_PI
* 2)), 0);
657 * t0.xy = MUL x.xx11, x.x1111 ; x^2, x, 1, 1
658 * t0 = MUL t0.xyxy t0.xx11 ; x^4, x^3, x^2, x
659 * t1 = MUL t0.xyyw t0.yz11 ; x^7 x^5 x^3 x
660 * result = DP4 t1.wzyx, sin_constants
664 tmp
, A0_DEST_CHANNEL_XY
, 0,
665 swizzle(tmp
, X
, X
, ONE
, ONE
),
666 swizzle(tmp
, X
, ONE
, ONE
, ONE
), 0);
670 tmp
, A0_DEST_CHANNEL_ALL
, 0,
671 swizzle(tmp
, X
, Y
, X
, Y
),
672 swizzle(tmp
, X
, X
, ONE
, ONE
), 0);
676 tmp
, A0_DEST_CHANNEL_ALL
, 0,
677 swizzle(tmp
, X
, Y
, Y
, W
),
678 swizzle(tmp
, X
, Z
, ONE
, ONE
), 0);
682 get_result_vector(p
, inst
),
683 get_result_flags(inst
), 0,
684 swizzle(tmp
, W
, Z
, Y
, X
),
685 i915_emit_const4fv(p
, sin_constants
), 0);
689 EMIT_2ARG_ARITH(A0_SLT
);
693 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
694 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
698 get_result_vector(p
, inst
),
699 get_result_flags(inst
), 0,
700 src0
, negate(src1
, 1, 1, 1, 1), 0);
704 EMIT_1ARG_ARITH(A0_MOV
); /* extended swizzle handled natively */
721 * result.x = src0.y * src1.z - src0.z * src1.y;
722 * result.y = src0.z * src1.x - src0.x * src1.z;
723 * result.z = src0.x * src1.y - src0.y * src1.x;
726 src0
= src_vector(p
, &inst
->SrcReg
[0], program
);
727 src1
= src_vector(p
, &inst
->SrcReg
[1], program
);
728 tmp
= i915_get_utemp(p
);
732 tmp
, A0_DEST_CHANNEL_ALL
, 0,
733 swizzle(src0
, Z
, X
, Y
, ONE
),
734 swizzle(src1
, Y
, Z
, X
, ONE
), 0);
738 get_result_vector(p
, inst
),
739 get_result_flags(inst
), 0,
740 swizzle(src0
, Y
, Z
, X
, ONE
),
741 swizzle(src1
, Z
, X
, Y
, ONE
),
742 negate(tmp
, 1, 1, 1, 0));
749 i915_program_error(p
, "bad opcode");
754 i915_release_utemps(p
);
758 /* Rather than trying to intercept and jiggle depth writes during
759 * emit, just move the value into its correct position at the end of
763 fixup_depth_write(struct i915_fragment_program
*p
)
765 if (p
->depth_written
) {
766 GLuint depth
= UREG(REG_TYPE_OD
, 0);
770 depth
, A0_DEST_CHANNEL_W
, 0,
771 swizzle(depth
, X
, Y
, Z
, Z
), 0, 0);
777 check_wpos(struct i915_fragment_program
*p
)
779 GLuint inputs
= p
->FragProg
.Base
.InputsRead
;
784 for (i
= 0; i
< p
->ctx
->Const
.MaxTextureCoordUnits
; i
++) {
785 if (inputs
& FRAG_BIT_TEX(i
))
787 else if (inputs
& FRAG_BIT_WPOS
) {
789 inputs
&= ~FRAG_BIT_WPOS
;
793 if (inputs
& FRAG_BIT_WPOS
) {
794 i915_program_error(p
, "No free texcoord for wpos value");
800 translate_program(struct i915_fragment_program
*p
)
802 struct i915_context
*i915
= I915_CONTEXT(p
->ctx
);
804 i915_init_program(i915
, p
);
807 fixup_depth_write(p
);
808 i915_fini_program(p
);
815 track_params(struct i915_fragment_program
*p
)
820 _mesa_load_state_parameters(p
->ctx
, p
->FragProg
.Base
.Parameters
);
822 for (i
= 0; i
< p
->nr_params
; i
++) {
823 GLint reg
= p
->param
[i
].reg
;
824 COPY_4V(p
->constant
[reg
], p
->param
[i
].values
);
827 p
->params_uptodate
= 1;
828 p
->on_hardware
= 0; /* overkill */
833 i915BindProgram(GLcontext
* ctx
, GLenum target
, struct gl_program
*prog
)
835 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
836 struct i915_context
*i915
= I915_CONTEXT(ctx
);
837 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
839 if (i915
->current_program
== p
)
842 if (i915
->current_program
) {
843 i915
->current_program
->on_hardware
= 0;
844 i915
->current_program
->params_uptodate
= 0;
847 i915
->current_program
= p
;
849 assert(p
->on_hardware
== 0);
850 assert(p
->params_uptodate
== 0);
855 static struct gl_program
*
856 i915NewProgram(GLcontext
* ctx
, GLenum target
, GLuint id
)
859 case GL_VERTEX_PROGRAM_ARB
:
860 return _mesa_init_vertex_program(ctx
, CALLOC_STRUCT(gl_vertex_program
),
863 case GL_FRAGMENT_PROGRAM_ARB
:{
864 struct i915_fragment_program
*prog
=
865 CALLOC_STRUCT(i915_fragment_program
);
867 i915_init_program(I915_CONTEXT(ctx
), prog
);
869 return _mesa_init_fragment_program(ctx
, &prog
->FragProg
,
879 return _mesa_new_program(ctx
, target
, id
);
884 i915DeleteProgram(GLcontext
* ctx
, struct gl_program
*prog
)
886 if (prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
887 struct i915_context
*i915
= I915_CONTEXT(ctx
);
888 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
890 if (i915
->current_program
== p
)
891 i915
->current_program
= 0;
894 _mesa_delete_program(ctx
, prog
);
899 i915IsProgramNative(GLcontext
* ctx
, GLenum target
, struct gl_program
*prog
)
901 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
902 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
905 translate_program(p
);
914 i915ProgramStringNotify(GLcontext
* ctx
,
915 GLenum target
, struct gl_program
*prog
)
917 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
918 struct i915_fragment_program
*p
= (struct i915_fragment_program
*) prog
;
921 /* Hack: make sure fog is correctly enabled according to this
922 * fragment program's fog options.
924 if (p
->FragProg
.FogOption
) {
925 /* add extra instructions to do fog, then turn off FogOption field */
926 _mesa_append_fog_code(ctx
, &p
->FragProg
);
927 p
->FragProg
.FogOption
= GL_NONE
;
931 _tnl_program_string(ctx
, target
, prog
);
936 i915ValidateFragmentProgram(struct i915_context
*i915
)
938 GLcontext
*ctx
= &i915
->intel
.ctx
;
939 struct intel_context
*intel
= intel_context(ctx
);
940 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
941 struct vertex_buffer
*VB
= &tnl
->vb
;
943 struct i915_fragment_program
*p
=
944 (struct i915_fragment_program
*) ctx
->FragmentProgram
._Current
;
946 const GLuint inputsRead
= p
->FragProg
.Base
.InputsRead
;
947 GLuint s4
= i915
->state
.Ctx
[I915_CTXREG_LIS4
] & ~S4_VFMT_MASK
;
948 GLuint s2
= S2_TEXCOORD_NONE
;
951 if (i915
->current_program
!= p
) {
952 if (i915
->current_program
) {
953 i915
->current_program
->on_hardware
= 0;
954 i915
->current_program
->params_uptodate
= 0;
957 i915
->current_program
= p
;
963 VB
->AttribPtr
[VERT_ATTRIB_POS
] = VB
->NdcPtr
;
966 translate_program(p
);
968 intel
->vertex_attr_count
= 0;
969 intel
->wpos_offset
= 0;
970 intel
->wpos_size
= 0;
971 intel
->coloroffset
= 0;
972 intel
->specoffset
= 0;
974 if (inputsRead
& FRAG_BITS_TEX_ANY
) {
975 EMIT_ATTR(_TNL_ATTRIB_POS
, EMIT_4F_VIEWPORT
, S4_VFMT_XYZW
, 16);
978 EMIT_ATTR(_TNL_ATTRIB_POS
, EMIT_3F_VIEWPORT
, S4_VFMT_XYZ
, 12);
981 if (inputsRead
& FRAG_BIT_COL0
) {
982 intel
->coloroffset
= offset
/ 4;
983 EMIT_ATTR(_TNL_ATTRIB_COLOR0
, EMIT_4UB_4F_BGRA
, S4_VFMT_COLOR
, 4);
986 if ((inputsRead
& (FRAG_BIT_COL1
| FRAG_BIT_FOGC
)) ||
987 i915
->vertex_fog
!= I915_FOG_NONE
) {
989 if (inputsRead
& FRAG_BIT_COL1
) {
990 intel
->specoffset
= offset
/ 4;
991 EMIT_ATTR(_TNL_ATTRIB_COLOR1
, EMIT_3UB_3F_BGR
, S4_VFMT_SPEC_FOG
, 3);
996 if ((inputsRead
& FRAG_BIT_FOGC
) || i915
->vertex_fog
!= I915_FOG_NONE
)
997 EMIT_ATTR(_TNL_ATTRIB_FOG
, EMIT_1UB_1F
, S4_VFMT_SPEC_FOG
, 1);
1002 /* XXX this was disabled, but enabling this code helped fix the Glean
1003 * tfragprog1 fog tests.
1006 if ((inputsRead
& FRAG_BIT_FOGC
) || i915
->vertex_fog
!= I915_FOG_NONE
) {
1007 EMIT_ATTR(_TNL_ATTRIB_FOG
, EMIT_1F
, S4_VFMT_FOG_PARAM
, 4);
1011 for (i
= 0; i
< p
->ctx
->Const
.MaxTextureCoordUnits
; i
++) {
1012 if (inputsRead
& FRAG_BIT_TEX(i
)) {
1013 int sz
= VB
->TexCoordPtr
[i
]->size
;
1015 s2
&= ~S2_TEXCOORD_FMT(i
, S2_TEXCOORD_FMT0_MASK
);
1016 s2
|= S2_TEXCOORD_FMT(i
, SZ_TO_HW(sz
));
1018 EMIT_ATTR(_TNL_ATTRIB_TEX0
+ i
, EMIT_SZ(sz
), 0, sz
* 4);
1020 else if (i
== p
->wpos_tex
) {
1022 /* If WPOS is required, duplicate the XYZ position data in an
1023 * unused texture coordinate:
1025 s2
&= ~S2_TEXCOORD_FMT(i
, S2_TEXCOORD_FMT0_MASK
);
1026 s2
|= S2_TEXCOORD_FMT(i
, SZ_TO_HW(3));
1028 intel
->wpos_offset
= offset
;
1029 intel
->wpos_size
= 3 * sizeof(GLuint
);
1031 EMIT_PAD(intel
->wpos_size
);
1035 if (s2
!= i915
->state
.Ctx
[I915_CTXREG_LIS2
] ||
1036 s4
!= i915
->state
.Ctx
[I915_CTXREG_LIS4
]) {
1039 I915_STATECHANGE(i915
, I915_UPLOAD_CTX
);
1041 /* Must do this *after* statechange, so as not to affect
1042 * buffered vertices reliant on the old state:
1044 intel
->vertex_size
= _tnl_install_attrs(&intel
->ctx
,
1045 intel
->vertex_attrs
,
1046 intel
->vertex_attr_count
,
1047 intel
->ViewportMatrix
.m
, 0);
1049 intel
->vertex_size
>>= 2;
1051 i915
->state
.Ctx
[I915_CTXREG_LIS2
] = s2
;
1052 i915
->state
.Ctx
[I915_CTXREG_LIS4
] = s4
;
1054 k
= intel
->vtbl
.check_vertex_size(intel
, intel
->vertex_size
);
1058 if (!p
->params_uptodate
)
1061 if (!p
->on_hardware
)
1062 i915_upload_program(i915
, p
);
1066 i915InitFragProgFuncs(struct dd_function_table
*functions
)
1068 functions
->BindProgram
= i915BindProgram
;
1069 functions
->NewProgram
= i915NewProgram
;
1070 functions
->DeleteProgram
= i915DeleteProgram
;
1071 functions
->IsProgramNative
= i915IsProgramNative
;
1072 functions
->ProgramStringNotify
= i915ProgramStringNotify
;