2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 #include "brw_context.h"
29 #include "brw_state.h"
30 #include "brw_defines.h"
32 #include "main/macros.h"
33 #include "intel_batchbuffer.h"
36 get_attr_override(struct brw_context
*brw
, int fs_attr
)
38 int attr_index
= 0, i
, vs_attr
;
40 if (fs_attr
<= FRAG_ATTRIB_TEX7
)
42 else if (fs_attr
== FRAG_ATTRIB_FACE
)
43 vs_attr
= 0; /* XXX */
44 else if (fs_attr
== FRAG_ATTRIB_PNTC
)
45 vs_attr
= 0; /* XXX */
47 assert(fs_attr
>= FRAG_ATTRIB_VAR0
);
48 vs_attr
= fs_attr
- FRAG_ATTRIB_VAR0
+ VERT_RESULT_VAR0
;
51 /* Find the source index (0 = first attribute after the 4D position)
52 * for this output attribute. attr is currently a VERT_RESULT_* but should
55 for (i
= 1; i
< vs_attr
; i
++) {
56 if (brw
->vs
.prog_data
->outputs_written
& BITFIELD64_BIT(i
))
64 upload_sf_state(struct brw_context
*brw
)
66 struct intel_context
*intel
= &brw
->intel
;
67 struct gl_context
*ctx
= &intel
->ctx
;
68 /* CACHE_NEW_VS_PROG */
69 uint32_t num_inputs
= brw_count_bits(brw
->vs
.prog_data
->outputs_written
);
70 uint32_t num_outputs
= brw_count_bits(brw
->fragment_program
->Base
.InputsRead
);
71 uint32_t dw1
, dw2
, dw3
, dw4
, dw16
;
74 GLboolean render_to_fbo
= brw
->intel
.ctx
.DrawBuffer
->Name
!= 0;
78 GEN6_SF_SWIZZLE_ENABLE
|
79 num_outputs
<< GEN6_SF_NUM_OUTPUTS_SHIFT
|
80 (num_inputs
+ 1) / 2 << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT
|
81 1 << GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT
;
82 dw2
= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE
|
83 GEN6_SF_STATISTICS_ENABLE
;
89 if ((ctx
->Polygon
.FrontFace
== GL_CCW
) ^ render_to_fbo
)
90 dw2
|= GEN6_SF_WINDING_CCW
;
92 if (ctx
->Polygon
.OffsetFill
)
93 dw2
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID
;
96 if (ctx
->Scissor
.Enabled
)
97 dw3
|= GEN6_SF_SCISSOR_ENABLE
;
100 if (ctx
->Polygon
.CullFlag
) {
101 switch (ctx
->Polygon
.CullFaceMode
) {
103 dw3
|= GEN6_SF_CULL_FRONT
;
106 dw3
|= GEN6_SF_CULL_BACK
;
108 case GL_FRONT_AND_BACK
:
109 dw3
|= GEN6_SF_CULL_BOTH
;
116 dw3
|= GEN6_SF_CULL_NONE
;
120 dw3
|= U_FIXED(CLAMP(ctx
->Line
.Width
, 0.0, 7.99), 7) <<
121 GEN6_SF_LINE_WIDTH_SHIFT
;
122 if (ctx
->Line
.SmoothFlag
) {
123 dw3
|= GEN6_SF_LINE_AA_ENABLE
;
124 dw3
|= GEN6_SF_LINE_AA_MODE_TRUE
;
125 dw3
|= GEN6_SF_LINE_END_CAP_WIDTH_1_0
;
129 if (!(ctx
->VertexProgram
.PointSizeEnabled
||
130 ctx
->Point
._Attenuated
))
131 dw4
|= GEN6_SF_USE_STATE_POINT_WIDTH
;
133 dw4
|= U_FIXED(CLAMP(ctx
->Point
.Size
, 0.125, 225.875), 3) <<
134 GEN6_SF_POINT_WIDTH_SHIFT
;
135 if (ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
)
136 dw1
|= GEN6_SF_POINT_SPRITE_LOWERLEFT
;
139 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
141 (2 << GEN6_SF_TRI_PROVOKE_SHIFT
) |
142 (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
) |
143 (1 << GEN6_SF_LINE_PROVOKE_SHIFT
);
146 (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
);
149 if (ctx
->Point
.PointSprite
) {
150 for (i
= 0; i
< 8; i
++) {
151 if (ctx
->Point
.CoordReplace
[i
])
157 OUT_BATCH(CMD_3D_SF_STATE
<< 16 | (20 - 2));
162 OUT_BATCH_F(ctx
->Polygon
.OffsetUnits
* 2); /* constant. copied from gen4 */
163 OUT_BATCH_F(ctx
->Polygon
.OffsetFactor
); /* scale */
164 OUT_BATCH_F(0.0); /* XXX: global depth offset clamp */
165 for (i
= 0; i
< 8; i
++) {
166 uint32_t attr_overrides
= 0;
168 for (; attr
< 64; attr
++) {
169 if (brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)) {
170 attr_overrides
|= get_attr_override(brw
, attr
);
176 for (; attr
< 64; attr
++) {
177 if (brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)) {
178 attr_overrides
|= get_attr_override(brw
, attr
) << 16;
183 OUT_BATCH(attr_overrides
);
185 OUT_BATCH(dw16
); /* point sprite texcoord bitmask */
186 OUT_BATCH(0); /* constant interp bitmask */
187 OUT_BATCH(0); /* wrapshortest enables 0-7 */
188 OUT_BATCH(0); /* wrapshortest enables 8-15 */
192 const struct brw_tracked_state gen6_sf_state
= {
194 .mesa
= (_NEW_LIGHT
|
199 .brw
= BRW_NEW_CONTEXT
,
200 .cache
= CACHE_NEW_VS_PROG
202 .emit
= upload_sf_state
,