Skip to content

Commit d943d72

Browse files
committed
GS/HW: Make static variables members where possible.
Fixes a bug with batch runner mode with split channel shuffle. Make variables constexpr where possible.
1 parent 35c3b3c commit d943d72

File tree

10 files changed

+46
-42
lines changed

10 files changed

+46
-42
lines changed

pcsx2/GS/Renderers/Common/GSDevice.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ void GSDevice::ResetRenderState()
339339
{
340340
ClearCurrent();
341341
PurgePool();
342+
343+
#ifdef PCSX2_DEVBUILD
344+
s_texture_counts.fill(0);
345+
#endif
342346
}
343347

344348
bool GSDevice::AcquireWindow(bool recreate_window)
@@ -790,7 +794,6 @@ void GSDevice::Merge(GSTexture* sTex[3], GSVector4* sRect, GSVector4* dRect, con
790794

791795
void GSDevice::Interlace(const GSVector2i& ds, int field, int mode, float yoffset)
792796
{
793-
static int bufIdx = 0;
794797
float offset = yoffset * static_cast<float>(field);
795798
offset = GSConfig.DisableInterlaceOffset ? 0.0f : offset;
796799

@@ -840,14 +843,14 @@ void GSDevice::Interlace(const GSVector2i& ds, int field, int mode, float yoffse
840843
m_current = m_blend;
841844
break;
842845
case 3: // FastMAD Motion Adaptive Deinterlacing
843-
bufIdx++;
844-
bufIdx &= ~1;
845-
bufIdx |= field;
846-
bufIdx &= 3;
846+
m_interlace_bufIdx++;
847+
m_interlace_bufIdx &= ~1;
848+
m_interlace_bufIdx |= field;
849+
m_interlace_bufIdx &= 3;
847850
ResizeRenderTarget(&m_mad, ds.x, ds.y * 2.0f, true, false);
848-
do_interlace(m_merge, m_mad, ShaderInterlace::MAD_BUFFER, false, offset, bufIdx);
851+
do_interlace(m_merge, m_mad, ShaderInterlace::MAD_BUFFER, false, offset, m_interlace_bufIdx);
849852
ResizeRenderTarget(&m_weavebob, ds.x, ds.y, true, false);
850-
do_interlace(m_mad, m_weavebob, ShaderInterlace::MAD_RECONSTRUCT, false, 0, bufIdx);
853+
do_interlace(m_mad, m_weavebob, ShaderInterlace::MAD_RECONSTRUCT, false, 0, m_interlace_bufIdx);
851854
m_current = m_weavebob;
852855
break;
853856
default:

pcsx2/GS/Renderers/Common/GSDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ class GSDevice : public GSAlignedClass<32>
903903
GSTexture* m_cas = nullptr;
904904
GSTexture* m_colclip_rt = nullptr; ///< Temp hw colclip texture
905905

906+
int m_interlace_bufIdx = 0;
907+
906908
bool AcquireWindow(bool recreate_window);
907909

908910
virtual GSTexture* CreateSurface(GSTexture::Type type, int width, int height, int levels, GSTexture::Format format) = 0;

pcsx2/GS/Renderers/DX11/GSDevice11.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,12 @@ void GSDevice11::SetupOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, u8
19291929

19301930
if (dssel.ztst != ZTST_ALWAYS || dssel.zwe)
19311931
{
1932-
static const D3D11_COMPARISON_FUNC ztst[] =
1932+
static constexpr D3D11_COMPARISON_FUNC ztst[] =
19331933
{
1934-
D3D11_COMPARISON_NEVER,
1935-
D3D11_COMPARISON_ALWAYS,
1936-
D3D11_COMPARISON_GREATER_EQUAL,
1937-
D3D11_COMPARISON_GREATER
1934+
D3D11_COMPARISON_NEVER,
1935+
D3D11_COMPARISON_ALWAYS,
1936+
D3D11_COMPARISON_GREATER_EQUAL,
1937+
D3D11_COMPARISON_GREATER
19381938
};
19391939

19401940
dsd.DepthEnable = true;
@@ -2027,7 +2027,7 @@ bool GSDevice11::CreateCASShaders()
20272027

20282028
bool GSDevice11::DoCAS(GSTexture* sTex, GSTexture* dTex, bool sharpen_only, const std::array<u32, NUM_CAS_CONSTANTS>& constants)
20292029
{
2030-
static const int threadGroupWorkRegionDim = 16;
2030+
static constexpr int threadGroupWorkRegionDim = 16;
20312031
const int dispatchX = (dTex->GetWidth() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
20322032
const int dispatchY = (dTex->GetHeight() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
20332033

pcsx2/GS/Renderers/DX12/GSDevice12.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ GSDevice12::ComPtr<ID3D12PipelineState> GSDevice12::CreateTFXPipeline(const Pipe
30303030
// DepthStencil
30313031
if (p.ds)
30323032
{
3033-
static const D3D12_COMPARISON_FUNC ztst[] = {D3D12_COMPARISON_FUNC_NEVER, D3D12_COMPARISON_FUNC_ALWAYS,
3033+
static constexpr D3D12_COMPARISON_FUNC ztst[] = {D3D12_COMPARISON_FUNC_NEVER, D3D12_COMPARISON_FUNC_ALWAYS,
30343034
D3D12_COMPARISON_FUNC_GREATER_EQUAL, D3D12_COMPARISON_FUNC_GREATER};
30353035
gpb.SetDepthState((p.dss.ztst != ZTST_ALWAYS || p.dss.zwe), p.dss.zwe, ztst[p.dss.ztst]);
30363036
if (p.dss.date)

pcsx2/GS/Renderers/HW/GSRendererHW.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,8 +2322,6 @@ void GSRendererHW::RoundSpriteOffset()
23222322

23232323
void GSRendererHW::Draw()
23242324
{
2325-
static u32 num_skipped_channel_shuffle_draws = 0;
2326-
23272325
// We mess with this state as an optimization, so take a copy and use that instead.
23282326
const GSDrawingContext* context = m_context;
23292327
m_cached_ctx.TEX0 = context->TEX0;
@@ -9464,17 +9462,13 @@ GSHWDrawConfig& GSRendererHW::BeginHLEHardwareDraw(
94649462
std::memset(&config.cb_vs, 0, sizeof(config.cb_vs));
94659463
std::memset(&config.cb_ps, 0, sizeof(config.cb_ps));
94669464

9467-
// Reused between draws, since the draw config is shared, you can't have multiple draws in flight anyway.
9468-
static GSVertex vertices[4];
9469-
static constexpr u16 indices[6] = {0, 1, 2, 2, 1, 3};
9470-
94719465
#define V(i, x, y, u, v) \
94729466
do \
94739467
{ \
9474-
vertices[i].XYZ.X = x; \
9475-
vertices[i].XYZ.Y = y; \
9476-
vertices[i].U = u; \
9477-
vertices[i].V = v; \
9468+
m_hle_vertices[i].XYZ.X = x; \
9469+
m_hle_vertices[i].XYZ.Y = y; \
9470+
m_hle_vertices[i].U = u; \
9471+
m_hle_vertices[i].V = v; \
94789472
} while (0)
94799473

94809474
const GSVector4i fp_rect = unscaled_rect.sll32<4>();
@@ -9490,10 +9484,10 @@ GSHWDrawConfig& GSRendererHW::BeginHLEHardwareDraw(
94909484
config.ds = ds;
94919485
config.tex = tex;
94929486
config.pal = nullptr;
9493-
config.indices = indices;
9494-
config.verts = vertices;
9495-
config.nverts = static_cast<u32>(std::size(vertices));
9496-
config.nindices = static_cast<u32>(std::size(indices));
9487+
config.indices = m_hle_indices;
9488+
config.verts = m_hle_vertices;
9489+
config.nverts = static_cast<u32>(std::size(m_hle_vertices));
9490+
config.nindices = static_cast<u32>(std::size(m_hle_indices));
94979491
config.indices_per_prim = 3;
94989492
config.drawlist = nullptr;
94999493
config.scissor = rt_or_ds->GetRect();

pcsx2/GS/Renderers/HW/GSRendererHW.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class GSRendererHW : public GSRenderer
183183
u32 m_channel_shuffle_width = 0;
184184
GSVector4i m_channel_shuffle_src_valid = GSVector4i::zero();
185185
bool m_full_screen_shuffle = false;
186+
u32 num_skipped_channel_shuffle_draws = 0;
186187

187188
GSTextureCache::Target* m_last_rt;
188189

@@ -205,6 +206,10 @@ class GSRendererHW : public GSRenderer
205206
std::unique_ptr<GSTextureCacheSW::Texture> m_sw_texture[7 + 1];
206207
std::unique_ptr<GSVirtualAlignedClass<32>> m_sw_rasterizer;
207208

209+
// HLE state
210+
GSVertex m_hle_vertices[4] = {};
211+
static constexpr u16 m_hle_indices[6] = {0, 1, 2, 2, 1, 3};
212+
208213
public:
209214
GSRendererHW();
210215
virtual ~GSRendererHW() override;

pcsx2/GS/Renderers/HW/GSTextureCache.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ std::unique_ptr<GSTextureCache> g_texture_cache;
3030

3131
static u8* s_unswizzle_buffer;
3232

33-
/// List of candidates for purging when the hash cache gets too large.
34-
static std::vector<std::pair<GSTextureCache::HashCacheMap::iterator, s32>> s_hash_cache_purge_list;
35-
3633
#ifdef PCSX2_DEVBUILD
3734
// We can only set one texture name per command buffer, which would break our fancy texture cache RT/DS/texture naming.
3835
// So, when debug device is enabled, don't reuse any textures that are drawable.
@@ -62,7 +59,6 @@ GSTextureCache::~GSTextureCache()
6259
{
6360
RemoveAll(true, true, true);
6461

65-
s_hash_cache_purge_list = {};
6662
_aligned_free(s_unswizzle_buffer);
6763
}
6864

@@ -109,6 +105,8 @@ void GSTextureCache::RemoveAll(bool sources, bool targets, bool hash_cache)
109105
m_hash_cache.clear();
110106
m_hash_cache_memory_usage = 0;
111107
m_hash_cache_replacement_memory_usage = 0;
108+
109+
m_hash_cache_purge_list.clear();
112110
}
113111
}
114112

@@ -6811,7 +6809,7 @@ void GSTextureCache::AgeHashCache()
68116809

68126810
bool might_need_cache_purge = (m_hash_cache.size() > MAX_HASH_CACHE_SIZE);
68136811
if (might_need_cache_purge)
6814-
s_hash_cache_purge_list.clear();
6812+
m_hash_cache_purge_list.clear();
68156813

68166814
for (auto it = m_hash_cache.begin(); it != m_hash_cache.end();)
68176815
{
@@ -6833,7 +6831,7 @@ void GSTextureCache::AgeHashCache()
68336831
{
68346832
might_need_cache_purge = (m_hash_cache.size() > MAX_HASH_CACHE_SIZE);
68356833
if (might_need_cache_purge)
6836-
s_hash_cache_purge_list.emplace_back(it, static_cast<s32>(e.age));
6834+
m_hash_cache_purge_list.emplace_back(it, static_cast<s32>(e.age));
68376835
}
68386836

68396837
++it;
@@ -6842,13 +6840,13 @@ void GSTextureCache::AgeHashCache()
68426840
// Pushing to a list, sorting, and removing ends up faster than re-iterating the map.
68436841
if (might_need_cache_purge)
68446842
{
6845-
std::sort(s_hash_cache_purge_list.begin(), s_hash_cache_purge_list.end(),
6843+
std::sort(m_hash_cache_purge_list.begin(), m_hash_cache_purge_list.end(),
68466844
[](const auto& lhs, const auto& rhs) { return lhs.second > rhs.second; });
68476845

68486846
const u32 entries_to_purge = std::min(static_cast<u32>(m_hash_cache.size() - MAX_HASH_CACHE_SIZE),
6849-
static_cast<u32>(s_hash_cache_purge_list.size()));
6847+
static_cast<u32>(m_hash_cache_purge_list.size()));
68506848
for (u32 i = 0; i < entries_to_purge; i++)
6851-
RemoveFromHashCache(s_hash_cache_purge_list[i].first);
6849+
RemoveFromHashCache(m_hash_cache_purge_list[i].first);
68526850
}
68536851
}
68546852

pcsx2/GS/Renderers/HW/GSTextureCache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ class GSTextureCache
424424
HashCacheMap m_hash_cache;
425425
u64 m_hash_cache_memory_usage = 0;
426426
u64 m_hash_cache_replacement_memory_usage = 0;
427+
/// List of candidates for purging when the hash cache gets too large.
428+
std::vector<std::pair<GSTextureCache::HashCacheMap::iterator, s32>> m_hash_cache_purge_list = {};
427429

428430
FastList<Target*> m_dst[2];
429431
FastList<TargetHeightElem> m_target_heights;

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ GSDepthStencilOGL* GSDeviceOGL::CreateDepthStencil(OMDepthStencilSelector dssel)
12681268

12691269
if (dssel.ztst != ZTST_ALWAYS || dssel.zwe)
12701270
{
1271-
static const GLenum ztst[] =
1271+
static constexpr GLenum ztst[] =
12721272
{
12731273
GL_NEVER,
12741274
GL_ALWAYS,
@@ -2101,7 +2101,7 @@ bool GSDeviceOGL::DoCAS(GSTexture* sTex, GSTexture* dTex, bool sharpen_only, con
21012101
PSSetShaderResource(0, sTex);
21022102
glBindImageTexture(0, static_cast<GSTextureOGL*>(dTex)->GetID(), 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
21032103

2104-
static const int threadGroupWorkRegionDim = 16;
2104+
static constexpr int threadGroupWorkRegionDim = 16;
21052105
const int dispatchX = (dTex->GetWidth() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
21062106
const int dispatchY = (dTex->GetHeight() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
21072107
glDispatchCompute(dispatchX, dispatchY, 1);

pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ bool GSDeviceVK::CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer
597597
// Enable debug layer on debug builds
598598
if (enable_validation_layer)
599599
{
600-
static const char* layer_names[] = {"VK_LAYER_LUNARG_standard_validation"};
600+
static constexpr const char* layer_names[] = {"VK_LAYER_LUNARG_standard_validation"};
601601
device_info.enabledLayerCount = 1;
602602
device_info.ppEnabledLayerNames = layer_names;
603603
}
@@ -4520,7 +4520,7 @@ bool GSDeviceVK::DoCAS(
45204520
dsub.PushUpdate(cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, m_cas_pipeline_layout, 0, false);
45214521

45224522
// the actual meat and potatoes! only four commands.
4523-
static const int threadGroupWorkRegionDim = 16;
4523+
static constexpr int threadGroupWorkRegionDim = 16;
45244524
const int dispatchX = (dTex->GetWidth() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
45254525
const int dispatchY = (dTex->GetHeight() + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
45264526

@@ -4877,7 +4877,7 @@ VkPipeline GSDeviceVK::CreateTFXPipeline(const PipelineSelector& p)
48774877
}
48784878

48794879
// DepthStencil
4880-
static const VkCompareOp ztst[] = {
4880+
static constexpr VkCompareOp ztst[] = {
48814881
VK_COMPARE_OP_NEVER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER};
48824882
gpb.SetDepthState((p.dss.ztst != ZTST_ALWAYS || p.dss.zwe), p.dss.zwe, ztst[p.dss.ztst]);
48834883
if (p.dss.date)

0 commit comments

Comments
 (0)