VideoCommon: add structures to graphics mods to allow for future adding or removing parameters with less code overhead

This commit is contained in:
iwubcode 2022-07-02 14:49:51 -05:00
parent 6cf99195c6
commit bc360584a3
16 changed files with 145 additions and 81 deletions

View File

@ -650,6 +650,7 @@
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\SkipAction.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\SkipAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\FBInfo.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\FBInfo.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModAction.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModActionData.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModActionFactory.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModActionFactory.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModGroup.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModGroup.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModManager.h" /> <ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModManager.h" />

View File

@ -61,6 +61,7 @@ add_library(videocommon
GraphicsModSystem/Runtime/FBInfo.cpp GraphicsModSystem/Runtime/FBInfo.cpp
GraphicsModSystem/Runtime/FBInfo.h GraphicsModSystem/Runtime/FBInfo.h
GraphicsModSystem/Runtime/GraphicsModAction.h GraphicsModSystem/Runtime/GraphicsModAction.h
GraphicsModSystem/Runtime/GraphicsModActionData.h
GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp GraphicsModSystem/Runtime/GraphicsModActionFactory.cpp
GraphicsModSystem/Runtime/GraphicsModActionFactory.h GraphicsModSystem/Runtime/GraphicsModActionFactory.h
GraphicsModSystem/Runtime/GraphicsModManager.cpp GraphicsModSystem/Runtime/GraphicsModManager.cpp

View File

@ -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; return;
*matrix *= Common::Matrix44::Translate(m_position_offset); if (!projection->matrix) [[unlikely]]
}
void MoveAction::OnProjectionAndTexture(Common::Matrix44* matrix)
{
if (!matrix)
return; 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);
} }

View File

@ -14,8 +14,8 @@ class MoveAction final : public GraphicsModAction
public: public:
static std::unique_ptr<MoveAction> Create(const picojson::value& json_data); static std::unique_ptr<MoveAction> Create(const picojson::value& json_data);
explicit MoveAction(Common::Vec3 position_offset); explicit MoveAction(Common::Vec3 position_offset);
void OnProjection(Common::Matrix44* matrix) override; void OnProjection(GraphicsModActionData::Projection* projection) override;
void OnProjectionAndTexture(Common::Matrix44* matrix) override; void OnProjectionAndTexture(GraphicsModActionData::Projection* projection) override;
private: private:
Common::Vec3 m_position_offset; Common::Vec3 m_position_offset;

View File

@ -5,27 +5,32 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
void PrintAction::OnDrawStarted(bool*) void PrintAction::OnDrawStarted(GraphicsModActionData::DrawStarted*)
{ {
INFO_LOG_FMT(VIDEO, "OnDrawStarted Called"); INFO_LOG_FMT(VIDEO, "OnDrawStarted Called");
} }
void PrintAction::OnEFB(bool*, u32 texture_width, u32 texture_height, u32* scaled_width, void PrintAction::OnEFB(GraphicsModActionData::EFB* efb)
u32* scaled_height)
{ {
if (!scaled_width || !scaled_height) if (!efb) [[unlikely]]
return; return;
INFO_LOG_FMT(VIDEO, "OnEFB Called. Original [{}, {}], Scaled [{}, {}]", texture_width, if (!efb->scaled_width) [[unlikely]]
texture_height, *scaled_width, *scaled_height); 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"); INFO_LOG_FMT(VIDEO, "OnProjection Called");
} }
void PrintAction::OnProjectionAndTexture(Common::Matrix44*) void PrintAction::OnProjectionAndTexture(GraphicsModActionData::Projection*)
{ {
INFO_LOG_FMT(VIDEO, "OnProjectionAndTexture Called"); INFO_LOG_FMT(VIDEO, "OnProjectionAndTexture Called");
} }

View File

@ -8,10 +8,9 @@
class PrintAction final : public GraphicsModAction class PrintAction final : public GraphicsModAction
{ {
public: public:
void OnDrawStarted(bool* skip) override; void OnDrawStarted(GraphicsModActionData::DrawStarted*) override;
void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, void OnEFB(GraphicsModActionData::EFB*) override;
u32* scaled_height) override; void OnProjection(GraphicsModActionData::Projection*) override;
void OnProjection(Common::Matrix44* matrix) override; void OnProjectionAndTexture(GraphicsModActionData::Projection*) override;
void OnProjectionAndTexture(Common::Matrix44* matrix) override;
void OnTextureLoad() override; void OnTextureLoad() override;
}; };

View File

@ -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, void ScaleAction::OnEFB(GraphicsModActionData::EFB* efb)
u32* scaled_height)
{ {
if (scaled_width && m_scale.x > 0) if (!efb) [[unlikely]]
*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)
return; return;
auto& the_matrix = *matrix;
the_matrix.data[0] = the_matrix.data[0] * m_scale.x; if (!efb->scaled_width) [[unlikely]]
the_matrix.data[5] = the_matrix.data[5] * m_scale.y; 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; return;
auto& the_matrix = *matrix;
the_matrix.data[0] = the_matrix.data[0] * m_scale.x; if (!projection->matrix) [[unlikely]]
the_matrix.data[5] = the_matrix.data[5] * m_scale.y; 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;
} }

View File

@ -14,10 +14,9 @@ class ScaleAction final : public GraphicsModAction
public: public:
static std::unique_ptr<ScaleAction> Create(const picojson::value& json_data); static std::unique_ptr<ScaleAction> Create(const picojson::value& json_data);
explicit ScaleAction(Common::Vec3 scale); explicit ScaleAction(Common::Vec3 scale);
void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, void OnEFB(GraphicsModActionData::EFB*) override;
u32* scaled_height) override; void OnProjection(GraphicsModActionData::Projection*) override;
void OnProjection(Common::Matrix44* matrix) override; void OnProjectionAndTexture(GraphicsModActionData::Projection*) override;
void OnProjectionAndTexture(Common::Matrix44* matrix) override;
private: private:
Common::Vec3 m_scale; Common::Vec3 m_scale;

View File

@ -3,18 +3,24 @@
#include "VideoCommon/GraphicsModSystem/Runtime/Actions/SkipAction.h" #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; return;
*skip = true; if (!draw_started->skip) [[unlikely]]
}
void SkipAction::OnEFB(bool* skip, u32, u32, u32*, u32*)
{
if (!skip)
return; 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;
} }

View File

@ -8,7 +8,6 @@
class SkipAction final : public GraphicsModAction class SkipAction final : public GraphicsModAction
{ {
public: public:
void OnDrawStarted(bool* skip) override; void OnDrawStarted(GraphicsModActionData::DrawStarted*) override;
void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, void OnEFB(GraphicsModActionData::EFB*) override;
u32* scaled_height) override;
}; };

View File

@ -3,8 +3,7 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
#include "Common/Matrix.h"
class GraphicsModAction class GraphicsModAction
{ {
@ -16,14 +15,11 @@ public:
GraphicsModAction& operator=(const GraphicsModAction&) = default; GraphicsModAction& operator=(const GraphicsModAction&) = default;
GraphicsModAction& operator=(GraphicsModAction&&) = default; GraphicsModAction& operator=(GraphicsModAction&&) = default;
virtual void OnDrawStarted(bool* skip) {} virtual void OnDrawStarted(GraphicsModActionData::DrawStarted*) {}
virtual void OnEFB(bool* skip, u32 texture_width, u32 texture_height, u32* scaled_width, virtual void OnEFB(GraphicsModActionData::EFB*) {}
u32* scaled_height)
{
}
virtual void OnXFB() {} virtual void OnXFB() {}
virtual void OnProjection(Common::Matrix44* matrix) {} virtual void OnProjection(GraphicsModActionData::Projection*) {}
virtual void OnProjectionAndTexture(Common::Matrix44* matrix) {} virtual void OnProjectionAndTexture(GraphicsModActionData::Projection*) {}
virtual void OnTextureLoad() {} virtual void OnTextureLoad() {}
virtual void OnFrameEnd() {} virtual void OnFrameEnd() {}
}; };

View File

@ -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

View File

@ -22,30 +22,29 @@ public:
: m_action_impl(std::move(action)), m_mod(std::move(mod)) : 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) if (!m_mod.m_enabled)
return; 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, void OnEFB(GraphicsModActionData::EFB* efb) override
u32* scaled_height) override
{ {
if (!m_mod.m_enabled) if (!m_mod.m_enabled)
return; 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) if (!m_mod.m_enabled)
return; 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) if (!m_mod.m_enabled)
return; return;
m_action_impl->OnProjectionAndTexture(matrix); m_action_impl->OnProjectionAndTexture(projection);
} }
void OnTextureLoad() override void OnTextureLoad() override
{ {

View File

@ -37,6 +37,7 @@
#include "VideoCommon/BPMemory.h" #include "VideoCommon/BPMemory.h"
#include "VideoCommon/FramebufferManager.h" #include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h" #include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
#include "VideoCommon/HiresTextures.h" #include "VideoCommon/HiresTextures.h"
#include "VideoCommon/OpcodeDecoding.h" #include "VideoCommon/OpcodeDecoding.h"
#include "VideoCommon/PixelShaderManager.h" #include "VideoCommon/PixelShaderManager.h"
@ -2158,9 +2159,10 @@ void TextureCacheBase::CopyRenderTargetToTexture(
else else
{ {
bool skip = false; 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)) 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) if (skip == true)
{ {

View File

@ -21,6 +21,7 @@
#include "VideoCommon/DataReader.h" #include "VideoCommon/DataReader.h"
#include "VideoCommon/FramebufferManager.h" #include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/GeometryShaderManager.h" #include "VideoCommon/GeometryShaderManager.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
#include "VideoCommon/IndexGenerator.h" #include "VideoCommon/IndexGenerator.h"
#include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/OpcodeDecoding.h" #include "VideoCommon/OpcodeDecoding.h"
@ -492,10 +493,11 @@ void VertexManagerBase::Flush()
for (const auto& texture_name : texture_names) for (const auto& texture_name : texture_names)
{ {
bool skip = false; bool skip = false;
GraphicsModActionData::DrawStarted draw_started{&skip};
for (const auto action : for (const auto action :
g_renderer->GetGraphicsModManager().GetDrawStartedActions(texture_name)) g_renderer->GetGraphicsModManager().GetDrawStartedActions(texture_name))
{ {
action->OnDrawStarted(&skip); action->OnDrawStarted(&draw_started);
} }
if (skip == true) if (skip == true)
return; return;

View File

@ -21,6 +21,7 @@
#include "VideoCommon/BPMemory.h" #include "VideoCommon/BPMemory.h"
#include "VideoCommon/CPMemory.h" #include "VideoCommon/CPMemory.h"
#include "VideoCommon/FreeLookCamera.h" #include "VideoCommon/FreeLookCamera.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
#include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderBase.h"
#include "VideoCommon/Statistics.h" #include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexLoaderManager.h"
@ -415,9 +416,10 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
if (g_freelook_camera.IsActive() && xfmem.projection.type == ProjectionType::Perspective) if (g_freelook_camera.IsActive() && xfmem.projection.type == ProjectionType::Perspective)
corrected_matrix *= g_freelook_camera.GetView(); corrected_matrix *= g_freelook_camera.GetView();
GraphicsModActionData::Projection projection{&corrected_matrix};
for (auto action : projection_actions) for (auto action : projection_actions)
{ {
action->OnProjection(&corrected_matrix); action->OnProjection(&projection);
} }
memcpy(constants.projection.data(), corrected_matrix.data.data(), 4 * sizeof(float4)); memcpy(constants.projection.data(), corrected_matrix.data.data(), 4 * sizeof(float4));