From 5803786beb4a7c1c95ccd96929b16143060dd663 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Tue, 31 Jan 2023 18:18:46 +1300 Subject: [PATCH] Move UseVertexDepthRange() out of Renderer There wasn't really a good place for it, but this will do --- Source/Core/VideoCommon/BPFunctions.cpp | 3 ++- Source/Core/VideoCommon/RenderBase.cpp | 20 ----------------- Source/Core/VideoCommon/RenderBase.h | 2 -- .../Core/VideoCommon/VertexShaderManager.cpp | 22 ++++++++++++++++++- Source/Core/VideoCommon/VertexShaderManager.h | 4 ++++ 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Source/Core/VideoCommon/BPFunctions.cpp b/Source/Core/VideoCommon/BPFunctions.cpp index 5bd4ab241c..ad9898b27e 100644 --- a/Source/Core/VideoCommon/BPFunctions.cpp +++ b/Source/Core/VideoCommon/BPFunctions.cpp @@ -18,6 +18,7 @@ #include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderState.h" #include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" #include "VideoCommon/XFMemory.h" @@ -246,7 +247,7 @@ void SetScissorAndViewport() max_depth = std::clamp(max_depth, 0.0f, GX_MAX_DEPTH); } - if (g_renderer->UseVertexDepthRange()) + if (VertexShaderManager::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. diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index f09dfcc048..61820e0c82 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -31,7 +31,6 @@ #include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" -#include "VideoCommon/XFMemory.h" std::unique_ptr g_renderer; @@ -141,22 +140,3 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num } } } - -bool Renderer::UseVertexDepthRange() -{ - // 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; - - // We need a full depth range if a ztexture is used. - if (bpmem.ztex2.op != ZTexOp::Disabled && !bpmem.zcontrol.early_ztest) - 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 0306a00e65..23e6895553 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -34,8 +34,6 @@ public: virtual u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data); virtual void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points); - - static bool UseVertexDepthRange(); }; extern std::unique_ptr g_renderer; diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 4177f3b834..817b7e5aa9 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -158,6 +158,26 @@ void VertexShaderManager::SetProjectionMatrix() } } +bool VertexShaderManager::UseVertexDepthRange() +{ + // 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; + + // We need a full depth range if a ztexture is used. + if (bpmem.ztex2.op != ZTexOp::Disabled && !bpmem.zcontrol.early_ztest) + 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; +} + + // Syncs the shader constant buffers with xfmem // TODO: A cleaner way to control the matrices without making a mess in the parameters field void VertexShaderManager::SetConstants(const std::vector& textures) @@ -356,7 +376,7 @@ void VertexShaderManager::SetConstants(const std::vector& textures) constants.viewport[0] = (2.f * xfmem.viewport.wd); constants.viewport[1] = (2.f * xfmem.viewport.ht); - if (g_renderer->UseVertexDepthRange()) + if (UseVertexDepthRange()) { // Oversized depth ranges are handled in the vertex shader. We need to reverse // the far value to use the reversed-Z trick. diff --git a/Source/Core/VideoCommon/VertexShaderManager.h b/Source/Core/VideoCommon/VertexShaderManager.h index 9a150980da..3b22d43aeb 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.h +++ b/Source/Core/VideoCommon/VertexShaderManager.h @@ -44,9 +44,13 @@ public: // (i.e. VertexShaderManager::SetConstants needs to be called before using this!) void TransformToClipSpace(const float* data, float* out, u32 mtxIdx); + static bool UseVertexDepthRange(); + VertexShaderConstants constants{}; bool dirty = false; + + private: alignas(16) std::array m_projection_matrix;