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 "brw_context.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
)
93 case TEXTURE_1D_INDEX
:
95 case TEXTURE_2D_INDEX
:
97 case TEXTURE_3D_INDEX
:
99 case TEXTURE_CUBE_INDEX
:
100 return WRITEMASK_XYZ
;
101 case TEXTURE_RECT_INDEX
:
108 /* Step two: Basically this is dead code elimination.
110 * Iterate backwards over instructions, noting which values
111 * contribute to the final result. Adjust writemasks to only
112 * calculate these values.
114 void brw_wm_pass1( struct brw_wm_compile
*c
)
118 for (insn
= c
->nr_insns
-1; insn
>= 0; insn
--) {
119 struct brw_wm_instruction
*inst
= &c
->instruction
[insn
];
121 GLuint read0
, read1
, read2
;
123 if (inst
->opcode
== OPCODE_KIL
) {
124 track_arg(c
, inst
, 0, WRITEMASK_XYZW
); /* All args contribute to final */
128 if (inst
->opcode
== WM_FB_WRITE
) {
129 track_arg(c
, inst
, 0, WRITEMASK_XYZW
);
130 track_arg(c
, inst
, 1, WRITEMASK_XYZW
);
131 if (c
->key
.source_depth_to_render_target
&&
132 c
->key
.computes_depth
)
133 track_arg(c
, inst
, 2, WRITEMASK_Z
);
135 track_arg(c
, inst
, 2, 0);
139 /* Lookup all the registers which were written by this
140 * instruction and get a mask of those that contribute to the output:
142 writemask
= get_tracked_mask(c
, inst
);
145 for (arg
= 0; arg
< 3; arg
++)
146 track_arg(c
, inst
, arg
, 0);
154 /* Mark all inputs which contribute to the marked outputs:
156 switch (inst
->opcode
) {
196 if (writemask
& WRITEMASK_X
) read0
|= WRITEMASK_YZ
;
197 if (writemask
& WRITEMASK_Y
) read0
|= WRITEMASK_XZ
;
198 if (writemask
& WRITEMASK_Z
) read0
|= WRITEMASK_XY
;
221 read0
= get_texcoord_mask(inst
->tex_idx
);
223 if (inst
->tex_shadow
)
224 read0
|= WRITEMASK_Z
;
228 /* Shadow ignored for txb.
230 read0
= get_texcoord_mask(inst
->tex_idx
) | WRITEMASK_W
;
234 read0
= writemask
& WRITEMASK_XY
;
238 read0
= writemask
& WRITEMASK_XY
;
244 read1
= WRITEMASK_XY
;
249 read1
= WRITEMASK_XY
;
253 read0
= WRITEMASK_X
; /* interpolant */
254 read1
= WRITEMASK_XY
; /* deltas */
255 read2
= WRITEMASK_W
; /* pixel w */
259 read0
= WRITEMASK_XY
;
260 read1
= WRITEMASK_XY
;
264 read0
= WRITEMASK_XYZ
;
265 read1
= WRITEMASK_XYZ
;
269 read0
= WRITEMASK_XYZ
;
270 read1
= WRITEMASK_XYZW
;
274 read0
= WRITEMASK_XYZW
;
275 read1
= WRITEMASK_XYZW
;
279 read0
= WRITEMASK_XYW
;
289 track_arg(c
, inst
, 0, read0
);
290 track_arg(c
, inst
, 1, read1
);
291 track_arg(c
, inst
, 2, read2
);
294 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
295 brw_wm_print_program(c
, "pass1");