From b26838ed37c8cc9896c85f0efb415842165bc250 Mon Sep 17 00:00:00 2001 From: Valentine Burley Date: Mon, 9 Mar 2026 19:32:10 +0100 Subject: [PATCH] tu: Add support for VK_EXT_depth_clamp_control Wire up the existing runtime plumbing to the z-clamp registers. Test: dEQP-VK.draw.*clamp_control* Signed-off-by: Valentine Burley Part-of: --- docs/features.txt | 2 +- src/freedreno/vulkan/tu_device.cc | 4 ++++ src/freedreno/vulkan/tu_pipeline.cc | 12 +++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index 0d25e65cf8c..b3a1b7eefd0 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -613,7 +613,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_debug_report DONE (anv, dzn, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv, vn) VK_EXT_debug_utils DONE (anv, dzn, hasvk, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv, vn) VK_EXT_depth_bias_control DONE (anv, hk, lvp, nvk, panvk, radv, vn) - VK_EXT_depth_clamp_control DONE (anv, hasvk, nvk, panvk, radv, vn) + VK_EXT_depth_clamp_control DONE (anv, hasvk, nvk, panvk, radv, tu, vn) VK_EXT_depth_clip_control DONE (anv, hasvk, hk, lvp, nvk, panvk, radv, tu, v3dv, vn) VK_EXT_depth_clip_enable DONE (anv, hasvk, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv/vc7+, vn) VK_EXT_depth_range_unrestricted DONE (anv/gen20+, nvk, radv, lvp, vn) diff --git a/src/freedreno/vulkan/tu_device.cc b/src/freedreno/vulkan/tu_device.cc index 9bff9092562..fc0b2bc4775 100644 --- a/src/freedreno/vulkan/tu_device.cc +++ b/src/freedreno/vulkan/tu_device.cc @@ -274,6 +274,7 @@ get_device_extensions(const struct tu_physical_device *device, .EXT_conservative_rasterization = device->info->chip >= 7, .EXT_custom_border_color = true, .EXT_custom_resolve = true, + .EXT_depth_clamp_control = true, .EXT_depth_clamp_zero_one = true, .EXT_depth_clip_control = true, .EXT_depth_clip_enable = true, @@ -630,6 +631,9 @@ tu_get_features(struct tu_physical_device *pdevice, features->customBorderColors = true; features->customBorderColorWithoutFormat = true; + /* VK_EXT_depth_clamp_control */ + features->depthClampControl = true; + /* VK_KHR_depth_clamp_zero_one */ features->depthClampZeroOne = true; diff --git a/src/freedreno/vulkan/tu_pipeline.cc b/src/freedreno/vulkan/tu_pipeline.cc index 7e4df1ba499..2412d0721ce 100644 --- a/src/freedreno/vulkan/tu_pipeline.cc +++ b/src/freedreno/vulkan/tu_pipeline.cc @@ -2531,6 +2531,7 @@ static const enum mesa_vk_dynamic_graphics_state tu_viewport_state[] = { MESA_VK_DYNAMIC_VP_VIEWPORTS, MESA_VK_DYNAMIC_VP_VIEWPORT_COUNT, MESA_VK_DYNAMIC_VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE, + MESA_VK_DYNAMIC_VP_DEPTH_CLAMP_RANGE, MESA_VK_DYNAMIC_RS_DEPTH_CLAMP_ENABLE, }; @@ -2636,12 +2637,17 @@ tu6_emit_viewport(struct tu_cs *cs, for (uint32_t i = 0; i < vp->viewport_count; i++) { const VkViewport *viewport = &vp->viewports[i]; - float zmin = MIN2(viewport->minDepth, viewport->maxDepth); - float zmax = MAX2(viewport->minDepth, viewport->maxDepth); + float zmin, zmax; - if (zero_one_depth_clamp) { + if (vp->depth_clamp_mode == VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT) { + zmin = vp->depth_clamp_range.minDepthClamp; + zmax = vp->depth_clamp_range.maxDepthClamp; + } else if (zero_one_depth_clamp) { zmin = 0.0f; zmax = 1.0f; + } else { + zmin = MIN2(viewport->minDepth, viewport->maxDepth); + zmax = MAX2(viewport->minDepth, viewport->maxDepth); } crb.add(GRAS_CL_VIEWPORT_ZCLAMP_MIN(CHIP, i, zmin));