VideoCommon: De-globalize VertexShaderManager class.

This commit is contained in:
Admiral H. Curtiss 2022-12-28 15:38:46 +01:00
parent 0900e68986
commit 50625728e0
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
19 changed files with 151 additions and 101 deletions

View File

@ -256,6 +256,8 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume,
{ {
INFO_LOG_FMT(BOOT, "Faking GC BS2..."); INFO_LOG_FMT(BOOT, "Faking GC BS2...");
auto& system = Core::System::GetInstance();
SetupMSR(); SetupMSR();
SetupHID(/*is_wii*/ false); SetupHID(/*is_wii*/ false);
SetupBAT(/*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[0x3e * 4 + 1] = 1.0f;
xfmem.postMatrices[0x3f * 4 + 2] = 1.0f; xfmem.postMatrices[0x3f * 4 + 2] = 1.0f;
g_vertex_manager->Flush(); 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); DVDReadDiscID(volume, 0x00000000);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
bool streaming = memory.Read_U8(0x80000008); bool streaming = memory.Read_U8(0x80000008);
if (streaming) if (streaming)

View File

@ -22,6 +22,7 @@
#include "VideoCommon/Fifo.h" #include "VideoCommon/Fifo.h"
#include "VideoCommon/PixelEngine.h" #include "VideoCommon/PixelEngine.h"
#include "VideoCommon/PixelShaderManager.h" #include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/VertexShaderManager.h"
namespace Core namespace Core
{ {
@ -45,6 +46,7 @@ struct System::Impl
PixelShaderManager m_pixel_shader_manager; PixelShaderManager m_pixel_shader_manager;
SerialInterface::SerialInterfaceState m_serial_interface_state; SerialInterface::SerialInterfaceState m_serial_interface_state;
Sram m_sram; Sram m_sram;
VertexShaderManager m_vertex_shader_manager;
VideoInterface::VideoInterfaceState m_video_interface_state; VideoInterface::VideoInterfaceState m_video_interface_state;
}; };
@ -161,6 +163,11 @@ Sram& System::GetSRAM() const
return m_impl->m_sram; return m_impl->m_sram;
} }
VertexShaderManager& System::GetVertexShaderManager() const
{
return m_impl->m_vertex_shader_manager;
}
VideoInterface::VideoInterfaceState& System::GetVideoInterfaceState() const VideoInterface::VideoInterfaceState& System::GetVideoInterfaceState() const
{ {
return m_impl->m_video_interface_state; return m_impl->m_video_interface_state;

View File

@ -8,6 +8,7 @@
class PixelShaderManager; class PixelShaderManager;
class SoundStream; class SoundStream;
struct Sram; struct Sram;
class VertexShaderManager;
namespace AudioInterface namespace AudioInterface
{ {
@ -110,6 +111,7 @@ public:
PixelShaderManager& GetPixelShaderManager() const; PixelShaderManager& GetPixelShaderManager() const;
SerialInterface::SerialInterfaceState& GetSerialInterfaceState() const; SerialInterface::SerialInterfaceState& GetSerialInterfaceState() const;
Sram& GetSRAM() const; Sram& GetSRAM() const;
VertexShaderManager& GetVertexShaderManager() const;
VideoInterface::VideoInterfaceState& GetVideoInterfaceState() const; VideoInterface::VideoInterfaceState& GetVideoInterfaceState() const;
private: private:

View File

@ -264,12 +264,14 @@ void VertexManager::UploadUniforms()
{ {
auto& system = Core::System::GetInstance(); 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)); sizeof(VertexShaderConstants));
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
} }
if (GeometryShaderManager::dirty) if (GeometryShaderManager::dirty)
{ {
UpdateConstantBuffer(m_geometry_constant_buffer.Get(), &GeometryShaderManager::constants, UpdateConstantBuffer(m_geometry_constant_buffer.Get(), &GeometryShaderManager::constants,

View File

@ -145,15 +145,18 @@ void VertexManager::UploadUniforms()
void VertexManager::UpdateVertexShaderConstants() 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; return;
Renderer::GetInstance()->SetConstantBuffer(1, m_uniform_stream_buffer.GetCurrentGPUPointer()); 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)); sizeof(VertexShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(VertexShaderConstants)); m_uniform_stream_buffer.CommitMemory(sizeof(VertexShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants)); ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants));
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
} }
void VertexManager::UpdateGeometryShaderConstants() void VertexManager::UpdateGeometryShaderConstants()
@ -237,12 +240,13 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager(); auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
// Copy the actual data in // Copy the actual data in
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + pixel_constants_offset, std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + pixel_constants_offset,
&pixel_shader_manager.constants, sizeof(PixelShaderConstants)); &pixel_shader_manager.constants, sizeof(PixelShaderConstants));
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + vertex_constants_offset, 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, std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants)); &GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
@ -251,7 +255,7 @@ void VertexManager::UploadAllConstants()
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size); ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size);
// Clear dirty flags // Clear dirty flags
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false; GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false; pixel_shader_manager.dirty = false;
} }

View File

@ -836,7 +836,9 @@ void Metal::StateTracker::PrepareRender()
{ {
m_flags.has_gx_vs_uniform = true; m_flags.has_gx_vs_uniform = true;
Map map = Allocate(UploadBuffer::Uniform, sizeof(VertexShaderConstants), AlignMask::Uniform); 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); SetVertexBufferNow(1, map.gpu_buffer, map.gpu_offset);
if (pipe->UsesFragmentBuffer(1)) if (pipe->UsesFragmentBuffer(1))
SetFragmentBufferNow(1, map.gpu_buffer, map.gpu_offset); SetFragmentBufferNow(1, map.gpu_buffer, map.gpu_offset);

View File

@ -93,9 +93,10 @@ void Metal::VertexManager::UploadUniforms()
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager(); 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); pixel_shader_manager.dirty);
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false; GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false; pixel_shader_manager.dirty = false;
} }

View File

@ -223,14 +223,15 @@ void ProgramShaderCache::UploadConstants()
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager(); 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); auto buffer = s_buffer->Map(s_ubo_buffer_size, s_ubo_align);
memcpy(buffer.first, &pixel_shader_manager.constants, sizeof(PixelShaderConstants)); memcpy(buffer.first, &pixel_shader_manager.constants, sizeof(PixelShaderConstants));
memcpy(buffer.first + Common::AlignUp(sizeof(PixelShaderConstants), s_ubo_align), 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) + memcpy(buffer.first + Common::AlignUp(sizeof(PixelShaderConstants), s_ubo_align) +
Common::AlignUp(sizeof(VertexShaderConstants), s_ubo_align), Common::AlignUp(sizeof(VertexShaderConstants), s_ubo_align),
@ -248,7 +249,7 @@ void ProgramShaderCache::UploadConstants()
sizeof(GeometryShaderConstants)); sizeof(GeometryShaderConstants));
pixel_shader_manager.dirty = false; pixel_shader_manager.dirty = false;
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false; GeometryShaderManager::dirty = false;
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, s_ubo_buffer_size); ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, s_ubo_buffer_size);

View File

@ -10,6 +10,8 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Core/System.h"
#include "VideoBackends/Software/NativeVertexFormat.h" #include "VideoBackends/Software/NativeVertexFormat.h"
#include "VideoBackends/Software/Rasterizer.h" #include "VideoBackends/Software/Rasterizer.h"
#include "VideoBackends/Software/SWRenderer.h" #include "VideoBackends/Software/SWRenderer.h"
@ -205,15 +207,19 @@ void SWVertexLoader::ParseVertex(const PortableVertexDeclaration& vdec, int inde
} }
if (!vdec.normals[1].enable) if (!vdec.normals[1].enable)
{ {
m_vertex.normal[1][0] = VertexShaderManager::constants.cached_tangent[0]; auto& system = Core::System::GetInstance();
m_vertex.normal[1][1] = VertexShaderManager::constants.cached_tangent[1]; auto& vertex_shader_manager = system.GetVertexShaderManager();
m_vertex.normal[1][2] = VertexShaderManager::constants.cached_tangent[2]; 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) if (!vdec.normals[2].enable)
{ {
m_vertex.normal[2][0] = VertexShaderManager::constants.cached_binormal[0]; auto& system = Core::System::GetInstance();
m_vertex.normal[2][1] = VertexShaderManager::constants.cached_binormal[1]; auto& vertex_shader_manager = system.GetVertexShaderManager();
m_vertex.normal[2][2] = VertexShaderManager::constants.cached_binormal[2]; 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); ParseColorAttributes(&m_vertex, src, vdec);

View File

@ -204,17 +204,20 @@ void VertexManager::UploadUniforms()
void VertexManager::UpdateVertexShaderConstants() 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; return;
StateTracker::GetInstance()->SetGXUniformBuffer( StateTracker::GetInstance()->SetGXUniformBuffer(
UBO_DESCRIPTOR_SET_BINDING_VS, m_uniform_stream_buffer->GetBuffer(), UBO_DESCRIPTOR_SET_BINDING_VS, m_uniform_stream_buffer->GetBuffer(),
m_uniform_stream_buffer->GetCurrentOffset(), sizeof(VertexShaderConstants)); 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)); sizeof(VertexShaderConstants));
m_uniform_stream_buffer->CommitMemory(sizeof(VertexShaderConstants)); m_uniform_stream_buffer->CommitMemory(sizeof(VertexShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants)); ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(VertexShaderConstants));
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
} }
void VertexManager::UpdateGeometryShaderConstants() void VertexManager::UpdateGeometryShaderConstants()
@ -289,6 +292,7 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager(); auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
// Update bindings // Update bindings
StateTracker::GetInstance()->SetGXUniformBuffer( StateTracker::GetInstance()->SetGXUniformBuffer(
@ -308,7 +312,7 @@ void VertexManager::UploadAllConstants()
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + pixel_constants_offset, std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + pixel_constants_offset,
&pixel_shader_manager.constants, sizeof(PixelShaderConstants)); &pixel_shader_manager.constants, sizeof(PixelShaderConstants));
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + vertex_constants_offset, 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, std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants)); &GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
@ -317,7 +321,7 @@ void VertexManager::UploadAllConstants()
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size); ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, allocation_size);
// Clear dirty flags // Clear dirty flags
VertexShaderManager::dirty = false; vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false; GeometryShaderManager::dirty = false;
pixel_shader_manager.dirty = false; pixel_shader_manager.dirty = false;
} }

View File

@ -54,7 +54,8 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF; 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) 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_SCISSORTL: // Scissor Rectable Top, Left
case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
case BPMEM_SCISSOROFFSET: // Scissor Offset case BPMEM_SCISSOROFFSET: // Scissor Offset
VertexShaderManager::SetViewportChanged(); vertex_shader_manager.SetViewportChanged();
GeometryShaderManager::SetViewportChanged(); GeometryShaderManager::SetViewportChanged();
return; return;
case BPMEM_LINEPTWIDTH: // Line Width case BPMEM_LINEPTWIDTH: // Line Width
@ -762,7 +763,8 @@ void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
if (reg != BPMEM_BP_MASK) if (reg != BPMEM_BP_MASK)
bpmem.bpMask = 0xFFFFFF; 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) void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future)

View File

@ -59,12 +59,14 @@ public:
if (sub_command == MATINDEX_A) if (sub_command == MATINDEX_A)
{ {
VertexLoaderManager::g_needs_cp_xf_consistency_check = true; 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) else if (sub_command == MATINDEX_B)
{ {
VertexLoaderManager::g_needs_cp_xf_consistency_check = true; 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) else if (sub_command == VCD_LO || sub_command == VCD_HI)
{ {

View File

@ -361,8 +361,10 @@ int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int coun
} }
s_current_vtx_fmt = loader->m_native_vertex_format; s_current_vtx_fmt = loader->m_native_vertex_format;
g_current_components = loader->m_native_components; g_current_components = loader->m_native_components;
VertexShaderManager::SetVertexFormat(loader->m_native_components, auto& system = Core::System::GetInstance();
loader->m_native_vertex_format->GetVertexDeclaration()); 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. // 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 // They still need to go through vertex loading, because we need to calculate a zfreeze refrence

View File

@ -319,8 +319,9 @@ void VertexManagerBase::UploadUniforms()
void VertexManagerBase::InvalidateConstants() void VertexManagerBase::InvalidateConstants()
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& vertex_shader_manager = system.GetVertexShaderManager();
auto& pixel_shader_manager = system.GetPixelShaderManager(); auto& pixel_shader_manager = system.GetPixelShaderManager();
VertexShaderManager::dirty = true; vertex_shader_manager.dirty = true;
GeometryShaderManager::dirty = true; GeometryShaderManager::dirty = true;
pixel_shader_manager.dirty = true; pixel_shader_manager.dirty = true;
} }
@ -486,6 +487,7 @@ void VertexManagerBase::Flush()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager(); auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat()); CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
// Calculate ZSlope for zfreeze // 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) if (!bpmem.genMode.zfreeze)
{ {
// Must be done after VertexShaderManager::SetConstants() // 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 // 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 // This allows us to determine the depth slope, which will be used if z-freeze
// is enabled in the following flush. // 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) for (unsigned int i = 0; i < 3; ++i)
{ {
// If this vertex format has per-vertex position matrix IDs, look it up. // 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) if (vert_decl.position.components == 2)
VertexLoaderManager::position_cache[2 - i][2] = 0; VertexLoaderManager::position_cache[2 - i][2] = 0;
VertexShaderManager::TransformToClipSpace(&VertexLoaderManager::position_cache[2 - i][0], vertex_shader_manager.TransformToClipSpace(&VertexLoaderManager::position_cache[2 - i][0],
&out[i * 4], mtxIdx); &out[i * 4], mtxIdx);
// Transform to Screenspace // Transform to Screenspace
float inv_w = 1.0f / out[3 + i * 4]; float inv_w = 1.0f / out[3 + i * 4];
@ -688,15 +692,17 @@ void VertexManagerBase::CalculateBinormals(NativeVertexFormat* format)
VertexLoaderManager::tangent_cache[3] = 0; VertexLoaderManager::tangent_cache[3] = 0;
VertexLoaderManager::binormal_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; vertex_shader_manager.constants.cached_tangent = VertexLoaderManager::tangent_cache;
VertexShaderManager::dirty = true; 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; vertex_shader_manager.constants.cached_binormal = VertexLoaderManager::binormal_cache;
VertexShaderManager::dirty = true; vertex_shader_manager.dirty = true;
} }
} }

View File

@ -30,27 +30,6 @@
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.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() void VertexShaderManager::Init()
{ {
// Initialize state tracking variables // Initialize state tracking variables

View File

@ -3,43 +3,65 @@
#pragma once #pragma once
#include <array>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/BitSet.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Matrix.h"
#include "VideoCommon/ConstantManager.h" #include "VideoCommon/ConstantManager.h"
class PointerWrap; class PointerWrap;
struct PortableVertexDeclaration; struct PortableVertexDeclaration;
// The non-API dependent parts. // The non-API dependent parts.
class VertexShaderManager class alignas(16) VertexShaderManager
{ {
public: public:
static void Init(); void Init();
static void Dirty(); void Dirty();
static void DoState(PointerWrap& p); void DoState(PointerWrap& p);
// constant management // 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); void InvalidateXFRange(int start, int end);
static void SetTexMatrixChangedA(u32 value); void SetTexMatrixChangedA(u32 value);
static void SetTexMatrixChangedB(u32 value); void SetTexMatrixChangedB(u32 value);
static void SetViewportChanged(); void SetViewportChanged();
static void SetProjectionChanged(); void SetProjectionChanged();
static void SetMaterialColorChanged(int index); void SetMaterialColorChanged(int index);
static void SetVertexFormat(u32 components, const PortableVertexDeclaration& format); void SetVertexFormat(u32 components, const PortableVertexDeclaration& format);
static void SetTexMatrixInfoChanged(int index); void SetTexMatrixInfoChanged(int index);
static void SetLightingConfigChanged(); void SetLightingConfigChanged();
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index. // 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 // 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 // NOTE: g_fProjectionMatrix must be up to date when this is called
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!) // (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; VertexShaderConstants constants{};
static bool dirty; 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{};
}; };

View File

@ -328,7 +328,7 @@ void VideoBackendBase::InitializeShared()
system.GetPixelEngine().Init(system); system.GetPixelEngine().Init(system);
BPInit(); BPInit();
VertexLoaderManager::Init(); VertexLoaderManager::Init();
VertexShaderManager::Init(); system.GetVertexShaderManager().Init();
GeometryShaderManager::Init(); GeometryShaderManager::Init();
system.GetPixelShaderManager().Init(); system.GetPixelShaderManager().Init();
TMEM::Init(); TMEM::Init();

View File

@ -76,7 +76,7 @@ void VideoCommon_DoState(PointerWrap& p)
system.GetPixelShaderManager().DoState(p); system.GetPixelShaderManager().DoState(p);
p.DoMarker("PixelShaderManager"); p.DoMarker("PixelShaderManager");
VertexShaderManager::DoState(p); system.GetVertexShaderManager().DoState(p);
p.DoMarker("VertexShaderManager"); p.DoMarker("VertexShaderManager");
GeometryShaderManager::DoState(p); GeometryShaderManager::DoState(p);

View File

@ -21,13 +21,14 @@
#include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/XFMemory.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(); 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) if (address >= XFMEM_REGISTERS_START && address < XFMEM_REGISTERS_END)
{ {
@ -61,7 +62,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETNUMCHAN: case XFMEM_SETNUMCHAN:
if (xfmem.numChan.numColorChans != (value & 3)) if (xfmem.numChan.numColorChans != (value & 3))
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetLightingConfigChanged(); vertex_shader_manager.SetLightingConfigChanged();
break; break;
case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color case XFMEM_SETCHAN0_AMBCOLOR: // Channel Ambient Color
@ -71,7 +72,7 @@ static void XFRegWritten(u32 address, u32 value)
if (xfmem.ambColor[chan] != value) if (xfmem.ambColor[chan] != value)
{ {
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetMaterialColorChanged(chan); vertex_shader_manager.SetMaterialColorChanged(chan);
} }
break; break;
} }
@ -83,7 +84,7 @@ static void XFRegWritten(u32 address, u32 value)
if (xfmem.matColor[chan] != value) if (xfmem.matColor[chan] != value)
{ {
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetMaterialColorChanged(chan + 2); vertex_shader_manager.SetMaterialColorChanged(chan + 2);
} }
break; break;
} }
@ -94,21 +95,21 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETCHAN1_ALPHA: case XFMEM_SETCHAN1_ALPHA:
if (((u32*)&xfmem)[address] != (value & 0x7fff)) if (((u32*)&xfmem)[address] != (value & 0x7fff))
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetLightingConfigChanged(); vertex_shader_manager.SetLightingConfigChanged();
break; break;
case XFMEM_DUALTEX: case XFMEM_DUALTEX:
if (xfmem.dualTexTrans.enabled != bool(value & 1)) if (xfmem.dualTexTrans.enabled != bool(value & 1))
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetTexMatrixInfoChanged(-1); vertex_shader_manager.SetTexMatrixInfoChanged(-1);
break; break;
case XFMEM_SETMATRIXINDA: case XFMEM_SETMATRIXINDA:
VertexShaderManager::SetTexMatrixChangedA(value); vertex_shader_manager.SetTexMatrixChangedA(value);
VertexLoaderManager::g_needs_cp_xf_consistency_check = true; VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
break; break;
case XFMEM_SETMATRIXINDB: case XFMEM_SETMATRIXINDB:
VertexShaderManager::SetTexMatrixChangedB(value); vertex_shader_manager.SetTexMatrixChangedB(value);
VertexLoaderManager::g_needs_cp_xf_consistency_check = true; VertexLoaderManager::g_needs_cp_xf_consistency_check = true;
break; break;
@ -121,7 +122,7 @@ static void XFRegWritten(u32 address, u32 value)
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetViewportChanged(); vertex_shader_manager.SetViewportChanged();
system.GetPixelShaderManager().SetViewportChanged(); system.GetPixelShaderManager().SetViewportChanged();
GeometryShaderManager::SetViewportChanged(); GeometryShaderManager::SetViewportChanged();
break; break;
@ -135,7 +136,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETPROJECTION + 5: case XFMEM_SETPROJECTION + 5:
case XFMEM_SETPROJECTION + 6: case XFMEM_SETPROJECTION + 6:
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetProjectionChanged(); vertex_shader_manager.SetProjectionChanged();
GeometryShaderManager::SetProjectionChanged(); GeometryShaderManager::SetProjectionChanged();
break; break;
@ -153,7 +154,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETTEXMTXINFO + 6: case XFMEM_SETTEXMTXINFO + 6:
case XFMEM_SETTEXMTXINFO + 7: case XFMEM_SETTEXMTXINFO + 7:
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETTEXMTXINFO); vertex_shader_manager.SetTexMatrixInfoChanged(address - XFMEM_SETTEXMTXINFO);
break; break;
case XFMEM_SETPOSTMTXINFO: case XFMEM_SETPOSTMTXINFO:
@ -165,7 +166,7 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETPOSTMTXINFO + 6: case XFMEM_SETPOSTMTXINFO + 6:
case XFMEM_SETPOSTMTXINFO + 7: case XFMEM_SETPOSTMTXINFO + 7:
g_vertex_manager->Flush(); g_vertex_manager->Flush();
VertexShaderManager::SetTexMatrixInfoChanged(address - XFMEM_SETPOSTMTXINFO); vertex_shader_manager.SetTexMatrixInfoChanged(address - XFMEM_SETPOSTMTXINFO);
break; break;
// -------------- // --------------
@ -218,6 +219,9 @@ void LoadXFReg(u16 base_address, u8 transfer_size, const u8* data)
end_address = XFMEM_REGISTERS_END; end_address = XFMEM_REGISTERS_END;
} }
auto& system = Core::System::GetInstance();
auto& vertex_shader_manager = system.GetVertexShaderManager();
// write to XF mem // write to XF mem
if (base_address < XFMEM_REGISTERS_START) 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; 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++) for (u32 i = 0; i < xf_mem_transfer_size; i++)
{ {
((u32*)&xfmem)[xf_mem_base + i] = Common::swap32(data); ((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); const u32 value = Common::swap32(data);
XFRegWritten(address, value); XFRegWritten(vertex_shader_manager, address, value);
((u32*)&xfmem)[address] = value; ((u32*)&xfmem)[address] = value;
data += 4; 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] + newData = (u32*)memory.GetPointer(g_main_cp_state.array_bases[array] +
g_main_cp_state.array_strides[array] * index); g_main_cp_state.array_strides[array] * index);
} }
auto& vertex_shader_manager = system.GetVertexShaderManager();
bool changed = false; bool changed = false;
for (u32 i = 0; i < size; ++i) for (u32 i = 0; i < size; ++i)
{ {
if (currData[i] != Common::swap32(newData[i])) if (currData[i] != Common::swap32(newData[i]))
{ {
changed = true; changed = true;
XFMemWritten(size, address); XFMemWritten(vertex_shader_manager, size, address);
break; break;
} }
} }