VideoBackends: Remove depth range clamping hacks.

Oversized depth ranges are handled correctly now, we don't need to hack around them with clamps anymore.
This commit is contained in:
Jules Blok 2017-02-21 16:15:22 +01:00
parent 94522d4cf3
commit bde8126913
4 changed files with 15 additions and 19 deletions

View File

@ -561,10 +561,8 @@ void Renderer::SetViewport()
float Y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissorYOff); float Y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissorYOff);
float Wd = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float Wd = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float Ht = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht); float Ht = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, 0.0f, 16777215.0f); float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float min_depth = float max_depth = xfmem.viewport.farZ / 16777216.0f;
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (Wd < 0.0f) if (Wd < 0.0f)
{ {
X += Wd; X += Wd;

View File

@ -466,10 +466,8 @@ void Renderer::SetViewport()
float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset); float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset);
float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht); float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, 0.0f, 16777215.0f); float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float min_depth = float max_depth = xfmem.viewport.farZ / 16777216.0f;
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (width < 0.0f) if (width < 0.0f)
{ {
x += width; x += width;

View File

@ -1111,6 +1111,8 @@ void Renderer::SetViewport()
(float)scissorYOff); (float)scissorYOff);
float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd); float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd);
float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht); float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht);
float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float max_depth = xfmem.viewport.farZ / 16777216.0f;
if (Width < 0) if (Width < 0)
{ {
X += Width; X += Width;
@ -1136,17 +1138,10 @@ void Renderer::SetViewport()
// Set the reversed depth range. // Set the reversed depth range.
if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges)
{ {
float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float max_depth = xfmem.viewport.farZ / 16777216.0f;
glDepthRangedNV(max_depth, min_depth); glDepthRangedNV(max_depth, min_depth);
} }
else else
{ {
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f);
float min_depth =
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
// If an oversized depth range is used, we need to calculate the depth range in the // If an oversized depth range is used, we need to calculate the depth range in the
// vertex shader. // vertex shader.
if (g_ActiveConfig.backend_info.bSupportsDepthClamp && if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
@ -1165,6 +1160,13 @@ void Renderer::SetViewport()
max_depth = GX_MAX_DEPTH; max_depth = GX_MAX_DEPTH;
} }
} }
else
{
// There's no way to support oversized depth ranges in this situation. Let's just clamp the
// range to the maximum value supported by the console GPU and hope for the best.
min_depth = MathUtil::Clamp(min_depth, 0.0f, GX_MAX_DEPTH);
max_depth = MathUtil::Clamp(max_depth, 0.0f, GX_MAX_DEPTH);
}
glDepthRangef(max_depth, min_depth); glDepthRangef(max_depth, min_depth);
} }

View File

@ -1641,10 +1641,8 @@ void Renderer::SetViewport()
float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset); float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset);
float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht); float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777215.0f, 16777215.0f); float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
float min_depth = float max_depth = xfmem.viewport.farZ / 16777216.0f;
MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (width < 0.0f) if (width < 0.0f)
{ {
x += width; x += width;