Make fragDepth clamping conditional
Per the spec:
If VkPipelineRasterizationStateCreateInfo::depthClampEnable is
enabled, before the sample’s zf is compared to za, zf is clamped to
[min(n,f),max(n,f)], where n and f are the minDepth and maxDepth depth
range values of the viewport used by this fragment, respectively.
So when we read oDepth back from a shader that sets fragDepth, it should
only be clamped when depth clamping is enabled, and it should be clamped
to the viewport depth clamp values, not [0, 1].
Bug: b/184063472
Change-Id: I92e99b80f3929b8b8030f41f6a3afbfebda4e737
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/54408
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Commit-Queue: Sean Risser <srisser@google.com>
Tested-by: Sean Risser <srisser@google.com>
diff --git a/src/Pipeline/PixelProgram.cpp b/src/Pipeline/PixelProgram.cpp
index 58f6e5a..cf815a4 100644
--- a/src/Pipeline/PixelProgram.cpp
+++ b/src/Pipeline/PixelProgram.cpp
@@ -235,7 +235,11 @@
it = spirvShader->outputBuiltins.find(spv::BuiltInFragDepth);
if(it != spirvShader->outputBuiltins.end())
{
- oDepth = Min(Max(routine.getVariable(it->second.Id)[it->second.FirstComponent], Float4(0.0f)), Float4(1.0f));
+ oDepth = routine.getVariable(it->second.Id)[it->second.FirstComponent];
+ if(state.depthClamp)
+ {
+ oDepth = Min(Max(oDepth, Float4(state.minDepthClamp)), Float4(state.maxDepthClamp));
+ }
}
}