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 "main/fbobject.h"
30 #include "intel_batchbuffer.h"
33 upload_sbe(struct brw_context
*brw
)
35 struct gl_context
*ctx
= &brw
->ctx
;
36 /* BRW_NEW_FS_PROG_DATA */
37 uint32_t num_outputs
= brw
->wm
.prog_data
->num_varying_inputs
;
38 uint16_t attr_overrides
[VARYING_SLOT_MAX
];
39 uint32_t urb_entry_read_length
;
40 uint32_t point_sprite_enables
;
41 uint32_t flat_enables
;
45 GEN7_SBE_SWIZZLE_ENABLE
|
46 num_outputs
<< GEN7_SBE_NUM_OUTPUTS_SHIFT
;
51 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
55 * Window coordinates in an FBO are inverted, which means point
56 * sprite origin must be inverted.
58 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
)
59 dw1
|= GEN6_SF_POINT_SPRITE_LOWERLEFT
;
61 dw1
|= GEN6_SF_POINT_SPRITE_UPPERLEFT
;
63 /* BRW_NEW_VUE_MAP_GEOM_OUT | BRW_NEW_FRAGMENT_PROGRAM |
64 * _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM | BRW_NEW_FS_PROG_DATA
66 calculate_attr_overrides(brw
, attr_overrides
,
67 &point_sprite_enables
,
69 &urb_entry_read_length
);
71 /* Typically, the URB entry read length and offset should be programmed in
72 * 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active stage
73 * which produces geometry. However, we don't know the proper value until
74 * we call calculate_attr_overrides().
76 * To fit with our existing code, we override the inherited values and
77 * specify it here directly, as we did on previous generations.
80 urb_entry_read_length
<< GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT
|
81 BRW_SF_URB_ENTRY_READ_OFFSET
<< GEN8_SBE_URB_ENTRY_READ_OFFSET_SHIFT
|
82 GEN8_SBE_FORCE_URB_ENTRY_READ_LENGTH
|
83 GEN8_SBE_FORCE_URB_ENTRY_READ_OFFSET
;
90 /* prepare the active component dwords */
92 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
93 if (!(brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)))
97 dw4
|= (GEN9_SBE_ACTIVE_COMPONENT_XYZW
<< (input_index
<< 1));
99 dw5
|= (GEN9_SBE_ACTIVE_COMPONENT_XYZW
<< (input_index
<< 1));
104 BEGIN_BATCH(sbe_cmd_length
);
105 OUT_BATCH(_3DSTATE_SBE
<< 16 | (sbe_cmd_length
- 2));
107 OUT_BATCH(point_sprite_enables
);
108 OUT_BATCH(flat_enables
);
109 if (sbe_cmd_length
>= 6) {
116 OUT_BATCH(_3DSTATE_SBE_SWIZ
<< 16 | (11 - 2));
118 /* Output DWords 1 through 8: */
119 for (int i
= 0; i
< 8; i
++) {
120 OUT_BATCH(attr_overrides
[i
* 2] | attr_overrides
[i
* 2 + 1] << 16);
123 OUT_BATCH(0); /* wrapshortest enables 0-7 */
124 OUT_BATCH(0); /* wrapshortest enables 8-15 */
128 const struct brw_tracked_state gen8_sbe_state
= {
130 .mesa
= _NEW_BUFFERS
|
134 .brw
= BRW_NEW_CONTEXT
|
135 BRW_NEW_FRAGMENT_PROGRAM
|
136 BRW_NEW_VUE_MAP_GEOM_OUT
,
137 .cache
= BRW_NEW_FS_PROG_DATA
,
143 upload_sf(struct brw_context
*brw
)
145 struct gl_context
*ctx
= &brw
->ctx
;
146 uint32_t dw1
= 0, dw2
= 0, dw3
= 0;
149 dw1
= GEN6_SF_STATISTICS_ENABLE
;
151 if (brw
->sf
.viewport_transform_enable
)
152 dw1
|= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE
;
155 uint32_t line_width_u3_7
=
156 U_FIXED(CLAMP(ctx
->Line
.Width
, 0.0, ctx
->Const
.MaxLineWidth
), 7);
157 if (line_width_u3_7
== 0)
159 if (brw
->gen
>= 9 || brw
->is_cherryview
) {
160 dw1
|= line_width_u3_7
<< GEN9_SF_LINE_WIDTH_SHIFT
;
162 dw2
|= line_width_u3_7
<< GEN6_SF_LINE_WIDTH_SHIFT
;
165 if (ctx
->Line
.SmoothFlag
) {
166 dw2
|= GEN6_SF_LINE_END_CAP_WIDTH_1_0
;
169 /* Clamp to ARB_point_parameters user limits */
170 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
172 /* Clamp to the hardware limits and convert to fixed point */
173 dw3
|= U_FIXED(CLAMP(point_size
, 0.125, 255.875), 3);
175 /* _NEW_PROGRAM | _NEW_POINT */
176 if (!(ctx
->VertexProgram
.PointSizeEnabled
|| ctx
->Point
._Attenuated
))
177 dw3
|= GEN6_SF_USE_STATE_POINT_WIDTH
;
179 /* _NEW_POINT | _NEW_MULTISAMPLE */
180 if ((ctx
->Point
.SmoothFlag
|| ctx
->Multisample
._Enabled
) &&
181 !ctx
->Point
.PointSprite
) {
182 dw3
|= GEN8_SF_SMOOTH_POINT_ENABLE
;
185 dw3
|= GEN6_SF_LINE_AA_MODE_TRUE
;
188 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
189 dw3
|= (2 << GEN6_SF_TRI_PROVOKE_SHIFT
) |
190 (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
) |
191 (1 << GEN6_SF_LINE_PROVOKE_SHIFT
);
193 dw3
|= (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
);
197 OUT_BATCH(_3DSTATE_SF
<< 16 | (4 - 2));
204 const struct brw_tracked_state gen8_sf_state
= {
211 .brw
= BRW_NEW_CONTEXT
,
218 upload_raster(struct brw_context
*brw
)
220 struct gl_context
*ctx
= &brw
->ctx
;
224 bool render_to_fbo
= _mesa_is_user_fbo(brw
->ctx
.DrawBuffer
);
227 if ((ctx
->Polygon
.FrontFace
== GL_CCW
) ^ render_to_fbo
)
228 dw1
|= GEN8_RASTER_FRONT_WINDING_CCW
;
230 if (ctx
->Polygon
.CullFlag
) {
231 switch (ctx
->Polygon
.CullFaceMode
) {
233 dw1
|= GEN8_RASTER_CULL_FRONT
;
236 dw1
|= GEN8_RASTER_CULL_BACK
;
238 case GL_FRONT_AND_BACK
:
239 dw1
|= GEN8_RASTER_CULL_BOTH
;
242 unreachable("not reached");
245 dw1
|= GEN8_RASTER_CULL_NONE
;
249 if (ctx
->Point
.SmoothFlag
)
250 dw1
|= GEN8_RASTER_SMOOTH_POINT_ENABLE
;
252 if (ctx
->Multisample
._Enabled
)
253 dw1
|= GEN8_RASTER_API_MULTISAMPLE_ENABLE
;
255 if (ctx
->Polygon
.OffsetFill
)
256 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID
;
258 if (ctx
->Polygon
.OffsetLine
)
259 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME
;
261 if (ctx
->Polygon
.OffsetPoint
)
262 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_POINT
;
264 switch (ctx
->Polygon
.FrontMode
) {
266 dw1
|= GEN6_SF_FRONT_SOLID
;
269 dw1
|= GEN6_SF_FRONT_WIREFRAME
;
272 dw1
|= GEN6_SF_FRONT_POINT
;
276 unreachable("not reached");
279 switch (ctx
->Polygon
.BackMode
) {
281 dw1
|= GEN6_SF_BACK_SOLID
;
284 dw1
|= GEN6_SF_BACK_WIREFRAME
;
287 dw1
|= GEN6_SF_BACK_POINT
;
290 unreachable("not reached");
294 if (ctx
->Line
.SmoothFlag
)
295 dw1
|= GEN8_RASTER_LINE_AA_ENABLE
;
298 if (ctx
->Scissor
.EnableFlags
)
299 dw1
|= GEN8_RASTER_SCISSOR_ENABLE
;
302 if (!ctx
->Transform
.DepthClamp
) {
304 dw1
|= GEN9_RASTER_VIEWPORT_Z_NEAR_CLIP_TEST_ENABLE
|
305 GEN9_RASTER_VIEWPORT_Z_FAR_CLIP_TEST_ENABLE
;
307 dw1
|= GEN8_RASTER_VIEWPORT_Z_CLIP_TEST_ENABLE
;
312 OUT_BATCH(_3DSTATE_RASTER
<< 16 | (5 - 2));
314 OUT_BATCH_F(ctx
->Polygon
.OffsetUnits
* 2); /* constant. copied from gen4 */
315 OUT_BATCH_F(ctx
->Polygon
.OffsetFactor
); /* scale */
320 const struct brw_tracked_state gen8_raster_state
= {
322 .mesa
= _NEW_BUFFERS
|
329 .brw
= BRW_NEW_CONTEXT
,
332 .emit
= upload_raster
,