2 * Copyright © 2011 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 #include "brw_context.h"
25 #include "brw_state.h"
26 #include "brw_defines.h"
28 #include "main/macros.h"
29 #include "intel_batchbuffer.h"
32 upload_sbe_state(struct brw_context
*brw
)
34 struct intel_context
*intel
= &brw
->intel
;
35 struct gl_context
*ctx
= &intel
->ctx
;
36 /* CACHE_NEW_VS_PROG */
37 uint32_t num_inputs
= brw_count_bits(brw
->vs
.prog_data
->outputs_written
);
38 /* BRW_NEW_FRAGMENT_PROGRAM */
39 uint32_t num_outputs
= brw_count_bits(brw
->fragment_program
->Base
.InputsRead
);
40 uint32_t dw1
, dw10
, dw11
;
44 int urb_start
= ctx
->Transform
.ClipPlanesEnabled
? 2 : 1;
46 int two_side_color
= (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
);
48 /* FINISHME: Attribute Swizzle Control Mode? */
50 GEN7_SBE_SWIZZLE_ENABLE
|
51 num_outputs
<< GEN7_SBE_NUM_OUTPUTS_SHIFT
|
52 (num_inputs
+ 1) / 2 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT
|
53 urb_start
<< GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT
;
56 if (ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
)
57 dw1
|= GEN6_SF_POINT_SPRITE_LOWERLEFT
;
60 if (ctx
->Point
.PointSprite
) {
61 for (i
= 0; i
< 8; i
++) {
62 if (ctx
->Point
.CoordReplace
[i
])
67 /* _NEW_LIGHT (flat shading) */
69 if (ctx
->Light
.ShadeModel
== GL_FLAT
) {
70 dw11
|= ((brw
->fragment_program
->Base
.InputsRead
& (FRAG_BIT_COL0
| FRAG_BIT_COL1
)) >>
71 ((brw
->fragment_program
->Base
.InputsRead
& FRAG_BIT_WPOS
) ? 0 : 1));
75 OUT_BATCH(_3DSTATE_SBE
<< 16 | (14 - 2));
78 /* Output dwords 2 through 9 */
79 for (i
= 0; i
< 8; i
++) {
80 uint32_t attr_overrides
= 0;
82 for (; attr
< 64; attr
++) {
83 if (brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)) {
84 attr_overrides
|= get_attr_override(brw
, attr
, two_side_color
);
90 for (; attr
< 64; attr
++) {
91 if (brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)) {
92 attr_overrides
|= get_attr_override(brw
, attr
, two_side_color
) << 16;
97 OUT_BATCH(attr_overrides
);
100 OUT_BATCH(dw10
); /* point sprite texcoord bitmask */
101 OUT_BATCH(dw11
); /* constant interp bitmask */
102 OUT_BATCH(0); /* wrapshortest enables 0-7 */
103 OUT_BATCH(0); /* wrapshortest enables 8-15 */
107 const struct brw_tracked_state gen7_sbe_state
= {
109 .mesa
= (_NEW_LIGHT
|
112 .brw
= (BRW_NEW_CONTEXT
|
113 BRW_NEW_FRAGMENT_PROGRAM
),
114 .cache
= CACHE_NEW_VS_PROG
116 .emit
= upload_sbe_state
,
120 upload_sf_state(struct brw_context
*brw
)
122 struct intel_context
*intel
= &brw
->intel
;
123 struct gl_context
*ctx
= &intel
->ctx
;
124 uint32_t dw1
, dw2
, dw3
;
127 bool render_to_fbo
= brw
->intel
.ctx
.DrawBuffer
->Name
!= 0;
129 dw1
= GEN6_SF_STATISTICS_ENABLE
| GEN6_SF_VIEWPORT_TRANSFORM_ENABLE
;
132 dw1
|= (gen7_depth_format(brw
) << GEN7_SF_DEPTH_BUFFER_SURFACE_FORMAT_SHIFT
);
135 if ((ctx
->Polygon
.FrontFace
== GL_CCW
) ^ render_to_fbo
)
136 dw1
|= GEN6_SF_WINDING_CCW
;
138 if (ctx
->Polygon
.OffsetFill
)
139 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID
;
141 if (ctx
->Polygon
.OffsetLine
)
142 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME
;
144 if (ctx
->Polygon
.OffsetPoint
)
145 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_POINT
;
147 switch (ctx
->Polygon
.FrontMode
) {
149 dw1
|= GEN6_SF_FRONT_SOLID
;
153 dw1
|= GEN6_SF_FRONT_WIREFRAME
;
157 dw1
|= GEN6_SF_FRONT_POINT
;
165 switch (ctx
->Polygon
.BackMode
) {
167 dw1
|= GEN6_SF_BACK_SOLID
;
171 dw1
|= GEN6_SF_BACK_WIREFRAME
;
175 dw1
|= GEN6_SF_BACK_POINT
;
185 if (ctx
->Polygon
.CullFlag
) {
186 switch (ctx
->Polygon
.CullFaceMode
) {
188 dw2
|= GEN6_SF_CULL_FRONT
;
191 dw2
|= GEN6_SF_CULL_BACK
;
193 case GL_FRONT_AND_BACK
:
194 dw2
|= GEN6_SF_CULL_BOTH
;
201 dw2
|= GEN6_SF_CULL_NONE
;
205 if (ctx
->Scissor
.Enabled
)
206 dw2
|= GEN6_SF_SCISSOR_ENABLE
;
209 dw2
|= U_FIXED(CLAMP(ctx
->Line
.Width
, 0.0, 7.99), 7) <<
210 GEN6_SF_LINE_WIDTH_SHIFT
;
211 if (ctx
->Line
.SmoothFlag
) {
212 dw2
|= GEN6_SF_LINE_AA_ENABLE
;
213 dw2
|= GEN6_SF_LINE_AA_MODE_TRUE
;
214 dw2
|= GEN6_SF_LINE_END_CAP_WIDTH_1_0
;
217 /* FINISHME: Last Pixel Enable? Vertex Sub Pixel Precision Select?
218 * FINISHME: AA Line Distance Mode?
224 if (!(ctx
->VertexProgram
.PointSizeEnabled
|| ctx
->Point
._Attenuated
))
225 dw3
|= GEN6_SF_USE_STATE_POINT_WIDTH
;
227 /* Clamp to ARB_point_parameters user limits */
228 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
230 /* Clamp to the hardware limits and convert to fixed point */
231 dw3
|= U_FIXED(CLAMP(point_size
, 0.125, 255.875), 3);
234 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
236 (2 << GEN6_SF_TRI_PROVOKE_SHIFT
) |
237 (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
) |
238 (1 << GEN6_SF_LINE_PROVOKE_SHIFT
);
240 dw3
|= (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
);
244 OUT_BATCH(_3DSTATE_SF
<< 16 | (7 - 2));
248 OUT_BATCH_F(ctx
->Polygon
.OffsetUnits
* 2); /* constant. copied from gen4 */
249 OUT_BATCH_F(ctx
->Polygon
.OffsetFactor
); /* scale */
250 OUT_BATCH_F(0.0); /* XXX: global depth offset clamp */
254 const struct brw_tracked_state gen7_sf_state
= {
256 .mesa
= (_NEW_LIGHT
|
262 .brw
= (BRW_NEW_CONTEXT
),
263 .cache
= CACHE_NEW_VS_PROG
265 .emit
= upload_sf_state
,