summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-12-28 15:38:46 +0100
committerAdmiral H. Curtiss <pikachu025@gmail.com>2022-12-28 15:52:29 +0100
commit50625728e089c8868eb919244d4e6eafa4f4cf79 (patch)
treebc88f46cfe671ed8ed25cfa24fe83a9c74b83e3e /Source/Core
parent0900e68986a4fa2254fb3c459f73af4815979e45 (diff)
VideoCommon: De-globalize VertexShaderManager class.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Boot/Boot_BS2Emu.cpp6
-rw-r--r--Source/Core/Core/System.cpp7
-rw-r--r--Source/Core/Core/System.h2
-rw-r--r--Source/Core/VideoBackends/D3D/D3DVertexManager.cpp8
-rw-r--r--Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp14
-rw-r--r--Source/Core/VideoBackends/Metal/MTLStateTracker.mm4
-rw-r--r--Source/Core/VideoBackends/Metal/MTLVertexManager.mm5
-rw-r--r--Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp7
-rw-r--r--Source/Core/VideoBackends/Software/SWVertexLoader.cpp18
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKVertexManager.cpp14
-rw-r--r--Source/Core/VideoCommon/BPStructs.cpp8
-rw-r--r--Source/Core/VideoCommon/OpcodeDecoding.cpp6
-rw-r--r--Source/Core/VideoCommon/VertexLoaderManager.cpp6
-rw-r--r--Source/Core/VideoCommon/VertexManagerBase.cpp26
-rw-r--r--Source/Core/VideoCommon/VertexShaderManager.cpp21
-rw-r--r--Source/Core/VideoCommon/VertexShaderManager.h56
-rw-r--r--Source/Core/VideoCommon/VideoBackendBase.cpp2
-rw-r--r--Source/Core/VideoCommon/VideoState.cpp2
-rw-r--r--Source/Core/VideoCommon/XFStructs.cpp40
19 files changed, 151 insertions, 101 deletions
diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp
index 5be2905096..8b9d4d727b 100644
--- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp
+++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp
@@ -256,6 +256,8 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume,
{
INFO_LOG_FMT(BOOT, "Faking GC BS2...");
+ auto& system = Core::System::GetInstance();
+
SetupMSR();
SetupHID(/*is_wii*/ false);
SetupBAT(/*is_wii*/ false);
@@ -271,11 +273,11 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume,
xfmem.postMatrices[0x3e * 4 + 1] = 1.0f;
xfmem.postMatrices[0x3f * 4 + 2] = 1.0f;
g_vertex_manager->Flush();
- VertexShaderManager::InvalidateXFRange(XFMEM_POSTMATRICES + 0x3d * 4, XFMEM_POSTMATRICES_END);
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ vertex_shader_manager.InvalidateXFRange(XFMEM_POSTMATRICES + 0x3d * 4, XFMEM_POSTMATRICES_END);
DVDReadDiscID(volume, 0x00000000);
- auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
bool streaming = memory.Read_U8(0x80000008);
if (streaming)
diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp
index 79c25592eb..65fc9d283b 100644
--- a/Source/Core/Core/System.cpp
+++ b/Source/Core/Core/System.cpp
@@ -22,6 +22,7 @@
#include "VideoCommon/Fifo.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/PixelShaderManager.h"
+#include "VideoCommon/VertexShaderManager.h"
namespace Core
{
@@ -45,6 +46,7 @@ struct System::Impl
PixelShaderManager m_pixel_shader_manager;
SerialInterface::SerialInterfaceState m_serial_interface_state;
Sram m_sram;
+ VertexShaderManager m_vertex_shader_manager;
VideoInterface::VideoInterfaceState m_video_interface_state;
};
@@ -161,6 +163,11 @@ Sram& System::GetSRAM() const
return m_impl->m_sram;
}
+VertexShaderManager& System::GetVertexShaderManager() const
+{
+ return m_impl->m_vertex_shader_manager;
+}
+
VideoInterface::VideoInterfaceState& System::GetVideoInterfaceState() const
{
return m_impl->m_video_interface_state;
diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h
index f92e57291e..d5615142b4 100644
--- a/Source/Core/Core/System.h
+++ b/Source/Core/Core/System.h
@@ -8,6 +8,7 @@
class PixelShaderManager;
class SoundStream;
struct Sram;
+class VertexShaderManager;
namespace AudioInterface
{
@@ -110,6 +111,7 @@ public:
PixelShaderManager& GetPixelShaderManager() const;
SerialInterface::SerialInterfaceState& GetSerialInterfaceState() const;
Sram& GetSRAM() const;
+ VertexShaderManager& GetVertexShaderManager() const;
VideoInterface::VideoInterfaceState& GetVideoInterfaceState() const;
private:
diff --git a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp
index b3c7012d8b..5b5cf5c941 100644
--- a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp
+++ b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp
@@ -264,12 +264,14 @@ void VertexManager::UploadUniforms()
{
auto& system = Core::System::GetInstance();
- if (VertexShaderManager::dirty)
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ if (vertex_shader_manager.dirty)
{
- UpdateConstantBuffer(m_vertex_constant_buffer.Get(), &VertexShaderManager::constants,
+ UpdateConstantBuffer(m_vertex_constant_buffer.Get(), &vertex_shader_manager.constants,
sizeof(VertexShaderConstants));
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
}
+
if (GeometryShaderManager::dirty)
{
UpdateConstantBuffer(m_geometry_constant_buffer.Get(), &GeometryShaderManager::constants,
diff --git a/Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp b/Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp
index 3d95c076cc..510955a201 100644
--- a/Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp
+++ b/Source/Core/VideoBackends/D3D12/D3D12VertexManager.cpp
@@ -145,15 +145,18 @@ void VertexManager::UploadUniforms()
void VertexManager::UpdateVertexShaderConstants()
{
- if (!VertexShaderManager::dirty || !ReserveConstantStorage())
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+
+ if (!vertex_shader_manager.dirty || !ReserveConstantStorage())
return;
Renderer::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer());
- std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &VertexShaderManager::constants,
+ std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &vertex_shader_manager.constants,
sizeof(VertexShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(VertexShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants));
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
}
void VertexManager::UpdateGeometryShaderConstants()
@@ -237,12 +240,13 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
// Copy the actual data in
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + pixel_constants_offset,
&pixel_shader_manager.constants, sizeof(PixelShaderConstants));
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + vertex_constants_offset,
- &VertexShaderManager::constants, sizeof(VertexShaderConstants));
+ &vertex_shader_manager.constants, sizeof(VertexShaderConstants));
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
@@ -251,7 +255,7 @@ void VertexManager::UploadAllConstants()
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size);
// Clear dirty flags
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false;
}
diff --git a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm
index 60c7dd19df..c5405246b4 100644
--- a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm
+++ b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm
@@ -836,7 +836,9 @@ void Metal::StateTracker::PrepareRender()
{
m_flags.has_gx_vs_uniform = true;
Map map = Allocate(UploadBuffer::Uniform, sizeof(VertexShaderConstants), AlignMask::Uniform);
- memcpy(map.cpu_buffer, &VertexShaderManager::constants, sizeof(VertexShaderConstants));
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ memcpy(map.cpu_buffer, &vertex_shader_manager.constants, sizeof(VertexShaderConstants));
SetVertexBufferNow(1, map.gpu_buffer, map.gpu_offset);
if (pipe->UsesFragmentBuffer(1))
SetFragmentBufferNow(1, map.gpu_buffer, map.gpu_offset);
diff --git a/Source/Core/VideoBackends/Metal/MTLVertexManager.mm b/Source/Core/VideoBackends/Metal/MTLVertexManager.mm
index df86461ae3..69ec48552b 100644
--- a/Source/Core/VideoBackends/Metal/MTLVertexManager.mm
+++ b/Source/Core/VideoBackends/Metal/MTLVertexManager.mm
@@ -93,9 +93,10 @@ void Metal::VertexManager::UploadUniforms()
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
- g_state_tracker->InvalidateUniforms(VertexShaderManager::dirty, GeometryShaderManager::dirty,
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ g_state_tracker->InvalidateUniforms(vertex_shader_manager.dirty, GeometryShaderManager::dirty,
pixel_shader_manager.dirty);
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false;
}
diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
index 485d718723..7566611041 100644
--- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
+++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
@@ -223,14 +223,15 @@ void ProgramShaderCache::UploadConstants()
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
- if (pixel_shader_manager.dirty || VertexShaderManager::dirty || GeometryShaderManager::dirty)
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ if (pixel_shader_manager.dirty || vertex_shader_manager.dirty || GeometryShaderManager::dirty)
{
auto buffer = s_buffer->Map(s_ubo_buffer_size, s_ubo_align);
memcpy(buffer.first, &pixel_shader_manager.constants, sizeof(PixelShaderConstants));
memcpy(buffer.first + Common::AlignUp(sizeof(PixelShaderConstants), s_ubo_align),
- &VertexShaderManager::constants, sizeof(VertexShaderConstants));
+ &vertex_shader_manager.constants, sizeof(VertexShaderConstants));
memcpy(buffer.first + Common::AlignUp(sizeof(PixelShaderConstants), s_ubo_align) +
Common::AlignUp(sizeof(VertexShaderConstants), s_ubo_align),
@@ -248,7 +249,7 @@ void ProgramShaderCache::UploadConstants()
sizeof(GeometryShaderConstants));
pixel_shader_manager.dirty = false;
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, s_ubo_buffer_size);
diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
index a38fd163ec..9fbf560ecf 100644
--- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
+++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
@@ -10,6 +10,8 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
+#include "Core/System.h"
+
#include "VideoBackends/Software/NativeVertexFormat.h"
#include "VideoBackends/Software/Rasterizer.h"
#include "VideoBackends/Software/SWRenderer.h"
@@ -205,15 +207,19 @@ void SWVertexLoader::ParseVertex(const PortableVertexDeclaration& vdec, int inde
}
if (!vdec.normals[1].enable)
{
- m_vertex.normal[1][0] = VertexShaderManager::constants.cached_tangent[0];
- m_vertex.normal[1][1] = VertexShaderManager::constants.cached_tangent[1];
- m_vertex.normal[1][2] = VertexShaderManager::constants.cached_tangent[2];
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ m_vertex.normal[1][0] = vertex_shader_manager.constants.cached_tangent[0];
+ m_vertex.normal[1][1] = vertex_shader_manager.constants.cached_tangent[1];
+ m_vertex.normal[1][2] = vertex_shader_manager.constants.cached_tangent[2];
}
if (!vdec.normals[2].enable)
{
- m_vertex.normal[2][0] = VertexShaderManager::constants.cached_binormal[0];
- m_vertex.normal[2][1] = VertexShaderManager::constants.cached_binormal[1];
- m_vertex.normal[2][2] = VertexShaderManager::constants.cached_binormal[2];
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ m_vertex.normal[2][0] = vertex_shader_manager.constants.cached_binormal[0];
+ m_vertex.normal[2][1] = vertex_shader_manager.constants.cached_binormal[1];
+ m_vertex.normal[2][2] = vertex_shader_manager.constants.cached_binormal[2];
}
ParseColorAttributes(&m_vertex, src, vdec);
diff --git a/Source/Core/VideoBackends/Vulkan/VKVertexManager.cpp b/Source/Core/VideoBackends/Vulkan/VKVertexManager.cpp
index c01335d85a..86b2e361ef 100644
--- a/Source/Core/VideoBackends/Vulkan/VKVertexManager.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKVertexManager.cpp
@@ -204,17 +204,20 @@ void VertexManager::UploadUniforms()
void VertexManager::UpdateVertexShaderConstants()
{
- if (!VertexShaderManager::dirty || !ReserveConstantStorage())
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+
+ if (!vertex_shader_manager.dirty || !ReserveConstantStorage())
return;
StateTracker::GetInstance()->SetGXUniformBuffer(
UBO_DESCRIPTOR_SET_BINDING_VS, m_uniform_stream_buffer->GetBuffer(),
m_uniform_stream_buffer->GetCurrentOffset(), sizeof(VertexShaderConstants));
- std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer(), &VertexShaderManager::constants,
+ std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer(), &vertex_shader_manager.constants,
sizeof(VertexShaderConstants));
m_uniform_stream_buffer->CommitMemory(sizeof(VertexShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants));
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
}
void VertexManager::UpdateGeometryShaderConstants()
@@ -289,6 +292,7 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
// Update bindings
StateTracker::GetInstance()->SetGXUniformBuffer(
@@ -308,7 +312,7 @@ void VertexManager::UploadAllConstants()
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + pixel_constants_offset,
&pixel_shader_manager.constants, sizeof(PixelShaderConstants));
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + vertex_constants_offset,
- &VertexShaderManager::constants, sizeof(VertexShaderConstants));
+ &vertex_shader_manager.constants, sizeof(VertexShaderConstants));
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
@@ -317,7 +321,7 @@ void VertexManager::UploadAllConstants()
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size);
// Clear dirty flags
- VertexShaderManager::dirty = false;
+ vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false;
}
diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp
index e7c2c640ff..376249fab9 100644
--- a/Source/Core/VideoCommon/BPStructs.cpp
+++ b/Source/Core/VideoCommon/BPStructs.cpp
@@ -54,7 +54,8 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF;
}
-static void BPWritten(PixelShaderManager& pixel_shader_manager, const BPCmd& bp,
+static void BPWritten(PixelShaderManager& pixel_shader_manager,
+ VertexShaderManager& vertex_shader_manager, const BPCmd& bp,
int cycles_into_future)
{
/*
@@ -136,7 +137,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, const BPCmd& bp,
case BPMEM_SCISSORTL: // Scissor Rectable Top, Left
case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
case BPMEM_SCISSOROFFSET: // Scissor Offset
- VertexShaderManager::SetViewportChanged();
+ vertex_shader_manager.SetViewportChanged();
GeometryShaderManager::SetViewportChanged();
return;
case BPMEM_LINEPTWIDTH: // Line Width
@@ -762,7 +763,8 @@ void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
if (reg != BPMEM_BP_MASK)
bpmem.bpMask = 0xFFFFFF;
- BPWritten(system.GetPixelShaderManager(), bp, cycles_into_future);
+ BPWritten(system.GetPixelShaderManager(), system.GetVertexShaderManager(), bp,
+ cycles_into_future);
}
void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future)
diff --git a/Source/Core/VideoCommon/OpcodeDecoding.cpp b/Source/Core/VideoCommon/OpcodeDecoding.cpp
index 3cf16eb8ad..9ffb59a277 100644
--- a/Source/Core/VideoCommon/OpcodeDecoding.cpp
+++ b/Source/Core/VideoCommon/OpcodeDecoding.cpp
@@ -59,12 +59,14 @@ public:
if (sub_command == MATINDEX_A)
{
VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
- VertexShaderManager::SetTexMatrixChangedA(value);
+ auto& system = Core::System::GetInstance();
+ system.GetVertexShaderManager().SetTexMatrixChangedA(value);
}
else if (sub_command == MATINDEX_B)
{
VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
- VertexShaderManager::SetTexMatrixChangedB(value);
+ auto& system = Core::System::GetInstance();
+ system.GetVertexShaderManager().SetTexMatrixChangedB(value);
}
else if (sub_command == VCD_LO || sub_command == VCD_HI)
{
diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp
index e788f8e3db..4d0597ba88 100644
--- a/Source/Core/VideoCommon/VertexLoaderManager.cpp
+++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp
@@ -361,8 +361,10 @@ int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int coun
}
s_current_vtx_fmt = loader->m_native_vertex_format;
g_current_components = loader->m_native_components;
- VertexShaderManager::SetVertexFormat(loader->m_native_components,
- loader->m_native_vertex_format->GetVertexDeclaration());
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ vertex_shader_manager.SetVertexFormat(loader->m_native_components,
+ loader->m_native_vertex_format->GetVertexDeclaration());
// if cull mode is CULL_ALL, tell VertexManager to skip triangles and quads.
// They still need to go through vertex loading, because we need to calculate a zfreeze refrence
diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp
index 1c5998862c..03eed59a88 100644
--- a/Source/Core/VideoCommon/VertexManagerBase.cpp
+++ b/Source/Core/VideoCommon/VertexManagerBase.cpp
@@ -319,8 +319,9 @@ void VertexManagerBase::UploadUniforms()
void VertexManagerBase::InvalidateConstants()
{
auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
auto& pixel_shader_manager = system.GetPixelShaderManager();
- VertexShaderManager::dirty = true;
+ vertex_shader_manager.dirty = true;
GeometryShaderManager::dirty = true;
pixel_shader_manager.dirty = true;
}
@@ -486,6 +487,7 @@ void VertexManagerBase::Flush()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
// Calculate ZSlope for zfreeze
@@ -512,7 +514,7 @@ void VertexManagerBase::Flush()
}
}
}
- VertexShaderManager::SetConstants(texture_names);
+ vertex_shader_manager.SetConstants(texture_names);
if (!bpmem.genMode.zfreeze)
{
// Must be done after VertexShaderManager::SetConstants()
@@ -634,6 +636,8 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
// Lookup vertices of the last rendered triangle and software-transform them
// This allows us to determine the depth slope, which will be used if z-freeze
// is enabled in the following flush.
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
for (unsigned int i = 0; i < 3; ++i)
{
// If this vertex format has per-vertex position matrix IDs, look it up.
@@ -643,8 +647,8 @@ void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format)
if (vert_decl.position.components == 2)
VertexLoaderManager::position_cache[2 - i][2] = 0;
- VertexShaderManager::TransformToClipSpace(&VertexLoaderManager::position_cache[2 - i][0],
- &out[i * 4], mtxIdx);
+ vertex_shader_manager.TransformToClipSpace(&VertexLoaderManager::position_cache[2 - i][0],
+ &out[i * 4], mtxIdx);
// Transform to Screenspace
float inv_w = 1.0f / out[3 + i * 4];
@@ -688,15 +692,17 @@ void VertexManagerBase::CalculateBinormals(NativeVertexFormat* format)
VertexLoaderManager::tangent_cache[3] = 0;
VertexLoaderManager::binormal_cache[3] = 0;
- if (VertexShaderManager::constants.cached_tangent != VertexLoaderManager::tangent_cache)
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+ if (vertex_shader_manager.constants.cached_tangent != VertexLoaderManager::tangent_cache)
{
- VertexShaderManager::constants.cached_tangent = VertexLoaderManager::tangent_cache;
- VertexShaderManager::dirty = true;
+ vertex_shader_manager.constants.cached_tangent = VertexLoaderManager::tangent_cache;
+ vertex_shader_manager.dirty = true;
}
- if (VertexShaderManager::constants.cached_binormal != VertexLoaderManager::binormal_cache)
+ if (vertex_shader_manager.constants.cached_binormal != VertexLoaderManager::binormal_cache)
{
- VertexShaderManager::constants.cached_binormal = VertexLoaderManager::binormal_cache;
- VertexShaderManager::dirty = true;
+ vertex_shader_manager.constants.cached_binormal = VertexLoaderManager::binormal_cache;
+ vertex_shader_manager.dirty = true;
}
}
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp
index 41ccd4a370..e81f603234 100644
--- a/Source/Core/VideoCommon/VertexShaderManager.cpp
+++ b/Source/Core/VideoCommon/VertexShaderManager.cpp
@@ -30,27 +30,6 @@
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"
-alignas(16) static std::array<float, 16> g_fProjectionMatrix;
-
-// track changes
-static std::array<bool, 2> bTexMatricesChanged;
-static bool bPosNormalMatrixChanged;
-static bool bProjectionChanged;
-static bool bViewportChanged;
-static bool bTexMtxInfoChanged;
-static bool bLightingConfigChanged;
-static bool bProjectionGraphicsModChange;
-static BitSet32 nMaterialsChanged;
-static std::array<int, 2> nTransformMatricesChanged; // min,max
-static std::array<int, 2> nNormalMatricesChanged; // min,max
-static std::array<int, 2> nPostTransformMatricesChanged; // min,max
-static std::array<int, 2> nLightsChanged; // min,max
-
-static Common::Matrix44 s_viewportCorrection;
-
-VertexShaderConstants VertexShaderManager::constants;
-bool VertexShaderManager::dirty;
-
void VertexShaderManager::Init()
{
// Initialize state tracking variables
diff --git a/Source/Core/VideoCommon/VertexShaderManager.h b/Source/Core/VideoCommon/VertexShaderManager.h
index 2a8aa7b596..c7237ad0b2 100644
--- a/Source/Core/VideoCommon/VertexShaderManager.h
+++ b/Source/Core/VideoCommon/VertexShaderManager.h
@@ -3,43 +3,65 @@
#pragma once
+#include <array>
#include <string>
#include <vector>
+#include "Common/BitSet.h"
#include "Common/CommonTypes.h"
+#include "Common/Matrix.h"
#include "VideoCommon/ConstantManager.h"
class PointerWrap;
struct PortableVertexDeclaration;
// The non-API dependent parts.
-class VertexShaderManager
+class alignas(16) VertexShaderManager
{
public:
- static void Init();
- static void Dirty();
- static void DoState(PointerWrap& p);
+ void Init();
+ void Dirty();
+ void DoState(PointerWrap& p);
// constant management
- static void SetConstants(const std::vector<std::string>& textures);
+ void SetConstants(const std::vector<std::string>& textures);
- static void InvalidateXFRange(int start, int end);
- static void SetTexMatrixChangedA(u32 value);
- static void SetTexMatrixChangedB(u32 value);
- static void SetViewportChanged();
- static void SetProjectionChanged();
- static void SetMaterialColorChanged(int index);
+ void InvalidateXFRange(int start, int end);
+ void SetTexMatrixChangedA(u32 value);
+ void SetTexMatrixChangedB(u32 value);
+ void SetViewportChanged();
+ void SetProjectionChanged();
+ void SetMaterialColorChanged(int index);
- static void SetVertexFormat(u32 components, const PortableVertexDeclaration& format);
- static void SetTexMatrixInfoChanged(int index);
- static void SetLightingConfigChanged();
+ void SetVertexFormat(u32 components, const PortableVertexDeclaration& format);
+ void SetTexMatrixInfoChanged(int index);
+ void SetLightingConfigChanged();
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
// out: 4 floats which will be initialized with the corresponding clip space coordinates
// NOTE: g_fProjectionMatrix must be up to date when this is called
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
- static void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
+ void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
- static VertexShaderConstants constants;
- static bool dirty;
+ VertexShaderConstants constants{};
+ bool dirty = false;
+
+private:
+ alignas(16) std::array<float, 16> g_fProjectionMatrix;
+
+ // track changes
+ std::array<bool, 2> bTexMatricesChanged{};
+ bool bPosNormalMatrixChanged = false;
+ bool bProjectionChanged = false;
+ bool bViewportChanged = false;
+ bool bTexMtxInfoChanged = false;
+ bool bLightingConfigChanged = false;
+ bool bProjectionGraphicsModChange = false;
+ BitSet32 nMaterialsChanged;
+ std::array<int, 2> nTransformMatricesChanged{}; // min,max
+ std::array<int, 2> nNormalMatricesChanged{}; // min,max
+ std::array<int, 2> nPostTransformMatricesChanged{}; // min,max
+ std::array<int, 2> nLightsChanged{}; // min,max
+
+ Common::Matrix44 s_viewportCorrection{};
};
diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp
index 18ab088fbb..568a12052d 100644
--- a/Source/Core/VideoCommon/VideoBackendBase.cpp
+++ b/Source/Core/VideoCommon/VideoBackendBase.cpp
@@ -328,7 +328,7 @@ void VideoBackendBase::InitializeShared()
system.GetPixelEngine().Init(system);
BPInit();
VertexLoaderManager::Init();
- VertexShaderManager::Init();
+ system.GetVertexShaderManager().Init();
GeometryShaderManager::Init();
system.GetPixelShaderManager().Init();
TMEM::Init();
diff --git a/Source/Core/VideoCommon/VideoState.cpp b/Source/Core/VideoCommon/VideoState.cpp
index 20af9c9f2b..23db63a65a 100644
--- a/Source/Core/VideoCommon/VideoState.cpp
+++ b/Source/Core/VideoCommon/VideoState.cpp
@@ -76,7 +76,7 @@ void VideoCommon_DoState(PointerWrap& p)
system.GetPixelShaderManager().DoState(p);
p.DoMarker("PixelShaderManager");
- VertexShaderManager::DoState(p);
+ system.GetVertexShaderManager().DoState(p);
p.DoMarker("VertexShaderManager");
GeometryShaderManager::DoState(p);
diff --git a/Source/Core/VideoCommon/XFStructs.cpp b/Source/Core/VideoCommon/XFStructs.cpp
index dd88572716..32d5085b76 100644
--- a/Source/Core/VideoCommon/XFStructs.cpp
+++ b/Source/Core/VideoCommon/XFStructs.cpp
@@ -21,13 +21,14 @@
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/XFMemory.h"
-static void XFMemWritten(u32 transferSize, u32 baseAddress)
+static void XFMemWritten(VertexShaderManager& vertex_shader_manager, u32 transferSize,
+ u32 baseAddress)
{
g_vertex_manager->Flush();
- VertexShaderManager::InvalidateXFRange(baseAddress, baseAddress + transferSize);
+ vertex_shader_manager.InvalidateXFRange(baseAddress, baseAddress + transferSize);
}
-static void XFRegWritten(u32 address, u32 value)
+static void XFRegWritten(VertexShaderManager& vertex_shader_manager, u32 address, u32 value)
{
if (address >= XFMEM_REGISTERS_START && address < XFMEM_REGISTERS_END)
{
@@ -61,7 +62,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETNUMCHAN:
if (xfmem.numChan.numColorChans != (value & 3))
g_vertex_manager->Flush();
- VertexShaderManager::SetLightingConfigChanged();
+ vertex_shader_manager.SetLightingConfigChanged();
break;
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
@@ -71,7 +72,7 @@ static void XFRegWritten(u32 address, u32 value)
if (xfmem.ambColor[chan] != value)
{
g_vertex_manager->Flush();
- VertexShaderManager::SetMaterialColorChanged(chan);
+ vertex_shader_manager.SetMaterialColorChanged(chan);
}
break;
}
@@ -83,7 +84,7 @@ static void XFRegWritten(u32 address, u32 value)
if (xfmem.matColor[chan] != value)
{
g_vertex_manager->Flush();
- VertexShaderManager::SetMaterialColorChanged(chan + 2);
+ vertex_shader_manager.SetMaterialColorChanged(chan + 2);
}
break;
}
@@ -94,21 +95,21 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETCHAN1_ALPHA:
if (((u32*)&xfmem)[address] != (value & 0x7fff))
g_vertex_manager->Flush();
- VertexShaderManager::SetLightingConfigChanged();
+ vertex_shader_manager.SetLightingConfigChanged();
break;
case XFMEM_DUALTEX:
if (xfmem.dualTexTrans.enabled != bool(value & 1))
g_vertex_manager->Flush();
- VertexShaderManager::SetTexMatrixInfoChanged(-1);
+ vertex_shader_manager.SetTexMatrixInfoChanged(-1);
break;
case XFMEM_SETMATRIXINDA:
- VertexShaderManager::SetTexMatrixChangedA(value);
+ vertex_shader_manager.SetTexMatrixChangedA(value);
VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
break;
case XFMEM_SETMATRIXINDB:
- VertexShaderManager::SetTexMatrixChangedB(value);
+ vertex_shader_manager.SetTexMatrixChangedB(value);
VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
break;
@@ -121,7 +122,7 @@ static void XFRegWritten(u32 address, u32 value)
{
auto& system = Core::System::GetInstance();
g_vertex_manager->Flush();
- VertexShaderManager::SetViewportChanged();
+ vertex_shader_manager.SetViewportChanged();
system.GetPixelShaderManager().SetViewportChanged();
GeometryShaderManager::SetViewportChanged();
break;
@@ -135,7 +136,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETPROJECTION + 5:
case XFMEM_SETPROJECTION + 6:
g_vertex_manager->Flush();
- VertexShaderManager::SetProjectionChanged();
+ vertex_shader_manager.SetProjectionChanged();
GeometryShaderManager::SetProjectionChanged();
break;
@@ -153,7 +154,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETTEXMTXINFO + 6:
case XFMEM_SETTEXMTXINFO + 7:
g_vertex_manager->Flush();
- VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETTEXMTXINFO);
+ vertex_shader_manager.SetTexMatrixInfoChanged(address - XFMEM_SETTEXMTXINFO);
break;
case XFMEM_SETPOSTMTXINFO:
@@ -165,7 +166,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETPOSTMTXINFO + 6:
case XFMEM_SETPOSTMTXINFO + 7:
g_vertex_manager->Flush();
- VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETPOSTMTXINFO);
+ vertex_shader_manager.SetTexMatrixInfoChanged(address - XFMEM_SETPOSTMTXINFO);
break;
// --------------
@@ -218,6 +219,9 @@ void LoadXFReg(u16 base_address, u8 transfer_size, const u8* data)
end_address = XFMEM_REGISTERS_END;
}
+ auto& system = Core::System::GetInstance();
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
+
// write to XF mem
if (base_address < XFMEM_REGISTERS_START)
{
@@ -230,7 +234,7 @@ void LoadXFReg(u16 base_address, u8 transfer_size, const u8* data)
base_address = XFMEM_REGISTERS_START;
}
- XFMemWritten(xf_mem_transfer_size, xf_mem_base);
+ XFMemWritten(vertex_shader_manager, xf_mem_transfer_size, xf_mem_base);
for (u32 i = 0; i < xf_mem_transfer_size; i++)
{
((u32*)&xfmem)[xf_mem_base + i] = Common::swap32(data);
@@ -245,7 +249,7 @@ void LoadXFReg(u16 base_address, u8 transfer_size, const u8* data)
{
const u32 value = Common::swap32(data);
- XFRegWritten(address, value);
+ XFRegWritten(vertex_shader_manager, address, value);
((u32*)&xfmem)[address] = value;
data += 4;
@@ -272,13 +276,15 @@ void LoadIndexedXF(CPArray array, u32 index, u16 address, u8 size)
newData = (u32*)memory.GetPointer(g_main_cp_state.array_bases[array] +
g_main_cp_state.array_strides[array] * index);
}
+
+ auto& vertex_shader_manager = system.GetVertexShaderManager();
bool changed = false;
for (u32 i = 0; i < size; ++i)
{
if (currData[i] != Common::swap32(newData[i]))
{
changed = true;
- XFMemWritten(size, address);
+ XFMemWritten(vertex_shader_manager, size, address);
break;
}
}