From ef789410429d0fc20a68fd8f7aca0ecc42695bf6 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 16 May 2015 21:25:52 +0200 Subject: [PATCH] VideoBackends: Clamp depth to uint24 range. --- Source/Core/VideoBackends/D3D/Render.cpp | 4 ++-- Source/Core/VideoBackends/OGL/Render.cpp | 4 ++-- Source/Core/VideoBackends/Software/Rasterizer.cpp | 4 +--- Source/Core/VideoCommon/PixelShaderManager.cpp | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index f11749d868..db841e5dd0 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -523,8 +523,8 @@ void Renderer::SetViewport() Ht = (Y + Ht <= GetTargetHeight()) ? Ht : (GetTargetHeight() - Y); D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht, - std::max(0.0f, std::min(1.0f, (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f)), - std::max(0.0f, std::min(1.0f, xfmem.viewport.farZ / 16777216.0f))); + MathUtil::Clamp(xfmem.viewport.farZ - xfmem.viewport.zRange, 0.0f, 16777215.0f) / 16777216.0f, + MathUtil::Clamp(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f); D3D::context->RSSetViewports(1, &vp); } diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 5fe2711845..1b13595386 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1217,8 +1217,8 @@ void Renderer::SetViewport() float Y = EFBToScaledYf((float)EFB_HEIGHT - xfmem.viewport.yOrig + xfmem.viewport.ht + (float)scissorYOff); float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd); float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht); - float GLNear = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f; - float GLFar = xfmem.viewport.farZ / 16777216.0f; + float GLNear = MathUtil::Clamp(xfmem.viewport.farZ - xfmem.viewport.zRange, 0.0f, 16777215.0f) / 16777216.0f; + float GLFar = MathUtil::Clamp(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f; if (Width < 0) { X += Width; diff --git a/Source/Core/VideoBackends/Software/Rasterizer.cpp b/Source/Core/VideoBackends/Software/Rasterizer.cpp index c03062134b..b7877dcaaa 100644 --- a/Source/Core/VideoBackends/Software/Rasterizer.cpp +++ b/Source/Core/VideoBackends/Software/Rasterizer.cpp @@ -127,9 +127,7 @@ inline void Draw(s32 x, s32 y, s32 xi, s32 yi) float dx = vertexOffsetX + (float)(x - vertex0X); float dy = vertexOffsetY + (float)(y - vertex0Y); - s32 z = (s32)ZSlope.GetValue(dx, dy); - if (z < 0 || z > 0x00ffffff) - return; + s32 z = (s32)MathUtil::Clamp(ZSlope.GetValue(dx, dy), 0.0f, 16777215.0f); if (!BoundingBox::active && bpmem.UseEarlyDepthTest() && g_SWVideoConfig.bZComploc) { diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index 77d92d0156..ac9728b7cd 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -96,8 +96,8 @@ void PixelShaderManager::SetConstants() if (s_bViewPortChanged) { - constants.zbias[1][0] = static_cast(xfmem.viewport.farZ); - constants.zbias[1][1] = static_cast(xfmem.viewport.zRange); + constants.zbias[1][0] = MathUtil::Clamp((u32)xfmem.viewport.farZ, 0, 0xFFFFFF); + constants.zbias[1][1] = MathUtil::Clamp((u32)xfmem.viewport.zRange, 0, 0xFFFFFF); dirty = true; s_bViewPortChanged = false; }