+ nir_ssa_def *frag_color = intr->src[0].ssa;
+
+ if (c->fs_key->sample_coverage) {
+ nir_intrinsic_instr *load =
+ nir_intrinsic_instr_create(b->shader,
+ nir_intrinsic_load_sample_mask_in);
+ load->num_components = 1;
+ nir_ssa_dest_init(&load->instr, &load->dest, 1, 32, NULL);
+ nir_builder_instr_insert(b, &load->instr);
+
+ nir_ssa_def *bitmask = &load->dest.ssa;
+
+ vc4_nir_store_sample_mask(c, b, bitmask);
+ } else if (c->fs_key->sample_alpha_to_coverage) {
+ nir_ssa_def *a = nir_channel(b, frag_color, 3);
+
+ /* XXX: We should do a nice dither based on the fragment
+ * coordinate, instead.
+ */
+ nir_ssa_def *num_samples = nir_imm_float(b, VC4_MAX_SAMPLES);
+ nir_ssa_def *num_bits = nir_f2i(b, nir_fmul(b, a, num_samples));
+ nir_ssa_def *bitmask = nir_isub(b,
+ nir_ishl(b,
+ nir_imm_int(b, 1),
+ num_bits),
+ nir_imm_int(b, 1));
+ vc4_nir_store_sample_mask(c, b, bitmask);
+ }
+
+ /* The TLB color read returns each sample in turn, so if our blending
+ * depends on the destination color, we're going to have to run the
+ * blending function separately for each destination sample value, and
+ * then output the per-sample color using TLB_COLOR_MS.
+ */
+ nir_ssa_def *blend_output;
+ if (c->fs_key->msaa && blend_depends_on_dst_color(c)) {
+ c->msaa_per_sample_output = true;
+
+ nir_ssa_def *samples[4];
+ for (int i = 0; i < VC4_MAX_SAMPLES; i++)
+ samples[i] = vc4_nir_blend_pipeline(c, b, frag_color, i);
+ blend_output = nir_vec4(b,
+ samples[0], samples[1],
+ samples[2], samples[3]);
+ } else {
+ blend_output = vc4_nir_blend_pipeline(c, b, frag_color, 0);
+ }