intel/nir: Rewrite the guts of lower_alpha_to_coverage
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 7 Aug 2020 16:25:54 +0000 (11:25 -0500)
committerMarge Bot <eric+marge@anholt.net>
Sat, 29 Aug 2020 16:41:05 +0000 (16:41 +0000)
commitb6fdb1405ee2688ffc15acdf0476dece8bc8846b
tree8c7bc0945df99816e1add2f6a8ca07ca7cabea45
parent72dc06e07e3f8b9ed5bb46e3927b8f87dd24e42b
intel/nir: Rewrite the guts of lower_alpha_to_coverage

I have no idea how this pass ever worked.  I guess it worked ok on the
one or two piglit tests but the whole thing seemed very fragile.  It
makes a number of undocumented and unasserted assumptions and they
aren't always valid.  This rewrite makes a number of changes:

 1. It now properly handles the case where the gl_SampleMask write comes
    before the gl_FragColor or gl_FragData[0] write.

 2. It should early-exit faster because it now looks at bits in
    shader_info::outputs_written instead of looking for variables.

 3. Instead of the fragile variable lookup where we try to look the
    variable up by both location and driver_location and match, we just
    use the driver_location calculations used by brw_fs_nir.

 4. It asserts that the index parameter to store_output is a constant
    instead of silently failing if it isn't.

 5. We now actually assert the implicit assumption that the two writes
    are in the same block.  We go even further and assert that they are
    in the last block in the shader.

 6. In the case where 3 or fewer components of the output are written,
    we explicitly choose to leave the sample mask alone.

Fixes: 7ecfbd4f6d4 "nir: Add alpha_to_coverage lowering pass"
Closes: #3166
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6233>
src/intel/compiler/brw_nir.h
src/intel/compiler/brw_nir_lower_alpha_to_coverage.c