Commit afbc899f by Nicolas Capens Committed by Nicolas Capens

Implement VK_EXT_depth_range_unrestricted

This extension allows the viewport's minimum and maximum depth to be outside of the 0.0 to 1.0 range: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_depth_range_unrestricted.html Note that while most extensions don't change the behavior of the logical device whether they're enabled or not (since they just allow new calls, enums, or values which are otherwise undefined behavior and implementing the functionality of the extension is valid as "undefined" behavior), enabling/disabling this extension does cause an observable difference. Bug: b/163135814 Tests: dEQP-VK.*depth_range_unrestricted* Change-Id: I418a2e7226140719af08601d8919f4cdbc7a237c Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/47608 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com>
parent 72ea2ee4
......@@ -104,6 +104,7 @@ public:
float depthBias;
float slopeDepthBias;
float depthBiasClamp;
bool depthRangeUnrestricted;
VkFormat renderTargetInternalFormat(int index) const;
int colorWriteActive(int index) const;
......
......@@ -115,6 +115,10 @@ const PixelProcessor::State PixelProcessor::update(const Context *context) const
state.depthTestActive = true;
state.depthCompareMode = context->depthCompareMode;
state.depthFormat = context->depthBuffer->getFormat();
// "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."
state.depthClamp = !state.depthFormat.isFloatFormat() || !context->depthRangeUnrestricted;
}
state.occlusionEnabled = context->occlusionEnabled;
......
......@@ -92,7 +92,8 @@ public:
bool alphaToCoverage;
bool centroid;
VkFrontFace frontFace;
VkFormat depthFormat;
vk::Format depthFormat;
bool depthClamp;
};
struct State : States
......
......@@ -90,7 +90,7 @@ void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBu
x -= *Pointer<Float4>(constants + OFFSET(Constants, X) + q * sizeof(float4));
}
z[q] = interpolate(x, Dz[q], z[q], primitive + OFFSET(Primitive, z), false, false, true);
z[q] = interpolate(x, Dz[q], z[q], primitive + OFFSET(Primitive, z), false, false, state.depthClamp);
}
}
......
......@@ -261,6 +261,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo *pCreateIn
context.depthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasConstantFactor : 0.0f;
context.slopeDepthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasSlopeFactor : 0.0f;
context.depthBiasClamp = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasClamp : 0.0f;
context.depthRangeUnrestricted = device->hasExtension(VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME);
// From the Vulkan spec for vkCmdSetDepthBias:
// The bias value O for a polygon is:
......
......@@ -378,6 +378,7 @@ static const VkExtensionProperties deviceExtensionProperties[] = {
#endif
{ VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME, VK_EXT_PROVOKING_VERTEX_SPEC_VERSION },
{ VK_GOOGLE_SAMPLER_FILTERING_PRECISION_EXTENSION_NAME, VK_GOOGLE_SAMPLER_FILTERING_PRECISION_SPEC_VERSION },
{ VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, VK_EXT_DEPTH_RANGE_UNRESTRICTED_SPEC_VERSION }
};
static bool hasExtension(const char *extensionName, const VkExtensionProperties *extensionProperties, uint32_t extensionPropertiesCount)
......
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