Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs_constval.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
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:
13
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.
17
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.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_context.h"
34 #include "program.h"
35 #include "program_instruction.h"
36 #include "macros.h"
37 #include "brw_vs.h"
38
39 /* Component is active if it may diverge from [0,0,0,1]. Undef values
40 * are promoted to [0,0,0,1] for the purposes of this analysis.
41 */
42 struct tracker {
43 GLboolean twoside;
44 GLubyte active[PROGRAM_OUTPUT+1][128];
45 GLuint size_masks[4];
46 };
47
48
49 static void set_active_component( struct tracker *t,
50 GLuint file,
51 GLuint index,
52 GLubyte active )
53 {
54 switch (file) {
55 case PROGRAM_TEMPORARY:
56 case PROGRAM_INPUT:
57 case PROGRAM_OUTPUT:
58 t->active[file][index] |= active;
59
60 default:
61 break;
62 }
63 }
64
65 static void set_active( struct tracker *t,
66 struct prog_dst_register dst,
67 GLuint active )
68 {
69 set_active_component( t, dst.File, dst.Index, active & dst.WriteMask );
70 }
71
72
73 static GLubyte get_active_component( struct tracker *t,
74 GLuint file,
75 GLuint index,
76 GLuint component,
77 GLubyte swz )
78 {
79 switch (swz) {
80 case SWIZZLE_ZERO:
81 return component < 3 ? 0 : (1<<component);
82 case SWIZZLE_ONE:
83 return component == 3 ? 0 : (1<<component);
84 default:
85 switch (file) {
86 case PROGRAM_TEMPORARY:
87 case PROGRAM_INPUT:
88 case PROGRAM_OUTPUT:
89 return t->active[file][index] & (1<<component);
90 default:
91 return 1 << component;
92 }
93 }
94 }
95
96
97 static GLubyte get_active( struct tracker *t,
98 struct prog_src_register src )
99 {
100 GLuint i;
101 GLubyte active = src.NegateBase; /* NOTE! */
102
103 if (src.RelAddr)
104 return 0xf;
105
106 for (i = 0; i < 4; i++)
107 active |= get_active_component(t, src.File, src.Index, i,
108 GET_SWZ(src.Swizzle, i));
109
110 return active;
111 }
112
113 static GLubyte get_output_size( struct tracker *t,
114 GLuint idx )
115 {
116 GLubyte active = t->active[PROGRAM_OUTPUT][idx];
117 if (active & (1<<3)) return 4;
118 if (active & (1<<2)) return 3;
119 if (active & (1<<1)) return 2;
120 if (active & (1<<0)) return 1;
121 return 0;
122 }
123
124 /* Note the potential copying that occurs in the setup program:
125 */
126 static void calc_sizes( struct tracker *t )
127 {
128 GLuint i;
129
130 if (t->twoside) {
131 t->active[PROGRAM_OUTPUT][VERT_RESULT_COL0] |=
132 t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC0];
133
134 t->active[PROGRAM_OUTPUT][VERT_RESULT_COL1] |=
135 t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC1];
136 }
137
138 for (i = 0; i < FRAG_ATTRIB_MAX; i++) {
139 switch (get_output_size(t, i)) {
140 case 4: t->size_masks[4-1] |= 1<<i;
141 case 3: t->size_masks[3-1] |= 1<<i;
142 case 2: t->size_masks[2-1] |= 1<<i;
143 case 1: t->size_masks[1-1] |= 1<<i;
144 break;
145 }
146 }
147 }
148
149 static GLubyte szflag[4+1] = {
150 0,
151 0x1,
152 0x3,
153 0x7,
154 0xf
155 };
156
157 /* Pull a size out of the packed array:
158 */
159 static GLuint get_input_size(struct brw_context *brw,
160 GLuint attr)
161 {
162 GLuint sizes_dword = brw->vb.info.sizes[attr/16];
163 GLuint sizes_bits = (sizes_dword>>((attr%16)*2)) & 0x3;
164 return sizes_bits + 1;
165 }
166
167 /* Calculate sizes of vertex program outputs. Size is the largest
168 * component index which might vary from [0,0,0,1]
169 */
170 static void calc_wm_input_sizes( struct brw_context *brw )
171 {
172 /* BRW_NEW_VERTEX_PROGRAM */
173 struct brw_vertex_program *vp =
174 (struct brw_vertex_program *)brw->vertex_program;
175 /* BRW_NEW_INPUT_DIMENSIONS */
176 struct tracker t;
177 GLuint insn;
178 GLuint i;
179
180 memset(&t, 0, sizeof(t));
181
182 /* _NEW_LIGHT */
183 if (brw->attribs.Light->Model.TwoSide)
184 t.twoside = 1;
185
186 for (i = 0; i < BRW_ATTRIB_MAX; i++)
187 if (vp->program.Base.InputsRead & (1<<i))
188 set_active_component(&t, PROGRAM_INPUT, i,
189 szflag[get_input_size(brw, i)]);
190
191 for (insn = 0; insn < vp->program.Base.NumInstructions; insn++) {
192 struct prog_instruction *inst = &vp->program.Base.Instructions[insn];
193
194 switch (inst->Opcode) {
195 case OPCODE_ARL:
196 break;
197
198 case OPCODE_MOV:
199 set_active(&t, inst->DstReg, get_active(&t, inst->SrcReg[0]));
200 break;
201
202 default:
203 set_active(&t, inst->DstReg, 0xf);
204 break;
205 }
206 }
207
208 calc_sizes(&t);
209
210 if (memcmp(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks)) != 0) {
211 memcpy(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks));
212 brw->state.dirty.brw |= BRW_NEW_WM_INPUT_DIMENSIONS;
213 }
214 }
215
216 const struct brw_tracked_state brw_wm_input_sizes = {
217 .dirty = {
218 .mesa = _NEW_LIGHT,
219 .brw = BRW_NEW_VERTEX_PROGRAM | BRW_NEW_INPUT_DIMENSIONS,
220 .cache = 0
221 },
222 .update = calc_wm_input_sizes
223 };
224