2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "pipe/p_shader_constants.h"
35 #include "brw_context.h"
46 static const char *wm_opcode_strings
[] = {
60 /***********************************************************************
64 static struct prog_src_register
src_reg(GLuint file
, GLuint idx
)
66 struct prog_src_register reg
;
69 reg
.Swizzle
= SWIZZLE_NOOP
;
71 reg
.Negate
= NEGATE_NONE
;
76 static struct prog_src_register
src_reg_from_dst(struct prog_dst_register dst
)
78 return src_reg(dst
.File
, dst
.Index
);
81 static struct prog_src_register
src_undef( void )
83 return src_reg(PROGRAM_UNDEFINED
, 0);
86 static GLboolean
src_is_undef(struct prog_src_register src
)
88 return src
.File
== PROGRAM_UNDEFINED
;
91 static struct prog_src_register
src_swizzle( struct prog_src_register reg
, int x
, int y
, int z
, int w
)
93 reg
.Swizzle
= MAKE_SWIZZLE4(x
,y
,z
,w
);
97 static struct prog_src_register
src_swizzle1( struct prog_src_register reg
, int x
)
99 return src_swizzle(reg
, x
, x
, x
, x
);
102 static struct prog_src_register
src_swizzle4( struct prog_src_register reg
, uint swizzle
)
104 reg
.Swizzle
= swizzle
;
109 /***********************************************************************
113 static struct prog_dst_register
dst_reg(GLuint file
, GLuint idx
)
115 struct prog_dst_register reg
;
118 reg
.WriteMask
= BRW_WRITEMASK_XYZW
;
120 reg
.CondMask
= COND_TR
;
127 static struct prog_dst_register
dst_mask( struct prog_dst_register reg
, int mask
)
129 reg
.WriteMask
&= mask
;
133 static struct prog_dst_register
dst_undef( void )
135 return dst_reg(PROGRAM_UNDEFINED
, 0);
140 static struct prog_dst_register
get_temp( struct brw_wm_compile
*c
)
142 int bit
= _mesa_ffs( ~c
->fp_temp
);
145 debug_printf("%s: out of temporaries\n", __FILE__
);
149 c
->fp_temp
|= 1<<(bit
-1);
150 return dst_reg(PROGRAM_TEMPORARY
, c
->first_internal_temp
+(bit
-1));
154 static void release_temp( struct brw_wm_compile
*c
, struct prog_dst_register temp
)
156 c
->fp_temp
&= ~(1 << (temp
.Index
- c
->first_internal_temp
));
160 /***********************************************************************
164 static struct prog_instruction
*get_fp_inst(struct brw_wm_compile
*c
)
166 return &c
->prog_instructions
[c
->nr_fp_insns
++];
169 static struct prog_instruction
*emit_insn(struct brw_wm_compile
*c
,
170 const struct prog_instruction
*inst0
)
172 struct prog_instruction
*inst
= get_fp_inst(c
);
177 static struct prog_instruction
* emit_op(struct brw_wm_compile
*c
,
179 struct prog_dst_register dest
,
181 struct prog_src_register src0
,
182 struct prog_src_register src1
,
183 struct prog_src_register src2
)
185 struct prog_instruction
*inst
= get_fp_inst(c
);
187 memset(inst
, 0, sizeof(*inst
));
191 inst
->SaturateMode
= saturate
;
192 inst
->SrcReg
[0] = src0
;
193 inst
->SrcReg
[1] = src1
;
194 inst
->SrcReg
[2] = src2
;
199 /* Many opcodes produce the same value across all the result channels.
200 * We'd rather not have to support that splatting in the opcode implementations,
201 * and brw_wm_pass*.c wants to optimize them out by shuffling references around
202 * anyway. We can easily get both by emitting the opcode to one channel, and
203 * then MOVing it to the others, which brw_wm_pass*.c already understands.
205 static struct prog_instruction
*emit_scalar_insn(struct brw_wm_compile
*c
,
206 const struct prog_instruction
*inst0
)
208 struct prog_instruction
*inst
;
209 unsigned int dst_chan
;
210 unsigned int other_channel_mask
;
212 if (inst0
->DstReg
.WriteMask
== 0)
215 dst_chan
= _mesa_ffs(inst0
->DstReg
.WriteMask
) - 1;
216 inst
= get_fp_inst(c
);
218 inst
->DstReg
.WriteMask
= 1 << dst_chan
;
220 other_channel_mask
= inst0
->DstReg
.WriteMask
& ~(1 << dst_chan
);
221 if (other_channel_mask
!= 0) {
224 dst_mask(inst0
->DstReg
, other_channel_mask
),
226 src_swizzle1(src_reg_from_dst(inst0
->DstReg
), dst_chan
),
234 /***********************************************************************
235 * Special instructions for interpolation and other tasks
238 static struct prog_src_register
get_pixel_xy( struct brw_wm_compile
*c
)
240 if (src_is_undef(c
->pixel_xy
)) {
241 struct prog_dst_register pixel_xy
= get_temp(c
);
242 struct prog_src_register payload_r0_depth
= src_reg(PROGRAM_PAYLOAD
, PAYLOAD_DEPTH
);
245 /* Emit the out calculations, and hold onto the results. Use
246 * two instructions as a temporary is required.
248 /* pixel_xy.xy = PIXELXY payload[0];
252 dst_mask(pixel_xy
, BRW_WRITEMASK_XY
),
258 c
->pixel_xy
= src_reg_from_dst(pixel_xy
);
264 static struct prog_src_register
get_delta_xy( struct brw_wm_compile
*c
)
266 if (src_is_undef(c
->delta_xy
)) {
267 struct prog_dst_register delta_xy
= get_temp(c
);
268 struct prog_src_register pixel_xy
= get_pixel_xy(c
);
269 struct prog_src_register payload_r0_depth
= src_reg(PROGRAM_PAYLOAD
, PAYLOAD_DEPTH
);
271 /* deltas.xy = DELTAXY pixel_xy, payload[0]
275 dst_mask(delta_xy
, BRW_WRITEMASK_XY
),
281 c
->delta_xy
= src_reg_from_dst(delta_xy
);
287 static struct prog_src_register
get_pixel_w( struct brw_wm_compile
*c
)
289 if (src_is_undef(c
->pixel_w
)) {
290 struct prog_dst_register pixel_w
= get_temp(c
);
291 struct prog_src_register deltas
= get_delta_xy(c
);
292 struct prog_src_register interp_wpos
= src_reg(PROGRAM_PAYLOAD
, FRAG_ATTRIB_WPOS
);
294 /* deltas.xyw = DELTAS2 deltas.xy, payload.interp_wpos.x
298 dst_mask(pixel_w
, BRW_WRITEMASK_W
),
305 c
->pixel_w
= src_reg_from_dst(pixel_w
);
311 static void emit_interp( struct brw_wm_compile
*c
,
313 GLuint semantic_index
,
316 struct prog_dst_register dst
= dst_reg(PROGRAM_INPUT
, idx
);
317 struct prog_src_register interp
= src_reg(PROGRAM_PAYLOAD
, idx
);
318 struct prog_src_register deltas
= get_delta_xy(c
);
320 /* Need to use PINTERP on attributes which have been
321 * multiplied by 1/W in the SF program, and LINTERP on those
325 case FRAG_ATTRIB_WPOS
:
326 /* Have to treat wpos.xy specially:
330 dst_mask(dst
, BRW_WRITEMASK_XY
),
336 dst
= dst_mask(dst
, BRW_WRITEMASK_ZW
);
338 /* PROGRAM_INPUT.attr.xyzw = INTERP payload.interp[attr].x, deltas.xyw
349 case TGSI_SEMANTIC_COLOR
:
350 if (c
->key
.flat_shade
) {
361 translate_interp_mode(interp_mode
),
369 case FRAG_ATTRIB_FOGC
:
370 /* Interpolate the fog coordinate */
373 dst_mask(dst
, BRW_WRITEMASK_X
),
381 dst_mask(dst
, BRW_WRITEMASK_YZW
),
392 case FRAG_ATTRIB_FACE
:
393 /* XXX review/test this case */
396 dst_mask(dst
, BRW_WRITEMASK_X
),
403 case FRAG_ATTRIB_PNTC
:
404 /* XXX review/test this case */
407 dst_mask(dst
, BRW_WRITEMASK_XY
),
415 dst_mask(dst
, BRW_WRITEMASK_ZW
),
428 translate_interp_mode(interp_mode
),
438 /***********************************************************************
439 * Hacks to extend the program parameter and constant lists.
442 /* Add the fog parameters to the parameter list of the original
443 * program, rather than creating a new list. Doesn't really do any
444 * harm and it's not as if the parameter handling isn't a big hack
447 static struct prog_src_register
search_or_add_param5(struct brw_wm_compile
*c
,
454 struct gl_program_parameter_list
*paramList
= c
->fp
->program
.Base
.Parameters
;
455 gl_state_index tokens
[STATE_LENGTH
];
463 for (idx
= 0; idx
< paramList
->NumParameters
; idx
++) {
464 if (paramList
->Parameters
[idx
].Type
== PROGRAM_STATE_VAR
&&
465 memcmp(paramList
->Parameters
[idx
].StateIndexes
, tokens
, sizeof(tokens
)) == 0)
466 return src_reg(PROGRAM_STATE_VAR
, idx
);
469 idx
= _mesa_add_state_reference( paramList
, tokens
);
471 return src_reg(PROGRAM_STATE_VAR
, idx
);
475 static struct prog_src_register
search_or_add_const4f( struct brw_wm_compile
*c
,
481 struct gl_program_parameter_list
*paramList
= c
->fp
->program
.Base
.Parameters
;
491 /* Have to search, otherwise multiple compilations will each grow
492 * the parameter list.
494 for (idx
= 0; idx
< paramList
->NumParameters
; idx
++) {
495 if (paramList
->Parameters
[idx
].Type
== PROGRAM_CONSTANT
&&
496 memcmp(paramList
->ParameterValues
[idx
], values
, sizeof(values
)) == 0)
498 /* XXX: this mimics the mesa bug which puts all constants and
499 * parameters into the "PROGRAM_STATE_VAR" category:
501 return src_reg(PROGRAM_STATE_VAR
, idx
);
504 idx
= _mesa_add_unnamed_constant( paramList
, values
, 4, &swizzle
);
505 assert(swizzle
== SWIZZLE_NOOP
); /* Need to handle swizzle in reg setup */
506 return src_reg(PROGRAM_STATE_VAR
, idx
);
511 /***********************************************************************
512 * Expand various instructions here to simpler forms.
514 static void precalc_dst( struct brw_wm_compile
*c
,
515 const struct prog_instruction
*inst
)
517 struct prog_src_register src0
= inst
->SrcReg
[0];
518 struct prog_src_register src1
= inst
->SrcReg
[1];
519 struct prog_dst_register dst
= inst
->DstReg
;
521 if (dst
.WriteMask
& BRW_WRITEMASK_Y
) {
522 /* dst.y = mul src0.y, src1.y
526 dst_mask(dst
, BRW_WRITEMASK_Y
),
533 if (dst
.WriteMask
& BRW_WRITEMASK_XZ
) {
534 struct prog_instruction
*swz
;
535 GLuint z
= GET_SWZ(src0
.Swizzle
, Z
);
537 /* dst.xz = swz src0.1zzz
541 dst_mask(dst
, BRW_WRITEMASK_XZ
),
543 src_swizzle(src0
, SWIZZLE_ONE
, z
, z
, z
),
546 /* Avoid letting negation flag of src0 affect our 1 constant. */
547 swz
->SrcReg
[0].Negate
&= ~NEGATE_X
;
549 if (dst
.WriteMask
& BRW_WRITEMASK_W
) {
550 /* dst.w = mov src1.w
554 dst_mask(dst
, BRW_WRITEMASK_W
),
563 static void precalc_lit( struct brw_wm_compile
*c
,
564 const struct prog_instruction
*inst
)
566 struct prog_src_register src0
= inst
->SrcReg
[0];
567 struct prog_dst_register dst
= inst
->DstReg
;
569 if (dst
.WriteMask
& BRW_WRITEMASK_XW
) {
570 struct prog_instruction
*swz
;
572 /* dst.xw = swz src0.1111
576 dst_mask(dst
, BRW_WRITEMASK_XW
),
578 src_swizzle1(src0
, SWIZZLE_ONE
),
581 /* Avoid letting the negation flag of src0 affect our 1 constant. */
582 swz
->SrcReg
[0].Negate
= NEGATE_NONE
;
585 if (dst
.WriteMask
& BRW_WRITEMASK_YZ
) {
588 dst_mask(dst
, BRW_WRITEMASK_YZ
),
598 * Some TEX instructions require extra code, cube map coordinate
599 * normalization, or coordinate scaling for RECT textures, etc.
600 * This function emits those extra instructions and the TEX
601 * instruction itself.
603 static void precalc_tex( struct brw_wm_compile
*c
,
604 const struct prog_instruction
*inst
)
606 struct prog_src_register coord
;
607 struct prog_dst_register tmpcoord
;
608 const GLuint unit
= c
->fp
->program
.Base
.SamplerUnits
[inst
->TexSrcUnit
];
610 assert(unit
< BRW_MAX_TEX_UNIT
);
612 if (inst
->TexSrcTarget
== TEXTURE_CUBE_INDEX
) {
613 struct prog_instruction
*out
;
614 struct prog_dst_register tmp0
= get_temp(c
);
615 struct prog_src_register tmp0src
= src_reg_from_dst(tmp0
);
616 struct prog_dst_register tmp1
= get_temp(c
);
617 struct prog_src_register tmp1src
= src_reg_from_dst(tmp1
);
618 struct prog_src_register src0
= inst
->SrcReg
[0];
620 /* find longest component of coord vector and normalize it */
621 tmpcoord
= get_temp(c
);
622 coord
= src_reg_from_dst(tmpcoord
);
624 /* tmpcoord = src0 (i.e.: coord = src0) */
625 out
= emit_op(c
, TGSI_OPCODE_MOV
,
631 out
->SrcReg
[0].Negate
= NEGATE_NONE
;
632 out
->SrcReg
[0].Abs
= 1;
634 /* tmp0 = MAX(coord.X, coord.Y) */
635 emit_op(c
, TGSI_OPCODE_MAX
,
638 src_swizzle1(coord
, X
),
639 src_swizzle1(coord
, Y
),
642 /* tmp1 = MAX(tmp0, coord.Z) */
643 emit_op(c
, TGSI_OPCODE_MAX
,
647 src_swizzle1(coord
, Z
),
650 /* tmp0 = 1 / tmp1 */
651 emit_op(c
, TGSI_OPCODE_RCP
,
652 dst_mask(tmp0
, BRW_WRITEMASK_X
),
658 /* tmpCoord = src0 * tmp0 */
659 emit_op(c
, TGSI_OPCODE_MUL
,
663 src_swizzle1(tmp0src
, SWIZZLE_X
),
666 release_temp(c
, tmp0
);
667 release_temp(c
, tmp1
);
669 else if (inst
->TexSrcTarget
== TEXTURE_RECT_INDEX
) {
670 struct prog_src_register scale
=
671 search_or_add_param5( c
,
677 tmpcoord
= get_temp(c
);
679 /* coord.xy = MUL inst->SrcReg[0], { 1/width, 1/height }
693 coord
= src_reg_from_dst(tmpcoord
);
696 coord
= inst
->SrcReg
[0];
699 /* Need to emit YUV texture conversions by hand. Probably need to
700 * do this here - the alternative is in brw_wm_emit.c, but the
701 * conversion requires allocating a temporary variable which we
702 * don't have the facility to do that late in the compilation.
704 if (c
->key
.yuvtex_mask
& (1 << unit
)) {
705 /* convert ycbcr to RGBA */
706 GLboolean swap_uv
= c
->key
.yuvtex_swap_mask
& (1<<unit
);
709 CONST C0 = { -.5, -.0625, -.5, 1.164 }
710 CONST C1 = { 1.596, -0.813, 2.018, -.391 }
712 UYV.xyz = ADD UYV, C0
713 UYV.y = MUL UYV.y, C0.w
715 RGB.xyz = MAD UYV.zzx, C1, UYV.y
717 RGB.xyz = MAD UYV.xxz, C1, UYV.y
718 RGB.y = MAD UYV.z, C1.w, RGB.y
720 struct prog_dst_register dst
= inst
->DstReg
;
721 struct prog_dst_register tmp
= get_temp(c
);
722 struct prog_src_register tmpsrc
= src_reg_from_dst(tmp
);
723 struct prog_src_register C0
= search_or_add_const4f( c
, -.5, -.0625, -.5, 1.164 );
724 struct prog_src_register C1
= search_or_add_const4f( c
, 1.596, -0.813, 2.018, -.391 );
739 /* tmp.xyz = ADD TMP, C0
743 dst_mask(tmp
, BRW_WRITEMASK_XYZ
),
749 /* YUV.y = MUL YUV.y, C0.w
754 dst_mask(tmp
, BRW_WRITEMASK_Y
),
762 * RGB.xyz = MAD YUV.zzx, C1, YUV.y
764 * RGB.xyz = MAD YUV.xxz, C1, YUV.y
769 dst_mask(dst
, BRW_WRITEMASK_XYZ
),
771 swap_uv
?src_swizzle(tmpsrc
, Z
,Z
,X
,X
):src_swizzle(tmpsrc
, X
,X
,Z
,Z
),
773 src_swizzle1(tmpsrc
, Y
));
775 /* RGB.y = MAD YUV.z, C1.w, RGB.y
779 dst_mask(dst
, BRW_WRITEMASK_Y
),
781 src_swizzle1(tmpsrc
, Z
),
783 src_swizzle1(src_reg_from_dst(dst
), Y
));
785 release_temp(c
, tmp
);
788 /* ordinary RGBA tex instruction */
801 /* For GL_EXT_texture_swizzle: */
802 if (c
->key
.tex_swizzles
[unit
] != SWIZZLE_NOOP
) {
803 /* swizzle the result of the TEX instruction */
804 struct prog_src_register tmpsrc
= src_reg_from_dst(inst
->DstReg
);
805 emit_op(c
, TGSI_OPCODE_MOV
,
807 SATURATE_OFF
, /* saturate already done above */
808 src_swizzle4(tmpsrc
, c
->key
.tex_swizzles
[unit
]),
813 if ((inst
->TexSrcTarget
== TEXTURE_RECT_INDEX
) ||
814 (inst
->TexSrcTarget
== TEXTURE_CUBE_INDEX
))
815 release_temp(c
, tmpcoord
);
820 * Check if the given TXP instruction really needs the divide-by-W step.
822 static GLboolean
projtex( struct brw_wm_compile
*c
,
823 const struct prog_instruction
*inst
)
825 const struct prog_src_register src
= inst
->SrcReg
[0];
828 assert(inst
->Opcode
== TGSI_OPCODE_TXP
);
830 /* Only try to detect the simplest cases. Could detect (later)
831 * cases where we are trying to emit code like RCP {1.0}, MUL x,
834 * More complex cases than this typically only arise from
835 * user-provided fragment programs anyway:
837 if (inst
->TexSrcTarget
== TEXTURE_CUBE_INDEX
)
838 retVal
= GL_FALSE
; /* ut2004 gun rendering !?! */
839 else if (src
.File
== PROGRAM_INPUT
&&
840 GET_SWZ(src
.Swizzle
, W
) == W
&&
841 (c
->key
.proj_attrib_mask
& (1 << src
.Index
)) == 0)
853 static void precalc_txp( struct brw_wm_compile
*c
,
854 const struct prog_instruction
*inst
)
856 struct prog_src_register src0
= inst
->SrcReg
[0];
858 if (projtex(c
, inst
)) {
859 struct prog_dst_register tmp
= get_temp(c
);
860 struct prog_instruction tmp_inst
;
862 /* tmp0.w = RCP inst.arg[0][3]
866 dst_mask(tmp
, BRW_WRITEMASK_W
),
868 src_swizzle1(src0
, GET_SWZ(src0
.Swizzle
, W
)),
872 /* tmp0.xyz = MUL inst.arg[0], tmp0.wwww
876 dst_mask(tmp
, BRW_WRITEMASK_XYZ
),
879 src_swizzle1(src_reg_from_dst(tmp
), W
),
882 /* dst = precalc(TEX tmp0)
885 tmp_inst
.SrcReg
[0] = src_reg_from_dst(tmp
);
886 precalc_tex(c
, &tmp_inst
);
888 release_temp(c
, tmp
);
892 /* dst = precalc(TEX src0)
894 precalc_tex(c
, inst
);
900 static void emit_fb_write( struct brw_wm_compile
*c
)
902 struct prog_src_register payload_r0_depth
= src_reg(PROGRAM_PAYLOAD
, PAYLOAD_DEPTH
);
903 struct prog_src_register outdepth
= src_reg(PROGRAM_OUTPUT
, FRAG_RESULT_DEPTH
);
904 struct prog_src_register outcolor
;
907 struct prog_instruction
*inst
, *last_inst
;
908 struct brw_context
*brw
= c
->func
.brw
;
910 /* The inst->Aux field is used for FB write target and the EOT marker */
912 if (brw
->state
.nr_color_regions
> 1) {
913 for (i
= 0 ; i
< brw
->state
.nr_color_regions
; i
++) {
914 outcolor
= src_reg(PROGRAM_OUTPUT
, FRAG_RESULT_DATA0
+ i
);
915 last_inst
= inst
= emit_op(c
,
916 WM_FB_WRITE
, dst_mask(dst_undef(),0), 0,
917 outcolor
, payload_r0_depth
, outdepth
);
919 if (c
->fp_fragcolor_emitted
) {
920 outcolor
= src_reg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
921 last_inst
= inst
= emit_op(c
, WM_FB_WRITE
, dst_mask(dst_undef(),0),
922 0, outcolor
, payload_r0_depth
, outdepth
);
926 last_inst
->Aux
|= 1; //eot
929 /* if gl_FragData[0] is written, use it, else use gl_FragColor */
930 if (c
->fp
->program
.Base
.OutputsWritten
& (1 << FRAG_RESULT_DATA0
))
931 outcolor
= src_reg(PROGRAM_OUTPUT
, FRAG_RESULT_DATA0
);
933 outcolor
= src_reg(PROGRAM_OUTPUT
, FRAG_RESULT_COLOR
);
935 inst
= emit_op(c
, WM_FB_WRITE
, dst_mask(dst_undef(),0),
936 0, outcolor
, payload_r0_depth
, outdepth
);
937 inst
->Aux
= 1|(0<<1);
944 /***********************************************************************
945 * Emit INTERP instructions ahead of first use of each attrib.
948 static void validate_src_regs( struct brw_wm_compile
*c
,
949 const struct prog_instruction
*inst
)
951 GLuint nr_args
= brw_wm_nr_args( inst
->Opcode
);
954 for (i
= 0; i
< nr_args
; i
++) {
955 if (inst
->SrcReg
[i
].File
== PROGRAM_INPUT
) {
956 GLuint idx
= inst
->SrcReg
[i
].Index
;
957 if (!(c
->fp_interp_emitted
& (1<<idx
))) {
959 c
->fp_interp_emitted
|= 1<<idx
;
965 static void validate_dst_regs( struct brw_wm_compile
*c
,
966 const struct prog_instruction
*inst
)
968 if (inst
->DstReg
.File
== PROGRAM_OUTPUT
) {
969 GLuint idx
= inst
->DstReg
.Index
;
970 if (idx
== FRAG_RESULT_COLOR
)
971 c
->fp_fragcolor_emitted
= 1;
975 static void print_insns( const struct prog_instruction
*insn
,
979 for (i
= 0; i
< nr
; i
++, insn
++) {
980 debug_printf("%3d: ", i
);
981 if (insn
->Opcode
< MAX_OPCODE
)
982 _mesa_print_instruction(insn
);
983 else if (insn
->Opcode
< MAX_WM_OPCODE
) {
984 GLuint idx
= insn
->Opcode
- MAX_OPCODE
;
986 _mesa_print_alu_instruction(insn
,
987 wm_opcode_strings
[idx
],
991 debug_printf("965 Opcode %d\n", insn
->Opcode
);
997 * Initial pass for fragment program code generation.
998 * This function is used by both the GLSL and non-GLSL paths.
1000 void brw_wm_pass_fp( struct brw_wm_compile
*c
)
1002 struct brw_fragment_program
*fp
= c
->fp
;
1005 if (BRW_DEBUG
& DEBUG_WM
) {
1006 debug_printf("pre-fp:\n");
1007 _mesa_print_program(&fp
->program
.Base
);
1011 c
->pixel_xy
= src_undef();
1012 c
->delta_xy
= src_undef();
1013 c
->pixel_w
= src_undef();
1015 c
->fp
->tex_units_used
= 0x0;
1017 /* Emit preamble instructions. This is where special instructions such as
1018 * WM_CINTERP, WM_LINTERP, WM_PINTERP and WM_WPOSXY are emitted to
1019 * compute shader inputs from varying vars.
1021 for (insn
= 0; insn
< fp
->program
.Base
.NumInstructions
; insn
++) {
1022 const struct prog_instruction
*inst
= &fp
->program
.Base
.Instructions
[insn
];
1023 validate_src_regs(c
, inst
);
1024 validate_dst_regs(c
, inst
);
1027 /* Loop over all instructions doing assorted simplifications and
1030 for (insn
= 0; insn
< fp
->program
.Base
.NumInstructions
; insn
++) {
1031 const struct prog_instruction
*inst
= &fp
->program
.Base
.Instructions
[insn
];
1032 struct prog_instruction
*out
;
1034 /* Check for INPUT values, emit INTERP instructions where
1038 switch (inst
->Opcode
) {
1039 case TGSI_OPCODE_ABS
:
1040 out
= emit_insn(c
, inst
);
1041 out
->Opcode
= TGSI_OPCODE_MOV
;
1042 out
->SrcReg
[0].Negate
= NEGATE_NONE
;
1043 out
->SrcReg
[0].Abs
= 1;
1046 case TGSI_OPCODE_SUB
:
1047 out
= emit_insn(c
, inst
);
1048 out
->Opcode
= TGSI_OPCODE_ADD
;
1049 out
->SrcReg
[1].Negate
^= NEGATE_XYZW
;
1052 case TGSI_OPCODE_SCS
:
1053 out
= emit_insn(c
, inst
);
1054 /* This should probably be done in the parser.
1056 out
->DstReg
.WriteMask
&= BRW_WRITEMASK_XY
;
1059 case TGSI_OPCODE_DST
:
1060 precalc_dst(c
, inst
);
1063 case TGSI_OPCODE_LIT
:
1064 precalc_lit(c
, inst
);
1067 case TGSI_OPCODE_TEX
:
1068 precalc_tex(c
, inst
);
1071 case TGSI_OPCODE_TXP
:
1072 precalc_txp(c
, inst
);
1075 case TGSI_OPCODE_TXB
:
1076 out
= emit_insn(c
, inst
);
1077 out
->TexSrcUnit
= fp
->program
.Base
.SamplerUnits
[inst
->TexSrcUnit
];
1078 assert(out
->TexSrcUnit
< BRW_MAX_TEX_UNIT
);
1081 case TGSI_OPCODE_XPD
:
1082 out
= emit_insn(c
, inst
);
1083 /* This should probably be done in the parser.
1085 out
->DstReg
.WriteMask
&= BRW_WRITEMASK_XYZ
;
1088 case TGSI_OPCODE_KIL
:
1089 out
= emit_insn(c
, inst
);
1090 /* This should probably be done in the parser.
1092 out
->DstReg
.WriteMask
= 0;
1094 case TGSI_OPCODE_END
:
1098 if (brw_wm_is_scalar_result(inst
->Opcode
))
1099 emit_scalar_insn(c
, inst
);
1106 if (BRW_DEBUG
& DEBUG_WM
) {
1107 debug_printf("pass_fp:\n");
1108 print_insns( c
->prog_instructions
, c
->nr_fp_insns
);