Merge pull request #11388 from AdmiralCurtiss/globals-vertexshadermanager

VideoCommon: De-globalize VertexShaderManager class.
This commit is contained in:
Mai 2022-12-29 04:48:24 +00:00 committed by GitHub
commit 7552deeff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 292 additions and 239 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

@ -30,49 +30,28 @@
#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
nTransformMatricesChanged.fill(-1);
nNormalMatricesChanged.fill(-1);
nPostTransformMatricesChanged.fill(-1);
nLightsChanged.fill(-1);
nMaterialsChanged = BitSet32(0);
bTexMatricesChanged.fill(false);
bPosNormalMatrixChanged = false;
bProjectionChanged = true;
bViewportChanged = false;
bTexMtxInfoChanged = false;
bLightingConfigChanged = false;
bProjectionGraphicsModChange = false;
m_minmax_transform_matrices_changed.fill(-1);
m_minmax_normal_matrices_changed.fill(-1);
m_minmax_post_transform_matrices_changed.fill(-1);
m_minmax_lights_changed.fill(-1);
m_materials_changed = BitSet32(0);
m_tex_matrices_changed.fill(false);
m_pos_normal_matrix_changed = false;
m_projection_changed = true;
m_viewport_changed = false;
m_tex_mtx_info_changed = false;
m_lighting_config_changed = false;
m_projection_graphics_mod_change = false;
std::memset(static_cast<void*>(&xfmem), 0, sizeof(xfmem));
constants = {};
// TODO: should these go inside ResetView()?
s_viewportCorrection = Common::Matrix44::Identity();
g_fProjectionMatrix = Common::Matrix44::Identity().data;
m_viewport_correction = Common::Matrix44::Identity();
m_projection_matrix = Common::Matrix44::Identity().data;
dirty = true;
}
@ -81,7 +60,7 @@ void VertexShaderManager::Dirty()
{
// This function is called after a savestate is loaded.
// Any constants that can changed based on settings should be re-calculated
bProjectionChanged = true;
m_projection_changed = true;
dirty = true;
}
@ -102,44 +81,44 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (nTransformMatricesChanged[0] >= 0)
if (m_minmax_transform_matrices_changed[0] >= 0)
{
int startn = nTransformMatricesChanged[0] / 4;
int endn = (nTransformMatricesChanged[1] + 3) / 4;
int startn = m_minmax_transform_matrices_changed[0] / 4;
int endn = (m_minmax_transform_matrices_changed[1] + 3) / 4;
memcpy(constants.transformmatrices[startn].data(), &xfmem.posMatrices[startn * 4],
(endn - startn) * sizeof(float4));
dirty = true;
nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1;
m_minmax_transform_matrices_changed[0] = m_minmax_transform_matrices_changed[1] = -1;
}
if (nNormalMatricesChanged[0] >= 0)
if (m_minmax_normal_matrices_changed[0] >= 0)
{
int startn = nNormalMatricesChanged[0] / 3;
int endn = (nNormalMatricesChanged[1] + 2) / 3;
int startn = m_minmax_normal_matrices_changed[0] / 3;
int endn = (m_minmax_normal_matrices_changed[1] + 2) / 3;
for (int i = startn; i < endn; i++)
{
memcpy(constants.normalmatrices[i].data(), &xfmem.normalMatrices[3 * i], 12);
}
dirty = true;
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
m_minmax_normal_matrices_changed[0] = m_minmax_normal_matrices_changed[1] = -1;
}
if (nPostTransformMatricesChanged[0] >= 0)
if (m_minmax_post_transform_matrices_changed[0] >= 0)
{
int startn = nPostTransformMatricesChanged[0] / 4;
int endn = (nPostTransformMatricesChanged[1] + 3) / 4;
int startn = m_minmax_post_transform_matrices_changed[0] / 4;
int endn = (m_minmax_post_transform_matrices_changed[1] + 3) / 4;
memcpy(constants.posttransformmatrices[startn].data(), &xfmem.postMatrices[startn * 4],
(endn - startn) * sizeof(float4));
dirty = true;
nPostTransformMatricesChanged[0] = nPostTransformMatricesChanged[1] = -1;
m_minmax_post_transform_matrices_changed[0] = m_minmax_post_transform_matrices_changed[1] = -1;
}
if (nLightsChanged[0] >= 0)
if (m_minmax_lights_changed[0] >= 0)
{
// TODO: Outdated comment
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
int istart = m_minmax_lights_changed[0] / 0x10;
int iend = (m_minmax_lights_changed[1] + 15) / 0x10;
for (int i = istart; i < iend; ++i)
{
@ -192,10 +171,10 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
}
dirty = true;
nLightsChanged[0] = nLightsChanged[1] = -1;
m_minmax_lights_changed[0] = m_minmax_lights_changed[1] = -1;
}
for (int i : nMaterialsChanged)
for (int i : m_materials_changed)
{
u32 data = i >= 2 ? xfmem.matColor[i - 2] : xfmem.ambColor[i];
constants.materials[i][0] = (data >> 24) & 0xFF;
@ -204,11 +183,11 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
constants.materials[i][3] = data & 0xFF;
dirty = true;
}
nMaterialsChanged = BitSet32(0);
m_materials_changed = BitSet32(0);
if (bPosNormalMatrixChanged)
if (m_pos_normal_matrix_changed)
{
bPosNormalMatrixChanged = false;
m_pos_normal_matrix_changed = false;
const float* pos = &xfmem.posMatrices[g_main_cp_state.matrix_index_a.PosNormalMtxIdx * 4];
const float* norm =
@ -221,9 +200,9 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (bTexMatricesChanged[0])
if (m_tex_matrices_changed[0])
{
bTexMatricesChanged[0] = false;
m_tex_matrices_changed[0] = false;
const std::array<const float*, 4> pos_matrix_ptrs{
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex0MtxIdx * 4],
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex1MtxIdx * 4],
@ -238,9 +217,9 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (bTexMatricesChanged[1])
if (m_tex_matrices_changed[1])
{
bTexMatricesChanged[1] = false;
m_tex_matrices_changed[1] = false;
const std::array<const float*, 4> pos_matrix_ptrs{
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex4MtxIdx * 4],
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex5MtxIdx * 4],
@ -255,9 +234,9 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (bViewportChanged)
if (m_viewport_changed)
{
bViewportChanged = false;
m_viewport_changed = false;
// The console GPU places the pixel center at 7/12 unless antialiasing
// is enabled, while D3D and OpenGL place it at 0.5. See the comment
@ -332,11 +311,11 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
}
}
if (bProjectionChanged || g_freelook_camera.GetController()->IsDirty() ||
!projection_actions.empty() || bProjectionGraphicsModChange)
if (m_projection_changed || g_freelook_camera.GetController()->IsDirty() ||
!projection_actions.empty() || m_projection_graphics_mod_change)
{
bProjectionChanged = false;
bProjectionGraphicsModChange = !projection_actions.empty();
m_projection_changed = false;
m_projection_graphics_mod_change = !projection_actions.empty();
const auto& rawProjection = xfmem.projection.rawProjection;
@ -347,59 +326,59 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
const Common::Vec2 fov_multiplier = g_freelook_camera.IsActive() ?
g_freelook_camera.GetFieldOfViewMultiplier() :
Common::Vec2{1, 1};
g_fProjectionMatrix[0] =
m_projection_matrix[0] =
rawProjection[0] * g_ActiveConfig.fAspectRatioHackW * fov_multiplier.x;
g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] =
m_projection_matrix[1] = 0.0f;
m_projection_matrix[2] =
rawProjection[1] * g_ActiveConfig.fAspectRatioHackW * fov_multiplier.x;
g_fProjectionMatrix[3] = 0.0f;
m_projection_matrix[3] = 0.0f;
g_fProjectionMatrix[4] = 0.0f;
g_fProjectionMatrix[5] =
m_projection_matrix[4] = 0.0f;
m_projection_matrix[5] =
rawProjection[2] * g_ActiveConfig.fAspectRatioHackH * fov_multiplier.y;
g_fProjectionMatrix[6] =
m_projection_matrix[6] =
rawProjection[3] * g_ActiveConfig.fAspectRatioHackH * fov_multiplier.y;
g_fProjectionMatrix[7] = 0.0f;
m_projection_matrix[7] = 0.0f;
g_fProjectionMatrix[8] = 0.0f;
g_fProjectionMatrix[9] = 0.0f;
g_fProjectionMatrix[10] = rawProjection[4];
g_fProjectionMatrix[11] = rawProjection[5];
m_projection_matrix[8] = 0.0f;
m_projection_matrix[9] = 0.0f;
m_projection_matrix[10] = rawProjection[4];
m_projection_matrix[11] = rawProjection[5];
g_fProjectionMatrix[12] = 0.0f;
g_fProjectionMatrix[13] = 0.0f;
m_projection_matrix[12] = 0.0f;
m_projection_matrix[13] = 0.0f;
g_fProjectionMatrix[14] = -1.0f;
g_fProjectionMatrix[15] = 0.0f;
m_projection_matrix[14] = -1.0f;
m_projection_matrix[15] = 0.0f;
g_stats.gproj = g_fProjectionMatrix;
g_stats.gproj = m_projection_matrix;
}
break;
case ProjectionType::Orthographic:
{
g_fProjectionMatrix[0] = rawProjection[0];
g_fProjectionMatrix[1] = 0.0f;
g_fProjectionMatrix[2] = 0.0f;
g_fProjectionMatrix[3] = rawProjection[1];
m_projection_matrix[0] = rawProjection[0];
m_projection_matrix[1] = 0.0f;
m_projection_matrix[2] = 0.0f;
m_projection_matrix[3] = rawProjection[1];
g_fProjectionMatrix[4] = 0.0f;
g_fProjectionMatrix[5] = rawProjection[2];
g_fProjectionMatrix[6] = 0.0f;
g_fProjectionMatrix[7] = rawProjection[3];
m_projection_matrix[4] = 0.0f;
m_projection_matrix[5] = rawProjection[2];
m_projection_matrix[6] = 0.0f;
m_projection_matrix[7] = rawProjection[3];
g_fProjectionMatrix[8] = 0.0f;
g_fProjectionMatrix[9] = 0.0f;
g_fProjectionMatrix[10] = rawProjection[4];
g_fProjectionMatrix[11] = rawProjection[5];
m_projection_matrix[8] = 0.0f;
m_projection_matrix[9] = 0.0f;
m_projection_matrix[10] = rawProjection[4];
m_projection_matrix[11] = rawProjection[5];
g_fProjectionMatrix[12] = 0.0f;
g_fProjectionMatrix[13] = 0.0f;
m_projection_matrix[12] = 0.0f;
m_projection_matrix[13] = 0.0f;
g_fProjectionMatrix[14] = 0.0f;
g_fProjectionMatrix[15] = 1.0f;
m_projection_matrix[14] = 0.0f;
m_projection_matrix[15] = 1.0f;
g_stats.g2proj = g_fProjectionMatrix;
g_stats.g2proj = m_projection_matrix;
g_stats.proj = rawProjection;
}
break;
@ -411,7 +390,8 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
PRIM_LOG("Projection: {} {} {} {} {} {}", rawProjection[0], rawProjection[1], rawProjection[2],
rawProjection[3], rawProjection[4], rawProjection[5]);
auto corrected_matrix = s_viewportCorrection * Common::Matrix44::FromArray(g_fProjectionMatrix);
auto corrected_matrix =
m_viewport_correction * Common::Matrix44::FromArray(m_projection_matrix);
if (g_freelook_camera.IsActive() && xfmem.projection.type == ProjectionType::Perspective)
corrected_matrix *= g_freelook_camera.GetView();
@ -429,9 +409,9 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (bTexMtxInfoChanged)
if (m_tex_mtx_info_changed)
{
bTexMtxInfoChanged = false;
m_tex_mtx_info_changed = false;
constants.xfmem_dualTexInfo = xfmem.dualTexTrans.enabled;
for (size_t i = 0; i < std::size(xfmem.texMtxInfo); i++)
constants.xfmem_pack1[i][0] = xfmem.texMtxInfo[i].hex;
@ -441,9 +421,9 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dirty = true;
}
if (bLightingConfigChanged)
if (m_lighting_config_changed)
{
bLightingConfigChanged = false;
m_lighting_config_changed = false;
for (size_t i = 0; i < 2; i++)
{
@ -464,7 +444,7 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
(u32)start < XFMEM_NORMALMATRICES +
((u32)g_main_cp_state.matrix_index_a.PosNormalMtxIdx & 31) * 3 + 9))
{
bPosNormalMatrixChanged = true;
m_pos_normal_matrix_changed = true;
}
if (((u32)start >= (u32)g_main_cp_state.matrix_index_a.Tex0MtxIdx * 4 &&
@ -476,7 +456,7 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
((u32)start >= (u32)g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4 &&
(u32)start < (u32)g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4 + 12))
{
bTexMatricesChanged[0] = true;
m_tex_matrices_changed[0] = true;
}
if (((u32)start >= (u32)g_main_cp_state.matrix_index_b.Tex4MtxIdx * 4 &&
@ -488,23 +468,25 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
((u32)start >= (u32)g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4 &&
(u32)start < (u32)g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4 + 12))
{
bTexMatricesChanged[1] = true;
m_tex_matrices_changed[1] = true;
}
if (start < XFMEM_POSMATRICES_END)
{
if (nTransformMatricesChanged[0] == -1)
if (m_minmax_transform_matrices_changed[0] == -1)
{
nTransformMatricesChanged[0] = start;
nTransformMatricesChanged[1] = end > XFMEM_POSMATRICES_END ? XFMEM_POSMATRICES_END : end;
m_minmax_transform_matrices_changed[0] = start;
m_minmax_transform_matrices_changed[1] =
end > XFMEM_POSMATRICES_END ? XFMEM_POSMATRICES_END : end;
}
else
{
if (nTransformMatricesChanged[0] > start)
nTransformMatricesChanged[0] = start;
if (m_minmax_transform_matrices_changed[0] > start)
m_minmax_transform_matrices_changed[0] = start;
if (nTransformMatricesChanged[1] < end)
nTransformMatricesChanged[1] = end > XFMEM_POSMATRICES_END ? XFMEM_POSMATRICES_END : end;
if (m_minmax_transform_matrices_changed[1] < end)
m_minmax_transform_matrices_changed[1] =
end > XFMEM_POSMATRICES_END ? XFMEM_POSMATRICES_END : end;
}
}
@ -514,18 +496,18 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
int _end = end < XFMEM_NORMALMATRICES_END ? end - XFMEM_NORMALMATRICES :
XFMEM_NORMALMATRICES_END - XFMEM_NORMALMATRICES;
if (nNormalMatricesChanged[0] == -1)
if (m_minmax_normal_matrices_changed[0] == -1)
{
nNormalMatricesChanged[0] = _start;
nNormalMatricesChanged[1] = _end;
m_minmax_normal_matrices_changed[0] = _start;
m_minmax_normal_matrices_changed[1] = _end;
}
else
{
if (nNormalMatricesChanged[0] > _start)
nNormalMatricesChanged[0] = _start;
if (m_minmax_normal_matrices_changed[0] > _start)
m_minmax_normal_matrices_changed[0] = _start;
if (nNormalMatricesChanged[1] < _end)
nNormalMatricesChanged[1] = _end;
if (m_minmax_normal_matrices_changed[1] < _end)
m_minmax_normal_matrices_changed[1] = _end;
}
}
@ -535,18 +517,18 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
int _end = end < XFMEM_POSTMATRICES_END ? end - XFMEM_POSTMATRICES :
XFMEM_POSTMATRICES_END - XFMEM_POSTMATRICES;
if (nPostTransformMatricesChanged[0] == -1)
if (m_minmax_post_transform_matrices_changed[0] == -1)
{
nPostTransformMatricesChanged[0] = _start;
nPostTransformMatricesChanged[1] = _end;
m_minmax_post_transform_matrices_changed[0] = _start;
m_minmax_post_transform_matrices_changed[1] = _end;
}
else
{
if (nPostTransformMatricesChanged[0] > _start)
nPostTransformMatricesChanged[0] = _start;
if (m_minmax_post_transform_matrices_changed[0] > _start)
m_minmax_post_transform_matrices_changed[0] = _start;
if (nPostTransformMatricesChanged[1] < _end)
nPostTransformMatricesChanged[1] = _end;
if (m_minmax_post_transform_matrices_changed[1] < _end)
m_minmax_post_transform_matrices_changed[1] = _end;
}
}
@ -555,18 +537,18 @@ void VertexShaderManager::InvalidateXFRange(int start, int end)
int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start - XFMEM_LIGHTS;
int _end = end < XFMEM_LIGHTS_END ? end - XFMEM_LIGHTS : XFMEM_LIGHTS_END - XFMEM_LIGHTS;
if (nLightsChanged[0] == -1)
if (m_minmax_lights_changed[0] == -1)
{
nLightsChanged[0] = _start;
nLightsChanged[1] = _end;
m_minmax_lights_changed[0] = _start;
m_minmax_lights_changed[1] = _end;
}
else
{
if (nLightsChanged[0] > _start)
nLightsChanged[0] = _start;
if (m_minmax_lights_changed[0] > _start)
m_minmax_lights_changed[0] = _start;
if (nLightsChanged[1] < _end)
nLightsChanged[1] = _end;
if (m_minmax_lights_changed[1] < _end)
m_minmax_lights_changed[1] = _end;
}
}
}
@ -577,8 +559,8 @@ void VertexShaderManager::SetTexMatrixChangedA(u32 Value)
{
g_vertex_manager->Flush();
if (g_main_cp_state.matrix_index_a.PosNormalMtxIdx != (Value & 0x3f))
bPosNormalMatrixChanged = true;
bTexMatricesChanged[0] = true;
m_pos_normal_matrix_changed = true;
m_tex_matrices_changed[0] = true;
g_main_cp_state.matrix_index_a.Hex = Value;
}
}
@ -588,24 +570,24 @@ void VertexShaderManager::SetTexMatrixChangedB(u32 Value)
if (g_main_cp_state.matrix_index_b.Hex != Value)
{
g_vertex_manager->Flush();
bTexMatricesChanged[1] = true;
m_tex_matrices_changed[1] = true;
g_main_cp_state.matrix_index_b.Hex = Value;
}
}
void VertexShaderManager::SetViewportChanged()
{
bViewportChanged = true;
m_viewport_changed = true;
}
void VertexShaderManager::SetProjectionChanged()
{
bProjectionChanged = true;
m_projection_changed = true;
}
void VertexShaderManager::SetMaterialColorChanged(int index)
{
nMaterialsChanged[index] = true;
m_materials_changed[index] = true;
}
static void UpdateValue(bool* dirty, u32* old_value, u32 new_value)
@ -650,12 +632,12 @@ void VertexShaderManager::SetTexMatrixInfoChanged(int index)
{
// TODO: Should we track this with more precision, like which indices changed?
// The whole vertex constants are probably going to be uploaded regardless.
bTexMtxInfoChanged = true;
m_tex_mtx_info_changed = true;
}
void VertexShaderManager::SetLightingConfigChanged()
{
bLightingConfigChanged = true;
m_lighting_config_changed = true;
}
void VertexShaderManager::TransformToClipSpace(const float* data, float* out, u32 MtxIdx)
@ -665,7 +647,7 @@ void VertexShaderManager::TransformToClipSpace(const float* data, float* out, u3
// We use the projection matrix calculated by VertexShaderManager, because it
// includes any free look transformations.
// Make sure VertexShaderManager::SetConstants() has been called first.
const float* proj_matrix = &g_fProjectionMatrix[0];
const float* proj_matrix = &m_projection_matrix[0];
const float t[3] = {data[0] * world_matrix[0] + data[1] * world_matrix[1] +
data[2] * world_matrix[2] + world_matrix[3],
@ -683,22 +665,22 @@ void VertexShaderManager::TransformToClipSpace(const float* data, float* out, u3
void VertexShaderManager::DoState(PointerWrap& p)
{
p.DoArray(g_fProjectionMatrix);
p.Do(s_viewportCorrection);
p.DoArray(m_projection_matrix);
p.Do(m_viewport_correction);
g_freelook_camera.DoState(p);
p.DoArray(nTransformMatricesChanged);
p.DoArray(nNormalMatricesChanged);
p.DoArray(nPostTransformMatricesChanged);
p.DoArray(nLightsChanged);
p.DoArray(m_minmax_transform_matrices_changed);
p.DoArray(m_minmax_normal_matrices_changed);
p.DoArray(m_minmax_post_transform_matrices_changed);
p.DoArray(m_minmax_lights_changed);
p.Do(nMaterialsChanged);
p.DoArray(bTexMatricesChanged);
p.Do(bPosNormalMatrixChanged);
p.Do(bProjectionChanged);
p.Do(bViewportChanged);
p.Do(bTexMtxInfoChanged);
p.Do(bLightingConfigChanged);
p.Do(m_materials_changed);
p.DoArray(m_tex_matrices_changed);
p.Do(m_pos_normal_matrix_changed);
p.Do(m_projection_changed);
p.Do(m_viewport_changed);
p.Do(m_tex_mtx_info_changed);
p.Do(m_lighting_config_changed);
p.Do(constants);

View File

@ -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
// NOTE: m_projection_matrix 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> m_projection_matrix;
// track changes
std::array<bool, 2> m_tex_matrices_changed{};
bool m_pos_normal_matrix_changed = false;
bool m_projection_changed = false;
bool m_viewport_changed = false;
bool m_tex_mtx_info_changed = false;
bool m_lighting_config_changed = false;
bool m_projection_graphics_mod_change = false;
BitSet32 m_materials_changed;
std::array<int, 2> m_minmax_transform_matrices_changed{};
std::array<int, 2> m_minmax_normal_matrices_changed{};
std::array<int, 2> m_minmax_post_transform_matrices_changed{};
std::array<int, 2> m_minmax_lights_changed{};
Common::Matrix44 m_viewport_correction{};
};

View File

@ -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();

View File

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

View File

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