int fs_attr, bool two_side_color)
{
int attr_override, slot;
- int vs_attr = frag_attrib_to_vert_result(fs_attr);
+ int vs_attr = _mesa_frag_attrib_to_vert_result(fs_attr);
if (vs_attr < 0 || vs_attr == VERT_RESULT_HPOS) {
/* These attributes will be overwritten by the fragment shader's
* interpolation code (see emit_interp() in brw_wm_fp.c), so just let
/* Find the VUE slot for this attribute. */
slot = vue_map->vert_result_to_slot[vs_attr];
+
+ /* If there was only a back color written but not front, use back
+ * as the color instead of undefined
+ */
+ if (slot == -1 && vs_attr == VERT_RESULT_COL0)
+ slot = vue_map->vert_result_to_slot[VERT_RESULT_BFC0];
+ if (slot == -1 && vs_attr == VERT_RESULT_COL1)
+ slot = vue_map->vert_result_to_slot[VERT_RESULT_BFC1];
+
if (slot == -1) {
/* This attribute does not exist in the VUE--that means that the vertex
* shader did not write to it. Behavior is undefined in this case, so
struct intel_context *intel = &brw->intel;
struct gl_context *ctx = &intel->ctx;
struct brw_vue_map vue_map;
+ uint32_t urb_entry_read_length;
/* CACHE_NEW_VS_PROG */
GLbitfield64 vs_outputs_written = brw->vs.prog_data->outputs_written;
- uint32_t num_inputs = brw_count_bits(vs_outputs_written);
/* BRW_NEW_FRAGMENT_PROGRAM */
- uint32_t num_outputs = brw_count_bits(brw->fragment_program->Base.InputsRead);
+ uint32_t num_outputs = _mesa_bitcount_64(brw->fragment_program->Base.InputsRead);
+ /* _NEW_LIGHT */
+ bool shade_model_flat = ctx->Light.ShadeModel == GL_FLAT;
uint32_t dw1, dw2, dw3, dw4, dw16, dw17;
int i;
/* _NEW_BUFFER */
- GLboolean render_to_fbo = brw->intel.ctx.DrawBuffer->Name != 0;
+ bool render_to_fbo = brw->intel.ctx.DrawBuffer->Name != 0;
int attr = 0, input_index = 0;
- int urb_entry_read_offset;
- int two_side_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
+ int urb_entry_read_offset = 1;
float point_size;
uint16_t attr_overrides[FRAG_ATTRIB_MAX];
- int nr_userclip;
+ bool userclip_active;
/* _NEW_TRANSFORM */
- if (ctx->Transform.ClipPlanesEnabled)
- urb_entry_read_offset = 2;
- else
- urb_entry_read_offset = 1;
- nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
+ userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
+
+ brw_compute_vue_map(&vue_map, intel, userclip_active, vs_outputs_written);
+ urb_entry_read_length = (vue_map.num_slots + 1)/2 - urb_entry_read_offset;
+ if (urb_entry_read_length == 0) {
+ /* Setting the URB entry read length to 0 causes undefined behavior, so
+ * if we have no URB data to read, set it to 1.
+ */
+ urb_entry_read_length = 1;
+ }
dw1 =
GEN6_SF_SWIZZLE_ENABLE |
num_outputs << GEN6_SF_NUM_OUTPUTS_SHIFT |
- (num_inputs + 1) / 2 << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT |
+ urb_entry_read_length << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT |
urb_entry_read_offset << GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT;
- dw2 = GEN6_SF_VIEWPORT_TRANSFORM_ENABLE |
- GEN6_SF_STATISTICS_ENABLE;
+
+ dw2 = GEN6_SF_STATISTICS_ENABLE;
+
+ /* Enable viewport transform only if no HiZ operation is progress
+ *
+ * From page 11 of the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
+ * Primitives Overview":
+ * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
+ * use of screen- space coordinates).
+ */
+ if (!brw->hiz.op)
+ dw2 |= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE;
+
dw3 = 0;
dw4 = 0;
dw16 = 0;
(1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT);
}
- /* flat shading */
- if (ctx->Light.ShadeModel == GL_FLAT) {
- dw17 |= ((brw->fragment_program->Base.InputsRead & (FRAG_BIT_COL0 | FRAG_BIT_COL1)) >>
- ((brw->fragment_program->Base.InputsRead & FRAG_BIT_WPOS) ? 0 : 1));
- }
-
/* Create the mapping from the FS inputs we produce to the VS outputs
* they source from.
*/
- brw_compute_vue_map(&vue_map, intel, nr_userclip, two_side_color,
- vs_outputs_written);
for (; attr < FRAG_ATTRIB_MAX; attr++) {
+ enum glsl_interp_qualifier interp_qualifier =
+ brw->fragment_program->InterpQualifier[attr];
+ bool is_gl_Color = attr == FRAG_ATTRIB_COL0 || attr == FRAG_ATTRIB_COL1;
+
if (!(brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(attr)))
continue;
if (attr == FRAG_ATTRIB_PNTC)
dw16 |= (1 << input_index);
+ /* flat shading */
+ if (interp_qualifier == INTERP_QUALIFIER_FLAT ||
+ (shade_model_flat && is_gl_Color &&
+ interp_qualifier == INTERP_QUALIFIER_NONE))
+ dw17 |= (1 << input_index);
+
/* The hardware can only do the overrides on 16 overrides at a
* time, and the other up to 16 have to be lined up so that the
* input index = the output index. We'll need to do some
*/
assert(input_index < 16 || attr == input_index);
+ /* _NEW_LIGHT | _NEW_PROGRAM */
attr_overrides[input_index++] =
get_attr_override(&vue_map, urb_entry_read_offset, attr,
- two_side_color);
+ ctx->VertexProgram._TwoSideEnabled);
}
for (; input_index < FRAG_ATTRIB_MAX; input_index++)
const struct brw_tracked_state gen6_sf_state = {
.dirty = {
.mesa = (_NEW_LIGHT |
+ _NEW_PROGRAM |
_NEW_POLYGON |
_NEW_LINE |
_NEW_SCISSOR |
_NEW_POINT |
_NEW_TRANSFORM),
.brw = (BRW_NEW_CONTEXT |
- BRW_NEW_FRAGMENT_PROGRAM),
+ BRW_NEW_FRAGMENT_PROGRAM |
+ BRW_NEW_HIZ),
.cache = CACHE_NEW_VS_PROG
},
.emit = upload_sf_state,