Skip to content

nir/lower_blend: Avoid emitting unnecessary fsats

Alyssa Rosenzweig requested to merge asahi/mesa:nir/blend-opt into main

The option struct passed to nir_lower_blend doesn't have a "blending disabled" flag. Unless blending is skipped due to logic ops or framebuffer formats, nir_lower_blend always blends, even if the blend mode is "replace" (corresponding to the API level blend disable).

That's mostly okay, since NIR can optimize out the code, at the expense of a little compile time. However, there's a catch: nir_lower_blend emits fsat at the start of the shader (for UNORM framebuffers, or fsat_signed SNORM). We can expect hardware to saturate the input to store_output itself, so these operations are redundant, but it's tricky to optimize these instructions out otherwise. Don't even try: detect the replace blend mode and don't call nir_blend in that case. Colour masking is still applied as usual.

[Removes pile of useless instructions on AGX]

Cc @jekstrand

Merge request reports