Skip to content

nir/lower_blend: Support dual-source blending properly

Alyssa Rosenzweig requested to merge alyssa/mesa:panvk/2src into main
Now that we're working on lowered I/O, passing in the dual source blend colour
via a sideband doesn't make any sense. The primary source blend colours are
implicitly passed in as the sources of store_output intrinsics; likewise, we
should get dual source blend colours from their respective stores. And since
dual colours are only needed by blending, we can delete the stores as we go.
That means nir_lower_blend now provides an all-in-one software lowering of dual
source blending with no driver support needed! It even works for 8 dual-src
render targets, but I don't have a use case for that.

The only tricky bit here is making sure we are robust against different orders
of store_output within the exit block. In particular, if we naively lower

   x = ...
   primary color = x
   y = ...
   dual color = y

we end up emitting uses of y before it has been defined, something like

   x = ...
   primary color = blend(x, y)
   y = ...

Instead, we remove dual stores and sink blend stores to the bottom of the block,
so we end up with the correct

   x = ...
   y = ...
   primary color = blend(x, y)

lower_io_to_temporaries ensures that the stores will be in the same (exit)
block, so we don't need to sink further than that ourselves.

The motivation of this change is to support dual-source blending in PanVK in a sane way. So far, with these patches + the trivial enable on top of !20906 (merged), about 99% of the relevant tests pass. I'm completely at a loss for what's going wrong with the remaining ones and vaguely suspicious of a preexisting panvk bug this is exposing.

Merge request reports