1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org develop this 3D driver.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Permission is hereby granted, free of charge, to any person obtaining
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org a copy of this software and associated documentation files (the
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org "Software"), to deal in the Software without restriction, including
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org without limitation the rights to use, copy, modify, merge, publish,
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org distribute, sublicense, and/or sell copies of the Software, and to
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org permit persons to whom the Software is furnished to do so, subject to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org The above copyright notice and this permission notice (including the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org next paragraph) shall be included in all copies or substantial
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org portions of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **********************************************************************/
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /*
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  * Authors:
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  *   Keith Whitwell <keith@tungstengraphics.com>
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  */
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/macros.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "brw_context.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "brw_vs.h"
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Component is active if it may diverge from [0,0,0,1].  Undef values
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * are promoted to [0,0,0,1] for the purposes of this analysis.
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct tracker {
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   bool twoside;
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte active[PROGRAM_OUTPUT+1][MAX_PROGRAM_TEMPS];
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLbitfield size_masks[4];  /**< one bit per fragment program input attrib */
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void set_active_component( struct tracker *t,
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				  GLuint file,
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				  GLuint index,
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				  GLubyte active )
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (file) {
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PROGRAM_TEMPORARY:
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PROGRAM_INPUT:
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PROGRAM_OUTPUT:
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      assert(file < PROGRAM_OUTPUT + 1);
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      assert(index < Elements(t->active[0]));
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      t->active[file][index] |= active;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      break;
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default:
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      break;
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void set_active( struct tracker *t,
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			struct prog_dst_register dst,
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			GLuint active )
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   set_active_component( t, dst.File, dst.Index, active & dst.WriteMask );
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic GLubyte get_active_component( struct tracker *t,
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				     GLuint file,
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				     GLuint index,
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				     GLuint component,
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				     GLubyte swz )
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (swz) {
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case SWIZZLE_ZERO:
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return component < 3 ? 0 : (1<<component);
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case SWIZZLE_ONE:
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return component == 3 ? 0 : (1<<component);
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default:
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      switch (file) {
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case PROGRAM_TEMPORARY:
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case PROGRAM_INPUT:
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case PROGRAM_OUTPUT:
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 return t->active[file][index] & (1<<component);
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      default:
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 return 1 << component;
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic GLubyte get_active( struct tracker *t,
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			   struct prog_src_register src )
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLuint i;
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte active = src.Negate; /* NOTE! */
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (src.RelAddr)
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return 0xf;
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (i = 0; i < 4; i++)
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      active |= get_active_component(t, src.File, src.Index, i,
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				     GET_SWZ(src.Swizzle, i));
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return active;
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Return the size (1,2,3 or 4) of the output/result for VERT_RESULT_idx.
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic GLubyte get_output_size( struct tracker *t,
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				GLuint idx )
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte active;
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   assert(idx < VERT_RESULT_MAX);
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   active = t->active[PROGRAM_OUTPUT][idx];
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (active & (1<<3)) return 4;
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (active & (1<<2)) return 3;
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (active & (1<<1)) return 2;
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (active & (1<<0)) return 1;
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return 0;
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Note the potential copying that occurs in the setup program:
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void calc_sizes( struct tracker *t )
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLint vertRes;
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (t->twoside) {
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      t->active[PROGRAM_OUTPUT][VERT_RESULT_COL0] |=
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC0];
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      t->active[PROGRAM_OUTPUT][VERT_RESULT_COL1] |=
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC1];
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Examine vertex program output sizes to set the size_masks[] info
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * which describes the fragment program input sizes.
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (vertRes = 0; vertRes < VERT_RESULT_MAX; vertRes++) {
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* map vertex program output index to fragment program input index */
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint fragAttrib = _mesa_vert_result_to_frag_attrib(vertRes);
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (fragAttrib < 0)
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         continue;
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      switch (get_output_size(t, vertRes)) {
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case 4: t->size_masks[4-1] |= 1 << fragAttrib;
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case 3: t->size_masks[3-1] |= 1 << fragAttrib;
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case 2: t->size_masks[2-1] |= 1 << fragAttrib;
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case 1: t->size_masks[1-1] |= 1 << fragAttrib;
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 break;
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic GLubyte szflag[4+1] = {
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   0,
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   0x1,
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   0x3,
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   0x7,
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   0xf
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Pull a size out of the packed array:
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic GLuint get_input_size(struct brw_context *brw,
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			     GLuint attr)
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLuint sizes_dword = brw->vb.info.sizes[attr/16];
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLuint sizes_bits = (sizes_dword>>((attr%16)*2)) & 0x3;
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return sizes_bits + 1;
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*    return brw->vb.inputs[attr].glarray->Size; */
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Calculate sizes of vertex program outputs.  Size is the largest
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * component index which might vary from [0,0,0,1]
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void calc_wm_input_sizes( struct brw_context *brw )
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct gl_context *ctx = &brw->intel.ctx;
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* BRW_NEW_VERTEX_PROGRAM */
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const struct brw_vertex_program *vp =
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw_vertex_program_const(brw->vertex_program);
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* BRW_NEW_INPUT_DIMENSIONS */
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct tracker t;
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLuint insn;
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLuint i;
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Mesa IR is not generated for GLSL vertex shaders.  If there's no Mesa
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * IR, the code below cannot determine which output components are
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * written.  So, skip it and assume everything is written.  This
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * circumvents some optimizations in the fragment shader, but it guarantees
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * that correct code is generated.
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (vp->program.Base.NumInstructions == 0) {
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw->wm.input_size_masks[0] = ~0;
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw->wm.input_size_masks[1] = ~0;
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw->wm.input_size_masks[2] = ~0;
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw->wm.input_size_masks[3] = ~0;
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   memset(&t, 0, sizeof(t));
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* _NEW_LIGHT | _NEW_PROGRAM */
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ctx->VertexProgram._TwoSideEnabled)
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      t.twoside = 1;
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (i = 0; i < VERT_ATTRIB_MAX; i++)
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (vp->program.Base.InputsRead & BITFIELD64_BIT(i))
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 set_active_component(&t, PROGRAM_INPUT, i,
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			      szflag[get_input_size(brw, i)]);
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (insn = 0; insn < vp->program.Base.NumInstructions; insn++) {
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      struct prog_instruction *inst = &vp->program.Base.Instructions[insn];
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      switch (inst->Opcode) {
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case OPCODE_ARL:
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 break;
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      case OPCODE_MOV:
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 set_active(&t, inst->DstReg, get_active(&t, inst->SrcReg[0]));
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 break;
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      default:
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 set_active(&t, inst->DstReg, 0xf);
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 break;
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   calc_sizes(&t);
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (memcmp(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks)) != 0) {
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      memcpy(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks));
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      brw->state.dirty.brw |= BRW_NEW_WM_INPUT_DIMENSIONS;
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst struct brw_tracked_state brw_wm_input_sizes = {
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   .dirty = {
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      .mesa  = _NEW_LIGHT | _NEW_PROGRAM,
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      .brw   = BRW_NEW_VERTEX_PROGRAM | BRW_NEW_INPUT_DIMENSIONS,
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      .cache = 0
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   },
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   .emit = calc_wm_input_sizes
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
256