+/**
+ * Individually fast clear each color buffer attachment. On previous gens this
+ * isn't required. The motivation for this comes from one line (which seems to
+ * be specific to SKL+). The list item is in section titled _MCS Buffer for
+ * Render Target(s)_
+ *
+ * "Since only one RT is bound with a clear pass, only one RT can be cleared
+ * at a time. To clear multiple RTs, multiple clear passes are required."
+ *
+ * The code follows the same idea as the resolve code which creates a fake FBO
+ * to avoid interfering with too much of the GL state.
+ */
+static void
+fast_clear_attachments(struct brw_context *brw,
+ struct gl_framebuffer *fb,
+ uint32_t fast_clear_buffers,
+ struct rect fast_clear_rect)
+{
+ struct gl_context *ctx = &brw->ctx;
+ const bool srgb_enabled = ctx->Color.sRGBEnabled;
+
+ assert(brw->gen >= 9);
+
+ /* Make sure the GL_FRAMEBUFFER_SRGB is disabled during fast clear so that
+ * the surface state will always be uploaded with a linear buffer. SRGB
+ * buffers are not supported on Gen9 because they are not marked as
+ * losslessly compressible. This shouldn't matter for the fast clear
+ * because the color is not written to the framebuffer yet so the hardware
+ * doesn't need to do any SRGB conversion.
+ */
+ if (srgb_enabled)
+ _mesa_set_framebuffer_srgb(ctx, GL_FALSE);
+
+ brw_bind_rep_write_shader(brw, (float *) fast_clear_color);
+
+ /* SKL+ also has a resolve mode for compressed render targets and thus more
+ * bits to let us select the type of resolve. For fast clear resolves, it
+ * turns out we can use the same value as pre-SKL though.
+ */
+ set_fast_clear_op(brw, GEN7_PS_RENDER_TARGET_FAST_CLEAR_ENABLE);
+
+ while (fast_clear_buffers) {
+ int index = ffs(fast_clear_buffers) - 1;
+
+ fast_clear_buffers &= ~(1 << index);
+
+ _mesa_meta_drawbuffers_from_bitfield(1 << index);
+
+ brw_draw_rectlist(brw, &fast_clear_rect, MAX2(1, fb->MaxNumLayers));
+
+ /* Now set the mcs we cleared to INTEL_FAST_CLEAR_STATE_CLEAR so we'll
+ * resolve them eventually.
+ */
+ struct gl_renderbuffer *rb = fb->_ColorDrawBuffers[0];
+ struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+ irb->mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_CLEAR;
+ }
+
+ set_fast_clear_op(brw, 0);
+
+ if (srgb_enabled)
+ _mesa_set_framebuffer_srgb(ctx, GL_TRUE);
+}
+