mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 06:39:46 -06:00
VideoCommon: De-globalize VertexShaderManager class.
This commit is contained in:
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,27 +30,6 @@
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
#include "VideoCommon/XFMemory.h"
|
||||
|
||||
alignas(16) static std::array<float, 16> g_fProjectionMatrix;
|
||||
|
||||
// track changes
|
||||
static std::array<bool, 2> bTexMatricesChanged;
|
||||
static bool bPosNormalMatrixChanged;
|
||||
static bool bProjectionChanged;
|
||||
static bool bViewportChanged;
|
||||
static bool bTexMtxInfoChanged;
|
||||
static bool bLightingConfigChanged;
|
||||
static bool bProjectionGraphicsModChange;
|
||||
static BitSet32 nMaterialsChanged;
|
||||
static std::array<int, 2> nTransformMatricesChanged; // min,max
|
||||
static std::array<int, 2> nNormalMatricesChanged; // min,max
|
||||
static std::array<int, 2> nPostTransformMatricesChanged; // min,max
|
||||
static std::array<int, 2> nLightsChanged; // min,max
|
||||
|
||||
static Common::Matrix44 s_viewportCorrection;
|
||||
|
||||
VertexShaderConstants VertexShaderManager::constants;
|
||||
bool VertexShaderManager::dirty;
|
||||
|
||||
void VertexShaderManager::Init()
|
||||
{
|
||||
// Initialize state tracking variables
|
||||
|
@ -3,43 +3,65 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Matrix.h"
|
||||
#include "VideoCommon/ConstantManager.h"
|
||||
|
||||
class PointerWrap;
|
||||
struct PortableVertexDeclaration;
|
||||
|
||||
// The non-API dependent parts.
|
||||
class VertexShaderManager
|
||||
class alignas(16) VertexShaderManager
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Dirty();
|
||||
static void DoState(PointerWrap& p);
|
||||
void Init();
|
||||
void Dirty();
|
||||
void DoState(PointerWrap& p);
|
||||
|
||||
// constant management
|
||||
static void SetConstants(const std::vector<std::string>& textures);
|
||||
void SetConstants(const std::vector<std::string>& textures);
|
||||
|
||||
static void InvalidateXFRange(int start, int end);
|
||||
static void SetTexMatrixChangedA(u32 value);
|
||||
static void SetTexMatrixChangedB(u32 value);
|
||||
static void SetViewportChanged();
|
||||
static void SetProjectionChanged();
|
||||
static void SetMaterialColorChanged(int index);
|
||||
void InvalidateXFRange(int start, int end);
|
||||
void SetTexMatrixChangedA(u32 value);
|
||||
void SetTexMatrixChangedB(u32 value);
|
||||
void SetViewportChanged();
|
||||
void SetProjectionChanged();
|
||||
void SetMaterialColorChanged(int index);
|
||||
|
||||
static void SetVertexFormat(u32 components, const PortableVertexDeclaration& format);
|
||||
static void SetTexMatrixInfoChanged(int index);
|
||||
static void SetLightingConfigChanged();
|
||||
void SetVertexFormat(u32 components, const PortableVertexDeclaration& format);
|
||||
void SetTexMatrixInfoChanged(int index);
|
||||
void SetLightingConfigChanged();
|
||||
|
||||
// data: 3 floats representing the X, Y and Z vertex model coordinates and the posmatrix index.
|
||||
// out: 4 floats which will be initialized with the corresponding clip space coordinates
|
||||
// NOTE: g_fProjectionMatrix must be up to date when this is called
|
||||
// (i.e. VertexShaderManager::SetConstants needs to be called before using this!)
|
||||
static void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
|
||||
void TransformToClipSpace(const float* data, float* out, u32 mtxIdx);
|
||||
|
||||
static VertexShaderConstants constants;
|
||||
static bool dirty;
|
||||
VertexShaderConstants constants{};
|
||||
bool dirty = false;
|
||||
|
||||
private:
|
||||
alignas(16) std::array<float, 16> g_fProjectionMatrix;
|
||||
|
||||
// track changes
|
||||
std::array<bool, 2> bTexMatricesChanged{};
|
||||
bool bPosNormalMatrixChanged = false;
|
||||
bool bProjectionChanged = false;
|
||||
bool bViewportChanged = false;
|
||||
bool bTexMtxInfoChanged = false;
|
||||
bool bLightingConfigChanged = false;
|
||||
bool bProjectionGraphicsModChange = false;
|
||||
BitSet32 nMaterialsChanged;
|
||||
std::array<int, 2> nTransformMatricesChanged{}; // min,max
|
||||
std::array<int, 2> nNormalMatricesChanged{}; // min,max
|
||||
std::array<int, 2> nPostTransformMatricesChanged{}; // min,max
|
||||
std::array<int, 2> nLightsChanged{}; // min,max
|
||||
|
||||
Common::Matrix44 s_viewportCorrection{};
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user