nir/lower_blend: Avoid emitting unnecessary fsats
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 10 Sep 2022 20:08:13 +0000 (16:08 -0400)
committerMarge Bot <emma+marge@anholt.net>
Mon, 12 Sep 2022 23:44:54 +0000 (23:44 +0000)
commit6177c43bb93f5a019651446e251953a3309d04a7
tree4103c04b3285632d6a71c52f31e3d398f5db732c
parent5f68262de31e2dbe364176ac87c53df80673dd3b
nir/lower_blend: Avoid emitting unnecessary fsats

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 for 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.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18535>
src/compiler/nir/nir_lower_blend.c