From c4e59b51151ec80dc61770314f036856f8b94c75 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 1 Jan 2020 21:52:07 +0300 Subject: [PATCH] vk: Clamp depth export in FS - PS3 matches OGL behavior where writing to the depth export register results in clamping. --- rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp index 6fb41f9815..a3eb50da7e 100644 --- a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp @@ -345,9 +345,12 @@ void VKFragmentDecompilerThread::insertMainEnd(std::stringstream & OS) { if (m_parr.HasParam(PF_PARAM_NONE, "vec4", "r1")) { - //Depth writes are always from a fp32 register. See issues section on nvidia's NV_fragment_program spec - //https://www.khronos.org/registry/OpenGL/extensions/NV/NV_fragment_program.txt - OS << " gl_FragDepth = r1.z;\n"; + // NOTE: Depth writes are always from a fp32 register. See issues section on nvidia's NV_fragment_program spec + // https://www.khronos.org/registry/OpenGL/extensions/NV/NV_fragment_program.txt + + // NOTE: Depth writes in OpenGL (and by extension RSX) are clamped to 0,1 range. + // Indeed, hardware tests on realhw prove that even in depth float mode, values outside this range are clamped. + OS << " gl_FragDepth = _saturate(r1.z);\n"; } else {