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 /* CACHE_NEW_WM_PROG */
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
;
44 GEN7_SBE_SWIZZLE_ENABLE
|
45 num_outputs
<< GEN7_SBE_NUM_OUTPUTS_SHIFT
;
48 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
52 * Window coordinates in an FBO are inverted, which means point
53 * sprite origin must be inverted.
55 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
)
56 dw1
|= GEN6_SF_POINT_SPRITE_LOWERLEFT
;
58 dw1
|= GEN6_SF_POINT_SPRITE_UPPERLEFT
;
60 /* BRW_NEW_VUE_MAP_GEOM_OUT | _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM |
63 calculate_attr_overrides(brw
, attr_overrides
,
64 &point_sprite_enables
,
66 &urb_entry_read_length
);
68 /* Typically, the URB entry read length and offset should be programmed in
69 * 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active stage
70 * which produces geometry. However, we don't know the proper value until
71 * we call calculate_attr_overrides().
73 * To fit with our existing code, we override the inherited values and
74 * specify it here directly, as we did on previous generations.
77 urb_entry_read_length
<< GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT
|
78 BRW_SF_URB_ENTRY_READ_OFFSET
<< GEN8_SBE_URB_ENTRY_READ_OFFSET_SHIFT
|
79 GEN8_SBE_FORCE_URB_ENTRY_READ_LENGTH
|
80 GEN8_SBE_FORCE_URB_ENTRY_READ_OFFSET
;
83 OUT_BATCH(_3DSTATE_SBE
<< 16 | (4 - 2));
85 OUT_BATCH(point_sprite_enables
);
86 OUT_BATCH(flat_enables
);
90 OUT_BATCH(_3DSTATE_SBE_SWIZ
<< 16 | (11 - 2));
92 /* Output DWords 1 through 8: */
93 for (int i
= 0; i
< 8; i
++) {
94 OUT_BATCH(attr_overrides
[i
* 2] | attr_overrides
[i
* 2 + 1] << 16);
97 OUT_BATCH(0); /* wrapshortest enables 0-7 */
98 OUT_BATCH(0); /* wrapshortest enables 8-15 */
102 const struct brw_tracked_state gen8_sbe_state
= {
104 .mesa
= _NEW_BUFFERS
| _NEW_LIGHT
| _NEW_POINT
| _NEW_PROGRAM
,
105 .brw
= BRW_NEW_CONTEXT
|
106 BRW_NEW_FRAGMENT_PROGRAM
|
107 BRW_NEW_VUE_MAP_GEOM_OUT
,
108 .cache
= CACHE_NEW_WM_PROG
,
114 upload_sf(struct brw_context
*brw
)
116 struct gl_context
*ctx
= &brw
->ctx
;
117 uint32_t dw1
= 0, dw2
= 0, dw3
= 0;
120 dw1
= GEN6_SF_STATISTICS_ENABLE
| GEN6_SF_VIEWPORT_TRANSFORM_ENABLE
;
123 uint32_t line_width_u3_7
= U_FIXED(CLAMP(ctx
->Line
.Width
, 0.0, 7.99), 7);
124 if (line_width_u3_7
== 0)
126 dw2
|= line_width_u3_7
<< GEN6_SF_LINE_WIDTH_SHIFT
;
128 if (ctx
->Line
.SmoothFlag
) {
129 dw2
|= GEN6_SF_LINE_END_CAP_WIDTH_1_0
;
132 /* Clamp to ARB_point_parameters user limits */
133 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
135 /* Clamp to the hardware limits and convert to fixed point */
136 dw3
|= U_FIXED(CLAMP(point_size
, 0.125, 255.875), 3);
138 /* _NEW_PROGRAM | _NEW_POINT */
139 if (!(ctx
->VertexProgram
.PointSizeEnabled
|| ctx
->Point
._Attenuated
))
140 dw3
|= GEN6_SF_USE_STATE_POINT_WIDTH
;
142 /* _NEW_POINT | _NEW_MULTISAMPLE */
143 if ((ctx
->Point
.SmoothFlag
|| ctx
->Multisample
._Enabled
) &&
144 !ctx
->Point
.PointSprite
) {
145 dw3
|= GEN8_SF_SMOOTH_POINT_ENABLE
;
148 dw3
|= GEN6_SF_LINE_AA_MODE_TRUE
;
151 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
152 dw3
|= (2 << GEN6_SF_TRI_PROVOKE_SHIFT
) |
153 (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
) |
154 (1 << GEN6_SF_LINE_PROVOKE_SHIFT
);
156 dw3
|= (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT
);
160 OUT_BATCH(_3DSTATE_SF
<< 16 | (4 - 2));
167 const struct brw_tracked_state gen8_sf_state
= {
174 .brw
= BRW_NEW_CONTEXT
,
181 upload_raster(struct brw_context
*brw
)
183 struct gl_context
*ctx
= &brw
->ctx
;
187 bool render_to_fbo
= _mesa_is_user_fbo(brw
->ctx
.DrawBuffer
);
190 if ((ctx
->Polygon
.FrontFace
== GL_CCW
) ^ render_to_fbo
)
191 dw1
|= GEN8_RASTER_FRONT_WINDING_CCW
;
193 if (ctx
->Polygon
.CullFlag
) {
194 switch (ctx
->Polygon
.CullFaceMode
) {
196 dw1
|= GEN8_RASTER_CULL_FRONT
;
199 dw1
|= GEN8_RASTER_CULL_BACK
;
201 case GL_FRONT_AND_BACK
:
202 dw1
|= GEN8_RASTER_CULL_BOTH
;
205 unreachable("not reached");
208 dw1
|= GEN8_RASTER_CULL_NONE
;
212 if (ctx
->Point
.SmoothFlag
)
213 dw1
|= GEN8_RASTER_SMOOTH_POINT_ENABLE
;
215 if (ctx
->Multisample
._Enabled
)
216 dw1
|= GEN8_RASTER_API_MULTISAMPLE_ENABLE
;
218 if (ctx
->Polygon
.OffsetFill
)
219 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID
;
221 if (ctx
->Polygon
.OffsetLine
)
222 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME
;
224 if (ctx
->Polygon
.OffsetPoint
)
225 dw1
|= GEN6_SF_GLOBAL_DEPTH_OFFSET_POINT
;
227 switch (ctx
->Polygon
.FrontMode
) {
229 dw1
|= GEN6_SF_FRONT_SOLID
;
232 dw1
|= GEN6_SF_FRONT_WIREFRAME
;
235 dw1
|= GEN6_SF_FRONT_POINT
;
239 unreachable("not reached");
242 switch (ctx
->Polygon
.BackMode
) {
244 dw1
|= GEN6_SF_BACK_SOLID
;
247 dw1
|= GEN6_SF_BACK_WIREFRAME
;
250 dw1
|= GEN6_SF_BACK_POINT
;
253 unreachable("not reached");
257 if (ctx
->Line
.SmoothFlag
)
258 dw1
|= GEN8_RASTER_LINE_AA_ENABLE
;
261 if (ctx
->Scissor
.EnableFlags
)
262 dw1
|= GEN8_RASTER_SCISSOR_ENABLE
;
265 if (!ctx
->Transform
.DepthClamp
)
266 dw1
|= GEN8_RASTER_VIEWPORT_Z_CLIP_TEST_ENABLE
;
269 OUT_BATCH(_3DSTATE_RASTER
<< 16 | (5 - 2));
271 OUT_BATCH_F(ctx
->Polygon
.OffsetUnits
* 2); /* constant. copied from gen4 */
272 OUT_BATCH_F(ctx
->Polygon
.OffsetFactor
); /* scale */
277 const struct brw_tracked_state gen8_raster_state
= {
279 .mesa
= _NEW_BUFFERS
|
286 .brw
= BRW_NEW_CONTEXT
,
289 .emit
= upload_raster
,