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
:
96 case TEXTURE_1D_ARRAY_INDEX
:
98 case TEXTURE_3D_INDEX
:
99 case TEXTURE_2D_ARRAY_INDEX
:
100 return WRITEMASK_XYZ
;
101 case TEXTURE_CUBE_INDEX
:
102 return WRITEMASK_XYZ
;
103 case TEXTURE_RECT_INDEX
:
110 /* Step two: Basically this is dead code elimination.
112 * Iterate backwards over instructions, noting which values
113 * contribute to the final result. Adjust writemasks to only
114 * calculate these values.
116 void brw_wm_pass1( struct brw_wm_compile
*c
)
120 for (insn
= c
->nr_insns
-1; insn
>= 0; insn
--) {
121 struct brw_wm_instruction
*inst
= &c
->instruction
[insn
];
123 GLuint read0
, read1
, read2
;
125 if (inst
->opcode
== OPCODE_KIL
) {
126 track_arg(c
, inst
, 0, WRITEMASK_XYZW
); /* All args contribute to final */
130 if (inst
->opcode
== WM_FB_WRITE
) {
131 track_arg(c
, inst
, 0, WRITEMASK_XYZW
);
132 track_arg(c
, inst
, 1, WRITEMASK_XYZW
);
133 if (c
->source_depth_to_render_target
&& c
->computes_depth
)
134 track_arg(c
, inst
, 2, WRITEMASK_Z
);
136 track_arg(c
, inst
, 2, 0);
140 /* Lookup all the registers which were written by this
141 * instruction and get a mask of those that contribute to the output:
143 writemask
= get_tracked_mask(c
, inst
);
146 for (arg
= 0; arg
< 3; arg
++)
147 track_arg(c
, inst
, arg
, 0);
155 /* Mark all inputs which contribute to the marked outputs:
157 switch (inst
->opcode
) {
197 if (writemask
& WRITEMASK_X
) read0
|= WRITEMASK_YZ
;
198 if (writemask
& WRITEMASK_Y
) read0
|= WRITEMASK_XZ
;
199 if (writemask
& WRITEMASK_Z
) read0
|= WRITEMASK_XY
;
222 read0
= get_texcoord_mask(inst
->tex_idx
);
224 if (inst
->tex_shadow
)
225 read0
|= WRITEMASK_Z
;
229 /* Shadow ignored for txb.
231 read0
= get_texcoord_mask(inst
->tex_idx
) | WRITEMASK_W
;
235 read0
= writemask
& WRITEMASK_XY
;
239 read0
= writemask
& WRITEMASK_XY
;
245 read1
= WRITEMASK_XY
;
250 read1
= WRITEMASK_XY
;
254 read0
= WRITEMASK_X
; /* interpolant */
255 read1
= WRITEMASK_XY
; /* deltas */
256 read2
= WRITEMASK_W
; /* pixel w */
260 read0
= WRITEMASK_XY
;
261 read1
= WRITEMASK_XY
;
265 read0
= WRITEMASK_XYZ
;
266 read1
= WRITEMASK_XYZ
;
270 read0
= WRITEMASK_XYZ
;
271 read1
= WRITEMASK_XYZW
;
275 read0
= WRITEMASK_XYZW
;
276 read1
= WRITEMASK_XYZW
;
280 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");