diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index a30d70b4c9..928c8c8196 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -109,6 +109,7 @@ + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index e68660d752..b6dd7d27e0 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -226,6 +226,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/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index f937ed60b4..b082963820 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -546,10 +546,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; @@ -561,10 +559,11 @@ 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 (UseVertexDepthRange()) { + // 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/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index 2fc00dc037..eb7048a311 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -66,6 +66,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/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index e5ca00bd7e..da5e48c053 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -454,10 +454,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; @@ -469,10 +467,11 @@ 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 (UseVertexDepthRange()) { + // 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/main.cpp b/Source/Core/VideoBackends/D3D12/main.cpp index bae916e0f8..11ead5a4e1 100644 --- a/Source/Core/VideoBackends/D3D12/main.cpp +++ b/Source/Core/VideoBackends/D3D12/main.cpp @@ -69,6 +69,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 1fe0914a91..b4d85eee65 100644 --- a/Source/Core/VideoBackends/Null/NullBackend.cpp +++ b/Source/Core/VideoBackends/Null/NullBackend.cpp @@ -29,6 +29,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 621c21c539..391fa7d2bd 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -437,6 +437,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"); @@ -625,7 +627,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 ", @@ -638,7 +640,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; @@ -1052,10 +1055,8 @@ 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; + float min_depth = (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f; + float max_depth = xfmem.viewport.farZ / 16777216.0f; if (Width < 0) { X += Width; @@ -1078,11 +1079,36 @@ 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. - glDepthRangef(max_depth, min_depth); + if (!g_ActiveConfig.backend_info.bSupportsOversizedDepthRanges && + !g_ActiveConfig.backend_info.bSupportsDepthClamp) + { + // 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); + } + + if (UseVertexDepthRange()) + { + // 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; + } + } + + // 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/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index 3be16a6cbf..f2901caa20 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -109,6 +109,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 96ebdd8adb..b98eb0955f 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -129,6 +129,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/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index d44317b3de..0a65290dd0 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -1628,10 +1628,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; @@ -1643,11 +1641,12 @@ 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 (UseVertexDepthRange()) { + // 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/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 1487e09afc..43051d4099 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/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 8384080099..774754839b 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 1c99e51950..87b3a5314a 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -926,3 +926,32 @@ 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; + + 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 ztexture_enabled; + } + else + { + // We need a full depth range if a ztexture is used. + if (ztexture_enabled) + 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 b1291adf0d..93c22f6202 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -140,6 +140,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: 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 4c3959d92d..36bace7426 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -391,39 +391,27 @@ void VertexShaderManager::SetConstants() constants.pixelcentercorrection[2] = 1.0f; constants.pixelcentercorrection[3] = 0.0f; - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + 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; } } diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index ec79e6de48..d62334df8e 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -179,6 +179,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