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>
34 #include "brw_debug.h"
37 static GLuint
get_tracked_mask(struct brw_wm_compile
*c
,
38 struct brw_wm_instruction
*inst
)
41 for (i
= 0; i
< 4; i
++) {
42 if (inst
->writemask
& (1<<i
)) {
43 if (!inst
->dst
[i
]->contributes_to_output
) {
44 inst
->writemask
&= ~(1<<i
);
50 return inst
->writemask
;
53 /* Remove a reference from a value's usage chain.
55 static void unlink_ref(struct brw_wm_ref
*ref
)
57 struct brw_wm_value
*value
= ref
->value
;
59 if (ref
== value
->lastuse
) {
60 value
->lastuse
= ref
->prevuse
;
63 struct brw_wm_ref
*i
= value
->lastuse
;
64 while (i
->prevuse
!= ref
) i
= i
->prevuse
;
65 i
->prevuse
= ref
->prevuse
;
69 static void track_arg(struct brw_wm_compile
*c
,
70 struct brw_wm_instruction
*inst
,
76 for (i
= 0; i
< 4; i
++) {
77 struct brw_wm_ref
*ref
= inst
->src
[arg
][i
];
79 if (readmask
& (1<<i
)) {
80 ref
->value
->contributes_to_output
= 1;
84 inst
->src
[arg
][i
] = NULL
;
90 static GLuint
get_texcoord_mask( GLuint tex_idx
)
94 return BRW_WRITEMASK_X
;
96 case TGSI_TEXTURE_RECT
:
97 return BRW_WRITEMASK_XY
;
99 return BRW_WRITEMASK_XYZ
;
100 case TGSI_TEXTURE_CUBE
:
101 return BRW_WRITEMASK_XYZ
;
103 case TGSI_TEXTURE_SHADOW1D
:
104 return BRW_WRITEMASK_XZ
;
105 case TGSI_TEXTURE_SHADOW2D
:
106 case TGSI_TEXTURE_SHADOWRECT
:
107 return BRW_WRITEMASK_XYZ
;
115 /* Step two: Basically this is dead code elimination.
117 * Iterate backwards over instructions, noting which values
118 * contribute to the final result. Adjust writemasks to only
119 * calculate these values.
121 void brw_wm_pass1( struct brw_wm_compile
*c
)
125 for (insn
= c
->nr_insns
-1; insn
>= 0; insn
--) {
126 struct brw_wm_instruction
*inst
= &c
->instruction
[insn
];
128 GLuint read0
, read1
, read2
;
130 if (inst
->opcode
== TGSI_OPCODE_KIL
) {
131 track_arg(c
, inst
, 0, BRW_WRITEMASK_XYZW
); /* All args contribute to final */
135 if (inst
->opcode
== WM_FB_WRITE
) {
136 track_arg(c
, inst
, 0, BRW_WRITEMASK_XYZW
);
137 track_arg(c
, inst
, 1, BRW_WRITEMASK_XYZW
);
138 if (c
->key
.source_depth_to_render_target
&&
139 c
->key
.computes_depth
)
140 track_arg(c
, inst
, 2, BRW_WRITEMASK_Z
);
142 track_arg(c
, inst
, 2, 0);
146 /* Lookup all the registers which were written by this
147 * instruction and get a mask of those that contribute to the output:
149 writemask
= get_tracked_mask(c
, inst
);
152 for (arg
= 0; arg
< 3; arg
++)
153 track_arg(c
, inst
, arg
, 0);
161 /* Mark all inputs which contribute to the marked outputs:
163 switch (inst
->opcode
) {
164 case TGSI_OPCODE_ABS
:
165 case TGSI_OPCODE_FLR
:
166 case TGSI_OPCODE_FRC
:
167 case TGSI_OPCODE_MOV
:
168 case TGSI_OPCODE_TRUNC
:
172 case TGSI_OPCODE_SUB
:
173 case TGSI_OPCODE_SLT
:
174 case TGSI_OPCODE_SLE
:
175 case TGSI_OPCODE_SGE
:
176 case TGSI_OPCODE_SGT
:
177 case TGSI_OPCODE_SEQ
:
178 case TGSI_OPCODE_SNE
:
179 case TGSI_OPCODE_ADD
:
180 case TGSI_OPCODE_MAX
:
181 case TGSI_OPCODE_MIN
:
182 case TGSI_OPCODE_MUL
:
187 case TGSI_OPCODE_DDX
:
188 case TGSI_OPCODE_DDY
:
192 case TGSI_OPCODE_MAD
:
193 case TGSI_OPCODE_CMP
:
194 case TGSI_OPCODE_LRP
:
200 case TGSI_OPCODE_XPD
:
201 if (writemask
& BRW_WRITEMASK_X
) read0
|= BRW_WRITEMASK_YZ
;
202 if (writemask
& BRW_WRITEMASK_Y
) read0
|= BRW_WRITEMASK_XZ
;
203 if (writemask
& BRW_WRITEMASK_Z
) read0
|= BRW_WRITEMASK_XY
;
207 case TGSI_OPCODE_COS
:
208 case TGSI_OPCODE_EX2
:
209 case TGSI_OPCODE_LG2
:
210 case TGSI_OPCODE_RCP
:
211 case TGSI_OPCODE_RSQ
:
212 case TGSI_OPCODE_SIN
:
213 case TGSI_OPCODE_SCS
:
216 read0
= BRW_WRITEMASK_X
;
219 case TGSI_OPCODE_POW
:
220 read0
= BRW_WRITEMASK_X
;
221 read1
= BRW_WRITEMASK_X
;
224 case TGSI_OPCODE_TEX
:
225 case TGSI_OPCODE_TXP
:
226 read0
= get_texcoord_mask(inst
->target
);
229 case TGSI_OPCODE_TXB
:
230 read0
= get_texcoord_mask(inst
->target
) | BRW_WRITEMASK_W
;
234 read0
= writemask
& BRW_WRITEMASK_XY
;
238 read0
= writemask
& BRW_WRITEMASK_XY
;
239 read1
= BRW_WRITEMASK_X
;
243 read0
= BRW_WRITEMASK_X
;
244 read1
= BRW_WRITEMASK_XY
;
248 read0
= BRW_WRITEMASK_X
;
249 read1
= BRW_WRITEMASK_XY
;
253 read0
= BRW_WRITEMASK_X
; /* interpolant */
254 read1
= BRW_WRITEMASK_XY
; /* deltas */
255 read2
= BRW_WRITEMASK_W
; /* pixel w */
258 case TGSI_OPCODE_DP3
:
259 read0
= BRW_WRITEMASK_XYZ
;
260 read1
= BRW_WRITEMASK_XYZ
;
263 case TGSI_OPCODE_DPH
:
264 read0
= BRW_WRITEMASK_XYZ
;
265 read1
= BRW_WRITEMASK_XYZW
;
268 case TGSI_OPCODE_DP4
:
269 read0
= BRW_WRITEMASK_XYZW
;
270 read1
= BRW_WRITEMASK_XYZW
;
273 case TGSI_OPCODE_LIT
:
274 read0
= BRW_WRITEMASK_XYW
;
277 case TGSI_OPCODE_DST
:
279 case TGSI_OPCODE_KILP
:
284 track_arg(c
, inst
, 0, read0
);
285 track_arg(c
, inst
, 1, read1
);
286 track_arg(c
, inst
, 2, read2
);
289 if (BRW_DEBUG
& DEBUG_WM
) {
290 brw_wm_print_program(c
, "pass1");