From 2c91587ac5b6cee0064e88058d7ab7e77d63770e Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 14 Sep 2023 20:56:33 -0500 Subject: [PATCH] nak: Saturate depth writes Otherwise, they get may clipped away. This seems wrong in light of unrestricted depth but it fixes a bunch of CTS tests for now so let's go with it. Part-of: --- src/nouveau/compiler/nak_from_nir.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nouveau/compiler/nak_from_nir.rs b/src/nouveau/compiler/nak_from_nir.rs index 3df50102582..ee35e1a1704 100644 --- a/src/nouveau/compiler/nak_from_nir.rs +++ b/src/nouveau/compiler/nak_from_nir.rs @@ -1654,7 +1654,19 @@ impl<'a> ShaderFromNir<'a> { srcs.push(Src::new_zero()); } if info.writes_depth { - srcs.push(self.fs_out_regs[depth_idx].into()); + // Saturate depth writes. + // + // TODO: This seems wrong in light of unrestricted depth but + // it's needed to pass CTS tests for now. + let depth = self.fs_out_regs[depth_idx]; + let sat_depth = b.alloc_ssa(RegFile::GPR, 1); + b.push_op(OpFAdd { + dst: sat_depth.into(), + srcs: [depth.into(), Src::new_zero()], + saturate: true, + rnd_mode: FRndMode::NearestEven, + }); + srcs.push(sat_depth.into()); } }