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 urb_entry_read_offset
;
41 uint32_t point_sprite_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 /* _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM,
64 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM |
65 * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA |
66 * BRW_NEW_VUE_MAP_GEOM_OUT
68 calculate_attr_overrides(brw
, attr_overrides
,
69 &point_sprite_enables
,
70 &urb_entry_read_length
,
71 &urb_entry_read_offset
);
73 /* Typically, the URB entry read length and offset should be programmed in
74 * 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active stage
75 * which produces geometry. However, we don't know the proper value until
76 * we call calculate_attr_overrides().
78 * To fit with our existing code, we override the inherited values and
79 * specify it here directly, as we did on previous generations.
82 urb_entry_read_length
<< GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT
|
83 urb_entry_read_offset
<< GEN8_SBE_URB_ENTRY_READ_OFFSET_SHIFT
|
84 GEN8_SBE_FORCE_URB_ENTRY_READ_LENGTH
|
85 GEN8_SBE_FORCE_URB_ENTRY_READ_OFFSET
;
92 /* prepare the active component dwords */
94 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
95 if (!(brw
->fragment_program
->Base
.InputsRead
& BITFIELD64_BIT(attr
)))
98 assert(input_index
< 32);
100 if (input_index
< 16)
101 dw4
|= (GEN9_SBE_ACTIVE_COMPONENT_XYZW
<< (input_index
<< 1));
103 dw5
|= (GEN9_SBE_ACTIVE_COMPONENT_XYZW
<< ((input_index
- 16) << 1));
108 BEGIN_BATCH(sbe_cmd_length
);
109 OUT_BATCH(_3DSTATE_SBE
<< 16 | (sbe_cmd_length
- 2));
111 OUT_BATCH(point_sprite_enables
);
112 OUT_BATCH(brw
->wm
.prog_data
->flat_inputs
);
113 if (sbe_cmd_length
>= 6) {
120 OUT_BATCH(_3DSTATE_SBE_SWIZ
<< 16 | (11 - 2));
122 /* Output DWords 1 through 8: */
123 for (int i
= 0; i
< 8; i
++) {
124 OUT_BATCH(attr_overrides
[i
* 2] | attr_overrides
[i
* 2 + 1] << 16);
127 OUT_BATCH(0); /* wrapshortest enables 0-7 */
128 OUT_BATCH(0); /* wrapshortest enables 8-15 */
132 const struct brw_tracked_state gen8_sbe_state
= {
134 .mesa
= _NEW_BUFFERS
|
139 .brw
= BRW_NEW_BLORP
|
141 BRW_NEW_FRAGMENT_PROGRAM
|
142 BRW_NEW_FS_PROG_DATA
|
143 BRW_NEW_GS_PROG_DATA
|
144 BRW_NEW_TES_PROG_DATA
|
145 BRW_NEW_VUE_MAP_GEOM_OUT
,
151 upload_sf(struct brw_context
*brw
)
153 struct gl_context
*ctx
= &brw
->ctx
;
154 uint32_t dw1
= 0, dw2
= 0, dw3
= 0;
157 dw1
= GEN6_SF_STATISTICS_ENABLE
;
159 if (brw
->sf
.viewport_transform_enable
)
160 dw1
|= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE
;
163 uint32_t line_width_u3_7
= brw_get_line_width(brw
);
164 if (brw
->gen
>= 9 || brw
->is_cherryview
) {
165 dw1
|= line_width_u3_7
<< GEN9_SF_LINE_WIDTH_SHIFT
;
167 dw2
|= line_width_u3_7
<< GEN6_SF_LINE_WIDTH_SHIFT
;
170 if (ctx
->Line
.SmoothFlag
) {
171 dw2
|= GEN6_SF_LINE_END_CAP_WIDTH_1_0
;
174 /* _NEW_POINT - Clamp to ARB_point_parameters user limits */
175 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
177 /* Clamp to the hardware limits and convert to fixed point */
178 dw3
|= U_FIXED(CLAMP(point_size
, 0.125f
, 255.875f
), 3);
180 /* _NEW_PROGRAM | _NEW_POINT, BRW_NEW_VUE_MAP_GEOM_OUT */
181 if (use_state_point_size(brw
))
182 dw3
|= GEN6_SF_USE_STATE_POINT_WIDTH
;
184 /* _NEW_POINT | _NEW_MULTISAMPLE */
185 if ((ctx
->Point
.SmoothFlag
|| _mesa_is_multisample_enabled(ctx
)) &&
186 !ctx
->Point
.PointSprite
) {
187 dw3
|= GEN8_SF_SMOOTH_POINT_ENABLE
;
190 dw3
|= GEN6_SF_LINE_AA_MODE_TRUE
;
193 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
194 dw3
|= (2 << GEN6_SF_TRI_PROVOKE_SHIFT
) |
195 (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
) |
196 (1 << GEN6_SF_LINE_PROVOKE_SHIFT
);
198 dw3
|= (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
);
202 OUT_BATCH(_3DSTATE_SF
<< 16 | (4 - 2));
209 const struct brw_tracked_state gen8_sf_state
= {
216 .brw
= BRW_NEW_BLORP
|
218 BRW_NEW_VUE_MAP_GEOM_OUT
,
224 upload_raster(struct brw_context
*brw
)
226 struct gl_context
*ctx
= &brw
->ctx
;
230 bool render_to_fbo
= _mesa_is_user_fbo(brw
->ctx
.DrawBuffer
);
233 if (ctx
->Polygon
._FrontBit
== render_to_fbo
)
234 dw1
|= GEN8_RASTER_FRONT_WINDING_CCW
;
236 if (ctx
->Polygon
.CullFlag
) {
237 switch (ctx
->Polygon
.CullFaceMode
) {
239 dw1
|= GEN8_RASTER_CULL_FRONT
;
242 dw1
|= GEN8_RASTER_CULL_BACK
;
244 case GL_FRONT_AND_BACK
:
245 dw1
|= GEN8_RASTER_CULL_BOTH
;
248 unreachable("not reached");
251 dw1
|= GEN8_RASTER_CULL_NONE
;
255 if (ctx
->Point
.SmoothFlag
)
256 dw1
|= GEN8_RASTER_SMOOTH_POINT_ENABLE
;
258 if (_mesa_is_multisample_enabled(ctx
))
259 dw1
|= GEN8_RASTER_API_MULTISAMPLE_ENABLE
;
261 if (ctx
->Polygon
.OffsetFill
)
262 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID
;
264 if (ctx
->Polygon
.OffsetLine
)
265 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME
;
267 if (ctx
->Polygon
.OffsetPoint
)
268 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_POINT
;
270 switch (ctx
->Polygon
.FrontMode
) {
272 dw1
|= GEN6_SF_FRONT_SOLID
;
275 dw1
|= GEN6_SF_FRONT_WIREFRAME
;
278 dw1
|= GEN6_SF_FRONT_POINT
;
282 unreachable("not reached");
285 switch (ctx
->Polygon
.BackMode
) {
287 dw1
|= GEN6_SF_BACK_SOLID
;
290 dw1
|= GEN6_SF_BACK_WIREFRAME
;
293 dw1
|= GEN6_SF_BACK_POINT
;
296 unreachable("not reached");
300 if (ctx
->Line
.SmoothFlag
)
301 dw1
|= GEN8_RASTER_LINE_AA_ENABLE
;
304 if (ctx
->Scissor
.EnableFlags
)
305 dw1
|= GEN8_RASTER_SCISSOR_ENABLE
;
308 if (!ctx
->Transform
.DepthClamp
) {
310 dw1
|= GEN9_RASTER_VIEWPORT_Z_NEAR_CLIP_TEST_ENABLE
|
311 GEN9_RASTER_VIEWPORT_Z_FAR_CLIP_TEST_ENABLE
;
313 dw1
|= GEN8_RASTER_VIEWPORT_Z_CLIP_TEST_ENABLE
;
318 OUT_BATCH(_3DSTATE_RASTER
<< 16 | (5 - 2));
320 OUT_BATCH_F(ctx
->Polygon
.OffsetUnits
* 2); /* constant. copied from gen4 */
321 OUT_BATCH_F(ctx
->Polygon
.OffsetFactor
); /* scale */
322 OUT_BATCH_F(ctx
->Polygon
.OffsetClamp
); /* global depth offset clamp */
326 const struct brw_tracked_state gen8_raster_state
= {
328 .mesa
= _NEW_BUFFERS
|
335 .brw
= BRW_NEW_BLORP
|
338 .emit
= upload_raster
,