Implement depthClamp

The depthClamp feature allows users to force the depth to fit between two values. Enabling depth clamping disables primitive depth clipping unless a user explicitly enables both. Bug: b/181655689 Tests: dEQP-VK.glsl.builtin_var.fragdepth.* Tests: dEQP-VK.clipping.clip_volume.depth_clamp.* Tests: dEQP-VK.draw.inverted_depth_ranges.* Tests: dEQP-VK.draw.depth_clamp.* Change-Id: Ib184b1972a11db2a806b7985754075fff55b4461 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/53929Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarSean Risser <srisser@google.com> Commit-Queue: Sean Risser <srisser@google.com>
parent 72b1f017
...@@ -311,11 +311,6 @@ GraphicsState::GraphicsState(const Device *device, const VkGraphicsPipelineCreat ...@@ -311,11 +311,6 @@ GraphicsState::GraphicsState(const Device *device, const VkGraphicsPipelineCreat
UNSUPPORTED("pCreateInfo->pRasterizationState->flags %d", int(pCreateInfo->pRasterizationState->flags)); UNSUPPORTED("pCreateInfo->pRasterizationState->flags %d", int(pCreateInfo->pRasterizationState->flags));
} }
if(rasterizationState->depthClampEnable != VK_FALSE)
{
UNSUPPORTED("VkPhysicalDeviceFeatures::depthClamp");
}
rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable != VK_FALSE); rasterizerDiscard = (rasterizationState->rasterizerDiscardEnable != VK_FALSE);
cullMode = rasterizationState->cullMode; cullMode = rasterizationState->cullMode;
frontFace = rasterizationState->frontFace; frontFace = rasterizationState->frontFace;
......
...@@ -118,9 +118,22 @@ const PixelProcessor::State PixelProcessor::update(const vk::GraphicsState &pipe ...@@ -118,9 +118,22 @@ const PixelProcessor::State PixelProcessor::update(const vk::GraphicsState &pipe
state.depthBias = (pipelineState.getConstantDepthBias() != 0.0f) || (pipelineState.getSlopeDepthBias() != 0.0f); state.depthBias = (pipelineState.getConstantDepthBias() != 0.0f) || (pipelineState.getSlopeDepthBias() != 0.0f);
bool pipelineDepthClamp = pipelineState.getDepthClampEnable();
// "For fixed-point depth buffers, fragment depth values are always limited to the range [0,1] by clamping after depth bias addition is performed. // "For fixed-point depth buffers, fragment depth values are always limited to the range [0,1] by clamping after depth bias addition is performed.
// Unless the VK_EXT_depth_range_unrestricted extension is enabled, fragment depth values are clamped even when the depth buffer uses a floating-point representation." // Unless the VK_EXT_depth_range_unrestricted extension is enabled, fragment depth values are clamped even when the depth buffer uses a floating-point representation."
state.depthClamp = !state.depthFormat.isFloatFormat() || !pipelineState.hasDepthRangeUnrestricted(); state.depthClamp = pipelineDepthClamp || !state.depthFormat.isFloatFormat() || !pipelineState.hasDepthRangeUnrestricted();
if(pipelineDepthClamp)
{
const VkViewport viewport = pipelineState.getViewport();
state.minDepthClamp = min(viewport.minDepth, viewport.maxDepth);
state.maxDepthClamp = max(viewport.minDepth, viewport.maxDepth);
}
else if(state.depthClamp)
{
state.minDepthClamp = 0.0f;
state.maxDepthClamp = 1.0f;
}
} }
state.depthBoundsTestActive = pipelineState.depthBoundsTestActive(); state.depthBoundsTestActive = pipelineState.depthBoundsTestActive();
......
...@@ -98,6 +98,9 @@ public: ...@@ -98,6 +98,9 @@ public:
vk::Format depthFormat; vk::Format depthFormat;
bool depthBias; bool depthBias;
bool depthClamp; bool depthClamp;
float minDepthClamp;
float maxDepthClamp;
}; };
struct State : States struct State : States
......
...@@ -129,7 +129,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu ...@@ -129,7 +129,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
if(state.depthClamp) if(state.depthClamp)
{ {
z[q] = Min(Max(z[q], Float4(0.0f)), Float4(1.0f)); z[q] = Min(Max(z[q], Float4(state.minDepthClamp)), Float4(state.maxDepthClamp));
} }
} }
} }
......
...@@ -46,7 +46,7 @@ const VkPhysicalDeviceFeatures &PhysicalDevice::getFeatures() const ...@@ -46,7 +46,7 @@ const VkPhysicalDeviceFeatures &PhysicalDevice::getFeatures() const
VK_FALSE, // logicOp VK_FALSE, // logicOp
VK_TRUE, // multiDrawIndirect VK_TRUE, // multiDrawIndirect
VK_TRUE, // drawIndirectFirstInstance VK_TRUE, // drawIndirectFirstInstance
VK_FALSE, // depthClamp VK_TRUE, // depthClamp
VK_TRUE, // depthBiasClamp VK_TRUE, // depthBiasClamp
VK_TRUE, // fillModeNonSolid VK_TRUE, // fillModeNonSolid
VK_TRUE, // depthBounds VK_TRUE, // depthBounds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment