77 changes: 40 additions & 37 deletions Source/Core/VideoCommon/BPStructs.cpp
Expand Up @@ -54,7 +54,8 @@ void BPInit()
bpmem.bpMask = 0xFFFFFF;
}

static void BPWritten(const BPCmd& bp, int cycles_into_future)
static void BPWritten(PixelShaderManager& pixel_shader_manager, const BPCmd& bp,
int cycles_into_future)
{
/*
----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -103,7 +104,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
bpmem.genMode.zfreeze);

if (bp.changes)
PixelShaderManager::SetGenModeChanged();
pixel_shader_manager.SetGenModeChanged();

// Only call SetGenerationMode when cull mode changes.
if (bp.changes & 0xC000)
Expand All @@ -119,15 +120,15 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_IND_MTXB + 6:
case BPMEM_IND_MTXC + 6:
if (bp.changes)
PixelShaderManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
pixel_shader_manager.SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
return;
case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0
if (bp.changes)
PixelShaderManager::SetIndTexScaleChanged(false);
pixel_shader_manager.SetIndTexScaleChanged(false);
return;
case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1
if (bp.changes)
PixelShaderManager::SetIndTexScaleChanged(true);
pixel_shader_manager.SetIndTexScaleChanged(true);
return;
// ----------------
// Scissor Control
Expand All @@ -145,7 +146,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
PRIM_LOG("zmode: test={}, func={}, upd={}", bpmem.zmode.testenable, bpmem.zmode.func,
bpmem.zmode.updateenable);
SetDepthMode();
PixelShaderManager::SetZModeControl();
pixel_shader_manager.SetZModeControl();
return;
case BPMEM_BLENDMODE: // Blending Control
if (bp.changes & 0xFFFF)
Expand All @@ -157,15 +158,15 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)

SetBlendMode();

PixelShaderManager::SetBlendModeChanged();
pixel_shader_manager.SetBlendModeChanged();
}
return;
case BPMEM_CONSTANTALPHA: // Set Destination Alpha
PRIM_LOG("constalpha: alp={}, en={}", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
if (bp.changes)
{
PixelShaderManager::SetAlpha();
PixelShaderManager::SetDestAlphaChanged();
pixel_shader_manager.SetAlpha();
pixel_shader_manager.SetDestAlphaChanged();
}
if (bp.changes & 0x100)
SetBlendMode();
Expand Down Expand Up @@ -279,7 +280,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
if (PE_copy.copy_to_xfb == 1)
{
// Make sure we disable Bounding box to match the side effects of the non-failure path
g_renderer->BBoxDisable();
g_renderer->BBoxDisable(pixel_shader_manager);
}

return;
Expand Down Expand Up @@ -310,7 +311,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
// We should be able to get away with deactivating the current bbox tracking
// here. Not sure if there's a better spot to put this.
// the number of lines copied is determined by the y scale * source efb height
g_renderer->BBoxDisable();
g_renderer->BBoxDisable(pixel_shader_manager);

float yScale;
if (PE_copy.scale_invert)
Expand Down Expand Up @@ -390,42 +391,42 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_FOGRANGE + 4:
case BPMEM_FOGRANGE + 5:
if (bp.changes)
PixelShaderManager::SetFogRangeAdjustChanged();
pixel_shader_manager.SetFogRangeAdjustChanged();
return;
case BPMEM_FOGPARAM0:
case BPMEM_FOGBMAGNITUDE:
case BPMEM_FOGBEXPONENT:
case BPMEM_FOGPARAM3:
if (bp.changes)
PixelShaderManager::SetFogParamChanged();
pixel_shader_manager.SetFogParamChanged();
return;
case BPMEM_FOGCOLOR: // Fog Color
if (bp.changes)
PixelShaderManager::SetFogColorChanged();
pixel_shader_manager.SetFogColorChanged();
return;
case BPMEM_ALPHACOMPARE: // Compare Alpha Values
PRIM_LOG("alphacmp: ref0={}, ref1={}, comp0={}, comp1={}, logic={}", bpmem.alpha_test.ref0,
bpmem.alpha_test.ref1, bpmem.alpha_test.comp0, bpmem.alpha_test.comp1,
bpmem.alpha_test.logic);
if (bp.changes & 0xFFFF)
PixelShaderManager::SetAlpha();
pixel_shader_manager.SetAlpha();
if (bp.changes)
{
PixelShaderManager::SetAlphaTestChanged();
pixel_shader_manager.SetAlphaTestChanged();
SetBlendMode();
}
return;
case BPMEM_BIAS: // BIAS
PRIM_LOG("ztex bias={:#x}", bpmem.ztex1.bias);
if (bp.changes)
PixelShaderManager::SetZTextureBias();
pixel_shader_manager.SetZTextureBias();
return;
case BPMEM_ZTEX2: // Z Texture type
{
if (bp.changes & 3)
PixelShaderManager::SetZTextureTypeChanged();
pixel_shader_manager.SetZTextureTypeChanged();
if (bp.changes & 12)
PixelShaderManager::SetZTextureOpChanged();
pixel_shader_manager.SetZTextureOpChanged();
PRIM_LOG("ztex op={}, type={}", bpmem.ztex2.op, bpmem.ztex2.type);
}
return;
Expand Down Expand Up @@ -478,7 +479,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_CLEARBBOX2:
{
const u8 offset = bp.address & 2;
g_renderer->BBoxEnable();
g_renderer->BBoxEnable(pixel_shader_manager);

g_renderer->BBoxWrite(offset, bp.newvalue & 0x3ff);
g_renderer->BBoxWrite(offset + 1, bp.newvalue >> 10);
Expand All @@ -492,7 +493,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
OnPixelFormatChange();
if (bp.changes & 7)
SetBlendMode(); // dual source could be activated by changing to PIXELFMT_RGBA6_Z24
PixelShaderManager::SetZModeControl();
pixel_shader_manager.SetZModeControl();
return;

case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel
Expand All @@ -510,7 +511,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_IREF:
{
if (bp.changes)
PixelShaderManager::SetTevIndirectChanged();
pixel_shader_manager.SetTevIndirectChanged();
return;
}

Expand All @@ -522,7 +523,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_TEV_KSEL + 5: // Texture Environment Swap Mode Table 5
case BPMEM_TEV_KSEL + 6: // Texture Environment Swap Mode Table 6
case BPMEM_TEV_KSEL + 7: // Texture Environment Swap Mode Table 7
PixelShaderManager::SetTevKSel(bp.address - BPMEM_TEV_KSEL, bp.newvalue);
pixel_shader_manager.SetTevKSel(bp.address - BPMEM_TEV_KSEL, bp.newvalue);
return;

/* This Register can be used to limit to which bits of BP registers is
Expand Down Expand Up @@ -619,13 +620,13 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
int num = (bp.address >> 1) & 0x3;
if (bpmem.tevregs[num].ra.type == TevRegType::Constant)
{
PixelShaderManager::SetTevKonstColor(num, 0, bpmem.tevregs[num].ra.red);
PixelShaderManager::SetTevKonstColor(num, 3, bpmem.tevregs[num].ra.alpha);
pixel_shader_manager.SetTevKonstColor(num, 0, bpmem.tevregs[num].ra.red);
pixel_shader_manager.SetTevKonstColor(num, 3, bpmem.tevregs[num].ra.alpha);
}
else
{
PixelShaderManager::SetTevColor(num, 0, bpmem.tevregs[num].ra.red);
PixelShaderManager::SetTevColor(num, 3, bpmem.tevregs[num].ra.alpha);
pixel_shader_manager.SetTevColor(num, 0, bpmem.tevregs[num].ra.red);
pixel_shader_manager.SetTevColor(num, 3, bpmem.tevregs[num].ra.alpha);
}
return;
}
Expand All @@ -638,13 +639,13 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
int num = (bp.address >> 1) & 0x3;
if (bpmem.tevregs[num].bg.type == TevRegType::Constant)
{
PixelShaderManager::SetTevKonstColor(num, 1, bpmem.tevregs[num].bg.green);
PixelShaderManager::SetTevKonstColor(num, 2, bpmem.tevregs[num].bg.blue);
pixel_shader_manager.SetTevKonstColor(num, 1, bpmem.tevregs[num].bg.green);
pixel_shader_manager.SetTevKonstColor(num, 2, bpmem.tevregs[num].bg.blue);
}
else
{
PixelShaderManager::SetTevColor(num, 1, bpmem.tevregs[num].bg.green);
PixelShaderManager::SetTevColor(num, 2, bpmem.tevregs[num].bg.blue);
pixel_shader_manager.SetTevColor(num, 1, bpmem.tevregs[num].bg.green);
pixel_shader_manager.SetTevColor(num, 2, bpmem.tevregs[num].bg.blue);
}
return;
}
Expand All @@ -660,7 +661,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
// -------------------------
case BPMEM_TREF:
case BPMEM_TREF + 4:
PixelShaderManager::SetTevOrder(bp.address - BPMEM_TREF, bp.newvalue);
pixel_shader_manager.SetTevOrder(bp.address - BPMEM_TREF, bp.newvalue);
return;
// ----------------------
// Set wrap size
Expand All @@ -671,7 +672,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
case BPMEM_SU_SSIZE + 12:
if (bp.changes)
{
PixelShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
pixel_shader_manager.SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
GeometryShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
}
return;
Expand Down Expand Up @@ -725,7 +726,7 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
// Indirect Tev
// --------------
case BPMEM_IND_CMD:
PixelShaderManager::SetTevIndirectChanged();
pixel_shader_manager.SetTevIndirectChanged();
return;
// --------------------------------------------------
// Set Color/Alpha of a Tev
Expand All @@ -734,8 +735,8 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
// --------------------------------------------------
case BPMEM_TEV_COLOR_ENV: // Texture Environment 1
case BPMEM_TEV_COLOR_ENV + 16:
PixelShaderManager::SetTevCombiner((bp.address - BPMEM_TEV_COLOR_ENV) >> 1,
(bp.address - BPMEM_TEV_COLOR_ENV) & 1, bp.newvalue);
pixel_shader_manager.SetTevCombiner((bp.address - BPMEM_TEV_COLOR_ENV) >> 1,
(bp.address - BPMEM_TEV_COLOR_ENV) & 1, bp.newvalue);
return;
default:
break;
Expand All @@ -749,6 +750,8 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
// Call browser: OpcodeDecoding.cpp RunCallback::OnBP()
void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
{
auto& system = Core::System::GetInstance();

int oldval = ((u32*)&bpmem)[reg];
int newval = (oldval & ~bpmem.bpMask) | (value & bpmem.bpMask);
int changes = (oldval ^ newval) & 0xFFFFFF;
Expand All @@ -759,7 +762,7 @@ void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
if (reg != BPMEM_BP_MASK)
bpmem.bpMask = 0xFFFFFF;

BPWritten(bp, cycles_into_future);
BPWritten(system.GetPixelShaderManager(), bp, cycles_into_future);
}

void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future)
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoCommon/BoundingBox.cpp
Expand Up @@ -13,16 +13,16 @@

#include <algorithm>

void BoundingBox::Enable()
void BoundingBox::Enable(PixelShaderManager& pixel_shader_manager)
{
m_is_active = true;
PixelShaderManager::SetBoundingBoxActive(m_is_active);
pixel_shader_manager.SetBoundingBoxActive(m_is_active);
}

void BoundingBox::Disable()
void BoundingBox::Disable(PixelShaderManager& pixel_shader_manager)
{
m_is_active = false;
PixelShaderManager::SetBoundingBoxActive(m_is_active);
pixel_shader_manager.SetBoundingBoxActive(m_is_active);
}

void BoundingBox::Flush()
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/VideoCommon/BoundingBox.h
Expand Up @@ -8,6 +8,7 @@

#include "Common/CommonTypes.h"

class PixelShaderManager;
class PointerWrap;

using BBoxType = s32;
Expand All @@ -20,8 +21,8 @@ class BoundingBox
virtual ~BoundingBox() = default;

bool IsEnabled() const { return m_is_active; }
void Enable();
void Disable();
void Enable(PixelShaderManager& pixel_shader_manager);
void Disable(PixelShaderManager& pixel_shader_manager);

void Flush();

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/VideoCommon/PixelEngine.cpp
Expand Up @@ -146,8 +146,9 @@ void PixelEngineManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base)
// BBOX registers, readonly and need to update a flag.
for (int i = 0; i < 4; ++i)
{
mmio->Register(base | (PE_BBOX_LEFT + 2 * i), MMIO::ComplexRead<u16>([i](Core::System&, u32) {
g_renderer->BBoxDisable();
mmio->Register(base | (PE_BBOX_LEFT + 2 * i),
MMIO::ComplexRead<u16>([i](Core::System& system, u32) {
g_renderer->BBoxDisable(system.GetPixelShaderManager());
return g_video_backend->Video_GetBoundingBox(i);
}),
MMIO::InvalidWrite<u16>());
Expand Down
52 changes: 22 additions & 30 deletions Source/Core/VideoCommon/PixelShaderManager.cpp
Expand Up @@ -12,21 +12,13 @@
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"

bool PixelShaderManager::s_bFogRangeAdjustChanged;
bool PixelShaderManager::s_bViewPortChanged;
bool PixelShaderManager::s_bIndirectDirty;
bool PixelShaderManager::s_bDestAlphaDirty;

PixelShaderConstants PixelShaderManager::constants;
bool PixelShaderManager::dirty;

void PixelShaderManager::Init()
{
constants = {};

// Init any intial constants which aren't zero when bpmem is zero.
s_bFogRangeAdjustChanged = true;
s_bViewPortChanged = false;
m_fog_range_adjusted_changed = true;
m_viewport_changed = false;

SetIndMatrixChanged(0);
SetIndMatrixChanged(1);
Expand Down Expand Up @@ -80,7 +72,7 @@ void PixelShaderManager::Dirty()
{
// This function is called after a savestate is loaded.
// Any constants that can changed based on settings should be re-calculated
s_bFogRangeAdjustChanged = true;
m_fog_range_adjusted_changed = true;

SetEfbScaleChanged(g_renderer->EFBToScaledXf(1), g_renderer->EFBToScaledYf(1));
SetFogParamChanged();
Expand All @@ -90,7 +82,7 @@ void PixelShaderManager::Dirty()

void PixelShaderManager::SetConstants()
{
if (s_bFogRangeAdjustChanged)
if (m_fog_range_adjusted_changed)
{
// set by two components, so keep changed flag here
// TODO: try to split both registers and move this logic to the shader
Expand Down Expand Up @@ -129,18 +121,18 @@ void PixelShaderManager::SetConstants()
}
dirty = true;

s_bFogRangeAdjustChanged = false;
m_fog_range_adjusted_changed = false;
}

if (s_bViewPortChanged)
if (m_viewport_changed)
{
constants.zbias[1][0] = (s32)xfmem.viewport.farZ;
constants.zbias[1][1] = (s32)xfmem.viewport.zRange;
dirty = true;
s_bViewPortChanged = false;
m_viewport_changed = false;
}

if (s_bIndirectDirty)
if (m_indirect_dirty)
{
for (int i = 0; i < 4; i++)
constants.pack1[i][3] = 0;
Expand All @@ -162,10 +154,10 @@ void PixelShaderManager::SetConstants()
}

dirty = true;
s_bIndirectDirty = false;
m_indirect_dirty = false;
}

if (s_bDestAlphaDirty)
if (m_dest_alpha_dirty)
{
// Destination alpha is only enabled if alpha writes are enabled. Force entire uniform to zero
// when disabled.
Expand Down Expand Up @@ -240,7 +232,7 @@ void PixelShaderManager::SetTevCombiner(int index, int alpha, u32 combiner)

void PixelShaderManager::SetTevIndirectChanged()
{
s_bIndirectDirty = true;
m_indirect_dirty = true;
}

void PixelShaderManager::SetAlpha()
Expand Down Expand Up @@ -268,7 +260,7 @@ void PixelShaderManager::SetAlphaTestChanged()

void PixelShaderManager::SetDestAlphaChanged()
{
s_bDestAlphaDirty = true;
m_dest_alpha_dirty = true;
}

void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height)
Expand Down Expand Up @@ -299,8 +291,8 @@ void PixelShaderManager::SetZTextureBias()

void PixelShaderManager::SetViewportChanged()
{
s_bViewPortChanged = true;
s_bFogRangeAdjustChanged =
m_viewport_changed = true;
m_fog_range_adjusted_changed =
true; // TODO: Shouldn't be necessary with an accurate fog range adjust implementation
}

Expand Down Expand Up @@ -430,7 +422,7 @@ void PixelShaderManager::SetFogRangeAdjustChanged()
if (g_ActiveConfig.bDisableFog)
return;

s_bFogRangeAdjustChanged = true;
m_fog_range_adjusted_changed = true;

if (constants.fogRangeBase != bpmem.fogRange.Base.hex)
{
Expand All @@ -442,7 +434,7 @@ void PixelShaderManager::SetFogRangeAdjustChanged()
void PixelShaderManager::SetGenModeChanged()
{
constants.genmode = bpmem.genMode.hex;
s_bIndirectDirty = true;
m_indirect_dirty = true;
dirty = true;
}

Expand All @@ -462,7 +454,7 @@ void PixelShaderManager::SetZModeControl()
constants.dither = dither;
dirty = true;
}
s_bDestAlphaDirty = true;
m_dest_alpha_dirty = true;
}

void PixelShaderManager::SetBlendModeChanged()
Expand Down Expand Up @@ -520,7 +512,7 @@ void PixelShaderManager::SetBlendModeChanged()
constants.logic_op_mode = state.logicmode;
dirty = true;
}
s_bDestAlphaDirty = true;
m_dest_alpha_dirty = true;
}

void PixelShaderManager::SetBoundingBoxActive(bool active)
Expand All @@ -535,10 +527,10 @@ void PixelShaderManager::SetBoundingBoxActive(bool active)

void PixelShaderManager::DoState(PointerWrap& p)
{
p.Do(s_bFogRangeAdjustChanged);
p.Do(s_bViewPortChanged);
p.Do(s_bIndirectDirty);
p.Do(s_bDestAlphaDirty);
p.Do(m_fog_range_adjusted_changed);
p.Do(m_viewport_changed);
p.Do(m_indirect_dirty);
p.Do(m_dest_alpha_dirty);

p.Do(constants);

Expand Down
81 changes: 41 additions & 40 deletions Source/Core/VideoCommon/PixelShaderManager.h
Expand Up @@ -9,51 +9,52 @@
class PointerWrap;

// The non-API dependent parts.
class PixelShaderManager
class PixelShaderManager final
{
public:
static void Init();
static void Dirty();
static void DoState(PointerWrap& p);
void Init();
void Dirty();
void DoState(PointerWrap& p);

static void SetConstants(); // sets pixel shader constants
void SetConstants(); // sets pixel shader constants

// constant management
// Some of these functions grab the constant values from global state,
// so make sure to call them after memory is committed
static void SetTevColor(int index, int component, s32 value);
static void SetTevKonstColor(int index, int component, s32 value);
static void SetTevOrder(int index, u32 order);
static void SetTevKSel(int index, u32 ksel);
static void SetTevCombiner(int index, int alpha, u32 combiner);
static void SetAlpha();
static void SetAlphaTestChanged();
static void SetDestAlphaChanged();
static void SetTexDims(int texmapid, u32 width, u32 height);
static void SetSamplerState(int texmapid, u32 tm0, u32 tm1);
static void SetZTextureBias();
static void SetViewportChanged();
static void SetEfbScaleChanged(float scalex, float scaley);
static void SetZSlope(float dfdx, float dfdy, float f0);
static void SetIndMatrixChanged(int matrixidx);
static void SetTevIndirectChanged();
static void SetZTextureTypeChanged();
static void SetZTextureOpChanged();
static void SetIndTexScaleChanged(bool high);
static void SetTexCoordChanged(u8 texmapid);
static void SetFogColorChanged();
static void SetFogParamChanged();
static void SetFogRangeAdjustChanged();
static void SetGenModeChanged();
static void SetZModeControl();
static void SetBlendModeChanged();
static void SetBoundingBoxActive(bool active);

static PixelShaderConstants constants;
static bool dirty;

static bool s_bFogRangeAdjustChanged;
static bool s_bViewPortChanged;
static bool s_bIndirectDirty;
static bool s_bDestAlphaDirty;
void SetTevColor(int index, int component, s32 value);
void SetTevKonstColor(int index, int component, s32 value);
void SetTevOrder(int index, u32 order);
void SetTevKSel(int index, u32 ksel);
void SetTevCombiner(int index, int alpha, u32 combiner);
void SetAlpha();
void SetAlphaTestChanged();
void SetDestAlphaChanged();
void SetTexDims(int texmapid, u32 width, u32 height);
void SetSamplerState(int texmapid, u32 tm0, u32 tm1);
void SetZTextureBias();
void SetViewportChanged();
void SetEfbScaleChanged(float scalex, float scaley);
void SetZSlope(float dfdx, float dfdy, float f0);
void SetIndMatrixChanged(int matrixidx);
void SetTevIndirectChanged();
void SetZTextureTypeChanged();
void SetZTextureOpChanged();
void SetIndTexScaleChanged(bool high);
void SetTexCoordChanged(u8 texmapid);
void SetFogColorChanged();
void SetFogParamChanged();
void SetFogRangeAdjustChanged();
void SetGenModeChanged();
void SetZModeControl();
void SetBlendModeChanged();
void SetBoundingBoxActive(bool active);

PixelShaderConstants constants{};
bool dirty = false;

private:
bool m_fog_range_adjusted_changed = false;
bool m_viewport_changed = false;
bool m_indirect_dirty = false;
bool m_dest_alpha_dirty = false;
};
12 changes: 7 additions & 5 deletions Source/Core/VideoCommon/RenderBase.cpp
Expand Up @@ -218,14 +218,14 @@ bool Renderer::IsBBoxEnabled() const
return m_bounding_box->IsEnabled();
}

void Renderer::BBoxEnable()
void Renderer::BBoxEnable(PixelShaderManager& pixel_shader_manager)
{
m_bounding_box->Enable();
m_bounding_box->Enable(pixel_shader_manager);
}

void Renderer::BBoxDisable()
void Renderer::BBoxDisable(PixelShaderManager& pixel_shader_manager)
{
m_bounding_box->Disable();
m_bounding_box->Disable(pixel_shader_manager);
}

u16 Renderer::BBoxRead(u32 index)
Expand Down Expand Up @@ -421,7 +421,9 @@ bool Renderer::CalculateTargetSize()
{
m_target_width = new_efb_width;
m_target_height = new_efb_height;
PixelShaderManager::SetEfbScaleChanged(EFBToScaledXf(1), EFBToScaledYf(1));
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
pixel_shader_manager.SetEfbScaleChanged(EFBToScaledXf(1), EFBToScaledYf(1));
return true;
}
return false;
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/VideoCommon/RenderBase.h
Expand Up @@ -42,6 +42,7 @@ class AbstractStagingTexture;
class BoundingBox;
class NativeVertexFormat;
class NetPlayChatUI;
class PixelShaderManager;
class PointerWrap;
struct TextureConfig;
struct ComputePipelineConfig;
Expand Down Expand Up @@ -216,8 +217,8 @@ class Renderer
virtual void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points);

bool IsBBoxEnabled() const;
void BBoxEnable();
void BBoxDisable();
void BBoxEnable(PixelShaderManager& pixel_shader_manager);
void BBoxDisable(PixelShaderManager& pixel_shader_manager);
u16 BBoxRead(u32 index);
void BBoxWrite(u32 index, u16 value);
void BBoxFlush();
Expand Down
8 changes: 6 additions & 2 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Expand Up @@ -1054,18 +1054,22 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
}

g_renderer->SetSamplerState(index, state);
PixelShaderManager::SetSamplerState(index, state.tm0.hex, state.tm1.hex);
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
pixel_shader_manager.SetSamplerState(index, state.tm0.hex, state.tm1.hex);
}

void TextureCacheBase::BindTextures(BitSet32 used_textures)
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
for (u32 i = 0; i < bound_textures.size(); i++)
{
const TCacheEntry* tentry = bound_textures[i];
if (used_textures[i] && tentry)
{
g_renderer->SetTexture(i, tentry->texture.get());
PixelShaderManager::SetTexDims(i, tentry->native_width, tentry->native_height);
pixel_shader_manager.SetTexDims(i, tentry->native_width, tentry->native_height);

const float custom_tex_scale = tentry->GetWidth() / float(tentry->native_width);
SetSamplerState(i, custom_tex_scale, tentry->is_custom_tex, tentry->has_arbitrary_mips);
Expand Down
12 changes: 9 additions & 3 deletions Source/Core/VideoCommon/VertexManagerBase.cpp
Expand Up @@ -15,6 +15,7 @@

#include "Core/ConfigManager.h"
#include "Core/DolphinAnalytics.h"
#include "Core/System.h"

#include "VideoCommon/BPMemory.h"
#include "VideoCommon/BoundingBox.h"
Expand Down Expand Up @@ -317,9 +318,11 @@ void VertexManagerBase::UploadUniforms()

void VertexManagerBase::InvalidateConstants()
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
VertexShaderManager::dirty = true;
GeometryShaderManager::dirty = true;
PixelShaderManager::dirty = true;
pixel_shader_manager.dirty = true;
}

void VertexManagerBase::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size)
Expand Down Expand Up @@ -481,6 +484,9 @@ void VertexManagerBase::Flush()
}
}

auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();

CalculateBinormals(VertexLoaderManager::GetCurrentVertexFormat());
// Calculate ZSlope for zfreeze
const auto used_textures = UsedTextures();
Expand Down Expand Up @@ -514,7 +520,7 @@ void VertexManagerBase::Flush()
}
else if (m_zslope.dirty && !m_cull_all) // or apply any dirty ZSlopes
{
PixelShaderManager::SetZSlope(m_zslope.dfdx, m_zslope.dfdy, m_zslope.f0);
pixel_shader_manager.SetZSlope(m_zslope.dfdx, m_zslope.dfdy, m_zslope.f0);
m_zslope.dirty = false;
}

Expand Down Expand Up @@ -559,7 +565,7 @@ void VertexManagerBase::Flush()

// Now we can upload uniforms, as nothing else will override them.
GeometryShaderManager::SetConstants(m_current_primitive_type);
PixelShaderManager::SetConstants();
pixel_shader_manager.SetConstants();
UploadUniforms();

// Update the pipeline, or compile one if needed.
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/VideoBackendBase.cpp
Expand Up @@ -330,7 +330,7 @@ void VideoBackendBase::InitializeShared()
VertexLoaderManager::Init();
VertexShaderManager::Init();
GeometryShaderManager::Init();
PixelShaderManager::Init();
system.GetPixelShaderManager().Init();
TMEM::Init();

g_Config.VerifyValidity();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/VideoState.cpp
Expand Up @@ -73,7 +73,7 @@ void VideoCommon_DoState(PointerWrap& p)

// the old way of replaying current bpmem as writes to push side effects to pixel shader manager
// doesn't really work.
PixelShaderManager::DoState(p);
system.GetPixelShaderManager().DoState(p);
p.DoMarker("PixelShaderManager");

VertexShaderManager::DoState(p);
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/VideoCommon/XFStructs.cpp
Expand Up @@ -118,11 +118,14 @@ static void XFRegWritten(u32 address, u32 value)
case XFMEM_SETVIEWPORT + 3:
case XFMEM_SETVIEWPORT + 4:
case XFMEM_SETVIEWPORT + 5:
{
auto& system = Core::System::GetInstance();
g_vertex_manager->Flush();
VertexShaderManager::SetViewportChanged();
PixelShaderManager::SetViewportChanged();
system.GetPixelShaderManager().SetViewportChanged();
GeometryShaderManager::SetViewportChanged();
break;
}

case XFMEM_SETPROJECTION:
case XFMEM_SETPROJECTION + 1:
Expand Down