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
:
97 case TEXTURE_EXTERNAL_INDEX
:
99 case TEXTURE_3D_INDEX
:
100 case TEXTURE_2D_ARRAY_INDEX
:
101 return WRITEMASK_XYZ
;
102 case TEXTURE_CUBE_INDEX
:
103 return WRITEMASK_XYZ
;
104 case TEXTURE_RECT_INDEX
:
111 /* Step two: Basically this is dead code elimination.
113 * Iterate backwards over instructions, noting which values
114 * contribute to the final result. Adjust writemasks to only
115 * calculate these values.
117 void brw_wm_pass1( struct brw_wm_compile
*c
)
121 for (insn
= c
->nr_insns
-1; insn
>= 0; insn
--) {
122 struct brw_wm_instruction
*inst
= &c
->instruction
[insn
];
124 GLuint read0
, read1
, read2
;
126 if (inst
->opcode
== OPCODE_KIL
) {
127 track_arg(c
, inst
, 0, WRITEMASK_XYZW
); /* All args contribute to final */
131 if (inst
->opcode
== WM_FB_WRITE
) {
132 track_arg(c
, inst
, 0, WRITEMASK_XYZW
);
133 track_arg(c
, inst
, 1, WRITEMASK_XYZW
);
134 if (c
->source_depth_to_render_target
&& c
->computes_depth
)
135 track_arg(c
, inst
, 2, WRITEMASK_Z
);
137 track_arg(c
, inst
, 2, 0);
141 /* Lookup all the registers which were written by this
142 * instruction and get a mask of those that contribute to the output:
144 writemask
= get_tracked_mask(c
, inst
);
147 for (arg
= 0; arg
< 3; arg
++)
148 track_arg(c
, inst
, arg
, 0);
156 /* Mark all inputs which contribute to the marked outputs:
158 switch (inst
->opcode
) {
198 if (writemask
& WRITEMASK_X
) read0
|= WRITEMASK_YZ
;
199 if (writemask
& WRITEMASK_Y
) read0
|= WRITEMASK_XZ
;
200 if (writemask
& WRITEMASK_Z
) read0
|= WRITEMASK_XY
;
223 read0
= get_texcoord_mask(inst
->tex_idx
);
225 if (inst
->tex_shadow
)
226 read0
|= WRITEMASK_Z
;
230 /* Shadow ignored for txb.
232 read0
= get_texcoord_mask(inst
->tex_idx
) | WRITEMASK_W
;
236 read0
= writemask
& WRITEMASK_XY
;
240 read0
= writemask
& WRITEMASK_XY
;
246 read1
= WRITEMASK_XY
;
251 read1
= WRITEMASK_XY
;
255 read0
= WRITEMASK_X
; /* interpolant */
256 read1
= WRITEMASK_XY
; /* deltas */
257 read2
= WRITEMASK_W
; /* pixel w */
261 read0
= WRITEMASK_XY
;
262 read1
= WRITEMASK_XY
;
266 read0
= WRITEMASK_XYZ
;
267 read1
= WRITEMASK_XYZ
;
271 read0
= WRITEMASK_XYZ
;
272 read1
= WRITEMASK_XYZW
;
276 read0
= WRITEMASK_XYZW
;
277 read1
= WRITEMASK_XYZW
;
281 read0
= WRITEMASK_XYW
;
290 track_arg(c
, inst
, 0, read0
);
291 track_arg(c
, inst
, 1, read1
);
292 track_arg(c
, inst
, 2, read2
);
295 if (unlikely(INTEL_DEBUG
& DEBUG_WM
)) {
296 brw_wm_print_program(c
, "pass1");