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"
36 #include "arbprogparse.h"
37 #include "program_instruction.h"
40 static GLuint
get_tracked_mask(struct brw_wm_compile
*c
,
41 struct brw_wm_instruction
*inst
)
44 for (i
= 0; i
< 4; i
++) {
45 if (inst
->writemask
& (1<<i
)) {
46 if (!inst
->dst
[i
]->contributes_to_output
) {
47 inst
->writemask
&= ~(1<<i
);
53 return inst
->writemask
;
56 /* Remove a reference from a value's usage chain.
58 static void unlink_ref(struct brw_wm_ref
*ref
)
60 struct brw_wm_value
*value
= ref
->value
;
62 if (ref
== value
->lastuse
) {
63 value
->lastuse
= ref
->prevuse
;
65 struct brw_wm_ref
*i
= value
->lastuse
;
66 while (i
->prevuse
!= ref
) i
= i
->prevuse
;
67 i
->prevuse
= ref
->prevuse
;
71 static void track_arg(struct brw_wm_compile
*c
,
72 struct brw_wm_instruction
*inst
,
78 for (i
= 0; i
< 4; i
++) {
79 struct brw_wm_ref
*ref
= inst
->src
[arg
][i
];
81 if (readmask
& (1<<i
))
82 ref
->value
->contributes_to_output
= 1;
85 inst
->src
[arg
][i
] = NULL
;
91 static GLuint
get_texcoord_mask( GLuint tex_idx
)
94 case TEXTURE_1D_INDEX
: return WRITEMASK_X
;
95 case TEXTURE_2D_INDEX
: return WRITEMASK_XY
;
96 case TEXTURE_3D_INDEX
: return WRITEMASK_XYZ
;
97 case TEXTURE_CUBE_INDEX
: return WRITEMASK_XYZ
;
98 case TEXTURE_RECT_INDEX
: return WRITEMASK_XY
;
103 /* Step two: Basically this is dead code elimination.
105 * Iterate backwards over instructions, noting which values
106 * contribute to the final result. Adjust writemasks to only
107 * calculate these values.
109 void brw_wm_pass1( struct brw_wm_compile
*c
)
113 for (insn
= c
->nr_insns
-1; insn
>= 0; insn
--) {
114 struct brw_wm_instruction
*inst
= &c
->instruction
[insn
];
116 GLuint read0
, read1
, read2
;
118 if (inst
->opcode
== OPCODE_KIL
) {
119 track_arg(c
, inst
, 0, WRITEMASK_XYZW
); /* All args contribute to final */
123 if (inst
->opcode
== WM_FB_WRITE
) {
124 track_arg(c
, inst
, 0, WRITEMASK_XYZW
);
125 track_arg(c
, inst
, 1, WRITEMASK_XYZW
);
126 if (c
->key
.source_depth_to_render_target
&&
127 c
->key
.computes_depth
)
128 track_arg(c
, inst
, 2, WRITEMASK_Z
);
130 track_arg(c
, inst
, 2, 0);
134 /* Lookup all the registers which were written by this
135 * instruction and get a mask of those that contribute to the output:
137 writemask
= get_tracked_mask(c
, inst
);
140 for (arg
= 0; arg
< 3; arg
++)
141 track_arg(c
, inst
, arg
, 0);
149 /* Mark all inputs which contribute to the marked outputs:
151 switch (inst
->opcode
) {
179 if (writemask
& WRITEMASK_X
) read0
|= WRITEMASK_YZ
;
180 if (writemask
& WRITEMASK_Y
) read0
|= WRITEMASK_XZ
;
181 if (writemask
& WRITEMASK_Z
) read0
|= WRITEMASK_XY
;
203 read0
= get_texcoord_mask(inst
->tex_idx
);
205 if (c
->key
.shadowtex_mask
& (1<<inst
->tex_unit
))
206 read0
|= WRITEMASK_Z
;
210 /* Shadow ignored for txb.
212 read0
= get_texcoord_mask(inst
->tex_idx
) | WRITEMASK_W
;
216 read0
= writemask
& WRITEMASK_XY
;
220 read0
= writemask
& WRITEMASK_XY
;
226 read1
= WRITEMASK_XY
;
231 read1
= WRITEMASK_XY
;
235 read0
= WRITEMASK_X
; /* interpolant */
236 read1
= WRITEMASK_XY
; /* deltas */
237 read2
= WRITEMASK_W
; /* pixel w */
241 read0
= WRITEMASK_XYZ
;
242 read1
= WRITEMASK_XYZ
;
246 read0
= WRITEMASK_XYZ
;
247 read1
= WRITEMASK_XYZW
;
251 read0
= WRITEMASK_XYZW
;
252 read1
= WRITEMASK_XYZW
;
256 read0
= WRITEMASK_XYW
;
267 track_arg(c
, inst
, 0, read0
);
268 track_arg(c
, inst
, 1, read1
);
269 track_arg(c
, inst
, 2, read2
);
272 if (INTEL_DEBUG
& DEBUG_WM
) {
273 brw_wm_print_program(c
, "pass1");