From 8866faa8d59301bf22e77a58ad895aca113d6134 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Jul 2023 01:55:06 +1000 Subject: [PATCH] GS: Remove GSCrc Finally! --- pcsx2/CMakeLists.txt | 2 -- pcsx2/GS/GS.cpp | 11 +++--- pcsx2/GS/GS.h | 2 +- pcsx2/GS/GSCrc.cpp | 45 ------------------------ pcsx2/GS/GSCrc.h | 41 --------------------- pcsx2/GS/GSState.cpp | 16 --------- pcsx2/GS/GSState.h | 8 ----- pcsx2/GS/Renderers/Common/GSRenderer.cpp | 33 ++++++++++------- pcsx2/GS/Renderers/Common/GSRenderer.h | 4 +++ pcsx2/GS/Renderers/HW/GSHwHack.cpp | 4 +-- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 7 ---- pcsx2/GS/Renderers/HW/GSRendererHW.h | 3 +- pcsx2/MTGS.cpp | 39 +++++--------------- pcsx2/MTGS.h | 3 +- pcsx2/VMManager.cpp | 2 +- pcsx2/pcsx2.vcxproj | 2 -- pcsx2/pcsx2.vcxproj.filters | 6 ---- 17 files changed, 45 insertions(+), 183 deletions(-) delete mode 100644 pcsx2/GS/GSCrc.cpp delete mode 100644 pcsx2/GS/GSCrc.h diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index b4d2f3698e..74a4b39e7b 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -518,7 +518,6 @@ set(pcsx2GSSources GS/GSAlignedClass.cpp GS/GSCapture.cpp GS/GSClut.cpp - GS/GSCrc.cpp GS/GSDrawingContext.cpp GS/GSDump.cpp GS/GSLocalMemory.cpp @@ -554,7 +553,6 @@ set(pcsx2GSHeaders GS/GSBlock.h GS/GSCapture.h GS/GSClut.h - GS/GSCrc.h GS/GSDrawingContext.h GS/GSDrawingEnvironment.h GS/GSDump.h diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index ca31c31bcb..e892c5a56b 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -202,6 +202,7 @@ static bool OpenGSRenderer(GSRendererType renderer, u8* basemem) g_gs_renderer->SetRegsMem(basemem); g_gs_renderer->ResetPCRTC(); + g_gs_renderer->UpdateRenderFixes(); g_perfmon.Reset(); return true; } @@ -239,7 +240,6 @@ bool GSreopen(bool recreate_device, bool recreate_renderer, const Pcsx2Config::G } u8* basemem = g_gs_renderer->GetRegsMem(); - const u32 gamecrc = g_gs_renderer->GetGameCRC(); freezeData fd = {}; std::unique_ptr fd_data; @@ -309,8 +309,6 @@ bool GSreopen(bool recreate_device, bool recreate_renderer, const Pcsx2Config::G Console.Error("(GSreopen) Failed to defrost"); return false; } - - g_gs_renderer->SetGameCRC(gamecrc); } if (!capture_filename.empty()) @@ -504,9 +502,10 @@ void GSThrottlePresentation() Threading::SleepUntil(s_next_manual_present_time); } -void GSSetGameCRC(u32 crc) +void GSGameChanged() { - g_gs_renderer->SetGameCRC(crc); + if (GSConfig.UseHardwareRenderer()) + GSTextureReplacements::GameChanged(); } void GSResizeDisplayWindow(int width, int height, float scale) @@ -731,7 +730,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config) GSConfig.BeforeDrawFunctionId != old_config.BeforeDrawFunctionId || GSConfig.MoveHandlerFunctionId != old_config.MoveHandlerFunctionId) { - g_gs_renderer->UpdateCRCHacks(); + g_gs_renderer->UpdateRenderFixes(); } // renderer-specific options (e.g. auto flush, TC offset) diff --git a/pcsx2/GS/GS.h b/pcsx2/GS/GS.h index 2b141e63b6..808a111c7a 100644 --- a/pcsx2/GS/GS.h +++ b/pcsx2/GS/GS.h @@ -94,7 +94,7 @@ bool GSBeginCapture(std::string filename); void GSEndCapture(); void GSPresentCurrentFrame(); void GSThrottlePresentation(); -void GSSetGameCRC(u32 crc); +void GSGameChanged(); void GSSetDisplayAlignment(GSDisplayAlignment alignment); void GSResizeDisplayWindow(int width, int height, float scale); void GSUpdateDisplayWindow(); diff --git a/pcsx2/GS/GSCrc.cpp b/pcsx2/GS/GSCrc.cpp deleted file mode 100644 index 400ffd5305..0000000000 --- a/pcsx2/GS/GSCrc.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2021 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#include "PrecompiledHeader.h" - -#include "GS/GSCrc.h" -#include "GS/GSExtra.h" -#include "GS/GS.h" -#include "Host.h" - -#include "common/StringUtil.h" - -const CRC::Game CRC::m_games[] = -{ - // Note: IDs 0x7ACF7E03, 0x7D4EA48F, 0x37C53760 - shouldn't be added as it's from the multiloaders when packing games. - {0x00000000, NoTitle /* NoRegion */}, - {0xFC46EA61, Tekken5 /* JP */}, - {0x1F88EE37, Tekken5 /* EU */}, - {0x1F88BECD, Tekken5 /* EU */}, // language selector... - {0x652050D2, Tekken5 /* US */}, - {0xEA64EF39, Tekken5 /* KO */}, -}; - -const CRC::Game& CRC::Lookup(u32 crc) -{ - for (const Game& game : m_games) - { - if (game.crc == crc) - return game; - } - - return m_games[0]; -} diff --git a/pcsx2/GS/GSCrc.h b/pcsx2/GS/GSCrc.h deleted file mode 100644 index 6955a03add..0000000000 --- a/pcsx2/GS/GSCrc.h +++ /dev/null @@ -1,41 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2021 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include - -class CRC -{ -public: - enum Title : u32 - { - NoTitle, - Tekken5, - TitleCount, - }; - - struct Game - { - u32 crc; - Title title; - }; - -private: - static const Game m_games[]; - -public: - static const Game& Lookup(u32 crc); -}; diff --git a/pcsx2/GS/GSState.cpp b/pcsx2/GS/GSState.cpp index 2790bd985a..515174a4da 100644 --- a/pcsx2/GS/GSState.cpp +++ b/pcsx2/GS/GSState.cpp @@ -2187,11 +2187,6 @@ void GSState::ReadLocalMemoryUnsync(u8* mem, int qwc, GIFRegBITBLTBUF BITBLTBUF, } } -void GSState::PurgePool() -{ - g_gs_device->PurgePool(); -} - void GSState::PurgeTextureCache() { } @@ -2610,17 +2605,6 @@ int GSState::Defrost(const freezeData* fd) return 0; } -void GSState::SetGameCRC(u32 crc) -{ - m_crc = crc; - UpdateCRCHacks(); -} - -void GSState::UpdateCRCHacks() -{ - m_game = CRC::Lookup(GSConfig.UserHacks_DisableRenderFixes ? 0 : m_crc); -} - // void GSState::UpdateContext() diff --git a/pcsx2/GS/GSState.h b/pcsx2/GS/GSState.h index a8d96d528e..805b487fc4 100644 --- a/pcsx2/GS/GSState.h +++ b/pcsx2/GS/GSState.h @@ -23,7 +23,6 @@ #include "GS/Renderers/Common/GSVertexTrace.h" #include "GS/Renderers/Common/GSDevice.h" #include "GS/GSVector.h" -#include "GSCrc.h" #include "GSAlignedClass.h" class GSDumpBase; @@ -218,8 +217,6 @@ public: const GSDrawingEnvironment* m_draw_env = &m_env; GSDrawingContext* m_context = nullptr; GSVector4i temp_draw_rect = {}; - u32 m_crc = 0; - CRC::Game m_game = {}; std::unique_ptr m_dump; bool m_scissor_invalid = false; bool m_nativeres = false; @@ -389,7 +386,6 @@ public: bool TestDrawChanged(); void FlushWrite(); virtual void Draw() = 0; - virtual void PurgePool(); virtual void PurgeTextureCache(); virtual void ReadbackTextureCache(); virtual void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r) {} @@ -409,10 +405,6 @@ public: int Freeze(freezeData* fd, bool sizeonly); int Defrost(const freezeData* fd); - u32 GetGameCRC() const { return m_crc; } - virtual void SetGameCRC(u32 crc); - virtual void UpdateCRCHacks(); - u8* GetRegsMem() const { return reinterpret_cast(m_regs); } void SetRegsMem(u8* basemem) { m_regs = reinterpret_cast(basemem); } diff --git a/pcsx2/GS/Renderers/Common/GSRenderer.cpp b/pcsx2/GS/Renderers/Common/GSRenderer.cpp index b5d342017b..58559c2b29 100644 --- a/pcsx2/GS/Renderers/Common/GSRenderer.cpp +++ b/pcsx2/GS/Renderers/Common/GSRenderer.cpp @@ -87,6 +87,15 @@ void GSRenderer::Destroy() GSCapture::EndCapture(); } +void GSRenderer::PurgePool() +{ + g_gs_device->PurgePool(); +} + +void GSRenderer::UpdateRenderFixes() +{ +} + bool GSRenderer::Merge(int field) { GSVector2i fs(0, 0); @@ -659,6 +668,9 @@ void GSRenderer::VSync(u32 field, bool registers_written, bool idle_frame) if (!m_dump && m_dump_frames > 0) { + if (GSConfig.UserHacks_ReadTCOnClose) + ReadbackTextureCache(); + freezeData fd = {0, nullptr}; Freeze(&fd, true); fd.data = new u8[fd.size]; @@ -673,26 +685,23 @@ void GSRenderer::VSync(u32 field, bool registers_written, bool idle_frame) std::string_view compression_str; if (GSConfig.GSDumpCompression == GSDumpCompressionMethod::Uncompressed) { - m_dump = std::unique_ptr(new GSDumpUncompressed(m_snapshot, VMManager::GetDiscSerial(), m_crc, - screenshot_width, screenshot_height, - screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), - fd, m_regs)); + m_dump = std::unique_ptr(new GSDumpUncompressed(m_snapshot, VMManager::GetDiscSerial(), + VMManager::GetDiscCRC(), screenshot_width, screenshot_height, + screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), fd, m_regs)); compression_str = "with no compression"; } else if (GSConfig.GSDumpCompression == GSDumpCompressionMethod::LZMA) { - m_dump = std::unique_ptr(new GSDumpXz(m_snapshot, VMManager::GetDiscSerial(), m_crc, - screenshot_width, screenshot_height, - screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), - fd, m_regs)); + m_dump = std::unique_ptr( + new GSDumpXz(m_snapshot, VMManager::GetDiscSerial(), VMManager::GetDiscCRC(), screenshot_width, + screenshot_height, screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), fd, m_regs)); compression_str = "with LZMA compression"; } else { - m_dump = std::unique_ptr(new GSDumpZst(m_snapshot, VMManager::GetDiscSerial(), m_crc, - screenshot_width, screenshot_height, - screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), - fd, m_regs)); + m_dump = std::unique_ptr( + new GSDumpZst(m_snapshot, VMManager::GetDiscSerial(), VMManager::GetDiscCRC(), screenshot_width, + screenshot_height, screenshot_pixels.empty() ? nullptr : screenshot_pixels.data(), fd, m_regs)); compression_str = "with Zstandard compression"; } diff --git a/pcsx2/GS/Renderers/Common/GSRenderer.h b/pcsx2/GS/Renderers/Common/GSRenderer.h index 9621d766ce..0885a1a46d 100644 --- a/pcsx2/GS/Renderers/Common/GSRenderer.h +++ b/pcsx2/GS/Renderers/Common/GSRenderer.h @@ -52,6 +52,10 @@ public: virtual void Destroy(); + virtual void UpdateRenderFixes(); + + void PurgePool(); + virtual void VSync(u32 field, bool registers_written, bool idle_frame); virtual bool CanUpscale() { return false; } virtual float GetUpscaleMultiplier() { return 1.0f; } diff --git a/pcsx2/GS/Renderers/HW/GSHwHack.cpp b/pcsx2/GS/Renderers/HW/GSHwHack.cpp index b0c47d4c40..69f324a3ef 100644 --- a/pcsx2/GS/Renderers/HW/GSHwHack.cpp +++ b/pcsx2/GS/Renderers/HW/GSHwHack.cpp @@ -1532,9 +1532,9 @@ s16 GSLookupMoveHandlerFunctionId(const std::string_view& name) return -1; } -void GSRendererHW::UpdateCRCHacks() +void GSRendererHW::UpdateRenderFixes() { - GSRenderer::UpdateCRCHacks(); + GSRenderer::UpdateRenderFixes(); m_nativeres = (GSConfig.UpscaleMultiplier == 1.0f); s_nativeres = m_nativeres; diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index cfd29f80ec..f58de8a658 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -76,13 +76,6 @@ GSTexture* GSRendererHW::LookupPaletteSource(u32 CBP, u32 CPSM, u32 CBW, GSVecto return g_texture_cache->LookupPaletteSource(CBP, CPSM, CBW, offset, scale, size); } -void GSRendererHW::SetGameCRC(u32 crc) -{ - GSRenderer::SetGameCRC(crc); - - GSTextureReplacements::GameChanged(); -} - bool GSRendererHW::CanUpscale() { return GSConfig.UpscaleMultiplier != 1.0f; diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.h b/pcsx2/GS/Renderers/HW/GSRendererHW.h index 14819d1f61..f72b685348 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.h +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.h @@ -185,8 +185,7 @@ public: void Destroy() override; - void SetGameCRC(u32 crc) override; - void UpdateCRCHacks() override; + void UpdateRenderFixes() override; bool CanUpscale() override; float GetUpscaleMultiplier() override; diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index cd1af8eb49..36871b6d04 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -57,9 +57,6 @@ namespace MTGS } }; - static bool TryOpenGS(); - static void CloseGS(); - static void ThreadEntryPoint(); static void MainLoop(); @@ -176,7 +173,8 @@ void MTGS::ThreadEntryPoint() } // try initializing.. this could fail - const bool opened = TryOpenGS(); + std::memcpy(RingBuffer.Regs, PS2MEM_GS, sizeof(PS2MEM_GS)); + const bool opened = GSopen(EmuConfig.GS, EmuConfig.GS.Renderer, RingBuffer.Regs); s_open_flag.store(opened, std::memory_order_release); // notify emu thread that we finished opening (or failed) @@ -195,7 +193,7 @@ void MTGS::ThreadEntryPoint() // when we come back here, it's because we closed (or shutdown) // that means the emu thread should be blocked, waiting for us to be done pxAssertRel(!s_open_flag.load(std::memory_order_relaxed), "Open flag is clear on close"); - CloseGS(); + GSclose(); s_open_or_close_done.Post(); // we need to reset sem_event here, because MainLoop() kills it. @@ -313,17 +311,6 @@ union PacketTagType }; }; -bool MTGS::TryOpenGS() -{ - std::memcpy(RingBuffer.Regs, PS2MEM_GS, sizeof(PS2MEM_GS)); - - if (!GSopen(EmuConfig.GS, EmuConfig.GS.Renderer, RingBuffer.Regs)) - return false; - - GSSetGameCRC(VMManager::GetDiscCRC()); - return true; -} - void MTGS::MainLoop() { // Threading info: run in MTGS thread @@ -554,10 +541,6 @@ void MTGS::MainLoop() } break; - case Command::CRC: - GSSetGameCRC(tag.data[0]); - break; - case Command::InitAndReadFIFO: MTGS_LOG("(MTGS Packet Read) ringtype=Fifo2, size=%d", tag.data[0]); GSInitAndReadFIFO((u8*)tag.pointer, tag.data[0]); @@ -623,11 +606,6 @@ void MTGS::MainLoop() s_sem_event.Kill(); } -void MTGS::CloseGS() -{ - GSclose(); -} - // Waits for the GS to empty out the entire ring buffer contents. // If syncRegs, then writes pcsx2's gs regs to MTGS's internal copy // If weakWait, then this function is allowed to exit after MTGS finished a path1 packet @@ -894,11 +872,6 @@ void MTGS::SendPointerPacket(Command type, u32 data0, void* data1) _FinishSimplePacket(); } -void MTGS::SendGameCRC(u32 crc) -{ - SendSimplePacket(Command::CRC, crc, 0, 0); -} - bool MTGS::WaitForOpen() { if (IsOpen()) @@ -956,6 +929,12 @@ void MTGS::RunOnGSThread(AsyncCallType func) SetEvent(); } +void MTGS::GameChanged() +{ + pxAssertRel(IsOpen(), "MTGS is running"); + RunOnGSThread(GSGameChanged); +} + void MTGS::ApplySettings() { pxAssertRel(IsOpen(), "MTGS is running"); diff --git a/pcsx2/MTGS.h b/pcsx2/MTGS.h index 9cb06cf239..dc3e37ac13 100644 --- a/pcsx2/MTGS.h +++ b/pcsx2/MTGS.h @@ -41,7 +41,6 @@ namespace MTGS Freeze, Reset, // issues a GSreset() command. SoftReset, // issues a soft reset for the GIF - CRC, GSPacket, MTVUGSPacket, InitAndReadFIFO, @@ -71,7 +70,6 @@ namespace MTGS void WaitGS(bool syncRegs = true, bool weakWait = false, bool isMTVU = false); void ResetGS(bool hardware_reset); - void SendGameCRC(u32 crc); bool WaitForOpen(); void WaitForClose(); void Freeze(FreezeAction mode, FreezeData& data); @@ -80,6 +78,7 @@ namespace MTGS void InitAndReadFIFO(u8* mem, u32 qwc); void RunOnGSThread(AsyncCallType func); + void GameChanged(); void ApplySettings(); void ResizeDisplayWindow(int width, int height, float scale); void UpdateDisplayWindow(); diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index bafedceee4..9aec4b0bc3 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -905,7 +905,7 @@ void VMManager::UpdateDiscDetails(bool booting) ReportGameChangeToHost(); Achievements::GameChanged(s_disc_crc, s_current_crc); if (MTGS::IsOpen()) - MTGS::SendGameCRC(s_disc_crc); + MTGS::GameChanged(); ReloadPINE(); UpdateDiscordPresence(Achievements::GetRichPresenceString()); diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 6eeb579ea2..cf468b657c 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -284,7 +284,6 @@ - @@ -626,7 +625,6 @@ - diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index 82850ba53b..c455a8fe84 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -995,9 +995,6 @@ System\Ps2\GS - - System\Ps2\GS - System\Ps2\GS @@ -1915,9 +1912,6 @@ System\Ps2\GS - - System\Ps2\GS - System\Ps2\GS