From 78d22cc7a5e03817ed06002f50120bfe77efcdd3 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Wed, 11 Aug 2021 12:24:50 +0100 Subject: [PATCH] [d3d9] Avoid depth degenerate viewports --- src/d3d9/d3d9_device.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 1899df88c..d68254c7a 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -5435,12 +5435,16 @@ namespace dxvk { // Originally we did this only for powers of two // resolutions but since NEAREST filtering fixed to // truncate, we need to do this all the time now. - float cf = 0.5f - (1.0f / 128.0f); + constexpr float cf = 0.5f - (1.0f / 128.0f); + + // How much to bias MinZ by to avoid a depth + // degenerate viewport. + constexpr float zBias = 0.001f; viewport = VkViewport{ float(vp.X) + cf, float(vp.Height + vp.Y) + cf, float(vp.Width), -float(vp.Height), - vp.MinZ, vp.MaxZ, + vp.MinZ, std::max(vp.MaxZ, vp.MinZ + zBias), }; // Scissor rectangles. Vulkan does not provide an easy way