From bc360584a3a8a8902f50642496b2d1287e5088ac Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 2 Jul 2022 14:49:51 -0500 Subject: [PATCH] VideoCommon: add structures to graphics mods to allow for future adding or removing parameters with less code overhead --- Source/Core/DolphinLib.props | 1 + Source/Core/VideoCommon/CMakeLists.txt | 1 + .../Runtime/Actions/MoveAction.cpp | 26 ++++++--- .../Runtime/Actions/MoveAction.h | 4 +- .../Runtime/Actions/PrintAction.cpp | 21 ++++--- .../Runtime/Actions/PrintAction.h | 9 ++- .../Runtime/Actions/ScaleAction.cpp | 56 ++++++++++++------- .../Runtime/Actions/ScaleAction.h | 7 +-- .../Runtime/Actions/SkipAction.cpp | 24 +++++--- .../Runtime/Actions/SkipAction.h | 5 +- .../Runtime/GraphicsModAction.h | 14 ++--- .../Runtime/GraphicsModActionData.h | 29 ++++++++++ .../Runtime/GraphicsModManager.cpp | 17 +++--- Source/Core/VideoCommon/TextureCacheBase.cpp | 4 +- Source/Core/VideoCommon/VertexManagerBase.cpp | 4 +- .../Core/VideoCommon/VertexShaderManager.cpp | 4 +- 16 files changed, 145 insertions(+), 81 deletions(-) create mode 100644 Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index b492166222..e2d2527163 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -650,6 +650,7 @@ + diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt index a7e9548d91..fc34f7a378 100644 --- a/Source/Core/VideoCommon/CMakeLists.txt +++ b/Source/Core/VideoCommon/CMakeLists.txt @@ -61,6 +61,7 @@ add_library(videocommon GraphicsModSystem/Runtime/FBInfo.cpp GraphicsModSystem/Runtime/FBInfo.h GraphicsModSystem/Runtime/GraphicsModAction.h + GraphicsModSystem/Runtime/GraphicsModActionData.h GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp GraphicsModSystem/Runtime/GraphicsModActionFactory.h GraphicsModSystem/Runtime/GraphicsModManager.cpp diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.cpp index cc724c0480..d141af585c 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.cpp @@ -30,18 +30,26 @@ MoveAction::MoveAction(Common::Vec3 position_offset) : m_position_offset(positio { } -void MoveAction::OnProjection(Common::Matrix44* matrix) +void MoveAction::OnProjection(GraphicsModActionData::Projection* projection) { - if (!matrix) + if (!projection) [[unlikely]] return; - *matrix *= Common::Matrix44::Translate(m_position_offset); -} - -void MoveAction::OnProjectionAndTexture(Common::Matrix44* matrix) -{ - if (!matrix) + if (!projection->matrix) [[unlikely]] return; - *matrix *= Common::Matrix44::Translate(m_position_offset); + auto& matrix = *projection->matrix; + matrix = matrix * Common::Matrix44::Translate(m_position_offset); +} + +void MoveAction::OnProjectionAndTexture(GraphicsModActionData::Projection* projection) +{ + if (!projection) [[unlikely]] + return; + + if (!projection->matrix) [[unlikely]] + return; + + auto& matrix = *projection->matrix; + matrix = matrix * Common::Matrix44::Translate(m_position_offset); } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.h index 768d6a9f38..273cab1cfc 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/MoveAction.h @@ -14,8 +14,8 @@ class MoveAction final : public GraphicsModAction public: static std::unique_ptr Create(const picojson::value& json_data); explicit MoveAction(Common::Vec3 position_offset); - void OnProjection(Common::Matrix44* matrix) override; - void OnProjectionAndTexture(Common::Matrix44* matrix) override; + void OnProjection(GraphicsModActionData::Projection* projection) override; + void OnProjectionAndTexture(GraphicsModActionData::Projection* projection) override; private: Common::Vec3 m_position_offset; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.cpp index e6f7d6b659..e131b4ee1e 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.cpp @@ -5,27 +5,32 @@ #include "Common/Logging/Log.h" -void PrintAction::OnDrawStarted(bool*) +void PrintAction::OnDrawStarted(GraphicsModActionData::DrawStarted*) { INFO_LOG_FMT(VIDEO, "OnDrawStarted Called"); } -void PrintAction::OnEFB(bool*, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) +void PrintAction::OnEFB(GraphicsModActionData::EFB* efb) { - if (!scaled_width || !scaled_height) + if (!efb) [[unlikely]] return; - INFO_LOG_FMT(VIDEO, "OnEFB Called. Original [{}, {}], Scaled [{}, {}]", texture_width, - texture_height, *scaled_width, *scaled_height); + if (!efb->scaled_width) [[unlikely]] + return; + + if (!efb->scaled_height) [[unlikely]] + return; + + INFO_LOG_FMT(VIDEO, "OnEFB Called. Original [{}, {}], Scaled [{}, {}]", efb->texture_width, + efb->texture_height, *efb->scaled_width, *efb->scaled_height); } -void PrintAction::OnProjection(Common::Matrix44*) +void PrintAction::OnProjection(GraphicsModActionData::Projection*) { INFO_LOG_FMT(VIDEO, "OnProjection Called"); } -void PrintAction::OnProjectionAndTexture(Common::Matrix44*) +void PrintAction::OnProjectionAndTexture(GraphicsModActionData::Projection*) { INFO_LOG_FMT(VIDEO, "OnProjectionAndTexture Called"); } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.h index 6d8c123b68..6474eeb5f0 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/PrintAction.h @@ -8,10 +8,9 @@ class PrintAction final : public GraphicsModAction { public: - void OnDrawStarted(bool* skip) override; - void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) override; - void OnProjection(Common::Matrix44* matrix) override; - void OnProjectionAndTexture(Common::Matrix44* matrix) override; + void OnDrawStarted(GraphicsModActionData::DrawStarted*) override; + void OnEFB(GraphicsModActionData::EFB*) override; + void OnProjection(GraphicsModActionData::Projection*) override; + void OnProjectionAndTexture(GraphicsModActionData::Projection*) override; void OnTextureLoad() override; }; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp index d0cac24acb..305cd8b737 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.cpp @@ -30,30 +30,46 @@ ScaleAction::ScaleAction(Common::Vec3 scale) : m_scale(scale) { } -void ScaleAction::OnEFB(bool*, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) +void ScaleAction::OnEFB(GraphicsModActionData::EFB* efb) { - if (scaled_width && m_scale.x > 0) - *scaled_width = texture_width * m_scale.x; - - if (scaled_height && m_scale.y > 0) - *scaled_height = texture_height * m_scale.y; -} - -void ScaleAction::OnProjection(Common::Matrix44* matrix) -{ - if (!matrix) + if (!efb) [[unlikely]] return; - auto& the_matrix = *matrix; - the_matrix.data[0] = the_matrix.data[0] * m_scale.x; - the_matrix.data[5] = the_matrix.data[5] * m_scale.y; + + if (!efb->scaled_width) [[unlikely]] + return; + + if (!efb->scaled_height) [[unlikely]] + return; + + if (m_scale.x > 0) + *efb->scaled_width = efb->texture_width * m_scale.x; + + if (m_scale.y > 0) + *efb->scaled_height = efb->texture_height * m_scale.y; } -void ScaleAction::OnProjectionAndTexture(Common::Matrix44* matrix) +void ScaleAction::OnProjection(GraphicsModActionData::Projection* projection) { - if (!matrix) + if (!projection) [[unlikely]] return; - auto& the_matrix = *matrix; - the_matrix.data[0] = the_matrix.data[0] * m_scale.x; - the_matrix.data[5] = the_matrix.data[5] * m_scale.y; + + if (!projection->matrix) [[unlikely]] + return; + + auto& matrix = *projection->matrix; + matrix.data[0] = matrix.data[0] * m_scale.x; + matrix.data[5] = matrix.data[5] * m_scale.y; +} + +void ScaleAction::OnProjectionAndTexture(GraphicsModActionData::Projection* projection) +{ + if (!projection) [[unlikely]] + return; + + if (!projection->matrix) [[unlikely]] + return; + + auto& matrix = *projection->matrix; + matrix.data[0] = matrix.data[0] * m_scale.x; + matrix.data[5] = matrix.data[5] * m_scale.y; } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h index cbe8744941..7192fe0c76 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/ScaleAction.h @@ -14,10 +14,9 @@ class ScaleAction final : public GraphicsModAction public: static std::unique_ptr Create(const picojson::value& json_data); explicit ScaleAction(Common::Vec3 scale); - void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) override; - void OnProjection(Common::Matrix44* matrix) override; - void OnProjectionAndTexture(Common::Matrix44* matrix) override; + void OnEFB(GraphicsModActionData::EFB*) override; + void OnProjection(GraphicsModActionData::Projection*) override; + void OnProjectionAndTexture(GraphicsModActionData::Projection*) override; private: Common::Vec3 m_scale; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.cpp index ae3551497f..b693fef4f7 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.cpp @@ -3,18 +3,24 @@ #include "VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h" -void SkipAction::OnDrawStarted(bool* skip) +void SkipAction::OnDrawStarted(GraphicsModActionData::DrawStarted* draw_started) { - if (!skip) + if (!draw_started) [[unlikely]] return; - *skip = true; -} - -void SkipAction::OnEFB(bool* skip, u32, u32, u32*, u32*) -{ - if (!skip) + if (!draw_started->skip) [[unlikely]] return; - *skip = true; + *draw_started->skip = true; +} + +void SkipAction::OnEFB(GraphicsModActionData::EFB* efb) +{ + if (!efb) [[unlikely]] + return; + + if (!efb->skip) [[unlikely]] + return; + + *efb->skip = true; } diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h index 5cd204a89d..59de810355 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h @@ -8,7 +8,6 @@ class SkipAction final : public GraphicsModAction { public: - void OnDrawStarted(bool* skip) override; - void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) override; + void OnDrawStarted(GraphicsModActionData::DrawStarted*) override; + void OnEFB(GraphicsModActionData::EFB*) override; }; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h index 54ea086a29..c8ef469190 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h @@ -3,8 +3,7 @@ #pragma once -#include "Common/CommonTypes.h" -#include "Common/Matrix.h" +#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h" class GraphicsModAction { @@ -16,14 +15,11 @@ public: GraphicsModAction& operator=(const GraphicsModAction&) = default; GraphicsModAction& operator=(GraphicsModAction&&) = default; - virtual void OnDrawStarted(bool* skip) {} - virtual void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) - { - } + virtual void OnDrawStarted(GraphicsModActionData::DrawStarted*) {} + virtual void OnEFB(GraphicsModActionData::EFB*) {} virtual void OnXFB() {} - virtual void OnProjection(Common::Matrix44* matrix) {} - virtual void OnProjectionAndTexture(Common::Matrix44* matrix) {} + virtual void OnProjection(GraphicsModActionData::Projection*) {} + virtual void OnProjectionAndTexture(GraphicsModActionData::Projection*) {} virtual void OnTextureLoad() {} virtual void OnFrameEnd() {} }; diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h new file mode 100644 index 0000000000..c073adc445 --- /dev/null +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h @@ -0,0 +1,29 @@ +// Copyright 2022 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "Common/CommonTypes.h" +#include "Common/Matrix.h" + +namespace GraphicsModActionData +{ +struct DrawStarted +{ + bool* skip; +}; + +struct EFB +{ + u32 texture_width; + u32 texture_height; + bool* skip; + u32* scaled_width; + u32* scaled_height; +}; + +struct Projection +{ + Common::Matrix44* matrix; +}; +} // namespace GraphicsModActionData diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp index 65efaaf963..db978646ae 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp @@ -22,30 +22,29 @@ public: : m_action_impl(std::move(action)), m_mod(std::move(mod)) { } - void OnDrawStarted(bool* skip) override + void OnDrawStarted(GraphicsModActionData::DrawStarted* draw_started) override { if (!m_mod.m_enabled) return; - m_action_impl->OnDrawStarted(skip); + m_action_impl->OnDrawStarted(draw_started); } - void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, - u32* scaled_height) override + void OnEFB(GraphicsModActionData::EFB* efb) override { if (!m_mod.m_enabled) return; - m_action_impl->OnEFB(skip, texture_width, texture_height, scaled_width, scaled_height); + m_action_impl->OnEFB(efb); } - void OnProjection(Common::Matrix44* matrix) override + void OnProjection(GraphicsModActionData::Projection* projection) override { if (!m_mod.m_enabled) return; - m_action_impl->OnProjection(matrix); + m_action_impl->OnProjection(projection); } - void OnProjectionAndTexture(Common::Matrix44* matrix) override + void OnProjectionAndTexture(GraphicsModActionData::Projection* projection) override { if (!m_mod.m_enabled) return; - m_action_impl->OnProjectionAndTexture(matrix); + m_action_impl->OnProjectionAndTexture(projection); } void OnTextureLoad() override { diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 7e49df8040..a90efd15be 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -37,6 +37,7 @@ #include "VideoCommon/BPMemory.h" #include "VideoCommon/FramebufferManager.h" #include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h" +#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h" #include "VideoCommon/HiresTextures.h" #include "VideoCommon/OpcodeDecoding.h" #include "VideoCommon/PixelShaderManager.h" @@ -2158,9 +2159,10 @@ void TextureCacheBase::CopyRenderTargetToTexture( else { bool skip = false; + GraphicsModActionData::EFB efb{tex_w, tex_h, &skip, &scaled_tex_w, &scaled_tex_h}; for (const auto action : g_renderer->GetGraphicsModManager().GetEFBActions(info)) { - action->OnEFB(&skip, tex_w, tex_h, &scaled_tex_w, &scaled_tex_h); + action->OnEFB(&efb); } if (skip == true) { diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 22245f1db2..e77e6e4525 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -21,6 +21,7 @@ #include "VideoCommon/DataReader.h" #include "VideoCommon/FramebufferManager.h" #include "VideoCommon/GeometryShaderManager.h" +#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h" #include "VideoCommon/IndexGenerator.h" #include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/OpcodeDecoding.h" @@ -492,10 +493,11 @@ void VertexManagerBase::Flush() for (const auto& texture_name : texture_names) { bool skip = false; + GraphicsModActionData::DrawStarted draw_started{&skip}; for (const auto action : g_renderer->GetGraphicsModManager().GetDrawStartedActions(texture_name)) { - action->OnDrawStarted(&skip); + action->OnDrawStarted(&draw_started); } if (skip == true) return; diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index b74c820271..41ccd4a370 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -21,6 +21,7 @@ #include "VideoCommon/BPMemory.h" #include "VideoCommon/CPMemory.h" #include "VideoCommon/FreeLookCamera.h" +#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/Statistics.h" #include "VideoCommon/VertexLoaderManager.h" @@ -415,9 +416,10 @@ void VertexShaderManager::SetConstants(const std::vector& textures) if (g_freelook_camera.IsActive() && xfmem.projection.type == ProjectionType::Perspective) corrected_matrix *= g_freelook_camera.GetView(); + GraphicsModActionData::Projection projection{&corrected_matrix}; for (auto action : projection_actions) { - action->OnProjection(&corrected_matrix); + action->OnProjection(&projection); } memcpy(constants.projection.data(), corrected_matrix.data.data(), 4 * sizeof(float4));