From 49854dbfba28f30ce98e2e9cc17574d4a4c3e4c6 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Tue, 27 Sep 2022 18:52:12 -0230 Subject: [PATCH] [d3d9] Saturate viewport depth range Viewport depth range in D3D9 is clamped at 0-1, same as OpenGL. Drivers like RADV, etc support VK_EXT_depth_range_unrestricted, which makes the regular UB of this actually work -- which isn't what we want. We also don't enable VK_EXT_depth_range_unrestricted, so we shouldn't be setting depth ranges outside of the 0-1 bounds anyway. Closes: #2960 --- src/d3d9/d3d9_device.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 3e5cd6ee6..536c6331a 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -5636,7 +5636,8 @@ namespace dxvk { viewport = VkViewport{ float(vp.X) + cf, float(vp.Height + vp.Y) + cf, float(vp.Width), -float(vp.Height), - vp.MinZ, std::max(vp.MaxZ, vp.MinZ + zBias), + std::clamp(vp.MinZ, 0.0f, 1.0f), + std::clamp(std::max(vp.MaxZ, vp.MinZ + zBias), 0.0f, 1.0f), }; // Scissor rectangles. Vulkan does not provide an easy way