From 28e6e259edc6828b467346d8e3f532c01791eabc Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 19 Feb 2017 16:41:04 +0100 Subject: VideoBackends: Set the maximum range when the depth range is oversized. The depth values generated by the vertex shader need to be clamped correctly. --- Source/Core/VideoBackends/OGL/Render.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index a92c4810f4..f55d06ecbc 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1123,6 +1123,24 @@ void Renderer::SetViewport() Height *= -1; } + // If an oversized depth range is used, we need to calculate the depth range in the vertex shader. + if (g_ActiveConfig.backend_info.bSupportsDepthClamp && + (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)) + { + // We need to ensure depth values are clamped the maximum value supported by the console GPU. + // Taking into account whether the depth range is inverted or not. + if (xfmem.viewport.zRange < 0.0f) + { + min_depth = GX_MAX_DEPTH; + max_depth = 0.0f; + } + else + { + min_depth = 0.0f; + max_depth = GX_MAX_DEPTH; + } + } + // Update the view port if (g_ogl_config.bSupportViewportFloat) { @@ -1134,10 +1152,7 @@ void Renderer::SetViewport() glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height)); } - // Set the reversed depth range. If we do depth clipping and depth range in the - // vertex shader we only need to ensure depth values don't exceed the maximum - // value supported by the console GPU. If not, we simply clamp the near/far values - // themselves to the maximum value as done above. + // Set the reversed depth range. glDepthRangef(max_depth, min_depth); } -- cgit v1.2.3 From 94522d4cf3f18ba0783a877a8254537f0ff383ac Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 6 Aug 2016 13:30:32 +0200 Subject: OGL: Add support for glDepthRangedNV to handle oversized depth ranges. --- Source/Core/VideoBackends/OGL/Render.cpp | 64 +++++++++++++++++++------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index f55d06ecbc..abee545ba4 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -474,6 +474,8 @@ Renderer::Renderer() // Clip distance support is useless without a method to clamp the depth range g_Config.backend_info.bSupportsDepthClamp = GLExtensions::Supports("GL_ARB_depth_clamp"); + g_Config.backend_info.bSupportsOversizedDepthRanges = + GLExtensions::Supports("GL_NV_depth_buffer_float"); g_ogl_config.bSupportsGLSLCache = GLExtensions::Supports("GL_ARB_get_program_binary"); g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory"); @@ -666,7 +668,7 @@ Renderer::Renderer() g_ogl_config.gl_renderer, g_ogl_config.gl_version), 5000); - WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s%s", + WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ", g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? "" : "PrimitiveRestart ", g_ActiveConfig.backend_info.bSupportsEarlyZ ? "" : "EarlyZ ", @@ -679,7 +681,8 @@ Renderer::Renderer() g_ActiveConfig.backend_info.bSupportsGSInstancing ? "" : "GSInstancing ", g_ActiveConfig.backend_info.bSupportsClipControl ? "" : "ClipControl ", g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ", - g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp "); + g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp ", + g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges ? "" : "DepthRangedNV "); s_last_multisamples = g_ActiveConfig.iMultisamples; s_MSAASamples = s_last_multisamples; @@ -1108,10 +1111,6 @@ void Renderer::SetViewport() (float)scissorYOff); float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd); float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht); - float range = MathUtil::Clamp(xfmem.viewport.zRange, -16777215.0f, 16777215.0f); - float min_depth = - MathUtil::Clamp(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f; - float max_depth = MathUtil::Clamp(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f; if (Width < 0) { X += Width; @@ -1123,24 +1122,6 @@ void Renderer::SetViewport() Height *= -1; } - // If an oversized depth range is used, we need to calculate the depth range in the vertex shader. - if (g_ActiveConfig.backend_info.bSupportsDepthClamp && - (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)) - { - // We need to ensure depth values are clamped the maximum value supported by the console GPU. - // Taking into account whether the depth range is inverted or not. - if (xfmem.viewport.zRange < 0.0f) - { - min_depth = GX_MAX_DEPTH; - max_depth = 0.0f; - } - else - { - min_depth = 0.0f; - max_depth = GX_MAX_DEPTH; - } - } - // Update the view port if (g_ogl_config.bSupportViewportFloat) { @@ -1153,7 +1134,40 @@ void Renderer::SetViewport() } // Set the reversed depth range. - glDepthRangef(max_depth, min_depth); + 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); + } + else + { + float range = MathUtil::Clamp(xfmem.viewport.zRange, -16777216.0f, 16777216.0f); + float min_depth = + MathUtil::Clamp(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f; + float max_depth = MathUtil::Clamp(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 + // vertex shader. + if (g_ActiveConfig.backend_info.bSupportsDepthClamp && + (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)) + { + // We need to ensure depth values are clamped the maximum value supported by the console GPU. + // Taking into account whether the depth range is inverted or not. + if (xfmem.viewport.zRange < 0.0f) + { + min_depth = GX_MAX_DEPTH; + max_depth = 0.0f; + } + else + { + min_depth = 0.0f; + max_depth = GX_MAX_DEPTH; + } + } + + glDepthRangef(max_depth, min_depth); + } } void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, -- cgit v1.2.3 From bde81269130c31c93cbb0f0f3ac8f23560751cac Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Tue, 21 Feb 2017 16:15:22 +0100 Subject: VideoBackends: Remove depth range clamping hacks. Oversized depth ranges are handled correctly now, we don't need to hack around them with clamps anymore. --- Source/Core/VideoBackends/OGL/Render.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index abee545ba4..f8405250d7 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1111,6 +1111,8 @@ void Renderer::SetViewport() (float)scissorYOff); float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd); 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) { X += Width; @@ -1136,17 +1138,10 @@ void Renderer::SetViewport() // Set the reversed depth range. 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); } else { - float range = MathUtil::Clamp(xfmem.viewport.zRange, -16777216.0f, 16777216.0f); - float min_depth = - MathUtil::Clamp(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f; - float max_depth = MathUtil::Clamp(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 // vertex shader. if (g_ActiveConfig.backend_info.bSupportsDepthClamp && @@ -1165,6 +1160,13 @@ void Renderer::SetViewport() 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); } -- cgit v1.2.3 From a15555fe0304e1ba560f91f8bacc8b121d226d1c Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 24 Feb 2017 15:16:28 +0100 Subject: VideoBackends: Use vertex shader depth range if ztexture is used. --- Source/Core/VideoBackends/OGL/Render.cpp | 45 ++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/Render.cpp') diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index f8405250d7..ee7d37bb67 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1135,41 +1135,36 @@ void Renderer::SetViewport() glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height)); } - // Set the reversed depth range. - if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) + if (!g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges && + !g_ActiveConfig.backend_info.bSupportsDepthClamp) { - glDepthRangedNV(max_depth, min_depth); + // 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); } - else + + if (UseVertexDepthRange()) { - // If an oversized depth range is used, we need to calculate the depth range in the - // vertex shader. - if (g_ActiveConfig.backend_info.bSupportsDepthClamp && - (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)) + // We need to ensure depth values are clamped the maximum value supported by the console GPU. + // Taking into account whether the depth range is inverted or not. + if (xfmem.viewport.zRange < 0.0f) { - // We need to ensure depth values are clamped the maximum value supported by the console GPU. - // Taking into account whether the depth range is inverted or not. - if (xfmem.viewport.zRange < 0.0f) - { - min_depth = GX_MAX_DEPTH; - max_depth = 0.0f; - } - else - { - min_depth = 0.0f; - max_depth = GX_MAX_DEPTH; - } + min_depth = GX_MAX_DEPTH; + max_depth = 0.0f; } 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); + min_depth = 0.0f; + max_depth = GX_MAX_DEPTH; } + } + // Set the reversed depth range. + if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) + glDepthRangedNV(max_depth, min_depth); + else glDepthRangef(max_depth, min_depth); - } } void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, -- cgit v1.2.3