From 28e6e259edc6828b467346d8e3f532c01791eabc Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 19 Feb 2017 16:41:04 +0100 Subject: [PATCH 1/5] 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/D3D/Render.cpp | 8 ++++--- Source/Core/VideoBackends/D3D12/Render.cpp | 8 ++++--- Source/Core/VideoBackends/OGL/Render.cpp | 23 +++++++++++++++---- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 11 +++++---- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index bf1500ab0f..431690ca25 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -576,10 +576,12 @@ void Renderer::SetViewport() Ht = -Ht; } - // If an inverted depth range is used, which D3D doesn't support, - // we need to calculate the depth range in the vertex shader. - if (xfmem.viewport.zRange < 0.0f) + // If an inverted or oversized depth range is used, we need to calculate the depth range in the + // vertex shader. + if (xfmem.viewport.zRange < 0.0f || 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. min_depth = 0.0f; max_depth = GX_MAX_DEPTH; } diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index 812a0adf11..d72ab7497a 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -481,10 +481,12 @@ void Renderer::SetViewport() height = -height; } - // If an inverted depth range is used, which D3D doesn't support, - // we need to calculate the depth range in the vertex shader. - if (xfmem.viewport.zRange < 0.0f) + // If an inverted or oversized depth range is used, we need to calculate the depth range in the + // vertex shader. + if (xfmem.viewport.zRange < 0.0f || 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. min_depth = 0.0f; max_depth = GX_MAX_DEPTH; } 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); } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index 77f6fd3453..765601b329 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -4,6 +4,7 @@ #include "VideoBackends/Vulkan/Renderer.h" +#include #include #include #include @@ -1655,11 +1656,13 @@ void Renderer::SetViewport() height = -height; } - // If an inverted depth range is used, which the Vulkan drivers don't - // support, we need to calculate the depth range in the vertex shader. - // TODO: Make this into a DriverDetails bug and write a test for CTS. - if (xfmem.viewport.zRange < 0.0f) + // If an oversized or inverted depth range is used, we need to calculate the depth range in the + // vertex shader. + // TODO: Inverted depth ranges are bugged in all drivers, which should be added to DriverDetails. + if (xfmem.viewport.zRange < 0.0f || 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. min_depth = 0.0f; max_depth = GX_MAX_DEPTH; } From 94522d4cf3f18ba0783a877a8254537f0ff383ac Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sat, 6 Aug 2016 13:30:32 +0200 Subject: [PATCH 2/5] OGL: Add support for glDepthRangedNV to handle oversized depth ranges. --- Source/Core/Common/Common.vcxproj | 1 + Source/Core/Common/Common.vcxproj.filters | 3 + .../Common/GL/GLExtensions/GLExtensions.cpp | 23 ++++--- .../Common/GL/GLExtensions/GLExtensions.h | 1 + .../GL/GLExtensions/NV_depth_buffer_float.h | 41 ++++++++++++ Source/Core/Core/Analytics.cpp | 2 + Source/Core/VideoBackends/D3D/main.cpp | 1 + Source/Core/VideoBackends/D3D12/main.cpp | 1 + .../Core/VideoBackends/Null/NullBackend.cpp | 1 + Source/Core/VideoBackends/OGL/Render.cpp | 64 +++++++++++-------- Source/Core/VideoBackends/OGL/main.cpp | 1 + Source/Core/VideoBackends/Software/SWmain.cpp | 1 + .../VideoBackends/Vulkan/VulkanContext.cpp | 19 +++--- .../Core/VideoCommon/VertexShaderManager.cpp | 3 +- Source/Core/VideoCommon/VideoConfig.h | 1 + 15 files changed, 119 insertions(+), 44 deletions(-) create mode 100644 Source/Core/Common/GL/GLExtensions/NV_depth_buffer_float.h diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 831dcad4a7..b4a0f1fba5 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -105,6 +105,7 @@ + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 3c9b952742..77d639045a 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -218,6 +218,9 @@ GL\GLExtensions + + GL\GLExtensions + GL\GLInterface diff --git a/Source/Core/Common/GL/GLExtensions/GLExtensions.cpp b/Source/Core/Common/GL/GLExtensions/GLExtensions.cpp index 591792468e..ff252bb1f7 100644 --- a/Source/Core/Common/GL/GLExtensions/GLExtensions.cpp +++ b/Source/Core/Common/GL/GLExtensions/GLExtensions.cpp @@ -984,6 +984,11 @@ PFNDOLCOPYIMAGESUBDATAPROC dolCopyImageSubData; // ARB_shader_storage_buffer_object PFNDOLSHADERSTORAGEBLOCKBINDINGPROC dolShaderStorageBlockBinding; +// NV_depth_buffer_float +PFNDOLDEPTHRANGEDNVPROC dolDepthRangedNV; +PFNDOLCLEARDEPTHDNVPROC dolClearDepthdNV; +PFNDOLDEPTHBOUNDSDNVPROC dolDepthBoundsdNV; + // Creates a GLFunc object that requires a feature #define GLFUNC_REQUIRES(x, y) \ { \ @@ -1838,6 +1843,11 @@ const GLFunc gl_function_array[] = { // ARB_shader_storage_buffer_object GLFUNC_REQUIRES(glShaderStorageBlockBinding, "ARB_shader_storage_buffer_object !VERSION_4_3"), + + // NV_depth_buffer_float + GLFUNC_REQUIRES(glDepthRangedNV, "GL_NV_depth_buffer_float"), + GLFUNC_REQUIRES(glClearDepthdNV, "GL_NV_depth_buffer_float"), + GLFUNC_REQUIRES(glDepthBoundsdNV, "GL_NV_depth_buffer_float"), }; namespace GLExtensions @@ -2060,26 +2070,21 @@ static void InitExtensionList() // Quite a lot of these had their names changed when merged in to core // Disable the ones that have std::string gl300exts[] = { - "GL_ARB_map_buffer_range", + "GL_ARB_map_buffer_range", "GL_ARB_color_buffer_float", "GL_ARB_texture_float", + "GL_ARB_half_float_pixel", "GL_ARB_framebuffer_object", "GL_ARB_texture_float", + "GL_ARB_vertex_array_object", "GL_NV_depth_buffer_float", + //"GL_EXT_texture_integer", //"GL_EXT_gpu_shader4", //"GL_APPLE_flush_buffer_range", - "GL_ARB_color_buffer_float", - //"GL_NV_depth_buffer_float", - "GL_ARB_texture_float", //"GL_EXT_packed_float", //"GL_EXT_texture_shared_exponent", - "GL_ARB_half_float_pixel", //"GL_NV_half_float", - "GL_ARB_framebuffer_object", //"GL_EXT_framebuffer_sRGB", - "GL_ARB_texture_float", - //"GL_EXT_texture_integer", //"GL_EXT_draw_buffers2", //"GL_EXT_texture_integer", //"GL_EXT_texture_array", //"GL_EXT_texture_compression_rgtc", //"GL_EXT_transform_feedback", - "GL_ARB_vertex_array_object", //"GL_NV_conditional_render", "VERSION_3_0", }; diff --git a/Source/Core/Common/GL/GLExtensions/GLExtensions.h b/Source/Core/Common/GL/GLExtensions/GLExtensions.h index fa00aa4a97..4c58167700 100644 --- a/Source/Core/Common/GL/GLExtensions/GLExtensions.h +++ b/Source/Core/Common/GL/GLExtensions/GLExtensions.h @@ -31,6 +31,7 @@ #include "Common/GL/GLExtensions/EXT_texture_filter_anisotropic.h" #include "Common/GL/GLExtensions/HP_occlusion_test.h" #include "Common/GL/GLExtensions/KHR_debug.h" +#include "Common/GL/GLExtensions/NV_depth_buffer_float.h" #include "Common/GL/GLExtensions/NV_occlusion_query_samples.h" #include "Common/GL/GLExtensions/NV_primitive_restart.h" #include "Common/GL/GLExtensions/gl_1_1.h" diff --git a/Source/Core/Common/GL/GLExtensions/NV_depth_buffer_float.h b/Source/Core/Common/GL/GLExtensions/NV_depth_buffer_float.h new file mode 100644 index 0000000000..7912c55ba2 --- /dev/null +++ b/Source/Core/Common/GL/GLExtensions/NV_depth_buffer_float.h @@ -0,0 +1,41 @@ +/* +** Copyright (c) 2013-2015 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#include "Common/GL/GLExtensions/gl_common.h" + +#define GL_DEPTH_COMPONENT32F_NV 0x8DAB +#define GL_DEPTH32F_STENCIL8_NV 0x8DAC +#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD +#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF + +typedef void(APIENTRYP PFNDOLDEPTHRANGEDNVPROC)(GLdouble zNear, GLdouble zFar); +typedef void(APIENTRYP PFNDOLCLEARDEPTHDNVPROC)(GLdouble depth); +typedef void(APIENTRYP PFNDOLDEPTHBOUNDSDNVPROC)(GLdouble zmin, GLdouble zmax); + +extern PFNDOLDEPTHRANGEDNVPROC dolDepthRangedNV; +extern PFNDOLCLEARDEPTHDNVPROC dolClearDepthdNV; +extern PFNDOLDEPTHBOUNDSDNVPROC dolDepthBoundsdNV; + +#define glDepthRangedNV dolDepthRangedNV +#define glClearDepthdNV dolClearDepthdNV +#define glDepthBoundsdNV dolDepthBoundsdNV diff --git a/Source/Core/Core/Analytics.cpp b/Source/Core/Core/Analytics.cpp index 8638b79dba..7c71446565 100644 --- a/Source/Core/Core/Analytics.cpp +++ b/Source/Core/Core/Analytics.cpp @@ -234,6 +234,8 @@ void DolphinAnalytics::MakePerGameBuilder() builder.AddData("gpu-has-dual-source-blend", g_Config.backend_info.bSupportsDualSourceBlend); builder.AddData("gpu-has-primitive-restart", g_Config.backend_info.bSupportsPrimitiveRestart); builder.AddData("gpu-has-oversized-viewports", g_Config.backend_info.bSupportsOversizedViewports); + builder.AddData("gpu-has-oversized-depth-ranges", + g_Config.backend_info.bSupportsOversizedDepthRanges); builder.AddData("gpu-has-geometry-shaders", g_Config.backend_info.bSupportsGeometryShaders); builder.AddData("gpu-has-3d-vision", g_Config.backend_info.bSupports3DVision); builder.AddData("gpu-has-early-z", g_Config.backend_info.bSupportsEarlyZ); diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index fe32d89603..4f2a32d32e 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -64,6 +64,7 @@ void VideoBackend::InitBackendInfo() g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsPrimitiveRestart = true; g_Config.backend_info.bSupportsOversizedViewports = false; + g_Config.backend_info.bSupportsOversizedDepthRanges = false; g_Config.backend_info.bSupportsGeometryShaders = true; g_Config.backend_info.bSupports3DVision = true; g_Config.backend_info.bSupportsPostProcessing = false; diff --git a/Source/Core/VideoBackends/D3D12/main.cpp b/Source/Core/VideoBackends/D3D12/main.cpp index ef377bab41..7d903bae63 100644 --- a/Source/Core/VideoBackends/D3D12/main.cpp +++ b/Source/Core/VideoBackends/D3D12/main.cpp @@ -68,6 +68,7 @@ void VideoBackend::InitBackendInfo() g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsPrimitiveRestart = true; g_Config.backend_info.bSupportsOversizedViewports = false; + g_Config.backend_info.bSupportsOversizedDepthRanges = false; g_Config.backend_info.bSupportsGeometryShaders = true; g_Config.backend_info.bSupports3DVision = true; g_Config.backend_info.bSupportsPostProcessing = false; diff --git a/Source/Core/VideoBackends/Null/NullBackend.cpp b/Source/Core/VideoBackends/Null/NullBackend.cpp index 1e3117088e..854b8450a4 100644 --- a/Source/Core/VideoBackends/Null/NullBackend.cpp +++ b/Source/Core/VideoBackends/Null/NullBackend.cpp @@ -28,6 +28,7 @@ void VideoBackend::InitBackendInfo() g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsPrimitiveRestart = true; g_Config.backend_info.bSupportsOversizedViewports = true; + g_Config.backend_info.bSupportsOversizedDepthRanges = false; g_Config.backend_info.bSupportsGeometryShaders = true; g_Config.backend_info.bSupports3DVision = false; g_Config.backend_info.bSupportsEarlyZ = true; 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, diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index 0d46982cca..fa08587ca1 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -107,6 +107,7 @@ void VideoBackend::InitBackendInfo() g_Config.backend_info.bSupportsInternalResolutionFrameDumps = true; // Overwritten in Render.cpp later + g_Config.backend_info.bSupportsOversizedDepthRanges = false; g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsPrimitiveRestart = true; g_Config.backend_info.bSupportsPaletteConversion = true; diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index adbe5046b6..e840ac4921 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -128,6 +128,7 @@ void VideoSoftware::InitBackendInfo() g_Config.backend_info.bSupportsDualSourceBlend = true; g_Config.backend_info.bSupportsEarlyZ = true; g_Config.backend_info.bSupportsOversizedViewports = true; + g_Config.backend_info.bSupportsOversizedDepthRanges = true; g_Config.backend_info.bSupportsPrimitiveRestart = false; g_Config.backend_info.bSupportsMultithreading = false; g_Config.backend_info.bSupportsInternalResolutionFrameDumps = false; diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 7dc809e6b2..d3f981e5f5 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -225,15 +225,16 @@ VulkanContext::GPUList VulkanContext::EnumerateGPUs(VkInstance instance) void VulkanContext::PopulateBackendInfo(VideoConfig* config) { config->backend_info.api_type = APIType::Vulkan; - config->backend_info.bSupportsExclusiveFullscreen = false; // Currently WSI does not allow this. - config->backend_info.bSupports3DVision = false; // D3D-exclusive. - config->backend_info.bSupportsOversizedViewports = true; // Assumed support. - config->backend_info.bSupportsEarlyZ = true; // Assumed support. - config->backend_info.bSupportsPrimitiveRestart = true; // Assumed support. - config->backend_info.bSupportsBindingLayout = false; // Assumed support. - config->backend_info.bSupportsPaletteConversion = true; // Assumed support. - config->backend_info.bSupportsClipControl = true; // Assumed support. - config->backend_info.bSupportsMultithreading = true; // Assumed support. + config->backend_info.bSupportsExclusiveFullscreen = false; // Currently WSI does not allow this. + config->backend_info.bSupports3DVision = false; // D3D-exclusive. + config->backend_info.bSupportsOversizedViewports = true; // Assumed support. + config->backend_info.bSupportsOversizedDepthRanges = false; // No support yet. + config->backend_info.bSupportsEarlyZ = true; // Assumed support. + config->backend_info.bSupportsPrimitiveRestart = true; // Assumed support. + config->backend_info.bSupportsBindingLayout = false; // Assumed support. + config->backend_info.bSupportsPaletteConversion = true; // Assumed support. + config->backend_info.bSupportsClipControl = true; // Assumed support. + config->backend_info.bSupportsMultithreading = true; // Assumed support. config->backend_info.bSupportsInternalResolutionFrameDumps = true; // Assumed support. config->backend_info.bSupportsPostProcessing = false; // No support yet. config->backend_info.bSupportsDualSourceBlend = false; // Dependent on features. diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index e516c2c63c..ed8d52efb7 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -391,7 +391,8 @@ void VertexShaderManager::SetConstants() constants.pixelcentercorrection[2] = 1.0f; constants.pixelcentercorrection[3] = 0.0f; - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + if (g_ActiveConfig.backend_info.bSupportsDepthClamp && + !g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) { // Oversized depth ranges are handled in the vertex shader. We need to reverse // the far value to get a reversed depth range mapping. This is necessary diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 9e6b0180f3..2972dca664 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -172,6 +172,7 @@ struct VideoConfig final bool bSupportsDualSourceBlend; bool bSupportsPrimitiveRestart; bool bSupportsOversizedViewports; + bool bSupportsOversizedDepthRanges; bool bSupportsGeometryShaders; bool bSupports3DVision; bool bSupportsEarlyZ; // needed by PixelShaderGen, so must stay in VideoCommon From bde81269130c31c93cbb0f0f3ac8f23560751cac Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Tue, 21 Feb 2017 16:15:22 +0100 Subject: [PATCH 3/5] 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/D3D/Render.cpp | 6 ++---- Source/Core/VideoBackends/D3D12/Render.cpp | 6 ++---- Source/Core/VideoBackends/OGL/Render.cpp | 16 +++++++++------- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 6 ++---- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 431690ca25..a100fb5616 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -561,10 +561,8 @@ void Renderer::SetViewport() float Y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissorYOff); float Wd = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float Ht = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht); - float range = MathUtil::Clamp(xfmem.viewport.zRange, 0.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; + float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f; + float max_depth = xfmem.viewport.farZ / 16777216.0f; if (Wd < 0.0f) { X += Wd; diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index d72ab7497a..d5bdaeb07a 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -466,10 +466,8 @@ void Renderer::SetViewport() float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset); float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht); - float range = MathUtil::Clamp(xfmem.viewport.zRange, 0.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; + float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f; + float max_depth = xfmem.viewport.farZ / 16777216.0f; if (width < 0.0f) { x += width; 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); } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index 765601b329..ebfc755327 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -1641,10 +1641,8 @@ void Renderer::SetViewport() float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset); float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd); float height = Renderer::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; + float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f; + float max_depth = xfmem.viewport.farZ / 16777216.0f; if (width < 0.0f) { x += width; From a15555fe0304e1ba560f91f8bacc8b121d226d1c Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 24 Feb 2017 15:16:28 +0100 Subject: [PATCH 4/5] VideoBackends: Use vertex shader depth range if ztexture is used. --- Source/Core/VideoBackends/D3D/Render.cpp | 3 +- Source/Core/VideoBackends/D3D12/Render.cpp | 3 +- Source/Core/VideoBackends/OGL/Render.cpp | 47 +++++++++---------- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 4 +- Source/Core/VideoCommon/BPStructs.cpp | 2 + Source/Core/VideoCommon/RenderBase.cpp | 27 +++++++++++ Source/Core/VideoCommon/RenderBase.h | 2 + .../Core/VideoCommon/VertexShaderManager.cpp | 41 ++++++---------- 8 files changed, 69 insertions(+), 60 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index a100fb5616..15273ed719 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -576,8 +576,7 @@ void Renderer::SetViewport() // If an inverted or oversized depth range is used, we need to calculate the depth range in the // vertex shader. - if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f || - fabs(xfmem.viewport.farZ) > 16777215.0f) + if (UseVertexDepthRange()) { // We need to ensure depth values are clamped the maximum value supported by the console GPU. min_depth = 0.0f; diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index d5bdaeb07a..4d2badc2e2 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -481,8 +481,7 @@ void Renderer::SetViewport() // If an inverted or oversized depth range is used, we need to calculate the depth range in the // vertex shader. - if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f || - fabs(xfmem.viewport.farZ) > 16777215.0f) + if (UseVertexDepthRange()) { // We need to ensure depth values are clamped the maximum value supported by the console GPU. min_depth = 0.0f; 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; } - - glDepthRangef(max_depth, min_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, diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index ebfc755327..3cf8919042 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -4,7 +4,6 @@ #include "VideoBackends/Vulkan/Renderer.h" -#include #include #include #include @@ -1657,8 +1656,7 @@ void Renderer::SetViewport() // If an oversized or inverted depth range is used, we need to calculate the depth range in the // vertex shader. // TODO: Inverted depth ranges are bugged in all drivers, which should be added to DriverDetails. - if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f || - fabs(xfmem.viewport.farZ) > 16777215.0f) + if (UseVertexDepthRange()) { // We need to ensure depth values are clamped the maximum value supported by the console GPU. min_depth = 0.0f; diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 128969af52..e42f36f471 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -332,6 +332,8 @@ static void BPWritten(const BPCmd& bp) { if (bp.changes & 3) PixelShaderManager::SetZTextureTypeChanged(); + if (bp.changes & 12) + VertexShaderManager::SetViewportChanged(); #if defined(_DEBUG) || defined(DEBUGFAST) const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"}; const char* pztype[] = {"Z8", "Z16", "Z24", "?"}; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index f47288ea4e..19ec2abed2 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -940,3 +940,30 @@ void Renderer::DumpFrameToImage(const FrameDumpConfig& config) TextureToPng(config.data, config.stride, filename, config.width, config.height, false); m_frame_dump_image_counter++; } + +bool Renderer::UseVertexDepthRange() const +{ + // We can't compute the depth range in the vertex shader if we don't support depth clamp. + if (!g_ActiveConfig.backend_info.bSupportsDepthClamp) + return false; + + if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) + { + // We support oversized depth ranges, but we need a full depth range if a ztexture is used. + return bpmem.ztex2.type != ZTEXTURE_DISABLE; + } + else + { + // We need a full depth range if a ztexture is used. + if (bpmem.ztex2.type != ZTEXTURE_DISABLE) + return true; + + // If an inverted depth range is unsupported, we also need to check if the range is inverted. + if (!g_ActiveConfig.backend_info.bSupportsReversedDepthRange && xfmem.viewport.zRange < 0.0f) + return true; + + // If an oversized depth range or a ztexture is used, we need to calculate the depth range + // in the vertex shader. + return fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f; + } +} diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 46c01afb78..2be470fe38 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -145,6 +145,8 @@ public: // Final surface changing // This is called when the surface is resized (WX) or the window changes (Android). virtual void ChangeSurface(void* new_surface_handle) {} + bool UseVertexDepthRange() const; + protected: static void CalculateTargetScale(int x, int y, int* scaledX, int* scaledY); bool CalculateTargetSize(); diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index ed8d52efb7..5998fa2112 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -391,40 +391,27 @@ void VertexShaderManager::SetConstants() constants.pixelcentercorrection[2] = 1.0f; constants.pixelcentercorrection[3] = 0.0f; - if (g_ActiveConfig.backend_info.bSupportsDepthClamp && - !g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) + if (g_renderer->UseVertexDepthRange()) { // Oversized depth ranges are handled in the vertex shader. We need to reverse - // the far value to get a reversed depth range mapping. This is necessary - // because the standard depth range equation pushes all depth values towards - // the back of the depth buffer where conventionally depth buffers have the - // least precision. + // the far value to use the reversed-Z trick. if (g_ActiveConfig.backend_info.bSupportsReversedDepthRange) { - if (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f) - { - // For backends that support reversing the depth range we also support cases - // where the console also uses reversed depth with the same accuracy. We need - // to make sure the depth range is positive here and then reverse the depth in - // the backend viewport. - constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f; - if (xfmem.viewport.zRange < 0.0f) - constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f; - else - constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; - } + // Sometimes the console also tries to use the reversed-Z trick. We can only do + // that with the expected accuracy if the backend can reverse the depth range. + constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f; + if (xfmem.viewport.zRange < 0.0f) + constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f; + else + constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; } else { - if (xfmem.viewport.zRange < 0.0f || xfmem.viewport.zRange > 16777215.0f || - fabs(xfmem.viewport.farZ) > 16777215.0f) - { - // For backends that don't support reversing the depth range we can still render - // cases where the console uses reversed depth correctly. But we simply can't - // provide the same accuracy as the console. - constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; - constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; - } + // For backends that don't support reversing the depth range we can still render + // cases where the console uses the reversed-Z trick. But we simply can't provide + // the expected accuracy, which might result in z-fighting. + constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f; + constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f; } } From 3f41e6d4cf9f1a318c6d32fea4d2b422684961a3 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 10 Mar 2017 15:43:32 +0100 Subject: [PATCH 5/5] RenderBase: Check if early ztest is enabled before falling back to vertex depth range. --- Source/Core/VideoCommon/RenderBase.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 19ec2abed2..8ee4de1546 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -947,15 +947,17 @@ bool Renderer::UseVertexDepthRange() const if (!g_ActiveConfig.backend_info.bSupportsDepthClamp) return false; + const bool ztexture_enabled = bpmem.ztex2.type != ZTEXTURE_DISABLE && !bpmem.zcontrol.early_ztest; + if (g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges) { // We support oversized depth ranges, but we need a full depth range if a ztexture is used. - return bpmem.ztex2.type != ZTEXTURE_DISABLE; + return ztexture_enabled; } else { // We need a full depth range if a ztexture is used. - if (bpmem.ztex2.type != ZTEXTURE_DISABLE) + if (ztexture_enabled) return true; // If an inverted depth range is unsupported, we also need to check if the range is inverted.