VideoCommon: De-globalize GeometryShaderManager class.

This commit is contained in:
Admiral H. Curtiss 2022-12-29 15:27:48 +01:00
parent 1bfecd8003
commit cb0a603c72
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
15 changed files with 90 additions and 67 deletions

View File

@ -20,6 +20,7 @@
#include "Core/HW/VideoInterface.h"
#include "VideoCommon/CommandProcessor.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/GeometryShaderManager.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/VertexShaderManager.h"
@ -40,6 +41,7 @@ struct System::Impl
DVDThread::DVDThreadState m_dvd_thread_state;
ExpansionInterface::ExpansionInterfaceState m_expansion_interface_state;
Fifo::FifoManager m_fifo;
GeometryShaderManager m_geometry_shader_manager;
Memory::MemoryManager m_memory;
MemoryInterface::MemoryInterfaceState m_memory_interface_state;
PixelEngine::PixelEngineManager m_pixel_engine;
@ -133,6 +135,11 @@ Fifo::FifoManager& System::GetFifo() const
return m_impl->m_fifo;
}
GeometryShaderManager& System::GetGeometryShaderManager() const
{
return m_impl->m_geometry_shader_manager;
}
Memory::MemoryManager& System::GetMemory() const
{
return m_impl->m_memory;

View File

@ -5,6 +5,7 @@
#include <memory>
class GeometryShaderManager;
class PixelShaderManager;
class SoundStream;
struct Sram;
@ -105,6 +106,7 @@ public:
DVDThread::DVDThreadState& GetDVDThreadState() const;
ExpansionInterface::ExpansionInterfaceState& GetExpansionInterfaceState() const;
Fifo::FifoManager& GetFifo() const;
GeometryShaderManager& GetGeometryShaderManager() const;
Memory::MemoryManager& GetMemory() const;
MemoryInterface::MemoryInterfaceState& GetMemoryInterfaceState() const;
PixelEngine::PixelEngineManager& GetPixelEngine() const;

View File

@ -272,11 +272,12 @@ void VertexManager::UploadUniforms()
vertex_shader_manager.dirty = false;
}
if (GeometryShaderManager::dirty)
auto& geometry_shader_manager = system.GetGeometryShaderManager();
if (geometry_shader_manager.dirty)
{
UpdateConstantBuffer(m_geometry_constant_buffer.Get(), &GeometryShaderManager::constants,
UpdateConstantBuffer(m_geometry_constant_buffer.Get(), &geometry_shader_manager.constants,
sizeof(GeometryShaderConstants));
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
}
auto& pixel_shader_manager = system.GetPixelShaderManager();

View File

@ -161,15 +161,18 @@ void VertexManager::UpdateVertexShaderConstants()
void VertexManager::UpdateGeometryShaderConstants()
{
if (!GeometryShaderManager::dirty || !ReserveConstantStorage())
auto& system = Core::System::GetInstance();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
if (!geometry_shader_manager.dirty || !ReserveConstantStorage())
return;
Renderer::GetInstance()->SetConstantBuffer(2, m_uniform_stream_buffer.GetCurrentGPUPointer());
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &GeometryShaderManager::constants,
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer(), &geometry_shader_manager.constants,
sizeof(GeometryShaderConstants));
m_uniform_stream_buffer.CommitMemory(sizeof(GeometryShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(GeometryShaderConstants));
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
}
void VertexManager::UpdatePixelShaderConstants()
@ -241,6 +244,7 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
// Copy the actual data in
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + pixel_constants_offset,
@ -248,7 +252,7 @@ void VertexManager::UploadAllConstants()
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + vertex_constants_offset,
&vertex_shader_manager.constants, sizeof(VertexShaderConstants));
std::memcpy(m_uniform_stream_buffer.GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
&geometry_shader_manager.constants, sizeof(GeometryShaderConstants));
// Finally, flush buffer memory after copying
m_uniform_stream_buffer.CommitMemory(allocation_size);
@ -256,7 +260,7 @@ void VertexManager::UploadAllConstants()
// Clear dirty flags
vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
pixel_shader_manager.dirty = false;
}

View File

@ -848,7 +848,9 @@ void Metal::StateTracker::PrepareRender()
if (!m_flags.has_gx_gs_uniform && pipe->UsesVertexBuffer(2))
{
m_flags.has_gx_gs_uniform = true;
[m_current_render_encoder setVertexBytes:&GeometryShaderManager::constants
auto& system = Core::System::GetInstance();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
[m_current_render_encoder setVertexBytes:&geometry_shader_manager.constants
length:sizeof(GeometryShaderConstants)
atIndex:2];
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(GeometryShaderConstants));

View File

@ -92,11 +92,12 @@ void Metal::VertexManager::CommitBuffer(u32 num_vertices, u32 vertex_stride, u32
void Metal::VertexManager::UploadUniforms()
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
g_state_tracker->InvalidateUniforms(vertex_shader_manager.dirty, GeometryShaderManager::dirty,
auto& geometry_shader_manager = system.GetGeometryShaderManager();
auto& pixel_shader_manager = system.GetPixelShaderManager();
g_state_tracker->InvalidateUniforms(vertex_shader_manager.dirty, geometry_shader_manager.dirty,
pixel_shader_manager.dirty);
vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
pixel_shader_manager.dirty = false;
}

View File

@ -224,7 +224,8 @@ void ProgramShaderCache::UploadConstants()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
if (pixel_shader_manager.dirty || vertex_shader_manager.dirty || GeometryShaderManager::dirty)
auto& geometry_shader_manager = system.GetGeometryShaderManager();
if (pixel_shader_manager.dirty || vertex_shader_manager.dirty || geometry_shader_manager.dirty)
{
auto buffer = s_buffer->Map(s_ubo_buffer_size, s_ubo_align);
@ -235,7 +236,7 @@ void ProgramShaderCache::UploadConstants()
memcpy(buffer.first + Common::AlignUp(sizeof(PixelShaderConstants), s_ubo_align) +
Common::AlignUp(sizeof(VertexShaderConstants), s_ubo_align),
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
&geometry_shader_manager.constants, sizeof(GeometryShaderConstants));
s_buffer->Unmap(s_ubo_buffer_size);
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->m_buffer, buffer.second,
@ -250,7 +251,7 @@ void ProgramShaderCache::UploadConstants()
pixel_shader_manager.dirty = false;
vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, s_ubo_buffer_size);
}

View File

@ -222,17 +222,20 @@ void VertexManager::UpdateVertexShaderConstants()
void VertexManager::UpdateGeometryShaderConstants()
{
if (!GeometryShaderManager::dirty || !ReserveConstantStorage())
auto& system = Core::System::GetInstance();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
if (!geometry_shader_manager.dirty || !ReserveConstantStorage())
return;
StateTracker::GetInstance()->SetGXUniformBuffer(
UBO_DESCRIPTOR_SET_BINDING_GS, m_uniform_stream_buffer->GetBuffer(),
m_uniform_stream_buffer->GetCurrentOffset(), sizeof(GeometryShaderConstants));
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer(), &GeometryShaderManager::constants,
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer(), &geometry_shader_manager.constants,
sizeof(GeometryShaderConstants));
m_uniform_stream_buffer->CommitMemory(sizeof(GeometryShaderConstants));
ADDSTAT(g_stats.this_frame.bytes_uniform_streamed, sizeof(GeometryShaderConstants));
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
}
void VertexManager::UpdatePixelShaderConstants()
@ -293,6 +296,7 @@ void VertexManager::UploadAllConstants()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
// Update bindings
StateTracker::GetInstance()->SetGXUniformBuffer(
@ -314,7 +318,7 @@ void VertexManager::UploadAllConstants()
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + vertex_constants_offset,
&vertex_shader_manager.constants, sizeof(VertexShaderConstants));
std::memcpy(m_uniform_stream_buffer->GetCurrentHostPointer() + geometry_constants_offset,
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
&geometry_shader_manager.constants, sizeof(GeometryShaderConstants));
// Finally, flush buffer memory after copying
m_uniform_stream_buffer->CommitMemory(allocation_size);
@ -322,7 +326,7 @@ void VertexManager::UploadAllConstants()
// Clear dirty flags
vertex_shader_manager.dirty = false;
GeometryShaderManager::dirty = false;
geometry_shader_manager.dirty = false;
pixel_shader_manager.dirty = false;
}

View File

@ -55,7 +55,8 @@ void BPInit()
}
static void BPWritten(PixelShaderManager& pixel_shader_manager,
VertexShaderManager& vertex_shader_manager, const BPCmd& bp,
VertexShaderManager& vertex_shader_manager,
GeometryShaderManager& geometry_shader_manager, const BPCmd& bp,
int cycles_into_future)
{
/*
@ -138,10 +139,10 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager,
case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
case BPMEM_SCISSOROFFSET: // Scissor Offset
vertex_shader_manager.SetViewportChanged();
GeometryShaderManager::SetViewportChanged();
geometry_shader_manager.SetViewportChanged();
return;
case BPMEM_LINEPTWIDTH: // Line Width
GeometryShaderManager::SetLinePtWidthChanged();
geometry_shader_manager.SetLinePtWidthChanged();
return;
case BPMEM_ZMODE: // Depth Control
PRIM_LOG("zmode: test={}, func={}, upd={}", bpmem.zmode.testenable, bpmem.zmode.func,
@ -674,7 +675,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager,
if (bp.changes)
{
pixel_shader_manager.SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
GeometryShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
geometry_shader_manager.SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
}
return;
}
@ -763,8 +764,8 @@ void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
if (reg != BPMEM_BP_MASK)
bpmem.bpMask = 0xFFFFFF;
BPWritten(system.GetPixelShaderManager(), system.GetVertexShaderManager(), bp,
cycles_into_future);
BPWritten(system.GetPixelShaderManager(), system.GetVertexShaderManager(),
system.GetGeometryShaderManager(), bp, cycles_into_future);
}
void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future)

View File

@ -12,13 +12,7 @@
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"
static const int LINE_PT_TEX_OFFSETS[8] = {0, 16, 8, 4, 2, 1, 1, 1};
GeometryShaderConstants GeometryShaderManager::constants;
bool GeometryShaderManager::dirty;
static bool s_projection_changed;
static bool s_viewport_changed;
static constexpr int LINE_PT_TEX_OFFSETS[8] = {0, 16, 8, 4, 2, 1, 1, 1};
void GeometryShaderManager::Init()
{
@ -35,7 +29,7 @@ void GeometryShaderManager::Dirty()
{
// This function is called after a savestate is loaded.
// Any constants that can changed based on settings should be re-calculated
s_projection_changed = true;
m_projection_changed = true;
// Uses EFB scale config
SetLinePtWidthChanged();
@ -43,20 +37,20 @@ void GeometryShaderManager::Dirty()
dirty = true;
}
static void SetVSExpand(VSExpand expand)
void GeometryShaderManager::SetVSExpand(VSExpand expand)
{
if (GeometryShaderManager::constants.vs_expand != expand)
if (constants.vs_expand != expand)
{
GeometryShaderManager::constants.vs_expand = expand;
GeometryShaderManager::dirty = true;
constants.vs_expand = expand;
dirty = true;
}
}
void GeometryShaderManager::SetConstants(PrimitiveType prim)
{
if (s_projection_changed && g_ActiveConfig.stereo_mode != StereoMode::Off)
if (m_projection_changed && g_ActiveConfig.stereo_mode != StereoMode::Off)
{
s_projection_changed = false;
m_projection_changed = false;
if (xfmem.projection.type == ProjectionType::Perspective)
{
@ -86,9 +80,9 @@ void GeometryShaderManager::SetConstants(PrimitiveType prim)
SetVSExpand(VSExpand::None);
}
if (s_viewport_changed)
if (m_viewport_changed)
{
s_viewport_changed = false;
m_viewport_changed = false;
constants.lineptparams[0] = 2.0f * xfmem.viewport.wd;
constants.lineptparams[1] = -2.0f * xfmem.viewport.ht;
@ -99,12 +93,12 @@ void GeometryShaderManager::SetConstants(PrimitiveType prim)
void GeometryShaderManager::SetViewportChanged()
{
s_viewport_changed = true;
m_viewport_changed = true;
}
void GeometryShaderManager::SetProjectionChanged()
{
s_projection_changed = true;
m_projection_changed = true;
}
void GeometryShaderManager::SetLinePtWidthChanged()
@ -129,8 +123,8 @@ void GeometryShaderManager::SetTexCoordChanged(u8 texmapid)
void GeometryShaderManager::DoState(PointerWrap& p)
{
p.Do(s_projection_changed);
p.Do(s_viewport_changed);
p.Do(m_projection_changed);
p.Do(m_viewport_changed);
p.Do(constants);

View File

@ -13,16 +13,22 @@ enum class PrimitiveType : u32;
class GeometryShaderManager
{
public:
static void Init();
static void Dirty();
static void DoState(PointerWrap& p);
void Init();
void Dirty();
void DoState(PointerWrap& p);
static void SetConstants(PrimitiveType prim);
static void SetViewportChanged();
static void SetProjectionChanged();
static void SetLinePtWidthChanged();
static void SetTexCoordChanged(u8 texmapid);
void SetConstants(PrimitiveType prim);
void SetViewportChanged();
void SetProjectionChanged();
void SetLinePtWidthChanged();
void SetTexCoordChanged(u8 texmapid);
static GeometryShaderConstants constants;
static bool dirty;
GeometryShaderConstants constants{};
bool dirty = false;
private:
void SetVSExpand(VSExpand expand);
bool m_projection_changed = false;
bool m_viewport_changed = false;
};

View File

@ -320,9 +320,10 @@ void VertexManagerBase::InvalidateConstants()
{
auto& system = Core::System::GetInstance();
auto& vertex_shader_manager = system.GetVertexShaderManager();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
auto& pixel_shader_manager = system.GetPixelShaderManager();
vertex_shader_manager.dirty = true;
GeometryShaderManager::dirty = true;
geometry_shader_manager.dirty = true;
pixel_shader_manager.dirty = true;
}
@ -487,6 +488,7 @@ void VertexManagerBase::Flush()
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
auto& geometry_shader_manager = system.GetGeometryShaderManager();
auto& vertex_shader_manager = system.GetVertexShaderManager();
CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
@ -566,7 +568,7 @@ void VertexManagerBase::Flush()
g_texture_cache->BindTextures(used_textures);
// Now we can upload uniforms, as nothing else will override them.
GeometryShaderManager::SetConstants(m_current_primitive_type);
geometry_shader_manager.SetConstants(m_current_primitive_type);
pixel_shader_manager.SetConstants();
UploadUniforms();

View File

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

View File

@ -79,7 +79,7 @@ void VideoCommon_DoState(PointerWrap& p)
system.GetVertexShaderManager().DoState(p);
p.DoMarker("VertexShaderManager");
GeometryShaderManager::DoState(p);
system.GetGeometryShaderManager().DoState(p);
p.DoMarker("GeometryShaderManager");
g_vertex_manager->DoState(p);

View File

@ -28,7 +28,8 @@ static void XFMemWritten(VertexShaderManager& vertex_shader_manager, u32 transfe
vertex_shader_manager.InvalidateXFRange(baseAddress, baseAddress + transferSize);
}
static void XFRegWritten(VertexShaderManager& vertex_shader_manager, u32 address, u32 value)
static void XFRegWritten(Core::System& system, VertexShaderManager& vertex_shader_manager,
u32 address, u32 value)
{
if (address >= XFMEM_REGISTERS_START && address < XFMEM_REGISTERS_END)
{
@ -119,14 +120,11 @@ static void XFRegWritten(VertexShaderManager& vertex_shader_manager, u32 address
case XFMEM_SETVIEWPORT + 3:
case XFMEM_SETVIEWPORT + 4:
case XFMEM_SETVIEWPORT + 5:
{
auto& system = Core::System::GetInstance();
g_vertex_manager->Flush();
vertex_shader_manager.SetViewportChanged();
system.GetPixelShaderManager().SetViewportChanged();
GeometryShaderManager::SetViewportChanged();
system.GetGeometryShaderManager().SetViewportChanged();
break;
}
case XFMEM_SETPROJECTION:
case XFMEM_SETPROJECTION + 1:
@ -137,7 +135,7 @@ static void XFRegWritten(VertexShaderManager& vertex_shader_manager, u32 address
case XFMEM_SETPROJECTION + 6:
g_vertex_manager->Flush();
vertex_shader_manager.SetProjectionChanged();
GeometryShaderManager::SetProjectionChanged();
system.GetGeometryShaderManager().SetProjectionChanged();
break;
case XFMEM_SETNUMTEXGENS: // GXSetNumTexGens
@ -249,7 +247,7 @@ void LoadXFReg(u16 base_address, u8 transfer_size, const u8* data)
{
const u32 value = Common::swap32(data);
XFRegWritten(vertex_shader_manager, address, value);
XFRegWritten(system, vertex_shader_manager, address, value);
((u32*)&xfmem)[address] = value;
data += 4;