From 30c44934e73ab575a2866ad36a48857134dafb0f Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Wed, 29 Jul 2026 01:52:30 -0400 Subject: [PATCH] [TEST] Debug depths on viewports --- .../renderer_vulkan/vk_rasterizer.cpp | 23 +++++++++++++++++-- .../vulkan_common/vulkan_device.cpp | 6 +++++ src/video_core/vulkan_common/vulkan_device.h | 6 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 297defeba0..c58f8dc5fe 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -102,8 +103,26 @@ VkViewport GetViewportState(const Device& device, const Maxwell& regs, size_t in .maxDepth = src.translate_z + src.scale_z, }; if (!device.IsExtDepthRangeUnrestrictedSupported()) { - viewport.minDepth = std::clamp(viewport.minDepth, 0.0f, 1.0f); - viewport.maxDepth = std::clamp(viewport.maxDepth, 0.0f, 1.0f); + const float requested_min = viewport.minDepth; + const float requested_max = viewport.maxDepth; + viewport.minDepth = std::clamp(requested_min, 0.0f, 1.0f); + viewport.maxDepth = std::clamp(requested_max, 0.0f, 1.0f); + if (viewport.minDepth != requested_min || viewport.maxDepth != requested_max) { + static float last_min = std::numeric_limits::quiet_NaN(); + static float last_max = std::numeric_limits::quiet_NaN(); + if (requested_min != last_min || requested_max != last_max) { + last_min = requested_min; + last_max = requested_max; + LOG_WARNING(Render_Vulkan, + "Viewport {} depth range squashed: requested [{}, {}] applied [{}, {}] " + "translate_z={} scale_z={} depth_mode={} clamp_zero_one={}", + index, requested_min, requested_max, viewport.minDepth, + viewport.maxDepth, src.translate_z, src.scale_z, + regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? "MinusOneToOne" + : "ZeroToOne", + device.IsExtDepthClampZeroOneSupported()); + } + } } return viewport; } diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index 6de1e4ce3e..8ad2385bf1 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp @@ -1231,6 +1231,12 @@ void Device::RemoveUnsuitableExtensions() { RemoveExtensionFeatureIfUnsuitable(extensions.depth_bias_control, features.depth_bias_control, VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME); + // VK_EXT_depth_clamp_zero_one + extensions.depth_clamp_zero_one = features.depth_clamp_zero_one.depthClampZeroOne; + RemoveExtensionFeatureIfUnsuitable(extensions.depth_clamp_zero_one, + features.depth_clamp_zero_one, + VK_EXT_DEPTH_CLAMP_ZERO_ONE_EXTENSION_NAME); + // VK_EXT_depth_clip_control extensions.depth_clip_control = features.depth_clip_control.depthClipControl; RemoveExtensionFeatureIfUnsuitable(extensions.depth_clip_control, features.depth_clip_control, diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index 47a3af8e0c..993282f83f 100644 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h @@ -54,6 +54,7 @@ VK_DEFINE_HANDLE(VmaAllocator) FEATURE(EXT, ColorWriteEnable, COLOR_WRITE_ENABLE, color_write_enable) \ FEATURE(EXT, CustomBorderColor, CUSTOM_BORDER_COLOR, custom_border_color) \ FEATURE(EXT, DepthBiasControl, DEPTH_BIAS_CONTROL, depth_bias_control) \ + FEATURE(EXT, DepthClampZeroOne, DEPTH_CLAMP_ZERO_ONE, depth_clamp_zero_one) \ FEATURE(EXT, DepthClipControl, DEPTH_CLIP_CONTROL, depth_clip_control) \ FEATURE(EXT, ExtendedDynamicState, EXTENDED_DYNAMIC_STATE, extended_dynamic_state) \ FEATURE(EXT, ExtendedDynamicState2, EXTENDED_DYNAMIC_STATE_2, extended_dynamic_state2) \ @@ -612,6 +613,11 @@ FN_MAX_LIMIT_LIST return extensions.depth_clip_control; } + /// Returns true if the device supports VK_EXT_depth_clamp_zero_one. + bool IsExtDepthClampZeroOneSupported() const { + return extensions.depth_clamp_zero_one; + } + /// Returns true if the device supports VK_EXT_depth_bias_control. bool IsExtDepthBiasControlSupported() const { return extensions.depth_bias_control;