bool has_pln;
bool precompile;
+ /**
+ * Some versions of Gen hardware don't do centroid interpolation correctly
+ * on unlit pixels, causing incorrect values for derivatives near triangle
+ * edges. Enabling this flag causes the fragment shader to use
+ * non-centroid interpolation for unlit pixels, at the expense of two extra
+ * fragment shader instructions.
+ */
+ bool needs_unlit_centroid_workaround;
+
struct {
struct brw_state_flags dirty;
} state;
struct brw_reg interp = interp_reg(location, k);
emit_linterp(attr, fs_reg(interp), interpolation_mode,
ir->centroid);
+ if (brw->needs_unlit_centroid_workaround && ir->centroid) {
+ /* Get the pixel/sample mask into f0 so that we know
+ * which pixels are lit. Then, for each channel that is
+ * unlit, replace the centroid data with non-centroid
+ * data.
+ */
+ emit(FS_OPCODE_MOV_DISPATCH_TO_FLAGS, attr);
+ fs_inst *inst = emit_linterp(attr, fs_reg(interp),
+ interpolation_mode, false);
+ inst->predicated = true;
+ inst->predicate_inverse = true;
+ }
if (intel->gen < 6) {
emit(BRW_OPCODE_MUL, attr, attr, this->pixel_w);
}
* (see enum brw_wm_barycentric_interp_mode) is needed by the fragment shader.
*/
static unsigned
-brw_compute_barycentric_interp_modes(bool shade_model_flat,
+brw_compute_barycentric_interp_modes(struct brw_context *brw,
+ bool shade_model_flat,
const struct gl_fragment_program *fprog)
{
unsigned barycentric_interp_modes = 0;
if (attr == FRAG_ATTRIB_WPOS || attr == FRAG_ATTRIB_FACE)
continue;
+ /* Determine the set (or sets) of barycentric coordinates needed to
+ * interpolate this variable. Note that when
+ * brw->needs_unlit_centroid_workaround is set, centroid interpolation
+ * uses PIXEL interpolation for unlit pixels and CENTROID interpolation
+ * for lit pixels, so we need both sets of barycentric coordinates.
+ */
if (interp_qualifier == INTERP_QUALIFIER_NOPERSPECTIVE) {
if (is_centroid) {
barycentric_interp_modes |=
1 << BRW_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC;
- } else {
+ }
+ if (!is_centroid || brw->needs_unlit_centroid_workaround) {
barycentric_interp_modes |=
1 << BRW_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC;
}
if (is_centroid) {
barycentric_interp_modes |=
1 << BRW_WM_PERSPECTIVE_CENTROID_BARYCENTRIC;
- } else {
+ }
+ if (!is_centroid || brw->needs_unlit_centroid_workaround) {
barycentric_interp_modes |=
1 << BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC;
}
brw_init_compile(brw, &c->func, c);
c->prog_data.barycentric_interp_modes =
- brw_compute_barycentric_interp_modes(c->key.flat_shade, &fp->program);
+ brw_compute_barycentric_interp_modes(brw, c->key.flat_shade,
+ &fp->program);
if (prog && prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
if (!brw_wm_fs_emit(brw, c, prog))