mesa: add/update comments in _mesa_copy_buffer_subdata()
[mesa.git] / src / mesa / drivers / dri / i965 / gen6_sf_state.c
index 67b649e7b79d1c5b6443635a1d33e5e01d36fc28..4c4ff308054687d203d7b4d0f458bda40ed20170 100644 (file)
@@ -118,6 +118,8 @@ upload_sf_state(struct brw_context *brw)
    GLbitfield64 vs_outputs_written = brw->vs.prog_data->outputs_written;
    /* BRW_NEW_FRAGMENT_PROGRAM */
    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 */
@@ -145,8 +147,19 @@ upload_sf_state(struct brw_context *brw)
       num_outputs << GEN6_SF_NUM_OUTPUTS_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;
@@ -263,6 +276,10 @@ upload_sf_state(struct brw_context *brw)
     * they source from.
     */
    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;
 
@@ -277,17 +294,10 @@ upload_sf_state(struct brw_context *brw)
         dw16 |= (1 << input_index);
 
       /* flat shading */
-      if (ctx->Light.ShadeModel == GL_FLAT) {
-         /*
-          * Setup the Constant Interpolation Enable bit mask for each
-          * corresponding attribute(currently, we only care two attrs:
-          * FRAG_BIT_COL0 and FRAG_BIT_COL1).
-          *
-          * FIXME: should we care other attributes?
-          */
-         if (attr == FRAG_ATTRIB_COL0 || attr == FRAG_ATTRIB_COL1)
-             dw17 |= (1 << input_index);
-      }
+      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
@@ -335,7 +345,8 @@ const struct brw_tracked_state gen6_sf_state = {
                _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,