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 "main/macros.h"
34 #include "brw_context.h"
37 /* Component is active if it may diverge from [0,0,0,1]. Undef values
38 * are promoted to [0,0,0,1] for the purposes of this analysis.
42 GLubyte active
[PROGRAM_OUTPUT
+1][MAX_PROGRAM_TEMPS
];
43 GLbitfield64 size_masks
[4]; /**< one bit per fragment program input attrib */
47 static void set_active_component( struct tracker
*t
,
53 case PROGRAM_TEMPORARY
:
56 assert(file
< PROGRAM_OUTPUT
+ 1);
57 assert(index
< Elements(t
->active
[0]));
58 t
->active
[file
][index
] |= active
;
65 static void set_active( struct tracker
*t
,
66 struct prog_dst_register dst
,
69 set_active_component( t
, dst
.File
, dst
.Index
, active
& dst
.WriteMask
);
73 static GLubyte
get_active_component( struct tracker
*t
,
81 return component
< 3 ? 0 : (1<<component
);
83 return component
== 3 ? 0 : (1<<component
);
86 case PROGRAM_TEMPORARY
:
89 return t
->active
[file
][index
] & (1<<component
);
91 return 1 << component
;
97 static GLubyte
get_active( struct tracker
*t
,
98 struct prog_src_register src
)
101 GLubyte active
= src
.Negate
; /* NOTE! */
106 for (i
= 0; i
< 4; i
++)
107 active
|= get_active_component(t
, src
.File
, src
.Index
, i
,
108 GET_SWZ(src
.Swizzle
, i
));
114 * Return the size (1,2,3 or 4) of the output/result for VARYING_SLOT_idx.
116 static GLubyte
get_output_size( struct tracker
*t
,
120 assert(idx
< VARYING_SLOT_MAX
);
121 active
= t
->active
[PROGRAM_OUTPUT
][idx
];
122 if (active
& (1<<3)) return 4;
123 if (active
& (1<<2)) return 3;
124 if (active
& (1<<1)) return 2;
125 if (active
& (1<<0)) return 1;
129 /* Note the potential copying that occurs in the setup program:
131 static void calc_sizes( struct tracker
*t
)
136 t
->active
[PROGRAM_OUTPUT
][VARYING_SLOT_COL0
] |=
137 t
->active
[PROGRAM_OUTPUT
][VARYING_SLOT_BFC0
];
139 t
->active
[PROGRAM_OUTPUT
][VARYING_SLOT_COL1
] |=
140 t
->active
[PROGRAM_OUTPUT
][VARYING_SLOT_BFC1
];
143 /* Examine vertex program output sizes to set the size_masks[] info
144 * which describes the fragment program input sizes.
146 for (vertRes
= 0; vertRes
< VARYING_SLOT_MAX
; vertRes
++) {
148 /* map vertex program output index to fragment program input index */
149 GLint fragAttrib
= _mesa_vert_result_to_frag_attrib(vertRes
);
153 switch (get_output_size(t
, vertRes
)) {
154 case 4: t
->size_masks
[4-1] |= BITFIELD64_BIT(fragAttrib
);
155 case 3: t
->size_masks
[3-1] |= BITFIELD64_BIT(fragAttrib
);
156 case 2: t
->size_masks
[2-1] |= BITFIELD64_BIT(fragAttrib
);
157 case 1: t
->size_masks
[1-1] |= BITFIELD64_BIT(fragAttrib
);
163 static GLubyte szflag
[4+1] = {
171 /* Pull a size out of the packed array:
173 static GLuint
get_input_size(struct brw_context
*brw
,
176 GLuint sizes_dword
= brw
->vb
.info
.sizes
[attr
/16];
177 GLuint sizes_bits
= (sizes_dword
>>((attr
%16)*2)) & 0x3;
178 return sizes_bits
+ 1;
179 /* return brw->vb.inputs[attr].glarray->Size; */
182 /* Calculate sizes of vertex program outputs. Size is the largest
183 * component index which might vary from [0,0,0,1]
185 static void calc_wm_input_sizes( struct brw_context
*brw
)
187 struct gl_context
*ctx
= &brw
->intel
.ctx
;
188 /* BRW_NEW_VERTEX_PROGRAM */
189 const struct brw_vertex_program
*vp
=
190 brw_vertex_program_const(brw
->vertex_program
);
191 /* BRW_NEW_INPUT_DIMENSIONS */
196 /* Mesa IR is not generated for GLSL vertex shaders. If there's no Mesa
197 * IR, the code below cannot determine which output components are
198 * written. So, skip it and assume everything is written. This
199 * circumvents some optimizations in the fragment shader, but it guarantees
200 * that correct code is generated.
202 if (vp
->program
.Base
.NumInstructions
== 0) {
203 brw
->wm
.input_size_masks
[0] = ~(GLbitfield64
) 0;
204 brw
->wm
.input_size_masks
[1] = ~(GLbitfield64
) 0;
205 brw
->wm
.input_size_masks
[2] = ~(GLbitfield64
) 0;
206 brw
->wm
.input_size_masks
[3] = ~(GLbitfield64
) 0;
211 memset(&t
, 0, sizeof(t
));
213 /* _NEW_LIGHT | _NEW_PROGRAM */
214 if (ctx
->VertexProgram
._TwoSideEnabled
)
217 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
218 if (vp
->program
.Base
.InputsRead
& BITFIELD64_BIT(i
))
219 set_active_component(&t
, PROGRAM_INPUT
, i
,
220 szflag
[get_input_size(brw
, i
)]);
222 for (insn
= 0; insn
< vp
->program
.Base
.NumInstructions
; insn
++) {
223 struct prog_instruction
*inst
= &vp
->program
.Base
.Instructions
[insn
];
225 switch (inst
->Opcode
) {
230 set_active(&t
, inst
->DstReg
, get_active(&t
, inst
->SrcReg
[0]));
234 set_active(&t
, inst
->DstReg
, 0xf);
243 * If the SF will be replacing the vertex output with a reference to
244 * gl_PointCoord, then tell the fragment shader that the value actually
247 if (ctx
->Point
.PointSprite
) {
248 for (int i
= 0; i
< 8; i
++) {
249 if (ctx
->Point
.CoordReplace
[i
]) {
250 t
.size_masks
[4-1] |= FRAG_BIT_TEX(i
);
251 t
.size_masks
[3-1] |= FRAG_BIT_TEX(i
);
252 t
.size_masks
[2-1] |= FRAG_BIT_TEX(i
);
253 t
.size_masks
[1-1] |= FRAG_BIT_TEX(i
);
258 if (memcmp(brw
->wm
.input_size_masks
, t
.size_masks
, sizeof(t
.size_masks
)) != 0) {
259 memcpy(brw
->wm
.input_size_masks
, t
.size_masks
, sizeof(t
.size_masks
));
260 brw
->state
.dirty
.brw
|= BRW_NEW_WM_INPUT_DIMENSIONS
;
264 const struct brw_tracked_state brw_wm_input_sizes
= {
266 .mesa
= _NEW_LIGHT
| _NEW_PROGRAM
| _NEW_POINT
,
267 .brw
= BRW_NEW_VERTEX_PROGRAM
| BRW_NEW_INPUT_DIMENSIONS
,
270 .emit
= calc_wm_input_sizes